mse: Compute exact MSE of a kernel estimator

Description Usage Arguments Value Examples

View source: R/mse.R

Description

This function computes the exact conditional bias, variance, and MSE of a kernel estimator. 'Conditional' means conditional given the design. The estimator must be a linear smoother from this package. The true regression function and response variance must both be known, therefore this function is only useful for theoretical examples.

Usage

1
2
3
4
5
6
7
8
9
mse(
  x_data,
  h,
  m,
  s2,
  estimator,
  t = seq(from = min(x_data), to = max(x_data), length = 100),
  ...
)

Arguments

x_data

a vector giving the x-values in the data set

h

a scalar, giving the bandwidth

m

an R function, corresponding to the true regression function

s2

a scalar giving the true response variance

estimator

the estimator used (nw, local_average, or another estimator with the same input and output type)

t

(optional) a vector specifying the points at which to evaluate the estimator. The default is a sequence of length 100 spanning the range of the x-data.

...

additional arguments to be passed to estimator (e.g. kernel or empty_nhood).

Value

A list with 4 components:

t

a vector containing the evaluation points used

bias

a vector containing the bias of the estimator at the evaluation points

var

a vector containing the variance of the estimator at the evaluation points

mse

a vector containing the mean-squared error of the estimator at the evaluation points

Examples

1
2
3
4
5
6
7
m <- function(x) { (x^2+1)*sin(2*pi*x*((1-x) + 4*x)) }
x <- sort(runif(80))
res <- mse(x, 0.02, m, 0.1^2, nw)
par(mfrow=c(1,2))
plot(res$t, res$mse, type="l", xlab="x", ylab="MSE")
plot(res$t, res$var, type="l", xlab="x", ylab="Variance")
rug(x)

timwaite/nprtw documentation built on Jan. 25, 2021, 1:50 a.m.