Description Usage Arguments Details Value Examples
This estimates nonparametric conditional expectation E[y|x=args]
using
the Nadaraya-Watson estimator with Gaussian kernel.
1 | GaussianNadarayaWatsonEstimator(x, y, h, args = NULL)
|
x |
a numeric vector or matrix of explanatory variable(s). |
y |
a numeric vector of outcome (or dependent) variable. |
h |
a numeric vector indicating bandwidth size(s) for each explanatory variable in |
args |
a numeric vector or matrix of arguments at which nonparametric conditional expectations are evaluated. |
This is the Nadaraya-Watson estimator taking as arguments data x
and y
,
bandwidth h
, and target points args
. If args
are not given, it will return
the leave-one-out version. The dimension of h
should be the same as that of x
, i.e.,
bandwidths need to be separately specified for each explanatory variable. A popular choice of
bandwidth is the Silverman's rule of thumb, h = sd(x)*N^(-1/r)
with r = 4 + q
, where
N
is the sample size and q
is the dimension of x
.
a numeric vector of nonparametric estimates of conditional expectation E[y|x=args]
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # data generating process
N <- 500L
x1 <- stats::rnorm(N)
x2 <- stats::rnorm(N)
x3 <- stats::rnorm(N)
x <- cbind(x1, x2, x3)
v <- (x1 + x2 + x3)/sqrt(3)
y <- v + rnorm(N)
# univariate case
h_u <- stats::sd(v)*N^(-1/5)
vargs <- stats::quantile(v)
yhat_univ_1 <- GaussianNadarayaWatsonEstimator(v, y, h_u, vargs)
yhat_univ_2 <- GaussianNadarayaWatsonEstimator(v, y, h_u) # leave-one-out version
# multivariate case
h_m <- apply(matrix(stats::rnorm(150), 50, 3), 2, stats::sd)*N^(-1/7)
xargs <- apply(matrix(stats::rnorm(150), 50, 3), 2, stats::quantile)
yhat_multi_1 <- GaussianNadarayaWatsonEstimator(x, y, h_m, xargs)
yhat_multi_2 <- GaussianNadarayaWatsonEstimator(x, y, h_m) # leave-one-out version
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.