[R-sig-Geo] categoric and dummy variables

Roger Bivand Roger.Bivand at nhh.no
Tue Jul 20 15:25:51 CEST 2010

On Tue, 20 Jul 2010, Pinar Aslantas Bostan wrote:

> Dear all,
> I am working with gwr function to predict precipitation distribution. I 
> have two datasets; first one is consisted of observation points (225 
> meteorological stations), and the second one is DEM points used to 
> obtain precipitation predictions over it. I am using these functions:

As I wrote when you asked five weeks ago, you need much more clarity in 
what you are doing and why. First try to use lm() to fit the model, and 
predict() from the lm fit and your newdata (dem).

Do look carefully at:


and check that the RHS variables match exactly (same name, same type - 
numerical or factor).

With regard to categorical variables, read up on factors. If you have 
factors, them lm() and gwr() - which uses lm() - will handle them 
correctly, as will the prediction, because dummies are generated 
internally. Read up on how the formula works.

Once this works for lm() and predict(), there is no good reason why it 
shouldn't work for gwr() - although the idea of using GWR for prediction 
does seem unjustified, because you can use local kriging with 
covariates for the same purpose.

Hope this helps,


> bw1=gwr.sel(log10(PREC)~V1+V2+V3+V4+V5+V6,data=station,adapt=T)

> gwr1<-gwr(log10(PREC)~V1+V2+V3+V4+V5+V6,data=station,adapt=bw1,
+ se.fit=T,hatmatrix=TRUE)

> gwr <-gwr(log10(PREC)~V1+V2+V3+V4+V5+V6, data=station, adapt=bw1, 
> fit.points = dem, predict=T, se.fit=T, fittedGWRobject=gwr1)
> From the independent variables, V1, V2 and V3 are continuous and V4, V5 
> and V6 are categorical variables. Categorical variables has 4, 6 and 8 
> classes respectively. Stations and DEM points has coded values for these 
> categorical variables. For example V5 has 6 land use classes.
> My first question is: Can R program understand and analyses that 
> categorical values as codes instead of for ex. magnitude while making 
> gwr analysis?
> My second question is about dummy variables. I converted my categorical 
> variables to dummy variables and then I tried to make gwr. But while 
> using 'fit.points=dem' gwr() gives error. I searched the internet, from 
> some of sources I read that dummy variables are not suitable for gwr 
> analysis. Are there anyone who has idea about using dummy variables in 
> gwr?
> Best regards,
> Pinar
> ----------------------------------------------------------------
> 	[[alternative HTML version deleted]]
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

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