mrp_onestep: Fits and tidies MRP outputs in one step

View source: R/one-step.R

mrp_onestepR Documentation

Fits and tidies MRP outputs in one step

Description

Fits and tidies MRP outputs in one step

Usage

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

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.

new_levels

If there are new levels in the poststrat table that do not have coefficients in the survey data, should there be an extrapolation or assignment to 0s? The answer should almost always be No in MRP.

allow_NA

A logical (TRUE or FALSE) indicating whether the summ_sims function should allow NAs in the cell-level estimate or break. The default is FALSE.

...

Arguments passed on to fit_brms_binomial

.prior

prior specification that can be interpreted by brms. The default is a standard normal prior, which is tighter than the brms default but has shown to have good prior posterior draws

.cores

Number of cores to uses

.chains

Number of chains to pass on fit_brms

.iter

Number of total iterations.

.warmup

Of the iterations, how much are burn-ins. Defaults to half.

verbose

Whether to show iteration messages

.seed

seed for randomization to pass into brm

.backend

The backend argument of brms. Currently only "cmdstanr"

.threads

The number of threads to do within-chain parallelization. Defaults to not using, which is NULL

Details

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

Examples

## Not run: 
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")

## End(Not run)


kuriwaki/ccesMRPrun documentation built on Sept. 24, 2024, 2:15 a.m.