Learn R Programming

estimateW

This is the development repository of the R package estimateW.

Features

The package provides methods to estimate spatial weight matrices in spatial autoregressive type models.

Install CRAN Version

Type into your R session:

install.packages("estimateW")

For more information, please visit the CRAN page of the package.

Install Latest Development Version

Type into your R session:

if (!require("remotes")) {
  install.packages("remotes")
}
remotes::install_github(
  repo = "https://github.com/tkrisztin/estimateW")

Demonstration

# Load the package
library(estimateW)
require(dplyr)

tt = length(unique(covid$date))
n = length(unique(covid$ISO3))

# reorder by date and longitude
covid = covid %>% 
  arrange(date, LON) %>%
  mutate(date = as.factor(date))
  
# Benchmark specification from Krisztin and Piribauer (2022) SEA
Y = as.matrix(covid$infections_pc - covid$infections_pc_lag)
X = model.matrix(~infections_pc_lag + stringency_2weekly + 
                   precipProbability + temperatureMax + ISO3 + as.factor(date) + 0,data = covid)

# use a flat prior for W
flat_W_prior = W_priors(n = n,nr_neighbors_prior = rep(1/n,n))

# Estimate a Bayesian model using covid infections data
res = sarw(Y = Y,tt = tt,Z = X,niter = 200,nretain = 50,
           W_prior = flat_W_prior)
           
# Plot the posterior of the spatial weight matrix
dimnames(res$postw)[[2]] = dimnames(res$postw)[[1]] = covid$ISO3[1:n]
plot(res,font=3,cex.axis=0.75,las=2)

References

Tamás Krisztin & Philipp Piribauer (2022) A Bayesian approach for the estimation of weight matrices in spatial autoregressive models, Spatial Economic Analysis, DOI: 10.1080/17421772.2022.2095426

Copy Link

Version

Install

install.packages('estimateW')

Monthly Downloads

176

Version

0.1.0

License

GPL (>= 3)

Maintainer

Tamas Krisztin

Last Published

May 13th, 2025

Functions in estimateW (0.1.0)

nuts1growth

Regional growth data
sar

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial autoregressive model (SAR) with exogenous spatial weight matrix.
sarw

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial autoregressive model (SAR) with unknown spatial weight matrix
plot.estimateW

Graphical summary of the estimated adjacency matrix \(\Omega\)
rho_sampler

An R6 class for sampling the spatial autoregressive parameter \(\rho\)
sdem

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial Durbin error model (SDEM) with exogenous spatial weight matrix.
sdm

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial Durbin model (SDM) with exogenous spatial weight matrix.
rho_priors

Specify prior for the spatial autoregressive parameter and sampling settings
plot.sim_dgp

Graphical summary of a generated spatial weight matrix
sdemw

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial Durbin error model (SDEM) with unknown spatial weight matrix
sigma_sampler

An R6 class for sampling for sampling \(\sigma^2\)
sim_dgp

Simulating from a data generating process
slxw

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial SLX model with unknown spatial weight matrix
semw

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial error model (SEM) with unknown spatial weight matrix
sdmw

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial Durbin model (SDM) with unknown spatial weight matrix
sigma_priors

Set prior specification for the error variance using an inverse Gamma distribution
sem

A Markov Chain Monte Carlo (MCMC) sampler for the panel spatial error model (SEM) with exogenous spatial weight matrix.
beta_priors

Set prior specifications for the slope parameters
W_priors

Set prior specifications for the spatial weight matrix
logdetPaceBarry

Pace and Barry's log determinant approximation
bbinompdf

Probability density for a hierarchical prior setup for the elements of the adjacency matrix based on the beta binomial distribution
covid

Covid incidences data
betapdf

The four-parameter Beta probability density function
logdetAinvUpdate

Efficient update of the log-determinant and the matrix inverse
normalgamma

A Markov Chain Monte Carlo (MCMC) sampler for a linear panel model
beta_sampler

An R6 class for sampling slope parameters
W_sampler

An R6 class for sampling the elements of \(W\)