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¶
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 fitmodeland should not contain unresolved missing values. WhenNULL, the default, the model frame ofmodelis used. It holds the terms of the model rather than its variables (log(x)rather thanx), so a model that transforms a variable needsdata, as does a model with anoffset()term, and so may a fit whoseweightsoroffsetargument is a column of the data, which the model frame holds as(weights)or(offset). listw- Spatial weights in
spdeplistwformat or a numeric matrix coercible viaspdep::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)
}