[R-sig-Geo] using gwr for interpolation

Roger Bivand Roger.Bivand at nhh.no
Fri May 29 13:24:27 CEST 2009


On Fri, 29 May 2009, Edzer Pebesma wrote:

> Can I use gwr for interpolation?
>
> I would for example use something like
>
> library(spgwr)
> data(meuse)
> coordinates(meuse) = ~x+y
> data(meuse.grid)
> gridded(meuse.grid) = ~x+y
> x = gwr(cadmium ~ dist, meuse, bandwidth = 228, fit.points = meuse.grid)
> spplot(x$SDF["gwr.e"])

Since GWR was created to look at *coefficient* variability, prediction 
isn't a natural, and fit.points are assumed just to be points, not points 
with attributes; there is nothing in Forthingham et al. (2002) about 
prediction. So:

spplot(x$SDF, "dist")

>
> But it doesn't give what I'd expected - somehow nicely interpolated
> cadmium values. I probably misused fit.points, but I couldn't see any
> predict method. Is this possible at all?
>

fortune("Yoda")
gwrcoefs <- as.matrix(as(x$SDF, "data.frame")[,2:3])
X <- model.matrix( ~ dist, meuse.grid)
meuse.grid$pred <- apply(gwrcoefs * X, 1, sum)
spplot(meuse.grid, "pred")

It could be written into gwr(), or as a predict() method, but that might 
require changes in the gwr object to make sure that the predicted 
attribute values were properly keyed to the fit point locations. To get 
standard errors, you'd need to store more of the objects returned by 
lm.wfit() for each fit point, which could be done, but should it?

Hope this helps,

Roger
>

-- 
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