From 023b6296986d73d8fc13abcee09ce0c27e06fc1d Mon Sep 17 00:00:00 2001 From: SpatLyu Date: Mon, 23 Dec 2024 11:53:58 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20SpatLyu/?= =?UTF-8?q?HSAR@202bad39e918b127548d589e6432fe50c082867e=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- articles/HSAR.html | 2 +- authors.html | 2 +- news/index.html | 4 ++-- pkgdown.yml | 2 +- reference/Beijingdistricts.html | 2 +- reference/depmunic.html | 2 +- reference/hsar.html | 2 +- reference/land.html | 2 +- reference/landprice.html | 2 +- reference/properties.html | 2 +- reference/sar.html | 2 +- search.json | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/articles/HSAR.html b/articles/HSAR.html index 7ac7949..ccba50a 100644 --- a/articles/HSAR.html +++ b/articles/HSAR.html @@ -60,7 +60,7 @@

Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)

- Source: vignettes/HSAR.Rmd + Source: vignettes/HSAR.Rmd
HSAR.Rmd
diff --git a/authors.html b/authors.html index b1f5d0b..59247ea 100644 --- a/authors.html +++ b/authors.html @@ -58,7 +58,7 @@

Authors

Citation

-

Source: inst/CITATION

+

Source: inst/CITATION

Dong, Guanpeng, Harris, Richard (2014). “Spatial Autoregressive Models for Geographically Hierarchical Data Structures.” diff --git a/news/index.html b/news/index.html index c7ed20d..d49df60 100644 --- a/news/index.html +++ b/news/index.html @@ -33,11 +33,11 @@

-

HSAR 0.6.0

+

HSAR 0.6.0

CRAN release: 2024-12-23

  • Resolve the CRAN check issues for HASR and resubmit it to CRAN.
