# [R-sig-Geo] How to compute the response variable from the GMerrorsar output?

Roger Bivand Roger.Bivand at nhh.no
Wed Apr 13 23:21:05 CEST 2011

```On Wed, 13 Apr 2011, Mihail Rosu wrote:

> Thanks Roger for your quick answer.
>
>
> Now, assuming that lambda is << 1, could I use
> fitted.values from GMErrorsar output to compute the (average)response
> variable?  I think of:
>
> mean(fitted.value) = mean(response -noise) ~= mean(response)
>
> provided that the mean(noise) ~= zero if the mean is computed over more than
> 30 points.
>
> Please be as kind as to advise on that,

For an error model, provided that it is correctly specified, and the
regression coefficients take values that are very similar to the OLS
coefficients (the standard errors may differ), you may do as you would
with OLS. If, however, the model is not well specified, the error SAR
coefficients differ from the OLS coefficients (see the optional Hausman
test in the summary method), indicating that there are missing variables
(or wrong functional forms) correlated with the spatially autocorrelated
error. In that case, you'd need to correct the specification.

Hope this helps,

Roger

>
> Thanks,
>
>
> On Wed, Apr 13, 2011 at 4:44 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
>
>> On Tue, 12 Apr 2011, Mihail Rosu wrote:
>>
>> Dear list,
>>>
>>> I'm using a 3rd party code to (spatially) analyse the dependence of crops
>>> yields (YLD) on soil types (MUSYM).  Consider the model
>>>
>>> model<- YLD ~ MUSYM -1
>>>
>>> The lm() function ouputs as coefficients the average YLD for the various
>>> soils (see below). I'm confused about the interpretation of coefficients
>>> outputed by GMerrorsar(). They are kind of twice smaller than the average
>>> YLD !?!?
>>>
>>
>> Use GM methods with spatial data with great care! Note that the spatial
>> coefficient estimate is outside its range (for your row standardised sptial
>> weights, it should be strictly less than 1). You can try to tune the
>> optimizer used, but in general maximum likelihood is to be prefered. If you
>> use spautolm() or errorsarlm() with method="Matrix", you should get the
>> exact results you need, or try method="MC" or method="Chebyshev" for
>> approximations.
>>
>> Hope this helps,
>>
>> Roger
>>
>>
>>
>>> Please help on "how to compute the predicted YLD from the GMerrorsar()
>>> output". Should I use the "fitted.values" instead of the coefficients?
>>>
>>> much thanks,
>>>
>>>
>>> diagnostics<-lm(model, data)
>>>> summary(diagnostics)
>>>>
>>>
>>> Call:
>>> lm(formula = model, data = data)
>>>
>>> Residuals:
>>>   Min      1Q  Median      3Q     Max
>>> -44.006  -2.489   2.948   7.258  32.591
>>>
>>> Coefficients:
>>>       Estimate Std. Error t value Pr(>|t|)
>>> MUSYMBa  42.1410     0.2279  184.90   <2e-16 ***
>>> MUSYMBe  39.1673     0.3420  114.52   <2e-16 ***
>>> MUSYMBf  19.5921     0.5783   33.88   <2e-16 ***
>>> MUSYMCa  33.1261     0.2935  112.88   <2e-16 ***
>>> MUSYMCh  43.6497     0.1580  276.21   <2e-16 ***
>>> MUSYMCn  41.7622     0.1309  318.98   <2e-16 ***
>>> MUSYMDa  37.1995     0.5189   71.69   <2e-16 ***
>>> MUSYMSb  38.3553     0.2168  176.93   <2e-16 ***
>>> MUSYMTa  44.0064     0.3164  139.10   <2e-16 ***
>>> ---
>>> Signif. codes:  0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1
>>>
>>> Residual standard error: 12.32 on 26679 degrees of freedom
>>> Multiple R-squared: 0.9171,     Adjusted R-squared: 0.917
>>> F-statistic: 3.278e+04 on 9 and 26679 DF,  p-value: < 2.2e-16
>>>
>>>
>>> dW <- dnearneigh(coords, 0, dist)
>>> dlist <- nbdists(dW, coords)
>>> idlist <- lapply(dlist, function(x) 1/x)
>>> W <- nb2listw(dW, glist=idlist, style="W")
>>>
>>> #Performs spatial error process model with empirically determined spatial
>>> weights matrix
>>>
>>> SEM<-GMerrorsar(model,data=data, W, na.action=na.exclude,
>>> zero.policy=TRUE)
>>>
>>> summary(SEM)
>>>>
>>>
>>> Call:GMerrorsar(formula = model, data = data, listw = W, na.action =
>>> na.exclude,     zero.policy = TRUE)
>>>
>>> Residuals:
>>>      Min         1Q     Median         3Q        Max
>>> -46.788453  -2.508823   0.024350   2.486553  37.375018
>>>
>>> Type: GM SAR estimator
>>> Coefficients: (GM standard errors)
>>>       Estimate Std. Error z value  Pr(>|z|)
>>> MUSYMBa  17.7399     2.3552  7.5322 4.996e-14
>>> MUSYMBe  21.8829     2.3987  9.1229 < 2.2e-16
>>> MUSYMBf  16.4898     2.4502  6.7299 1.698e-11
>>> MUSYMCa  21.3378     2.4094  8.8561 < 2.2e-16
>>> MUSYMCh  18.8470     2.3216  8.1182 4.441e-16
>>> MUSYMCn  18.8399     2.3164  8.1332 4.441e-16
>>> MUSYMDa  19.5054     2.4220  8.0533 8.882e-16
>>> MUSYMSb  19.0423     2.3655  8.0501 8.882e-16
>>> MUSYMTa  19.2016     2.3662  8.1150 4.441e-16
>>>
>>> Lambda: 1.0157
>>> Number of observations: 26688
>>> Number of parameters estimated: 11
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>>
>>>
>> --
>> 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
>>
>>
>

--
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

```