[R] question about krige code in R

Roger Bivand Roger.Bivand at nhh.no
Thu Jul 31 18:20:22 CEST 2008


Alessandro <alessandro.montaghi <at> unifi.it> writes:

> 
> Hi All,
> 
> I have this question. I wish to create a kriging map with R but I haven't a
> auxiliary map. I have only one txt file with X, Y and Z records. 
> 
> When I use this code: 
> 
...
> subground.ok <- krige (Z~sqrt(X+Y), subground, subground.ovgm, nmax=40) *
> 
> *[the original code is elevations.ok = krige(Z~1, elevations, dem,
> elevations.ovgm, nmax=80) ]

Three points:

1) you are copying someone's template code, but don't say where you found it,
which makes repairing it hard; by guesswork, this is krige() in the gstat 
package, and by Google, probably a template from RSAGA used out of context 
and without reading up the function help pages - recommended!

2) you have fallen into the trap of hoping that the function will know what 
you mean my magic - your arguments are passed by position order, not by name,
so the third argument subground.ovgm is assumed to be the newdata= value, but 
is the model= value. If you had given all (or at least from the third) 
arguments names, krige() would know better what you wanted, which was to
make kriging predictions with the given model at the data locations, right?

Moral, use names for arguments where they help remove ambiguity!

3) If you had split things out into a gstat() step, and a predict.gstat() 
step, you might have seen what was going on. Even then, kriging is usually
used for prediction for unknown locations, so it simply will not work without
a newdata= argument giving the interpolation coordinates and values of your 
variables X and Y. 

Roger

PS. The R-sig-geo list is probably better suited to this kind of question.

> 
> when I use this one there is this message (with my data setting), because I
> have only txt file and I haven't a DEM ascii file: 
> 
> "Error in proj4string(newdata) :  proj4string only works for class(es
> extending) Spatial." 
> 
> Is it possible use only one file with krige?
> 
> Thank you
> 
> Ale
>



More information about the R-help mailing list