Load packages
# Packages
library(tidyverse)
library(ggdist)
library(extrafont)
library(distributional)
used in the analysis reported in the article #Knowledge: Improving food-related knowledge via seeding implemented as a social media intervention
August 21, 2024
# Plot colors
clrs <- c("#54AA8F","#00335B",
"#22A884FF","#414487FF",
"#496aa2","#e46c0a","#90b6d4")
# ggplot theme
theme_nice <- function(){
theme_minimal(base_family = "Jost") +
theme(plot.title = element_text(hjust = 0.5,size = 20),
panel.grid.minor = element_blank(),
text = element_text(size = 20),
panel.border = element_rect(colour = "black", linewidth = 0.5, fill = NA),
axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(3, 3, 0, 0), "mm"), angle = 90),
legend.title = element_text(face = "bold",size=16),
strip.text = element_text(face = "bold"),
legend.position = "bottom"
)}
dist_1 <- tibble(
dist = dist_inverse_gamma(5,1),
dist_name = "~sigma[r/epsilon] %~% InvGamma(5,1)")
dist_2 <- tibble(
dist = "lkjcorr_marginal",
dist_name = "rho[r] %~% lkj(2)")
ggplot() +
stat_halfeye(data = dist_1,aes(xdist = dist)) +
stat_halfeye(data = dist_2,aes(xdist = dist, arg1 = 3, arg2 = 2)) +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "")
dist_df <- tibble(
dist = c(dist_normal(-.75,.50), dist_student_t(3, -.20, .15)),
dist_name = c("b[0] %~% Normal(-0.75,0.50)",
"b[1] %~% Student_t(3, -0.20, 0.15)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Metric Knowledge")
dist_df <- tibble(
dist = c(dist_normal(0,.50), dist_normal(0.05,.50)),
dist_name = c("b[0] %~% Normal(0, 0.50)",
"b[1] %~% Normal(0.05, 0.50)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Mapping Knowledge")
dist_df <- tibble(
dist = c(dist_normal(-1,.50), dist_student_t(3, .10, .20)),
dist_name = c("b[0] %~% Normal(-1.00,0.50)",
"b[1] %~% Student_t(3, 0.10, 0.20)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Metric Knowledge")
dist_df <- tibble(
dist = c(dist_normal(0,.50), dist_normal(0.05,.50)),
dist_name = c("b[0] %~% Normal(0, 0.50)",
"b[1] %~% Normal(-0.05, 0.50)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Mapping Knowledge")
dist_df <- tibble(
dist = c(dist_normal(-.75,.50), dist_student_t(3, -.20, .15),
dist_normal(-.20,1.0), dist_student_t(3, .20, .30)),
dist_name = c("b[0] %~% Normal(-0.75,0.50)",
"b[match] %~% Student_t(3, -0.20, 0.15)",
"b[crit] %~% Normal(-.20,1.0)",
"b[interaction] %~% Student_t(3, .20, .30)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_wrap(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Metric Knowledge")
dist_df <- tibble(
dist = c(dist_normal(0,.50), dist_normal(0.05,.50)),
dist_name = c("b[0]/b[crit]/b[interaction] %~% Normal(0,.50)",
"b[match] %~% Normal(0.05,.50)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Mapping Knowledge")
---
title: "Prior Distributions"
subtitle: "used in the analysis reported in the article #Knowledge: Improving food-related knowledge via seeding implemented as a social media intervention"
date: "`r Sys.Date()`"
format:
html:
code-fold: true
code-copy: true
code-tools: true
embed-resources: true
df-print: kable
toc: true
toc-location: right
fig-format: svg
page-layout: full
fig-height: 4
fig-width: 9
fig-align: center
pdf:
toc: true
toc-depth: 2
fig-height: 4
fig-width: 9
fig-align: center
df-print: kable
execute:
echo: false
execute:
warning: false
messages: false
editor_options:
chunk_output_type: console
---
```{r setup}
#| code-summary: "Load packages"
# Packages
library(tidyverse)
library(ggdist)
library(extrafont)
library(distributional)
```
```{r ggplot}
#| code-summary: "Define ggplot theme"
# Plot colors
clrs <- c("#54AA8F","#00335B",
"#22A884FF","#414487FF",
"#496aa2","#e46c0a","#90b6d4")
# ggplot theme
theme_nice <- function(){
theme_minimal(base_family = "Jost") +
theme(plot.title = element_text(hjust = 0.5,size = 20),
panel.grid.minor = element_blank(),
text = element_text(size = 20),
panel.border = element_rect(colour = "black", linewidth = 0.5, fill = NA),
axis.title.x = element_text(margin = unit(c(3, 0, 0, 0), "mm")),
axis.title.y = element_text(margin = unit(c(3, 3, 0, 0), "mm"), angle = 90),
legend.title = element_text(face = "bold",size=16),
strip.text = element_text(face = "bold"),
legend.position = "bottom"
)}
```
# General
```{r}
dist_1 <- tibble(
dist = dist_inverse_gamma(5,1),
dist_name = "~sigma[r/epsilon] %~% InvGamma(5,1)")
dist_2 <- tibble(
dist = "lkjcorr_marginal",
dist_name = "rho[r] %~% lkj(2)")
ggplot() +
stat_halfeye(data = dist_1,aes(xdist = dist)) +
stat_halfeye(data = dist_2,aes(xdist = dist, arg1 = 3, arg2 = 2)) +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "")
```
# Hypothesis 1
```{r}
dist_df <- tibble(
dist = c(dist_normal(-.75,.50), dist_student_t(3, -.20, .15)),
dist_name = c("b[0] %~% Normal(-0.75,0.50)",
"b[1] %~% Student_t(3, -0.20, 0.15)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Metric Knowledge")
```
```{r}
dist_df <- tibble(
dist = c(dist_normal(0,.50), dist_normal(0.05,.50)),
dist_name = c("b[0] %~% Normal(0, 0.50)",
"b[1] %~% Normal(0.05, 0.50)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Mapping Knowledge")
```
# Hypothesis 2
```{r}
dist_df <- tibble(
dist = c(dist_normal(-1,.50), dist_student_t(3, .10, .20)),
dist_name = c("b[0] %~% Normal(-1.00,0.50)",
"b[1] %~% Student_t(3, 0.10, 0.20)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Metric Knowledge")
```
```{r}
dist_df <- tibble(
dist = c(dist_normal(0,.50), dist_normal(0.05,.50)),
dist_name = c("b[0] %~% Normal(0, 0.50)",
"b[1] %~% Normal(-0.05, 0.50)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Mapping Knowledge")
```
# Hypothesis 3
```{r}
#| fig-height: 8
#| fig-width: 9
dist_df <- tibble(
dist = c(dist_normal(-.75,.50), dist_student_t(3, -.20, .15),
dist_normal(-.20,1.0), dist_student_t(3, .20, .30)),
dist_name = c("b[0] %~% Normal(-0.75,0.50)",
"b[match] %~% Student_t(3, -0.20, 0.15)",
"b[crit] %~% Normal(-.20,1.0)",
"b[interaction] %~% Student_t(3, .20, .30)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_wrap(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Metric Knowledge")
```
```{r}
dist_df <- tibble(
dist = c(dist_normal(0,.50), dist_normal(0.05,.50)),
dist_name = c("b[0]/b[crit]/b[interaction] %~% Normal(0,.50)",
"b[match] %~% Normal(0.05,.50)")
)
ggplot(dist_df,aes(xdist = dist)) +
stat_halfeye() +
facet_grid(.~dist_name, scales="free", labeller = label_parsed) +
theme_nice() +
labs(y = "", title = "Mapping Knowledge")
```