Install the lastest develop version
devtools::install_github("zhenhua-wang/vmsae")
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")
For multivariate models, we can select a response variable to plot with var_idx
plot(model, type = "compare", var_idx = 2)
We can also plot the mean and standard deviation of the estimation
plot(model, type = "estimate", var_idx = 1)
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)


