[R] Cross validation for Ordinary Kriging

Jon Olav Skoien jon.skoien at jrc.ec.europa.eu
Fri Jan 7 12:40:10 CET 2011


The error suggests that there is something wrong with x2, and that there 
is a difference between the row names of the coordinates and the data. 
If you call
see if the first element of @coords is different from NULL, as this can 
cause some problems when cross-validating. If it is, try to figure out 
why. You can also set the row.names equal to NULL directly:
row.names(x2 at coords) = NULL
although I dont think such manipulation of the slots of an object is 
usually recommended.


BTW, you will usually get more response to questions about spatial data 
handling using the list r-sig-geo 

On 1/6/2011 4:00 PM, pearl may dela cruz wrote:
> ear ALL,
> The last part of my thesis analysis is the cross validation. Right now I am
> having difficulty using the cross validation of gstat. Below are my commands
> with the tsport_ace as the variable:
> nfold<- 3
> part<- sample(1:nfold, 69, replace = TRUE)
> sel<- (part != 1)
> m.model<- x2[sel, ]
> m.valid<- x2[-sel, ]
> t<- fit.variogram(v,vgm(0.0437, "Exp", 26, 0))
> cv69<- krige.cv(tsport_ace ~ 1, x2, t, nfold = nrow(x2))
> The last line gives an error saying:
> Error in SpatialPointsDataFrame(coordinates(data),
> data.frame(matrix(as.numeric(NA),  :
>    row.names of data and coords do not match
> I don't know what is wrong. The x2 data is a SpatialPointsdataframe that is why
> i did not specify the location (as it will take it from the data). Here is the
> usage of the function krige.cv:
> krige.cv(formula, locations, data, model = NULL, beta = NULL, nmax = Inf,
>          nmin = 0, maxdist = Inf, nfold = nrow(data), verbose = TRUE, ...)
> I hope you can help me on this. Thanks a lot.
> Best regards,
> Pearl
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list