# Cross-validation for kriging in R (package geoR): how to include the trend while reestimate is TRUE?

3 messages
Open this post in threaded view
|

## Cross-validation for kriging in R (package geoR): how to include the trend while reestimate is TRUE?

 Dear all, I have a question related to the function xvalid (package geoR), which I asked on StackOverflow before but unfortunately did not get answered, probably because it is too specifically related to spatial statistics and this specific function (http://stackoverflow.com/questions/43520716/cross-validation-for-kriging-in-r-how-to-include-the-trend-while-reestimating-t). I hope anyone of you is able to answer it. I would like to compute a variogram, fit it, and then perform cross-validation. Function xvalid seems to work pretty nice to do the cross-validation. It works when I set reestimate=TRUE (so it reestimates the variogram for every point removed from the dataset in cross-validation) and it also works when using a trend. However, it does not seem to work when combining these two. Here is a reproducible example using the Meuse example dataset: library(geoR) library(sp) data(meuse) # import data coordinates(meuse) = ~x+y # make spatialpointsdataframe meuse@proj4string <- CRS("+init=epsg:28992") # add projection meuse_geo <- as.geodata(meuse) # create object of class geodata for geoR compatibility meuse_geo\$data <- meuse@data # attach all data (incl. covariates) to meuse_geo meuse_vario <- variog(geodata=meuse_geo, data=meuse_geo\$data\$lead, trend= ~meuse_geo\$data\$elev) # variogram meuse_vfit <- variofit(meuse_vario, nugget=0.1, fix.nugget=T) # fit # cross-validation works fine: xvalid(geodata=meuse_geo, data=meuse_geo\$data\$lead, model=meuse_vfit, variog.obj = meuse_vario, reestimate=F) # cross-validation does not work when reestimate = T: xvalid(geodata=meuse_geo, data=meuse_geo\$data\$lead, model=meuse_vfit, variog.obj = meuse_vario, reestimate=T) The error I get is: Error in variog(coords = cv.coords, data = cv.data, uvec = variog.obj\$uvec,  : coords and trend have incompatible sizes It seems to remove the point from the dataset during cross-validation, but it doesn't seem to remove the point from the covariates/trend data. Any ideas on solving this / work-arounds? Thanks a lot in advance for thinking along. Best, Vera --- V.M. (Vera) van Zoest, MSc | PhD candidate | University of Twente | Faculty ITC | Department Earth Observation Science (EOS) | ITC Building, room 2-038 | T: +31 (0)53 - 489 4412 | [hidden email] | Study Geoinformatics: www.itc.nl/geoinformatics         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo