I am exploring the use of GWmodel to run some GWR regressions. I set it up and tried to run some sample regressions using the gwr.basic function, but ran into the following error,

Error in t(X * W.i) : dims [product 4659] do not match the length of object [0]

This is what I did,

gwr.basic(Y~X+I(X^2), data = spdf,bw = bw.gwr.1, kernel = "gausssian", adaptive = TRUE, F123.test = TRUE)

And here is the summary of my input data set, spdf

    Object of class SpatialPointsDataFrame
              min       max
    Long 95.71586 103.70657
    Lat  40.12491  42.89963
    Is projected: NA 
    proj4string : [NA]
    Number of points: 1553
    Data attributes:
         Y             X    
     Min.   : 51.33   Min.   :100  
     1st Qu.:196.19   1st Qu.:115  
     Median :224.74   Median :123  
     Mean   :216.66   Mean   :123  
     3rd Qu.:245.70   3rd Qu.:131  
     Max.   :346.72   Max.   :150** 

What may be happening?


1 Answer 1


I believe that you need to set the argument "longlat=TRUE". Since your data is in geographic coordinates it is likely that the kernel is being incorrectly defined. You also may want to explicitly specify the data slot "data = spdf@data".

Please use caution with specification of the GWR method in anything other than exploratory analysis of nonstationarity. It is a somewhat suspect method and there are a number of papers that indicate the incorrectness of this method in both type I & II error and severe bias in coefficients. That said, it can be a great exploratory tool, just not an inferential one.

  • Thanks a lot for the quick comment Jeff, can you point me to some of those papers. Also my problem is such that I am trying to learn the relationship between Y and X, but this relationship is general a function of spatial coordinates, I have data from a wide variety of spatial coordinates, what may be a good way to approach this problem? Also on your other note now I do gwr.res <- gwr.basic(Yield~Days+I(Days^2), data = spdf,bw = bw.gwr.1, kernel = "gausssian", adaptive = TRUE, F123.test = TRUE, longlat=T) I still get the same error :( Nov 21, 2014 at 18:34
  • Per my second recommendation, try to specify the @data slot for your data argument. I will add some references to my original post. As far as model options, I would highly recommend a mixed effects model. You can specify a spatially lagged y, an autocovariance/autocorrelation term or a polynomial of [y,x] as the random effect. This will decorrelate the error and reveal the underlying linear relationship. Keep in mind that GWR is specifically a model for second order effects (nonstationarity) and if you are after a first order effect it is quite inappropriate, invariant of its validity. Nov 21, 2014 at 18:44
  • I tried the suggestion and got, Error in gwr.basic(Y ~ X + I(X^2), data = spdf@data, bw = bw.gwr.1, : Given regression data must be Spatial*DataFrame Nov 21, 2014 at 18:54
  • I am not sure if I follow what you are saying, the relationship that Y and X have, I mean the coefficients of say a quadratic curve are functions of space, I think a GWR is one of the most suitable ways? Maybe I am missing something, but if I were to approach the problem I would approach it in a very similar way, I mean to say that an algorithm that gives more weight to the neighboring points, hence building a robust local model, at the same time gives some weight to further off points. What do you think? Nov 21, 2014 at 18:58
  • I would remove the inhibit interpretation of X^2. Often you have to parse a formula when writing a function and perhaps the I() is not being interpreted correctly in the funciton. Nov 21, 2014 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.