Title: | Dynamic ICAR Spatiotemporal Factor Models |
---|---|
Description: | Bayesian factor models are effective tools for dimension reduction. This is especially applicable to multivariate large-scale datasets. It allows researchers to understand the latent factors of the data which are the linear or non-linear combination of the variables. Dynamic Intrinsic Conditional Autocorrelative Priors (ICAR) Spatiotemporal Factor Models 'DIFM' package provides function to run Markov Chain Monte Carlo (MCMC), evaluation methods and visual plots from Shin and Ferreira (2023)<doi:10.1016/j.spasta.2023.100763>. Our method is a class of Bayesian factor model which can account for spatial and temporal correlations. By incorporating these correlations, the model can capture specific behaviors and provide predictions. |
Authors: | Hwasoo Shin [aut, cre], Marco Ferreira [aut] |
Maintainer: | Hwasoo Shin <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0 |
Built: | 2024-11-09 06:39:44 UTC |
Source: | CRAN |
Bayesian factor models are effective tools for dimension reduction. This is especially applicable to multivariate large-scale datasets. It allows researchers to understand the latent factors of the data which are the linear or non-linear combination of the variables. Dynamic Intrinsic Conditional Autocorrelative Priors (ICAR) Spatiotemporal Factor Models 'DIFM' package provides function to run Markov Chain Monte Carlo (MCMC), evaluation methods and visual plots from Shin and Ferreira (2023)<doi:10.1016/j.spasta.2023.100763>. Our method is a class of Bayesian factor model which can account for spatial and temporal correlations. By incorporating these correlations, the model can capture specific behaviors and provide predictions.
Package: BCFM2
Type: Package
Version: 1.0
Date: 2023-02-20
License: GPL(>=2)
Hwasoo Shin [aut, cre], Marco Ferreira [aut]
Maintainer: Hwasoo Shin <[email protected]>
Shin, H. and Ferreira, M. (2023). "Dynamic ICAR Spatiotemporal Factor Models." Spatial Statistics, 56, 100763
Lopes, H. and West, M. (2004). “Bayesian Model Assessment in Factor Analysis.” Statistica Sinica, 14, 41–67.
Prado, R., Ferreira, M. A. R., and West, M. (2021). Time Series: Modeling, Computation, and Inference. 2nd ed. Boca Raton: CRC Press.
It computes the spatial covariance and precision matrix of the neighboring subregions using Intrinsice Autoregressive Conditional (ICAR) process.
buildH(areapoly, permutation = NA)
buildH(areapoly, permutation = NA)
areapoly |
The polygon of the areas. We can obtain this through |
permutation |
Permutation order of the subregions |
The off-digonal values are -1 when two subregions are neighbors. Otherwise, we assign 0. The diagonal values are the sum of the values of its own row.
A list of two matrices: Precision matrix H and the covariance matrix obtained through Moore-Penrose inverse of H.
Sets the hyperparameters to generate Gibbs sampler of DIFM
difm.hyp.parm( model.attributes, n.tau = 2.2, n.s2.tau = 0.1, n.sigma = 2.2, n.s2.sigma = 0.1, Hlist, Psi.size = 0.01 )
difm.hyp.parm( model.attributes, n.tau = 2.2, n.s2.tau = 0.1, n.sigma = 2.2, n.s2.sigma = 0.1, Hlist, Psi.size = 0.01 )
model.attributes |
Model attributes from |
n.tau |
Shape parameter for tau |
n.s2.tau |
Rate parameter for tau |
n.sigma |
Shape parameter for sigma squared |
n.s2.sigma |
Rate parameter for sigma squared |
Hlist |
Neighborhood matrix |
Psi.size |
The magnitude of covariance for the evolution matrix |
A list of hyperparameters of tau, W, sigma, and theta.
It initialize the basic parameters and model attributes for DIFM
difm.model.attributes(data, n.iter, n.factors, G0)
difm.model.attributes(data, n.iter, n.factors, G0)
data |
The dataset |
n.iter |
Number of iterations |
n.factors |
Number of factors to run DIFM |
G0 |
The basic evolution matrix for one factor |
A list of number of timepoints, subregions, factors, matrix of evolution matrix, and matrix to extract common factors.
This function runs Dynamic ICAR factors Model (DIFM), simulated from C++ codes
DIFMcpp(model.attributes, hyp.parm, data, every = 1, verbose = TRUE)
DIFMcpp(model.attributes, hyp.parm, data, every = 1, verbose = TRUE)
model.attributes |
Model attributes from |
hyp.parm |
Hyperparameters from |
data |
The dataset |
every |
Save |
verbose |
Print out the iteration process |
The Gibbs sampler of DIFM
This function runs Dynamic ICAR factors Model (DIFM)
DIFMR(model.attributes, hyp.parm, data, every = 1, verbose = TRUE)
DIFMR(model.attributes, hyp.parm, data, every = 1, verbose = TRUE)
model.attributes |
Model attributes from |
hyp.parm |
Hyperparameters from |
data |
The dataset |
every |
Save |
verbose |
Print out the iteration process |
The Gibbs sampler of DIFM
It calculates the marginal density (Lewis and Raftery, 1997) from the DIFM sample using C++.
marginal_d_cpp(data, attributes, hyp_parm, Gibbs, burnin = -1L, verbose = TRUE)
marginal_d_cpp(data, attributes, hyp_parm, Gibbs, burnin = -1L, verbose = TRUE)
data |
The dataset |
attributes |
Model attributes generated from |
hyp_parm |
Hyperparameters generated from |
Gibbs |
Result of Gibbs sampler from DIFM function. |
burnin |
Burn-in period. If not specified, one tenths of the iterations will be the burn-in period. |
verbose |
Print out the process. |
A list of 4 items: Laplace-Metropolis predictive density of the given DIFM, integrated likelihood, the maximum of the predictive densities and determinant of the covariance matrix of the parameters.
It calculates the marginal density (Lewis and Raftery, 1997) from the DIFM sample using R.
marginal.d( data, model.attributes, hyp.parm, Gibbs, burnin = NA, verbose = TRUE )
marginal.d( data, model.attributes, hyp.parm, Gibbs, burnin = NA, verbose = TRUE )
data |
The dataset |
model.attributes |
Model attributes generated from |
hyp.parm |
Hyperparameters generated from |
Gibbs |
Result of Gibbs sampler from DIFM function. |
burnin |
Burn-in period. If not specified, one tenths of the iterations will be the burn-in period. |
verbose |
Print out the iteration process. |
Metropolis-Laplace estimator of the Marginal density
It finds the vector of permutation to permute data by its largest absolute value in each eigenvector. It sets the order by specified number of factors, and the rest is ordered as they were.
permutation.order(data, n.factors)
permutation.order(data, n.factors)
data |
The dataset |
n.factors |
Number of factors |
The numeric vector of permutation
It finds the vector of permutation to permute data by its largest absolute value in each eigenvector. It sets the order by specified number of factors, and the rest is ordered as they were. The data is permuted, and if needed, scaled.
permutation.scale(data, n.factors, return.scale = FALSE)
permutation.scale(data, n.factors, return.scale = FALSE)
data |
The dataset |
n.factors |
Number of factors |
return.scale |
Scale data after permutation |
The permuted and standardized dataset, either in matrix or array.
The functions builds a column-wise plots of factor loadings. The parameters fixed at 1 are displayed with red dashed vertical lines.
plot_B.CI( Gibbs, true.val = NA, burnin = NA, permutation = NA, main.bool = TRUE, layout.dim = NA )
plot_B.CI( Gibbs, true.val = NA, burnin = NA, permutation = NA, main.bool = TRUE, layout.dim = NA )
Gibbs |
Result of Gibbs sampler from DIFM function |
true.val |
True values of factor loadings. If not available, NA. |
burnin |
Number of burn-in. If not specified, it uses the first tenths as burn-in period. |
permutation |
Permutation of variables. If not specified, no permutation. |
main.bool |
Add title of the plots. |
layout.dim |
Dimension of panel layout for multiple factor loadings. If not specificed, factor loadings plots are layout in one column. |
Factor loadings credible interval plots
The functions builds maps of factor loadings.
plot_B.spatial( Gibbs, areapoly, burnin = NA, permutation = NA, main.bool = TRUE, layout.dim = NA )
plot_B.spatial( Gibbs, areapoly, burnin = NA, permutation = NA, main.bool = TRUE, layout.dim = NA )
Gibbs |
Result of Gibbs sampler from DIFM function. |
areapoly |
The polygon of the areas. We can obtain this through |
burnin |
Number of burn-in. If not specified, it uses the first tenths as burn-in period. |
permutation |
Permutation of variables. If not specified, no permutation. |
main.bool |
Add title of the plots. |
layout.dim |
Dimension of panel layout for multiple factor loadings. If not specificed, factor loadings plots are layout in one column. |
Factor loadings map plots
It returns a credible interval plot of idiosyncratic variance, sigma squared. The lines are 95
plot_sigma2.CI(Gibbs, burnin = NA, permutation = NA, main.bool = TRUE)
plot_sigma2.CI(Gibbs, burnin = NA, permutation = NA, main.bool = TRUE)
Gibbs |
Result of Gibbs sampler from DIFM function. |
burnin |
Number of burn-in. If not specified, it uses the first tenths as burn-in period. |
permutation |
Permutation of variables. If not specified, no permutation. |
main.bool |
Add title of the plots. |
A credible interval plot of sigma squared
It returns a credible interval plot of factor loadings covariance, tau. The lines are 95
plot_tau.CI(Gibbs, burnin = NA, true.val = NA, main.bool = TRUE)
plot_tau.CI(Gibbs, burnin = NA, true.val = NA, main.bool = TRUE)
Gibbs |
Result of Gibbs sampler from DIFM function. |
burnin |
Number of burn-in. If not specified, it uses the first tenths as burn-in period. |
true.val |
True values of tau. If not available, NA. |
main.bool |
Add title of the plots. |
Credible interval plot of tau
The functions builds the plot of 95% confidence intervals of the common realizations, X. The black solid lines are the posterior mean and the dased lines are the 95% confidence intervals.
plot_X.CI(Gibbs, burnin = NA, main.bool = FALSE, layout.dim = NA)
plot_X.CI(Gibbs, burnin = NA, main.bool = FALSE, layout.dim = NA)
Gibbs |
Result of Gibbs sampler from DIFM function. |
burnin |
Number of burn-in. If not specified, it uses the first tenths as burn-in period. |
main.bool |
Add title of the plots. |
layout.dim |
Dimension of panel layout for multiple common factors. If not specificed, common factor plots are layout in one column. |
Credible interval plots of common factors
A subset of data of property crime per 100,000 people in western states from 1960 to 2019.
Property
Property
## 'Property' A data frame with 60 rows and 11 columns:
Arizona
California
Colorado
Idaho
Montana
Nevada
New Mexico
Oregon
Utah
Washington
Wyoming
...
<https://www.disastercenter.com/crime/>
A subset of data of violent crime per 100,000 people in western states from 1960 to 2019.
Violent
Violent
## 'Violent' A data frame with 60 rows and 11 columns:
Arizona
California
Colorado
Idaho
Montana
Nevada
New Mexico
Oregon
Utah
Washington
Wyoming
...
<https://www.disastercenter.com/crime/>
A sp map data of the western states in United States
WestStates
WestStates
## 'WestStates' A SpatialPolygonsDataFrame data of the western states in United States
The number ID of the western states
Abbreviations of the state names
Names of the states
A SpatialPolygonsDataFrame data of the western states in United States
<https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html>