sf
library)How do we assess spatial autocorrelation?
What are the possible patterns of spatial autocorrelation?
How do we assess point spatial data?
How do we assess polygon spatial data?
\[I = \frac{N}{W}\frac{\sum\sum w_{ij}(x_i - \bar{x})(x_j - \bar(x))}{\sum(x_i - \bar{x})^2}\]
Make a distance matrix
Convert it to a weight matrix
Run spdep::moran.test
Yes, this is a PITA…
#first, mke a distance matrix of points
boreal_dists <- boreal %>%
dplyr::select(x,y) %>%
dist() %>%
as.matrix()
#inverse of distance is weight
boreal_dists_weights <- 1/boreal_dists
diag(boreal_dists_weights) <- 0
#turn into a weights list
boreal_w <- mat2listw(boreal_dists_weights)
Moran I test under randomisation
data: boreal$NDVI
weights: boreal_w
Moran I statistic standard deviate = 45.157, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
1.834024e-01 -1.879699e-03 1.683501e-05
How do we assess spatial autocorrelation?
What are the possible patterns of spatial autocorrelation?
How do we assess point spatial data?
How do we assess polygon spatial data?
SAR:
Simultaneous Autoregressive Process \(y_i = BX_i + \sum Sy_ij + \epsilon_{i}\)
CAR:
Conditional Autoregressive Process \(y_i | y_{-i} ~\sim \mathcalc{N}{ BX_i + \sum S_{ij}yj, m_{ij}\)
from https://stats.stackexchange.com/a/9983
Non-spatial model
My House Value is a function of my home Gardening Investment.
SAR model
My House Value is a function of the House Values of my neighbours.
CAR model
My House Value is a function of the Gardening Investment of my neighbours.
\[ cor(\epsilon) = \begin{pmatrix}
1 & \rho_{ij} &\rho_{ik} & ... \\
\rho_{ji} & 1& \rho_jk & ...\\
\rho_{ki} & \rho_{kj} & 1 & ... \\
. & . & . & ... \\
. & . & . & ... \\
. & . & . & ... \\
\end{pmatrix}\]
\[\rho{ij} = f(x_i, x_j)\] e.g., \[\rho{ij} = exp(-Distance/range)\]
model psill range
1 Nug 0.0009415914 0.000
2 Sph 0.0072401874 1412.745
#1. Make a gstat object (model)
boreal_gstat <- gstat(formula = NDVI ~ 1, loc= ~x+y,
data = boreal, model = best_vario)
#2. Create a grid of "Pixels" using x as columns and y as rows
TheGrid <- expand.grid(x=seq(1,3000, 100),y=seq(1,7000, 100))
coordinates(TheGrid)<- ~ x+y
#coordinates(boreal)<- ~ x+y
gridded(TheGrid) <- TRUE
#3. Make a predicted surface
TheSurface <- predict(boreal_gstat, model=best_vario, newdata=TheGrid)
#plot
image(TheSurface, col=terrain.colors(20),
xlim = c(1,3e3), ylim = c(1, 7e3))
[using ordinary kriging]
How do we assess spatial autocorrelation?
What are the possible patterns of spatial autocorrelation?
How do we assess point spatial data?
How do we assess polygon spatial data?
How do we assess spatial autocorrelation?
What are the possible patterns of spatial autocorrelation?
How do we assess point spatial data?
How do we assess polygon spatial data?
Moran I test under randomisation
data: residuals(boreal_mod)
weights: boreal_w
Moran I statistic standard deviate = 30.255, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
1.217804e-01 -1.879699e-03 1.670611e-05
best_resid_vario <- fit.variogram(v_bor_resid,
model = vgm(c("Exp", "Gau", "Mat", "Sph")))
best_vario
model psill range
1 Nug 0.0009415914 0.000
2 Sph 0.0072401874 1412.745
# A tibble: 2 x 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 0.327 0.00552 59.3 1.95e-236
2 Wet -4.88 0.154 -31.6 3.05e-124
# A tibble: 2 x 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 0.402 9.19 0.0437 9.65e- 1
2 Wet -3.04 0.168 -18.1 1.62e-57
predict
and brms
or glmmTMB
modelHow do we assess spatial autocorrelation?
What are the possible patterns of spatial autocorrelation?
How do we assess point spatial data?
How do we assess polygon spatial data?
Moran I test under randomisation
data: residuals(penn_mod)
weights: penn_weights
Moran I statistic standard deviate = 0.60877, p-value = 0.2713
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.030083778 -0.015151515 0.005521394
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.621208 2.135931 1.695377 0.09478954
smoking 18.345216 8.944603 2.050982 0.04430385
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.715435 2.161831 1.718652 0.08567779
smoking 17.919386 9.048019 1.980476 0.04765004