Fits and tidies MRP outputs in one step

mrp_onestep(
  .formula,
  .data,
  poststrat_tgt,
  area_var = "cd",
  count_var = "count",
  weight_var = NULL,
  add_on = NULL,
  dtplyr = TRUE,
  ...
)

Arguments

.formula

Formula in binary y ~ (1|x1) + (1|x2) form.

.data

Individual-level dataset

poststrat_tgt

The poststratification target. It must contain the column count, which is treated as the number of trials in the binomial model.

area_var

Character for the variable(s) that corresponds to the area to aggregate to.

count_var

A character string for the variable name for the population count in the poststrat_tgt dataframe. This will be renamed as if it is a trial count in the model. Defaults to "count".

weight_var

Character for the variable that corresponds to weights.

add_on

Any area-level data to be merged with the output, for example validation data

dtplyr

Whether to use a data.table/dtplyr backend for processing for slightly faster dataframe wrangling. Currently does not apply to anything within the function.

...

Additional arguments to pass to the model fitting function, fit_brms()

Details

Combines fit_brms, poststrat_draws, and direct_est. See scatter_45 for options on visualization

Examples

if (FALSE) {
library(ccesMRPviz)
mrp_fit <- mrp_onestep(response ~ (1|educ) + (1|cd),
                       .data = cces_GA,
                       poststrat_tgt = acs_GA,
                       area_var = "cd",
                       count_var = "count",
                       weight_var = "weight_post",
                       add_on = elec_GA)

scatter_45(mrp_fit, clinton_vote, p_mrp_est,
           xlab = "Clinton Vote", ylab = "MRP Estimate")
}