Skip to content

Spatial heteroscedasticity test

Source: R/modern_diagnostics.R · Help: ?performSpatialHeteroTest

Evaluates spatial clustering in squared residuals using Moran's I with a permutation reference distribution. Significant positive autocorrelation in the squared residuals is evidence of spatially varying variance.

Usage

performSpatialHeteroTest(
  model,
  data = NULL,
  listw,
  permutations = 999,
  zero.policy = NULL
)

Arguments

model
A fitted stats::lm object describing the mean structure whose residual variance is to be assessed.
data
A base::data.frame (or compatible object) containing the variables referenced in model. The data must include all observations used to fit model and should not contain unresolved missing values. When NULL, the default, the model frame of model is used. It holds the terms of the model rather than its variables (log(x) rather than x), so a model that transforms a variable needs data, as does a model with an offset() term, and so may a fit whose weights or offset argument is a column of the data, which the model frame holds as (weights) or (offset).
listw
Spatial weights in spdep listw format or a numeric matrix coercible via spdep::mat2listw().
permutations
Number of Monte Carlo permutations used to compute the reference distribution. Defaults to 999, the default of every resampling test in the package since 0.15.0; it was 499 before.
zero.policy
Logical flag forwarded to the spatial diagnostic to permit islands with no neighbours.

Value

An htest result with Moran's I statistic applied to squared residuals.

References

Anselin, L. (1988). Spatial Econometrics: Methods and Models. Kluwer.

Bivand, R. S., Pebesma, E., & Gómez-Rubio, V. (2013). Applied Spatial Data Analysis with R (2nd ed.). Springer.

Examples

if (requireNamespace("spdep", quietly = TRUE)) {
  data(mtcars)
  coords <- cbind(runif(nrow(mtcars)), runif(nrow(mtcars)))
  nb <- spdep::knn2nb(spdep::knearneigh(coords, k = 4))
  lw <- spdep::nb2listw(nb)
  model <- lm(mpg ~ wt + hp, data = mtcars)
  performSpatialHeteroTest(model, mtcars, listw = lw, permutations = 199)
}