[R-sig-Geo] Leave one out cross validation in a Generalized linear Model?

Swen Meyer s.meyer at lmu.de
Thu Sep 29 10:48:44 CEST 2011


Hi Alex,
thanks for the tip. You are writing about the " Leave-one-out 
cross-validation of the 'lm', but I need it for a GLM. I can do the CV 
for the lm with gstat using the krige.cv function (see below), but I 
don`t know how to use the CV for the GLM part. I also tried the 
"errorest" function in the "Ipred" package.  But I wasn`t able to put 
the GLM in there in the right way and I can`t find anything about GLM in 
the manual?
Any Idea?
Thats how I do the CV for the LM and below ther is the GLM tjhat I´m 
susing for the Regression Kriging:
###################
##Linear Regression##
#######LM##########

fit1 <- lm((log1p(SAND))~PC1 + PC2 + PC3 + PC4 + PC5  + PC7 + PC8 + PC9 
+ PC10 + PC11 + PC12 + PC13 + PC14 + PC15 + PC16 + PC17 + PC18 +PC19 , 
boden.ov[sel,] )
step1 <- stepAIC(fit1, direction="backward")
step1$anova # display results
reg <- formula(step1)

#####loocv for the LM
kordinary_reg.cv <- krige.cv(reg  , loc = boden.ov)

###############################
####GLM model (package (GLM))##
###############################
summary(lm(formula(step1), boden.ov[sel,]))
m.glm <- glm(formula(step1), boden.ov[sel,], family=gaussian(log))
summary(m.glm)
p.glm <- predict(m.glm, newdata=boden.grid, type="link", se.fit=TRUE)
om.glm <- as(boden.grid["band1"], "SpatialPointsDataFrame")
om.glm$var1.pred <- p.glm$fit
om.glm$var1.var <- p.glm$se.fit
om.glm$svar <- p.glm$se.fit^2/(m.glm$null.deviance/m.glm$df.null)
gridded(om.glm) <- TRUE
fullgrid(om.glm) <- TRUE
Best,
Swen

Am 27.09.2011 15:33, schrieb Alexander Brenning:
> Hi Swen,
> try 'errorest' in package 'ipred'. Leave-one-out cross-validation of 
> the 'lm' is pretty straightforward with this function. For LOO-CV of 
> regression kriging (i.e. combined prediction of regression and kriging 
> method) you would have to write small wrapper functions to be passed 
> to 'errorest' via the 'model' and 'predict' arguments - see the 
> Examples section of the errorest help.
> Best,
>   Alex
>
>
>
> -- 
> --------------------------------------------------------------
> Dipl. - Geogr. Swen Meyer
> Department of Geography
> Physical Geography and Environmental Modeling Ludwig-Maximilian University of Munich
>
> Luisenstrasse 37
> 80333 Munich/Germany
> fon: +49 (0)89 2180-6648
> fax: +49 (0)89 2180-6675
> email: s.meyer at lmu.de
> web: www.geographie.uni-muenchen.de
>



More information about the R-sig-Geo mailing list