---
title: "Results"
---
```{r}
#| label: setup
#| include: false
library(tidyverse)
library(targets)
library(brms)
library(marginaleffects)
library(tidybayes)
library(patchwork)
library(scales)
library(here)
tar_load(conjoint)
# Respondent subgroups (H5 experience indicators and E3 demographics)
# TODO: Move add_moderators() into build_respondents() in R/funs_data.R
source(here("notebook", "_moderators.R"))
conjoint <- add_moderators(conjoint)
# Format numbers as percentage points
label_pp <- label_number(
accuracy = 1,
scale = 100,
suffix = " pp.",
style_negative = "minus"
)
# Conjoint attributes. (Not called `attributes` since that masks
# base::attributes(), which breaks marginaleffects when it re-evaluates calls)
conjoint_attributes <- c(
"rbi", "ubi", "nonprofit_type", "use_of_donations", "financial_situation"
)
# Lookup tables so attributes and levels plot in the right order. Levels come
# from the factors themselves, so the first level is the reference category
attribute_lookup <- tibble(
attribute = conjoint_attributes,
attribute_nice = c(
"Core service price (RBI)", "Side business (UBI)", "Nonprofit type",
"Use of donations", "Financial situation"
)
) |>
mutate(attribute_nice = fct_inorder(attribute_nice))
attribute_levels_lookup <- attribute_lookup |>
mutate(level = map(attribute, \(x) levels(conjoint[[x]]))) |>
unnest(level) |>
mutate(level_nice = fct_inorder(level))
# The four AMCEs that H5a (RBI) and H5b (UBI) are about
h5_contrasts <- tribble(
~term, ~contrast, ~contrast_nice,
"rbi", "Reduced price - Free", "H5a: Reduced price − Free",
"rbi", "Full price - Free", "H5a: Full price − Free",
"ubi", "Event space rental - None", "H5b: Event space rental − None",
"ubi", "Running a pizza shop - None", "H5b: Running a pizza shop − None"
) |>
mutate(contrast_nice = fct_inorder(contrast_nice))
# Overall share of profiles chosen. It's a little under 1/3 because some tasks
# ended with "none", which isn't in the data
baseline_rate <- mean(conjoint$response)
```
This page post-processes the models defined on the [Models](models.qmd) page. See the [Estimands](estimands.qmd) page for formal definitions of each quantity and the [Deviations](deviations.qmd) page for how this differs from the preregistration.
## Load models
The models are fit on the Models page and saved in `output/`. Here we just load them.
```{r}
#| label: load-models
model_conjoint <- readRDS(here("output", "model_conjoint_bernoulli.rds"))
model_h5 <- readRDS(here("output", "model_h5.rds"))
model_e3 <- readRDS(here("output", "model_e3.rds"))
# The models were fit with inline data expressions like
# `drop_na(conjoint, all_of(moderators_h5))`, which marginaleffects/insight
# can't reliably recover from this page's environment. Attach the exact
# training data explicitly so datagrid() and avg_*() never have to guess.
model_conjoint <- set_modeldata(model_conjoint, conjoint)
model_h5 <- set_modeldata(model_h5, drop_na(conjoint, all_of(moderators_h5)))
model_e3 <- set_modeldata(model_e3, drop_na(conjoint, all_of(moderators_e3)))
```
```{r}
#| label: subgroup-lookup
# Subgroup labels with respondent counts, like "Liberal (n=507)". Counts come
# from the data each model was actually fit on (after listwise deletion), so
# they can be slightly smaller than the full-sample counts
subgroup_lookup <- moderators |>
mutate(counts = map2(moderator, family, \(x, fam) {
model_data <- if (fam == "H5") model_h5$data else model_e3$data
# (select() + count() instead of count(.data[[x]]), since .data[[x]] inside
# a nested mutate() fails with "object 'x' not found")
model_data |>
distinct(id, .keep_all = TRUE) |>
select(subgroup = all_of(x)) |>
count(subgroup) |>
mutate(subgroup = as.character(subgroup))
})) |>
unnest(counts) |>
mutate(subgroup_label = fct_inorder(str_glue("{subgroup} (n={n})"))) |>
select(moderator, subgroup, subgroup_label)
```
```{r}
#| label: plot-helpers
# Reference level for each attribute (the first factor level)
reference_levels <- attribute_levels_lookup |>
slice(1, .by = attribute) |>
select(attribute, ref_level = level)
# Subgroup order within each moderator; the first subgroup is the comparison
# baseline for differences (e.g., "Rarely/never", "18–29", "Liberal")
subgroup_order <- subgroup_lookup |>
mutate(subgroup_rank = row_number(), .by = moderator) |>
select(moderator, subgroup, subgroup_rank)
# Conditional MMs → conditional AMCEs → differences in conditional AMCEs
# between subgroups, all within each posterior draw. The MMs for every level
# average over the same grid (H5) or the same randomized profiles (E3), so each
# AMCE is just MM(level) − MM(reference level). (For H5 this matches
# avg_comparisons() exactly.)
build_subgroup_effects <- function(mms_draws) {
mms <- mms_draws |>
mutate(drawid = as.character(drawid)) |>
left_join(reference_levels, by = join_by(attribute)) |>
left_join(subgroup_order, by = join_by(moderator, subgroup))
amces <- mms |>
mutate(
draw = draw - draw[level == ref_level],
.by = c(moderator, attribute, subgroup, drawid)
) |>
filter(level != ref_level)
diffs <- amces |>
mutate(
ref_subgroup = subgroup[subgroup_rank == 1],
draw = draw - draw[subgroup_rank == 1],
.by = c(moderator, attribute, level, drawid)
) |>
filter(subgroup_rank != 1) |>
mutate(comparison = str_glue("{subgroup} − {ref_subgroup}"))
add_labels <- function(df) {
df |>
left_join(attribute_levels_lookup, by = join_by(attribute, level)) |>
left_join(subgroup_lookup, by = join_by(moderator, subgroup)) |>
left_join(moderators, by = join_by(moderator))
}
list(
mms = add_labels(mms),
amces = add_labels(amces),
diffs = add_labels(diffs) |> mutate(comparison = fct_inorder(comparison))
)
}
# Shared pieces for the side-by-side MM | AMCE | difference plots. Every panel
# uses the same rows (attribute levels, with the reference level on top), so
# you can read across a row: the MMs for that level, its AMCE relative to the
# reference level, and how much that AMCE differs between subgroups
facet_attributes <- facet_grid(
rows = vars(attribute_nice),
scales = "free_y",
space = "free_y",
labeller = labeller(attribute_nice = label_wrap_gen(12))
)
# Reference levels get a hollow point at 0 in the AMCE and difference panels.
# This layer goes first and includes *every* level of each attribute (x is NA
# for the non-reference ones), since ggplot builds each discrete y axis from
# the levels in the order the layers see them, dropping unused levels. If this
# layer only had the reference level, the rows would be misaligned with the
# marginal means panel
reference_points <- function(df) {
geom_point(
data = attribute_levels_lookup |>
filter(attribute %in% unique(df$attribute)) |>
left_join(reference_levels, by = join_by(attribute)) |>
mutate(x = if_else(level == ref_level, 0, NA_real_)),
aes(x = x, y = fct_rev(level_nice)),
inherit.aes = FALSE,
shape = 1,
na.rm = TRUE
)
}
hide_y <- theme(axis.text.y = element_blank(), axis.ticks.y = element_blank())
hide_strips <- theme(strip.text.y = element_blank())
# (Groups are reversed in the plots so the dodged order matches the legend)
dodge <- position_dodge(width = 0.8)
# Conditional MMs | conditional AMCEs | differences in AMCEs for one moderator
plot_subgroup_effects <- function(effects, mod, atts = c("rbi", "ubi")) {
mms <- filter(effects$mms, moderator == mod, attribute %in% atts)
amces <- filter(effects$amces, moderator == mod, attribute %in% atts)
diffs <- filter(effects$diffs, moderator == mod, attribute %in% atts)
p_mms <- ggplot(mms, aes(x = draw, y = fct_rev(level_nice), fill = subgroup_label, group = fct_rev(subgroup_label))) +
geom_vline(xintercept = baseline_rate, linetype = "dashed", linewidth = 0.25) +
stat_halfeye(normalize = "groups", position = dodge) +
scale_x_continuous(labels = label_percent()) +
facet_attributes +
labs(
x = "Probability of choosing\nthe profile", y = NULL, fill = NULL,
title = "Marginal means"
) +
hide_strips
p_amces <- ggplot(amces, aes(x = draw, y = fct_rev(level_nice), fill = subgroup_label, group = fct_rev(subgroup_label))) +
reference_points(amces) +
geom_vline(xintercept = 0, linewidth = 0.25) +
stat_halfeye(normalize = "groups", position = dodge) +
scale_x_continuous(labels = label_pp) +
facet_attributes +
labs(
x = "Percentage point change\nvs. reference level", y = NULL, fill = NULL,
title = "AMCEs"
) +
hide_y + hide_strips
p_diffs <- ggplot(diffs, aes(x = draw, y = fct_rev(level_nice), fill = comparison, group = fct_rev(comparison))) +
reference_points(diffs) +
geom_vline(xintercept = 0, linewidth = 0.25) +
stat_halfeye(normalize = "groups", position = dodge) +
scale_x_continuous(labels = label_pp) +
scale_fill_grey(start = 0.4, end = 0.8) +
facet_attributes +
labs(
x = "Difference in AMCEs\n(percentage points)", y = NULL, fill = NULL,
title = "Difference in AMCEs"
) +
hide_y +
theme(strip.text.y = element_text(angle = 0))
(p_mms | p_amces | p_diffs) +
plot_layout(guides = "collect") +
plot_annotation(title = unique(mms$moderator_nice)) &
theme(legend.position = "bottom", legend.direction = "vertical")
}
```
## Reference grids
The estimands are population averages (see [Estimands](estimands.qmd)), but we *compute* them with respondent intercepts set to 0 (`re_formula = NA`) over a **balanced grid** of every possible profile (3 × 3 × 4 × 4 × 2 = 288 profiles), since σ for the respondent intercepts is ≈ 0.02 and the two versions are practically identical (checked [below](#typical-vs-pop)). Averaging over that grid gives every attribute level equal weight, which matches the uniform *marginal* distribution of each attribute in the design. (Profiles within a task aren't drawn independently, since 61% of tasks show three distinct `rbi` levels, which suggests a balanced-overlap design. But each level's marginal frequency is uniform, and a profile-level Bernoulli model doesn't use the within-task competitor distribution.)
It's also much cheaper. Predicting on the observed data means a 36,030-row × 4,000-draw matrix (~1.15 GB) for every call; the grid is 288 × 4,000.
The grid is balanced over the five *attributes* only. Respondent moderators are never put on a balanced grid, since every combination of giving × volunteering × work history (etc.) getting equal weight matches no real population. Instead, they enter at their observed joint distribution (see the [H5](#h5) and [E3](#e3) sections).
::: {.callout-note}
#### Why `datagrid()` with the default `grid_type`?
With the default `grid_type = "mean_or_mode"`, every variable we set to `unique` gets all its levels (crossed), and everything else in the model gets held at its mean or mode. In `model_conjoint` the only other variable is `id`, which gets set to its "mode" (an arbitrary respondent, since everyone has 30 rows). That's irrelevant with `re_formula = NA`, but it means **these grids should never be used with `re_formula = NULL`**; that would give predictions for one specific respondent.
The other grid types don't work here:
- `grid_type = "balanced"` sets *all* factor and character columns to `unique`, including `id` (and the binary `response`), giving 288 × 1,201 × 2 = 691,776 rows.
- `grid_type = "counterfactual"` duplicates the full dataset for each combination of the listed values (36,030 × 288 ≈ 10.4 million rows).
:::
```{r}
#| label: grid-main
# Set each attribute to `unique` (i.e. all its levels) → all 288 profiles.
# `extra` takes additional datagrid() arguments, like list(giving = unique).
# (do.call() rather than rlang::inject(!!!) because inject() inside mutate()
# gets its !!! processed too early by dplyr)
make_grid <- function(model, extra = list()) {
grid_args <- conjoint_attributes |>
set_names() |>
map(\(x) unique)
do.call(datagrid, c(list(model = model), grid_args, extra))
}
grid_main <- make_grid(model_conjoint)
nrow(grid_main)
```
## Overall results
### Marginal means
```{r}
#| label: mms-main
mms_main <- attribute_lookup |>
mutate(
mms = map(attribute, \(att) {
avg_predictions(
model_conjoint,
newdata = grid_main,
by = att,
re_formula = NA
)
})
)
# Long data frame of posterior draws for every attribute level
mms_main_draws <- mms_main |>
mutate(
draws = map2(mms, attribute, \(x, att) {
# avg_predictions() names the `by` column after the attribute (rbi, ubi,
# etc.), so rename it to something consistent before combining
get_draws(x) |>
rename(level = all_of(att))
})
) |>
select(-mms) |>
unnest(draws) |>
left_join(
attribute_levels_lookup,
by = join_by(attribute, attribute_nice, level)
)
```
```{r}
#| label: tbl-mms-main
#| tbl-cap: "Marginal means (posterior medians and 95% credible intervals)"
mms_main_draws |>
group_by(attribute_nice, level_nice) |>
median_qi(draw) |>
select(Attribute = attribute_nice, Level = level_nice, MM = draw, .lower, .upper) |>
knitr::kable(digits = 3)
```
### AMCEs
```{r}
#| label: amces-main
amces_main <- avg_comparisons(
model_conjoint,
variables = conjoint_attributes,
newdata = grid_main,
re_formula = NA
)
amces_main_draws <- get_draws(amces_main) |>
separate_wider_delim(contrast, delim = " - ", names = c("level", "ref")) |>
rename(attribute = term)
```
```{r}
#| label: tbl-amces-main
#| tbl-cap: "AMCEs (posterior medians, 95% credible intervals, and probability of direction)"
amces_main_draws |>
left_join(attribute_levels_lookup, by = join_by(attribute, level)) |>
group_by(attribute_nice, level_nice, ref) |>
summarize(
AMCE = median(draw),
.lower = quantile(draw, 0.025),
.upper = quantile(draw, 0.975),
`P(> 0)` = mean(draw > 0),
.groups = "drop"
) |>
rename(Attribute = attribute_nice, Level = level_nice, Reference = ref) |>
knitr::kable(digits = 3)
```
### Marginal means and AMCEs together
@fig-main-effects shows the MMs and AMCEs side by side. Each row is the same attribute level in both panels, so the AMCE for a level is the gap between its MM and the reference level's MM (the hollow point at 0).
```{r}
#| label: fig-main-effects
#| fig-cap: "Posterior marginal means and AMCEs for all attributes. The dashed line is the overall share of profiles chosen; hollow points mark each attribute's reference level."
#| fig-width: 9
#| fig-height: 7.5
amces_main_plot <- amces_main_draws |>
left_join(attribute_levels_lookup, by = join_by(attribute, level))
p_mms <- ggplot(mms_main_draws, aes(x = draw, y = fct_rev(level_nice), fill = attribute_nice)) +
geom_vline(xintercept = baseline_rate, linetype = "dashed", linewidth = 0.25) +
stat_halfeye(normalize = "groups") +
guides(fill = "none") +
scale_x_continuous(labels = label_percent()) +
facet_attributes +
labs(x = "Probability of choosing the profile", y = NULL, title = "Marginal means") +
hide_strips
p_amces <- ggplot(amces_main_plot, aes(x = draw, y = fct_rev(level_nice), fill = attribute_nice)) +
reference_points(amces_main_plot) +
geom_vline(xintercept = 0, linewidth = 0.25) +
stat_halfeye(normalize = "groups") +
guides(fill = "none") +
scale_x_continuous(labels = label_pp) +
facet_attributes +
labs(x = "Percentage point change vs. reference level", y = NULL, title = "AMCEs") +
hide_y +
theme(strip.text.y = element_text(angle = 0))
p_mms | p_amces
```
## H5: Nonprofit experience {#h5}
> **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).
For each of the four experience indicators, the primary H5 estimands are:
1. The **conditional AMCEs** of RBI (reduced price − free, full price − free) and UBI (event space rental − none, pizza shop − none) among the more- and less-experienced groups
2. Their **difference** (more − less experienced)
3. The posterior probability that the difference is positive. The RBI and UBI AMCEs are negative, so attenuation means the AMCE is *less* negative among the more experienced, and **P(difference > 0) is the posterior probability of H5**.
"More experience" means giving often/occasionally, volunteering often/occasionally, having worked at a nonprofit, and having given $200+ in the past year.
These are **unadjusted** subgroup quantities. The AMCE among frequent givers averages over the observed mix of volunteering, nonprofit work, and $200+ giving *among frequent givers*, not over a balanced grid of the other moderators. To get that from the joint model, we predict on the 288-profile attribute grid × every observed combination of the four indicators, and weight each combination by its number of respondents (`wts = "n_resp"`). With `by = moderator`, {marginaleffects} computes weighted averages within each level of the moderator, so each level gets the observed distribution of the other three indicators within that level.
::: {.callout-important}
#### Reference categories
[Leeper, Hobolt, and Tilley (2020)](https://doi.org/10.1017/pan.2019.30) show that differences in conditional AMCEs depend on the reference category: they mix how subgroups differ on the level of interest with how they differ on the reference level. Here the reference levels (free, no side business) are exactly what H5 is about ("the negative effect of RBI" is the effect of charging relative to not charging), so the AMCE difference is the right estimand. But we also report the companion **conditional MMs** so readers can see whether a difference comes from the RBI levels or from the free baseline.
The moderators aren't randomized, so these differences are descriptive, not causal.
:::
```{r}
#| label: h5-grid
# Observed combinations of the four experience indicators, with the number of
# respondents in each (≤ 2^4 = 16 combinations)
h5_combos <- model_h5$data |>
distinct(id, across(all_of(moderators_h5))) |>
count(across(all_of(moderators_h5)), name = "n_resp")
# 288 attribute profiles × each observed combination. datagrid() also adds the
# moderators at their modes, so drop those before crossing in the combinations
grid_h5 <- make_grid(model_h5) |>
select(-any_of(c("rowid", moderators_h5))) |>
cross_join(h5_combos)
nrow(grid_h5)
```
```{r}
#| label: tbl-h5-combos
#| tbl-cap: "Observed combinations of the four experience indicators (respondents in model_h5)"
knitr::kable(h5_combos)
```
### H5a/H5b: Conditional AMCEs and differences
```{r}
#| label: h5-amces
h5_amces <- tibble(moderator = moderators_h5) |>
mutate(
# Conditional AMCEs of RBI and UBI within each level of the moderator
amces = map(moderator, \(mod) {
avg_comparisons(
model_h5,
variables = c("rbi", "ubi"),
by = mod,
newdata = grid_h5,
wts = "n_resp",
re_formula = NA
)
}),
# Difference in conditional AMCEs: more − less experienced. The less
# experienced group is each moderator's first (reference) level
diffs = map(moderator, \(mod) {
avg_comparisons(
model_h5,
variables = c("rbi", "ubi"),
by = mod,
newdata = grid_h5,
wts = "n_resp",
re_formula = NA,
hypothesis = difference ~ reference | term + contrast
)
})
)
h5_amces_draws <- h5_amces |>
mutate(draws = map2(amces, moderator, \(x, mod) {
get_draws(x) |>
rename(subgroup = all_of(mod)) |>
mutate(subgroup = as.character(subgroup))
})) |>
select(moderator, draws) |>
unnest(draws) |>
mutate(
experience = if_else(
subgroup == h5_more_experienced[moderator],
"More experienced",
"Less experienced"
)
) |>
left_join(moderators, by = join_by(moderator)) |>
left_join(h5_contrasts, by = join_by(term, contrast))
h5_diffs_draws <- h5_amces |>
mutate(draws = map(diffs, get_draws)) |>
select(moderator, draws) |>
unnest(draws) |>
left_join(moderators, by = join_by(moderator)) |>
left_join(h5_contrasts, by = join_by(term, contrast))
```
```{r}
#| label: tbl-h5
#| tbl-cap: "H5a/H5b: Conditional AMCEs among less and more experienced respondents, their difference (more − less), and the posterior probability that the difference is positive (i.e., that the effect is attenuated). Posterior medians with 95% credible intervals."
# Format a vector of draws as "median [2.5%, 97.5%]" in percentage points
label_pp_precise <- label_number(
accuracy = 0.1, scale = 100, suffix = " pp.", style_negative = "minus"
)
fmt_ci <- function(x) {
as.character(str_glue(
"{label_pp_precise(median(x))} ",
"[{label_pp_precise(quantile(x, 0.025))}, {label_pp_precise(quantile(x, 0.975))}]"
))
}
h5_amces_summary <- h5_amces_draws |>
summarize(amce = fmt_ci(draw), .by = c(moderator_nice, contrast_nice, experience)) |>
pivot_wider(names_from = experience, values_from = amce)
h5_diffs_summary <- h5_diffs_draws |>
summarize(
`Difference (more − less)` = fmt_ci(draw),
`P(diff > 0)` = mean(draw > 0),
.by = c(moderator_nice, contrast_nice)
)
h5_amces_summary |>
left_join(h5_diffs_summary, by = join_by(moderator_nice, contrast_nice)) |>
arrange(contrast_nice, moderator_nice) |>
select(
Contrast = contrast_nice, Moderator = moderator_nice,
`Less experienced`, `More experienced`, everything()
) |>
knitr::kable(digits = 3)
```
### Companion conditional marginal means
```{r}
#| label: h5-mms
# Conditional MMs for every attribute within each level of each H5 moderator,
# averaging over the observed combinations of the other three indicators
mms_h5 <- expand_grid(moderator = moderators_h5, attribute = conjoint_attributes) |>
mutate(
mms = map2(attribute, moderator, \(att, mod) {
avg_predictions(
model_h5,
newdata = grid_h5,
by = c(att, mod),
wts = "n_resp",
re_formula = NA
)
})
)
mms_h5_draws <- mms_h5 |>
mutate(
draws = pmap(list(mms, attribute, moderator), \(x, att, mod) {
get_draws(x) |>
rename(level = all_of(att), subgroup = all_of(mod)) |>
# Subgroup levels differ across moderators, so make them all character
# before stacking (the order comes back from subgroup_lookup)
mutate(subgroup = as.character(subgroup))
})
) |>
select(moderator, attribute, draws) |>
unnest(draws) |>
select(moderator, attribute, level, subgroup, drawid, draw)
```
```{r}
#| label: tbl-h5-mms
#| tbl-cap: "Conditional MMs for RBI and UBI levels among less and more experienced respondents, and their difference (more − less)"
mms_h5_draws |>
filter(attribute %in% c("rbi", "ubi")) |>
mutate(
experience = if_else(subgroup == h5_more_experienced[moderator], "more", "less")
) |>
select(-subgroup) |>
pivot_wider(names_from = experience, values_from = draw) |>
mutate(diff = more - less) |>
left_join(moderators, by = join_by(moderator)) |>
left_join(attribute_levels_lookup, by = join_by(attribute, level)) |>
summarize(
`MM (less)` = median(less),
`MM (more)` = median(more),
`Difference` = fmt_ci(diff),
`P(diff > 0)` = mean(diff > 0),
.by = c(moderator_nice, attribute_nice, level_nice)
) |>
rename(Moderator = moderator_nice, Attribute = attribute_nice, Level = level_nice) |>
knitr::kable(digits = 3)
```
### H5 figures
Each figure below shows one experience indicator, with three panels that share the same rows:
1. **Marginal means**: the probability of choosing a profile at each RBI/UBI level, for the less and more experienced groups
2. **AMCEs**: each level's MM minus the reference level's MM (free; no side business), within each group
3. **Difference in AMCEs**: more − less experienced. This is the H5 estimand; values above 0 mean the (negative) AMCE is smaller among the more experienced, as H5 predicts
Reading across a row connects the contrast back to the MMs it comes from: e.g., for volunteering, the full price AMCE is less negative among volunteers mostly because their MM at full price is higher (their MM at free is only slightly lower).
```{r}
#| label: h5-effects
effects_h5 <- build_subgroup_effects(mms_h5_draws)
```
```{r}
#| label: fig-h5-giving
#| fig-cap: "H5: Conditional MMs, AMCEs, and differences in AMCEs by giving frequency"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_h5, "giving")
```
```{r}
#| label: fig-h5-volunteering
#| fig-cap: "H5: Conditional MMs, AMCEs, and differences in AMCEs by volunteering frequency"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_h5, "volunteering")
```
```{r}
#| label: fig-h5-npo-work
#| fig-cap: "H5: Conditional MMs, AMCEs, and differences in AMCEs by nonprofit work experience"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_h5, "npo_work")
```
```{r}
#| label: fig-h5-gave-200
#| fig-cap: "H5: Conditional MMs, AMCEs, and differences in AMCEs by past-year giving ($200+)"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_h5, "gave_200")
```
### Adjusted (Jensen-style) differences
As a secondary analysis, here's the *adjusted* version: set everyone's level of the moderator counterfactually (e.g., everyone gives often, then everyone gives rarely), hold the other three indicators at their observed values, and compare. This asks whether, say, giving frequency is associated with RBI sensitivity *net of* volunteering, nonprofit work, and large gifts.
```{r}
#| label: tbl-h5-adjusted
#| tbl-cap: "Unadjusted vs. adjusted differences in conditional AMCEs (more − less experienced)"
h5_adjusted <- tibble(moderator = moderators_h5) |>
mutate(diffs = map(moderator, \(mod) {
lvls <- levels(model_h5$data[[mod]])
# Stack one copy of the grid per moderator level, with the moderator set
# to that level for every row (the other indicators keep their observed
# combinations and weights)
grid_cf <- lvls |>
map(\(l) {
grid_h5 |>
mutate(across(all_of(mod), \(x) factor(l, levels = lvls)))
}) |>
list_rbind()
avg_comparisons(
model_h5,
variables = c("rbi", "ubi"),
by = mod,
newdata = grid_cf,
wts = "n_resp",
re_formula = NA,
hypothesis = difference ~ reference | term + contrast
)
}))
h5_adjusted_draws <- h5_adjusted |>
mutate(draws = map(diffs, get_draws)) |>
select(moderator, draws) |>
unnest(draws) |>
left_join(moderators, by = join_by(moderator)) |>
left_join(h5_contrasts, by = join_by(term, contrast))
bind_rows(
h5_diffs_draws |> mutate(version = "Unadjusted"),
h5_adjusted_draws |> mutate(version = "Adjusted")
) |>
summarize(
diff = fmt_ci(draw),
p = mean(draw > 0),
.by = c(contrast_nice, moderator_nice, version)
) |>
pivot_wider(names_from = version, values_from = c(diff, p)) |>
arrange(contrast_nice, moderator_nice) |>
select(
Contrast = contrast_nice, Moderator = moderator_nice,
Unadjusted = diff_Unadjusted, `P(> 0), unadj.` = p_Unadjusted,
Adjusted = diff_Adjusted, `P(> 0), adj.` = p_Adjusted
) |>
knitr::kable(digits = 3)
```
## E3: Demographics {#e3}
> **E3**: Effects of RBI and UBI may vary by age, gender, education, income, marital status, political ideology, religiosity, and race.
The E3 quantities are the same unadjusted subgroup MMs and AMCEs, but we can't use the H5 approach. The eight demographics have `r nrow(distinct(model_e3$data, across(all_of(moderators_e3))))` observed combinations, so the attribute grid × combinations would be ~186,000 rows. That's a ~6 GB prediction matrix with 4,000 draws, and `avg_comparisons()` would need several of them.
Instead, we **predict once on the observed rows** of the model data (`r scales::comma(nrow(model_e3$data))` rows, ~1.1 GB) with `re_formula = NA`, and average the draws within each attribute level × subgroup cell. This automatically uses the observed joint distribution of the other seven demographics within each subgroup. It also uses the observed distribution of the other attributes, which is uniform in expectation because of randomization rather than exactly uniform like the grid. Conditional AMCEs are then differences in these MMs within each posterior draw. Because the attributes are randomized, that's the same estimand as the counterfactual contrast, up to tiny finite-sample imbalances in the profiles shown within each cell.
If 1.1 GB is too much, add `ndraws = 1000` to the `predictions()` call.
```{r}
#| label: e3-predictions
# One prediction for every observed row, for every posterior draw
preds_e3 <- predictions(model_e3, re_formula = NA)
# If memory is tight:
# preds_e3 <- predictions(model_e3, re_formula = NA, ndraws = 1000)
# Rows = observations, columns = posterior draws
preds_e3_matrix <- get_draws(preds_e3, shape = "PxD")
preds_e3_data <- as_tibble(preds_e3) |>
select(all_of(c(conjoint_attributes, moderators_e3)))
# Average the prediction draws within each attribute level × subgroup cell.
# rowsum() adds up the rows within each cell, so dividing by the cell sizes
# gives cell means for every draw at once
cell_mean_draws <- function(att, mod) {
cells <- interaction(
preds_e3_data[[att]], preds_e3_data[[mod]],
sep = "___", drop = TRUE, lex.order = TRUE
)
sums <- rowsum(preds_e3_matrix, cells)
counts <- rowsum(rep(1, length(cells)), cells)
(sums / as.vector(counts)) |>
as_tibble(rownames = "cell") |>
pivot_longer(-cell, names_to = "drawid", values_to = "draw") |>
separate_wider_delim(cell, delim = "___", names = c("level", "subgroup"))
}
mms_e3_draws <- expand_grid(moderator = moderators_e3, attribute = conjoint_attributes) |>
mutate(draws = map2(attribute, moderator, cell_mean_draws)) |>
unnest(draws)
```
As a check, the cell means match `avg_predictions()` for one cell:
```{r}
#| label: e3-check
check_e3 <- avg_predictions(model_e3, by = c("rbi", "ideology"), re_formula = NA)
mms_e3_draws |>
filter(moderator == "ideology", attribute == "rbi") |>
summarize(cell_means = median(draw), .by = c(level, subgroup)) |>
left_join(
as_tibble(check_e3) |>
mutate(across(c(rbi, ideology), as.character)) |>
select(level = rbi, subgroup = ideology, avg_predictions = estimate),
by = join_by(level, subgroup)
)
rm(check_e3)
```
```{r}
#| label: e3-amces
# Conditional AMCEs (each attribute level − reference level, within each
# subgroup and draw) and differences in conditional AMCEs (each subgroup − the
# moderator's first subgroup, within each level and draw)
effects_e3 <- build_subgroup_effects(mms_e3_draws)
```
```{r}
#| label: tbl-e3
#| tbl-cap: "E3: Differences in conditional AMCEs of RBI and UBI between demographic subgroups (each subgroup − reference subgroup)"
effects_e3$diffs |>
filter(attribute %in% c("rbi", "ubi")) |>
mutate(contrast = str_glue("{level} − {ref_level}")) |>
summarize(
Difference = fmt_ci(draw),
`P(diff > 0)` = mean(draw > 0),
.by = c(moderator_nice, contrast, comparison)
) |>
rename(Moderator = moderator_nice, Contrast = contrast, Comparison = comparison) |>
knitr::kable(digits = 3)
```
### E3 figures
Same layout as the [H5 figures](#h5-figures): marginal means, AMCEs, and differences in AMCEs, with the rows lined up across panels. For moderators with more than two groups, the differences are each group minus the first group (e.g., each age group − 18–29; moderate and conservative − liberal).
```{r}
#| label: fig-e3-age
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by age"
#| fig-width: 10
#| fig-height: 7
#| column: page
plot_subgroup_effects(effects_e3, "age_group")
```
```{r}
#| label: fig-e3-gender
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by gender"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_e3, "gender")
```
```{r}
#| label: fig-e3-education
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by education"
#| fig-width: 10
#| fig-height: 6.5
#| column: page
plot_subgroup_effects(effects_e3, "education")
```
```{r}
#| label: fig-e3-income
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by household income"
#| fig-width: 10
#| fig-height: 6.5
#| column: page
plot_subgroup_effects(effects_e3, "income")
```
```{r}
#| label: fig-e3-marital
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by marital status"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_e3, "marital")
```
```{r}
#| label: fig-e3-ideology
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by political ideology"
#| fig-width: 10
#| fig-height: 6.5
#| column: page
plot_subgroup_effects(effects_e3, "ideology")
```
```{r}
#| label: fig-e3-religion
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by religious affiliation"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_e3, "religious")
```
```{r}
#| label: fig-e3-race
#| fig-cap: "E3: Conditional MMs, AMCEs, and differences in AMCEs by race"
#| fig-width: 10
#| fig-height: 5.5
#| column: page
plot_subgroup_effects(effects_e3, "race")
```
## All attributes by subgroup
The same three-panel layout for all five attributes, for every moderator. The H5 indicators come from `model_h5` (averaged over the attribute grid × observed combinations of the other indicators) and the E3 demographics come from `model_e3` (averaged over the observed rows). These aren't part of the preregistered hypotheses (which are only about RBI and UBI), but they show whether subgroup differences are specific to commercialization or show up across the board, which would suggest a general difference in choice behavior (like opting out; see below) rather than a reaction to RBI/UBI.
```{r}
#| label: all-attributes-h5
#| fig-width: 10
#| fig-height: 9
#| column: page
moderators_h5 |>
map(\(mod) plot_subgroup_effects(effects_h5, mod, atts = conjoint_attributes)) |>
walk(print)
```
```{r}
#| label: all-attributes-e3
#| fig-width: 10
#| fig-height: 9
#| column: page
moderators_e3 |>
map(\(mod) plot_subgroup_effects(effects_e3, mod, atts = conjoint_attributes)) |>
walk(print)
```
## Opting out ("none") by subgroup
The "none" option was dropped from the data, so every row is a real profile, but respondents chose "none" in some tasks, and that opt-out rate differs across subgroups. Because each subgroup's MMs are probabilities of choosing a *profile*, a subgroup that opts out more will have lower MMs across the board, even if its relative preferences across attribute levels are identical. **Differences in conditional MMs therefore mix attribute preferences with opt-out propensity.** A uniform level shift in the MM differences for a moderator is likely an opt-out story, not an attribute story; differences that vary across levels of an attribute are the more interesting ones. (AMCEs are differences within a subgroup, so a pure level shift mostly cancels out of them, though not exactly on the probability scale.)
Here are the raw opt-out rates (share of tasks where none of the three profiles was chosen):
```{r}
#| label: tbl-none-by-subgroup
#| tbl-cap: "Share of tasks where the respondent chose \"none\", by subgroup (raw data)"
# One row per respondent × task; "none" means no profile in the task was chosen
tasks_none <- conjoint |>
summarize(
chose_none = sum(response) == 0,
.by = c(id, task, all_of(moderators$moderator))
)
bind_rows(
tibble(family = "", moderator_nice = "Everyone", subgroup = "All respondents",
p_none = mean(tasks_none$chose_none), tasks = nrow(tasks_none)),
moderators |>
mutate(rates = map(moderator, \(x) {
tasks_none |>
select(subgroup = all_of(x), chose_none) |>
drop_na(subgroup) |>
summarize(p_none = mean(chose_none), tasks = n(), .by = subgroup) |>
arrange(subgroup) |>
mutate(subgroup = as.character(subgroup))
})) |>
unnest(rates) |>
mutate(moderator_nice = as.character(moderator_nice))
) |>
select(
Family = family, Moderator = moderator_nice, Subgroup = subgroup,
`P(none)` = p_none, Tasks = tasks
) |>
knitr::kable(digits = 3)
```
## Check: `re_formula = NA` vs. `NULL` {#typical-vs-pop}
Everything above sets the respondent intercepts to 0 (`re_formula = NA`). The population-averaged estimand strictly averages over respondents' intercepts too: predict each observed row with its own respondent intercept (`re_formula = NULL`) and average those (see the [Estimands](estimands.qmd) page). This section checks that the shortcut doesn't matter, for the main model only.
The two versions differ in two ways: (1) how they handle the respondent intercepts, and (2) the observed data uses the empirical distribution of attribute levels, which is only approximately uniform. With a logit link, the two can diverge when $\sigma_0$ is large, but here $\sigma_0$ is tiny (≈0.02 in an earlier fit), so they should be nearly identical.
::: {.callout-warning}
#### Memory
Each `avg_predictions()` call on the observed data builds a 36,030 × 4,000 matrix of predictions (~1.15 GB). If that's a problem, add `ndraws = 1000` (passed through to `brms::posterior_epred()`) to use a random subset of draws.
:::
```{r}
#| label: mms-main-pop
# No newdata → use the data the model was fit on; re_formula = NULL → include
# each respondent's estimated intercept
mms_main_pop <- attribute_lookup |>
mutate(
mms = map(attribute, \(att) {
avg_predictions(model_conjoint, by = att, re_formula = NULL)
# If memory is tight:
# avg_predictions(model_conjoint, by = att, re_formula = NULL, ndraws = 1000)
})
)
mms_main_pop_draws <- mms_main_pop |>
mutate(
draws = map2(mms, attribute, \(x, att) {
get_draws(x) |>
rename(level = all_of(att))
})
) |>
select(-mms) |>
unnest(draws) |>
left_join(
attribute_levels_lookup,
by = join_by(attribute, attribute_nice, level)
)
# AMCEs as differences in these MMs, within each draw. Strictly, the
# counterfactual version is avg_comparisons(model_conjoint, variables = ...,
# re_formula = NULL), but that predicts 2 × (number of contrasts) copies of the
# full data (several GB per attribute). Because attributes are randomized, the
# difference in observed-data MMs is essentially the same thing.
amces_main_pop_draws <- mms_main_pop_draws |>
group_by(attribute, drawid) |>
mutate(draw = draw - first(draw, order_by = level_nice)) |>
ungroup() |>
filter(level_nice != first(level_nice, order_by = level_nice), .by = attribute)
```
```{r}
#| label: fig-typical-vs-pop
#| fig-cap: "Marginal means and AMCEs computed with intercepts at 0 over the balanced grid (`re_formula = NA`) and with each respondent's intercept over the observed data (`re_formula = NULL`)"
#| fig-height: 6
estimand_versions <- c(
"Balanced grid, re_formula = NA",
"Observed data, re_formula = NULL"
)
p_mms <- bind_rows(
mms_main_draws |> mutate(version = estimand_versions[1]),
mms_main_pop_draws |> mutate(version = estimand_versions[2])
) |>
mutate(version = factor(version, levels = estimand_versions)) |>
ggplot(aes(x = draw, y = level_nice, color = version)) +
stat_pointinterval(position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = label_percent()) +
labs(x = "Marginal mean", y = NULL, color = NULL, title = "Marginal means") +
facet_wrap(vars(attribute_nice), scales = "free_y", ncol = 2) +
theme(legend.position = "bottom")
p_amces <- bind_rows(
amces_main_draws |>
left_join(attribute_levels_lookup, by = join_by(attribute, level)) |>
mutate(version = estimand_versions[1]),
amces_main_pop_draws |> mutate(version = estimand_versions[2])
) |>
mutate(version = factor(version, levels = estimand_versions)) |>
ggplot(aes(x = draw, y = level_nice, color = version)) +
geom_vline(xintercept = 0) +
stat_pointinterval(position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = label_pp) +
labs(x = "AMCE", y = NULL, color = NULL, title = "AMCEs") +
facet_wrap(vars(attribute_nice), scales = "free_y", ncol = 2) +
theme(legend.position = "bottom")
p_mms
p_amces
```
```{r}
#| label: tbl-typical-vs-pop
#| tbl-cap: "Posterior medians of the marginal means under each version, and their difference"
bind_rows(
mms_main_draws |> mutate(version = "re_formula_NA"),
mms_main_pop_draws |> mutate(version = "re_formula_NULL")
) |>
group_by(attribute_nice, level_nice, version) |>
summarize(estimate = median(draw), .groups = "drop") |>
pivot_wider(names_from = version, values_from = estimate) |>
mutate(difference = re_formula_NA - re_formula_NULL) |>
select(
Attribute = attribute_nice, Level = level_nice,
`NA (grid)` = re_formula_NA, `NULL (observed)` = re_formula_NULL, difference
) |>
knitr::kable(digits = 4)
```
A third version, integrating the random effects out over new simulated respondents (`allow_new_levels = TRUE, sample_new_levels = "gaussian"` with a grid of fake `id`s; see [this post](https://www.andrewheiss.com/blog/2022/11/29/conditional-marginal-marginaleffects/)), isn't worth it with $\sigma_0$ this small, but it's the one to use if we ever add random slopes.
## Robustness: multinomial model
This compares the overall AMCEs from `model_conjoint` (Bernoulli) with the categorical (multinomial) version on the [Models](models.qmd#robustness-multinomial) page, which mirrors the preregistered hierarchical multinomial logit (deviation #1). That model isn't fit by default, so this section only runs if `output/model_conjoint_categorical.rds` exists.
```{r}
#| label: categorical-amces
#| eval: !expr file.exists(here::here("output", "model_conjoint_categorical.rds"))
model_conjoint_categorical <- readRDS(here("output", "model_conjoint_categorical.rds"))
# P(profile chosen) = 1 − P(category 0, "not chosen"), over the same balanced
# 288-profile grid with intercepts at 0
preds_categorical <- model_conjoint_categorical |>
epred_draws(newdata = grid_main, re_formula = NA) |>
ungroup() |>
filter(.category == "0") |>
mutate(.epred = 1 - .epred)
# MMs for each attribute level, then AMCEs relative to the reference level
amces_categorical_draws <- attribute_lookup |>
mutate(mms = map(attribute, \(att) {
preds_categorical |>
summarize(draw = mean(.epred), .by = c(all_of(att), .draw)) |>
rename(level = all_of(att)) |>
mutate(level = as.character(level))
})) |>
unnest(mms) |>
left_join(
attribute_levels_lookup,
by = join_by(attribute, attribute_nice, level)
) |>
mutate(draw = draw - first(draw, order_by = level_nice), .by = c(attribute, .draw)) |>
filter(level_nice != first(level_nice, order_by = level_nice), .by = attribute)
```
```{r}
#| label: fig-categorical-amces
#| fig-cap: "AMCEs from the Bernoulli and categorical (multinomial) models"
#| fig-height: 6
#| eval: !expr file.exists(here::here("output", "model_conjoint_categorical.rds"))
bind_rows(
amces_main_draws |>
left_join(attribute_levels_lookup, by = join_by(attribute, level)) |>
mutate(model = "Bernoulli (model_conjoint)"),
amces_categorical_draws |>
mutate(model = "Categorical (model_conjoint_categorical)")
) |>
ggplot(aes(x = draw, y = level_nice, color = model)) +
geom_vline(xintercept = 0) +
stat_pointinterval(position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = label_pp) +
labs(x = "AMCE", y = NULL, color = NULL) +
facet_wrap(vars(attribute_nice), scales = "free_y", ncol = 2) +
theme(legend.position = "bottom")
```
## Sample vs. US adults
::: {.callout-note}
#### TODO
Appendix table comparing the sample's demographics (age, gender, race, education, income, marital status) with the American Community Survey. This is descriptive context for generalizing the population-average estimands; we're not reweighting or doing MRP.
:::
## tl;dr
These numbers are typed in by hand from the tables above, so they'll need to be updated if the models change (or later I can use real inline code chunks)
**Overall**
- Price matters most. Compared to free core services, a reduced price lowers the probability of choosing a nonprofit by 14 percentage points, and full price lowers it by 26.
- Side businesses matter much less: −2 points for event space rental and −5 for a pizza shop.
- For scale: a mental health center gets +16 points over an arts center, being under financial stress gets +6.5 over being in good condition, and earmarking donations for rainy day funds or unrestricted use costs about 6 points compared to paying program staff.
**H5 (nonprofit experience)**
- H5a (price) is supported for volunteering only. The full price penalty is 5.1 points smaller among people who volunteer [2.5, 7.6], and the reduced price penalty is 2.8 points smaller [0.1, 5.5]. Both hold when adjusting for the other three indicators (5.4 and 3.1).
- Volunteers' smaller penalty comes mostly from a higher MM at full price, not a lower MM at free.
- Giving frequency and $200+ giving have small positive differences in the price AMCEs (1.1–1.4 points, P(> 0) of 0.69–0.87) that go to about zero after adjustment. Nonprofit work shows nothing.
- H5b (side businesses) isn't supported. Every UBI difference is within ±1.6 points and every interval includes 0. There's not much of a UBI effect to attenuate in the first place.
**E3 (demographics, exploratory)**
- The full price penalty is smaller among conservatives (7.6 points smaller than liberals) and moderates (5.5), religious respondents (5.7), non-White respondents (4.5), and married or partnered respondents (3.1). Differences for reduced price are smaller and mostly include 0.
- Part of the ideology gap is at the free level: liberals' MM for free services (~46%) is higher than conservatives' (~41%). Liberals reward free services more, and conservatives penalize full price less.
- A few other single comparisons clear 0 (men's reduced price penalty is 3.2 points larger than women's; married respondents' pizza shop penalty is 3.1 points larger), but they don't form a pattern, and with 52 E3 comparisons a few of these are expected by chance.
- Age, education, and income show no consistent differences.
**Caveats**
- Subgroups differ in how often they chose "none" (e.g., 5.7% for liberals vs. 12% for moderates and conservatives; 6.0% for volunteers vs. 10.8% for non-volunteers). This shifts their MMs up or down, and differences in AMCEs only partly cancel it out.
- None of the moderators are randomized, so subgroup differences are descriptive. Ideology, religion, education, income, and marital status were measured after the conjoint.
- Setting respondent intercepts to 0 vs. averaging over each respondent's intercept changes the MMs by at most 0.16 points.