[R-sig-Geo] R: R: R: R: Spatial Durbin Model with regimes in a cross section framework

Roger Bivand Roger.Bivand at nhh.no
Wed Oct 21 18:55:40 CEST 2015


On Wed, 21 Oct 2015, Loredana Mirra wrote:

> I will try to install and use R and Spdep on another pc with another OS

A Windows binary of the development version is at:

http://win-builder.r-project.org/rIKm3X2H8hCW

which should work (install from local zip file after downloading) on 
Windows 10.

Roger


> Loredana
>
> -----Messaggio originale-----
> Da: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> Inviato: mercoledì 21 ottobre 2015 15:26
> A: Loredana Mirra
> Cc: r-sig-geo at r-project.org
> Oggetto: Re: R: R: R: [R-sig-Geo] Spatial Durbin Model with regimes in a
> cross section framework
>
> On Wed, 21 Oct 2015, Loredana Mirra wrote:
>
>> Thanks Roger,
>> At least you managed to have an output even if it contains some issues
>> which I could address changing variables.
>> Instead sorry but I am stuck. How can I get that?
>
> library(spdep)
> sessionInfo() # spdep >=0.5-88
> load("chow_error.RData")
> ONE <- rep(1, nrow(highways))
> NOC_Nord <- as.integer(!highways$C_Nord) durb<-lagsarlm(GR5101m~ 0+
> (ONE+LVAPC51):(C_Nord+NOC_Nord),
>  data=highways, listw, type="mixed")
> summary(durb)
>
> works for me (I'm using the development version of spdep, which seems to be
> the reason for the difference). There was an indexing error in
> create_WX() that is corrected in the development version but not in 0.5-88
> on CRAN. Which OS are you using - there are reasons for not releasing the
> development version yet?
>
> Roger
>
>> Loredana
>>
>>
>> -----Messaggio originale-----
>> Da: Roger Bivand [mailto:Roger.Bivand at nhh.no]
>> Inviato: mercoledì 21 ottobre 2015 14:19
>> A: Loredana Mirra
>> Cc: r-sig-geo at r-project.org
>> Oggetto: Re: R: R: [R-sig-Geo] Spatial Durbin Model with regimes in a
>> cross section framework
>>
>> On Wed, 21 Oct 2015, Loredana Mirra wrote:
>>
>>> Here the traceback()
>>> 4: stop("0 (non-NA) cases")
>>> 3: lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...)
>>> 2: lm(y ~ x - 1)
>>> 1: lagsarlm(GR5101m ~ 0 + (ONE + LVAPC51):(C_Nord + NOC_Nord), data =
>>> highwaysreg,
>>>       listw, type = "mixed")
>>>
>>> No, problem. Data are not private. I tried to use the lmSLX and I got
>>> the same error
>>
>> OK, thanks. I cannot reproduce your error as such - I'm constructing:
>>
>> ONE <- rep(1, nrow(highways))
>> NOC_Nord <- as.integer(!highways$C_Nord)
>>
>> which may not be correct. I'm seeing:
>>
>> Warning message:
>> In lagsarlm(GR5101m ~ 0 + I(factor(C_Nord))/(LVAPC51), data = highways,  :
>>   inversion of asymptotic covariance matrix failed for tol.solve = 1e-10
>>   reciprocal condition number = 6.6223e-12 - using numerical Hessian.
>>
>> and an issue in an interaction term between the NOC_Nord term and the
>> intercept:
>>
>> Coefficients: (numerical Hessian approximate standard errors)
>>     (1 not defined because of singularities)
>>                        Estimate Std. Error  z value Pr(>|z|)
>> ONE:C_Nord            0.1385889  0.1310782   1.0573   0.2904
>> ONE:NOC_Nord          0.1493507  0.1322529   1.1293   0.2588
>> LVAPC51:C_Nord       -0.0170657  0.0010275 -16.6083   <2e-16
>> LVAPC51:NOC_Nord     -0.0192602  0.0018370 -10.4845   <2e-16
>> lag.ONE:C_Nord        0.0195317  0.1159969   0.1684   0.8663
>> lag.ONE:NOC_Nord             NA         NA       NA       NA
>> lag.LVAPC51:C_Nord   -0.0034108  0.0086611  -0.3938   0.6937
>> lag.LVAPC51:NOC_Nord -0.0032861  0.0223143  -0.1473   0.8829
>>
>> Rho: 0.57171, LR test value: 1.8528, p-value: 0.17346 Approximate
>> (numerical
>> Hessian) standard error: 0.34917
>>     z-value: 1.6374, p-value: 0.10156
>> Wald statistic: 2.6809, p-value: 0.10156
>>
>> Roger
>>
>>
>>> This is the link to the file with errors
>>> https://onedrive.live.com/redir?resid=4484D82DD190F118!2202&authkey=!
>>> A
>>> EXvKmB
>>> o2FVgrQI&ithint=file%2cRData
>>>
>>> Thank you
>>>
>>> Loredana
>>>
>>>
>>>
>>> -----Messaggio originale-----
>>> Da: Roger Bivand [mailto:Roger.Bivand at nhh.no]
>>> Inviato: mercoledì 21 ottobre 2015 13:26
>>> A: Loredana Mirra
>>> Cc: r-sig-geo at r-project.org
>>> Oggetto: Re: R: [R-sig-Geo] Spatial Durbin Model with regimes in a
>>> cross section framework
>>>
>>> On Wed, 21 Oct 2015, Loredana Mirra wrote:
>>>
>>>> Hi, and thank you again for your help. Following Anselin (2007)
>>>> Spatial regression analysis in R  I managed to test for the presence
>>>> of spatial regimes (also performing a Chow test) in R.
>>>>
>>>> Since, I need to apply a Spatial Durbin model, I tried fitting it
>>>> using the following (just adding the option "mixed") to the sar
>>>> command in the cases of regimes (Centre_North and South in my case):
>>>>
>>>> durb<-lagsarlm(GR5101m~ 0+ (ONE+
>>>> LVAPC51):(C_Nord+NOC_Nord),data=highways,listw, type="mixed")
>>>> summary(durb)
>>>>
>>>> I always get this error
>>>> error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
>>>>  0 (non-NA) cases
>>>
>>> Please provide the output of traceback() after the error has occurred.
>>> I think that if the same model can be fitted with type="lag", but not
>>> with "mixed", then the lagged X variables are possibly to blame.
>>>
>>> Maybe also try to use lmSLX() on the same formula, data and listw
>>> objects, to see whether you also see failures in the lagged X
>>> variables. The underlying create_WX() function does check for NAs,
>>> but may not do it correctly - possibly for this formula.
>>>
>>> If this sounds hard, do:
>>>
>>> save(highways, listw, file="chow_error.RData")
>>>
>>> and make the "chow_error.RData" file available on a link (possibly
>>> off-list if the data are private).
>>>
>>> Hope this helps,
>>>
>>> Roger
>>>
>>>>
>>>> I checked if there were NA cases and tried with other variables or
>>>> weight matrices. I wonder if this is a good approach or what is wrong.
>>>>
>>>> Thank you for your attention
>>>> Loredana Mirra
>>>>
>>>>
>>>>
>>>>
>>>> -----Messaggio originale-----
>>>> Da: Roger Bivand [mailto:Roger.Bivand at nhh.no]
>>>> Inviato: venerdì 2 ottobre 2015 10:59
>>>> A: Loredana Mirra
>>>> Cc: r-sig-geo at r-project.org
>>>> Oggetto: Re:[R-sig-Geo] Spatial Durbin Model with regimes in a cross
>>>> section framework
>>>>
>>>> On Fri, 2 Oct 2015, Loredana Mirra wrote:
>>>>
>>>>>
>>>>> Thank you very much for your kind help. Yes, I should check also
>>>>> if, after having estimated separated coefficients,  the difference,
>>>>> if any, is statistically significant (using a chow test).
>>>>> Implementing such test is the major issue to me. Can you give me an
> hint about this?
>>>>
>>>> Please see ch. 4 in Kleiber and Zeilis (2008) Applied Econometrics
>>>> with
>> R.
>>>> You may use anova() on the no-regime model and the regime model,
>>>> which is equivalent to a Chow test (personal communication, Achim
>>>> Zeileis,
>>> 2005).
>>>> It will however suffer from misspecification such as outliers,
>>>> discussed in section 4.3 and the use of a Wald test with an HC
>>>> covariance
>>> matrix.
>>>>
>>>>> Thanks also for the suggestion about the interpretation of output
>>>>> in
>> SDM.
>>>>
>>>> A "Chow" test might go through a Likelihood Ratio test, but should
>>>> arguably be presented using the empirical distributions of the
>>>> impacts for each X variable for the no-regime model and for each regime.
>>>>
>>>> Hope this helps,
>>>>
>>>> Roger
>>>>
>>>>> Best Regards
>>>>> Loredana
>>>>> -----Messaggio originale-----
>>>>> Da: Roger Bivand [mailto:Roger.Bivand at nhh.no]
>>>>> Inviato: giovedì 1 ottobre 2015 20:45
>>>>> A: Loredana Mirra
>>>>> Cc: r-sig-geo at r-project.org
>>>>> Oggetto: Re: [R-sig-Geo] Spatial Durbin Model with regimes in a
>>>>> cross section framework
>>>>>
>>>>> On Thu, 1 Oct 2015, Loredana Mirra wrote:
>>>>>
>>>>>> I am writing to ask you a suggestion about the availability of a R
>>>>>> routine or piece of program for the purposes of my empirical analysis.
>>>>>> I should revise my paper using a Spatial Durbin model. This was
>>>>>> recommended in order to mitigate a problem due to the possible
>>>>>> presence of
>>>>> unobserved factors.
>>>>>>
>>>>>> Unfortunately data do not permit to perform a panel but a cross
>>>>>> section analysis. I do not have troubles to perform a Spatial
>>>>>> Durbin Model on the entire sample, but I need to study the
>>>>>> presence of Spatial Regimes. The problem is that I cannot find a
>>>>>> program, in a cross sections framework. Do you know if there is a
>>>>>> program available in R
>>>>> to perform this analysis?
>>>>>
>>>>> How do you want to handle the "regimes"? Estimate separate
>>>>> coefficients for each regime (regime defined as a factor)? If so,
>>>>> this is a standard formula construction, and can be used with
>>>>> formula objects in model fitting
>>>>> functions:
>>>>>
>>>>> lm(mpg ~ 0 + I(factor(am))/(disp + wt), data=mtcars)
>>>>>
>>>>> or similar - check in detailed discussions of formula objects.
>>>>>
>>>>> You need to be careful to report impacts, not coefficient values,
>>>>> from the Spatial Durbin model.
>>>>>
>>>>> Hope this helps,
>>>>>
>>>>> Roger
>>>>>
>>>>>> Thank you very much in advance for your help.
>>>>>>
>>>>>> Best regards
>>>>>>
>>>>>> Loredana Mirra
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -------------------------
>>>>>>
>>>>>>
>>>>>>
>>>>>> Dott.ssa  Loredana Mirra
>>>>>>
>>>>>> Universit??? di Roma ???Tor Vergata???
>>>>>>
>>>>>> Dipartimento di Economia Diritto e Istituzioni
>>>>>>
>>>>>> Via Columbia, 2
>>>>>>
>>>>>> 00133 Roma
>>>>>>
>>>>>> Italia
>>>>>>
>>>>>> tel. +390672595725
>>>>>>
>>>>>> <mailto:pozzolo at unimol.it> loredana.mirra at uniroma2.it
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ---
>>>>>> Questa e-mail ??? stata controllata per individuare virus con
>>>>>> Avast
>>>>> antivirus.
>>>>>> https://www.avast.com/antivirus
>>>>>>
>>>>>> 	[[alternative HTML version deleted]]
>>>>>>
>>>>>>
>>>>>
>>>>> --
>>>>> Roger Bivand
>>>>> Department of Economics, Norwegian School of Economics, Helleveien
>>>>> 30,
>>>>> N-5045 Bergen, Norway.
>>>>> voice: +47 55 95 93 55; fax +47 55 95 91 00
>>>>> e-mail: Roger.Bivand at nhh.no
>>>>>
>>>>>
>>>>> ---
>>>>> Questa e-mail è stata controllata per individuare virus con Avast
>>>> antivirus.
>>>>> https://www.avast.com/antivirus
>>>>>
>>>>>
>>>>
>>>> --
>>>> Roger Bivand
>>>> Department of Economics, Norwegian School of Economics, Helleveien
>>>> 30,
>>>> N-5045 Bergen, Norway.
>>>> voice: +47 55 95 93 55; fax +47 55 95 91 00
>>>> e-mail: Roger.Bivand at nhh.no
>>>>
>>>>
>>>> ---
>>>> Questa e-mail è stata controllata per individuare virus con Avast
>>> antivirus.
>>>> https://www.avast.com/antivirus
>>>>
>>>>
>>>
>>> --
>>> Roger Bivand
>>> Department of Economics, Norwegian School of Economics, Helleveien
>>> 30,
>>> N-5045 Bergen, Norway.
>>> voice: +47 55 95 93 55; fax +47 55 95 91 00
>>> e-mail: Roger.Bivand at nhh.no
>>>
>>>
>>> ---
>>> Questa e-mail è stata controllata per individuare virus con Avast
>> antivirus.
>>> https://www.avast.com/antivirus
>>>
>>>
>>
>> --
>> Roger Bivand
>> Department of Economics, Norwegian School of Economics, Helleveien 30,
>> N-5045 Bergen, Norway.
>> voice: +47 55 95 93 55; fax +47 55 95 91 00
>> e-mail: Roger.Bivand at nhh.no
>>
>>
>> ---
>> Questa e-mail è stata controllata per individuare virus con Avast
> antivirus.
>> https://www.avast.com/antivirus
>>
>>
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics, Helleveien 30,
> N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 91 00
> e-mail: Roger.Bivand at nhh.no
>
>
> ---
> Questa e-mail è stata controllata per individuare virus con Avast antivirus.
> https://www.avast.com/antivirus
>
>

-- 
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list