stars object with 2 dimensions and 1 attribute
attribute(s):
Min. 1st Qu. Median Mean 3rd Qu. Max.
filea76a54fed5e64 -6084 -4853 -3745 -2750.098 -155 3218
dimension(s):
from to offset delta refsys point x/y
x 1 1054 0 0.0426784 WGS 84 TRUE [x]
y 1 446 -21.943 -0.0426784 WGS 84 TRUE [y]
Geostatistical data
Suppose we have 200 elevation observations, randomly sampled over the area of SA:
set.seed(1331) # remove this if you want different random pointspts =st_sample(sa, 200)st_geometry(sa) |>plot()plot(pts, add =TRUE)
Moran I test under randomisation
data: v2.elev$random
weights: lw
Moran I statistic standard deviate = -1.0595, p-value = 0.8553
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
-0.051330515 -0.005025126 0.001910166
then for actual (elevation) data:
moran.test(v2.elev$elev, lw)
Moran I test under randomisation
data: v2.elev$elev
weights: lw
Moran I statistic standard deviate = 16.618, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Moran I statistic Expectation Variance
0.721435742 -0.005025126 0.001911137
Global Moran I for regression residuals
data:
model: lm(formula = elev ~ 1, data = v2.elev)
weights: lw
Moran I statistic standard deviate = 16.63, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Observed Moran I Expectation Variance
0.721435742 -0.005025126 0.001908353
lm(elev~x+y, v2.elev) |>lm.morantest(lw)
Global Moran I for regression residuals
data:
model: lm(formula = elev ~ x + y, data = v2.elev)
weights: lw
Moran I statistic standard deviate = 16.404, p-value < 2.2e-16
alternative hypothesis: greater
sample estimates:
Observed Moran I Expectation Variance
0.689267331 -0.014895347 0.001842773
Non-spatial and spatial regression model, using x and y as regressors, can be computed; non-spatial uses lm():
lm(elev~x+y, v2.elev) |>summary()
Call:
lm(formula = elev ~ x + y, data = v2.elev)
Residuals:
Min 1Q Median 3Q Max
-1095.16 -215.09 48.33 288.65 782.61
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.157e+02 6.178e+02 0.835 0.40484
x 2.591e-04 8.248e-05 3.141 0.00194 **
y 4.611e-05 9.655e-05 0.478 0.63346
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 370.1 on 197 degrees of freedom
Multiple R-squared: 0.07773, Adjusted R-squared: 0.06837
F-statistic: 8.302 on 2 and 197 DF, p-value: 0.0003454
Spatial error model can use one of many (see Ch 17), here errorsarlm():
library(spatialreg)
Loading required package: Matrix
Attaching package: 'spatialreg'
The following objects are masked from 'package:spdep':
get.ClusterOption, get.coresOption, get.mcOption,
get.VerboseOption, get.ZeroPolicyOption, set.ClusterOption,
set.coresOption, set.mcOption, set.VerboseOption,
set.ZeroPolicyOption
Call:errorsarlm(formula = elev ~ x + y, data = v2.elev, listw = lw,
Durbin = FALSE)
Residuals:
Min 1Q Median 3Q Max
-514.031 -88.375 -10.678 103.665 578.148
Type: error
Coefficients: (asymptotic standard errors)
Estimate Std. Error z value Pr(>|z|)
(Intercept) -5.8857e+03 2.9743e+03 -1.9788 0.0478334
x -1.5065e-03 4.4506e-04 -3.3849 0.0007119
y 1.1575e-03 4.2643e-04 2.7144 0.0066387
Lambda: 0.9742, LR test value: 255.62, p-value: < 2.22e-16
Asymptotic standard error: 0.011728
z-value: 83.068, p-value: < 2.22e-16
Wald statistic: 6900.3, p-value: < 2.22e-16
Log likelihood: -1337.232 for error model
ML residual variance (sigma squared): 26159, (sigma: 161.74)
Number of observations: 200
Number of parameters estimated: 5
AIC: 2684.5, (AIC for lm: 2938.1)