[R] Cross validation for Ordinary Kriging

Jon Olav Skoien jon.skoien at jrc.ec.europa.eu
Fri Jan 7 14:05:13 CET 2011


On 1/7/2011 12:40 PM, Jon Olav Skoien wrote:
> Pearl,
>
> 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
> str(x2)
> 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.

Pearl,

It seems the problem was caused by a recent change in sp without 
updating gstat, the maintainer has fixed it and submitted new version of 
gstat to CRAN. So you should be able to use your original script after 
downloading the new version, probably available in a couple of days. In 
the mean time the suggestion above should still work.

Cheers,
Jon

>
> Cheers,
> Jon
>
> BTW, you will usually get more response to questions about spatial 
> data handling using the list r-sig-geo 
> (https://stat.ethz.ch/mailman/listinfo/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.
>
> ______________________________________________
> 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