In this report, we reproduce the analyses testing between group differences in Study 4.
First, we load the relevant packages, define functions and plotting aesthetics, and load and tidy the data.
# parameter estimate plotting function for purrr models
plot_model = function(model_data, palette, size = .75, facet = NULL, sharing_type = FALSE) {
mod_renamed = model_data %>%
mutate(term = gsub("msg_", "", term),
term = gsub("_", " ", term),
term = gsub(":", " x ", term),
term = gsub(" z", "", term),
term = gsub("rel self x topichealth", "self-relevance x\ntopic (health)", term),
term = gsub("topichealth x rel social", "social relevance x\ntopic (health)", term),
term = gsub("topichealth", "topic (health)", term),
term = gsub("rel self", "self\nrelevance", term),
term = gsub("rel social", "social\nrelevance", term),
term = gsub(" within", "\nwithin", term),
term = gsub(" between", "\nbetween", term),
term = gsub("article condother", "other > control", term),
term = gsub("article condself", "self > control", term),
term = gsub("condition", "group", term),
term = gsub("grouptimed", "group (timed)", term),
term = gsub("groupuntimed", "group (untimed)", term),
term = gsub("x topic \\(health\\)", "x\ntopic (health)", term))
if (isTRUE(sharing_type)) {
mod_renamed = mod_renamed %>%
mutate(sharing_type = recode(sharing_type, "msg_share_broad" = "broadcast sharing",
"msg_share_narrow" = "narrowcast sharing"))
}
mod = mod_renamed %>%
ggplot(aes(x = term, y = estimate)) +
geom_pointrange(aes( ymin = conf.low, ymax = conf.high), position = position_dodge(.5), size = size, linewidth = size) +
geom_hline(yintercept = 0, color = "grey50", linetype = "dotted") +
coord_flip() +
scale_fill_manual(name = "", values = palette) +
scale_color_manual(name = "", values = palette) +
labs(x = "", y = "\nstandardized regression coefficient\n") +
plot_aes
if (!is.null(facet)) {
mod +
facet_grid(~ get(facet))
} else {
mod
}
}
# plot model predictions function
# parameter estimate plotting function for purrr models
plot_predicted = function(predicted_data, palette, size = .75, facet = NULL, sharing_type = FALSE) {
if (isTRUE(sharing_type)) {
predicted_data = predicted_data %>%
mutate(sharing_type = recode(sharing_type, "msg_share_broad" = "broadcast sharing",
"msg_share_narrow" = "narrowcast sharing"))
}
mod = predicted_data %>%
ggplot(aes(x = group, y = predicted)) +
geom_pointrange(aes( ymin = conf.low, ymax = conf.high), position = position_dodge(.5), size = size, linewidth = size) +
geom_hline(yintercept = 0, color = "grey50", linetype = "dotted") +
coord_flip() +
scale_fill_manual(name = "", values = palette) +
scale_color_manual(name = "", values = palette) +
labs(x = "", y = "\nstandardized regression coefficient\n") +
plot_aes
if (!is.null(facet)) {
mod +
facet_grid(facet)
} else {
mod
}
}
# MLM results table function
table_model = function(model_data, sharing_type = FALSE, intercept = FALSE, spread = FALSE) {
mod = model_data %>%
rename("SE" = std.error,
"t" = statistic,
"p" = p.value) %>%
select(-group, -effect) %>%
mutate_at(vars(-contains("term"), -contains("value"), -contains("sharing_type"), -p), round, 2) %>%
mutate(term = gsub("msg_", "", term),
term = gsub("_", " ", term),
term = gsub(":", " x ", term),
term = gsub("z", "", term),
term = gsub("topichealth", "topic (health)", term),
term = gsub("rel self", "self-relevance", term),
term = gsub("rel social", "social relevance", term),
term = gsub("within", "within", term),
term = gsub("between", "between", term),
term = gsub("sharing type", "sharing type (narrowcast)", term),
term = ifelse(grepl("between x ", term), "sharing type (narrowcast) x social relevance between", term),
term = gsub("article condself", "self - control", term),
term = gsub("article condother", "other - control", term),
term = gsub("conditiontimed", "group (timed)", term),
term = gsub("conditionuntimed", "group (untimed)", term),
term = gsub("\\(Intercept\\)", "control", term),
p = ifelse(p < .001, "< .001",
ifelse(p == 1, "1.000", gsub("0.(.*)", ".\\1", sprintf("%.3f", p)))),
`b [95% CI]` = sprintf("%.2f [%0.2f, %.2f]", estimate, conf.low, conf.high))
if (isTRUE(intercept)) {
mod = mod %>%
mutate(term = recode(term, "control" = "intercept"))
}
if (isTRUE(sharing_type)) {
mod = mod %>%
mutate(sharing_type = recode(sharing_type, "msg_share_broad" = "broadcast sharing",
"msg_share_narrow" = "narrowcast sharing")) %>%
select(sharing_type, term, `b [95% CI]`, df, t, p)
} else {
mod = mod %>%
select(term, `b [95% CI]`, df, t, p)
}
if (isTRUE(spread)) {
mod %>%
select(-df, -t, -p) %>%
spread(`b [95% CI]`) %>%
kable() %>%
kableExtra::kable_styling()
} else {
mod %>%
kable() %>%
kableExtra::kable_styling()
}
}palette_condition = c("self" = "#ee9b00",
"control" = "#bb3e03",
"other" = "#005f73")
palette_group = c("comment" = "#005f73",
"timed" = "#5F0F40",
"untimed" = "#D295BF")
palette_group_con = c("timed > comment" = "#5F0F40",
"untimed > comment" = "#D295BF")
plot_aes = theme_minimal() +
theme(legend.position = "top",
legend.text = element_text(size = 12),
text = element_text(size = 16, family = "Futura Medium"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.text = element_text(color = "black"),
axis.line = element_line(colour = "black"),
axis.ticks.y = element_blank())data = read.csv("../data/study4_data.csv", stringsAsFactors = FALSE) %>%
select(-sharing_type) %>%
rename("sharing_type" = sharing_type_key) %>%
group_by(sharing_type) %>%
mutate(article_cond = ifelse(article_cond == "social", "other", article_cond),
msg_share_z = scale(msg_share, center = TRUE, scale = TRUE),
msg_rel_self_z = scale(msg_rel_self, center = TRUE, scale = TRUE),
msg_rel_social_z = scale(msg_rel_social, center = TRUE, scale = TRUE)) %>%
rename("condition" = group) %>%
ungroup()
sub_conditions = data %>%
select(SID, condition) %>%
unique()Sample size by group
data %>%
select(condition, SID) %>%
unique() %>%
group_by(condition) %>%
summarize(n = n()) %>%
kable() %>%
kable_styling()| condition | n |
|---|---|
| comment | 124 |
| timed | 157 |
| untimed | 167 |
Summarize means and SDs
data %>%
select(-msg_share_z) %>%
spread(sharing_type, msg_share) %>%
gather(variable, value, msg_share_broad, msg_share_narrow, msg_rel_self, msg_rel_social) %>%
group_by(variable) %>%
summarize(M = mean(value, na.rm = TRUE),
SD = sd(value, na.rm = TRUE)) %>%
mutate(variable = recode(variable, "msg_rel_self" ="self-relevance",
"msg_rel_social" = "social relevance",
"msg_share_broad" = "broadcast intention",
"msg_share_narrow" = "narrowcast intention")) %>%
kable(digits = 2) %>%
kableExtra::kable_styling()| variable | M | SD |
|---|---|---|
| self-relevance | 49.33 | 34.19 |
| social relevance | 54.47 | 33.04 |
| broadcast intention | 27.56 | 31.40 |
| narrowcast intention | 35.65 | 33.96 |