| varNPreg | R Documentation |
Estimates the error variance \sigma^2 nonparametrically in the model
Y_i = m(x_i) + E_i,
where
E_i \sim (0,\sigma^2), i.i.d.
Computes leave-one-out residuals (local linear approximation followed by reweighting) and their variance.
varNPreg(x, y)
x |
abscissae values, ordered increasingly. |
y |
observations at |
A list with components
res |
numeric; residuals at |
snr |
explained variance of the true curve, i.e., an |
sigma2 |
estimation of residual variance, |
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().
Martin Maechler
lokerns, glkerns.
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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.