View source: R/cces_collapse.R
build_counts | R Documentation |
Currently only is compatible with question of type "yesno"
.
build_counts(
formula,
data,
keep_vars = NULL,
name_ones_as = "yes",
name_trls_as = "n_response",
multiple_qIDs = FALSE,
verbose = TRUE
)
formula |
the model formula used to fit the multilevel regression model.
Should be of the form |
data |
A cleaned CCES dataset, e.g. from ccc_std_demographics which is
then combined with outcome and contextual data in cces_join_slim.
By default it expects the LHS outcome to be named |
keep_vars |
Variables that will be kept as a cell variable, regardless of whether it is specified in a formula. Input as character vector. |
name_ones_as |
What to name the variable that represents the number of successes in the binomial |
name_trls_as |
What to name the variable that represents the number of trials in the binomial. |
multiple_qIDs |
Does the data contain multiple outcomes in long form and
therefore require the counts to be built for each outcome? Defaults to |
verbose |
Show warning messages? Defaults to TRUE |
A dataframe of cells. The following variables have fixed names and
will be assumed by ccesMRPrun::fit_brms_binomial
:
yes
: the number of successes observed in the cell
n_response
the number of non-missing responses, representing the number
of trials.
library(dplyr)
ccc_samp_std <- ccc_samp %>%
mutate(y = sample(c("For", "Against"), size = n(), replace = TRUE)) %>%
ccc_std_demographics()
ccc_samp_out <- build_counts(y ~ age + gender + educ + (1|cd),
ccc_samp_std)
ccc_samp_out
# alternative options
build_counts(y ~ educ + (1|cd), ccc_samp_std,
name_ones_as = "success", name_trls_as = "trials")
build_counts(y ~ educ + (1|cd), ccc_samp_std,
keep_vars = "state")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.