[R-sig-Geo] two problems when trying to use "impacts"

Roger Bivand Roger.Bivand at nhh.no
Mon Aug 16 10:02:38 CEST 2010


On Mon, 16 Aug 2010, Malcolm Fairbrother wrote:

> Good evening,
>
> I'm trying to use "impacts" from package spdep, to get the impacts of 
> unit changes in the independent variables, based on a fitted "lagsarlm" 
> model. However, I'm running into two problems:
>
> First, when I call "impacts", I get an error message that my weights are 
> not row-standardised, when in fact they are. I can deal with this 
> problem by coercing obj$listw_style to "W", but I'm wondering why this 
> is happening at all.

You are creating the listw object with mat2listw(). This does not try to 
set the correct style, but assigns "M". To be sure that row 
standardisation is imposed, do:

oxw.listw0 <- mat2listw(as.matrix(oxw))
oxw.listw <- nb2listw(oxw.listw0$neighbours, glist=oxw.listw0$weights,
  style="W")

which also does sanity checks.

>
> Second, when I try to run simulations to generate estimates of the 
> uncertainties for the estimates of the impacts, "impacts" seems not to 
> acknowledge "R", and simply returns the estimates without any 
> uncertainty. Can anyone tell me what I'm doing wrong (i.e., how I can 
> get a series of simulations instead)?

No, please note the difference between the print() and summary() methods 
for objects returned by impacts() methods - see the ?impacts help page, 
and especially the eamples at the foot. You need:

imps <- impacts(lagmod, R=100, listw=oxw.listw)
summary(imps)

possibly with additional arguments to summary(), to have the simulations 
printed.

Hope this helps,

Roger


>
> The code I'm using is below.
>
> Many thanks in advance for any assistance.
>
> - Malcolm
>
>
>> oxw <- oxw/apply(oxw, 1, sum) # this is the weights matrix
>
>> table(apply(oxw, 1, sum)==1, useNA="always") # confirming rows sum to 1
> TRUE <NA>
>  48    0
>
>> oxw.listw <- mat2listw(as.matrix(oxw)) # seems OK
>
>> lagmod <- lagsarlm(ben95 ~ rskpovpc +wage95 + instcoad + ipcfold + teitrend + match, data=ox, listw=oxw.listw, method="eigen", tol.solve=1.0e-11) # seems OK
>
>> impacts(lagmod, listw=oxw.listw)
> Error in impacts.sarlm(lagmod, listw = oxw.listw) :
>  Only row-standardised weights supported
>
>> lagmod$listw_style <- "W" # coercing to a different "style"
>
>> impacts(lagmod, listw=oxw.listw) # results make sense
> Impact measures (lag, exact):
>             Direct     Indirect        Total
> rskpovpc   3.953047   3.81574967   7.76879705
> wage95    -0.027922  -0.02695221  -0.05487421
> instcoad   1.566704   1.51228867   3.07899227
> ipcfold  487.134198 470.21499459 957.34919259
> teitrend   2.654201   2.56201450   5.21621501
> match     -5.894235  -5.68951544 -11.58375015
>
>> impacts(lagmod, R=100, listw=oxw.listw) # doesn't run sims...
> Impact measures (lag, exact):
>             Direct     Indirect        Total
> rskpovpc   3.953047   3.81574967   7.76879705
> wage95    -0.027922  -0.02695221  -0.05487421
> instcoad   1.566704   1.51228867   3.07899227
> ipcfold  487.134198 470.21499459 957.34919259
> teitrend   2.654201   2.56201450   5.21621501
> match     -5.894235  -5.68951544 -11.58375015
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

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



More information about the R-sig-Geo mailing list