Learn R Programming

spfilteR (version 2.1.0)

MI.resid: Moran Test for Residual Spatial Autocorrelation

Description

This function assesses the degree of spatial autocorrelation present in regression residuals by means of the Moran coefficient.

Usage

MI.resid(
  resid,
  x = NULL,
  W,
  alternative = "greater",
  boot = NULL,
  na.rm = TRUE
)

Value

A data.frame object with the following elements:

I

observed value of the Moran coefficient

EI

expected value of Moran's I

VarI

variance of Moran's I

zI

standardized Moran coefficient

pI

p-value of the test statistic

Arguments

resid

residual vector

x

vector/ matrix of regressors (default = NULL)

W

spatial connectivity matrix

alternative

specification of alternative hypothesis as 'greater' (default), 'lower', or 'two.sided'

boot

optional integer specifying the number of simulation iterations to compute the variance. If NULL (default), variance calculated under assumed normality

na.rm

listwise deletion of observations with missing values (TRUE/ FALSE)

Author

Sebastian Juhl

Details

The function assumes an intercept-only model if x = NULL. Furthermore, MI.resid automatically symmetrizes the matrix W by: 1/2 * (W + W').

References

Cliff, Andrew D. and John K. Ord (1981): Spatial Processes: Models & Applications. Pion, London.

Cliff, Andrew D. and John K. Ord (1972): Testing for Spatial Autocorrelation Among Regression Residuals. Geographical Analysis, 4 (3): pp. 267 - 284

See Also

lmFilter, glmFilter, MI.vec, MI.local

Examples

Run this code
data(fakedata)
y <- fakedataset$x1
x <- fakedataset$x2

resid <- y - x %*% solve(crossprod(x)) %*% crossprod(x,y)
(Moran <- MI.resid(resid = resid, x = x, W = W, alternative = "greater"))

# intercept-only model
x <- rep(1, length(y))
resid2 <- y - x %*% solve(crossprod(x)) %*% crossprod(x,y)
intercept <- MI.resid(resid = resid2, W = W, alternative = "greater")
# same result with MI.vec for the intercept-only model
vec <- MI.vec(x = resid2, W = W, alternative = "greater")
rbind(intercept, vec)

Run the code above in your browser using DataLab