Skip to content

zhenhua-wang/vmsae

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VMSAE

Installation

Install the lastest develop version

devtools::install_github("zhenhua-wang/vmsae")

Basic Usage

Load the package

library(vmsae)

Install the python environment

install_environment()

Load the python environment

load_environment()

Download the pretrained model

download_pretrained_vae(model_name = "mo_county", save_dir = "./datasets")

Train VGMSFH using numpyro. Note that y and y_sigma are N by k matrix, where N represents the number of locations and k is the number of response variables. GEOID represents FIPS codes or other equivalent identifiers. W is the adjacency matrix.

model <- vgmsfh_numpyro(y, y_sigma, X, W,
  GEOID = GEOID,
  model_name = "mo_county", save_dir = "./datasets",
  num_samples = 10000, num_warmup = 10000)

Plot the estimation result

plot(model, type = "compare")

plot/compare.png

For multivariate models, we can select a response variable to plot with var_idx

plot(model, type = "compare", var_idx = 2)

plot/compare2.png

We can also plot the mean and standard deviation of the estimation

plot(model, type = "estimate", var_idx = 1)

plot/estimate.png

Train VAE

For advanced user, the following command can be used to train your own generator for spatial random effects. The resulting VAE is saved to the folder ./model.

loss <- train_vae(W = W,
  GEOID = GEOID,
  model_name = "mo_county",
  save_dir = "./model",
  n_samples = 10000,
  batch_size = 256,
  epoch = 10000)

Here, W is the adjacency matrix of your geography, which can be produced with spdep package. For example,

W <- nb2mat(poly2nb(mo_county_data), style = "B", zero.policy = TRUE)

About

Auto-Encoding Variational Multivariate Small Area Estimation

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published