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.
Format
An R6 generator object.
Methods
Method new()
Initializes the MRPWorkflow object, setting up necessary fields for data processing and model fitting.
Usage
MRPWorkflow$new()
Method metadata()
Retrieves the metadata associated with the current workflow, including information about time variables, family, and special cases.
Method data()
Retrieves the preprocessed sample data that has been prepared for MRP analysis.
Method preprocess()
Preprocesses the input sample data by cleaning, validating, and preparing it for MRP analysis. This includes handling time-varying data, aggregated data, and special cases.
Usage
MRPWorkflow$preprocess(
data,
is_timevar = FALSE,
is_aggregated = FALSE,
special_case = NULL,
family = NULL,
zip_threshold = 0,
state_threshold = 0
)
Arguments
data
Input sample data to be preprocessed
is_timevar
Logical indicating whether the data contains time-varying components
is_aggregated
Logical indicating whether the data is already aggregated
special_case
Character string specifying special case handling (e.g., "covid", "poll")
family
Character string specifying the model family (e.g., "binomial", "normal")
zip_threshold
Numeric value specifying the minimum number of records required for a ZIP code to be included in the analysis (default is 0)
state_threshold
Numeric value specifying the minimum number of records required for a state to be included in the analysis (default is 0)
Method link_acs()
Links the preprocessed sample data to ACS poststratification data based on geographic and demographic variables.
Method load_pstrat()
Loads and processes custom poststratification data instead of using ACS data. This method validates the data and prepares it for MRP analysis.
Method demo_bars()
Creates bar plots comparing demographic distributions between input survey data and target population data.
Method covar_hist()
Creates histogram plots showing the distribution of geographic covariates across zip codes. Only available for COVID data.
Method sample_size_map()
Creates interactive choropleth maps showing data distribution with respect to geography.
Method outcome_plot()
Creates plots showing the distribution of outcome measures over time (for time-varying data) or as static distributions (for cross-sectional data).
Method outcome_map()
Creates maps showing average outcome measure by geography for cross-sectional data, or highest/lowest weekly average for time-varying data.
Method estimate_plot()
Creates plots showing MRP estimates for different subgroups, either over time (for time-varying data) or as static estimates (for cross-sectional data).
Usage
MRPWorkflow$estimate_plot(
model,
group = NULL,
interval = 0.95,
show_caption = TRUE,
file = NULL,
...
)
Arguments
model
Fitted MRPModel object
group
Character string specifying the demographic group for plotting
interval
Confidence interval or standard deviation for the estimates (default is 0.95)
show_caption
Logical indicating whether to show the caption in the plot (default is TRUE)
file
Optional file path to save the plot
...
Additional arguments passed to ggsave
Method estimate_map()
Creates interactive choropleth maps showing MRP estimates by geographic regions.
Usage
MRPWorkflow$estimate_map(
model,
geo = NULL,
time_index = NULL,
interval = 0.95,
file = NULL,
...
)
Arguments
model
Fitted MRPModel object
geo
Character string specifying the geographic level for mapping
time_index
Numeric value specifying the time index for time-varying data
interval
Confidence interval or standard deviation for the estimates (default is 0.95)
file
Optional file path to save the map
...
Additional arguments
Method create_model()
Creates a new MRPModel object with validated effects specification and prepared data for Bayesian model fitting.
Method pp_check()
Creates posterior predictive check plots to assess model fit by comparing observed data to replicated data from the posterior predictive distribution.
Method compare_models()
Compares multiple fitted MRP models using leave-one-out cross-validation to assess relative model performance.