4Modelos espaciais de corte transversal (cross-section)
4.1 Pacotes
library(spatialreg)
Loading required package: spData
The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
which was just loaded, will retire in October 2023.
Please refer to R-spatial evolution reports for details, especially
https://r-spatial.org/r/2023/05/15/evolution4.html.
It may be desirable to make the sf package available;
package maintainers should consider adding sf to Suggests:.
The sp package is now running under evolution status 2
(status 2 uses the sf package in place of rgdal)
To access larger datasets in this package, install the spDataLarge
package with: `install.packages('spDataLarge',
repos='https://nowosad.github.io/drat/', type='source')`
Loading required package: Matrix
Loading required package: sf
Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
library(spdep)
Attaching package: 'spdep'
The following objects are masked from 'package:spatialreg':
get.ClusterOption, get.coresOption, get.mcOption,
get.VerboseOption, get.ZeroPolicyOption, set.ClusterOption,
set.coresOption, set.mcOption, set.VerboseOption,
set.ZeroPolicyOption
library(sphet)
Attaching package: 'sphet'
The following object is masked from 'package:spatialreg':
impacts
4.2 Shapefile
# Pacoteslibrary(sf)library(sp)# Abra o arquivomontana.shp <-st_read("data/natregimes_montana.gml")
Reading layer `natregimes_montana' from data source
`/home/raphael/projects/ecoespacial/data/natregimes_montana.gml'
using driver `GML'
Simple feature collection with 55 features and 74 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -116.0625 ymin: 44.35373 xmax: -104.0426 ymax: 49
Geodetic CRS: WGS 84
montana.shp <-st_make_valid(montana.shp)montana.shp <-as_Spatial(montana.shp)# Plotar o mapaplot(montana.shp)
mod1.sar <-lagsarlm(formula = esp1, data = montana.shp@data, listw = w1)summary(mod1.sar)
Call:lagsarlm(formula = esp1, data = montana.shp@data, listw = w1)
Residuals:
Min 1Q Median 3Q Max
-6.4712 -3.0399 -1.3250 2.5259 16.8433
Type: lag
Coefficients: (asymptotic standard errors)
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.16687 0.85033 3.7243 0.0001959
RD90 2.91026 1.06059 2.7440 0.0060695
Rho: 0.1792, LR test value: 0.84239, p-value: 0.35871
Asymptotic standard error: 0.18437
z-value: 0.97196, p-value: 0.33107
Wald statistic: 0.94472, p-value: 0.33107
Log likelihood: -158.4951 for lag model
ML residual variance (sigma squared): 18.519, (sigma: 4.3034)
Number of observations: 55
Number of parameters estimated: 4
AIC: 324.99, (AIC for lm: 323.83)
LM test for residual autocorrelation
test value: 0.54172, p-value: 0.46172
Impact measures (lag, trace):
Direct Indirect Total
RD90 2.897931 0.2282375 3.126169
========================================================
Simulation results (IV variance matrix):
========================================================
Simulated standard errors
Direct Indirect Total
RD90 1.361766 7.614692 8.265529
Simulated z-values:
Direct Indirect Total
RD90 2.318299 0.2932021 0.6520604
Simulated p-values:
Direct Indirect Total
RD90 0.020433 0.76937 0.51436
4.9 SEM (MV)
\(y = X \beta + u \\ u = \lambda Wu + \varepsilon\)
mod1.sem <-errorsarlm(formula = esp1, data = montana.shp@data, listw = w1)summary(mod1.sem)
Call:errorsarlm(formula = esp1, data = montana.shp@data, listw = w1)
Residuals:
Min 1Q Median 3Q Max
-6.4097 -3.0084 -1.1481 2.5629 16.6659
Type: error
Coefficients: (asymptotic standard errors)
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.75130 0.73537 5.1012 3.375e-07
RD90 2.89021 1.03890 2.7820 0.005402
Lambda: 0.20192, LR test value: 0.98506, p-value: 0.32095
Asymptotic standard error: 0.18804
z-value: 1.0738, p-value: 0.28291
Wald statistic: 1.153, p-value: 0.28291
Log likelihood: -158.4237 for error model
ML residual variance (sigma squared): 18.436, (sigma: 4.2937)
Number of observations: 55
Number of parameters estimated: 4
AIC: NA (not available for weighted model), (AIC for lm: 323.83)
Impact measures (SlX, glht, n-k):
Direct Indirect Total
RD90 2.86351 -0.286971 2.576539
========================================================
Standard errors:
Direct Indirect Total
RD90 1.115113 2.374184 2.76964
========================================================
Z-values:
Direct Indirect Total
RD90 2.56791 -0.1208714 0.9302793
p-values:
Direct Indirect Total
RD90 0.010231 0.90379 0.35223
4.14 SLX (STSLS)
mod1.slx_stsls <-spreg(formula = esp1, data = montana.shp@data, listw = w1,lag.instr =FALSE, Durbin =TRUE, model ="ols", step1.c =TRUE, het =TRUE, endog = endog, instruments = instruments)summary(mod1.slx_stsls)
mod1.slx_stsls2 <-spreg(formula = esp1, data = montana.shp@data, listw = w1,lag.instr =FALSE, Durbin =TRUE, model ="ols", step1.c =TRUE, het =TRUE)summary(sphet::impacts(mod1.slx_stsls2, tr=trMat, R=1000), zstats=TRUE, short=TRUE)
Impact measures (SlX, glht, n-k):
Direct Indirect Total
RD90 2.86351 -0.286971 2.576539
========================================================
Standard errors:
Direct Indirect Total
RD90 1.213777 2.216879 2.652204
========================================================
Z-values:
Direct Indirect Total
RD90 2.359174 -0.1294482 0.9714708
p-values:
Direct Indirect Total
RD90 0.018316 0.897 0.33131
Call:errorsarlm(formula = esp1, data = montana.shp@data, listw = w1,
Durbin = TRUE)
Residuals:
Min 1Q Median 3Q Max
-6.3568 -2.9878 -1.0313 2.5668 16.5735
Type: error
Coefficients: (asymptotic standard errors)
Estimate Std. Error z value Pr(>|z|)
(Intercept) 3.69127 0.85423 4.3212 1.552e-05
RD90 2.83836 1.10454 2.5697 0.01018
lag.RD90 -0.33914 2.45675 -0.1380 0.89021
Lambda: 0.20244, LR test value: 0.98866, p-value: 0.32007
Asymptotic standard error: 0.18799
z-value: 1.0769, p-value: 0.28153
Wald statistic: 1.1597, p-value: 0.28153
Log likelihood: -158.4142 for error model
ML residual variance (sigma squared): 18.429, (sigma: 4.2929)
Number of observations: 55
Number of parameters estimated: 5
AIC: NA (not available for weighted model), (AIC for lm: 325.82)
Impact measures (SlX, glht, n-k):
Direct Indirect Total
RD90 2.840057 -0.3343859 2.505671
========================================================
Standard errors:
Direct Indirect Total
RD90 1.263635 2.402231 3.03313
========================================================
Z-values:
Direct Indirect Total
RD90 2.24753 -0.139198 0.8261007
p-values:
Direct Indirect Total
RD90 0.024606 0.88929 0.40875