[R-sig-Geo] GWR Analysis

Roger Bivand Roger.Bivand at nhh.no
Tue Jun 22 11:58:25 CEST 2010


On Tue, 22 Jun 2010, Pinar Aslantas Bostan wrote:

> Dear Roger,
>
> Thank you for your mail. I tried lm() and it doesn't resulted with negative 
> values. Also gwr() doesn't give negative values if I don't use fit.points.

OK. What this means then is that for fit.points some local coefficients 
with your chosen adaptive proportion and chosen kernel, and with the 
values of Z, V1, and V2 (are V1 and V2 coordinates - is a GW trend model a 
good idea?) are driving the predictions negative. Could you try this with 
different adaptive proportion values to see whether the predictions stay 
non-negative? Are the relationships between PREC and Z, V1, and V2 really 
linear? Can you fit a gam() and look at the linearity of the fits? Would 
taking log(PREC) help with the linearity (as well as with bounding the 
model)? Do you have any resource persons at your university? Do you have 
access to Chris Lloyd's nice 2006 book on local models:

http://www.crcpress.com/product/isbn/0415316812

Hope this helps,

Roger

>
>> bw1=gwr.sel(PREC~Z+V1+V2,station,adapt=T)
>> xx1<-gwr(PREC~Z+V1+V2,station,adapt=bw1,se.fit=T,hatmatrix=TRUE)
>> gwrx<-xx1$SDF
>> min(gwrx$pred)
> [1] 311.189
>> max(gwrx$pred)
> [1] 1700.559
>
> But if I use fit.points to predict precipitation on a grid, then it gave 
> negative values.
>
>> x1 <-gwr(PREC~Z+V1+V2,station,adapt=bw1, fit.points = dem, predict=T, 
>> se.fit=T, fittedGWRobject=xx1)
>> gwrres<-x1$SDF
>> min(gwrres$pred)
> [1] -1126.052
>> max(gwrres$pred)
> [1] 2104.136
>
> You mentioned about limiting the design of the model, so that it doesn't give 
> negative values. Do you have any idea about that, how can I perform this?
>
> Best regards,
> Pinar
>
>
>
>
> Alinti Roger Bivand <Roger.Bivand at nhh.no>
>
>> On Mon, 21 Jun 2010, Pinar Aslantas Bostan wrote:
>> 
>>> Dear Roger,
>>> 
>>> Maybe you can remember, last week I asked some questions about gwr 
>>> analysis and you helped me. In order to make refresh, I want to summarize 
>>> my problem. I am trying to make gwr analysis to predict precipitation 
>>> distribution on a DEM. I have two datasets; first one is 'station' 
>>> consists of 225 prec. measurements and 3 independent variables (Z, V1, 
>>> V2). The second one is 'DEM' dataset which has 31203 # of pixels. Firstly 
>>> I tried with using SPDF (SpatialPointsDataFrame) and obtained predicted 
>>> precipitations on DEM. But when I plot the predicted precipitation values, 
>>> I saw a lot of negative values which is impossible to get such a values.
>> 
>> No, this is just a weighted linear model. Unless you limit it by design, 
>> all such linear models will happily predict out of domain. Consider how you 
>> might by design limit the response to non-negative values.
>> 
>>> I thought that this was caused because I used point data sets (SPDF) for 
>>> grid.
>> 
>> Why would you think that? All you need to provoke this is a slightly 
>> unfortunate placing of the met stations (all in west and falling trend 
>> eastwards beyond the observed stations). Did the regular lm() fit also 
>> predict negative values (very likely yes).
>> 
>> This isn't a GWR problem, it's more general. Fix it for lm() first.
>> 
>> Roger
>> 
>>> Then I tried with using SGDF (SpatialGridDataFrame). At this time, gwr() 
>>> resulted with an error message "new data matrix rows mismatch". You told 
>>> me that 'The error message is generated when the number of columns in the 
>>> matrix of X variables is not the same in data and and fit.points.' I gave 
>>> some information about datasets below.
>>> 
>>>> class(station)
>>> [1] "SpatialPointsDataFrame"
>>> attr(,"package")
>>> [1] "sp"
>>>> names(station)
>>> [1] "PREC" "Z"    "V1"   "V2"
>>>> class(dem)
>>> [1] "SpatialGridDataFrame"
>>> attr(,"package")
>>> [1] "sp"
>>>> names(dem)
>>> [1] "Z"  "V1" "V2"
>>> 
>>> 'PREC' is the observations and I want to get predictions of them on 'dem'.
>>> 
>>> I checked the str() and variables are stored in the same way.
>>> 
>>>> bw=gwr.sel(PREC~Z+V1+V2,data=station,adapt=T)
>>>> xx1<-gwr(PREC~Z+V1+V2,station,adapt=bw,hatmatrix=TRUE)
>>>> x1 <-gwr(PREC~Z+V1+V2,data=station,adapt=bw, fit.points = dem, predict=T, 
>>>> se.fit=T, fittedGWRobject=xx1)
>>> Error in gwr(PREC ~ Z + V1 + V2, data = station, adapt = bw, fit.points = 
>>> dem,  :
>>> new data matrix rows mismatch
>>> 
>>> 
>>> If I wrote 'predict=F' then gwr() works but gives only sum.w, coefficients 
>>> and localR2.
>>> 
>>> I tried to run gwr() under debug but I didn't understand the output.
>>> 
>>> I really don't understand the problem and need help.
>>> 
>>> Best regards,
>>> Pinar
>>> 
>>> 
>>> ----------------------------------------------------------------
>>> This message was sent using IMP, the Internet Messaging Program.
>>> 
>>> 
>> 
>> -- 
>> 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
>> 
>> 
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>

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