lm.morantest {spdep} | R Documentation

## Moran's I test for residual spatial autocorrelation

### Description

Moran's I test for spatial autocorrelation in residuals from an estimated linear model (`lm()`). The helper function `listw2U()` constructs a weights list object corresponding to the sparse matrix 1/2 (W + W')

### Usage

    lm.morantest(model, listw, zero.policy=FALSE,
                alternative = "greater", spChk=NULL, resfun=weighted.residuals)
    listw2U(listw)

### Arguments

`model` | an object of class `lm` returned by `lm`; weights may be specified in the `lm` fit, but offsets should not be used
`listw` | a `listw` object created for example by `nb2listw`
`zero.policy` | if TRUE assign zero to the lagged value of zones without neighbours, if FALSE assign NA
`alternative` | a character string specifying the alternative hypothesis, must be one of "greater" (default), "less" or "two.sided".
`spChk` | should the data vector names be checked against the spatial objects for identity integrity, TRUE, or FALSE, default NULL to use `get.spChkOption()`
`resfun` | default: weighted.residuals; the function to be used to extract residuals from the `lm` object, may be `residuals`, `weighted.residuals`, `rstandard`, or `rstudent`

### Value

A list with class `htest` containing the following components:

`statistic` | the value of the standard deviate of Moran's I.
`p.value` | the p-value of the test.
`estimate` | the value of the observed Moran's I, its expectation and variance under the method assumption.
`alternative` | a character string describing the alternative hypothesis.
`method` | a character string giving the method used.
`data.name` | a character string giving the name(s) of the data.

### Note

The examples also show how to use permutation bootstrap if desired.

### Author(s)

Roger Bivand Roger.Bivand@nhh.no

### References

Cliff, A. D., Ord, J. K. 1981 Spatial processes, Pion, p. 203,

### See Also

`lm.LMtests`, `lm`

### Examples

    data(oldcol)
    oldcrime1.lm <- lm(CRIME ~ 1, data = COL.OLD)
    oldcrime.lm <- lm(CRIME ~ HOVAL + INC, data = COL.OLD)
    lm.morantest(oldcrime.lm, nb2listw(COL.nb, style="W"))
    lm.LMtests(oldcrime.lm, nb2listw(COL.nb, style="W"))
    lm.morantest(oldcrime.lm, nb2listw(COL.nb, style="S"))
    lm.morantest(oldcrime1.lm, nb2listw(COL.nb, style="W"))
    moran.test(spNamedVec("CRIME", COL.OLD), nb2listw(COL.nb, style="W"),
     randomisation=FALSE)
    oldcrime.wlm <- lm(CRIME ~ HOVAL + INC, data = COL.OLD, weights = I(1/AREA))
    lm.morantest(oldcrime.wlm, nb2listw(COL.nb, style="W"), resfun=weighted.residuals)
    lm.morantest(oldcrime.wlm, nb2listw(COL.nb, style="W"), resfun=rstudent)
    if (require(boot)) {
      oldcrime.lmx <- lm(CRIME ~ HOVAL + INC, data = COL.OLD, x=TRUE)
      listw <- nb2listw(COL.nb, style="W")
      MoraneI.boot <- function(var, i, ...) {
        var <- var[i]
        lmres <- lm(var ~ oldcrime.lmx$x - 1)
        return(moran(x=residuals(lmres), ...)$I)
      }
      boot1 <- boot(residuals(oldcrime.lmx), statistic=MoraneI.boot, R=499,
        sim="permutation", listw=listw, n=length(listw$neighbours), S0=Szero(listw))
      zi <- (boot1$t0 - mean(boot1$t))/sqrt(var(boot1$t))
      boot1
      plot(boot1)
      cat("Bootstrap permutation standard deviate:", zi, "\n\n")
      lm.morantest(oldcrime.lm, nb2listw(COL.nb, style="W"))
    }

[Package spdep version 0.3-25 Index]