The sar() function implements a standard spatial econometrics model (SAR) or a spatially lagged dependent
variable model using the Markov chain Monte Carlo (McMC) simulation approach.
Usage
sar(
formula,
data = NULL,
W,
burnin = 5000,
Nsim = 10000,
thinning = 1,
parameters.start = NULL
)Arguments
- formula
A symbolic description of the model to fit. A formula for the covariate part of the model using the syntax of the
stats::lm()function fitting standard linear regression models. Neither the response variable nor the explanatory variables are allowed to contain NA values.- data
A
data.framecontaining variables used in the formula object.- W
The N by N spatial weights matrix or neighbourhood matrix where N is the number of spatial units. The formulation of W could be based on geographical distances separating units or based on geographical contiguity. To ensure the maximum value of the spatial autoregressive parameter \(\rho\) less than 1, W is usually row-normalised before implementing the SAR model. As in most cases, spatial weights matrix is very sparse, therefore W here should be converted to a sparse matrix before imported into the
sar()function to save computational burden and reduce computing time. More specifically, W should be a column-oriented numeric sparse matrices of adgCMatrixclass defined in theMatrixpackage. The converion between a dense numeric matrix and a sparse numeric matrix is made quite convenient through theMatrixlibrary.- burnin
The number of McMC samples to discard as the burnin period.
- Nsim
The total number of McMC samples to generate.
- thinning
MCMC thinning factor.
- parameters.start
A list with names "rho", "sigma2e", and "beta" corresponding to initial values for the model parameters \(\rho, \sigma^2_e\) and the regression coefficients respectively.
Value
A list.
- cbetas
A matrix with the MCMC samples of the draws for the coefficients.
- Mbetas
A vector of estimated mean values of regression coefficients.
- SDbetas
The standard deviations of estimated regression coefficients.
- Mrho
The estimated mean of the lower-level spatial autoregressive parameter \(\rho\).
- SDrho
The standard deviation of the estimated lower-level spatial autoregressive parameter.
- Msigma2e
The estimated mean of the lower-level variance parameter \(\sigma^{2}_{e} \).
- SDsigma2e
The standard deviation of the estimated lower-level variance parameter \(\sigma^{2}_{e} \).
- DIC
The deviance information criterion (DIC) of the fitted model.
- pd
The effective number of parameters of the fitted model.
- Log_Likelihood
The log-likelihood of the fitted model.
- R_Squared
A pseudo R square model fit indicator.
- impact_direct
Summaries of the direct impact of a covariate effect on the outcome variable.
- impact_idirect
Summaries of the indirect impact of a covariate effect on the outcome variable.
- impact_total
Summaries of the total impact of a covariate effect on the outcome variable.
References
Anselin, L. (1988). Spatial Econometrics: Methods and Models. Dordrecht: Kluwer Academic Publishers.
LeSage, J. P., and R. K. Pace. (2009). Introduction to Spatial Econometrics. Boca Raton, FL: CRC Press/Taylor & Francis
Examples
data(landprice)
head(landprice)
#> obs lnprice lnarea lndcbd dsubway dpark dele popden crimerate
#> 1 190 7.16382 11.58780 9.93534 7.14334 6.78243 6.67827 0.548966 10.7511
#> 2 992 7.45757 9.20029 9.84785 7.78904 6.95662 7.05138 0.548966 10.7511
#> 3 189 5.57430 10.27820 9.94866 6.83023 7.06579 6.81916 0.548966 10.7511
#> 4 993 7.12569 7.97788 9.84388 7.81991 7.00792 7.11267 0.548966 10.7511
#> 5 969 6.81564 5.81928 9.91940 7.64640 6.88254 4.10025 0.548966 10.7511
#> 6 994 7.48522 7.78634 9.84203 7.83398 7.03089 7.13981 0.548966 10.7511
#> district.id year
#> 1 3 1
#> 2 3 0
#> 3 3 1
#> 4 3 0
#> 5 3 0
#> 6 3 0
data(land)
# extract the land parcel level spatial weights matrix
library(spdep)
library(Matrix)
nb.25 <- spdep::dnearneigh(land,0,2500)
#> Warning: neighbour object has 4 sub-graphs
# to a weights matrix
dist.25 <- spdep::nbdists(nb.25,land)
dist.25 <- lapply(dist.25,function(x) exp(-0.5 * (x / 2500)^2))
mat.25 <- spdep::nb2mat(nb.25,glist=dist.25,style="W")
W <- as(mat.25,"dgCMatrix")
## run the sar() function
res.formula <- lnprice ~ lnarea + lndcbd + dsubway + dpark + dele +
popden + crimerate + as.factor(year)
betas= coef(lm(formula=res.formula,data=landprice))
pars=list(rho = 0.5, sigma2e = 2.0, betas = betas)
# \donttest{
res <- sar(res.formula,data=landprice,W=W,
burnin=500, Nsim=1000, thinning=1,
parameters.start=pars)
#> Warning: style is M (missing); style should be set to a valid value
#> Warning: style is M (missing); style should be set to a valid value
#> Warning: neighbour object has 4 sub-graphs
#> Warning: neighbour object has 4 sub-graphs
summary(res)
#>
#> Call:
#> sar(formula = res.formula, data = landprice, W = W, burnin = 500,
#> Nsim = 1000, thinning = 1, parameters.start = pars)
#> Type: sar
#>
#> Coefficients:
#> Mean SD
#> (Intercept) 6.737630269 0.818079874
#> lnarea -0.005719445 0.017247122
#> lndcbd -0.094740074 0.048771545
#> dsubway -0.151643773 0.035970185
#> dpark -0.157857342 0.045494496
#> dele -0.029816791 0.031133744
#> popden 0.021883069 0.010122997
#> crimerate 0.006587173 0.004186146
#> as.factor(year)1 -0.188676396 0.055358777
#> as.factor(year)2 -0.028473003 0.117606164
#> as.factor(year)3 -0.141082644 0.106536143
#> as.factor(year)4 0.568167565 0.116770315
#> as.factor(year)5 0.398577580 0.127235613
#> as.factor(year)6 2.182982029 0.218861961
#>
#> Spatial Coefficients:
#> rho
#> 0.540786
#>
#> Diagnostics
#> Deviance information criterion (DIC): 4685.173
#> Effective number of parameters (pd): 946.1534
#> Log likelihood: -1396.433
#> Pseudo R squared: 0.3490643
#>
#> Impacts:
#> direct indirect total
#> (Intercept) 6.859170012 7.445940515 14.30511053
#> lnarea -0.005822618 -0.006320716 -0.01214333
#> lndcbd -0.096449085 -0.104699861 -0.20114895
#> dsubway -0.154379266 -0.167585704 -0.32196497
#> dpark -0.160704922 -0.174452490 -0.33515741
#> dele -0.030354655 -0.032951356 -0.06330601
#> popden 0.022277817 0.024183582 0.04646140
#> crimerate 0.006705998 0.007279666 0.01398566
#> as.factor(year)1 -0.192079919 -0.208511475 -0.40059139
#> as.factor(year)2 -0.028986626 -0.031466299 -0.06045292
#> as.factor(year)3 -0.143627626 -0.155914310 -0.29954194
#> as.factor(year)4 0.578416709 0.627897603 1.20631431
#> as.factor(year)5 0.405767499 0.440479046 0.84624654
#> as.factor(year)6 2.222360722 2.412473478 4.63483420
#>
#> Quantiles:
#> 5% 25% 50% 75%
#> (Intercept) 5.4434639783 6.157168506 6.709470822 7.302200233
#> lnarea -0.0328765692 -0.017821166 -0.005463058 0.005856100
#> lndcbd -0.1730984329 -0.127324126 -0.095208813 -0.062252626
#> dsubway -0.2091430980 -0.175056815 -0.152237342 -0.127584724
#> dpark -0.2373570805 -0.187964085 -0.157734737 -0.126874878
#> dele -0.0804025749 -0.051703414 -0.029316239 -0.008598948
#> popden 0.0054864590 0.014609713 0.021807337 0.028871168
#> crimerate -0.0004534109 0.003780401 0.006555009 0.009287260
#> as.factor(year)1 -0.2755554110 -0.227170329 -0.190208777 -0.150670672
#> as.factor(year)2 -0.2216162498 -0.106162234 -0.031273008 0.056592459
#> as.factor(year)3 -0.3145641039 -0.212820017 -0.142123169 -0.069986383
#> as.factor(year)4 0.3815558031 0.486903979 0.577037260 0.645439006
#> as.factor(year)5 0.1921811770 0.311250905 0.402842600 0.481160644
#> as.factor(year)6 1.8102412431 2.040945726 2.191140129 2.327396858
#> 95%
#> (Intercept) 8.07493122
#> lnarea 0.02199887
#> lndcbd -0.01735103
#> dsubway -0.09344331
#> dpark -0.08558776
#> dele 0.02254704
#> popden 0.03876719
#> crimerate 0.01328335
#> as.factor(year)1 -0.09614654
#> as.factor(year)2 0.15480772
#> as.factor(year)3 0.04372262
#> as.factor(year)4 0.76308728
#> as.factor(year)5 0.60495177
#> as.factor(year)6 2.55192672
# }