Skip to content

Geographically weighted regression

4 messages · Roger Bivand, i-c-b m@iii@g oii web@de

#
On Sat, 23 Feb 2019, f-c-b at web.de wrote:

            
I see:
+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,
+ fit.points=Daten10, predictions=TRUE)
Warning message:
In gwr(formula = Ziel ~ Var1 + Var3 + Var4, data = Daten90, bandwidth = 
bwG,  :
   standard errors set to NA, normalised RSS not available

but using your gwrG object and:
+ bandwidth = bwG, gweight = gwr.Gauss,hatmatrix = TRUE,
+ fit.points=Daten10, predictions=TRUE, fittedGWRobject=gwrG)

I think the model matrix handling of the factor is OK. The problem in the 
GWmodel::gwr.predict() approach is that the full model matrix approach is 
used on the formula and data arguments, but not on predictdata, which is 
coerced to data frame but never regularised by going through model.matrix, 
hence the error message:

Browse[2]>
debug: if (any((inde_vars %in% names(predictdata)) == F)) stop("All the 
independent variables should be included in the predictdata")
Browse[2]> inde_vars
[1] "Var12006" "Var12007" "Var12008" "Var12009" "Var3"     "Var4"
Browse[2]> names(predictdata)
  [1] "OBJECTID"   "Rechtswert" "Hochwert"   "Var1"       "Var2"
  [6] "Var3"       "Ziel"       "Var4"       "coords.x1"  "coords.x2"

Had the proper approach been used, the names would have been the same.

The relevant part of spgwr::gwr() in R/gwr.R is:

 	if (predictions) {
             t1 <- try(slot(fit.points, "data"), silent=TRUE)
 	    if (class(t1) == "try-error")
 			stop("No data slot in fit.points")
             predx <- try(model.matrix(delete.response(mt), fit.points))
             if (class(predx) == "try-error")
 			stop("missing RHS variable in fit.points")
             if (ncol(predx) != ncol(x))
 			stop("new data matrix columns mismatch")
         }

(lines 71-80)

which uses model.matrix() and uses try() to catch mis-matches.

Hope this helps,

Roger

  
    
#
On Sun, 24 Feb 2019, f-c-b at web.de wrote:

            
I am not looking over your shoulder. Always provide the code verbatim, if 
I guess which mess you are in, I may get the wrong mess.

Generally, I advise against GWR in all settings, it should only ever be 
used for exploring data for non-stationarity.

Roger