Description Usage Arguments Value Author(s) Examples
Cross-validation of fitted model
1 |
model |
a model object (GLM or GAM) |
strata |
(optional) vector of the same length as the number of rows in the 'data' data.frame with integers (1:n) corresponding to n pre-defined strata to be used |
K |
the number of folds/strata in block cross-validation for random generation (if strata vector is not supplied) Minimum the same number as starta, maxuimum nrow(df)/10 |
data |
data.frame for evaluation. Must contain columns with the same names as were supplied to the model fitting function |
vector with cross-validation predictions for each observation (to be used for model evaluation)
Niklaus Zimmermann, Philipp Brun
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Fit a simple model
mod1=glm(X3740 ~ poly(bio_01,2) + poly(bio_01,2) + poly(forest_fraction,2),
data=obs.sel,family="binomial")
# Use basic cv.model set-up for cross-validation predictions
cvpr1=cv.model(mod1,K=5)
# Use cv.model for block cross-validation with few blocks
par(mfrow=c(1,2))
strt1=make_blocks(df=obs.sel[,c("bio_01","bio_03")],nstrat=3,nclusters=3)
cvpr2=cv.model(mod1,strata=strt1)
# Quick comparison
plot(cvpr1[,2],cvpr2[,2],col=strt1,main="few blocks vs random")
lines(c(-1,2),c(-1,2),col="red")
# Use cv.model for block cross-validation with many blocks
strt2=make_blocks(df=obs.sel[,c("bio_01","bio_03")],nstrat=5,nclusters=15)
cvpr3=cv.model(mod1,strata=strt2)
# Quick comparison
plot(cvpr1[,2],cvpr3[,2],col=strt2,main="many blocks vs random")
lines(c(-1,2),c(-1,2),col="red")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.