Description Usage Arguments Value Author(s) See Also Examples
Leave-one-out cross-validation of nonparametric kernel regression models, partial linear models, and categorical regression splines.
1 2 3 4 5 |
x |
an object of class |
A single numeric value:
the mean squared prediction error over all observations,
where the predicted values are obtained
based on models that are estimated without the respective observation.
This value has an attribute err
that is the vector of the prediction errors of all observations.
Arne Henningsen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | set.seed(42)
n <- 250
x1 <- rnorm(n)
x2 <- rnorm(n)
y <- 1 + x1 + x2^2 + rnorm(n)
model <- npreg( y ~ x1 + x2, regtype="ll" )
cv <- npregCv( model )
c( cv )
all.equal( cv, model$bws$fval, check.attributes = FALSE )
# partially linear model
set.seed(42)
n <- 250
x1 <- rnorm(n)
x2 <- rbinom(n, 1, .5)
z1 <- rbinom(n, 1, .5)
z2 <- rnorm(n)
y <- 1 + x1 + x2 + z1 + sin(z2) + rnorm(n)
model <- npplreg( y ~ x1 + factor(x2) | factor(z1) + z2, regtype="ll" )
cv <- npplregCv( model )
c( cv )
# categorical regression splines
set.seed(42)
n <- 250
num.eval <- 50
x1 <- runif(n)
x2 <- runif(n)
z <- round( runif( n, min = 0, max = 3 ) )
dgp <- cos( 2 * pi * x1 ) + sin( 2 * pi * x2 ) + z/5
z <- factor(z)
y <- dgp + rnorm( n, sd = 0.5 )
model <- crs( y ~ x1 + x2 + z, deriv = 1, nmulti = 1 )
cv <- crsCv( model )
c( cv )
all.equal( cv, model$cv.min, check.attributes = FALSE )
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.