nonormmoran: Detection of spatial autocorrelation

View source: R/nonormmoran.R

nonormmoranR Documentation

Detection of spatial autocorrelation

Description

The function nonnormmoran is used to detect spatial autocorrelation in the residuals u from the least squares model Y=\beta \times X+u. It calculates Moran's I statistic of the residuals based on the gaussian asymptotic distribution and give a p-value associated to the test of spatial autocorrelation (gaussian version).

Usage

nonormmoran(y, x, W)

Arguments

y

vector of size n of dependent variable

x

matrix n \times p containing explanatory variables

W

spatial weight matrix

Details

W is supposed standartized :

I=(n/s)\frac{u'Wu}{u'u}

I \sim N(E(I),var(I))

let M=(I-X(X'X)^{-1}X')

E(I)=(n/s)\frac{tr(MW)}{n-k}

d=\frac{n-p}{n+p+2}

V(I)=(n/s)^2[tr(MWMW')+tr(MW)^2+(tr(MW))^2]/d-E(I)^2

Z_I=\frac{I-E(I)}{v(I)^{1/2}}

When W is row-normalised, s=n else s is the number of nonzero links

Value

a list with nobs is the number of observations, nvar, the number of explanatory variables, morani is the Moran's I statistic estimate, imean is E(I), ivar is var(I), istat is the normalized Moran's I statistic (corresponding to Z_I), and prob the associated p-value.

Note

This function is closed to the function lm.morantest included in the spdep package. nonnormmoran is less confortable to use because it didn't take into account S4 classes.

Author(s)

Translated into R from Jim Lessage's Spatial Econometrics Toolbox, http://www.spatial-econometrics.com/

References

Thibault Laurent, Anne Ruiz-Gazen, Christine Thomas-Agnan (2012), GeoXp: An R Package for Exploratory Spatial Data Analysis. Journal of Statistical Software, 47(2), 1-23.

See Also

moranplotmap,neighbourmap,makeneighborsw,normw

Examples

###
# data baltimore
if (require(spData, quietly = TRUE)) {
  data(baltimore, package = "spData")
}

# a spatial weight matrix constructed in the matrix format
W <- makeneighborsw(cbind(baltimore$X, baltimore$Y), method = "neighbor", 4)

# when W is not row-normalised ...
nonormmoran(baltimore$PRICE, cbind(rep(1, nrow(baltimore)), 
  baltimore[, 14:15]), W)
# when W is row_normalised ...
nonormmoran(baltimore$PRICE, cbind(rep(1, nrow(baltimore)), 
  baltimore[, 14:15]), normw(W))

# If we compare to the function lm.morantest
baltimore.lm <- lm(PRICE ~ LOTSZ + SQFT, data = baltimore)

spdep::lm.morantest(baltimore.lm, spdep::mat2listw(W, style = "W"))

tibo31/GeoXp documentation built on April 8, 2023, 7:50 a.m.