[R-sig-Geo] krige error message: dimensions do not match

Edzer J. Pebesma e.pebesma at geo.uu.nl
Sat Mar 3 21:02:03 CET 2007


Dagmar,

this is hard to tell from here without having something that I can 
reproduce; my first suggestion would be NA's in the values or 
coordinates, but you say it is not. Also hard to read your code: is 
crossvalid a global logical? How can you pass the character vector 
location.xvalid to the function matrix(), the to apply and interpret it 
as indexes? But perhaps I missed it.

Have you looked at gstat.cv and krige.cv in package gstat to do cross 
validation?
--
Edzer

dagmar.mueller at gkss.de wrote:
> Hello, 
>
> I think my question might be related to  karl.sommer's  ( error message 
> rgdal: dimensions do not match, Date: Wed, 5 Jul 2006). 
> Have you found out, why the error message 'dimensions do not match ...' 
> occured? 
>
> I'm trying to write a simple cross validation function, which combines the 
> functionality of xvalid (geoR) to use a subset of data for cross 
> validation with the possibility of nested variogram models from vgm 
> (gstat). 
>
> If I check for dimensions of the data.frames data.out and cv.dat, they 
> have exactly the expected dimensions. Nevertheless krige() returns the 
> error "Fehler: dimensions do not match: locations 373628 and data 163419". 
>
> dim(dat): 186815    4
> dim(cv.dat): 186814    4
> dim(data.out): 1    4
>
> There are no 'NA's or 'NaN's in the data.frame. 
> Does anyone know, why the error occurs? I'm completly at a loss.. 
>
> Yours sincerely, 
> Dagmar Mueller 
>
>
> This is the code (modified xvalid()-code): 
> --------------------------------
> MyCV<-function (dat , model,locations.xvalid = "all",krig.nmax=100) {
>    #some code...
>     if (crossvalid) {
>         cv.f <- function(ndata, ...) {
>             data.out <- dat[ndata, ]
>             cv.dat <- dat[-ndata, ]
>         kr<-krige(res~1,loc=~Lon+Lat,data=cv.dat, newdata=data.out[,1:2], 
> model=model, nmax=krig.nmax)
>  
>             res <- c(data.out, kr$var1.pred, kr$var1.var)
>             return(res)
>         }
>         res <- as.data.frame(t(apply(matrix(locations.xvalid), 1, cv.f)))
>  
>     }
>  
> #some code...
>  
>     return(res)
> }
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>




More information about the R-sig-Geo mailing list