没有合适的资源?快使用搜索试试~ 我知道了~
首页R语言-核密度及其导数估计、最优窗宽选择的方法
R语言-核密度及其导数估计、最优窗宽选择的方法
需积分: 50 33 下载量 106 浏览量
更新于2023-03-03
评论 14
收藏 469KB PDF 举报
一份文件是介绍用R语言中如何利用核函数估计密度函数及其各阶导数的方法,是比较新的文献,2015年的,里面介绍了7种窗宽的确定方法以及R程序
资源详情
资源评论
资源推荐
Kernel Estimator and Bandwidth Selection for Density
and its Derivatives
The kedd Package
Version 1.0.3
by Arsalane Chouaib Guidoum
∗
Revised October 30, 2015
1 Introduction
In statistics, the univariate kernel density estimation (KDE) is a non-parametric way to estimate
the probability density function f(x) of a random variable X, is a fundamental data smoothing
problem where inferences about the population are made, based on a finite data sample. This
techniques are widely used in various inference procedures such as signal processing, data mining
and econometrics, see e.g., Silverman [1986], Wand and Jones [1995], Jeffrey [1996], Wolfgang et
all [2004], Alexandre [2009]. The kernel estimator are standard in many books with applications
and computer vision, see Wolfgang [1991], Scott [1992], Bowman and Azzalini [1997], Venables
and Ripley [2002], for computational complexity and with implementation in S, for an overview.
Estimation of the density derivatives also comes up in various other applications like estimation of
modes and inflexion points of densities, a good list of applications which require the estimation of
density derivatives can be found in Singh [1977].
There already exist a number of packages that can perform kernel density estimation in R
(density in R base); see for example KernSmooth [Wand and Ripley, 2013], sm [Bowman and Az-
zalini, 2013], np [Tristen and Jeffrey, 2008] and feature [Duong and Matt, 2013], they exist also of
functions for kernel density derivative estimation (KDDE), e.g., kdde in ks package [Duong, 2007].
We introduce in this vignette a new R package kedd [Guidoum, 2015] for use with the statistical
programming environment R Development Core Team [2015], which implements smoothing tech-
niques and computing bandwidth selectors of the r
th
derivative of a probability density f(x) for
univariate data, using several kernels functions.
2 Convolutions and derivatives in kernels
In non-parametric statistics, a kernel is a weighting function used in non-parametric estimation
techniques. Kernels are used in kernel density estimation to estimate random variables density
functions f(x), or in kernel regression to estimate the conditional expectation of a random variable,
see e.g., Silverman [1986], Wand and Jones [1995]. In general any functions having the following
assumptions can be used as a kernel:
(A1) K(x) ≥ 0 and
R
R
K(x)dx = 1.
(A2) Symmetric about the origin, e.g.,
R
R
xK(x)dx = 0.
∗
Department of Probabilities & Statistics.
Faculty of Mathematics.
University of Science and Technology Houari Boumediene.
BP 32 El-Alia, U.S.T.H.B, Algeria.
acguidoum@usthb.dz
1
(A3) Has finite second moment, e.g., µ
2
(K) =
R
R
x
2
K(x)dx < ∞. We denote R(K) =
R
R
(K(x))
2
dx.
If K(x) is a kernel, then so is the function
¯
K(x) defined by
¯
K(x) = λK(λx), where λ > 0, this can
be used to select a scale that is appropriate for the data. The kernel function is very important to
spreading a probability mass of 1/n, the most widely used kernel is the Gaussian of zero mean and
unit variance. Some classical of kernel function K(x; r) (r is the maximum derivative of kernel) in
kedd package are the following:
Kernel K(x; r) R(K) µ
2
(K)
Gaussian K(x; ∞) =
1
√
2π
exp
−
x
2
2
1
]−∞,+∞[
1/ (2
√
π) 1
Epanechnikov K(x; 2) =
3
4
1 − x
2
1
(|x|≤1)
3/5 1/5
Uniform K(x; 0) =
1
2
1
(|x|≤1)
1/2 1/3
Triangular K(x; 1) = (1 − |x|)1
(|x|≤1)
2/3 1/6
Triweight K(x; 6) =
35
32
1 − x
2
3
1
(|x|≤1)
350/429 1/9
Tricube K(x; 9) =
70
81
1 − |x|
3
3
1
(|x|≤1)
175/247 35/243
Biweight K(x; 4) =
15
16
1 − x
2
2
1
(|x|≤1)
5/7 1/7
Cosine K(x; ∞) =
π
4
cos
π
2
x
1
(|x|≤1)
π
2
/16
−8 + π
2
/π
2
Table 1: Kernel functions in kedd pakage.
The r
th
derivative of the kernel function K(x) is written as:
K
(r)
(x) =
d
r
dx
r
K(x) (1)
and convolution of K
(r)
(x) is:
K
(r)
∗ K
(r)
(x) =
Z
R
K
(r)
(x)K
(r)
(x − y)dy (2)
for example the r
th
derivative of the Gaussian kernel is given by:
K
(r)
(x) = (−1)
r
H
r
(x)K(x)
and the r
th
convolution can be written as:
K
(r)
∗ K
(r)
(x) = (−1)
2r
Z
R
H
r
(x)H
r
(x − y)K(x)K(x − y)dy
where H
r
(x) is the r
th
Hermite polynomial, see e.g., Olver et all [2010]. We use kernel.fun for
kernel derivative defined by (1), and kernel.conv for kernel convolution defined by (2).
For example the first derivative of the Gaussian kernel displayed on the left in Figure 1. On the
right is the first convolution of the Gaussian kernel.
> library(kedd)
> kernel.fun(x = seq(-0.02,0.02,by=0.01), deriv.order = 1, kernel = "gaussian")$kx
[1] 0.007977250 0.003989223 0.000000000 -0.003989223 -0.007977250
> kernel.conv(x = seq(-0.02,0.02,by=0.01), deriv.order = 1, kernel = "gaussian")$kx
[1] -0.1410051 -0.1410368 -0.1410474 -0.1410368 -0.1410051
> plot(kernel.fun(deriv.order = 1, kernel = "gaussian"))
> plot(kernel.conv(deriv.order = 1, kernel = "gaussian"))
2
−4 −2 0 2 4
−0.2
−0.1
0.0
0.1
0.2
x
−5 0 5
−0.10
−0.05
0.00
0.05
x
Figure 1: (Left) First derivative of the Gaussian kernel. (Right) Convolution of the first derivative
Gaussian kernel.
3 Kernel density derivative estimator
Let (X
1
, X
2
, . . . , X
n
) be a data sample, independent and identically distributed of a continuous
random variable X, with density function f(x). If the kernel K is differentiable r times then a
natural estimator of the r
th
derivative of f(x) the r
th
derivative of the kernel estimate [Bhattacharya,
1967, Schuster, 1969, Alekseev, 1972]:
ˆ
f
(r)
h
(x) =
d
r
dx
r
1
nh
n
X
i=1
K
x − X
i
h
=
1
nh
r+1
n
X
i=1
K
(r)
x − X
i
h
(3)
where K
(r)
is r
th
derivative of the kernel function K, which we take to be a symmetric probability
density with at least r non zero derivatives when estimating f
(r)
(x), and h is the bandwidth, this
parameter is very important that controls the degree of smoothing applied to the data.
The following assumptions on the density f
(r)
(x), the bandwidth h, and the kernel K:
(A4) The (r + 2) derivatives f
(r+2)
(x) is continuous, square integrable and ultimately monotone.
(A5) In the asymptotic framework, as lim
n→∞
h
n
= 0 and lim
n→∞
nh
2r+1
n
= ∞, i.e., as the number
of sample n is increased h approaches zero at a rate slower than 1/n
2r+1
.
(A6) Assumptions about K are introduced in the previous section.
As seen in Equation (3), when working with a kernel estimator of the r
th
derivative function two
choices must be made: the kernel function K and the smoothing parameter or bandwidth h. The
choice of K is a problem of less importance, because K is not very sensitive to the shape of estimator,
and different functions that produce good results can be used. In practice, the choice of an efficient
method for the computation of h, for an observed data sample is a crucial problem, because of the
effect of the bandwidth on the shape of the corresponding estimator. If the bandwidth is small, we
will obtain an under smoothed estimator, with high variability. On the contrary, if the value of h
is big, the resulting estimator will be over smooth and farther from the function that we are trying
to estimate.
An example is drawn in Figure 2 where we show in left four different kernel (Gaussian, biweight,
triweight and tricube) estimators of the first derivative of a bimodal (separated) Gaussian density
(Equation 5), and a given value of h = 0.6. On the right, using the Gaussian kernel and four
different values for the bandwidth.
3
−4 −2 0 2 4
−0.6
−0.4
−0.2
0.0
0.2
0.4
0.6
x
density derivative function
TRUE
gaussian
biweight
triweight
tricube
−3 −2 −1 0 1 2 3
−0.5
0.0
0.5
1.0
x
density derivative function
TRUE
h = 0.14
h = 0.3
h = 0.6
h = 1.2
Figure 2: (Left) Different kernels for estimation, with h = 0.6. (Right) Effect of the bandwidth on
the kernel estimator.
We have implemented in R the function dkde corresponds to the derivative of kernel density
estimator (Equation 3). Eight possibilities are allowed for the kernel functions that are summarized
in Table 1. We enumerate the arguments and results of this function in Table 2.
Arguments Description
x The data sample.
y The points of the grid at which the density derivative is to be estimated.
The default are 4h outside of range(x).
deriv.order Derivative order (scalar).
h The smoothing bandwidth to be used. The default, ”ucv” unbiased cross-
validation.
kernel The kernel function (see Table 1), by default "gaussian".
Results Description
eval.points The coordinates of the points where the density derivative is estimated.
est.fx The estimated density derivative values (Equation 3).
Table 2: Summary of arguments and results of dkde.
Working with the dataset ’bimodal’ correspond to data sample of 200 random numbers of a bi-
modality (separated) of a two-component Gaussian mixture density (Equation 4), with the following
parameters: −µ
1
= µ
2
= 3/2 and σ
1
= σ
2
= 1/2. The dkde function enables to compute the r
th
derivative of kernel density estimator over a grid of points, with a bandwidth selected by the user,
but it also allows to estimate directly this parameter by the unbiased cross-validation method h.ucv
(see following Section). We have chosen this method as the automatic one because it is the fastest
in computation time terms. Now we estimate the first three derivatives of f(x), can be written as:
f(x) = 0.5φ(µ
1
, σ
1
) + 0.5φ(µ
2
, σ
2
) (4)
f
(1)
(x) = 0.5(−4x − 6)φ(µ
1
, σ
1
) + 0.5(−4x + 6)φ(µ
2
, σ
2
) (5)
f
(2)
(x) = 0.5
(−4x − 6)
2
− 4
φ(µ
1
, σ
1
) + 0.5
(−4x + 6)
2
− 4
φ(µ
2
, σ
2
) (6)
f
(3)
(x) = 0.5(−4x − 6)
(−4x − 6)
2
− 12
φ(µ
1
, σ
1
) + 0.5(−4x + 6)
(−4x + 6)
2
− 12
φ(µ
2
, σ
2
) (7)
4
where φ is a standard normal density.
> hatf <- dkde(bimodal, deriv.order = 0)
Data: bimodal (200 obs.); Kernel: gaussian
Derivative order: 0; Bandwidth 'h' = 0.2098
eval.points est.fx
Min. :-3.86436 Min. :0.0000032
1st Qu.:-1.98016 1st Qu.:0.0147846
Median :-0.09595 Median :0.0737948
Mean :-0.09595 Mean :0.1324227
3rd Qu.: 1.78826 3rd Qu.:0.2326044
Max. : 3.67246 Max. :0.4374314
> hatf1 <- dkde(bimodal, deriv.order = 1)
Data: bimodal (200 obs.); Kernel: gaussian
Derivative order: 1; Bandwidth 'h' = 0.259
eval.points est.fx
Min. :-4.06125 Min. :-0.4870865
1st Qu.:-2.07860 1st Qu.:-0.1521016
Median :-0.09595 Median : 0.0009041
Mean :-0.09595 Mean : 0.0000000
3rd Qu.: 1.88670 3rd Qu.: 0.1731795
Max. : 3.86935 Max. : 0.5038096
> hatf2 <- dkde(bimodal, deriv.order = 2)
Data: bimodal (200 obs.); Kernel: gaussian
Derivative order: 2; Bandwidth 'h' = 0.3017
eval.points est.fx
Min. :-4.23200 Min. :-1.6800486
1st Qu.:-2.16398 1st Qu.: 0.0012798
Median :-0.09595 Median : 0.1421495
Mean :-0.09595 Mean :-0.0000073
3rd Qu.: 1.97208 3rd Qu.: 0.3389096
Max. : 4.04010 Max. : 0.7457487
> hatf3 <- dkde(bimodal, deriv.order = 3)
Data: bimodal (200 obs.); Kernel: gaussian
Derivative order: 3; Bandwidth 'h' = 0.3367
eval.points est.fx
Min. :-4.37205 Min. :-4.353602
1st Qu.:-2.23400 1st Qu.:-0.472761
Median :-0.09595 Median : 0.001312
Mean :-0.09595 Mean :-0.000008
3rd Qu.: 2.04210 3rd Qu.: 0.388689
Max. : 4.18016 Max. : 3.614749
5
剩余21页未读,继续阅读
Cet777
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0