[R-sig-Geo] Modify lagsarlm function in spdep package
Roger Bivand
Roger.Bivand at nhh.no
Wed Dec 12 20:11:00 CET 2012
On Wed, 12 Dec 2012, Lei Wang wrote:
> Dear subscribers and Prof. Bivand,
>
> I am using lagsarlm function in spdep package to study my research problem.
> I am trying to use restaurants' price, rating, and some other variables to
> explain their customer visit. So customer visit is my dependent variable,
> and I have 6 independent variables. I want to use the spatial mixed model
> so that I can find out whether there are spatial correlated issue in my
> independent variables. I understand that for the spatial mixed model, the
> lagsarlm function calculates the spatial lag coefficients for all the 6
> independent variable, but what I really want is just for two of them.
>
> So I checked the course code for lagsarlm function to see where I should
> modify based on my need. I figured I should change the part that construct
> the WX matrix. My modification is as follows:
You do not want to do this in this way - simply create two new variables
with lag.listw() and use them in a regular lag model. You will not be able
to use impact measures in the usual way - if n is small enough to invert
(I - \rho W), use dense matrix methods to generate the S(W)_r for the
variable pair.
Roger
PS: the reasons functions and variables are not found in your case is that
they are not exported in the NAMESPACE, so need to be prepended with
spdep:::.
>
> if (m > 1) {
> WX <- matrix(nrow = n, ncol = 2)
> wx1 <- lag.listw(listw, x[, 7], zero.policy = zero.policy)
> wx2 <- lag.listw(listw, x[, 8], zero.policy = zero.policy)
> if (any(is.na(wx)))
> stop("NAs in lagged independent variable")
> WX <- cbind(wx1, wx2)
> }
>
> and all the other parts remain same. However, when I run this self-defined
> function, R keeps giving me the following error message:
>
> Error in get("verbose", envir = .spdepOptions) :
> object '.spdepOptions' not found
>
> I have made sure that I loaded the spdep package before I run this
> function.
>
> Could you please let me know why I get this error and how should I fix it?
>
> I really appreciate any help or suggestion you could give to me.
>
>
> Best,
>
> Michelle
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
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