# hsar: Hierarchical SAR model estimation In HSAR: Hierarchical Spatial Autoregressive Model

## Description

The specification of a HSAR model is as follows:

y_i,j = ρ * W_i * y + x'_i,j * β +z'_j * γ + θ_j + ε_i,j

θ_j = λ * M_j * θ + μ_j

ε_i,j ~ N(0,σ^2_e); μ_j ~ N(0,σ^2_u)

where i=1,2,...,n_j and j=1,2,...,J are indicators of lower- and higher-level spatial units. n_j is the number of lower-level units in the j-th higher level unit and Sum(j=1,J)=N. x'_i,j and z'_j represent vectors of lower- and higher-level independent variables. β and γ are regression coefficients to estimate. θ, a N * J vector of higher-level random effects, also follows a simultaneous autoregressive process. W and M are two spatial weights matrices (or neighbourhood connection matrices) at the lower and higher levels, defining how spatial units at each level are connected. ρ and λ are two spatial autoregressive parameters measuring the strength of the dependencies/correlations at the two spatial scales.

A succinct matrix formulation of the model is,

y = ρ * W * y + X * β + Z * γ + Δ * θ + ε

θ = λ * M * θ + μ

It is also useful to note that the HSAR model nests a standard (random intercept) multilevel model model when ρ and λ are both equal to zero and a standard spaital econometric model when λ and σ^2_u are both equal to zero.

## Usage

 1 2 hsar( formula, data = NULL, W=NULL, M=NULL, Delta, 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 lm() function fitting standard linear regression models. Neither the response variable nor the explanatory variables are allowed to contain NA values. data A data frame containing variables used in the formula object. W The N by N lower-level spatial weights matrix or neighbourhood matrix where N is the total number of lower-level 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 ρ less than 1, W should be row-normalised before running the HSAR 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 hsar() function to save computational burdon and reduce computing time. More specifically, W should be a column-oriented numeric sparse matrices of a dgCMatrix class defined in the Matrix package. The converion between a dense numeric matrix and a sparse numeric matrix is made quite convenient through the Matrix library. M The J by J higher-level spatial weights matrix or neighbourhood matrix where J is the total number of higher-level spatial units. Similar with W, the formulation of M could be based on geographical distances separating units or based on geographical contiguity. To ensure the maximum value of the spatial autoregressive parameter λ less than 1, M is also row-normalised before running the HSAR model. As with W, M should also be a column-oriented numeric sparse matrices. Delta The N by J random effect design matrix that links the J by 1 higher-level random effect vector back to the N by 1 response variable under investigation. It is simply how lower-level units are grouped into each high-level units with columns of the matrix being each higher-level units. As with W and M, δ should also be a column-oriented numeric sparse matrices. 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", "lambda", "sigma2e", "sigma2u" and "beta" corresponding to initial values for the model parameters ρ, λ, σ^2_e, σ^2_u and the regression coefficients respectively.

## Details

In order to use the hsar() function, users need to specify the two spatial weights matrices W and M and the random effect design matrix δ. However, it is very easy to extract such spatial weights matrices from spatial data using the package spdep. Geographic distance-based or contiguity-based spatial weights matrix for both spatial points data and spatial polygons data are available in the spdep package.

Before the extraction of W and M, it is better to first sort the data using the higher-level unit identifier. Then, the random effect design matrix can be extracted simply (see the following example) and so are the two spatial weights matrices. Make sure the order of higher-level units in the weights matrix M is in line with that in the δ matrix.

Two simpler versions of the HSAR model can also be fitted using the hsar() function. The first is a HSAR model with λ equal to zero, indicating an assumption of independence in the higher-level random effect \mathbf{θ}. The second is a HSAR with ρ equal to zero, indicating an independence assumption in the outcome variable conditioning on the hgiher-level random effect. This model is useful in situations where we are interested in the neighbourhood/contextual effect on individual's outcomes and have good reasons to suspect the effect from geographical contexts upon individuals to be dependent. Meanwhile we have no information on how lower-level units are connnected.

## Value

A list object containing:

 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 ρ. SDrho The standard deviation of the estimated lower-level spatial autoregressive parameter. Mlamda The estimated mean of the higher-level spatial autoregressive parameter λ. SDlambda The standard deviation of the estimated higher-level spatial autoregressive parameter. Msigma2e The estimated mean of the lower-level variance parameter σ^2_e. SDsigma2e The standard deviation of the estimated lower-level variance parameter σ^{2}_{e} . Msigma2u The estimated mean of the higher-level variance parameter σ^2_u. SDsigma2u The standard deviation of the estimated higher-level variance parameter σ^2_u. Mus Mean values of θ SDus Standard deviation of θ 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.

## Author(s)

Guanpeng Dong, Richard Harris, Angelos Mimis mimis@panteion.gr

## References

Dong, G. and Harris, R. 2015. Spatial Autoregressive Models for Geographically Hierarchical Data Structures. Geographical Analysis, 47:173-191.

LeSage, J. P., and R. K. Pace. (2009). Introduction to Spatial Econometrics. Boca Raton, FL: CRC Press/Taylor & Francis.

sar, landprice, Beijingdistricts, landSPDF
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 library(spdep) # Running the hsar() function using the Beijing land price data data(landprice) # load shapefiles of Beijing districts and land parcels data(Beijingdistricts) data(landSPDF) plot(Beijingdistricts,border="green") plot(landSPDF,add=TRUE,col="red",pch=16,cex=0.8) # Define the random effect matrix model.data <- landprice[order(landprice$district.id),] head(model.data,50) # the number of individuals within each neighbourhood MM <- as.data.frame(table(model.data$district.id)) # the total number of neighbourhood, 100 Utotal <- dim(MM)[1] Unum <- MM[,2] Uid <- rep(c(1:Utotal),Unum) n <- nrow(model.data) Delta <- matrix(0,nrow=n,ncol=Utotal) for(i in 1:Utotal) { Delta[Uid==i,i] <- 1 } rm(i) # Delta[1:50,1:10] Delta <- as(Delta,"dgCMatrix") # extract the district level spatial weights matrix using the queen's rule nb.list <- spdep::poly2nb(Beijingdistricts) mat.list <- spdep::nb2mat(nb.list,style="W") M <- as(mat.list,"dgCMatrix") # extract the land parcel level spatial weights matrix nb.25 <- spdep::dnearneigh(landSPDF,0,2500) # to a weights matrix dist.25 <- spdep::nbdists(nb.25,landSPDF) 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 hsar() 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,lambda = 0.5, sigma2e = 2.0, sigma2u = 2.0, betas = betas ) ## Not run: res <- hsar(res.formula,data=model.data,W=W,M=M,Delta=Delta, burnin=500, Nsim=1000, thinning = 1, parameters.start=pars) summary(res) # visualise the district level random effect library(classInt) library(RColorBrewer) x <- as.numeric(res$Mus) breaks <- classIntervals(x,4,"fisher")$brks groups <- cut(x,breaks,include.lowest=TRUE,labels=FALSE) palette <- brewer.pal(4, "Blues") plot(Beijingdistricts,col=palette[groups],border="grey") ## End(Not run)