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:
How to fit the same gwr using gam and bayesx function(the smooth functions of location )
How to control the parameters to be similiar as possible including optimal bandwidth
The mgcv error comes from the factor that you are specifying the "interactions" between the spatial smooth and variables
income
andhousing
. Read?gam.models
for details on usingby
terms. I think for this you needIn 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 withbayesx()
, but it looks like it uses the sames()
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()
andbayesx()
or getting both or one of these comparable with thespgwr()
model?