diff --git a/pkgdown.yml b/pkgdown.yml index b82830c..c2116f7 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: HSAR: HSAR.html -last_built: 2024-12-20T02:30Z +last_built: 2024-12-23T11:53Z urls: reference: https://spatlyu.github.io/HSAR/reference article: https://spatlyu.github.io/HSAR/articles diff --git a/reference/Beijingdistricts.html b/reference/Beijingdistricts.html index 247ec23..eddf590 100644 --- a/reference/Beijingdistricts.html +++ b/reference/Beijingdistricts.html @@ -33,7 +33,7 @@
diff --git a/reference/depmunic.html b/reference/depmunic.html index 74b4b38..69e3de7 100644 --- a/reference/depmunic.html +++ b/reference/depmunic.html @@ -33,7 +33,7 @@
diff --git a/reference/hsar.html b/reference/hsar.html index 11777ef..d5bc0d6 100644 --- a/reference/hsar.html +++ b/reference/hsar.html @@ -53,7 +53,7 @@
diff --git a/reference/land.html b/reference/land.html index 6c41c67..b7f9183 100644 --- a/reference/land.html +++ b/reference/land.html @@ -33,7 +33,7 @@
diff --git a/reference/landprice.html b/reference/landprice.html index d2779ba..e369ce1 100644 --- a/reference/landprice.html +++ b/reference/landprice.html @@ -33,7 +33,7 @@
diff --git a/reference/properties.html b/reference/properties.html index 9597cc9..861956e 100644 --- a/reference/properties.html +++ b/reference/properties.html @@ -35,7 +35,7 @@
diff --git a/reference/sar.html b/reference/sar.html index e3cbe33..1acd1ab 100644 --- a/reference/sar.html +++ b/reference/sar.html @@ -35,7 +35,7 @@
diff --git a/search.json b/search.json index 3848d43..db65825 100644 --- a/search.json +++ b/search.json @@ -1 +1 @@ -[{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"an-application-of-hsar-for-asking-prices-in-the-municipality-of-athens","dir":"Articles","previous_headings":"","what":"An application of HSAR for asking prices in the municipality of Athens","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"application hsar(), based rel data, illustrated. design weight matrices needed random effect design matrix explained.","code":""},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"libraries","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Libraries","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"start loading libraries used.","code":"library(sf) library(spdep) library(tidyverse) ## ── Attaching core tidyverse packages ─────────────────────────────────────── tidyverse 2.0.0 ── ## ✔ dplyr 1.1.4 ✔ readr 2.1.5 ## ✔ forcats 1.0.0 ✔ stringr 1.5.1 ## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1 ## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1 ## ✔ purrr 1.0.2 ## ── Conflicts ───────────────────────────────────────────────────────── tidyverse_conflicts() ── ## ✖ tidyr::expand() masks Matrix::expand() ## ✖ dplyr::filter() masks stats::filter() ## ✖ dplyr::lag() masks stats::lag() ## ✖ tidyr::pack() masks Matrix::pack() ## ✖ tidyr::unpack() masks Matrix::unpack() ## ℹ Use the conflicted package () to force all conflicts to become errors library(HSAR)"},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"reading-the-datasets","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Reading the datasets","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"higher level, seven departments municipality Athens lower level point data properties. characteristics come areal data id department, number airbnb properties, number museums, population, number citizens origin non european union country, area green space (m^2) area polygon (km^2). characteristics properties size (m^2), asking price (euros), price per square meter, age (years) shortest distance metro/train station (m). Now going create two variables higher, municipality department, level. first one population density per 10k citizens, second one percentage non EU citizens. next step create model data going use hsar model. , need property (lower data), data relevant department(higher level). now, know property, department resides coresponding data polygon. also need data sorting order.","code":"data(depmunic) data(properties) plot(st_geometry(depmunic),col = sf.colors(12, categorical = TRUE), border = 'grey') plot(st_geometry(properties),add=TRUE,col=\"red\",pch=16,cex=0.6) names(depmunic) ## [1] \"num_dep\" \"airbnb\" \"museums\" \"population\" \"pop_rest\" \"greensp\" \"area\" ## [8] \"geometry\" depmunic$pop_rest ## [1] 8202 5009 2735 4167 5099 16531 8017 names(properties) ## [1] \"id\" \"size\" \"price\" \"prpsqm\" \"age\" \"dist_metro\" \"geometry\" hist(properties$age, xlab = \"Age\", main=\"Age of the properties\") depmunic$popdens <- depmunic$population/ (10000*depmunic$area) depmunic$foreigners <- 100 * depmunic$pop_rest/ depmunic$population properties_in_dd <- st_join(properties, depmunic, join = st_within) model.data <- properties_in_dd[order(properties_in_dd$num_dep),]"},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"create-matrices-used-in-the-hsar-function","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Create matrices used in the hsar function","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"order run model need create effect design matrix (Delta), weight matrix high-level - polygon data (M), weight matrix lower level - point data (W). order define random effect matrix, start estimating number properties municipality department geting total number municipality departments (7), define vector number municipality department property belongs define random effect matrix (Delta) wich dimension 1000x7 Now estimate spatial weight matrix higher level case municipality departments (polygons). start poly2nb constructs neighbours list polygons nb2mat generate weight matrix neighbours list previously created. transform weight matrix sparse matrix format. closer look M , can visualize Similarly, create spatial weight matrix lower level properties (point data). create neighbour list distance 1300 meters weights matrix W follows W matrix, can check neighbours statistics","code":"properties_count <- count(as_tibble(model.data), num_dep) MM <- as.data.frame(properties_count) Utotal <- dim(MM)[1] Unum <- MM[,2] Uid <- rep(c(1:Utotal),Unum) n <- nrow(properties) Delta <- matrix(0,nrow=n,ncol=Utotal) for(i in 1:Utotal) { Delta[Uid==i,i] <- 1 } Delta <- as(Delta,\"dgCMatrix\") nb.list <- poly2nb(depmunic) mat.list <- nb2mat(nb.list,style=\"W\") M <- as(mat.list,\"dgCMatrix\") plot(st_geometry(depmunic),border = 'grey') plot(st_centroid(depmunic), add = TRUE) ## Warning: st_centroid assumes attributes are constant over geometries ## Warning in plot.sf(st_centroid(depmunic), add = TRUE): ignoring all but the first attribute plot(nb.list, st_centroid(depmunic), add = TRUE) ## Warning: st_centroid assumes attributes are constant over geometries nb.1300 <- dnearneigh(properties,0,1300) mat.1300 <- nb2mat(nb.1300,style=\"W\") W <- as(mat.1300,\"dgCMatrix\") nb.1300 ## Neighbour list object: ## Number of regions: 1000 ## Number of nonzero links: 170254 ## Percentage nonzero weights: 17.0254 ## Average number of links: 170.254"},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"run-the-models","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Run the models","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":", ready matrices Delta, M W, wun hsar() function two simpler models defined rho = 0 lambda=0. , firstly, assuming rho = 0 (interaction effects lower level) get secondly, given lambda = 0 (interaction higher level) get","code":"res.formula <- prpsqm ~ size + age + greensp + population + museums + airbnb res <- hsar(res.formula,data=model.data,W=W,M=M,Delta=Delta, burnin=500, Nsim=1000) ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value summary(res) ## ## Call: ## hsar(formula = res.formula, data = model.data, W = W, M = M, ## Delta = Delta, burnin = 500, Nsim = 1000) ## Type: hsar ## ## Coefficients: ## Mean SD ## (Intercept) 1.880468e+03 9.835447e+00 ## size 4.298802e+00 5.112041e-01 ## age -1.995687e+01 1.304370e+00 ## greensp 8.404794e-04 8.738884e-04 ## population -9.940391e-03 2.273935e-03 ## museums -4.515772e+01 1.008513e+01 ## airbnb 6.022747e-01 2.496115e-01 ## ## Spatial Coefficients: ## rho lambda ## [1,] 0.196536 0.018432 ## ## Diagnostics ## Deviance information criterion (DIC): 28193.01 ## Effective number of parameters (pd): -1.66553 ## Log likelihood: -14098.17 ## Pseudo R squared: 0.3601049 ## ## Impacts: ## direct indirect total ## (Intercept) 1.881082e+03 4.592335e+02 2.340316e+03 ## size 4.300207e+00 1.049821e+00 5.350028e+00 ## age -1.996339e+01 -4.873715e+00 -2.483711e+01 ## greensp 8.407540e-04 2.052555e-04 1.046009e-03 ## population -9.943639e-03 -2.427567e-03 -1.237121e-02 ## museums -4.517248e+01 -1.102808e+01 -5.620055e+01 ## airbnb 6.024715e-01 1.470830e-01 7.495545e-01 ## ## Quantiles: ## 5% 25% 50% 75% 95% ## (Intercept) 1.864369e+03 1.874059e+03 1.880361e+03 1.887328e+03 1.896080e+03 ## size 3.436255e+00 3.956910e+00 4.291712e+00 4.628642e+00 5.155081e+00 ## age -2.215863e+01 -2.075471e+01 -1.991798e+01 -1.911688e+01 -1.792525e+01 ## greensp -3.546526e-04 2.905312e-04 7.376810e-04 1.261277e-03 2.657171e-03 ## population -1.382163e-02 -1.159143e-02 -9.920309e-03 -8.353503e-03 -6.404121e-03 ## museums -6.148110e+01 -5.224350e+01 -4.495013e+01 -3.850940e+01 -2.847943e+01 ## airbnb 1.776907e-01 4.578970e-01 6.114716e-01 7.457536e-01 1.010643e+00 res_1 <- hsar(res.formula,data=model.data,W=NULL,M=M,Delta=Delta,burnin=500, Nsim=1000) ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value summary(res_1) ## ## Call: ## hsar(formula = res.formula, data = model.data, W = NULL, M = M, ## Delta = Delta, burnin = 500, Nsim = 1000) ## Type: hsar with rho = 0 ## ## Coefficients: ## Mean SD ## (Intercept) 1.880592e+03 1.010450e+01 ## size 4.329009e+00 4.214029e-01 ## age -2.004845e+01 1.258780e+00 ## greensp 6.812935e-04 6.843458e-04 ## population -6.877688e-03 1.100394e-03 ## museums -4.585817e+01 9.479326e+00 ## airbnb 6.288388e-01 2.222552e-01 ## ## Spatial Coefficients: ## lambda ## -0.130888 ## ## Diagnostics ## Deviance information criterion (DIC): 28196.24 ## Effective number of parameters (pd): -1.988165 ## Log likelihood: -14100.11 ## Pseudo R squared: 0.3587056 ## ## Quantiles: ## 5% 25% 50% 75% 95% ## (Intercept) 1.863327e+03 1.874280e+03 1.880446e+03 1.887451e+03 1.897526e+03 ## size 3.648867e+00 4.026734e+00 4.331703e+00 4.647616e+00 5.040309e+00 ## age -2.217344e+01 -2.090501e+01 -2.002926e+01 -1.916105e+01 -1.800675e+01 ## greensp -5.464395e-04 3.468840e-04 7.498473e-04 1.081365e-03 1.660609e-03 ## population -8.718853e-03 -7.542340e-03 -6.897453e-03 -6.200430e-03 -4.988964e-03 ## museums -6.078241e+01 -5.205170e+01 -4.542701e+01 -3.995038e+01 -3.145765e+01 ## airbnb 2.844778e-01 4.953275e-01 6.164306e-01 7.496283e-01 9.872352e-01 res_2 <- hsar(res.formula,data=model.data,W=W,M=NULL,Delta=Delta,burnin=500, Nsim=1000) ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value summary(res_2) ## ## Call: ## hsar(formula = res.formula, data = model.data, W = W, M = NULL, ## Delta = Delta, burnin = 500, Nsim = 1000) ## Type: hsar with lambda = 0 ## ## Coefficients: ## Mean SD ## (Intercept) 1.880293e+03 9.970170e+00 ## size 4.271588e+00 4.581010e-01 ## age -1.995568e+01 1.295576e+00 ## greensp 9.672711e-04 6.581401e-04 ## population -9.434666e-03 2.083913e-03 ## museums -4.545286e+01 1.035321e+01 ## airbnb 5.415177e-01 1.964108e-01 ## ## Spatial Coefficients: ## rho ## 0.19122 ## ## Diagnostics ## Deviance information criterion (DIC): 28196.99 ## Effective number of parameters (pd): -1.752399 ## Log likelihood: -14100.25 ## Pseudo R squared: 0.3597633 ## ## Quantiles: ## 5% 25% 50% 75% 95% ## (Intercept) 1.864332e+03 1.873364e+03 1.880298e+03 1.886796e+03 1.896416e+03 ## size 3.550689e+00 3.944261e+00 4.254099e+00 4.559823e+00 5.073155e+00 ## age -2.192657e+01 -2.079846e+01 -1.995871e+01 -1.909676e+01 -1.780104e+01 ## greensp 3.886899e-05 5.256176e-04 8.835621e-04 1.378462e-03 2.197482e-03 ## population -1.282486e-02 -1.074985e-02 -9.589800e-03 -8.107401e-03 -6.107883e-03 ## museums -6.271483e+01 -5.293104e+01 -4.448211e+01 -3.801137e+01 -2.948482e+01 ## airbnb 2.208243e-01 4.100049e-01 5.411334e-01 6.705060e-01 8.635070e-01"},{"path":"https://spatlyu.github.io/HSAR/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Guanpeng Dong. Author, copyright holder. Wenbo Lv. Author, maintainer. Richard Harris. Author. Angelos Mimis. Author.","code":""},{"path":"https://spatlyu.github.io/HSAR/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Dong, Guanpeng, Harris, Richard (2014). “Spatial Autoregressive Models Geographically Hierarchical Data Structures.” Geographical Analysis, 47(2), 173–191. doi:10.1111/gean.12049.","code":"@Article{, title = {Spatial Autoregressive Models for Geographically Hierarchical Data Structures}, journal = {Geographical Analysis}, volume = {47}, number = {2}, pages = {173–191}, year = {2014}, publisher = {Wiley}, author = {{Dong} and {Guanpeng} and {Harris} and {Richard}}, doi = {10.1111/gean.12049}, }"},{"path":"https://spatlyu.github.io/HSAR/index.html","id":"hsar","dir":"","previous_headings":"","what":"Hierarchical Spatial Autoregressive Model","title":"Hierarchical Spatial Autoregressive Model","text":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","code":""},{"path":"https://spatlyu.github.io/HSAR/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Hierarchical Spatial Autoregressive Model","text":"Install CRAN : Install development binary version R-universe : Install development source version GitHub :","code":"install.packages(\"HSAR\", dep = TRUE) install.packages('HSAR', repos = c(\"https://spatlyu.r-universe.dev\", \"https://cloud.r-project.org\"), dep = TRUE) if (!requireNamespace(\"devtools\")) { install.packages(\"devtools\") } devtools::install_github(\"SpatLyu/HSAR\", build_vignettes = TRUE, dep = TRUE)"},{"path":"https://spatlyu.github.io/HSAR/reference/Beijingdistricts.html","id":null,"dir":"Reference","previous_headings":"","what":"Boundaries of districts in Beijing — Beijingdistricts","title":"Boundaries of districts in Beijing — Beijingdistricts","text":"Boundaries districts Beijing","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/Beijingdistricts.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Boundaries of districts in Beijing — Beijingdistricts","text":"","code":"Beijingdistricts"},{"path":"https://spatlyu.github.io/HSAR/reference/Beijingdistricts.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Boundaries of districts in Beijing — Beijingdistricts","text":"object class sf (inherits data.frame) 111 rows 2 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":null,"dir":"Reference","previous_headings":"","what":"Municipality departments of Athens — depmunic","title":"Municipality departments of Athens — depmunic","text":"Municipality departments Athens","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Municipality departments of Athens — depmunic","text":"","code":"depmunic"},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Municipality departments of Athens — depmunic","text":"object class sf (inherits data.frame) 7 rows 8 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Municipality departments of Athens — depmunic","text":"sf object 7 polygons following 7 variables: num_dep unique identifier municipality department. airbnb number airbnb properties 2017 museums number museums population population recorded census 2011. pop_rest number citizens origin non european country. greensp area green spaces (unit: square meters). area area polygon (unit: square kilometers).","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":null,"dir":"Reference","previous_headings":"","what":"Hierarchical SAR model estimation — hsar","title":"Hierarchical SAR model estimation — hsar","text":"specification HSAR model follows: $$y_{,j} = \\rho *\\mathbf{W}_i *\\mathbf{y} + \\mathbf{x}^\\prime_{,j} * \\mathbf{\\beta} + \\mathbf{z}^\\prime_j * \\mathbf{\\gamma} + \\theta_j + \\epsilon_{,j} $$ $$\\theta_j = \\lambda * \\mathbf{M}_j * \\mathbf{\\theta} + \\mu_j $$ $$\\epsilon_{,j} \\sim N(0,\\sigma_e^2), \\hspace{2cm} \\mu_j \\sim N(0,\\sigma_u^2)$$ \\(=1,2,...,n_j\\) \\(j=1,2,...,J\\) indicators lower- higher-level spatial units. \\(n_j\\) number lower-level units \\(j-th\\) higher level unit \\(\\sum_{j=1}^J=\\mathbf{N}\\). \\(\\mathbf{x}^\\prime_{,j}\\) \\(\\mathbf{z}^\\prime_j\\) represent vectors lower- higher-level independent variables. \\(\\mathbf{\\beta}\\) \\(\\mathbf{\\gamma}\\) regression coefficients estimate. \\(\\mathbf{\\theta}\\), \\(N \\times J\\) vector higher-level random effects, also follows simultaneous autoregressive process. \\(\\mathbf{W}\\) \\(\\mathbf{M}\\) two spatial weights matrices (neighbourhood connection matrices) lower higher levels, defining spatial units level connected. \\(\\rho\\) \\(\\lambda\\) two spatial autoregressive parameters measuring strength dependencies/correlations two spatial scales. succinct matrix formulation model , $$\\mathbf{y} = \\rho * \\mathbf{W} * \\mathbf{y} + \\mathbf{X} * \\mathbf{\\beta} + \\mathbf{Z} * \\mathbf{\\gamma} + \\Delta * \\mathbf{\\theta} + \\mathbf{\\epsilon} $$ $$\\mathbf{\\theta} = \\lambda * \\mathbf{M} * \\mathbf{\\theta} + \\mathbf{\\mu}$$ also useful note HSAR model nests standard (random intercept) multilevel model model \\(\\rho\\) \\(\\lambda\\) equal zero standard spaital econometric model \\(\\lambda\\) \\(\\sigma^2_u\\) equal zero.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Hierarchical SAR model estimation — hsar","text":"","code":"hsar( formula, data = NULL, W = NULL, M = NULL, Delta, burnin = 5000, Nsim = 10000, thinning = 1, parameters.start = NULL )"},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Hierarchical SAR model estimation — hsar","text":"formula symbolic description model fit. formula covariate part model using syntax lm() function fitting standard linear regression models. Neither response variable explanatory variables allowed contain NA values. data data.frame containing variables used formula object. W N N lower-level spatial weights matrix neighbourhood matrix N total number lower-level spatial units. formulation W based geographical distances separating units based geographical contiguity. ensure maximum value spatial autoregressive parameter \\(\\rho\\) less 1, W row-normalised running HSAR model. cases, spatial weights matrix sparse, therefore W converted sparse matrix imported hsar() function save computational burden reduce computing time. specifically, W column-oriented numeric sparse matrices dgCMatrix class defined Matrix package. converion dense numeric matrix sparse numeric matrix made quite convenient Matrixlibrary. M J J higher-level spatial weights matrix neighbourhood matrix J total number higher-level spatial units. Similar W, formulation M based geographical distances separating units based geographical contiguity. ensure maximum value spatial autoregressive parameter \\(\\lambda\\) less 1, M also row-normalised running HSAR model. W, M also column-oriented numeric sparse matrices. Delta N J random effect design matrix links J 1 higher-level random effect vector back N 1 response variable investigation. simply lower-level units grouped high-level units columns matrix higher-level units. W M, \\(\\delta\\) also column-oriented numeric sparse matrices. burnin number MCMC samples discard burnin period. Nsim total number MCMC samples generate. thinning MCMC thinning factor. parameters.start list names \"rho\", \"lambda\", \"sigma2e\", \"sigma2u\" \"beta\" corresponding initial values model parameters \\(\\rho, \\lambda, \\sigma^2_e, \\sigma^2_u\\) regression coefficients respectively.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Hierarchical SAR model estimation — hsar","text":"list. cbetas matrix MCMC samples draws coefficients. Mbetas vector estimated mean values regression coefficients. SDbetas standard deviations estimated regression coefficients. Mrho estimated mean lower-level spatial autoregressive parameter \\(\\rho\\). SDrho standard deviation estimated lower-level spatial autoregressive parameter. Mlamda estimated mean higher-level spatial autoregressive parameter \\(\\lambda\\). SDlambda standard deviation estimated higher-level spatial autoregressive parameter. Msigma2e estimated mean lower-level variance parameter \\(\\sigma^2_e\\). SDsigma2e standard deviation estimated lower-level variance parameter \\(\\sigma^{2}_{e} \\). Msigma2u estimated mean higher-level variance parameter \\(\\sigma^2_u\\). SDsigma2u standard deviation estimated higher-level variance parameter \\(\\sigma^2_u\\). Mus Mean values \\(\\theta\\) SDus Standard deviation \\(\\theta\\) DIC deviance information criterion (DIC) fitted model. pd effective number parameters fitted model. Log_Likelihood log-likelihood fitted model. R_Squared pseudo R square model fit indicator. impact_direct Summaries direct impact covariate effect outcome variable. impact_idirect Summaries indirect impact covariate effect outcome variable. impact_total Summaries total impact covariate effect outcome variable.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Hierarchical SAR model estimation — hsar","text":"order use hsar() function, users need specify two spatial weights matrices W M random effect design matrix \\(\\delta\\). However, easy extract spatial weights matrices spatial data using package spdep. Geographic distance-based contiguity-based spatial weights matrix spatial points data spatial polygons data available spdep package. extraction W M, better first sort data using higher-level unit identifier. , random effect design matrix can extracted simply (see following example) two spatial weights matrices. Make sure order higher-level units weights matrix M line \\(\\delta\\) matrix. Two simpler versions HSAR model can also fitted using hsar() function. first HSAR model \\(\\lambda\\) equal zero, indicating assumption independence higher-level random effect \\(\\mathbf{\\theta}\\). second HSAR \\(\\rho\\) equal zero, indicating independence assumption outcome variable conditioning hgiher-level random effect. model useful situations interested neighbourhood/contextual effect individual's outcomes good reasons suspect effect geographical contexts upon individuals dependent. Meanwhile information lower-level units connnected.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Hierarchical SAR model estimation — hsar","text":"Dong, G. Harris, R. 2015. Spatial Autoregressive Models Geographically Hierarchical Data Structures. Geographical Analysis, 47:173-191. LeSage, J. P., R. K. Pace. (2009). Introduction Spatial Econometrics. Boca Raton, FL: CRC Press/Taylor & Francis.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Hierarchical SAR model estimation — hsar","text":"","code":"library(spdep) #> Loading required package: spData #> 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: sf #> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE # Running the hsar() function using the Beijing land price data data(landprice) # load shapefiles of Beijing districts and land parcels data(Beijingdistricts) data(land) plot(Beijingdistricts,border=\"green\") plot(land,add=TRUE,col=\"red\",pch=16,cex=0.8) #> Warning: ignoring all but the first attribute # Define the random effect matrix model.data <- landprice[order(landprice$district.id),] head(model.data,50) #> 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.75110 #> 2 992 7.45757 9.20029 9.84785 7.78904 6.95662 7.05138 0.548966 10.75110 #> 3 189 5.57430 10.27820 9.94866 6.83023 7.06579 6.81916 0.548966 10.75110 #> 4 993 7.12569 7.97788 9.84388 7.81991 7.00792 7.11267 0.548966 10.75110 #> 5 969 6.81564 5.81928 9.91940 7.64640 6.88254 4.10025 0.548966 10.75110 #> 6 994 7.48522 7.78634 9.84203 7.83398 7.03089 7.13981 0.548966 10.75110 #> 7 968 7.61282 8.94551 9.91779 7.64360 6.84364 4.60356 0.548966 10.75110 #> 8 1001 5.87349 10.70910 9.95534 7.89121 7.11019 5.67984 0.548966 10.75110 #> 9 970 6.93528 7.71869 9.91752 7.65810 6.86760 4.53460 0.548966 10.75110 #> 10 990 7.33226 9.56638 9.92978 7.04352 7.14927 6.05410 1.407250 2.25832 #> 11 184 7.63495 8.28041 9.92761 6.72229 6.50598 6.10753 1.407250 2.25832 #> 12 991 7.71761 9.11156 9.91618 7.18259 7.07855 6.16031 1.407250 2.25832 #> 13 183 6.79302 6.39403 9.92025 6.76006 6.23524 6.10494 1.407250 2.25832 #> 14 975 6.44927 7.76908 9.92113 6.89202 6.38918 5.88140 1.407250 2.25832 #> 15 510 8.36696 9.86256 9.89898 7.34607 7.10587 6.61334 1.407250 2.25832 #> 16 976 7.26088 6.53771 9.92084 6.96297 6.45627 5.63952 1.407250 2.25832 #> 17 305 6.57806 10.32370 9.70741 7.18129 7.95357 6.68403 0.941242 0.00000 #> 18 48 8.94133 8.89344 9.76620 6.57319 7.46929 7.09027 0.941242 0.00000 #> 19 544 5.76832 7.56743 9.68472 7.07977 8.05148 5.94517 0.941242 0.00000 #> 20 1002 5.91562 9.84392 9.74486 7.08293 7.92710 5.87879 2.866570 2.08476 #> 21 1003 5.85396 9.57639 9.74538 7.19933 7.96247 6.22910 2.866570 2.08476 #> 22 191 7.04490 10.48240 9.75845 7.14172 7.86279 6.09166 2.866570 2.08476 #> 23 1004 7.22372 10.23640 9.70496 7.63960 8.26740 7.16855 2.866570 2.08476 #> 24 187 7.46123 9.15915 9.71533 7.57044 8.21326 7.11444 2.866570 2.08476 #> 25 995 6.16533 9.13465 9.64341 6.36002 8.27941 6.92502 2.866570 2.08476 #> 26 640 9.65128 11.31550 9.71856 6.64810 7.96881 6.00015 2.866570 2.08476 #> 27 185 6.75336 11.54640 9.72137 6.40432 7.92675 6.01485 2.866570 2.08476 #> 28 186 6.75782 9.88451 9.71611 7.62061 8.23178 7.18594 2.866570 2.08476 #> 29 542 6.81431 8.54922 9.63861 7.18116 8.37391 6.38286 2.866570 2.08476 #> 30 165 7.80049 9.00639 9.15882 7.95475 7.32233 6.79457 2.296760 8.92581 #> 31 155 8.45877 9.14783 9.12435 7.70243 7.12462 6.95931 2.296760 8.92581 #> 32 157 8.45267 8.09617 9.12652 7.65767 7.06754 6.98893 2.296760 8.92581 #> 33 79 8.56406 5.29616 9.12581 7.77669 7.20131 6.83696 2.296760 8.92581 #> 34 112 8.41125 7.89692 9.02285 7.52898 7.60357 5.66579 2.296760 8.92581 #> 35 158 8.92698 8.33687 9.13184 7.64895 7.02301 7.02868 2.296760 8.92581 #> 36 884 7.55678 7.85011 9.11186 7.81621 7.34735 6.58003 2.296760 8.92581 #> 37 1 8.63880 10.97180 9.03807 7.38706 7.50760 5.61153 2.296760 8.92581 #> 38 164 7.53140 10.01800 9.01294 7.72827 7.64932 5.87202 2.296760 8.92581 #> 39 174 8.22883 9.48070 9.02293 7.48346 7.59182 5.40304 2.296760 8.92581 #> 40 547 9.52909 4.72180 9.18782 8.13285 7.56351 6.35573 2.296760 8.92581 #> 41 156 8.25099 8.96954 9.13146 7.77387 7.16582 6.88552 2.296760 8.92581 #> 42 3 8.11774 9.87884 8.80295 6.76108 5.51591 6.37044 2.625880 2.29662 #> 43 605 7.27915 8.22380 9.00097 5.75406 7.23258 5.80163 2.625880 2.29662 #> 44 137 8.00299 9.20029 8.87777 6.87581 5.62608 5.89557 2.625880 2.29662 #> 45 606 7.05708 9.72113 8.97459 6.19309 7.07984 5.47498 2.625880 2.29662 #> 46 41 9.08469 8.68191 8.50677 4.63046 7.44178 5.96059 1.393050 2.62490 #> 47 138 6.44894 9.42679 8.44812 6.33522 7.36762 5.69235 1.393050 2.62490 #> 48 621 7.87562 3.94158 8.31624 5.63957 7.06336 5.59615 1.393050 2.62490 #> 49 143 8.37008 9.21999 8.39678 6.29016 7.25234 5.99851 1.393050 2.62490 #> 50 147 9.51180 8.13649 8.46924 5.50417 7.35118 5.25879 1.393050 2.62490 #> district.id year #> 1 3 1 #> 2 3 0 #> 3 3 1 #> 4 3 0 #> 5 3 0 #> 6 3 0 #> 7 3 0 #> 8 3 0 #> 9 3 0 #> 10 5 0 #> 11 5 1 #> 12 5 0 #> 13 5 1 #> 14 5 0 #> 15 5 6 #> 16 5 0 #> 17 7 1 #> 18 7 3 #> 19 7 4 #> 20 8 0 #> 21 8 0 #> 22 8 1 #> 23 8 0 #> 24 8 1 #> 25 8 0 #> 26 8 5 #> 27 8 1 #> 28 8 1 #> 29 8 4 #> 30 9 1 #> 31 9 1 #> 32 9 1 #> 33 9 2 #> 34 9 2 #> 35 9 1 #> 36 9 0 #> 37 9 3 #> 38 9 1 #> 39 9 1 #> 40 9 4 #> 41 9 1 #> 42 10 3 #> 43 10 5 #> 44 10 1 #> 45 10 5 #> 46 11 3 #> 47 11 1 #> 48 11 5 #> 49 11 1 #> 50 11 1 # 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(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 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 ) # \\donttest{ res <- hsar(res.formula, data=landprice, W=W, M=M, Delta=Delta, 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 #> 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 summary(res) #> #> Call: #> hsar(formula = res.formula, data = landprice, W = W, M = M, Delta = Delta, #> burnin = 500, Nsim = 1000, thinning = 1, parameters.start = pars) #> Type: hsar #> #> Coefficients: #> Mean SD #> (Intercept) 10.823382203 1.221871043 #> lnarea -0.021329874 0.018183168 #> lndcbd -0.322854608 0.098254836 #> dsubway -0.178585312 0.042194049 #> dpark -0.138172209 0.063856562 #> dele -0.011751765 0.036490094 #> popden 0.021742925 0.013632147 #> crimerate 0.005174869 0.008934741 #> as.factor(year)1 -0.209125116 0.055401487 #> as.factor(year)2 -0.019693758 0.121319935 #> as.factor(year)3 -0.077408600 0.103388835 #> as.factor(year)4 0.738310426 0.122220634 #> as.factor(year)5 0.536615572 0.133706317 #> as.factor(year)6 2.252085264 0.206765301 #> #> Spatial Coefficients: #> rho lambda #> [1,] 0.271906 0.721898 #> #> Diagnostics #> Deviance information criterion (DIC): 5442.945 #> Effective number of parameters (pd): 1394.183 #> Log likelihood: -1327.29 #> Pseudo R squared: 0.4187515 #> #> Impacts: #> direct indirect total #> (Intercept) 10.861415061 3.997941320 14.859356381 #> lnarea -0.021404826 -0.007878830 -0.029283655 #> lndcbd -0.323989104 -0.119256047 -0.443245151 #> dsubway -0.179212852 -0.065965849 -0.245178701 #> dpark -0.138657740 -0.051038056 -0.189695796 #> dele -0.011793060 -0.004340867 -0.016133927 #> popden 0.021819329 0.008031403 0.029850732 #> crimerate 0.005193054 0.001911493 0.007104547 #> as.factor(year)1 -0.209859972 -0.077246643 -0.287106615 #> as.factor(year)2 -0.019762961 -0.007274481 -0.027037442 #> as.factor(year)3 -0.077680610 -0.028593192 -0.106273802 #> as.factor(year)4 0.740904814 0.272717133 1.013621947 #> as.factor(year)5 0.538501214 0.198215080 0.736716294 #> as.factor(year)6 2.259998986 0.831875338 3.091874324 #> #> Quantiles: #> 5% 25% 50% 75% #> (Intercept) 8.892382596 10.018795558 10.773897803 11.620051926 #> lnarea -0.051333621 -0.033551672 -0.022100726 -0.009389147 #> lndcbd -0.490238287 -0.388114452 -0.323298408 -0.256423639 #> dsubway -0.246254692 -0.206408591 -0.182733963 -0.151003580 #> dpark -0.242219541 -0.185569865 -0.139622112 -0.095612120 #> dele -0.076146804 -0.036638809 -0.011648700 0.014138707 #> popden -0.000529679 0.012910910 0.021625150 0.030909393 #> crimerate -0.007668902 -0.001345453 0.005176461 0.011011118 #> as.factor(year)1 -0.299065574 -0.245013902 -0.207679348 -0.172791782 #> as.factor(year)2 -0.213710644 -0.092857276 -0.012155374 0.061563819 #> as.factor(year)3 -0.248086487 -0.147803403 -0.076140168 -0.009761551 #> as.factor(year)4 0.534222455 0.659020178 0.732390014 0.828634462 #> as.factor(year)5 0.324173983 0.448940584 0.538454115 0.616658139 #> as.factor(year)6 1.912667020 2.120298434 2.246687384 2.384850047 #> 95% #> (Intercept) 12.92742581 #> lnarea 0.01010697 #> lndcbd -0.15816522 #> dsubway -0.10048557 #> dpark -0.03042691 #> dele 0.04744300 #> popden 0.04619270 #> crimerate 0.02018651 #> as.factor(year)1 -0.11619380 #> as.factor(year)2 0.18518942 #> as.factor(year)3 0.09040742 #> as.factor(year)4 0.93623133 #> as.factor(year)5 0.75861290 #> as.factor(year)6 2.57297924 # visualise the district level random effect groups <- sdsfun::discretize_vector(res$Mus,n = 4,method = \"natural\") palette <- RColorBrewer::brewer.pal(4, \"Blues\") plot(Beijingdistricts,col=palette[groups],border=\"grey\") # }"},{"path":"https://spatlyu.github.io/HSAR/reference/land.html","id":null,"dir":"Reference","previous_headings":"","what":"The spatial locations of the Beijing land price data — land","title":"The spatial locations of the Beijing land price data — land","text":"spatial locations Beijing land price data","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/land.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The spatial locations of the Beijing land price data — land","text":"","code":"land"},{"path":"https://spatlyu.github.io/HSAR/reference/land.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"The spatial locations of the Beijing land price data — land","text":"object class sf (inherits data.frame) 1117 rows 3 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":null,"dir":"Reference","previous_headings":"","what":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"Leased residential land parcels, 2003 2009 Beijing, China","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"","code":"landprice"},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"object class data.frame 1117 rows 11 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"data.frame 1117 observations following 11 variables. obs unique identifier land parcel. lnprice log leasing price per square metre residential land parcel (unit: RMB, Chinese yuan) dsubway log distance land parcel nearest railway station (unit:meters) dele log distance land parcel nearest elementary school (unit:meters) dpark log distance land parcel nearest green park (unit:meters) lnarea log size land parcel (unit: square meters). lndcbd log distance land parcel CBD (centre business district) Beijing (unit:meters) year year land parcel leased values 0,1,2,3,4,5,6 representing year 2003,2004,2005,2006,2007,2008,2009 popden population density district (unit: 1000 persons per square kilometers) crimerate number reported serious crimes committed district per 1000 persons. district.id identifier district land parcel located.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":null,"dir":"Reference","previous_headings":"","what":"Dataset of properties in the municipality of Athens — properties","title":"Dataset of properties in the municipality of Athens — properties","text":"dataset apartments municipality Athens 2017. Point location properties given together main characteristics distance closest metro/train station.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset of properties in the municipality of Athens — properties","text":"","code":"properties"},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Dataset of properties in the municipality of Athens — properties","text":"object class sf (inherits data.frame) 1000 rows 7 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Dataset of properties in the municipality of Athens — properties","text":"sf object 1000 points following 6 variables. id unique identifier property. size size property (unit: square meters) price asking price (unit: euros) prpsqm asking price per squre meter (unit: euroes/square meter). age Age property 2017 (unit: years). dist_metro distance closest train/metro station (unit: meters).","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":null,"dir":"Reference","previous_headings":"","what":"SAR model estimation — sar","title":"SAR model estimation — sar","text":"sar() function implements standard spatial econometrics model (SAR) spatially lagged dependent variable model using Markov chain Monte Carlo (McMC) simulation approach.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"SAR model estimation — sar","text":"","code":"sar( formula, data = NULL, W, burnin = 5000, Nsim = 10000, thinning = 1, parameters.start = NULL )"},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"SAR model estimation — sar","text":"formula symbolic description model fit. formula covariate part model using syntax stats::lm() function fitting standard linear regression models. Neither response variable explanatory variables allowed contain NA values. data data.frame containing variables used formula object. W N N spatial weights matrix neighbourhood matrix N number spatial units. formulation W based geographical distances separating units based geographical contiguity. ensure maximum value spatial autoregressive parameter \\(\\rho\\) less 1, W usually row-normalised implementing SAR model. cases, spatial weights matrix sparse, therefore W converted sparse matrix imported sar() function save computational burden reduce computing time. specifically, W column-oriented numeric sparse matrices dgCMatrix class defined Matrix package. converion dense numeric matrix sparse numeric matrix made quite convenient Matrix library. burnin number McMC samples discard burnin period. Nsim total number McMC samples generate. thinning MCMC thinning factor. parameters.start list names \"rho\", \"sigma2e\", \"beta\" corresponding initial values model parameters \\(\\rho, \\sigma^2_e\\) regression coefficients respectively.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"SAR model estimation — sar","text":"list. cbetas matrix MCMC samples draws coefficients. Mbetas vector estimated mean values regression coefficients. SDbetas standard deviations estimated regression coefficients. Mrho estimated mean lower-level spatial autoregressive parameter \\(\\rho\\). SDrho standard deviation estimated lower-level spatial autoregressive parameter. Msigma2e estimated mean lower-level variance parameter \\(\\sigma^{2}_{e} \\). SDsigma2e standard deviation estimated lower-level variance parameter \\(\\sigma^{2}_{e} \\). DIC deviance information criterion (DIC) fitted model. pd effective number parameters fitted model. Log_Likelihood log-likelihood fitted model. R_Squared pseudo R square model fit indicator. impact_direct Summaries direct impact covariate effect outcome variable. impact_idirect Summaries indirect impact covariate effect outcome variable. impact_total Summaries total impact covariate effect outcome variable.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"SAR model estimation — sar","text":"Anselin, L. (1988). Spatial Econometrics: Methods Models. Dordrecht: Kluwer Academic Publishers. LeSage, J. P., R. K. Pace. (2009). Introduction Spatial Econometrics. Boca Raton, FL: CRC Press/Taylor & Francis","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"SAR model estimation — sar","text":"","code":"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.692659271 0.821582708 #> lnarea -0.005703754 0.017245283 #> lndcbd -0.093812794 0.048795925 #> dsubway -0.151066147 0.035977010 #> dpark -0.157082432 0.045501847 #> dele -0.029478755 0.031136321 #> popden 0.021820387 0.010123086 #> crimerate 0.006581084 0.004185754 #> as.factor(year)1 -0.188791418 0.055353624 #> as.factor(year)2 -0.028732593 0.117591116 #> as.factor(year)3 -0.141198327 0.106523962 #> as.factor(year)4 0.568283074 0.116757966 #> as.factor(year)5 0.398618141 0.127220897 #> as.factor(year)6 2.183383251 0.218838610 #> #> Spatial Coefficients: #> rho #> 0.544068 #> #> Diagnostics #> Deviance information criterion (DIC): 4704.887 #> Effective number of parameters (pd): 956.0725 #> Log likelihood: -1396.371 #> Pseudo R squared: 0.3487775 #> #> Impacts: #> direct indirect total #> (Intercept) 6.815286826 7.483055987 14.29834281 #> lnarea -0.005808262 -0.006377362 -0.01218562 #> lndcbd -0.095531697 -0.104891996 -0.20042369 #> dsubway -0.153834086 -0.168906916 -0.32274100 #> dpark -0.159960606 -0.175633718 -0.33559432 #> dele -0.030018885 -0.032960168 -0.06297905 #> popden 0.022220195 0.024397354 0.04661755 #> crimerate 0.006701667 0.007358304 0.01405997 #> as.factor(year)1 -0.192250585 -0.211087505 -0.40333809 #> as.factor(year)2 -0.029259052 -0.032125885 -0.06138494 #> as.factor(year)3 -0.143785461 -0.157873715 -0.30165918 #> as.factor(year)4 0.578695551 0.635396766 1.21409232 #> as.factor(year)5 0.405921899 0.445694565 0.85161646 #> as.factor(year)6 2.223388716 2.441238743 4.66462746 #> #> Quantiles: #> 5% 25% 50% 75% #> (Intercept) 5.3931321636 6.102344739 6.667925879 7.261131168 #> lnarea -0.0328579787 -0.017805259 -0.005443984 0.005865107 #> lndcbd -0.1719583291 -0.126473435 -0.094248991 -0.061389837 #> dsubway -0.2086087870 -0.174525097 -0.151688345 -0.127059403 #> dpark -0.2366361542 -0.187072950 -0.157027536 -0.126171278 #> dele -0.0799836946 -0.051391759 -0.029007668 -0.008189104 #> popden 0.0054129196 0.014553396 0.021759805 0.028808175 #> crimerate -0.0004581391 0.003773817 0.006547580 0.009282714 #> as.factor(year)1 -0.2756505015 -0.227269916 -0.190331369 -0.150788147 #> as.factor(year)2 -0.2218306150 -0.106403948 -0.031509779 0.056263472 #> as.factor(year)3 -0.3146393375 -0.212914997 -0.142246504 -0.070137649 #> as.factor(year)4 0.3816845823 0.487045899 0.577141855 0.645571177 #> as.factor(year)5 0.1922468443 0.311307645 0.402879081 0.481189056 #> as.factor(year)6 1.8106568356 2.041326641 2.191568289 2.327773608 #> 95% #> (Intercept) 8.03383299 #> lnarea 0.02201095 #> lndcbd -0.01651091 #> dsubway -0.09292392 #> dpark -0.08466489 #> dele 0.02294826 #> popden 0.03870791 #> crimerate 0.01327714 #> as.factor(year)1 -0.09626197 #> as.factor(year)2 0.15447486 #> as.factor(year)3 0.04359984 #> as.factor(year)4 0.76317569 #> as.factor(year)5 0.60496796 #> as.factor(year)6 2.55235508 # }"},{"path":"https://spatlyu.github.io/HSAR/news/index.html","id":"hsar-060","dir":"Changelog","previous_headings":"","what":"HSAR 0.6.0","title":"HSAR 0.6.0","text":"Resolve CRAN check issues HASR resubmit CRAN.","code":""}] +[{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"an-application-of-hsar-for-asking-prices-in-the-municipality-of-athens","dir":"Articles","previous_headings":"","what":"An application of HSAR for asking prices in the municipality of Athens","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"application hsar(), based rel data, illustrated. design weight matrices needed random effect design matrix explained.","code":""},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"libraries","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Libraries","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"start loading libraries used.","code":"library(sf) library(spdep) library(tidyverse) ## ── Attaching core tidyverse packages ─────────────────────────────────────── tidyverse 2.0.0 ── ## ✔ dplyr 1.1.4 ✔ readr 2.1.5 ## ✔ forcats 1.0.0 ✔ stringr 1.5.1 ## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1 ## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1 ## ✔ purrr 1.0.2 ## ── Conflicts ───────────────────────────────────────────────────────── tidyverse_conflicts() ── ## ✖ tidyr::expand() masks Matrix::expand() ## ✖ dplyr::filter() masks stats::filter() ## ✖ dplyr::lag() masks stats::lag() ## ✖ tidyr::pack() masks Matrix::pack() ## ✖ tidyr::unpack() masks Matrix::unpack() ## ℹ Use the conflicted package () to force all conflicts to become errors library(HSAR)"},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"reading-the-datasets","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Reading the datasets","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"higher level, seven departments municipality Athens lower level point data properties. characteristics come areal data id department, number airbnb properties, number museums, population, number citizens origin non european union country, area green space (m^2) area polygon (km^2). characteristics properties size (m^2), asking price (euros), price per square meter, age (years) shortest distance metro/train station (m). Now going create two variables higher, municipality department, level. first one population density per 10k citizens, second one percentage non EU citizens. next step create model data going use hsar model. , need property (lower data), data relevant department(higher level). now, know property, department resides coresponding data polygon. also need data sorting order.","code":"data(depmunic) data(properties) plot(st_geometry(depmunic),col = sf.colors(12, categorical = TRUE), border = 'grey') plot(st_geometry(properties),add=TRUE,col=\"red\",pch=16,cex=0.6) names(depmunic) ## [1] \"num_dep\" \"airbnb\" \"museums\" \"population\" \"pop_rest\" \"greensp\" \"area\" ## [8] \"geometry\" depmunic$pop_rest ## [1] 8202 5009 2735 4167 5099 16531 8017 names(properties) ## [1] \"id\" \"size\" \"price\" \"prpsqm\" \"age\" \"dist_metro\" \"geometry\" hist(properties$age, xlab = \"Age\", main=\"Age of the properties\") depmunic$popdens <- depmunic$population/ (10000*depmunic$area) depmunic$foreigners <- 100 * depmunic$pop_rest/ depmunic$population properties_in_dd <- st_join(properties, depmunic, join = st_within) model.data <- properties_in_dd[order(properties_in_dd$num_dep),]"},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"create-matrices-used-in-the-hsar-function","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Create matrices used in the hsar function","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":"order run model need create effect design matrix (Delta), weight matrix high-level - polygon data (M), weight matrix lower level - point data (W). order define random effect matrix, start estimating number properties municipality department geting total number municipality departments (7), define vector number municipality department property belongs define random effect matrix (Delta) wich dimension 1000x7 Now estimate spatial weight matrix higher level case municipality departments (polygons). start poly2nb constructs neighbours list polygons nb2mat generate weight matrix neighbours list previously created. transform weight matrix sparse matrix format. closer look M , can visualize Similarly, create spatial weight matrix lower level properties (point data). create neighbour list distance 1300 meters weights matrix W follows W matrix, can check neighbours statistics","code":"properties_count <- count(as_tibble(model.data), num_dep) MM <- as.data.frame(properties_count) Utotal <- dim(MM)[1] Unum <- MM[,2] Uid <- rep(c(1:Utotal),Unum) n <- nrow(properties) Delta <- matrix(0,nrow=n,ncol=Utotal) for(i in 1:Utotal) { Delta[Uid==i,i] <- 1 } Delta <- as(Delta,\"dgCMatrix\") nb.list <- poly2nb(depmunic) mat.list <- nb2mat(nb.list,style=\"W\") M <- as(mat.list,\"dgCMatrix\") plot(st_geometry(depmunic),border = 'grey') plot(st_centroid(depmunic), add = TRUE) ## Warning: st_centroid assumes attributes are constant over geometries ## Warning in plot.sf(st_centroid(depmunic), add = TRUE): ignoring all but the first attribute plot(nb.list, st_centroid(depmunic), add = TRUE) ## Warning: st_centroid assumes attributes are constant over geometries nb.1300 <- dnearneigh(properties,0,1300) mat.1300 <- nb2mat(nb.1300,style=\"W\") W <- as(mat.1300,\"dgCMatrix\") nb.1300 ## Neighbour list object: ## Number of regions: 1000 ## Number of nonzero links: 170254 ## Percentage nonzero weights: 17.0254 ## Average number of links: 170.254"},{"path":"https://spatlyu.github.io/HSAR/articles/HSAR.html","id":"run-the-models","dir":"Articles","previous_headings":"An application of HSAR for asking prices in the municipality of Athens","what":"Run the models","title":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","text":", ready matrices Delta, M W, wun hsar() function two simpler models defined rho = 0 lambda=0. , firstly, assuming rho = 0 (interaction effects lower level) get secondly, given lambda = 0 (interaction higher level) get","code":"res.formula <- prpsqm ~ size + age + greensp + population + museums + airbnb res <- hsar(res.formula,data=model.data,W=W,M=M,Delta=Delta, burnin=500, Nsim=1000) ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value summary(res) ## ## Call: ## hsar(formula = res.formula, data = model.data, W = W, M = M, ## Delta = Delta, burnin = 500, Nsim = 1000) ## Type: hsar ## ## Coefficients: ## Mean SD ## (Intercept) 1.880468e+03 9.835447e+00 ## size 4.298802e+00 5.112041e-01 ## age -1.995687e+01 1.304370e+00 ## greensp 8.404794e-04 8.738884e-04 ## population -9.940391e-03 2.273935e-03 ## museums -4.515772e+01 1.008513e+01 ## airbnb 6.022747e-01 2.496115e-01 ## ## Spatial Coefficients: ## rho lambda ## [1,] 0.196536 0.018432 ## ## Diagnostics ## Deviance information criterion (DIC): 28193.01 ## Effective number of parameters (pd): -1.66553 ## Log likelihood: -14098.17 ## Pseudo R squared: 0.3601049 ## ## Impacts: ## direct indirect total ## (Intercept) 1.881082e+03 4.592335e+02 2.340316e+03 ## size 4.300207e+00 1.049821e+00 5.350028e+00 ## age -1.996339e+01 -4.873715e+00 -2.483711e+01 ## greensp 8.407540e-04 2.052555e-04 1.046009e-03 ## population -9.943639e-03 -2.427567e-03 -1.237121e-02 ## museums -4.517248e+01 -1.102808e+01 -5.620055e+01 ## airbnb 6.024715e-01 1.470830e-01 7.495545e-01 ## ## Quantiles: ## 5% 25% 50% 75% 95% ## (Intercept) 1.864369e+03 1.874059e+03 1.880361e+03 1.887328e+03 1.896080e+03 ## size 3.436255e+00 3.956910e+00 4.291712e+00 4.628642e+00 5.155081e+00 ## age -2.215863e+01 -2.075471e+01 -1.991798e+01 -1.911688e+01 -1.792525e+01 ## greensp -3.546526e-04 2.905312e-04 7.376810e-04 1.261277e-03 2.657171e-03 ## population -1.382163e-02 -1.159143e-02 -9.920309e-03 -8.353503e-03 -6.404121e-03 ## museums -6.148110e+01 -5.224350e+01 -4.495013e+01 -3.850940e+01 -2.847943e+01 ## airbnb 1.776907e-01 4.578970e-01 6.114716e-01 7.457536e-01 1.010643e+00 res_1 <- hsar(res.formula,data=model.data,W=NULL,M=M,Delta=Delta,burnin=500, Nsim=1000) ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value summary(res_1) ## ## Call: ## hsar(formula = res.formula, data = model.data, W = NULL, M = M, ## Delta = Delta, burnin = 500, Nsim = 1000) ## Type: hsar with rho = 0 ## ## Coefficients: ## Mean SD ## (Intercept) 1.880592e+03 1.010450e+01 ## size 4.329009e+00 4.214029e-01 ## age -2.004845e+01 1.258780e+00 ## greensp 6.812935e-04 6.843458e-04 ## population -6.877688e-03 1.100394e-03 ## museums -4.585817e+01 9.479326e+00 ## airbnb 6.288388e-01 2.222552e-01 ## ## Spatial Coefficients: ## lambda ## -0.130888 ## ## Diagnostics ## Deviance information criterion (DIC): 28196.24 ## Effective number of parameters (pd): -1.988165 ## Log likelihood: -14100.11 ## Pseudo R squared: 0.3587056 ## ## Quantiles: ## 5% 25% 50% 75% 95% ## (Intercept) 1.863327e+03 1.874280e+03 1.880446e+03 1.887451e+03 1.897526e+03 ## size 3.648867e+00 4.026734e+00 4.331703e+00 4.647616e+00 5.040309e+00 ## age -2.217344e+01 -2.090501e+01 -2.002926e+01 -1.916105e+01 -1.800675e+01 ## greensp -5.464395e-04 3.468840e-04 7.498473e-04 1.081365e-03 1.660609e-03 ## population -8.718853e-03 -7.542340e-03 -6.897453e-03 -6.200430e-03 -4.988964e-03 ## museums -6.078241e+01 -5.205170e+01 -4.542701e+01 -3.995038e+01 -3.145765e+01 ## airbnb 2.844778e-01 4.953275e-01 6.164306e-01 7.496283e-01 9.872352e-01 res_2 <- hsar(res.formula,data=model.data,W=W,M=NULL,Delta=Delta,burnin=500, Nsim=1000) ## Warning in spdep::mat2listw(W): style is M (missing); style should be set to a valid value ## Warning in sn2listw(df, style = style, zero.policy = zero.policy, from_mat2listw = TRUE): ## style is M (missing); style should be set to a valid value summary(res_2) ## ## Call: ## hsar(formula = res.formula, data = model.data, W = W, M = NULL, ## Delta = Delta, burnin = 500, Nsim = 1000) ## Type: hsar with lambda = 0 ## ## Coefficients: ## Mean SD ## (Intercept) 1.880293e+03 9.970170e+00 ## size 4.271588e+00 4.581010e-01 ## age -1.995568e+01 1.295576e+00 ## greensp 9.672711e-04 6.581401e-04 ## population -9.434666e-03 2.083913e-03 ## museums -4.545286e+01 1.035321e+01 ## airbnb 5.415177e-01 1.964108e-01 ## ## Spatial Coefficients: ## rho ## 0.19122 ## ## Diagnostics ## Deviance information criterion (DIC): 28196.99 ## Effective number of parameters (pd): -1.752399 ## Log likelihood: -14100.25 ## Pseudo R squared: 0.3597633 ## ## Quantiles: ## 5% 25% 50% 75% 95% ## (Intercept) 1.864332e+03 1.873364e+03 1.880298e+03 1.886796e+03 1.896416e+03 ## size 3.550689e+00 3.944261e+00 4.254099e+00 4.559823e+00 5.073155e+00 ## age -2.192657e+01 -2.079846e+01 -1.995871e+01 -1.909676e+01 -1.780104e+01 ## greensp 3.886899e-05 5.256176e-04 8.835621e-04 1.378462e-03 2.197482e-03 ## population -1.282486e-02 -1.074985e-02 -9.589800e-03 -8.107401e-03 -6.107883e-03 ## museums -6.271483e+01 -5.293104e+01 -4.448211e+01 -3.801137e+01 -2.948482e+01 ## airbnb 2.208243e-01 4.100049e-01 5.411334e-01 6.705060e-01 8.635070e-01"},{"path":"https://spatlyu.github.io/HSAR/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Guanpeng Dong. Author, copyright holder. Wenbo Lv. Author, maintainer. Richard Harris. Author. Angelos Mimis. Author.","code":""},{"path":"https://spatlyu.github.io/HSAR/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Dong, Guanpeng, Harris, Richard (2014). “Spatial Autoregressive Models Geographically Hierarchical Data Structures.” Geographical Analysis, 47(2), 173–191. doi:10.1111/gean.12049.","code":"@Article{, title = {Spatial Autoregressive Models for Geographically Hierarchical Data Structures}, journal = {Geographical Analysis}, volume = {47}, number = {2}, pages = {173–191}, year = {2014}, publisher = {Wiley}, author = {{Dong} and {Guanpeng} and {Harris} and {Richard}}, doi = {10.1111/gean.12049}, }"},{"path":"https://spatlyu.github.io/HSAR/index.html","id":"hsar","dir":"","previous_headings":"","what":"Hierarchical Spatial Autoregressive Model","title":"Hierarchical Spatial Autoregressive Model","text":"Hierarchical Spatial Simultaneous Autoregressive Model (HSAR)","code":""},{"path":"https://spatlyu.github.io/HSAR/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Hierarchical Spatial Autoregressive Model","text":"Install CRAN : Install development binary version R-universe : Install development source version GitHub :","code":"install.packages(\"HSAR\", dep = TRUE) install.packages('HSAR', repos = c(\"https://spatlyu.r-universe.dev\", \"https://cloud.r-project.org\"), dep = TRUE) if (!requireNamespace(\"devtools\")) { install.packages(\"devtools\") } devtools::install_github(\"SpatLyu/HSAR\", build_vignettes = TRUE, dep = TRUE)"},{"path":"https://spatlyu.github.io/HSAR/reference/Beijingdistricts.html","id":null,"dir":"Reference","previous_headings":"","what":"Boundaries of districts in Beijing — Beijingdistricts","title":"Boundaries of districts in Beijing — Beijingdistricts","text":"Boundaries districts Beijing","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/Beijingdistricts.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Boundaries of districts in Beijing — Beijingdistricts","text":"","code":"Beijingdistricts"},{"path":"https://spatlyu.github.io/HSAR/reference/Beijingdistricts.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Boundaries of districts in Beijing — Beijingdistricts","text":"object class sf (inherits data.frame) 111 rows 2 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":null,"dir":"Reference","previous_headings":"","what":"Municipality departments of Athens — depmunic","title":"Municipality departments of Athens — depmunic","text":"Municipality departments Athens","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Municipality departments of Athens — depmunic","text":"","code":"depmunic"},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Municipality departments of Athens — depmunic","text":"object class sf (inherits data.frame) 7 rows 8 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/depmunic.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Municipality departments of Athens — depmunic","text":"sf object 7 polygons following 7 variables: num_dep unique identifier municipality department. airbnb number airbnb properties 2017 museums number museums population population recorded census 2011. pop_rest number citizens origin non european country. greensp area green spaces (unit: square meters). area area polygon (unit: square kilometers).","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":null,"dir":"Reference","previous_headings":"","what":"Hierarchical SAR model estimation — hsar","title":"Hierarchical SAR model estimation — hsar","text":"specification HSAR model follows: $$y_{,j} = \\rho *\\mathbf{W}_i *\\mathbf{y} + \\mathbf{x}^\\prime_{,j} * \\mathbf{\\beta} + \\mathbf{z}^\\prime_j * \\mathbf{\\gamma} + \\theta_j + \\epsilon_{,j} $$ $$\\theta_j = \\lambda * \\mathbf{M}_j * \\mathbf{\\theta} + \\mu_j $$ $$\\epsilon_{,j} \\sim N(0,\\sigma_e^2), \\hspace{2cm} \\mu_j \\sim N(0,\\sigma_u^2)$$ \\(=1,2,...,n_j\\) \\(j=1,2,...,J\\) indicators lower- higher-level spatial units. \\(n_j\\) number lower-level units \\(j-th\\) higher level unit \\(\\sum_{j=1}^J=\\mathbf{N}\\). \\(\\mathbf{x}^\\prime_{,j}\\) \\(\\mathbf{z}^\\prime_j\\) represent vectors lower- higher-level independent variables. \\(\\mathbf{\\beta}\\) \\(\\mathbf{\\gamma}\\) regression coefficients estimate. \\(\\mathbf{\\theta}\\), \\(N \\times J\\) vector higher-level random effects, also follows simultaneous autoregressive process. \\(\\mathbf{W}\\) \\(\\mathbf{M}\\) two spatial weights matrices (neighbourhood connection matrices) lower higher levels, defining spatial units level connected. \\(\\rho\\) \\(\\lambda\\) two spatial autoregressive parameters measuring strength dependencies/correlations two spatial scales. succinct matrix formulation model , $$\\mathbf{y} = \\rho * \\mathbf{W} * \\mathbf{y} + \\mathbf{X} * \\mathbf{\\beta} + \\mathbf{Z} * \\mathbf{\\gamma} + \\Delta * \\mathbf{\\theta} + \\mathbf{\\epsilon} $$ $$\\mathbf{\\theta} = \\lambda * \\mathbf{M} * \\mathbf{\\theta} + \\mathbf{\\mu}$$ also useful note HSAR model nests standard (random intercept) multilevel model model \\(\\rho\\) \\(\\lambda\\) equal zero standard spaital econometric model \\(\\lambda\\) \\(\\sigma^2_u\\) equal zero.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Hierarchical SAR model estimation — hsar","text":"","code":"hsar( formula, data = NULL, W = NULL, M = NULL, Delta, burnin = 5000, Nsim = 10000, thinning = 1, parameters.start = NULL )"},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Hierarchical SAR model estimation — hsar","text":"formula symbolic description model fit. formula covariate part model using syntax lm() function fitting standard linear regression models. Neither response variable explanatory variables allowed contain NA values. data data.frame containing variables used formula object. W N N lower-level spatial weights matrix neighbourhood matrix N total number lower-level spatial units. formulation W based geographical distances separating units based geographical contiguity. ensure maximum value spatial autoregressive parameter \\(\\rho\\) less 1, W row-normalised running HSAR model. cases, spatial weights matrix sparse, therefore W converted sparse matrix imported hsar() function save computational burden reduce computing time. specifically, W column-oriented numeric sparse matrices dgCMatrix class defined Matrix package. converion dense numeric matrix sparse numeric matrix made quite convenient Matrixlibrary. M J J higher-level spatial weights matrix neighbourhood matrix J total number higher-level spatial units. Similar W, formulation M based geographical distances separating units based geographical contiguity. ensure maximum value spatial autoregressive parameter \\(\\lambda\\) less 1, M also row-normalised running HSAR model. W, M also column-oriented numeric sparse matrices. Delta N J random effect design matrix links J 1 higher-level random effect vector back N 1 response variable investigation. simply lower-level units grouped high-level units columns matrix higher-level units. W M, \\(\\delta\\) also column-oriented numeric sparse matrices. burnin number MCMC samples discard burnin period. Nsim total number MCMC samples generate. thinning MCMC thinning factor. parameters.start list names \"rho\", \"lambda\", \"sigma2e\", \"sigma2u\" \"beta\" corresponding initial values model parameters \\(\\rho, \\lambda, \\sigma^2_e, \\sigma^2_u\\) regression coefficients respectively.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Hierarchical SAR model estimation — hsar","text":"list. cbetas matrix MCMC samples draws coefficients. Mbetas vector estimated mean values regression coefficients. SDbetas standard deviations estimated regression coefficients. Mrho estimated mean lower-level spatial autoregressive parameter \\(\\rho\\). SDrho standard deviation estimated lower-level spatial autoregressive parameter. Mlamda estimated mean higher-level spatial autoregressive parameter \\(\\lambda\\). SDlambda standard deviation estimated higher-level spatial autoregressive parameter. Msigma2e estimated mean lower-level variance parameter \\(\\sigma^2_e\\). SDsigma2e standard deviation estimated lower-level variance parameter \\(\\sigma^{2}_{e} \\). Msigma2u estimated mean higher-level variance parameter \\(\\sigma^2_u\\). SDsigma2u standard deviation estimated higher-level variance parameter \\(\\sigma^2_u\\). Mus Mean values \\(\\theta\\) SDus Standard deviation \\(\\theta\\) DIC deviance information criterion (DIC) fitted model. pd effective number parameters fitted model. Log_Likelihood log-likelihood fitted model. R_Squared pseudo R square model fit indicator. impact_direct Summaries direct impact covariate effect outcome variable. impact_idirect Summaries indirect impact covariate effect outcome variable. impact_total Summaries total impact covariate effect outcome variable.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"note","dir":"Reference","previous_headings":"","what":"Note","title":"Hierarchical SAR model estimation — hsar","text":"order use hsar() function, users need specify two spatial weights matrices W M random effect design matrix \\(\\delta\\). However, easy extract spatial weights matrices spatial data using package spdep. Geographic distance-based contiguity-based spatial weights matrix spatial points data spatial polygons data available spdep package. extraction W M, better first sort data using higher-level unit identifier. , random effect design matrix can extracted simply (see following example) two spatial weights matrices. Make sure order higher-level units weights matrix M line \\(\\delta\\) matrix. Two simpler versions HSAR model can also fitted using hsar() function. first HSAR model \\(\\lambda\\) equal zero, indicating assumption independence higher-level random effect \\(\\mathbf{\\theta}\\). second HSAR \\(\\rho\\) equal zero, indicating independence assumption outcome variable conditioning hgiher-level random effect. model useful situations interested neighbourhood/contextual effect individual's outcomes good reasons suspect effect geographical contexts upon individuals dependent. Meanwhile information lower-level units connnected.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Hierarchical SAR model estimation — hsar","text":"Dong, G. Harris, R. 2015. Spatial Autoregressive Models Geographically Hierarchical Data Structures. Geographical Analysis, 47:173-191. LeSage, J. P., R. K. Pace. (2009). Introduction Spatial Econometrics. Boca Raton, FL: CRC Press/Taylor & Francis.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/hsar.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Hierarchical SAR model estimation — hsar","text":"","code":"library(spdep) #> Loading required package: spData #> 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: sf #> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.4.0; sf_use_s2() is TRUE # Running the hsar() function using the Beijing land price data data(landprice) # load shapefiles of Beijing districts and land parcels data(Beijingdistricts) data(land) plot(Beijingdistricts,border=\"green\") plot(land,add=TRUE,col=\"red\",pch=16,cex=0.8) #> Warning: ignoring all but the first attribute # Define the random effect matrix model.data <- landprice[order(landprice$district.id),] head(model.data,50) #> 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.75110 #> 2 992 7.45757 9.20029 9.84785 7.78904 6.95662 7.05138 0.548966 10.75110 #> 3 189 5.57430 10.27820 9.94866 6.83023 7.06579 6.81916 0.548966 10.75110 #> 4 993 7.12569 7.97788 9.84388 7.81991 7.00792 7.11267 0.548966 10.75110 #> 5 969 6.81564 5.81928 9.91940 7.64640 6.88254 4.10025 0.548966 10.75110 #> 6 994 7.48522 7.78634 9.84203 7.83398 7.03089 7.13981 0.548966 10.75110 #> 7 968 7.61282 8.94551 9.91779 7.64360 6.84364 4.60356 0.548966 10.75110 #> 8 1001 5.87349 10.70910 9.95534 7.89121 7.11019 5.67984 0.548966 10.75110 #> 9 970 6.93528 7.71869 9.91752 7.65810 6.86760 4.53460 0.548966 10.75110 #> 10 990 7.33226 9.56638 9.92978 7.04352 7.14927 6.05410 1.407250 2.25832 #> 11 184 7.63495 8.28041 9.92761 6.72229 6.50598 6.10753 1.407250 2.25832 #> 12 991 7.71761 9.11156 9.91618 7.18259 7.07855 6.16031 1.407250 2.25832 #> 13 183 6.79302 6.39403 9.92025 6.76006 6.23524 6.10494 1.407250 2.25832 #> 14 975 6.44927 7.76908 9.92113 6.89202 6.38918 5.88140 1.407250 2.25832 #> 15 510 8.36696 9.86256 9.89898 7.34607 7.10587 6.61334 1.407250 2.25832 #> 16 976 7.26088 6.53771 9.92084 6.96297 6.45627 5.63952 1.407250 2.25832 #> 17 305 6.57806 10.32370 9.70741 7.18129 7.95357 6.68403 0.941242 0.00000 #> 18 48 8.94133 8.89344 9.76620 6.57319 7.46929 7.09027 0.941242 0.00000 #> 19 544 5.76832 7.56743 9.68472 7.07977 8.05148 5.94517 0.941242 0.00000 #> 20 1002 5.91562 9.84392 9.74486 7.08293 7.92710 5.87879 2.866570 2.08476 #> 21 1003 5.85396 9.57639 9.74538 7.19933 7.96247 6.22910 2.866570 2.08476 #> 22 191 7.04490 10.48240 9.75845 7.14172 7.86279 6.09166 2.866570 2.08476 #> 23 1004 7.22372 10.23640 9.70496 7.63960 8.26740 7.16855 2.866570 2.08476 #> 24 187 7.46123 9.15915 9.71533 7.57044 8.21326 7.11444 2.866570 2.08476 #> 25 995 6.16533 9.13465 9.64341 6.36002 8.27941 6.92502 2.866570 2.08476 #> 26 640 9.65128 11.31550 9.71856 6.64810 7.96881 6.00015 2.866570 2.08476 #> 27 185 6.75336 11.54640 9.72137 6.40432 7.92675 6.01485 2.866570 2.08476 #> 28 186 6.75782 9.88451 9.71611 7.62061 8.23178 7.18594 2.866570 2.08476 #> 29 542 6.81431 8.54922 9.63861 7.18116 8.37391 6.38286 2.866570 2.08476 #> 30 165 7.80049 9.00639 9.15882 7.95475 7.32233 6.79457 2.296760 8.92581 #> 31 155 8.45877 9.14783 9.12435 7.70243 7.12462 6.95931 2.296760 8.92581 #> 32 157 8.45267 8.09617 9.12652 7.65767 7.06754 6.98893 2.296760 8.92581 #> 33 79 8.56406 5.29616 9.12581 7.77669 7.20131 6.83696 2.296760 8.92581 #> 34 112 8.41125 7.89692 9.02285 7.52898 7.60357 5.66579 2.296760 8.92581 #> 35 158 8.92698 8.33687 9.13184 7.64895 7.02301 7.02868 2.296760 8.92581 #> 36 884 7.55678 7.85011 9.11186 7.81621 7.34735 6.58003 2.296760 8.92581 #> 37 1 8.63880 10.97180 9.03807 7.38706 7.50760 5.61153 2.296760 8.92581 #> 38 164 7.53140 10.01800 9.01294 7.72827 7.64932 5.87202 2.296760 8.92581 #> 39 174 8.22883 9.48070 9.02293 7.48346 7.59182 5.40304 2.296760 8.92581 #> 40 547 9.52909 4.72180 9.18782 8.13285 7.56351 6.35573 2.296760 8.92581 #> 41 156 8.25099 8.96954 9.13146 7.77387 7.16582 6.88552 2.296760 8.92581 #> 42 3 8.11774 9.87884 8.80295 6.76108 5.51591 6.37044 2.625880 2.29662 #> 43 605 7.27915 8.22380 9.00097 5.75406 7.23258 5.80163 2.625880 2.29662 #> 44 137 8.00299 9.20029 8.87777 6.87581 5.62608 5.89557 2.625880 2.29662 #> 45 606 7.05708 9.72113 8.97459 6.19309 7.07984 5.47498 2.625880 2.29662 #> 46 41 9.08469 8.68191 8.50677 4.63046 7.44178 5.96059 1.393050 2.62490 #> 47 138 6.44894 9.42679 8.44812 6.33522 7.36762 5.69235 1.393050 2.62490 #> 48 621 7.87562 3.94158 8.31624 5.63957 7.06336 5.59615 1.393050 2.62490 #> 49 143 8.37008 9.21999 8.39678 6.29016 7.25234 5.99851 1.393050 2.62490 #> 50 147 9.51180 8.13649 8.46924 5.50417 7.35118 5.25879 1.393050 2.62490 #> district.id year #> 1 3 1 #> 2 3 0 #> 3 3 1 #> 4 3 0 #> 5 3 0 #> 6 3 0 #> 7 3 0 #> 8 3 0 #> 9 3 0 #> 10 5 0 #> 11 5 1 #> 12 5 0 #> 13 5 1 #> 14 5 0 #> 15 5 6 #> 16 5 0 #> 17 7 1 #> 18 7 3 #> 19 7 4 #> 20 8 0 #> 21 8 0 #> 22 8 1 #> 23 8 0 #> 24 8 1 #> 25 8 0 #> 26 8 5 #> 27 8 1 #> 28 8 1 #> 29 8 4 #> 30 9 1 #> 31 9 1 #> 32 9 1 #> 33 9 2 #> 34 9 2 #> 35 9 1 #> 36 9 0 #> 37 9 3 #> 38 9 1 #> 39 9 1 #> 40 9 4 #> 41 9 1 #> 42 10 3 #> 43 10 5 #> 44 10 1 #> 45 10 5 #> 46 11 3 #> 47 11 1 #> 48 11 5 #> 49 11 1 #> 50 11 1 # 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(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 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 ) # \\donttest{ res <- hsar(res.formula, data=landprice, W=W, M=M, Delta=Delta, 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 #> 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 summary(res) #> #> Call: #> hsar(formula = res.formula, data = landprice, W = W, M = M, Delta = Delta, #> burnin = 500, Nsim = 1000, thinning = 1, parameters.start = pars) #> Type: hsar #> #> Coefficients: #> Mean SD #> (Intercept) 10.823382203 1.221871043 #> lnarea -0.021329874 0.018183168 #> lndcbd -0.322854608 0.098254836 #> dsubway -0.178585312 0.042194049 #> dpark -0.138172209 0.063856562 #> dele -0.011751765 0.036490094 #> popden 0.021742925 0.013632147 #> crimerate 0.005174869 0.008934741 #> as.factor(year)1 -0.209125116 0.055401487 #> as.factor(year)2 -0.019693758 0.121319935 #> as.factor(year)3 -0.077408600 0.103388835 #> as.factor(year)4 0.738310426 0.122220634 #> as.factor(year)5 0.536615572 0.133706317 #> as.factor(year)6 2.252085264 0.206765301 #> #> Spatial Coefficients: #> rho lambda #> [1,] 0.271906 0.721898 #> #> Diagnostics #> Deviance information criterion (DIC): 5442.945 #> Effective number of parameters (pd): 1394.183 #> Log likelihood: -1327.29 #> Pseudo R squared: 0.4187515 #> #> Impacts: #> direct indirect total #> (Intercept) 10.861415061 3.997941320 14.859356381 #> lnarea -0.021404826 -0.007878830 -0.029283655 #> lndcbd -0.323989104 -0.119256047 -0.443245151 #> dsubway -0.179212852 -0.065965849 -0.245178701 #> dpark -0.138657740 -0.051038056 -0.189695796 #> dele -0.011793060 -0.004340867 -0.016133927 #> popden 0.021819329 0.008031403 0.029850732 #> crimerate 0.005193054 0.001911493 0.007104547 #> as.factor(year)1 -0.209859972 -0.077246643 -0.287106615 #> as.factor(year)2 -0.019762961 -0.007274481 -0.027037442 #> as.factor(year)3 -0.077680610 -0.028593192 -0.106273802 #> as.factor(year)4 0.740904814 0.272717133 1.013621947 #> as.factor(year)5 0.538501214 0.198215080 0.736716294 #> as.factor(year)6 2.259998986 0.831875338 3.091874324 #> #> Quantiles: #> 5% 25% 50% 75% #> (Intercept) 8.892382596 10.018795558 10.773897803 11.620051926 #> lnarea -0.051333621 -0.033551672 -0.022100726 -0.009389147 #> lndcbd -0.490238287 -0.388114452 -0.323298408 -0.256423639 #> dsubway -0.246254692 -0.206408591 -0.182733963 -0.151003580 #> dpark -0.242219541 -0.185569865 -0.139622112 -0.095612120 #> dele -0.076146804 -0.036638809 -0.011648700 0.014138707 #> popden -0.000529679 0.012910910 0.021625150 0.030909393 #> crimerate -0.007668902 -0.001345453 0.005176461 0.011011118 #> as.factor(year)1 -0.299065574 -0.245013902 -0.207679348 -0.172791782 #> as.factor(year)2 -0.213710644 -0.092857276 -0.012155374 0.061563819 #> as.factor(year)3 -0.248086487 -0.147803403 -0.076140168 -0.009761551 #> as.factor(year)4 0.534222455 0.659020178 0.732390014 0.828634462 #> as.factor(year)5 0.324173983 0.448940584 0.538454115 0.616658139 #> as.factor(year)6 1.912667020 2.120298434 2.246687384 2.384850047 #> 95% #> (Intercept) 12.92742581 #> lnarea 0.01010697 #> lndcbd -0.15816522 #> dsubway -0.10048557 #> dpark -0.03042691 #> dele 0.04744300 #> popden 0.04619270 #> crimerate 0.02018651 #> as.factor(year)1 -0.11619380 #> as.factor(year)2 0.18518942 #> as.factor(year)3 0.09040742 #> as.factor(year)4 0.93623133 #> as.factor(year)5 0.75861290 #> as.factor(year)6 2.57297924 # visualise the district level random effect groups <- sdsfun::discretize_vector(res$Mus,n = 4,method = \"natural\") palette <- RColorBrewer::brewer.pal(4, \"Blues\") plot(Beijingdistricts,col=palette[groups],border=\"grey\") # }"},{"path":"https://spatlyu.github.io/HSAR/reference/land.html","id":null,"dir":"Reference","previous_headings":"","what":"The spatial locations of the Beijing land price data — land","title":"The spatial locations of the Beijing land price data — land","text":"spatial locations Beijing land price data","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/land.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"The spatial locations of the Beijing land price data — land","text":"","code":"land"},{"path":"https://spatlyu.github.io/HSAR/reference/land.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"The spatial locations of the Beijing land price data — land","text":"object class sf (inherits data.frame) 1117 rows 3 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":null,"dir":"Reference","previous_headings":"","what":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"Leased residential land parcels, 2003 2009 Beijing, China","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"","code":"landprice"},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"object class data.frame 1117 rows 11 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/landprice.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Leased residential land parcels, from 2003 to 2009 in Beijing, China — landprice","text":"data.frame 1117 observations following 11 variables. obs unique identifier land parcel. lnprice log leasing price per square metre residential land parcel (unit: RMB, Chinese yuan) dsubway log distance land parcel nearest railway station (unit:meters) dele log distance land parcel nearest elementary school (unit:meters) dpark log distance land parcel nearest green park (unit:meters) lnarea log size land parcel (unit: square meters). lndcbd log distance land parcel CBD (centre business district) Beijing (unit:meters) year year land parcel leased values 0,1,2,3,4,5,6 representing year 2003,2004,2005,2006,2007,2008,2009 popden population density district (unit: 1000 persons per square kilometers) crimerate number reported serious crimes committed district per 1000 persons. district.id identifier district land parcel located.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":null,"dir":"Reference","previous_headings":"","what":"Dataset of properties in the municipality of Athens — properties","title":"Dataset of properties in the municipality of Athens — properties","text":"dataset apartments municipality Athens 2017. Point location properties given together main characteristics distance closest metro/train station.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Dataset of properties in the municipality of Athens — properties","text":"","code":"properties"},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"Dataset of properties in the municipality of Athens — properties","text":"object class sf (inherits data.frame) 1000 rows 7 columns.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/properties.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Dataset of properties in the municipality of Athens — properties","text":"sf object 1000 points following 6 variables. id unique identifier property. size size property (unit: square meters) price asking price (unit: euros) prpsqm asking price per squre meter (unit: euroes/square meter). age Age property 2017 (unit: years). dist_metro distance closest train/metro station (unit: meters).","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":null,"dir":"Reference","previous_headings":"","what":"SAR model estimation — sar","title":"SAR model estimation — sar","text":"sar() function implements standard spatial econometrics model (SAR) spatially lagged dependent variable model using Markov chain Monte Carlo (McMC) simulation approach.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"SAR model estimation — sar","text":"","code":"sar( formula, data = NULL, W, burnin = 5000, Nsim = 10000, thinning = 1, parameters.start = NULL )"},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"SAR model estimation — sar","text":"formula symbolic description model fit. formula covariate part model using syntax stats::lm() function fitting standard linear regression models. Neither response variable explanatory variables allowed contain NA values. data data.frame containing variables used formula object. W N N spatial weights matrix neighbourhood matrix N number spatial units. formulation W based geographical distances separating units based geographical contiguity. ensure maximum value spatial autoregressive parameter \\(\\rho\\) less 1, W usually row-normalised implementing SAR model. cases, spatial weights matrix sparse, therefore W converted sparse matrix imported sar() function save computational burden reduce computing time. specifically, W column-oriented numeric sparse matrices dgCMatrix class defined Matrix package. converion dense numeric matrix sparse numeric matrix made quite convenient Matrix library. burnin number McMC samples discard burnin period. Nsim total number McMC samples generate. thinning MCMC thinning factor. parameters.start list names \"rho\", \"sigma2e\", \"beta\" corresponding initial values model parameters \\(\\rho, \\sigma^2_e\\) regression coefficients respectively.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"SAR model estimation — sar","text":"list. cbetas matrix MCMC samples draws coefficients. Mbetas vector estimated mean values regression coefficients. SDbetas standard deviations estimated regression coefficients. Mrho estimated mean lower-level spatial autoregressive parameter \\(\\rho\\). SDrho standard deviation estimated lower-level spatial autoregressive parameter. Msigma2e estimated mean lower-level variance parameter \\(\\sigma^{2}_{e} \\). SDsigma2e standard deviation estimated lower-level variance parameter \\(\\sigma^{2}_{e} \\). DIC deviance information criterion (DIC) fitted model. pd effective number parameters fitted model. Log_Likelihood log-likelihood fitted model. R_Squared pseudo R square model fit indicator. impact_direct Summaries direct impact covariate effect outcome variable. impact_idirect Summaries indirect impact covariate effect outcome variable. impact_total Summaries total impact covariate effect outcome variable.","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"SAR model estimation — sar","text":"Anselin, L. (1988). Spatial Econometrics: Methods Models. Dordrecht: Kluwer Academic Publishers. LeSage, J. P., R. K. Pace. (2009). Introduction Spatial Econometrics. Boca Raton, FL: CRC Press/Taylor & Francis","code":""},{"path":"https://spatlyu.github.io/HSAR/reference/sar.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"SAR model estimation — sar","text":"","code":"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.692659271 0.821582708 #> lnarea -0.005703754 0.017245283 #> lndcbd -0.093812794 0.048795925 #> dsubway -0.151066147 0.035977010 #> dpark -0.157082432 0.045501847 #> dele -0.029478755 0.031136321 #> popden 0.021820387 0.010123086 #> crimerate 0.006581084 0.004185754 #> as.factor(year)1 -0.188791418 0.055353624 #> as.factor(year)2 -0.028732593 0.117591116 #> as.factor(year)3 -0.141198327 0.106523962 #> as.factor(year)4 0.568283074 0.116757966 #> as.factor(year)5 0.398618141 0.127220897 #> as.factor(year)6 2.183383251 0.218838610 #> #> Spatial Coefficients: #> rho #> 0.544068 #> #> Diagnostics #> Deviance information criterion (DIC): 4704.887 #> Effective number of parameters (pd): 956.0725 #> Log likelihood: -1396.371 #> Pseudo R squared: 0.3487775 #> #> Impacts: #> direct indirect total #> (Intercept) 6.815286826 7.483055987 14.29834281 #> lnarea -0.005808262 -0.006377362 -0.01218562 #> lndcbd -0.095531697 -0.104891996 -0.20042369 #> dsubway -0.153834086 -0.168906916 -0.32274100 #> dpark -0.159960606 -0.175633718 -0.33559432 #> dele -0.030018885 -0.032960168 -0.06297905 #> popden 0.022220195 0.024397354 0.04661755 #> crimerate 0.006701667 0.007358304 0.01405997 #> as.factor(year)1 -0.192250585 -0.211087505 -0.40333809 #> as.factor(year)2 -0.029259052 -0.032125885 -0.06138494 #> as.factor(year)3 -0.143785461 -0.157873715 -0.30165918 #> as.factor(year)4 0.578695551 0.635396766 1.21409232 #> as.factor(year)5 0.405921899 0.445694565 0.85161646 #> as.factor(year)6 2.223388716 2.441238743 4.66462746 #> #> Quantiles: #> 5% 25% 50% 75% #> (Intercept) 5.3931321636 6.102344739 6.667925879 7.261131168 #> lnarea -0.0328579787 -0.017805259 -0.005443984 0.005865107 #> lndcbd -0.1719583291 -0.126473435 -0.094248991 -0.061389837 #> dsubway -0.2086087870 -0.174525097 -0.151688345 -0.127059403 #> dpark -0.2366361542 -0.187072950 -0.157027536 -0.126171278 #> dele -0.0799836946 -0.051391759 -0.029007668 -0.008189104 #> popden 0.0054129196 0.014553396 0.021759805 0.028808175 #> crimerate -0.0004581391 0.003773817 0.006547580 0.009282714 #> as.factor(year)1 -0.2756505015 -0.227269916 -0.190331369 -0.150788147 #> as.factor(year)2 -0.2218306150 -0.106403948 -0.031509779 0.056263472 #> as.factor(year)3 -0.3146393375 -0.212914997 -0.142246504 -0.070137649 #> as.factor(year)4 0.3816845823 0.487045899 0.577141855 0.645571177 #> as.factor(year)5 0.1922468443 0.311307645 0.402879081 0.481189056 #> as.factor(year)6 1.8106568356 2.041326641 2.191568289 2.327773608 #> 95% #> (Intercept) 8.03383299 #> lnarea 0.02201095 #> lndcbd -0.01651091 #> dsubway -0.09292392 #> dpark -0.08466489 #> dele 0.02294826 #> popden 0.03870791 #> crimerate 0.01327714 #> as.factor(year)1 -0.09626197 #> as.factor(year)2 0.15447486 #> as.factor(year)3 0.04359984 #> as.factor(year)4 0.76317569 #> as.factor(year)5 0.60496796 #> as.factor(year)6 2.55235508 # }"},{"path":"https://spatlyu.github.io/HSAR/news/index.html","id":"hsar-060","dir":"Changelog","previous_headings":"","what":"HSAR 0.6.0","title":"HSAR 0.6.0","text":"CRAN release: 2024-12-23 Resolve CRAN check issues HASR resubmit CRAN.","code":""}]