NadarayaWatsonkernel: Nadaraya-Watson kernel estimator

Description Usage Arguments Details Value Author(s) References Examples

View source: R/NadarayaWatsonkernel.R

Description

Nadaraya (1964) and Watson (1964) proposed to estimate m as a locally weighted average, using a kernel as a weighting function.

Usage

1
NadarayaWatsonkernel(x, y, h, gridpoint)

Arguments

x

A set of x observations.

y

A set of y observations.

h

Optimal bandwidth chosen by the user.

gridpoint

A set of gridpoints.

Details

\frac{∑^n_{i=1}K_h(x-x_i)y_i}{∑^n_{j=1}K_h(x-x_j)}, where K is a kernel function with a bandwidth h.

Value

gridpoint

A set of gridpoints.

mh

Density values corresponding to the set of gridpoints.

Author(s)

Han Lin Shang

References

M. Rosenblatt (1956) Remarks on some nonparametric estimates of a density function, The Annals of Mathematical Statistics, 27(3), 832-837.

E. Parzen (1962) On estimation of a probability density function and mode, The Annals of Mathematical Statistics, 33(3), 1065-1076.

E. A. Nadaraya (1964) On estimating regression, Theory of probability and its applications, 9(1), 141-142.

G. S. Watson (1964) Smooth regression analysis, Sankhya: The Indian Journal of Statistics (Series A), 26(4), 359-372.

Examples

1
2
3
x = rnorm(100)
y = rnorm(100)
NadarayaWatsonkernel(x, y, h = 2, gridpoint = seq(-3, 3, length.out = 100))

Example output

Loading required package: MASS
$gridpoint
  [1] -3.00000000 -2.93939394 -2.87878788 -2.81818182 -2.75757576 -2.69696970
  [7] -2.63636364 -2.57575758 -2.51515152 -2.45454545 -2.39393939 -2.33333333
 [13] -2.27272727 -2.21212121 -2.15151515 -2.09090909 -2.03030303 -1.96969697
 [19] -1.90909091 -1.84848485 -1.78787879 -1.72727273 -1.66666667 -1.60606061
 [25] -1.54545455 -1.48484848 -1.42424242 -1.36363636 -1.30303030 -1.24242424
 [31] -1.18181818 -1.12121212 -1.06060606 -1.00000000 -0.93939394 -0.87878788
 [37] -0.81818182 -0.75757576 -0.69696970 -0.63636364 -0.57575758 -0.51515152
 [43] -0.45454545 -0.39393939 -0.33333333 -0.27272727 -0.21212121 -0.15151515
 [49] -0.09090909 -0.03030303  0.03030303  0.09090909  0.15151515  0.21212121
 [55]  0.27272727  0.33333333  0.39393939  0.45454545  0.51515152  0.57575758
 [61]  0.63636364  0.69696970  0.75757576  0.81818182  0.87878788  0.93939394
 [67]  1.00000000  1.06060606  1.12121212  1.18181818  1.24242424  1.30303030
 [73]  1.36363636  1.42424242  1.48484848  1.54545455  1.60606061  1.66666667
 [79]  1.72727273  1.78787879  1.84848485  1.90909091  1.96969697  2.03030303
 [85]  2.09090909  2.15151515  2.21212121  2.27272727  2.33333333  2.39393939
 [91]  2.45454545  2.51515152  2.57575758  2.63636364  2.69696970  2.75757576
 [97]  2.81818182  2.87878788  2.93939394  3.00000000

$mh
  [1] -0.0059558077 -0.0047555543 -0.0035971487 -0.0024802679 -0.0014045946
  [6] -0.0003698182  0.0006243656  0.0015782544  0.0024921390  0.0033663031
 [11]  0.0042010234  0.0049965693  0.0057532028  0.0064711787  0.0071507441
 [16]  0.0077921386  0.0083955943  0.0089613356  0.0094895793  0.0099805346
 [21]  0.0104344032  0.0108513790  0.0112316488  0.0115753915  0.0118827791
 [26]  0.0121539760  0.0123891399  0.0125884211  0.0127519633  0.0128799036
 [31]  0.0129723725  0.0130294943  0.0130513872  0.0130381637  0.0129899306
 [36]  0.0129067896  0.0127888370  0.0126361649  0.0124488605  0.0122270072
 [41]  0.0119706846  0.0116799689  0.0113549334  0.0109956485  0.0106021826
 [46]  0.0101746023  0.0097129725  0.0092173576  0.0086878211  0.0081244266
 [51]  0.0075272382  0.0068963206  0.0062317402  0.0055335652  0.0048018660
 [56]  0.0040367161  0.0032381923  0.0024063754  0.0015413507  0.0006432083
 [61] -0.0002879558 -0.0012520398 -0.0022489354 -0.0032785267 -0.0043406905
 [66] -0.0054352953 -0.0065622006 -0.0077212568 -0.0089123045 -0.0101351738
 [71] -0.0113896841 -0.0126756433 -0.0139928474 -0.0153410803 -0.0167201128
 [76] -0.0181297026 -0.0195695936 -0.0210395154 -0.0225391833 -0.0240682973
 [81] -0.0256265423 -0.0272135873 -0.0288290854 -0.0304726730 -0.0321439702
 [86] -0.0338425797 -0.0355680875 -0.0373200616 -0.0390980527 -0.0409015935
 [91] -0.0427301990 -0.0445833656 -0.0464605720 -0.0483612785 -0.0502849268
 [96] -0.0522309407 -0.0541987257 -0.0561876688 -0.0581971391 -0.0602264878

bbemkr documentation built on May 1, 2019, 10:53 p.m.