0

I want to compare GWR fittings produced between spgwr and mgcv, but I got a error with gam function of mgcv . Here is a example :

require(spgwr)
require(mgcv)
require(R2BayesX)

data(columbus)
col.bw <- gwr.sel(crime ~ income + housing, data=columbus,verbose=F,
                  coords=cbind(columbus$x, columbus$y))
col.gauss <- gwr(crime ~ income + housing, data=columbus,
                 coords=cbind(columbus$x, columbus$y), 
                 bandwidth=col.bw, hatmatrix=TRUE)

#gwr fitting with Intercept
col.gam<-gam(crime ~s(x,y)+s(x,y)*income+s(x,y)*housing, data=columbus)#mgcv ERROR
b1<-bayesx(crime ~sx(x,y)+sx(x,y)*income+sx(x,y)*housing, data=columbus)#R2Bayesx ERROR

Question:

  1. How to fit the same gwr using gam and bayesx function(the smooth functions of location )

  2. How to control the parameters to be similiar as possible including optimal bandwidth

seifer_08ms
  • 375
  • 5
  • 17

1 Answers1

1

The mgcv error comes from the factor that you are specifying the "interactions" between the spatial smooth and variables income and housing. Read ?gam.models for details on using by terms. I think for this you need

col.gam <- gam(crime ~s(x,y, k = 5) + s(x,y, by = income, k = 5) + 
               s(x,y, by = housing, k = 5), data=columbus)

In this example, as there are only 49 observations, you need to restrict the dimensions of the basis functions, which I do here with k = 5, but you should investigate whether you need to vary these a little, within the constraints of the data.

By the looks of the error from bayesx, you have the same issue of specifying the model incorrectly. I'm not familiar with bayesx(), but it looks like it uses the same s() function as supplied with mgcv, so the model specification should be the same as I show above.

As for 2. can you expand on what you mean here Comparable getween gam() and bayesx() or getting both or one of these comparable with the spgwr() model?

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • Thanks! Actually, I want to discrimimate varing effect about location between all models. Because GWR may perform spurious varying correlations especially in small sample(see P ez, A., S. Farber,D. Wheeler 2011), I want to explore variation of the estimated coefficients by other models under the similiar configuration and to discern the possible relationships. – seifer_08ms Dec 13 '13 at 05:35