Skip to content

lAGRANGE MULTIPLIER Test and error in listw object

4 messages · az14, Roger Bivand

#
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)
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
[1] 1056 1056
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.
1 day later
#
On Tue, 6 May 2014, az14 wrote:

            
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

  
    
#
On Wed, 7 May 2014, az14 wrote:

            
Some tests are available in the splm package, please refer to its 
documentation and JSS paper:

http://www.jstatsoft.org/v47/i01

and consider using the R-forge version:

https://r-forge.r-project.org/R/?group_id=352

as it is somewhat newer than the CRAN version.

Hope this helps,

Roger