[R-sig-Geo] spgwr and predictions for separate spdf dataset
Roger Bivand
Roger.Bivand at nhh.no
Sat Dec 22 18:11:32 CET 2012
On Mon, 10 Dec 2012, Kristin Graves wrote:
> Hello-
> I am pretty new at R so apologize in advance if I am not using the correct
> terminology.
>
> I am running spgwr, analyzing a spatial points data frame of 113 records
> (busall). I have a separate spatial points data frame (9 records, busfill)
> for which I would like to obtain predicted values for the dependent
> variable.
>
> busfill contains all the right hand side variables but does not include the
> dependent variable (k16) at all.
>
> My modeling statement is as follows:
>
> model_gwr<-(k16~c5+c6, data=busall, bandwidth=0.2212, predictions=TRUE,
> fittedGWRobject=busfill)
This is not the correct syntax. I think that what you want is:
model_gwr <- gwr(k16~c5+c6, data=busall, bandwidth=0.2212,
predictions=TRUE, fit.points=busfill)
where you fit the model based on the data including responses in busall to
the busfill points. The help page says:
predictions: default FALSE; if TRUE and no fit points given, return GW
fitted values at data points, if fit points given and are a
Spatial*DataFrame object containing the RHS variables in the
formula, return GW predictions at the fit points
and
fit.points: an object containing the coordinates of fit points; often
an object from package ‘sp’; if missing, the coordinates
given through the data argument object, or the coords
argument are used
If you also want prediction "standard errors", follow the example:
data(meuse)
coordinates(meuse) <- c("x", "y")
meuse$ffreq <- factor(meuse$ffreq)
data(meuse.grid)
coordinates(meuse.grid) <- c("x", "y")
meuse.grid$ffreq <- factor(meuse.grid$ffreq)
gridded(meuse.grid) <- TRUE
xx <- gwr(cadmium ~ dist, meuse, bandwidth = 228, hatmatrix=TRUE)
xx
x <- gwr(cadmium ~ dist, meuse, bandwidth = 228, fit.points =
meuse.grid, predict=TRUE, se.fit=TRUE, fittedGWRobject=xx)
x
spplot(x$SDF, "pred")
spplot(x$SDF, "pred.se")
Hope this helps,
Roger
>
> The model runs without error. But I don't know how to view the newly
> predicted values for k16 for my busfill dataset. Perhaps I have
> mis-specified the model, or perhaps I have set up my input busfill dataset
> incorrectly.
>
> Any help is greatly appreciated.
>
> Thanks,
> Kristin Graves
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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