Coding Analisis Spasial
Coding Analisis Spasial
Coding Analisis Spasial
R
Anuraga
library("maptools")
## NULL
## NULL
#regresi global
ols <- lm( y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7, data=data)
summary(ols)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.0832 -3.7265 -0.4836 4.6464 10.1558
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 82.90172 20.22625 4.099 0.000291 ***
## x1 -0.32816 0.14451 -2.271 0.030492 *
## x2 -7.98427 1.99576 -4.001 0.000381 ***
## x3 -1.24091 2.01743 -0.615 0.543132
## x4 0.26703 0.20319 1.314 0.198743
## x5 -0.15276 0.12646 -1.208 0.236501
## x6 -0.20455 0.19224 -1.064 0.295783
## x7 0.01538 0.03691 0.417 0.679882
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.852 on 30 degrees of freedom
## Multiple R-squared: 0.8468, Adjusted R-squared: 0.8111
## F-statistic: 23.7 on 7 and 30 DF, p-value: 1.402e-10
##
## Call:
## lm(formula = y ~ x1 + x2, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.3751 -4.8687 -0.3345 5.0513 10.8337
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 99.66099 5.68896 17.518 < 2e-16 ***
## x1 -0.53179 0.09553 -5.567 2.88e-06 ***
## x2 -6.01590 1.83710 -3.275 0.00239 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.969 on 35 degrees of freedom
## Multiple R-squared: 0.8141, Adjusted R-squared: 0.8034
## F-statistic: 76.62 on 2 and 35 DF, p-value: 1.636e-13
library(gvlma)
gvmodel <- gvlma(ols1)
summary(gvmodel)
##
## Call:
## lm(formula = y ~ x1 + x2, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.3751 -4.8687 -0.3345 5.0513 10.8337
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 99.66099 5.68896 17.518 < 2e-16 ***
## x1 -0.53179 0.09553 -5.567 2.88e-06 ***
## x2 -6.01590 1.83710 -3.275 0.00239 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.969 on 35 degrees of freedom
## Multiple R-squared: 0.8141, Adjusted R-squared: 0.8034
## F-statistic: 76.62 on 2 and 35 DF, p-value: 1.636e-13
##
##
## ASSESSMENT OF THE LINEAR MODEL ASSUMPTIONS
## USING THE GLOBAL TEST ON 4 DEGREES-OF-FREEDOM:
## Level of Significance = 0.05
##
## Call:
## gvlma(x = ols1)
##
## Value p-value Decision
## Global Stat 2.090408 0.7191 Assumptions acceptable.
## Skewness 0.007742 0.9299 Assumptions acceptable.
## Kurtosis 1.459612 0.2270 Assumptions acceptable.
## Link Function 0.586122 0.4439 Assumptions acceptable.
## Heteroscedasticity 0.036932 0.8476 Assumptions acceptable.
par(mfrow=c(2,2))
plot(ols1)
#regresi spasial
globalmorans <- lm.morantest(ols1, listw = queen.wl, alternative =
"two.sided")
globalmorans
##
## Global Moran I for regression residuals
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: queen.wl
##
## Moran I statistic standard deviate = 3.2135, p-value = 0.001311
## alternative hypothesis: two.sided
## sample estimates:
## Observed Moran I Expectation Variance
## 0.34391177 -0.05510886 0.01541865
## Statistic df p-value
## LMerr 6.3757 1.0000 0.0116
## LMlag 5.0488 1.0000 0.0246
## RLMerr 2.3817 1.0000 0.1228
## RLMlag 1.0547 1.0000 0.3044
## SARMA 7.4305 2.0000 0.0243
print(ujilagrange)
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: queen.wl
##
## LMerr = 6.3757, df = 1, p-value = 0.01157
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: queen.wl
##
## LMlag = 5.0488, df = 1, p-value = 0.02464
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: queen.wl
##
## RLMerr = 2.3817, df = 1, p-value = 0.1228
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: queen.wl
##
## RLMlag = 1.0547, df = 1, p-value = 0.3044
##
##
## Lagrange multiplier diagnostics for spatial dependence
##
## data:
## model: lm(formula = y ~ x1 + x2, data = data)
## weights: queen.wl
##
## SARMA = 7.4305, df = 2, p-value = 0.02435
# 1. Spatial SAR
lagakb <- lagsarlm(ols1, listw=queen.wl, data=data, type="lag")
summary(lagakb, correlation = FALSE, Nagelkerke = TRUE, Hausman=TRUE,
adj.se=TRUE)
##
## Call:lagsarlm(formula = ols1, data = data, listw = queen.wl, type = "lag")
##
## Residuals:
## Min 1Q Median 3Q Max
## -8.688292 -4.025453 -0.061897 4.191491 11.534906
##
## Type: lag
## Coefficients: (asymptotic standard errors)
## Estimate Std. Error t value Pr(>|z|)
## (Intercept) 80.86898 10.87578 7.4357 1.039e-13
## x1 -0.41763 0.10407 -4.0129 5.999e-05
## x2 -5.82716 1.73895 -3.3510 0.0008053
##
## Rho: 0.20727, LR test value: 4.6634, p-value: 0.030812
## Asymptotic standard error: 0.10588
## t-value: 1.9576, p-value: 0.050276
## Wald statistic: 4.1607, p-value: 0.041372
##
## Log likelihood: -117.9157 for lag model
## ML residual variance (sigma squared): 28.672, (sigma: 5.3547)
## Nagelkerke pseudo-R-squared: 0.83554
## Number of observations: 38
## Number of parameters estimated: 5
## AIC: 245.83, (AIC for lm: 248.49)
## LM test for residual autocorrelation
## test value: 3.1451, p-value: 0.076154
#BP test
bptest.sarlm(lagakb)
##
## studentized Breusch-Pagan test
##
## data:
## BP = 4.2674, df = 2, p-value = 0.1184
?nb2listw
## done