[R-sig-Geo] lAGRANGE MULTIPLIER Test and error in listw object

Roger Bivand Roger.Bivand at nhh.no
Wed May 7 16:59:45 CEST 2014


On Tue, 6 May 2014, az14 wrote:

> Dear List,
> I 'm trying to run  the Lagrange multiplier test (LM Test) using R.
> so i import my data file(don) and do an lm regression as bellow:
>
>> don<-read.csv("donnees2.csv",header=TRUE,sep=";",dec=",")
>> widad.lm<-lm(coop~dens_t1+perchom_t1+percvieux_t1+psdc_t1,data=don)
>> summary(widad.lm)
>

The problem starts with lm() because there are missing values on at least 
one of the variables in the model. This reproduces the problem:

library(spdep)
data(columbus)
mat <- nb2mat(col.gal.nb, style="B")
mat2 <- mat%*%mat
x <- mat2listw(mat2)
lw <- nb2listw(x$neighbours, glist=x$weights,style="W")
lm1 <- lm(CRIME ~ HOVAL + INC, data=columbus)
lm.LMtests(lm1, listw=lw, test=c("LMerr","RLMerr"))

# OK

is.na(columbus$CRIME[2]) <- TRUE
lm2 <- lm(CRIME ~ HOVAL + INC, data=columbus)
lm.LMtests(lm2, listw=lw, test=c("LMerr","RLMerr"))

#Error in subset.listw(listw, subset, zero.policy = zero.policy) :
#  Not yet able to subset general weights lists

So arguably you could remove the observations that are not complete from 
don and from the weights matrix (rows and columns), or use a weights 
object in the call to lm.LMtests that can be subsetted.

Fitting OLS models with missing values is risky anyway, and missing values 
may actually indicate that the file read by read.csv() didn't contain what 
you thought it did. The summary of widad.lm reports the number of 
observations deleted due to missingness.

Hope this helps,

Roger

> Then i import my distance matrix( 1056*1056).
>
>
> matrice<-read.csv("matw2.csv",header=FALSEE,sep=";",dec=",")
> mat<-do.call(rbind,matrice)
> dim(mat)
> is.matrix(mat)
> True
> mat2<-mat%*%mat
>> dim(mat2)
> [1] 1056 1056
>> x <- mat2listw(mat2)
> When i run the LM test; with an nb2listw object, i get this error:
>
> lm.LMtests(widad.lm,nb2listw(x$neighbours, glist=x$weights,
> style="W"),test=c("LMerr","RLMerr"))
> Erreur dans subset.listw(listw, subset, zero.policy = zero.policy) :
>  /Not yet able to subset general weights lists
> I tryed to do it with mat2listw, but i get error too.
>
> lm.LMtests(widad.lm, mat2listw(mat2),test=c("LMerr","RLMerr"))
> Erreur dans subset.listw(listw, subset, zero.policy = zero.policy) :
>  Not yet able to subset general weights lists
>
>
> Any help would be appreciated.
> Thank you.
> Zineb.
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/lAGRANGE-MULTIPLIER-Test-and-error-in-listw-object-tp7586372.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> 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, 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