[R-sig-Geo] Regression kriging - error not found when ordinary kriging

Ashton Shortridge ashton at msu.edu
Mon Nov 18 14:40:06 CET 2013


Hi Jordan,

I always use the 'data' parameter when kriging. Here's how I'd do it:

class(bd)   # This should be a SpatialPointsDataFrame
names(bd) #  all the variables in the model (Total, m5005CVOL, etc)

class(blank) # This should be a SpatialPointsDataFrame
names(blank) # all the variables in the model except for Total

TotalRegKrige <- krige(Total~m5005CVOL+n50010CVOL+n50015CVOL+DTM, bd, blank, 
model=fit_r)


Hope this helps.

Ashton



On Friday, November 15, 2013 10:10:30 AM Jordan Chetcuti wrote:
> Hello, I was wondering if anyone has encountered this issue?
> 
> 
> This line works:
>                       TotalKrige <- krige(Total~1, locations=bd,
> newdata=blank, model=fit_Total)
> 
> This line does not:
>                      TotalRegKrige <-
> krige(Total~m5005CVOL+n50010CVOL+n50015CVOL+DTM, locations=bd,
> newdata=blank, model=fit_r)
> 
> Message:
>                      Error in eval(expr, envir, enclos) : object
> 'm5005CVOL' not found
> 
> I have emailed the author of the library "gstat", he very helpfully
> offered some advice and that I post here. I have also included my
> intial email exchange with Prof. Pebesma.
> 
> I have included a description of my two datsets below and the
> libraries I have loaded.
> 
> data = locations (therefore it isn't necessary to have "data"
> specified (in the way it is in a linear model lm() )
> newdata = the locations to krige
> 
> I have also tried among other things:
> 
> TotalRegKrige <-
> krige(Total~bd$m5005CVOL+bd$n50010CVOL+bd$n50015CVOL+bd$DTM,
> locations=bd, newdata=blank, model=fit_r)
> 
> Giveing:
> 
> Error in gstat.formula.predict(d$formula, newdata, na.action = na.action,  :
> NROW(locs) != NROW(X): this should not occur
> In addition: Warning messages:
> 1: 'newdata' had 26026 rows but variables found have 83 rows
> 2: 'newdata' had 26026 rows but variables found have 83 rows
> 
> This would lead me to think there is an error in the ascii grid,
> except that it worked perfectly in the ordinary kriging example.
> 
> Any help anyone can give would be greatly appreciated.
> 
> Regards
> 
> Jordan Chetcuti
> 
> p.s. see descriptions of data and libraries below, and conversation
> with Prof. Pebesma.
> 
> 
> Dataset "bd"
> 
> > summary(bd)
> 
> Object of class SpatialPointsDataFrame
> Coordinates:
>       min     max
> X  228112  232468
> Y 2190072 2195810
> Is projected: NA
> proj4string : [NA]
> Number of points: 83
> Data attributes:
>    StationID       m1K10CrnR       m1K10TrHT       m1K10CVOL (only
> first few, contains many).
> 
> Dataset "blank"
> 
> > summary(blank)
> 
> Object of class SpatialGridDataFrame
> Coordinates:
>          min     max
> [1,]  226693  233843
> [2,] 2187940 2197040
> Is projected: NA
> proj4string : [NA]
> Grid attributes:
>   cellcentre.offset cellsize cells.dim
> 1            226718       50       143
> 2           2187965       50       182
> Data attributes:
>    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>       1       1       1       1       1       1
> 
> 
> Libraries
> 1. geoR
> 2. gstat
> 3. sp
> 4. lattice
> 
> >---------- Forwarded message ----------
> >From: Edzer Pebesma <edzer.pebesma at uni-muenster.de>
> >Date: 14 November 2013 21:15
> >Subject: Re: Regression kriging
> >To: Jordan Chetcuti <chetcuti at hawaii.edu>
> >
> >
> >You omitted the error, which is:
> >
> >Error in eval(expr, envir, enclos) : object 'm5005CVOL' not found
> >
> >it means that in "blank", the prediction locations, m5005CVOL is not
> >found (as is true of all other predictors).
> >
> >Please consider posting to r-sig-geo in the future.
> >
> >with best regards,
> >
> >Edzer Pebesma
> >
> >On 11/15/2013 03:30 AM, Jordan Chetcuti wrote:
> >> Dear Prof. Pebesma,
> >> 
> >> My name is Jordan Chetcuti and I am a graduate student at the University
> >> of
> >> Hawaii at Manoa, in the Geography department.
> >> 
> >> I am attempting to do regression kriging on some of my data, but I am
> >> alas
> >> having a bit of a problem with gstat.
> >> 
> >> within my script this line works:
> >> 
> >> TotalKrige <- krige(Total~1, locations=bd, newdata=blank,
> >> model=fit_Total)
> >> 
> >> this does not:
> >> 
> >> TotalRegKrige <- krige(Total~m5005CVOL+n50010CVOL+n50015CVOL+DTM,
> >> locations=bd, newdata=blank, model=fit_r)
> >> 
> >> The problem seems to be in the "newdata" when regression kriging
> >> (replacing
> >> "blank" with "bd" does not cause the error, although it also does not
> >> krige
> >> between the points)
> >> 
> >> I was wondering if you would mind having a very quick look at this for
> >> me?
> >> My hope is that it is something I have simply mistyped. I've spent
> >> considerable time writing vba, vb.net and python scripts and numerous
> >> weeks
> >> working in R recently and I am usually pretty good at de-bugging. Alas at
> >> the moment I can't seem to find a solution.
> >> 
> >> Any help would be greatly received.
> >> 
> >> Sincerely
> >> 
> >> Jordan Chetcuti
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-----
Ashton Shortridge
Associate Professor			ashton at msu.edu
Dept of Geography			http://www.msu.edu/~ashton
235 Geography Building		ph (517) 432-3561
Michigan State University		fx (517) 432-1671



More information about the R-sig-Geo mailing list