View source: R/diagnostics_sim.R
| moran_i | R Documentation |
Tests whether residuals exhibit spatial structure after model fitting. Supports inverse-distance and k-nearest-neighbour weight matrices. No external dependencies (uses normal approximation for inference).
moran_i(
object,
coords,
weights = c("inverse", "knn"),
k = 10L,
resid_type = "pearson",
alternative = c("two.sided", "greater", "less")
)
object |
A fitted model, or a numeric vector of residuals |
coords |
N x 2 coordinate matrix (required) |
weights |
Weight scheme: |
k |
Number of neighbours for knn (default 10) |
resid_type |
Residual type if extracting from model (default |
alternative |
|
An htest object with Moran's I, expected I, and p-value
set.seed(1)
coords <- cbind(runif(50), runif(50))
resid <- rnorm(50)
moran_i(resid, coords)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.