varNPreg {lokern}R Documentation

Nonparametric Variance Estimator

Description

Estimates the error variance σ2\sigma^2 nonparametrically in the model

Yi=m(xi)+Ei,Y_i = m(x_i) + E_i,

where Ei(0,σ2)E_i \sim (0,\sigma^2), i.i.d.

Computes leave-one-out residuals (local linear approximation followed by reweighting) and their variance.

Usage

varNPreg(x, y)

Arguments

x

abscissae values, ordered increasingly.

y

observations at y[i] at x[i].

Value

A list with components

res

numeric; residuals at x[] of length n.

snr

explained variance of the true curve, i.e., an R2R^2, defined as 1σ2^/σ02^1 - \hat{\sigma^2}/ \hat{\sigma_0^2}, where σ2^=\hat{\sigma^2} = sigma2, and σ02^:=var(Y)=E[Y2](E[Y])2\hat{\sigma_0^2} := var(Y) = E[Y^2] - (E[Y])^2, see the example below.

sigma2

estimation of residual variance, σ2^\hat{\sigma^2}.

Note

This is an R interface to the resest Fortran subroutine, used in lokerns and glkerns, see the latter's help page for references and context.

Earlier version of the lokern package accidentally contained varest() which has been an identical copy of varNPreg().

Author(s)

Martin Maechler

See Also

lokerns, glkerns.

Examples

n <- 100
x <- sort(runif(n))
y <- sin(pi*x) + rnorm(n)/10
str(ve <- varNPreg(x,y))

plot(x, y)
## "fitted" = y - residuals:
lines(x, y - ve$res, col=adjustcolor(2, 1/2), lwd=3)
segments(x,y,x,y-ve$res, col=3:4, lty=2:3, lwd=1:2)

## sigma2 :=  1/n  sum_i res_i^2  :
          with(ve,         c(sigma2, sum(res^2)/n))
stopifnot(with(ve, all.equal(sigma2, sum(res^2)/n)))

## show how 'snr' is computed, given 'sigma2'  { in ../src/auxkerns.f }
dx2 <- diff(x, 2) # (x[i+1] - x[i-1]) i= 2..{n-1}
dx.n <- c(x[2]-x[1], dx2, x[n]-x[n-1])
SY  <- sum(dx.n * y)
SY2 <- sum(dx.n * y^2)
rx <- 2*(x[n]-x[1]) # 'dn'
(sigm2.0 <- SY2/rx - (SY/rx)^2)
(R2 <- 1 - ve$sigma2 / sigm2.0)
stopifnot(all.equal(ve$snr, R2))

[Package lokern version 1.1-12 Index]