-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
I have a Gaussian DV with 3+ groups. I'd like to compare the means with a standardized mean difference (SMD, like a Cohen's d), but standardized with pairwise pooled SDs, rather than the overall pooled SD. I think the nicest way to do this is to use compare_levels() twice, first for the raw mean contrasts, and then second to compute the pairwise pooled SDs. Then I can combine the two to compute the pairwise SMDs. Is this the preferred approach, or can you see a better alternative?
# Load
library(tidyverse)
library(brms)
library(tidybayes)
# Make the data
set.seed(3)
dat <- data.frame(
group = letters[1:3],
mu = -1:1,
sigma = 9:11 / 10) |>
mutate(y = map2(mu, sigma, .f = \(mu, sigma) rnorm(n = 200, mean = mu, sd = sigma))) |>
select(group, y) |>
unnest(y)
# dat |>
# group_by(group) |>
# summarise(m = mean(y),
# s = sd(y))
# Fit the model
fit <- brm(
data = dat,
bf(y ~ 1 + group, sigma ~ 1 + group),
cores = 4, seed = 1)
# Wrangle
left_join(
# Mean contrasts
distinct(dat, group) |>
add_linpred_draws(fit, value = "mu") |>
compare_levels(variable = mu, by = group),
# Pairwise pooled SDs
distinct(dat, group) |>
add_linpred_draws(fit, dpar = "sigma", transform = TRUE) |>
compare_levels(variable = sigma, by = group, fun = \(a, b) sqrt((a^2 + b^2) / 2)) |>
# Adjust the name for the join
mutate(group = str_replace(group, ":", "-")),
by = join_by(.chain, .iteration, .draw, group)
) |>
# Compute the pairwise SMDs
mutate(smd = mu / sigma) |>
# Plot
ggplot(aes(x = smd, y = group)) +
stat_halfeye() +
labs(x = "Mean difference standardized with the pairwise pooled SD",
y = NULL)

Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels