Code
# TODO: Move this into build_respondents() in R/funs_data.R
source(here("notebook", "_moderators.R"))
conjoint <- add_moderators(conjoint)All models are Bayesian multilevel logistic regressions fit with {brms}. Each row in conjoint is one profile shown in one task (1,201 respondents × 10 tasks × 3 profiles = 36,030 rows), and response is 1 if the respondent chose that profile. Every model saves itself to output/ with file_refit = "on_change", so this page only refits a model if its data, formula, priors, or Stan code change.
There are three models:
model_conjoint: attributes only (overall MMs and AMCEs)model_h5: attributes × the four nonprofit-experience moderators (confirmatory H5a/b)model_e3: attributes × eight demographics (exploratory E3)The preregistration specified a hierarchical multinomial logit with moderator effects derived post-estimation rather than interacted in the model. These models deviate from that: they’re Bernoulli, with the moderators interacted with the attributes. See the Deviations page. A multinomial version of the main model is included as a robustness check.
Post-processing (marginal means, AMCEs, subgroup comparisons) lives on the Results page, and the estimands themselves are defined on the Estimands page.
giving, volunteering, and npo_work are created in build_respondents() in R/funs_data.R. The other moderators are derived in notebook/_moderators.R (sourced by both this page and the Results page) until we’ve confirmed they match Meng’s subgroups. Eventually add_moderators() should move into build_respondents().
The moderators come in two families:
# Count respondents (not rows) in each subgroup, including those missing the
# moderator (who get dropped from that family's model)
moderators |>
mutate(counts = map(moderator, \(x) {
# (select() + count() instead of count(.data[[x]]), since .data[[x]] inside
# a nested mutate() fails with "object 'x' not found")
conjoint |>
distinct(id, .keep_all = TRUE) |>
select(subgroup = all_of(x)) |>
count(subgroup) |>
mutate(subgroup = as.character(subgroup))
})) |>
unnest(counts) |>
select(
Family = family, Moderator = moderator_nice, Measured = measured,
Subgroup = subgroup, Respondents = n
) |>
knitr::kable()| Family | Moderator | Measured | Subgroup | Respondents |
|---|---|---|---|---|
| H5 | Giving frequency | Survey Q3 (pretreatment) | Rarely/never | 506 |
| H5 | Giving frequency | Survey Q3 (pretreatment) | Often/occasionally | 692 |
| H5 | Giving frequency | Survey Q3 (pretreatment) | NA | 3 |
| H5 | Volunteering | Survey Q3 (pretreatment) | Rarely/never | 859 |
| H5 | Volunteering | Survey Q3 (pretreatment) | Often/occasionally | 336 |
| H5 | Volunteering | Survey Q3 (pretreatment) | NA | 6 |
| H5 | Nonprofit work | Survey Q3 (pretreatment) | Never worked at a nonprofit | 784 |
| H5 | Nonprofit work | Survey Q3 (pretreatment) | Has worked at a nonprofit | 413 |
| H5 | Nonprofit work | Survey Q3 (pretreatment) | NA | 4 |
| H5 | Gave $200+ | Survey Q3 (pretreatment) | Under $200 | 876 |
| H5 | Gave $200+ | Survey Q3 (pretreatment) | Gave $200+ | 321 |
| H5 | Gave $200+ | Survey Q3 (pretreatment) | NA | 4 |
| E3 | Age | Prolific prescreener | 18–29 | 224 |
| E3 | Age | Prolific prescreener | 30–44 | 334 |
| E3 | Age | Prolific prescreener | 45–59 | 352 |
| E3 | Age | Prolific prescreener | 60+ | 282 |
| E3 | Age | Prolific prescreener | NA | 9 |
| E3 | Gender | Prolific prescreener | Female | 607 |
| E3 | Gender | Prolific prescreener | Male | 585 |
| E3 | Gender | Prolific prescreener | NA | 9 |
| E3 | Education | Survey Q6 (post-treatment) | HS or less | 156 |
| E3 | Education | Survey Q6 (post-treatment) | Some college or associate | 401 |
| E3 | Education | Survey Q6 (post-treatment) | Bachelor’s+ | 636 |
| E3 | Education | Survey Q6 (post-treatment) | NA | 8 |
| E3 | Income | Survey Q6 (post-treatment) | <$50k | 420 |
| E3 | Income | Survey Q6 (post-treatment) | $50–99k | 445 |
| E3 | Income | Survey Q6 (post-treatment) | $100k+ | 331 |
| E3 | Income | Survey Q6 (post-treatment) | NA | 5 |
| E3 | Marital status | Survey Q6 (post-treatment) | Not married | 591 |
| E3 | Marital status | Survey Q6 (post-treatment) | Married/partnered | 607 |
| E3 | Marital status | Survey Q6 (post-treatment) | NA | 3 |
| E3 | Ideology | Survey Q6 (post-treatment) | Liberal | 507 |
| E3 | Ideology | Survey Q6 (post-treatment) | Moderate | 255 |
| E3 | Ideology | Survey Q6 (post-treatment) | Conservative | 388 |
| E3 | Ideology | Survey Q6 (post-treatment) | NA | 51 |
| E3 | Religion | Survey Q6 (post-treatment) | Not religious | 555 |
| E3 | Religion | Survey Q6 (post-treatment) | Religious | 644 |
| E3 | Religion | Survey Q6 (post-treatment) | NA | 2 |
| E3 | Race | Prolific prescreener | White | 754 |
| E3 | Race | Prolific prescreener | Non-White | 438 |
| E3 | Race | Prolific prescreener | NA | 9 |
Each heterogeneity model drops respondents who are missing any of its moderators (listwise deletion):
tribble(
~Model, ~vars,
"model_conjoint", character(0),
"model_h5", moderators_h5,
"model_e3", moderators_e3
) |>
mutate(
data = map(vars, \(x) drop_na(conjoint, all_of(x))),
Rows = map_int(data, nrow),
Respondents = map_int(data, \(x) n_distinct(x$id)),
`Respondents dropped` = n_distinct(conjoint$id) - Respondents
) |>
select(-vars, -data) |>
knitr::kable(format.args = list(big.mark = ","))| Model | Rows | Respondents | Respondents dropped |
|---|---|---|---|
| model_conjoint | 36,030 | 1,201 | 0 |
| model_h5 | 35,550 | 1,185 | 16 |
| model_e3 | 33,840 | 1,128 | 73 |
The main model includes all five attributes plus respondent-specific intercepts:
\[ \begin{aligned} \text{Response}_{i_j} \sim&\ \operatorname{Bernoulli}(\pi_{i_j}) \\ \operatorname{logit}(\pi_{i_j}) =&\ (\beta_0 + b_{0_j}) + \beta_1 \text{RBI}_{i_j} + \beta_2 \text{UBI}_{i_j} + \beta_3 \text{Nonprofit type}_{i_j} + \\ &\ \beta_4 \text{Use of donations}_{i_j} + \beta_5 \text{Financial situation}_{i_j} \\ b_{0_j} \sim&\ \mathcal{N}(0, \sigma_0) \\[10pt] \beta_0 \sim&\ \operatorname{Student\ t}(3, 0, 2.5) \qquad \text{(brms default, on the centered intercept)} \\ \beta_{1 \dots 5} \sim&\ \mathcal{N}(0, 3) \\ \sigma_0 \sim&\ \operatorname{Exponential}(1) \end{aligned} \]
where \(i\) is a profile shown to respondent \(j\) and each \(\beta\) is a vector of coefficients for the non-reference levels of that attribute.
model_conjoint <- brm(
bf(response ~ rbi + ubi + nonprofit_type + use_of_donations +
financial_situation + (1 | id)),
data = conjoint,
family = bernoulli(),
prior = c(
prior(normal(0, 3), class = b),
prior(exponential(1), class = sd)
),
# Drop constant terms from the likelihood (faster; doesn't affect estimates).
# (This does break bridge_sampling()/Bayes factors, which need the
# normalized density; loo() is fine.)
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
# 4 chains × 3 threads = 12 threads
backend = "cmdstanr", threads = threading(3),
# Stan compiler optimizations (faster sampling, slightly slower compile)
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_conjoint_bernoulli"),
file_refit = "on_change"
)
## Start sampling
## Running MCMC with 4 parallel chains, with 3 thread(s) per chain...
##
## Chain 1 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 1 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 3 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 2 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 4 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 2 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 3 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 4 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 2 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 3 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 4 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 1 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 2 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 3 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 4 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 2 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 1 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 2 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 4 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 3 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 2 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 3 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 4 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 2 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 3 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 4 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 1 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 3 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 4 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 1 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 2 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 3 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 1 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 2 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 3 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 4 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 2 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 3 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 2 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 4 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 1 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 2 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 3 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 1 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 2 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 3 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 4 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 2 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 3 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 2 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 3 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 4 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 1 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 2 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 3 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 1 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1 finished in 36.8 seconds.
## Chain 2 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2 finished in 36.8 seconds.
## Chain 3 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 4 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 3 finished in 37.9 seconds.
## Chain 4 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 4 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 4 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 4 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 4 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4 finished in 45.5 seconds.
##
## All 4 chains finished successfully.
## Mean chain execution time: 39.2 seconds.
## Total execution time: 45.7 seconds.
## Loading required namespace: rstanmodel_conjoint
## Family: bernoulli
## Links: mu = logit
## Formula: response ~ rbi + ubi + nonprofit_type + use_of_donations + financial_situation + (1 | id)
## Data: conjoint (Number of observations: 36030)
## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
## total post-warmup draws = 4000
##
## Multilevel Hyperparameters:
## ~id (Number of levels: 1201)
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept) 0.02 0.01 0.00 0.05 1.00 1601 1521
##
## Regression Coefficients:
## Estimate Est.Error l-95% CI u-95% CI
## Intercept -0.45 0.04 -0.53 -0.37
## rbiReducedprice -0.62 0.03 -0.68 -0.57
## rbiFullprice -1.33 0.03 -1.39 -1.27
## ubiEventspacerental -0.11 0.03 -0.17 -0.05
## ubiRunningapizzashop -0.26 0.03 -0.32 -0.20
## nonprofit_typeStudenttutoringcenter 0.34 0.03 0.28 0.41
## nonprofit_typeUrbanforestrycenter 0.12 0.04 0.05 0.19
## nonprofit_typeMentalhealthcenter 0.81 0.03 0.74 0.88
## use_of_donationsCapacitybuilding -0.13 0.03 -0.20 -0.07
## use_of_donationsRainydayfunds -0.32 0.03 -0.39 -0.26
## use_of_donationsUnrestricteduse -0.29 0.03 -0.35 -0.22
## financial_situationUnderfinancialstress 0.34 0.02 0.29 0.39
## Rhat Bulk_ESS Tail_ESS
## Intercept 1.00 4275 2748
## rbiReducedprice 1.00 5306 2706
## rbiFullprice 1.00 5376 3088
## ubiEventspacerental 1.00 5240 3062
## ubiRunningapizzashop 1.00 5072 2949
## nonprofit_typeStudenttutoringcenter 1.00 3730 3038
## nonprofit_typeUrbanforestrycenter 1.00 4039 2863
## nonprofit_typeMentalhealthcenter 1.00 3908 2876
## use_of_donationsCapacitybuilding 1.00 3869 3049
## use_of_donationsRainydayfunds 1.00 4144 3208
## use_of_donationsUnrestricteduse 1.00 3925 3106
## financial_situationUnderfinancialstress 1.00 6632 2658
##
## Draws were sampled using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).The (1 | id) term accounts for repeated choices within respondents. Respondent-specific slopes for each attribute ((1 + rbi + ubi + ... | id)) would model preference heterogeneity that the moderators don’t capture, and they’d give us individual-level part-worths. But they add ~12 SDs (plus ~66 correlations with | instead of ||) and ~14,000 respondent-level parameters, and they make the model much slower to fit. They also mean re_formula = NA predictions (all slopes at 0) are no longer close to the population average on the probability scale. Since our estimands are population-level marginal means and AMCEs, intercepts are enough for now.
Note that in a forced-choice design, every respondent chooses exactly one profile per task (or “none”), so each respondent’s average response is pinned at (or a little below) 1/3. The random intercepts can only pick up differences in how often people chose the (dropped) “none” option, which is likely why \(\sigma_0\) is tiny (≈0.02 in an earlier fit).
H5a/b: The negative effect of RBI [UBI] is attenuated among donors with more nonprofit experience (donating, volunteering, working in nonprofits, or making large prior donations).
model_h5 interacts every attribute with all four experience indicators in one model:
model_h5 <- brm(
bf(
response ~
# Attributes (choice-level, nested in respondents)...
(rbi + ubi + nonprofit_type + use_of_donations + financial_situation) *
# ...interacted with the four (pretreatment) experience indicators
(giving + volunteering + npo_work + gave_200) +
(1 | id)
# If sampling is slow, try adding `decomp = "QR"` here (note that the
# normal(0, 3) prior then applies to the QR-scale coefficients, not to b)
),
# brms would drop these anyway; doing it explicitly makes the sample visible
data = drop_na(conjoint, all_of(moderators_h5)),
family = bernoulli(),
prior = c(
prior(normal(0, 3), class = b),
prior(exponential(1), class = sd)
),
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
backend = "cmdstanr", threads = threading(3),
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_h5"),
file_refit = "on_change"
)
## Start sampling
## Running MCMC with 4 parallel chains, with 3 thread(s) per chain...
##
## Chain 1 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 2 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 1 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 3 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 4 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 2 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 3 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 4 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 2 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 3 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 4 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 2 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 3 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 1 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 4 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 2 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 3 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 4 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 2 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 1 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 2 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 4 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 1 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 2 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 3 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 4 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 1 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 2 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 4 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 3 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 2 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 3 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 1 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 3 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 4 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 2 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 3 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 4 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 1 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 2 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 3 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 4 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 2 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 4 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 3 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 1 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 2 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 4 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 2 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 4 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 3 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 1 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 2 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 3 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 2 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 3 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 1 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 2 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 3 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 3 finished in 103.0 seconds.
## Chain 1 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 2 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2 finished in 105.7 seconds.
## Chain 4 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 1 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1 finished in 106.1 seconds.
## Chain 4 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4 finished in 107.9 seconds.
##
## All 4 chains finished successfully.
## Mean chain execution time: 105.7 seconds.
## Total execution time: 108.2 seconds.One joint model can give two kinds of H5 estimand, both calculated on the Results page:
The four indicators are only modestly correlated (pairwise correlations of the binary indicators range from about 0.1 to 0.4), so these can diverge. Because the model has no moderator × moderator × attribute terms, it assumes the moderators’ effects on each attribute’s coefficient are additive on the logit scale.
E3: Effects of RBI and UBI may vary by age, gender, education, income, marital status, political ideology, religiosity, and race.
model_e3 interacts every attribute with all eight demographics:
# This is deliberately a separate model from model_h5. Education, income,
# marital status, ideology, and religion were asked *after* the conjoint (Q6),
# so they're post-treatment. Keeping them out of model_h5 means they never
# enter the adjustment set for the confirmatory H5 estimands.
model_e3 <- brm(
bf(
response ~
(rbi + ubi + nonprofit_type + use_of_donations + financial_situation) *
(age_group + gender + education + income + marital + ideology +
religious + race) +
(1 | id)
# If sampling is slow, try adding `decomp = "QR"` here (note that the
# normal(0, 3) prior then applies to the QR-scale coefficients, not to b)
),
data = drop_na(conjoint, all_of(moderators_e3)),
family = bernoulli(),
prior = c(
prior(normal(0, 3), class = b),
prior(exponential(1), class = sd)
),
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
backend = "cmdstanr", threads = threading(3),
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_e3"),
file_refit = "on_change"
)
## Start sampling
## Running MCMC with 4 parallel chains, with 3 thread(s) per chain...
##
## Chain 1 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 4 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 3 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 1 Iteration: 100 / 2000 [ 5%] (Warmup)
## Chain 2 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 3 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 4 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1 Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 2 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 3 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 4 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 2 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1 Iteration: 300 / 2000 [ 15%] (Warmup)
## Chain 3 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 4 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 2 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 1 Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 3 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 4 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 2 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1 Iteration: 500 / 2000 [ 25%] (Warmup)
## Chain 3 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 4 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 2 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 1 Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 4 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 2 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 1 Iteration: 700 / 2000 [ 35%] (Warmup)
## Chain 3 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 4 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 2 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 3 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 1 Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 4 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 2 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1 Iteration: 900 / 2000 [ 45%] (Warmup)
## Chain 3 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 3 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 4 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 1 Iteration: 1100 / 2000 [ 55%] (Sampling)
## Chain 2 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 3 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 4 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1 Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 2 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 3 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 4 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 1 Iteration: 1300 / 2000 [ 65%] (Sampling)
## Chain 2 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 4 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 1 Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 2 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 3 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 4 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 1 Iteration: 1500 / 2000 [ 75%] (Sampling)
## Chain 2 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 3 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 4 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1 Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 2 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 3 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 4 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 1 Iteration: 1700 / 2000 [ 85%] (Sampling)
## Chain 2 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 3 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 1 Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 2 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 3 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 4 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 1 Iteration: 1900 / 2000 [ 95%] (Sampling)
## Chain 2 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2 finished in 381.9 seconds.
## Chain 3 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 3 finished in 384.0 seconds.
## Chain 4 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4 finished in 388.0 seconds.
## Chain 1 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1 finished in 391.7 seconds.
##
## All 4 chains finished successfully.
## Mean chain execution time: 386.4 seconds.
## Total execution time: 392.1 seconds.# Worst R-hat and bulk ESS ratio across all parameters, plus divergences
list(
model_conjoint = model_conjoint,
model_h5 = model_h5,
model_e3 = model_e3
) |>
map(\(m) {
tibble(
n_respondents = n_distinct(m$data$id),
n_coefficients = length(fixef(m)[, 1]),
sd_intercept = posterior_summary(m, variable = "sd_id__Intercept")[, "Estimate"],
max_rhat = max(rhat(m), na.rm = TRUE),
min_neff_ratio = min(neff_ratio(m), na.rm = TRUE),
divergences = sum(subset(nuts_params(m), Parameter == "divergent__")$Value)
)
}) |>
list_rbind(names_to = "model") |>
knitr::kable(digits = 3)| model | n_respondents | n_coefficients | sd_intercept | max_rhat | min_neff_ratio | divergences |
|---|---|---|---|---|---|---|
| model_conjoint | 1201 | 12 | 0.016 | 1.007 | 0.342 | 0 |
| model_h5 | 1185 | 60 | 0.016 | 1.006 | 0.346 | 0 |
| model_e3 | 1128 | 168 | 0.017 | 1.007 | 0.335 | 0 |
This is the robustness check for deviation #1 (Bernoulli instead of the preregistered hierarchical multinomial logit). It’s the main model as a categorical (multinomial) logit, following this guide. The outcome records which position in the task was chosen: choice_alt is 0 if this profile wasn’t chosen, and 1, 2, or 3 if it was chosen and was shown in that position. Category 0 is the reference, so there’s a separate linear predictor (mu1, mu2, mu3) for each position, and P(profile chosen) = 1 − P(category 0). Tasks where the respondent chose “none” have all three rows at 0.
It’s not evaluated by default (it’s much slower than the Bernoulli model). The Results page compares its overall AMCEs with model_conjoint if output/model_conjoint_categorical.rds exists.
conjoint_choice_alt <- conjoint |>
mutate(choice_alt = factor(concept * response))
conjoint_choice_alt |>
count(response, concept, choice_alt)
## # A tibble: 6 × 4
## response concept choice_alt n
## <dbl> <dbl> <fct> <int>
## 1 0 1 0 8243
## 2 0 2 0 8379
## 3 0 3 0 8531
## 4 1 1 1 3767
## 5 1 2 2 3631
## 6 1 3 3 3479model_conjoint_categorical <- brm(
bf(choice_alt ~ 0 + rbi + ubi + nonprofit_type + use_of_donations +
financial_situation + (1 | ID | id)),
data = conjoint_choice_alt,
family = categorical(refcat = "0"),
prior = c(
prior(normal(0, 3), class = b, dpar = mu1),
prior(normal(0, 3), class = b, dpar = mu2),
prior(normal(0, 3), class = b, dpar = mu3),
prior(exponential(1), class = sd, dpar = mu1),
prior(exponential(1), class = sd, dpar = mu2),
prior(exponential(1), class = sd, dpar = mu3)
),
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
backend = "cmdstanr", threads = threading(3),
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_conjoint_categorical"),
file_refit = "on_change"
)---
title: "Models"
---
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(targets)
library(brms)
library(here)
tar_load(conjoint)
# Fitted models get saved here as .rds files via brm(file = ...)
fs::dir_create(here("output"))
```
All models are Bayesian multilevel logistic regressions fit with {brms}. Each row in `conjoint` is one profile shown in one task (1,201 respondents × 10 tasks × 3 profiles = 36,030 rows), and `response` is 1 if the respondent chose that profile. Every model saves itself to `output/` with `file_refit = "on_change"`, so this page only refits a model if its data, formula, priors, or Stan code change.
There are three models:
1. `model_conjoint`: attributes only (overall MMs and AMCEs)
2. `model_h5`: attributes × the four nonprofit-experience moderators (confirmatory H5a/b)
3. `model_e3`: attributes × eight demographics (exploratory E3)
The preregistration specified a hierarchical multinomial logit with moderator effects derived post-estimation rather than interacted in the model. These models deviate from that: they're Bernoulli, with the moderators interacted with the attributes. See the [Deviations](deviations.qmd) page. A [multinomial version](#robustness-multinomial) of the main model is included as a robustness check.
Post-processing (marginal means, AMCEs, subgroup comparisons) lives on the [Results](results.qmd) page, and the estimands themselves are defined on the [Estimands](estimands.qmd) page.
## Respondent subgroups
::: {.callout-warning}
#### Temporary home for the subgroup definitions
`giving`, `volunteering`, and `npo_work` are created in `build_respondents()` in [`R/funs_data.R`](https://github.com/andrewheiss/front-fish/blob/main/R/funs_data.R). The other moderators are derived in `notebook/_moderators.R` (sourced by both this page and the Results page) until we've confirmed they match Meng's subgroups. Eventually `add_moderators()` should move into `build_respondents()`.
:::
```{r}
#| label: add-moderators
# TODO: Move this into build_respondents() in R/funs_data.R
source(here("notebook", "_moderators.R"))
conjoint <- add_moderators(conjoint)
```
The moderators come in two families:
- **H5 (confirmatory)**: four indicators of nonprofit experience (giving frequency, volunteering frequency, nonprofit work, and giving $200+ in the past year). All four were asked in Q3, *before* the conjoint.
- **E3 (exploratory)**: eight demographics. Age, gender, and race come from Prolific's prescreener (pretreatment). Education, income, marital status, ideology, and religion were asked in Q6, *after* the conjoint, so they're technically post-treatment.
```{r}
#| label: tbl-moderator-counts
#| tbl-cap: "Respondents in each subgroup"
# Count respondents (not rows) in each subgroup, including those missing the
# moderator (who get dropped from that family's model)
moderators |>
mutate(counts = map(moderator, \(x) {
# (select() + count() instead of count(.data[[x]]), since .data[[x]] inside
# a nested mutate() fails with "object 'x' not found")
conjoint |>
distinct(id, .keep_all = TRUE) |>
select(subgroup = all_of(x)) |>
count(subgroup) |>
mutate(subgroup = as.character(subgroup))
})) |>
unnest(counts) |>
select(
Family = family, Moderator = moderator_nice, Measured = measured,
Subgroup = subgroup, Respondents = n
) |>
knitr::kable()
```
Each heterogeneity model drops respondents who are missing *any* of its moderators (listwise deletion):
```{r}
#| label: tbl-listwise-deletion
#| tbl-cap: "Sample used by each model"
tribble(
~Model, ~vars,
"model_conjoint", character(0),
"model_h5", moderators_h5,
"model_e3", moderators_e3
) |>
mutate(
data = map(vars, \(x) drop_na(conjoint, all_of(x))),
Rows = map_int(data, nrow),
Respondents = map_int(data, \(x) n_distinct(x$id)),
`Respondents dropped` = n_distinct(conjoint$id) - Respondents
) |>
select(-vars, -data) |>
knitr::kable(format.args = list(big.mark = ","))
```
## Main model
The main model includes all five attributes plus respondent-specific intercepts:
$$
\begin{aligned}
\text{Response}_{i_j} \sim&\ \operatorname{Bernoulli}(\pi_{i_j}) \\
\operatorname{logit}(\pi_{i_j}) =&\ (\beta_0 + b_{0_j}) + \beta_1 \text{RBI}_{i_j} + \beta_2 \text{UBI}_{i_j} + \beta_3 \text{Nonprofit type}_{i_j} + \\
&\ \beta_4 \text{Use of donations}_{i_j} + \beta_5 \text{Financial situation}_{i_j} \\
b_{0_j} \sim&\ \mathcal{N}(0, \sigma_0) \\[10pt]
\beta_0 \sim&\ \operatorname{Student\ t}(3, 0, 2.5) \qquad \text{(brms default, on the centered intercept)} \\
\beta_{1 \dots 5} \sim&\ \mathcal{N}(0, 3) \\
\sigma_0 \sim&\ \operatorname{Exponential}(1)
\end{aligned}
$$
where $i$ is a profile shown to respondent $j$ and each $\beta$ is a vector of coefficients for the non-reference levels of that attribute.
```{r}
#| label: model-conjoint
model_conjoint <- brm(
bf(response ~ rbi + ubi + nonprofit_type + use_of_donations +
financial_situation + (1 | id)),
data = conjoint,
family = bernoulli(),
prior = c(
prior(normal(0, 3), class = b),
prior(exponential(1), class = sd)
),
# Drop constant terms from the likelihood (faster; doesn't affect estimates).
# (This does break bridge_sampling()/Bayes factors, which need the
# normalized density; loo() is fine.)
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
# 4 chains × 3 threads = 12 threads
backend = "cmdstanr", threads = threading(3),
# Stan compiler optimizations (faster sampling, slightly slower compile)
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_conjoint_bernoulli"),
file_refit = "on_change"
)
```
```{r}
#| label: model-conjoint-summary
model_conjoint
```
### Why only respondent intercepts?
The `(1 | id)` term accounts for repeated choices within respondents. Respondent-specific slopes for each attribute (`(1 + rbi + ubi + ... | id)`) would model preference heterogeneity that the moderators don't capture, and they'd give us individual-level part-worths. But they add ~12 SDs (plus ~66 correlations with `|` instead of `||`) and ~14,000 respondent-level parameters, and they make the model much slower to fit. They also mean `re_formula = NA` predictions (all slopes at 0) are no longer close to the population average on the probability scale. Since our estimands are population-level marginal means and AMCEs, intercepts are enough for now.
Note that in a forced-choice design, every respondent chooses exactly one profile per task (or "none"), so each respondent's average `response` is pinned at (or a little below) 1/3. The random intercepts can only pick up differences in how often people chose the (dropped) "none" option, which is likely why $\sigma_0$ is tiny (≈0.02 in an earlier fit).
## H5: nonprofit experience
> **H5a/b**: The negative effect of RBI [UBI] is attenuated among donors with more nonprofit experience (donating, volunteering, working in nonprofits, or making large prior donations).
`model_h5` interacts every attribute with all four experience indicators in one model:
```{r}
#| label: model-h5
model_h5 <- brm(
bf(
response ~
# Attributes (choice-level, nested in respondents)...
(rbi + ubi + nonprofit_type + use_of_donations + financial_situation) *
# ...interacted with the four (pretreatment) experience indicators
(giving + volunteering + npo_work + gave_200) +
(1 | id)
# If sampling is slow, try adding `decomp = "QR"` here (note that the
# normal(0, 3) prior then applies to the QR-scale coefficients, not to b)
),
# brms would drop these anyway; doing it explicitly makes the sample visible
data = drop_na(conjoint, all_of(moderators_h5)),
family = bernoulli(),
prior = c(
prior(normal(0, 3), class = b),
prior(exponential(1), class = sd)
),
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
backend = "cmdstanr", threads = threading(3),
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_h5"),
file_refit = "on_change"
)
```
One joint model can give two kinds of H5 estimand, both calculated on the Results page:
- **Unadjusted (primary)**: the AMCE among, e.g., frequent givers, averaging over the *observed* mix of volunteering, nonprofit work, and $200+ giving among frequent givers. This is the subgroup quantity in [Leeper, Hobolt, and Tilley (2020)](https://doi.org/10.1017/pan.2019.30), and it's what "the effect of RBI among frequent givers" means in plain language.
- **Adjusted (secondary)**: set everyone's giving to "often" (then "rarely"), hold the other three indicators at their observed values, and average (Jensen et al. 2021, *PSRM*). This asks whether giving frequency is associated with RBI sensitivity *net of* the other experience indicators.
The four indicators are only modestly correlated (pairwise correlations of the binary indicators range from about 0.1 to 0.4), so these can diverge. Because the model has no moderator × moderator × attribute terms, it assumes the moderators' effects on each attribute's coefficient are additive on the logit scale.
## E3: demographics
> **E3**: Effects of RBI and UBI may vary by age, gender, education, income, marital status, political ideology, religiosity, and race.
`model_e3` interacts every attribute with all eight demographics:
```{r}
#| label: model-e3
# This is deliberately a separate model from model_h5. Education, income,
# marital status, ideology, and religion were asked *after* the conjoint (Q6),
# so they're post-treatment. Keeping them out of model_h5 means they never
# enter the adjustment set for the confirmatory H5 estimands.
model_e3 <- brm(
bf(
response ~
(rbi + ubi + nonprofit_type + use_of_donations + financial_situation) *
(age_group + gender + education + income + marital + ideology +
religious + race) +
(1 | id)
# If sampling is slow, try adding `decomp = "QR"` here (note that the
# normal(0, 3) prior then applies to the QR-scale coefficients, not to b)
),
data = drop_na(conjoint, all_of(moderators_e3)),
family = bernoulli(),
prior = c(
prior(normal(0, 3), class = b),
prior(exponential(1), class = sd)
),
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
backend = "cmdstanr", threads = threading(3),
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_e3"),
file_refit = "on_change"
)
```
## Diagnostics
```{r}
#| label: tbl-diagnostics
#| tbl-cap: "Quick convergence check"
# Worst R-hat and bulk ESS ratio across all parameters, plus divergences
list(
model_conjoint = model_conjoint,
model_h5 = model_h5,
model_e3 = model_e3
) |>
map(\(m) {
tibble(
n_respondents = n_distinct(m$data$id),
n_coefficients = length(fixef(m)[, 1]),
sd_intercept = posterior_summary(m, variable = "sd_id__Intercept")[, "Estimate"],
max_rhat = max(rhat(m), na.rm = TRUE),
min_neff_ratio = min(neff_ratio(m), na.rm = TRUE),
divergences = sum(subset(nuts_params(m), Parameter == "divergent__")$Value)
)
}) |>
list_rbind(names_to = "model") |>
knitr::kable(digits = 3)
```
## Robustness: multinomial model {#robustness-multinomial}
This is the robustness check for deviation #1 (Bernoulli instead of the preregistered hierarchical multinomial logit). It's the main model as a categorical (multinomial) logit, following [this guide](https://www.andrewheiss.com/blog/2023/08/12/conjoint-multilevel-multinomial-guide/). The outcome records which position in the task was chosen: `choice_alt` is 0 if this profile wasn't chosen, and 1, 2, or 3 if it was chosen and was shown in that position. Category 0 is the reference, so there's a separate linear predictor (`mu1`, `mu2`, `mu3`) for each position, and P(profile chosen) = 1 − P(category 0). Tasks where the respondent chose "none" have all three rows at 0.
It's not evaluated by default (it's much slower than the Bernoulli model). The Results page compares its overall AMCEs with `model_conjoint` if `output/model_conjoint_categorical.rds` exists.
```{r}
#| label: conjoint-choice-alt
conjoint_choice_alt <- conjoint |>
mutate(choice_alt = factor(concept * response))
conjoint_choice_alt |>
count(response, concept, choice_alt)
```
```{r}
#| label: model-conjoint-categorical
#| eval: false
model_conjoint_categorical <- brm(
bf(choice_alt ~ 0 + rbi + ubi + nonprofit_type + use_of_donations +
financial_situation + (1 | ID | id)),
data = conjoint_choice_alt,
family = categorical(refcat = "0"),
prior = c(
prior(normal(0, 3), class = b, dpar = mu1),
prior(normal(0, 3), class = b, dpar = mu2),
prior(normal(0, 3), class = b, dpar = mu3),
prior(exponential(1), class = sd, dpar = mu1),
prior(exponential(1), class = sd, dpar = mu2),
prior(exponential(1), class = sd, dpar = mu3)
),
normalize = FALSE,
chains = 4, cores = 4, iter = 2000, seed = 1873,
backend = "cmdstanr", threads = threading(3),
stan_model_args = list(stanc_options = list("O1")),
refresh = 100,
file = here("output", "model_conjoint_categorical"),
file_refit = "on_change"
)
```