| MRPWorkflow | R Documentation |
A MRPWorkflow object is an R6 object created by
the mrp_workflow() function. This class provides methods for all steps
in the workflow, from data preparation and visualization to model fitting.
MRPWorkflow objects have the following associated
methods with their own (linked) documentation pages:
| Method | Description |
$preprocess() | Preprocess sample data. |
$preprocessed_data() | Return preprocessed sample data. |
$link_acs() | Link sample data to ACS data. |
$load_pstrat() | Load custom poststratification data. |
| Method | Description |
$create_model() | Create a MRPModel object. |
$pp_check() | Perform posterior predictive check. |
$compare_models() | Compare models using LOO-CV. |
| Method | Description |
$demo_bars() | Create demographic comparison bar plots. |
$covar_hist() | Create geographic covariate distribution histograms. |
$sample_size_map() | Create sample size map. |
$outcome_plot() | Create summary plots of raw outcome measure. |
$outcome_map() | Visualize raw outcome measure by geography. |
$estimate_plot() | Visualize estimates for demographic groups. |
$estimate_map() | Visualize estimates for geographic areas. |
library(shinymrp)
# Initialize the MRP workflow
workflow <- mrp_workflow()
# Load example data
sample_data <- example_sample_data()
### DATA PREPARATION
# Preprocess sample data
workflow$preprocess(
sample_data,
is_timevar = TRUE,
is_aggregated = TRUE,
special_case = NULL,
family = "binomial"
)
# Link data to the ACS
# and obtain poststratification data
workflow$link_acs(
link_geo = "zip",
acs_year = 2021
)
### DESCRIPTIVE STATISTICS
# Visualize demographic distribution of data
sex_bars <- workflow$demo_bars(demo = "sex")
# Visualize geographic distribution of data
ss_map <- workflow$sample_size_map()
# Visualize outcome measure
raw_outcome_plot <- workflow$outcome_plot()
### MODEL BUILDING
# Create new model objects
model <- workflow$create_model(
intercept_prior = "normal(0, 4)",
fixed = list(
sex = "normal(0, 2)",
race = "normal(0, 2)"
),
varying = list(
age = "",
time = ""
)
)
# Run MCMC
model$fit(n_iter = 500, n_chains = 2, seed = 123)
# Estimates summary and diagnostics
model$summary()
# Sampling diagnostics
model$diagnostics()
# Posterior predictive check
workflow$pp_check(model)
### VISUALIZE RESULTS
# Plots of overall estimates, estimates for demographic groups, and geographic areas
workflow$estimate_plot(model, group = "sex")
# Choropleth map of estimates for geographic areas
workflow$estimate_map(model, geo = "county")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.