[R-sig-Geo] RE : grid error for kriging

Roger Bivand Roger.Bivand at nhh.no
Mon Nov 9 15:45:50 CET 2009


On Mon, 9 Nov 2009, Tobin Cara wrote:

> Dear Roger,
>
> My Prec00 is a data frame as I imported it as a matrix from a text file. 
> It has 32 rows (one for each precipitation station) and 72 columns (72 
> hours of data at each station). I interpolated by importing a second 
> matrix with just the X, Y, and Z of the original data and iterated for 
> each column. I had no problem doing this when I used a simpler grid 
> (data_v) with more X, Y and Z values, imported as a text file(not a 
> spatial DTM).
>
> list_ked <- vector("list",72)
>
> for(i in 1:72){
> list_ked[[i]] <- krige(Prec00[,i]~Z, locations=DataCoord, newdata=data_v, model = fitted_vario)
> }
>
> My successful KED code without iterating with the DTM 'elev' (where I 
> used the mean of Prec00 over 72 hours) was:
>
> elev_ked <- krige(meanPrec~Z, meanPrec, newdata=elev, fitted_vario)
>
> The difference in the data frame for the mean is I have the X, Y, and Z 
> associated with each meanPrec value at each station in the same matrix 
> (32 rows by 4 cols: X, Y, Z, meanPrec).
>
> So, when mixing a spatial data frame 'elev' with 2 matrices defining the 
> original data, there seems to be a problem. Calling Prec00 gives me only 
> the precipitation for a time step because its a separate matrix from the 
> coordinates.

Did you check the class of Prec00? If it wasn't a SpatialGridDataFrame, it 
wouldn't have given you that error message. Please do use class() and 
str() to check (and double-check) the class of objects. You may believe 
that it is a data.frame, but that doesn't seem likely.

You didn't provide the output of traceback() following the original error. 
It helps a lot in disentangling the causes of an apparent 
misunderstanding. The newdata= argument could also be the source of the 
problem. You would be well advised to use gstat() and predict() instead of 
krige(), then you see which step is problematic. Setting things up with a 
single input Spatial*DataFrame as the data= argument (not locations=), and 
a single Spatial*DataFrame as the newdata= argument in predict() is also 
preferable, because then the data and their locations are kept together.

Simplify first, please. The error you reported came from wrong syntax in 
subsetting a SpatialGridDataFrame, whatever you may have intended.

Roger


>
> Any ideas?
>
> Cheers
>
> ________________________________________
> De : Roger Bivand [Roger.Bivand at nhh.no]
> Date d'envoi : lundi, 9. novembre 2009 12:27
> À : Tobin Cara
> Cc : r-sig-geo at stat.math.ethz.ch
> Objet : Re: [R-sig-Geo] grid error for kriging
>
> On Mon, 9 Nov 2009, Tobin Cara wrote:
>
>> Hello,
>>
>> Has anyone ever used a DTM as their grid for interpolation and come
>> across this error. My DTM has pixels 100 m by 100 m, so I really do not
>> understand this error as it is regular. Also, this only happens when I
>> am doing multiple iterations in time.
>>
>>
>>
>> Code:
>> list_ked[[i]] <- krige(Prec00[,i]~Zloc, locations=DataCoord, newdata=elev, model = fitted_vario)
>> [using universal kriging]
>>
>
> Please do check the arguments to the formula carefully. If Prec00 is a
> SpatialGridDataFrame, you are not asking for it's i'th variable here. It's
> a design decision that you need Prec00[,,i] to get the variable, or get it
> by name:
>
> library(sp)
> data(meuse.grid)
> coordinates(meuse.grid) <- c("x", "y")
> str(meuse.grid[,1])
> gridded(meuse.grid) <- TRUE
> str(meuse.grid[,1])
> fullgrid(meuse.grid) <- TRUE
> str(meuse.grid[,1])
> str(meuse.grid[,,1])
>
> Maybe helping some users to subset by row and column has removed the
> otherwise prevalent semantic link to data.frame objects, and maybe this
> (tricky) side of the "[" operator on SpatialGridDataFrame objects should
> be reversed?
>
> Roger
>
>>
>>
>> Error:
>> suggested tolerance minimum: 0.25
>> Error in points2grid(points, tolerance, round, fuzz.tol) :
>> dimension 1 : coordinate intervals are not constant
>>
>>
>> I can rescale the DTM to be less refined (now it is 100 m2 for a 6,000
>> km2 area) if needed.
>>
>> Thank you again,
>>
>> Cara
>>
>>
>>
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
> --
> Roger Bivand
> Economic Geography Section, Department of Economics, Norwegian School of
> Economics and Business Administration, Helleveien 30, N-5045 Bergen,
> Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand at nhh.no

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list