[R-sig-Geo] Universal Kriging with factor covariate

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Feb 10 15:45:06 CET 2011



On 02/10/2011 03:28 PM, piero campa wrote:
> 
> Ok sure.
> I will hereby simulate the interpolation of a target variable "points"
> (whose data is attached) via a single factor predictor "classes" created
> randomly over the region of interest:
> 
> # libraries
> library(sp)
> library(gstat)
> library(automap)
> 
> # Import the point pattern from the txt file and turn it to Spatial
> # (set properly the path variable)
> points <- read.table(path, header=TRUE)
> coordinates(points)<- ~ LON+LAT
> 
> # Create grid enclosing the points and fill it with random factor data 
> grid <- GridTopology(c(9,43.5), c(.1,.1), c(40, 20))
> SPgrid <- SpatialGridDataFrame(grid, data.frame(classes=round(runif(40*20,
> 1, 10))))
> SPgrid$classes <- as.factor(SPgrid$classes)
> 
> # Overlay the factor covariate onto the points
> ov <- overlay(SPgrid, points)
> points$CL <- ov$classes
> 
> # Create the linear regression model
> lm <- lm(pm10 ~ CL, points)
> summary(lm)
> 
> # Fit the variogram of the residuals
> rvar <- autofitVariogram(residuals(lm) ~ 1, points)
> 
> # Regression Kriging
> pm10.rk <- krige(lm$call$formula, points, SPgrid, rvar)
> --> HERE I HAVE ERROR:
> Error in function (classes, fdef, mtable)  : 
>   unable to find an inherited method for function "krige", for signature
> "call", "SpatialPointsDataFrame"

You wrongly assumed that lm$call$formula is a formula. Try:

krige(as.formula(lm$call$formula), points, #etc

or simply:

krige(pm10 ~ CL, points, ...

Hth,

> 
> Hope this helps getting closer to the problem,
> Piero
> 
> http://r-sig-geo.2731867.n2.nabble.com/file/n6011444/2009-045.ARPA.txt
> 2009-045.ARPA.txt 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763  http://ifgi.uni-muenster.de
http://www.52north.org/geostatistics      e.pebesma at wwu.de



More information about the R-sig-Geo mailing list