knitr::opts_chunk$set(echo = TRUE)
dimstar
is an R package implementing a novel MCEM algorithm for estimating latent-Guassian spatio-temporal autoregressive models for potentially multivariate binary and count outcomes.
Install dimstar straight from github:
require(devtools) devtools::install_github('hunzikp/dimstar')
NOTE: This is a development version; documentation is pending. The package assumes that Python (2.7 / 3.6) and scipy are installed on your machine.
In the following, we replicate the county-level Spatial Probit analysis of the 1996 presidential elections reported in Section 5.1 of Liesenfeld et al. (2016). The outcome is a dummy indicating whether a county was won by Democratic candidate Bill Clinton.
## Dependencies library(spdep) library(Matrix) library(dimstar) ## Prepare W coords <- as.matrix(elections.df[,c("lon" ,"lat")]) el_knn <- knearneigh(coords, k = 6, longlat = TRUE) el_nb <- knn2nb(knn = el_knn, sym = TRUE) W <- nb2mat(el_nb, style = "W") W <- Matrix(W, sparse = TRUE) ## Prepare X X <- model.matrix(clinton ~ log_urban + prop_smcollege + prop_associate + prop_college + prop_gradprof, data = elections.df) ## Instantiate model object X.ls <- list(X) y.ls <- list(elections.df$clinton) model <- DISTAR$new(X.ls = X.ls, y.ls = y.ls, W_t = W, N = nrow(X), G = 1, TT = 1, count = FALSE, spatial_dep = TRUE, temporal_dep = FALSE, outcome_dep = FALSE) ## Train set.seed(0) ch_vec <- model$train(maxiter = 15, M = 50, abs_tol = 1e-4, verbose = TRUE) ## Standard errors model$compute_vcov(M = 100) ## Report model$coeftest()
Note that the estimates are near-identical to the ones reported by Liesenfeld et al. (2016).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.