Skip to contents

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

Returns

A new MRPWorkflow object.


Method metadata()

Retrieves the metadata associated with the current workflow, including information about time variables, family, and special cases.

Usage

MRPWorkflow$metadata()


Method data()

Retrieves the preprocessed sample data that has been prepared for MRP analysis.

Usage

MRPWorkflow$data()


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)


Links the preprocessed sample data to ACS poststratification data based on geographic and demographic variables.

Usage

MRPWorkflow$link_acs(link_geo = NULL, acs_year = 2023)

Arguments

link_geo

Character string specifying the geographic level for linking (e.g., "state", "county", "zip")

acs_year

Numeric value specifying the ACS year to use for poststratification data


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.

Usage

MRPWorkflow$load_pstrat(pstrat_data, is_aggregated = FALSE)

Arguments

pstrat_data

Custom poststratification data to be loaded

is_aggregated

Logical indicating whether the poststratification data is already aggregated


Method demo_bars()

Creates bar plots comparing demographic distributions between input survey data and target population data.

Usage

MRPWorkflow$demo_bars(demo, file = NULL, ...)

Arguments

demo

Character string specifying the demographic variable to plot

file

Optional file path to save the plot

...

Additional arguments passed to ggsave

Returns

A ggplot object or patchwork object showing demographic comparisons


Method covar_hist()

Creates histogram plots showing the distribution of geographic covariates across zip codes. Only available for COVID data.

Usage

MRPWorkflow$covar_hist(covar, file = NULL, ...)

Arguments

covar

Character string specifying the covariate. Options: "edu", "poverty", "employ", "income", "urban", "adi"

file

Optional file path to save the plot

...

Additional arguments passed to ggsave

Returns

A ggplot object showing the covariate distribution histogram


Method sample_size_map()

Creates interactive choropleth maps showing data distribution with respect to geography.

Usage

MRPWorkflow$sample_size_map(file = NULL)

Arguments

file

Optional file path to save the plot

Returns

A highcharter map object showing sample size distribution


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).

Usage

MRPWorkflow$outcome_plot(file = NULL, ...)

Arguments

file

Optional file path to save the plot

...

Additional arguments passed to ggsave

Returns

A ggplot object showing the outcome measure distribution


Method outcome_map()

Creates maps showing average outcome measure by geography for cross-sectional data, or highest/lowest weekly average for time-varying data.

Usage

MRPWorkflow$outcome_map(summary_type = NULL, file = NULL)

Arguments

summary_type

Character string for time-varying data: "max" or "min"

file

Optional file path to save the map

Returns

A highcharter map object showing outcome measures by geography


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

Returns

A ggplot object showing the group estimates


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

Returns

A highcharter map object showing MRP estimates by geography


Method create_model()

Creates a new MRPModel object with validated effects specification and prepared data for Bayesian model fitting.

Usage

MRPWorkflow$create_model(model_spec)

Arguments

model_spec

List containing model effects specification including intercept, fixed effects, varying effects, and interactions

Returns

A new MRPModel object


Method pp_check()

Creates posterior predictive check plots to assess model fit by comparing observed data to replicated data from the posterior predictive distribution.

Usage

MRPWorkflow$pp_check(model, file = NULL, ...)

Arguments

model

Fitted MRPModel object

file

Optional file path to save the plot

...

Additional arguments passed to ggsave


Method compare_models()

Compares multiple fitted MRP models using leave-one-out cross-validation to assess relative model performance.

Usage

MRPWorkflow$compare_models(..., suppress = NULL)

Arguments

...

Multiple MRPModel objects to compare

suppress

Character string specifying output to suppress during comparison

Returns

A data frame summarizing the comparison results


Method clone()

The objects of this class are cloneable with this method.

Usage

MRPWorkflow$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.