Multicountry Replication Study

Code to load data and libraries
# Load libraries
library(dplyr); library(purrr); library(stringr)
library(ggplot2); library(ggpubr); library(jcolors)
library(cowplot); library(ggprism); library(tidybayes)
library(reshape2); library(parallel); library(rstan)
library(brms); library(bayestestR);
library(plotly);

library(flextable) 
library(knitr);
library(kableExtra);
library(tidyverse)


color_21countries <- c(
  "#440154FF", "#481467FF", "#482576FF", "#463480FF", 
  "#414487FF", "#3B528BFF", "#35608DFF", "#2F6C8EFF",
  "#2A788EFF", "#25848EFF", "#21908CFF", "#1E9C89FF",
  "#22A884FF", "#2FB47CFF", "#43BF71FF", "#5DC863FF",
  "#7AD151FF", "#9AD93CFF", "#BBDF27FF", "#DEE318FF",
  "#FDE725FF"
)

# Load Preregistered data 
MrAB <- read.csv("../Data/Preregistered/MrAB.csv")
Game <- read.csv("../Data/Preregistered/Game.csv")
Drink <- read.csv("../Data/Preregistered/Drink.csv")
Jacket <- read.csv("../Data/Preregistered/Jacket.csv")
Play <- read.csv("../Data/Preregistered/Play.csv")
Gym <- read.csv("../Data/Preregistered/Gym.csv")
Plane <- read.csv("../Data/Preregistered/Plane.csv")

# Load data
data_MrAB <- read.csv(file = "../Data/data_MrAB.csv")
data_Game <- read.csv(file = "../Data/data_Game.csv")
data_Drink <- read.csv(file = "../Data/data_Drink.csv")
data_Jacket <- read.csv(file = "../Data/data_Jacket.csv")
data_Play <- read.csv(file = "../Data/data_Play.csv")
data_Gym <- read.csv(file = "../Data/data_Gym.csv")
data_Plane <- read.csv(file = "../Data/data_Plane.csv")

original_theta <- readRDS('../Data/original_theta.rds')
data_paper <- map_dfr(1:length(original_theta), function(i) original_theta[[i]])


countries2remove <- data_MrAB %>% 
  filter(attention_check_grater_than_3) %>% 
  group_by(subject) %>% 
  filter(row_number()==1) %>% 
  group_by(Country) %>% 
  summarise(sample_size=n()) %>% 
  filter(sample_size<250) %>% 
  .[,"Country", drop=TRUE]

countries2remove_attention_check_grater_than_2 <- data_MrAB %>% 
  filter(attention_check_grater_than_2) %>% 
  group_by(subject) %>% 
  filter(row_number()==1) %>% 
  group_by(Country) %>% 
  summarise(sample_size=n()) %>% 
  filter(sample_size<250) %>% 
  .[,"Country", drop=TRUE]

Exclusion Criterion

In this report we define five exclusion criterion. First, exclude participants with a completion time lower than a third of the median value of the Length of Interview [\(LOI_{subject} < {Mdn(LOI) \over 3}\)]. Second, exclude participants whose Country group is different than their Residence OR Native Language [\((Residence | Native~Language) != Country\)]. Third, exclude participants who will report a value below 4 (i.e. 1-3) on the “attentional check” question (i.e. “How serious have you been about filling in the survey?”) [\(attentional~ check < 4\)]. Fourth, exclude participants who will report a value below 3 (i.e. 1-2) on the “attentional check” question [\(attentional~ check < 3\)]. Fifth, exclude countries with a sample size lower than 250 participants [\(Sample < 250\)]. In this report we will run the entire analysis protocol for five exclusion criterion.


Full Exploratory Preregistered Partial None
\(LOI_{subject} < {Mdn(LOI) \over 3}\)
\((Residence | Language) != Country\)
\(attentional ~ check < 4\)
\(attentional ~ check < 3\)
\(Sample < 250\)



Demographics

Click on the tabs to open the tables.

Create table
# Participants from 21 countries
df <- data_Plane %>% 
  filter(coupon=='free') %>% 
  # EXCLUSION: Preregistered
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 )


df_egypt <- df %>% filter(coupon=="free") %>% filter(Country=='Egypt')
convert_farsi_to_arabic <- function(x) {
  if(x=="٠"|x=="۰"){
    return( "0" )
  } else if (x=="۱" | x=="١"){
    return( "1" )
  } else if (x=="۲" | x=="٢"){
    return( "2" )
  } else if (x=="۳"|x=="٣"){
    return( "3" )
  } else if (x=="۴" | x=="٤"){
    return( "4" )
  } else if (x=="۵" | x=="٥"){
    return( "5" )
  } else if (x=="۶"|x=="٦"){
    return( "6" )
  } else if (x=="۷" | x=="٧"){
    return( "7" )
  } else if (x=="۸" | x=="٨"){
    return( "8" )
  } else if (x=="۹" | x=="٩"){
    return( "9" )
  } else if( any(x %in% as.character(0:9) ) ){
    return( x )
  } else {
    warning( paste("Persian number", x, "not found!!!") )
  }
}

convert <- function(x){
  apply(
    str_split(string = x, pattern = "", simplify = T),
    2,
    convert_farsi_to_arabic
  ) %>% paste0(collapse = "")
}

df[df$Country=='Egypt', "Age"] <-  sapply(as.list(df_egypt$Age), convert)


data_table <- rbind(
  df %>% 
    mutate(Age=as.numeric(Age)) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country="Pooled",
      Language="",
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(median(Age), " (", quantile(Age,probs = .25), "-", quantile(Age,probs = .75), ")")
    ),
  df %>% 
    group_by(Country) %>% 
    mutate(Age=round(as.numeric(Age)),0) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country=names(which.max(table(Country))),
      Language=names(which.max(table(NativeLanguage))),
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(round(median(Age)), " (", round(quantile(Age,probs = .25)), "-", round(quantile(Age,probs = .75)), ")")
    ) 
) %>% 
  mutate(
    Language=ifelse(Country=="Canada", "English, French", Language),
    Language=ifelse(Country=="India", "Hindi, Tamil, English", Language)
    )


data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
        table.attr = "style='width:40%;'", booktabs = T) %>%
  kable_classic(html_font = "Cambria") %>%
  # kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE) %>%
  save_kable("tables/png/Demographics.png", zoom = 3)

data_table %>%
  flextable() %>% 
  set_caption(caption = "Table 1: Demographics") %>% 
  theme_apa() %>% 
  width(width=c(1,1,0.5,0.8,1.2)) %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/docx/Demographics.docx")

data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
      table.attr = "style='width:60%;'") %>%
  kable_classic(html_font = "Cambria") %>%
  kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE)
Table 1 | Demographics
Country Language n % female Age, median (IQR) (yr)
Pooled 5589 57.13 30 (24-40)
Austria German 277 64.62 27 (23-34)
Brazil Brazilian Portuguese 252 61.51 40 (32-52)
Canada English, French 265 56.60 36 (29-45)
China Chinese 262 65.65 25 (23-29)
Denmark Danish 259 52.12 35 (27-52)
Egypt Arabic 256 49.61 26 (21-44)
France French 271 68.27 32 (26-42)
Germany German 262 72.52 24 (21-28)
India Hindi, Tamil, English 255 44.71 25 (22-34)
Indonesia Indonesian 262 48.09 26 (21-31)
Italy Italian 289 56.75 29 (25-46)
Lithuania Lithuanian 263 68.06 30 (22-37)
Morocco Arabic 260 47.31 30 (24-38)
Netherlands Dutch 253 73.52 21 (18-27)
Portugal European Portuguese 270 56.67 27 (24-33)
Romania Romanian 265 49.43 35 (30-44)
Spain Spanish 289 34.60 31 (25-40)
Sweden Swedish 304 50.33 31 (26-40)
Switzerland German 274 43.07 36 (29-48)
USA English 250 67.60 33 (27-45)
Vietnam Vietnamese 251 73.31 28 (23-35)
Create table
# Participants from 21 countries
df <- data_Plane %>% 
  filter(coupon=='free') %>% 
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) 

df_egypt <- df %>% filter(coupon=="free") %>% filter(Country=='Egypt')

df[df$Country=='Egypt', "Age"] <-  sapply(as.list(df_egypt$Age), convert)


data_table <- rbind(
  df %>% 
    mutate(Age=as.numeric(Age)) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country="Pooled",
      Language="",
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(median(Age), " (", quantile(Age,probs = .25), "-", quantile(Age,probs = .75), ")")
    ),
  df %>% 
    group_by(Country) %>% 
    mutate(Age=round(as.numeric(Age)),0) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country=names(which.max(table(Country))),
      Language=names(which.max(table(NativeLanguage))),
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(round(median(Age)), " (", round(quantile(Age,probs = .25)), "-", round(quantile(Age,probs = .75)), ")")
    ) 
) %>% 
  mutate(
    Language=ifelse(Country=="Canada", "English, French", Language),
    Language=ifelse(Country=="India", "Hindi, Tamil, English", Language)
    )


data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
        table.attr = "style='width:40%;'", booktabs = T) %>%
  kable_classic(html_font = "Cambria") %>%
  # kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE) %>%
  save_kable("tables/png/Demographics Exploratoy.png", zoom = 3)

data_table %>%
  flextable() %>% 
  set_caption(caption = "Table 1: Demographics") %>% 
  theme_apa() %>% 
  width(width=c(1,1,0.5,0.8,1.2)) %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/docx/Demographics Exploratory.docx")

data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
      table.attr = "style='width:60%;'") %>%
  kable_classic(html_font = "Cambria") %>%
  kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE)
Table 1 | Demographics
Country Language n % female Age, median (IQR) (yr)
Pooled 5505 57.17 30 (24-40)
Austria German 266 65.04 27 (23-34)
Brazil Brazilian Portuguese 251 61.75 40 (32-52)
Canada English, French 259 57.14 36 (29-45)
China Chinese 258 65.89 25 (23-29)
Denmark Danish 259 52.12 35 (27-52)
Egypt Arabic 246 50.41 26 (21-44)
France French 271 68.27 32 (26-42)
Germany German 260 72.69 24 (21-28)
India Hindi, Tamil, English 251 44.62 25 (22-34)
Indonesia Indonesian 258 48.45 25 (21-31)
Italy Italian 289 56.75 29 (25-46)
Lithuania Lithuanian 256 67.97 30 (22-37)
Morocco Arabic 230 44.35 30 (23-38)
Netherlands Dutch 252 73.41 21 (18-27)
Portugal European Portuguese 270 56.67 27 (24-33)
Romania Romanian 265 49.43 35 (30-44)
Spain Spanish 288 34.38 31 (25-40)
Sweden Swedish 304 50.33 31 (26-40)
Switzerland German 274 43.07 36 (29-48)
USA English 248 67.74 33 (27-45)
Vietnam Vietnamese 250 73.60 28 (23-35)
Create table
# Participants from 21 countries
df <- data_Plane %>% 
  filter(coupon=='free') %>% 
  # EXCLUSION: Exploratory Partial
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_2 ) 

df_egypt <- df %>% filter(coupon=="free") %>% filter(Country=='Egypt')

df[df$Country=='Egypt', "Age"] <-  sapply(as.list(df_egypt$Age), convert)


data_table <- rbind(
  df %>% 
    mutate(Age=as.numeric(Age)) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country="Pooled",
      Language="",
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(median(Age), " (", quantile(Age,probs = .25), "-", quantile(Age,probs = .75), ")")
    ),
  df %>% 
    group_by(Country) %>% 
    mutate(Age=round(as.numeric(Age)),0) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country=names(which.max(table(Country))),
      Language=names(which.max(table(NativeLanguage))),
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(round(median(Age)), " (", round(quantile(Age,probs = .25)), "-", round(quantile(Age,probs = .75)), ")")
    ) 
) %>% 
  mutate(
    Language=ifelse(Country=="Canada", "English, French", Language),
    Language=ifelse(Country=="India", "Hindi, Tamil, English", Language)
    )


data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
        table.attr = "style='width:40%;'", booktabs = T) %>%
  kable_classic(html_font = "Cambria") %>%
  # kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE) %>%
  save_kable("tables/png/Demographics Partial.png", zoom = 3)

data_table %>%
  flextable() %>% 
  set_caption(caption = "Table 1: Demographics") %>% 
  theme_apa() %>% 
  width(width=c(1,1,0.5,0.8,1.2)) %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/docx/Demographics (Partial).docx")

data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
      table.attr = "style='width:60%;'") %>%
  kable_classic(html_font = "Cambria") %>%
  kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE)
Table 1 | Demographics
Country Language n % female Age, median (IQR) (yr)
Pooled 6730 57.12 29 (23-40)
Austria German 331 64.05 27 (23-34)
Brazil Brazilian Portuguese 284 60.56 41 (32-52)
Canada English, French 286 57.69 37 (29-46)
China Chinese 332 66.27 25 (23-29)
Denmark Danish 295 51.86 34 (26-52)
Egypt Arabic 326 51.84 25 (21-42)
France French 287 68.29 32 (25-42)
Germany German 296 71.28 24 (21-29)
India Hindi, Tamil, English 335 44.48 25 (22-32)
Indonesia Indonesian 402 54.73 25 (21-29)
Italy Italian 418 55.74 30 (25-51)
Lithuania Lithuanian 333 68.77 30 (22-37)
Morocco Arabic 287 45.64 30 (24-38)
Netherlands Dutch 293 72.70 21 (18-27)
Portugal European Portuguese 328 53.66 27 (24-32)
Romania Romanian 296 50.68 35 (30-43)
Spain Spanish 354 36.72 30 (25-40)
Sweden Swedish 346 50.29 31 (26-40)
Switzerland German 311 42.44 36 (28-48)
USA English 292 66.10 32 (25-43)
Vietnam Vietnamese 298 72.48 27 (22-34)
Create table
# Participants from 21 countries
df <- data_Plane %>% 
  filter(coupon=='free') %>% 
  # EXCLUSION: None
  filter( T ) 

df_egypt <- df %>% filter(coupon=="free") %>% filter(Country=='Egypt')

df[df$Country=='Egypt', "Age"] <-  sapply(as.list(df_egypt$Age), convert)


data_table <- rbind(
  df %>% 
    mutate(Age=as.numeric(Age)) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country="Pooled",
      Language="",
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(median(Age), " (", quantile(Age,probs = .25), "-", quantile(Age,probs = .75), ")")
    ),
  df %>% 
    group_by(Country) %>% 
    mutate(Age=round(as.numeric(Age)),0) %>% 
    filter(Age>0 & Age<99) %>% 
    summarise(
      Country=names(which.max(table(Country))),
      Language=names(which.max(table(NativeLanguage))),
      n = n(),
      `% female` = round(mean(Gender=='Female')*100,2),
      `Age, median (IQR) (yr)` = str_c(round(median(Age)), " (", round(quantile(Age,probs = .25)), "-", round(quantile(Age,probs = .75)), ")")
    ) 
) %>% 
  mutate(
    Language=ifelse(Country=="Canada", "English, French", Language),
    Language=ifelse(Country=="India", "Hindi, Tamil, English", Language)
    )


data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
        table.attr = "style='width:40%;'", booktabs = T) %>%
  kable_classic(html_font = "Cambria") %>%
  # kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE) %>%
  save_kable("tables/png/Demographics None.png", zoom = 3)

data_table %>%
  flextable() %>% 
  set_caption(caption = "Table 1: Demographics") %>% 
  theme_apa() %>% 
  width(width=c(1,1,0.5,0.8,1.2)) %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/docx/Demographics (None).docx")

data_table %>%
  kable(caption="<b>Table 1 | </b> Demographics", align=rep('l', 5),
      table.attr = "style='width:60%;'") %>%
  kable_classic(html_font = "Cambria") %>%
  kable_material(c("striped", "hover")) %>%
  row_spec(0, bold = TRUE)
Table 1 | Demographics
Country Language n % female Age, median (IQR) (yr)
Pooled 8519 57.32 30 (24-40)
Austria German 339 63.42 27 (23-34)
Brazil Brazilian Portuguese 285 60.70 41 (32-52)
Canada English, French 292 57.88 37 (29-46)
China Chinese 347 65.71 25 (23-29)
Colombia Spanish 63 71.43 32 (26-41)
Denmark Danish 299 51.84 35 (26-53)
Egypt Arabic 347 52.74 25 (21-42)
France French 289 68.51 32 (25-42)
Germany German 301 71.76 24 (21-29)
Ghana English 140 52.14 36 (26-45)
Hungary Hungarian 59 79.66 32 (30-46)
India Hindi, Tamil, English 356 44.38 24 (22-31)
Indonesia Indonesian 414 55.07 25 (21-29)
Iran Persian 132 43.18 28 (23-37)
Israel Hebrew 145 60.00 33 (28-42)
Italy Italian 437 56.29 30 (25-51)
Lithuania Lithuanian 338 68.64 30 (22-38)
Morocco Arabic 293 45.05 30 (24-38)
Netherlands Dutch 302 72.85 21 (18-27)
Portugal European Portuguese 333 53.75 27 (24-32)
Romania Romanian 297 50.84 35 (30-43)
Russia Russian 186 83.33 32 (26-40)
Singapore English 221 56.11 25 (23-30)
South Africa English 203 55.67 39 (28-48)
South Korea Korean 115 73.04 32 (28-44)
Spain Spanish 360 36.39 31 (25-40)
Sweden Swedish 346 50.29 31 (26-40)
Switzerland German 314 42.36 36 (28-48)
Turkey Turkish 174 45.98 28 (24-39)
UK English 184 40.22 32 (26-40)
USA English 298 66.11 31 (24-42)
Vietnam Vietnamese 310 72.90 27 (22-34)



Effect Size


In this section we show the effect size of each study for each country. We use log Odd Ratios (OR) to quantify the effect size of binary variables, while we use Standardized Mean Differences (SMD) as a measure of effect size of continuous variables. Each dot correspond to a country. The dots size indicate the inverse of the standard error (e.g. 1/SE). The red horizontal lines indicate the effect size calculated using the results reported in the original papers. For the Drink and Gym study, we could not calculate the effect size of the original papers as information about pooled standard deviation are not reported. To facilitate the interpretation of the results, the variables are coded in such a way that the effect reported in the original papers are positive in all studies.


Create preregistered exclusion dataset
# data_MrAB_theta <- data_MrAB %>% filter(response!=2) %>% 
#   # EXCLUSION: Full Exclusion
#   filter( !(Country %in% countries2remove) ) %>% 
#   filter( attention_check_grater_than_3 ) %>% 
#   # Calculate mean Finantial Literacy
#   group_by(Country) %>% 
#   mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
#   # Calculate ODD RATIO
#   group_by(scenario, scenario_group, response, Country) %>% 
#   mutate(n = n()) %>% filter(row_number()==1) %>% 
#   group_by(scenario, Country) %>% 
#   mutate(Odds = n[response==1]/n[response==0]) %>% 
#   group_by(scenario_group, Country) %>% 
#   # filter(Country=="Austria", scenario_group=="gain") %>% 
#   mutate(se_theta = sqrt(sum(1/n))) %>%
#   group_by(scenario, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
#   group_by(Country) %>% 
#   mutate(ORgain = Odds[scenario=="gain-gain VS gain"]/Odds[scenario=="gain-loss VS gain"],
#          ORloss = Odds[scenario=="loss-loss VS loss"]/Odds[scenario=="loss-gain VS loss"],
#          theta = ifelse(scenario_group=="gain", log(ORgain), log(ORloss))) %>% 
#   group_by(Country, scenario_group) %>% filter(row_number()==1) %>% 
#   select(-c(ORgain, ORloss, Odds, n)) %>% ungroup()

data_MrAB_theta <- data_MrAB %>% 
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Financial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  group_by(subject, scenario_group) %>% 
  mutate(
    resp = case_when(
      (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0) ~ 1, 
      (response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0) ~ 1,
      T ~ 0
    )
  ) %>% 
  group_by(Country, scenario_group) %>% 
  mutate(
    p = mean(resp),
    n = n(),
    p_h0 = 1/9,
    se_theta = sqrt( 1 / (n * p * (1-p)) ), # SE logit
    logit_data =log( p/(1-p) ),
    logit_h0 = log( p_h0/(1-p_h0) ),
    theta = logit_data-logit_h0 # evidence ratio
  ) %>% 
  filter(row_number()==1) %>% 
  ungroup()
    


data_Game_theta <- data_Game %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Finantial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  # Calculate ODD RATIO
  group_by(buyer, response, Country) %>%
  mutate(n = n()) %>% filter(row_number()==1) %>%
  group_by(buyer, Country) %>%
  mutate(Odds = n[response==1]/n[response==0]) %>%
  group_by(buyer, Country) %>%
  # filter(Country=="Austria", scenario_group=="gain") %>%
  mutate(se_theta = sqrt(sum(1/n))) %>%
  filter(row_number()==1) %>% select(-response) %>%
  group_by(Country) %>% 
  mutate(OR = Odds[buyer=="Stranger"]/Odds[buyer=="Friend"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup() 

data_Drink_theta <- data_Drink %>% 
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Finantial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  # Remove really really extreme outliers
  filter(response<10000 & response>=0) %>% 
  mutate(response=response+1, logResp=log(response)) %>% 
  # Compute effect size as Standardized Mean Difference
  group_by(Country, store) %>% mutate(n=n()) %>% 
  group_by(Country) %>% 
  # Calculate Mean Difference 
  mutate(md=mean(logResp[store=="Resort Hotel"])-mean(logResp[store=="Grocery Store"])) %>% 
  # Calculate effect size
  mutate(theta=md/sd(logResp)) %>% 
  group_by(Country, store) %>% filter(row_number()==1) %>% 
  group_by(Country) %>% 
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[store=="Resort Hotel"]*n[store=="Grocery Store"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  select(-c(md, response, first, second, logResp, n)) %>% 
  filter(row_number()==1) %>% ungroup()

data_Jacket_theta <- data_Jacket %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Finantial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  # Calculate ODD RATIO
  group_by(price, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(price, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(price, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(price, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[price=="low"]/Odds[price=="high"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Play_theta <- data_Play %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Finantial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  # Calculate ODD RATIO
  group_by(loss, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(loss, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(loss, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(loss, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[loss=="cash"]/Odds[loss=="ticket"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Gym_theta <- data_Gym %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Finantial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  # Calculate Mean Difference
  group_by(frame, Country) %>% mutate(n = n()) %>%
  group_by(Country) %>% 
  mutate(pooled_sd = sd(response),
         md = mean(response[frame=="Yearly"])-mean(response[frame=="Per-session"]),
         theta = md/pooled_sd) %>% 
  group_by(frame, Country) %>% filter(row_number()==1) %>% 
  group_by(Country) %>%
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[frame=="Per-session"]*n[frame=="Yearly"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  filter(row_number()==1) %>% ungroup() %>% 
  select(-c(md, first, second, pooled_sd, n, response))

data_Plane_theta <- data_Plane %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Finantial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  # Calculate ODD RATIO
  group_by(coupon, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(coupon, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(coupon, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(coupon, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[coupon=="purchased"]/Odds[coupon=="free"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

theta_preregisteredExclusion <- list(
  MrAB = data_MrAB_theta %>% 
    mutate(study="MrAB", x=ifelse(scenario_group=="gain", 1, 2),
           family="binomial1") %>% 
    select(-c(X, scenario)) %>% rename(condition = scenario_group),
  Game = data_Game_theta %>% mutate(study="Game", x=1, family="binomial") %>% 
    select(-c(X, market_value)) %>% rename(condition = buyer),
  Drink = data_Drink_theta %>% mutate(study="Drink", x=1, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = store),
  Jacket = data_Jacket_theta %>% mutate(study="Jacket", x=2, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = price),
  Play = data_Play_theta %>% mutate(study="Play", x=3, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = loss),
  Gym = data_Gym_theta %>% mutate(study="Gym", x=2, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = frame),
  Plane = data_Plane_theta %>% mutate(study="Plane", x=4, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = coupon)
)
Plot full exclusion dataset
#re-run
data_theta <- map_dfr(1:length(theta_preregisteredExclusion), function(i) theta_preregisteredExclusion[[i]])
nCountries <- length(unique(theta_preregisteredExclusion[[1]]$Country))

plot_OR <- data_theta %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_point(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), color="firebrick", size=35, shape="-") +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(log(OR))) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,5.5), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = unique(data_theta$study[data_theta$family=="binomial"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_ER <- data_theta %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(ER)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_d <- data_theta %>% filter(family=="gaussian") %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  ggplot(aes(x, theta, color=Country)) +
  geom_jitter( aes(size=1/se_theta), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(SMD)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", breaks = -1:1, limits = c(-1, 1.5)) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = unique(data_theta$study[data_theta$family=="gaussian"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

cowplot::plot_grid(plot_OR, plot_ER, plot_d, nrow = 1, rel_widths = c(0.5, 0.25, .25))

Create full dataset
data_MrAB_theta <- data_MrAB %>% 
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Financial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  group_by(subject, scenario_group) %>% 
  mutate(
    resp = case_when(
      (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0) ~ 1, 
      (response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0) ~ 1,
      T ~ 0
    )
  ) %>% 
  group_by(Country, scenario_group) %>% 
  mutate(
    p = mean(resp),
    n = n(),
    p_h0 = 1/9,
    se_theta = sqrt( 1 / (n * p * (1-p)) ), # SE logit
    logit_data =log( p/(1-p) ),
    logit_h0 = log( p_h0/(1-p_h0) ),
    theta = logit_data-logit_h0 # evidence ratio
  ) %>% 
  filter(row_number()==1) %>% 
  ungroup()

data_Game_theta <- data_Game %>%
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(buyer, response, Country) %>%
  mutate(n = n()) %>% filter(row_number()==1) %>%
  group_by(buyer, Country) %>%
  mutate(Odds = n[response==1]/n[response==0]) %>%
  group_by(buyer, Country) %>%
  # filter(Country=="Austria", scenario_group=="gain") %>%
  mutate(se_theta = sqrt(sum(1/n))) %>%
  filter(row_number()==1) %>% select(-response) %>%
  group_by(Country) %>% 
  mutate(OR = Odds[buyer=="Stranger"]/Odds[buyer=="Friend"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup() 

data_Drink_theta <- data_Drink %>% 
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Remove really really extreme outliers
  filter(response<10000 & response>=0) %>% 
  mutate(response=response+1, logResp=log(response)) %>% 
  # Compute effect size as Standardized Mean Difference
  group_by(Country, store) %>% mutate(n=n()) %>% 
  group_by(Country) %>% 
  # Calculate Mean Difference 
  mutate(md=mean(logResp[store=="Resort Hotel"])-mean(logResp[store=="Grocery Store"])) %>% 
  # Calculate effect size
  mutate(theta=md/sd(logResp)) %>% 
  group_by(Country, store) %>% filter(row_number()==1) %>% 
  group_by(Country) %>% 
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[store=="Resort Hotel"]*n[store=="Grocery Store"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  select(-c(md, response, first, second, logResp, n)) %>% 
  filter(row_number()==1) %>% ungroup()

data_Jacket_theta <- data_Jacket %>%
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(price, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(price, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(price, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(price, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[price=="low"]/Odds[price=="high"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Play_theta <- data_Play %>%
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(loss, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(loss, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(loss, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(loss, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[loss=="cash"]/Odds[loss=="ticket"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Gym_theta <- data_Gym %>%
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate Mean Difference
  group_by(frame, Country) %>% mutate(n = n()) %>%
  group_by(Country) %>% 
  mutate(pooled_sd = sd(response),
         md = mean(response[frame=="Yearly"])-mean(response[frame=="Per-session"]),
         theta = md/pooled_sd) %>% 
  group_by(frame, Country) %>% filter(row_number()==1) %>% 
  group_by(Country) %>%
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[frame=="Per-session"]*n[frame=="Yearly"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  filter(row_number()==1) %>% ungroup() %>% 
  select(-c(md, first, second, pooled_sd, n, response))

data_Plane_theta <- data_Plane %>%
  # EXCLUSION: Full Exclusion
  filter(native_language_is_country_language | Country!=Residence) %>% 
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(coupon, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(coupon, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(coupon, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(coupon, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[coupon=="purchased"]/Odds[coupon=="free"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

theta_fullExclusion <- list(
  MrAB = data_MrAB_theta %>% 
    mutate(study="MrAB", x=ifelse(scenario_group=="gain", 1, 2),
           family="binomial1") %>% 
    select(-c(X, scenario)) %>% rename(condition = scenario_group),
  Game = data_Game_theta %>% mutate(study="Game", x=1, family="binomial") %>% 
    select(-c(X, market_value)) %>% rename(condition = buyer),
  Drink = data_Drink_theta %>% mutate(study="Drink", x=1, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = store),
  Jacket = data_Jacket_theta %>% mutate(study="Jacket", x=2, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = price),
  Play = data_Play_theta %>% mutate(study="Play", x=3, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = loss),
  Gym = data_Gym_theta %>% mutate(study="Gym", x=2, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = frame),
  Plane = data_Plane_theta %>% mutate(study="Plane", x=4, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = coupon)
)
Plot full exclusion dataset
data_theta <- map_dfr(1:length(theta_fullExclusion), function(i) theta_fullExclusion[[i]])
nCountries <- length(unique(theta_fullExclusion[[1]]$Country))

#re-run
plot_OR <- data_theta %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_point(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), color="firebrick", size=35, shape="-") +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(log(OR))) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,5.5), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = unique(data_theta$study[data_theta$family=="binomial"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_ER <- data_theta %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(ER)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_d <- data_theta %>% filter(family=="gaussian") %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  ggplot(aes(x, theta, color=Country)) +
  geom_jitter( aes(size=1/se_theta), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(SMD)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", breaks = -1:1, limits = c(-1, 1.5)) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = unique(data_theta$study[data_theta$family=="gaussian"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

cowplot::plot_grid(plot_OR, plot_ER, plot_d, nrow = 1, rel_widths = c(0.5, 0.25, .25))

Create exploratory dataset
data_MrAB_theta <- data_MrAB %>% 
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate mean Financial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  group_by(subject, scenario_group) %>% 
  mutate(
    resp = case_when(
      (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0) ~ 1, 
      (response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0) ~ 1,
      T ~ 0
    )
  ) %>% 
  group_by(Country, scenario_group) %>% 
  mutate(
    p = mean(resp),
    n = n(),
    p_h0 = 1/9,
    se_theta = sqrt( 1 / (n * p * (1-p)) ), # SE logit
    logit_data =log( p/(1-p) ),
    logit_h0 = log( p_h0/(1-p_h0) ),
    theta = logit_data-logit_h0 # evidence ratio
  ) %>% 
  filter(row_number()==1) %>% 
  ungroup()

data_Game_theta <- data_Game %>%
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(buyer, response, Country) %>%
  mutate(n = n()) %>% filter(row_number()==1) %>%
  group_by(buyer, Country) %>%
  mutate(Odds = n[response==1]/n[response==0]) %>%
  group_by(buyer, Country) %>%
  # filter(Country=="Austria", scenario_group=="gain") %>%
  mutate(se_theta = sqrt(sum(1/n))) %>%
  filter(row_number()==1) %>% select(-response) %>%
  group_by(Country) %>% 
  mutate(OR = Odds[buyer=="Stranger"]/Odds[buyer=="Friend"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup() 

data_Drink_theta <- data_Drink %>% 
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Remove really really extreme outliers
  filter(response<10000 & response>=0) %>% 
  mutate(response=response+1, logResp=log(response)) %>% 
  # Compute effect size as Standardized Mean Difference
  group_by(Country, store) %>% mutate(n=n()) %>% 
  group_by(Country) %>% 
  # Calculate Mean Difference 
  mutate(md=mean(logResp[store=="Resort Hotel"])-mean(logResp[store=="Grocery Store"])) %>% 
  # Calculate effect size
  mutate(theta=md/sd(logResp)) %>% 
  group_by(Country, store) %>% filter(row_number()==1) %>% 
  group_by(Country) %>% 
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[store=="Resort Hotel"]*n[store=="Grocery Store"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  select(-c(md, response, first, second, logResp, n)) %>% 
  filter(row_number()==1) %>% ungroup()

data_Jacket_theta <- data_Jacket %>%
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(price, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(price, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(price, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(price, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[price=="low"]/Odds[price=="high"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Play_theta <- data_Play %>%
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(loss, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(loss, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(loss, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(loss, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[loss=="cash"]/Odds[loss=="ticket"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Gym_theta <- data_Gym %>%
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate Mean Difference
  group_by(frame, Country) %>% mutate(n = n()) %>%
  group_by(Country) %>% 
  mutate(pooled_sd = sd(response),
         md = mean(response[frame=="Yearly"])-mean(response[frame=="Per-session"]),
         theta = md/pooled_sd) %>% 
  group_by(frame, Country) %>% filter(row_number()==1) %>% 
  group_by(Country) %>%
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[frame=="Per-session"]*n[frame=="Yearly"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  filter(row_number()==1) %>% ungroup() %>% 
  select(-c(md, first, second, pooled_sd, n, response))

data_Plane_theta <- data_Plane %>%
  # EXCLUSION: Exploratory Exclusion
  filter( !loi_lower_than_loiX0_33 ) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Calculate ODD RATIO
  group_by(coupon, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(coupon, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(coupon, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(coupon, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[coupon=="purchased"]/Odds[coupon=="free"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

theta_exploratoryExclusion <- list(
  MrAB = data_MrAB_theta %>% 
    mutate(study="MrAB", x=ifelse(scenario_group=="gain", 1, 2),
           family="binomial1") %>% 
    select(-c(X, scenario)) %>% rename(condition = scenario_group),
  Game = data_Game_theta %>% mutate(study="Game", x=1, family="binomial") %>% 
    select(-c(X, market_value)) %>% rename(condition = buyer),
  Drink = data_Drink_theta %>% mutate(study="Drink", x=1, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = store),
  Jacket = data_Jacket_theta %>% mutate(study="Jacket", x=2, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = price),
  Play = data_Play_theta %>% mutate(study="Play", x=3, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = loss),
  Gym = data_Gym_theta %>% mutate(study="Gym", x=2, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = frame),
  Plane = data_Plane_theta %>% mutate(study="Plane", x=4, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = coupon)
)
Plot exploratory exclusion dataset
data_theta <- map_dfr(1:length(theta_exploratoryExclusion), function(i) theta_fullExclusion[[i]])
nCountries <- length(unique(theta_exploratoryExclusion[[1]]$Country))

#re-run
plot_OR <- data_theta %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_point(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), color="firebrick", size=35, shape="-") +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(log(OR))) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,5.5), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = unique(data_theta$study[data_theta$family=="binomial"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_ER <- data_theta %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(ER)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_d <- data_theta %>% filter(family=="gaussian") %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  ggplot(aes(x, theta, color=Country)) +
  geom_jitter( aes(size=1/se_theta), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(SMD)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", breaks = -1:1, limits = c(-1, 1.5)) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = unique(data_theta$study[data_theta$family=="gaussian"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

cowplot::plot_grid(plot_OR, plot_ER, plot_d, nrow = 1, rel_widths = c(0.5, 0.25, .25))

Create partial exclusion dataset
data_MrAB_theta <- data_MrAB %>% 
   # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Calculate mean Financial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  group_by(subject, scenario_group) %>% 
  mutate(
    resp = case_when(
      (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0) ~ 1, 
      (response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0) ~ 1,
      T ~ 0
    )
  ) %>% 
  group_by(Country, scenario_group) %>% 
  mutate(
    p = mean(resp),
    n = n(),
    p_h0 = 1/9,
    se_theta = sqrt( 1 / (n * p * (1-p)) ), # SE logit
    logit_data =log( p/(1-p) ),
    logit_h0 = log( p_h0/(1-p_h0) ),
    theta = logit_data-logit_h0 # evidence ratio
  ) %>% 
  filter(row_number()==1) %>% 
  ungroup()

data_Game_theta <- data_Game %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Calculate ODD RATIO
  group_by(buyer, response, Country) %>%
  mutate(n = n()) %>% filter(row_number()==1) %>%
  group_by(buyer, Country) %>%
  mutate(Odds = n[response==1]/n[response==0]) %>%
  group_by(buyer, Country) %>%
  # filter(Country=="Austria", scenario_group=="gain") %>%
  mutate(se_theta = sqrt(sum(1/n))) %>%
  filter(row_number()==1) %>% select(-response) %>%
  group_by(Country) %>% 
  mutate(OR = Odds[buyer=="Stranger"]/Odds[buyer=="Friend"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup() 

data_Drink_theta <- data_Drink %>% 
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Remove really really extreme outliers
  filter(response<10000 & response>=0) %>% 
  mutate(response=response+1, logResp=log(response)) %>% 
  # Compute effect size as Standardized Mean Difference
  group_by(Country, store) %>% mutate(n=n()) %>% 
  group_by(Country) %>% 
  # Calculate Mean Difference 
  mutate(md=mean(logResp[store=="Resort Hotel"])-mean(logResp[store=="Grocery Store"])) %>% 
  # Calculate effect size
  mutate(theta=md/sd(logResp)) %>% 
  group_by(Country, store) %>% filter(row_number()==1) %>% 
  group_by(Country) %>% 
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[store=="Resort Hotel"]*n[store=="Grocery Store"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  select(-c(md, response, first, second, logResp, n)) %>% 
  filter(row_number()==1) %>% ungroup()

data_Jacket_theta <- data_Jacket %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Calculate ODD RATIO
  group_by(price, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(price, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(price, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(price, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[price=="low"]/Odds[price=="high"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Play_theta <- data_Play %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Calculate ODD RATIO
  group_by(loss, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(loss, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(loss, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(loss, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[loss=="cash"]/Odds[loss=="ticket"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Gym_theta <- data_Gym %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Calculate Mean Difference
  group_by(frame, Country) %>% mutate(n = n()) %>%
  group_by(Country) %>% 
  mutate(pooled_sd = sd(response),
         md = mean(response[frame=="Yearly"])-mean(response[frame=="Per-session"]),
         theta = md/pooled_sd) %>% 
  group_by(frame, Country) %>% filter(row_number()==1) %>% 
  group_by(Country) %>%
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[frame=="Per-session"]*n[frame=="Yearly"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  filter(row_number()==1) %>% ungroup() %>% 
  select(-c(md, first, second, pooled_sd, n, response))

data_Plane_theta <- data_Plane %>%
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove_attention_check_grater_than_2) ) %>% 
  filter( attention_check_grater_than_2 ) %>% 
  # Calculate ODD RATIO
  group_by(coupon, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(coupon, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(coupon, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(coupon, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[coupon=="purchased"]/Odds[coupon=="free"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

theta_partialExclusion <- list(
  MrAB = data_MrAB_theta %>% 
    mutate(study="MrAB", x=ifelse(scenario_group=="gain", 1, 2),
           family="binomial1") %>% 
    select(-c(X, scenario)) %>% rename(condition = scenario_group),
  Game = data_Game_theta %>% mutate(study="Game", x=1, family="binomial") %>% 
    select(-c(X, market_value)) %>% rename(condition = buyer),
  Drink = data_Drink_theta %>% mutate(study="Drink", x=1, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = store),
  Jacket = data_Jacket_theta %>% mutate(study="Jacket", x=2, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = price),
  Play = data_Play_theta %>% mutate(study="Play", x=3, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = loss),
  Gym = data_Gym_theta %>% mutate(study="Gym", x=2, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = frame),
  Plane = data_Plane_theta %>% mutate(study="Plane", x=4, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = coupon)
)
Plot partial exclusion dataset
data_theta <- map_dfr(1:length(theta_partialExclusion), function(i) theta_partialExclusion[[i]])
nCountries <- length(unique(theta_partialExclusion[[1]]$Country))

#re-run
plot_OR <- data_theta %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_point(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), color="firebrick", size=35, shape="-") +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(log(OR))) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,5.5), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = unique(data_theta$study[data_theta$family=="binomial"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_ER <- data_theta %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(ER)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_d <- data_theta %>% filter(family=="gaussian") %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  ggplot(aes(x, theta, color=Country)) +
  geom_jitter( aes(size=1/se_theta), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(SMD)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", breaks = -1:1, limits = c(-1, 1.5)) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = unique(data_theta$study[data_theta$family=="gaussian"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

cowplot::plot_grid(plot_OR, plot_ER, plot_d, nrow = 1, rel_widths = c(0.5, 0.25, .25))

Create no exclusion dataset
data_MrAB_theta <- data_MrAB %>% 
  filter(T) %>% 
  # Calculate mean Financial Literacy
  group_by(Country) %>% 
  mutate(FinancialLiteracy = mean(FinancialLiteracy)) %>% 
  group_by(subject, scenario_group) %>% 
  mutate(
    resp = case_when(
      (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0) ~ 1, 
      (response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0) ~ 1,
      T ~ 0
    )
  ) %>% 
  group_by(Country, scenario_group) %>% 
  mutate(
    p = mean(resp),
    n = n(),
    p_h0 = 1/9,
    se_theta = sqrt( 1 / (n * p * (1-p)) ), # SE logit
    logit_data =log( p/(1-p) ),
    logit_h0 = log( p_h0/(1-p_h0) ),
    theta = logit_data-logit_h0 # evidence ratio
  ) %>% 
  filter(row_number()==1) %>% 
  ungroup()

data_Game_theta <- data_Game %>%
  # EXCLUSION: Full Exclusion
  filter( T ) %>% 
  # Calculate ODD RATIO
  group_by(buyer, response, Country) %>%
  mutate(n = n()) %>% filter(row_number()==1) %>%
  group_by(buyer, Country) %>%
  mutate(Odds = n[response==1]/n[response==0]) %>%
  group_by(buyer, Country) %>%
  # filter(Country=="Austria", scenario_group=="gain") %>%
  mutate(se_theta = sqrt(sum(1/n))) %>%
  filter(row_number()==1) %>% select(-response) %>%
  group_by(Country) %>% 
  mutate(OR = Odds[buyer=="Stranger"]/Odds[buyer=="Friend"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup() 

data_Drink_theta <- data_Drink %>% 
  # EXCLUSION: Full Exclusion
  filter( T ) %>% 
  # Remove really really extreme outliers
  filter(response<10000 & response>=0) %>% 
  mutate(response=response+1, logResp=log(response)) %>% 
  # Compute effect size as Standardized Mean Difference
  group_by(Country, store) %>% mutate(n=n()) %>% 
  group_by(Country) %>% 
  # Calculate Mean Difference 
  mutate(md=mean(logResp[store=="Resort Hotel"])-mean(logResp[store=="Grocery Store"])) %>% 
  # Calculate effect size
  mutate(theta=md/sd(logResp)) %>% 
  group_by(Country, store) %>% filter(row_number()==1) %>% 
  group_by(Country) %>% 
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[store=="Resort Hotel"]*n[store=="Grocery Store"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  select(-c(md, response, first, second, logResp, n)) %>% 
  filter(row_number()==1) %>% ungroup()

data_Jacket_theta <- data_Jacket %>%
  # EXCLUSION: No Exclusion
  filter( T ) %>% 
  # Calculate ODD RATIO
  group_by(price, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(price, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(price, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(price, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[price=="low"]/Odds[price=="high"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Play_theta <- data_Play %>%
  # EXCLUSION: No Exclusion
  filter( T ) %>%
  # Calculate ODD RATIO
  group_by(loss, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(loss, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(loss, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(loss, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[loss=="cash"]/Odds[loss=="ticket"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

data_Gym_theta <- data_Gym %>%
  # EXCLUSION: Full Exclusion
  filter( T ) %>% 
  # Calculate Mean Difference
  group_by(frame, Country) %>% mutate(n = n()) %>%
  group_by(Country) %>% 
  mutate(pooled_sd = sd(response),
         md = mean(response[frame=="Yearly"])-mean(response[frame=="Per-session"]),
         theta = md/pooled_sd) %>% 
  group_by(frame, Country) %>% filter(row_number()==1) %>% 
  group_by(Country) %>%
  # -- Calculate standard error -- #
  mutate(first = sum(n) / (n[frame=="Per-session"]*n[frame=="Yearly"]),
         second = theta[1]^2/(2*sum(n)),
         se_theta = sqrt(first+second)) %>% 
  filter(row_number()==1) %>% ungroup() %>% 
  select(-c(md, first, second, pooled_sd, n, response))

data_Plane_theta <- data_Plane %>%
  # EXCLUSION: No Exclusion
  filter( T ) %>% 
  # Calculate ODD RATIO
  group_by(coupon, response, Country) %>% 
  mutate(n = n()) %>% filter(row_number()==1) %>% 
  group_by(coupon, Country) %>% 
  mutate(Odds = n[response==1]/n[response==0]) %>% 
  group_by(coupon, Country) %>% 
  # filter(Country=="Austria", scenario_group=="gain") %>% 
  mutate(se_theta = sqrt(sum(1/n))) %>%
  group_by(coupon, Country) %>% filter(row_number()==1) %>% select(-response) %>% 
  group_by(Country) %>% 
  mutate(OR = Odds[coupon=="purchased"]/Odds[coupon=="free"],
         theta = log(OR)) %>% filter(row_number()==1) %>% 
  select(-c(OR, Odds, n)) %>% ungroup()

theta_noExclusion <- list(
  MrAB = data_MrAB_theta %>% 
    mutate(study="MrAB", x=ifelse(scenario_group=="gain", 1, 2),
           family="binomial1") %>% 
    select(-c(X, scenario)) %>% rename(condition = scenario_group),
  Game = data_Game_theta %>% mutate(study="Game", x=1, family="binomial") %>% 
    select(-c(X, market_value)) %>% rename(condition = buyer),
  Drink = data_Drink_theta %>% mutate(study="Drink", x=1, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = store),
  Jacket = data_Jacket_theta %>% mutate(study="Jacket", x=2, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = price),
  Play = data_Play_theta %>% mutate(study="Play", x=3, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = loss),
  Gym = data_Gym_theta %>% mutate(study="Gym", x=2, family="gaussian") %>% 
    select(-c(X)) %>% rename(condition = frame),
  Plane = data_Plane_theta %>% mutate(study="Plane", x=4, family="binomial") %>% 
    select(-c(X)) %>% rename(condition = coupon)
)
Plot no exclusion dataset
data_theta <- map_dfr(1:length(theta_noExclusion), function(i) theta_noExclusion[[i]])
nCountries <- length(unique(theta_noExclusion[[1]]$Country))

#re-run
plot_OR <- data_theta %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_point(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), color="firebrick", size=35, shape="-") +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(log(OR))) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,5.5), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = unique(data_theta$study[data_theta$family=="binomial"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_ER <- data_theta %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta)) +
  geom_jitter( aes(size=1/se_theta, color=Country), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(ER)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_fill_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

plot_d <- data_theta %>% filter(family=="gaussian") %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  ggplot(aes(x, theta, color=Country)) +
  geom_jitter( aes(size=1/se_theta), width = 0.1, alpha=0.7) +
  geom_hline(yintercept = 0, linetype=2) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y=expression(SMD)) +
  scale_color_manual(values = viridis::viridis_pal()(nCountries)) +
  scale_y_continuous(guide = "prism_offset", breaks = -1:1, limits = c(-1, 1.5)) + 
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = unique(data_theta$study[data_theta$family=="gaussian"]),
                     guide = "prism_offset") + 
  guides(size = "none") + 
  theme(text = element_text(size = 15), legend.position = "none")

cowplot::plot_grid(plot_OR, plot_ER, plot_d, nrow = 1, rel_widths = c(0.5, 0.25, .25))



Bayesian Meta-Analysis


In this section we perform a Bayesian meta-analysis. The purple dots indicate the population level estimates, while the gray dots indicate the estimates of each country. Our results show that the population effect replicate the original findings for each study, regardless of the exclusion criterion used.


Click on the tabs to see the model’s summary for each study

Show codes
# MrAB (re-run)
mMrAB1 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              prior = prior_string("normal(0,2.5)", class = "Intercept"),
              data = theta_preregisteredExclusion$MrAB %>% filter(condition=="gain"),
              iter = 20000, refresh = 0)

fe <- fixef(mMrAB1)[,"Estimate"]
re <- ranef(mMrAB1)$Country[,,][,"Estimate"]
postMrAB1 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 1)

mMrAB2 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              prior = prior_string("normal(0,2.5)", class = "Intercept"),
              data = theta_preregisteredExclusion$MrAB %>% filter(condition=="loss"),
              iter = 20000, refresh = 0)

fe <- fixef(mMrAB2)[,"Estimate"]
re <- ranef(mMrAB2)$Country[,,][,"Estimate"]
postMrAB2 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 2)
Code
# re-run1
table_bayesian <- fixef(mMrAB1) %>% as.data.frame(row.names = '') %>% 
  mutate(Study="MrAB1", 
         Estimate = round(Estimate, 2),
         `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
         ) %>% 
  select(-c(Est.Error, Q2.5, Q97.5))


sjPlot::tab_model(mMrAB1)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.48 1.31 – 1.65
Random Effects
σ2 0.13
τ00 0.01
ICC 0.94
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.939
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mMrAB2) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="MrAB2", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)

sjPlot::tab_model(mMrAB2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 2.13 1.99 – 2.27
Random Effects
σ2 0.08
τ00 0.01
ICC 0.92
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.917
Show codes
# MrAB
mGame <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             prior = prior_string("normal(0,2.5)", class = "Intercept"),
             data = theta_preregisteredExclusion$Game,
             iter = 20000)

fe <- fixef(mGame)[,"Estimate"]
re <- ranef(mGame)$Country[,,][,"Estimate"]
postGame <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Game", x = 1)
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mGame) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="Game", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)

sjPlot::tab_model(mGame)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.90 1.68 – 2.12
Random Effects
σ2 0.22
τ00 0.00
ICC 0.98
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.983
Show codes
mDrink <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              prior = prior_string("normal(0,2.5)", class = "Intercept"),
             data = theta_preregisteredExclusion$Drink,
             iter = 20000)

fe <- fixef(mDrink)[,"Estimate"]
re <- ranef(mDrink)$Country[,,][,"Estimate"]
postDrink <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Drink", x = 1)
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mDrink) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="Drink", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)
sjPlot::tab_model(mDrink)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.76 0.66 – 0.86
Random Effects
σ2 0.04
τ00 0.01
ICC 0.80
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.738
Show codes
mJacket <- brm(theta|se(se_theta) ~ 1 + (1|Country),
               prior = prior_string("normal(0,2.5)", class = "Intercept"),
               data = theta_preregisteredExclusion$Jacket,
               iter = 20000)

fe <- fixef(mJacket)[,"Estimate"]
re <- ranef(mJacket)$Country[,,][,"Estimate"]
postJacket <- data.frame(post=c(fe, fe+re), 
                         Country=c("all", names(re)), 
                         study="Jacket", x = 2)
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mJacket) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="Jacket", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)

sjPlot::tab_model(mJacket)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.53 0.42 – 0.63
Random Effects
σ2 0.03
τ00 0.02
ICC 0.67
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.676
Show codes
mPlay <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             prior = prior_string("normal(0,2.5)", class = "Intercept"),
             data = theta_preregisteredExclusion$Play,
             iter = 20000)

fe <- fixef(mPlay)[,"Estimate"]
re <- ranef(mPlay)$Country[,,][,"Estimate"]
postPlay <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Play", x = 3)
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mPlay) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="Play", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)

sjPlot::tab_model(mPlay)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.58 0.41 – 0.75
Random Effects
σ2 0.12
τ00 0.02
ICC 0.87
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.870
Show codes
mGym <- brm(theta|se(se_theta) ~ 1 + (1|Country),
            prior = prior_string("normal(0,2.5)", class = "Intercept"),
            data = theta_preregisteredExclusion$Gym,
            iter = 20000)

fe <- fixef(mGym)[,"Estimate"]
re <- ranef(mGym)$Country[,,][,"Estimate"]
postGym <- data.frame(post=c(fe, fe+re), 
                      Country=c("all", names(re)), 
                      study="Gym", x = 2)
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mGym) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="Gym", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)

sjPlot::tab_model(mGym)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.72 0.50 – 0.94
Random Effects
σ2 0.21
τ00 0.01
ICC 0.96
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.963
Show codes
mPlane <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              prior = prior_string("normal(0,2.5)", class = "Intercept"),
              data = theta_preregisteredExclusion$Plane,
              iter = 20000)

fe <- fixef(mPlane)[,"Estimate"]
re <- ranef(mPlane)$Country[,,][,"Estimate"]
postPlane <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Plane", x = 4)
Code
# re-run1
table_bayesian <- rbind(
  table_bayesian,
  fixef(mPlane) %>% as.data.frame(row.names = '') %>% 
    mutate(Study="Plane", 
           Estimate = round(Estimate, 2),
           `CIs (95%)`=str_c(round(Q2.5,2), round(Q97.5,2), sep = ' - '),
           ) %>% 
    select(-c(Est.Error, Q2.5, Q97.5))
)
#
sjPlot::tab_model(mPlane)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.82 0.69 – 0.95
Random Effects
σ2 0.06
τ00 0.02
ICC 0.74
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.744
Plot posteriors full exclusion
# Re-plot1
# Include Credible interval
postMrAB1$lower <- c(fixef(mMrAB1)[,"Q2.5"], fixef(mMrAB1)[,"Q2.5"]+ranef(mMrAB1)$Country[,,][,"Q2.5"] )
postMrAB1$upper <- c(fixef(mMrAB1)[,"Q97.5"], fixef(mMrAB1)[,"Q97.5"]+ranef(mMrAB1)$Country[,,][,"Q97.5"] )

postMrAB2$lower <- c(fixef(mMrAB2)[,"Q2.5"], fixef(mMrAB2)[,"Q2.5"]+ranef(mMrAB2)$Country[,,][,"Q2.5"] )
postMrAB2$upper <- c(fixef(mMrAB2)[,"Q97.5"], fixef(mMrAB2)[,"Q97.5"]+ranef(mMrAB2)$Country[,,][,"Q97.5"] )

postGame$lower <- c(fixef(mGame)[,"Q2.5"], fixef(mGame)[,"Q2.5"]+ranef(mGame)$Country[,,][,"Q2.5"] )
postGame$upper <- c(fixef(mGame)[,"Q97.5"], fixef(mGame)[,"Q97.5"]+ranef(mGame)$Country[,,][,"Q97.5"] )

postDrink$lower <- c(fixef(mDrink)[,"Q2.5"], fixef(mDrink)[,"Q2.5"]+ranef(mDrink)$Country[,,][,"Q2.5"] )
postDrink$upper <- c(fixef(mDrink)[,"Q97.5"], fixef(mDrink)[,"Q97.5"]+ranef(mDrink)$Country[,,][,"Q97.5"] )

postJacket$lower <- c(fixef(mJacket)[,"Q2.5"], fixef(mJacket)[,"Q2.5"]+ranef(mJacket)$Country[,,][,"Q2.5"] )
postJacket$upper <- c(fixef(mJacket)[,"Q97.5"], fixef(mJacket)[,"Q97.5"]+ranef(mJacket)$Country[,,][,"Q97.5"] )

postPlay$lower <- c(fixef(mPlay)[,"Q2.5"], fixef(mPlay)[,"Q2.5"]+ranef(mPlay)$Country[,,][,"Q2.5"] )
postPlay$upper <- c(fixef(mPlay)[,"Q97.5"], fixef(mPlay)[,"Q97.5"]+ranef(mPlay)$Country[,,][,"Q97.5"] )

postGym$lower <- c(fixef(mGym)[,"Q2.5"], fixef(mGym)[,"Q2.5"]+ranef(mGym)$Country[,,][,"Q2.5"] )
postGym$upper <- c(fixef(mGym)[,"Q97.5"], fixef(mGym)[,"Q97.5"]+ranef(mGym)$Country[,,][,"Q97.5"] )

postPlane$lower <- c(fixef(mPlane)[,"Q2.5"], fixef(mPlane)[,"Q2.5"]+ranef(mPlane)$Country[,,][,"Q2.5"] )
postPlane$upper <- c(fixef(mPlane)[,"Q97.5"], fixef(mPlane)[,"Q97.5"]+ranef(mPlane)$Country[,,][,"Q97.5"] )

post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% 
  mutate(
    family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

post_OR <- post %>% filter(family=="binomial") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  geom_segment(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), linewidth=1.8,
               aes(x=x-0.2, xend=x+0.2, y=theta, yend=theta), color="#472E7CFF") +
  
  geom_segment(data = post %>% filter(family=="binomial") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:4,
                     labels = post %>% filter(family=="binomial") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_ER <- post %>% filter(family=="binomial1") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  
  geom_segment(data = post %>% filter(family=="binomial1") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_SMD <- post %>% filter(family=="gaussian") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +

  geom_segment(data = post %>% filter(family=="gaussian") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=1) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="white", size=3) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:3) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

cowplot::plot_grid(post_OR, post_ER, post_SMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Compute Bayes Factor
# re-run1
compute_bayes_factor <- function(model){
  intercept <- as_draws(model, variable = "b_Intercept")
  posterior <- as.vector(unlist(intercept))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
}

log10_bf <- c(
  round(log10(as.numeric(compute_bayes_factor(mMrAB1))), 2),
  round(log10(as.numeric(compute_bayes_factor(mMrAB2))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGame))), 2),
  round(log10(as.numeric(compute_bayes_factor(mDrink))), 2),
  round(log10(as.numeric(compute_bayes_factor(mJacket))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlay))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGym))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlane))), 2)
)
Code
# re-run1
rownames(table_bayesian) <- table_bayesian$Study
 
table_bayesian$`log₁₀(BF)` <- log10_bf
 
table_bayesian$` ` <- row.names(table_bayesian)
row.names(table_bayesian) <- NULL

table_bayesian[,c(5,1:4)] %>%
  select(-Study) %>%
  flextable() %>%
  set_caption(caption = "Table 2: Hierarchical Bayesian Meta-Analysis") %>%
  theme_apa() %>%
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='center') %>%
  align(align='center', part='header') %>%
  autofit() %>%
  save_as_docx(path = "tables/Hierarchical Bayesian Meta-Analysis.docx")

table_bayesian[,c(5,1:4)] %>%
  select(-Study) |>
  kbl(caption="<b>Table 2 | </b> Hierarchical Bayesian Meta-Analysis",
      format = "html", table.attr = "style='width:50%;'") %>%
  kable_classic(html_font = "Cambria") %>%
  kable_material(c("striped", "hover"))
Table 2 | Hierarchical Bayesian Meta-Analysis
Estimate CIs (95%) log₁₀(BF)
MrAB1 1.48 1.31 - 1.65 13.24
MrAB2 2.13 1.99 - 2.27 31.67
Game 1.90 1.68 - 2.12 17.02
Drink 0.76 0.66 - 0.86 10.63
Jacket 0.53 0.42 - 0.63 7.96
Play 0.58 0.41 - 0.75 4.54
Gym 0.72 0.5 - 0.94 4.56
Plane 0.82 0.69 - 0.95 11.63

Number of participants: 5589

Click on the tabs to see the model’s summary for each study

Show codes
# MrAB
mMrAB1 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_partialExclusion$MrAB %>% filter(condition=="gain"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB1)[,"Estimate"]
re <- ranef(mMrAB1)$Country[,,][,"Estimate"]
postMrAB1 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 1)

mMrAB2 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_partialExclusion$MrAB %>% filter(condition=="loss"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB2)[,"Estimate"]
re <- ranef(mMrAB2)$Country[,,][,"Estimate"]
postMrAB2 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.46 1.29 – 1.62
Random Effects
σ2 0.12
τ00 0.01
ICC 0.95
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.945
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 2.09 1.96 – 2.24
Random Effects
σ2 0.08
τ00 0.01
ICC 0.93
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.928
Show codes
# MrAB
mGame <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_partialExclusion$Game,
             iter = 10000)

fe <- fixef(mGame)[,"Estimate"]
re <- ranef(mGame)$Country[,,][,"Estimate"]
postGame <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Game", x = 1)

sjPlot::tab_model(mGame)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.89 1.66 – 2.11
Random Effects
σ2 0.22
τ00 0.00
ICC 0.99
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.986
Show codes
mDrink <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_partialExclusion$Drink,
             iter = 10000)

fe <- fixef(mDrink)[,"Estimate"]
re <- ranef(mDrink)$Country[,,][,"Estimate"]
postDrink <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Drink", x = 1)

sjPlot::tab_model(mDrink)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.74 0.63 – 0.85
Random Effects
σ2 0.05
τ00 0.01
ICC 0.85
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.835
Show codes
mJacket <- brm(theta|se(se_theta) ~ 1 + (1|Country),
               data = theta_partialExclusion$Jacket,
               iter = 10000)

fe <- fixef(mJacket)[,"Estimate"]
re <- ranef(mJacket)$Country[,,][,"Estimate"]
postJacket <- data.frame(post=c(fe, fe+re), 
                         Country=c("all", names(re)), 
                         study="Jacket", x = 2)

sjPlot::tab_model(mJacket)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.52 0.42 – 0.62
Random Effects
σ2 0.03
τ00 0.01
ICC 0.72
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.729
Show codes
mPlay <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_partialExclusion$Play,
             iter = 10000)

fe <- fixef(mPlay)[,"Estimate"]
re <- ranef(mPlay)$Country[,,][,"Estimate"]
postPlay <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Play", x = 3)

sjPlot::tab_model(mPlay)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.56 0.40 – 0.73
Random Effects
σ2 0.11
τ00 0.01
ICC 0.88
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.882
Show codes
mGym <- brm(theta|se(se_theta) ~ 1 + (1|Country),
            data = theta_partialExclusion$Gym,
            iter = 10000)

fe <- fixef(mGym)[,"Estimate"]
re <- ranef(mGym)$Country[,,][,"Estimate"]
postGym <- data.frame(post=c(fe, fe+re), 
                      Country=c("all", names(re)), 
                      study="Gym", x = 2)

sjPlot::tab_model(mGym)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.70 0.48 – 0.90
Random Effects
σ2 0.19
τ00 0.01
ICC 0.97
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.967
Show codes
mPlane <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_partialExclusion$Plane,
              iter = 10000)

fe <- fixef(mPlane)[,"Estimate"]
re <- ranef(mPlane)$Country[,,][,"Estimate"]
postPlane <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Plane", x = 4)

sjPlot::tab_model(mPlane)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.75 0.63 – 0.88
Random Effects
σ2 0.05
τ00 0.02
ICC 0.75
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.756
Plot posteriors
# Re-plot1
# Include Credible interval
postMrAB1$lower <- c(fixef(mMrAB1)[,"Q2.5"], fixef(mMrAB1)[,"Q2.5"]+ranef(mMrAB1)$Country[,,][,"Q2.5"] )
postMrAB1$upper <- c(fixef(mMrAB1)[,"Q97.5"], fixef(mMrAB1)[,"Q97.5"]+ranef(mMrAB1)$Country[,,][,"Q97.5"] )

postMrAB2$lower <- c(fixef(mMrAB2)[,"Q2.5"], fixef(mMrAB2)[,"Q2.5"]+ranef(mMrAB2)$Country[,,][,"Q2.5"] )
postMrAB2$upper <- c(fixef(mMrAB2)[,"Q97.5"], fixef(mMrAB2)[,"Q97.5"]+ranef(mMrAB2)$Country[,,][,"Q97.5"] )

postGame$lower <- c(fixef(mGame)[,"Q2.5"], fixef(mGame)[,"Q2.5"]+ranef(mGame)$Country[,,][,"Q2.5"] )
postGame$upper <- c(fixef(mGame)[,"Q97.5"], fixef(mGame)[,"Q97.5"]+ranef(mGame)$Country[,,][,"Q97.5"] )

postDrink$lower <- c(fixef(mDrink)[,"Q2.5"], fixef(mDrink)[,"Q2.5"]+ranef(mDrink)$Country[,,][,"Q2.5"] )
postDrink$upper <- c(fixef(mDrink)[,"Q97.5"], fixef(mDrink)[,"Q97.5"]+ranef(mDrink)$Country[,,][,"Q97.5"] )

postJacket$lower <- c(fixef(mJacket)[,"Q2.5"], fixef(mJacket)[,"Q2.5"]+ranef(mJacket)$Country[,,][,"Q2.5"] )
postJacket$upper <- c(fixef(mJacket)[,"Q97.5"], fixef(mJacket)[,"Q97.5"]+ranef(mJacket)$Country[,,][,"Q97.5"] )

postPlay$lower <- c(fixef(mPlay)[,"Q2.5"], fixef(mPlay)[,"Q2.5"]+ranef(mPlay)$Country[,,][,"Q2.5"] )
postPlay$upper <- c(fixef(mPlay)[,"Q97.5"], fixef(mPlay)[,"Q97.5"]+ranef(mPlay)$Country[,,][,"Q97.5"] )

postGym$lower <- c(fixef(mGym)[,"Q2.5"], fixef(mGym)[,"Q2.5"]+ranef(mGym)$Country[,,][,"Q2.5"] )
postGym$upper <- c(fixef(mGym)[,"Q97.5"], fixef(mGym)[,"Q97.5"]+ranef(mGym)$Country[,,][,"Q97.5"] )

postPlane$lower <- c(fixef(mPlane)[,"Q2.5"], fixef(mPlane)[,"Q2.5"]+ranef(mPlane)$Country[,,][,"Q2.5"] )
postPlane$upper <- c(fixef(mPlane)[,"Q97.5"], fixef(mPlane)[,"Q97.5"]+ranef(mPlane)$Country[,,][,"Q97.5"] )

post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% 
  mutate(
    family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    ) %>% 
  mutate(
    x = ifelse(study=="Jacket", 2, x),
    x = ifelse(study=="Play", 3, x),
    x = ifelse(study=="Plane", 4, x)
  )

post_OR <- post %>% filter(family=="binomial") %>%
  # mutate(x=x-2) %>% 
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  geom_segment(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), linewidth=1.8,
               aes(x=x-0.2, xend=x+0.2, y=theta, yend=theta), color="#472E7CFF") +
  
  geom_segment(data = post %>% filter(family=="binomial") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:4,
                     labels = post %>% filter(family=="binomial") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_ER <- post %>% filter(family=="binomial1") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  
  geom_segment(data = post %>% filter(family=="binomial1") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_SMD <- post %>% filter(family=="gaussian") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +

  geom_segment(data = post %>% filter(family=="gaussian") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=1) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="white", size=3) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,2), breaks = -1:2) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

cowplot::plot_grid(post_OR, post_ER, post_SMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Compute Bayes Factor
# re-run1
compute_bayes_factor <- function(model){
  intercept <- as_draws(model, variable = "b_Intercept")
  posterior <- as.vector(unlist(intercept))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
}


log10_bf <- c(
  round(log10(as.numeric(compute_bayes_factor(mMrAB1))), 2),
  round(log10(as.numeric(compute_bayes_factor(mMrAB2))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGame))), 2),
  round(log10(as.numeric(compute_bayes_factor(mDrink))), 2),
  round(log10(as.numeric(compute_bayes_factor(mJacket))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlay))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGym))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlane))), 2)
)
Code
# re-run1
rownames(table_bayesian) <- table_bayesian$Study
 
table_bayesian$`log₁₀(BF)` <- log10_bf
 
table_bayesian$` ` <- row.names(table_bayesian)
row.names(table_bayesian) <- NULL

table_bayesian[,c(5,1:4)] %>%
  select(-Study) %>% 
  flextable() %>% 
  set_caption(caption = "Table 2: Hierarchical Bayesian Meta-Analysis") %>% 
  theme_apa() %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  autofit() %>% 
  save_as_docx(path = "tables/Hierarchical Bayesian Meta-Analysis (Partial).docx")

table_bayesian[,c(5,1:4)] %>%
  select(-Study) |>
  kbl(caption="<b>Table 2 | </b> Hierarchical Bayesian Meta-Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 2 | Hierarchical Bayesian Meta-Analysis
Estimate CIs (95%) log₁₀(BF)
MrAB1 1.46 1.29 - 1.62 16.29
MrAB2 2.10 1.96 - 2.24 49.66
Game 1.89 1.66 - 2.11 13.49
Drink 0.74 0.63 - 0.85 11.40
Jacket 0.52 0.42 - 0.62 7.09
Play 0.56 0.4 - 0.73 6.03
Gym 0.69 0.48 - 0.9 4.87
Plane 0.75 0.63 - 0.88 8.18

Number of participants: 6730

Click on the tabs to see the model’s summary for each study

Show codes
# MrAB
mMrAB1 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_fullExclusion$MrAB %>% filter(condition=="gain"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB1)[,"Estimate"]
re <- ranef(mMrAB1)$Country[,,][,"Estimate"]
postMrAB1 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 1)

mMrAB2 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_fullExclusion$MrAB %>% filter(condition=="loss"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB2)[,"Estimate"]
re <- ranef(mMrAB2)$Country[,,][,"Estimate"]
postMrAB2 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.50 1.32 – 1.67
Random Effects
σ2 0.13
τ00 0.01
ICC 0.93
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.934
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 2.14 1.98 – 2.30
Random Effects
σ2 0.10
τ00 0.01
ICC 0.92
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.925
Show codes
# Game
mGame <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_fullExclusion$Game,
             iter = 10000)

fe <- fixef(mGame)[,"Estimate"]
re <- ranef(mGame)$Country[,,][,"Estimate"]
postGame <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Game", x = 1)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.89 1.66 – 2.12
Random Effects
σ2 0.24
τ00 0.00
ICC 0.98
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.982
Show codes
mDrink <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_fullExclusion$Drink,
             iter = 10000)

fe <- fixef(mDrink)[,"Estimate"]
re <- ranef(mDrink)$Country[,,][,"Estimate"]
postDrink <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Drink", x = 1)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.76 0.66 – 0.86
Random Effects
σ2 0.03
τ00 0.01
ICC 0.77
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.697
Show codes
mJacket <- brm(theta|se(se_theta) ~ 1 + (1|Country),
               data = theta_fullExclusion$Jacket,
               iter = 10000)

fe <- fixef(mJacket)[,"Estimate"]
re <- ranef(mJacket)$Country[,,][,"Estimate"]
postJacket <- data.frame(post=c(fe, fe+re), 
                         Country=c("all", names(re)), 
                         study="Jacket", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.53 0.42 – 0.63
Random Effects
σ2 0.03
τ00 0.02
ICC 0.62
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.634
Show codes
mPlay <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_fullExclusion$Play,
             iter = 10000)

fe <- fixef(mPlay)[,"Estimate"]
re <- ranef(mPlay)$Country[,,][,"Estimate"]
postPlay <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Play", x = 3)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.59 0.43 – 0.77
Random Effects
σ2 0.12
τ00 0.02
ICC 0.86
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.856
Show codes
mGym <- brm(theta|se(se_theta) ~ 1 + (1|Country),
            data = theta_fullExclusion$Gym,
            iter = 10000)

fe <- fixef(mGym)[,"Estimate"]
re <- ranef(mGym)$Country[,,][,"Estimate"]
postGym <- data.frame(post=c(fe, fe+re), 
                      Country=c("all", names(re)), 
                      study="Gym", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.73 0.51 – 0.94
Random Effects
σ2 0.21
τ00 0.01
ICC 0.96
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.960
Show codes
mPlane <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_fullExclusion$Plane,
              iter = 10000)

fe <- fixef(mPlane)[,"Estimate"]
re <- ranef(mPlane)$Country[,,][,"Estimate"]
postPlane <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Plane", x = 4)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.82 0.68 – 0.95
Random Effects
σ2 0.06
τ00 0.02
ICC 0.73
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.728
Plot posteriors full exclusion
# Re-plot1
# Include Credible interval
postMrAB1$lower <- c(fixef(mMrAB1)[,"Q2.5"], fixef(mMrAB1)[,"Q2.5"]+ranef(mMrAB1)$Country[,,][,"Q2.5"] )
postMrAB1$upper <- c(fixef(mMrAB1)[,"Q97.5"], fixef(mMrAB1)[,"Q97.5"]+ranef(mMrAB1)$Country[,,][,"Q97.5"] )

postMrAB2$lower <- c(fixef(mMrAB2)[,"Q2.5"], fixef(mMrAB2)[,"Q2.5"]+ranef(mMrAB2)$Country[,,][,"Q2.5"] )
postMrAB2$upper <- c(fixef(mMrAB2)[,"Q97.5"], fixef(mMrAB2)[,"Q97.5"]+ranef(mMrAB2)$Country[,,][,"Q97.5"] )

postGame$lower <- c(fixef(mGame)[,"Q2.5"], fixef(mGame)[,"Q2.5"]+ranef(mGame)$Country[,,][,"Q2.5"] )
postGame$upper <- c(fixef(mGame)[,"Q97.5"], fixef(mGame)[,"Q97.5"]+ranef(mGame)$Country[,,][,"Q97.5"] )

postDrink$lower <- c(fixef(mDrink)[,"Q2.5"], fixef(mDrink)[,"Q2.5"]+ranef(mDrink)$Country[,,][,"Q2.5"] )
postDrink$upper <- c(fixef(mDrink)[,"Q97.5"], fixef(mDrink)[,"Q97.5"]+ranef(mDrink)$Country[,,][,"Q97.5"] )

postJacket$lower <- c(fixef(mJacket)[,"Q2.5"], fixef(mJacket)[,"Q2.5"]+ranef(mJacket)$Country[,,][,"Q2.5"] )
postJacket$upper <- c(fixef(mJacket)[,"Q97.5"], fixef(mJacket)[,"Q97.5"]+ranef(mJacket)$Country[,,][,"Q97.5"] )

postPlay$lower <- c(fixef(mPlay)[,"Q2.5"], fixef(mPlay)[,"Q2.5"]+ranef(mPlay)$Country[,,][,"Q2.5"] )
postPlay$upper <- c(fixef(mPlay)[,"Q97.5"], fixef(mPlay)[,"Q97.5"]+ranef(mPlay)$Country[,,][,"Q97.5"] )

postGym$lower <- c(fixef(mGym)[,"Q2.5"], fixef(mGym)[,"Q2.5"]+ranef(mGym)$Country[,,][,"Q2.5"] )
postGym$upper <- c(fixef(mGym)[,"Q97.5"], fixef(mGym)[,"Q97.5"]+ranef(mGym)$Country[,,][,"Q97.5"] )

postPlane$lower <- c(fixef(mPlane)[,"Q2.5"], fixef(mPlane)[,"Q2.5"]+ranef(mPlane)$Country[,,][,"Q2.5"] )
postPlane$upper <- c(fixef(mPlane)[,"Q97.5"], fixef(mPlane)[,"Q97.5"]+ranef(mPlane)$Country[,,][,"Q97.5"] )

post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% 
  mutate(
    family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

post_OR <- post %>% filter(family=="binomial") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  geom_segment(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), linewidth=1.8,
               aes(x=x-0.2, xend=x+0.2, y=theta, yend=theta), color="#472E7CFF") +
  
  geom_segment(data = post %>% filter(family=="binomial") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:4,
                     labels = post %>% filter(family=="binomial") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_ER <- post %>% filter(family=="binomial1") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  
  geom_segment(data = post %>% filter(family=="binomial1") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_SMD <- post %>% filter(family=="gaussian") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +

  geom_segment(data = post %>% filter(family=="gaussian") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=1) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="white", size=3) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,2), breaks = -1:2) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

cowplot::plot_grid(post_OR, post_ER, post_SMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Compute Bayes Factor
# re-run1
compute_bayes_factor <- function(model){
  intercept <- as_draws(model, variable = "b_Intercept")
  posterior <- as.vector(unlist(intercept))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
}


log10_bf <- c(
  round(log10(as.numeric(compute_bayes_factor(mMrAB1))), 2),
  round(log10(as.numeric(compute_bayes_factor(mMrAB2))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGame))), 2),
  round(log10(as.numeric(compute_bayes_factor(mDrink))), 2),
  round(log10(as.numeric(compute_bayes_factor(mJacket))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlay))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGym))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlane))), 2)
)
Code
# re-run1
rownames(table_bayesian) <- table_bayesian$Study
 
table_bayesian$`log₁₀(BF)` <- log10_bf
 
table_bayesian$` ` <- row.names(table_bayesian)
row.names(table_bayesian) <- NULL

table_bayesian[,c(5,1:4)] %>%
  select(-Study) %>% 
  flextable() %>% 
  set_caption(caption = "Table 2: Hierarchical Bayesian Meta-Analysis") %>% 
  theme_apa() %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  autofit() %>% 
  save_as_docx(path = "tables/Hierarchical Bayesian Meta-Analysis (Full).docx")

table_bayesian[,c(5,1:4)] %>%
  select(-Study) |>
  kbl(caption="<b>Table 2 | </b> Hierarchical Bayesian Meta-Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 2 | Hierarchical Bayesian Meta-Analysis
Estimate CIs (95%) log₁₀(BF)
MrAB1 1.50 1.32 - 1.67 13.56
MrAB2 2.14 1.98 - 2.3 27.66
Game 1.89 1.66 - 2.12 15.74
Drink 0.76 0.66 - 0.86 14.51
Jacket 0.53 0.42 - 0.63 7.84
Play 0.59 0.43 - 0.77 5.02
Gym 0.73 0.51 - 0.94 3.36
Plane 0.82 0.68 - 0.95 8.16

Number of participants: 10142

Click on the tabs to see the model’s summary for each study

Show codes
# MrAB
mMrAB1 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_exploratoryExclusion$MrAB %>% filter(condition=="gain"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB1)[,"Estimate"]
re <- ranef(mMrAB1)$Country[,,][,"Estimate"]
postMrAB1 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 1)

mMrAB2 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_exploratoryExclusion$MrAB %>% filter(condition=="loss"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB2)[,"Estimate"]
re <- ranef(mMrAB2)$Country[,,][,"Estimate"]
postMrAB2 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.49 1.33 – 1.67
Random Effects
σ2 0.13
τ00 0.01
ICC 0.94
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.938
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 2.13 1.98 – 2.28
Random Effects
σ2 0.09
τ00 0.01
ICC 0.92
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.923
Show codes
# Game
mGame <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_exploratoryExclusion$Game,
             iter = 10000)

fe <- fixef(mGame)[,"Estimate"]
re <- ranef(mGame)$Country[,,][,"Estimate"]
postGame <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Game", x = 1)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.90 1.66 – 2.13
Random Effects
σ2 0.24
τ00 0.00
ICC 0.98
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.984
Show codes
mDrink <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_fullExclusion$Drink,
             iter = 10000)

fe <- fixef(mDrink)[,"Estimate"]
re <- ranef(mDrink)$Country[,,][,"Estimate"]
postDrink <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Drink", x = 1)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.76 0.66 – 0.86
Random Effects
σ2 0.03
τ00 0.01
ICC 0.77
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.696
Show codes
# re-run1
mJacket <- brm(theta|se(se_theta) ~ 1 + (1|Country),
               data = theta_exploratoryExclusion$Jacket,
               iter = 10000)

fe <- fixef(mJacket)[,"Estimate"]
re <- ranef(mJacket)$Country[,,][,"Estimate"]
postJacket <- data.frame(post=c(fe, fe+re), 
                         Country=c("all", names(re)), 
                         study="Jacket", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.53 0.43 – 0.63
Random Effects
σ2 0.03
τ00 0.02
ICC 0.67
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.680
Show codes
# re-run1
mPlay <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_exploratoryExclusion$Play,
             iter = 10000)

fe <- fixef(mPlay)[,"Estimate"]
re <- ranef(mPlay)$Country[,,][,"Estimate"]
postPlay <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Play", x = 3)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.59 0.42 – 0.76
Random Effects
σ2 0.12
τ00 0.02
ICC 0.87
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.867
Show codes
mGym <- brm(theta|se(se_theta) ~ 1 + (1|Country),
            data = theta_exploratoryExclusion$Gym,
            iter = 10000)

fe <- fixef(mGym)[,"Estimate"]
re <- ranef(mGym)$Country[,,][,"Estimate"]
postGym <- data.frame(post=c(fe, fe+re), 
                      Country=c("all", names(re)), 
                      study="Gym", x = 2)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.73 0.52 – 0.94
Random Effects
σ2 0.21
τ00 0.01
ICC 0.96
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.962
Show codes
# re-run1
mPlane <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_exploratoryExclusion$Plane,
              iter = 10000)

fe <- fixef(mPlane)[,"Estimate"]
re <- ranef(mPlane)$Country[,,][,"Estimate"]
postPlane <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Plane", x = 4)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.82 0.69 – 0.95
Random Effects
σ2 0.06
τ00 0.02
ICC 0.73
N Country 21
Observations 21
Marginal R2 / Conditional R2 0.000 / 0.734
Plot posteriors full exclusion
# Re-plot
# Include Credible interval
postMrAB1$lower <- c(fixef(mMrAB1)[,"Q2.5"], fixef(mMrAB1)[,"Q2.5"]+ranef(mMrAB1)$Country[,,][,"Q2.5"] )
postMrAB1$upper <- c(fixef(mMrAB1)[,"Q97.5"], fixef(mMrAB1)[,"Q97.5"]+ranef(mMrAB1)$Country[,,][,"Q97.5"] )

postMrAB2$lower <- c(fixef(mMrAB2)[,"Q2.5"], fixef(mMrAB2)[,"Q2.5"]+ranef(mMrAB2)$Country[,,][,"Q2.5"] )
postMrAB2$upper <- c(fixef(mMrAB2)[,"Q97.5"], fixef(mMrAB2)[,"Q97.5"]+ranef(mMrAB2)$Country[,,][,"Q97.5"] )

postGame$lower <- c(fixef(mGame)[,"Q2.5"], fixef(mGame)[,"Q2.5"]+ranef(mGame)$Country[,,][,"Q2.5"] )
postGame$upper <- c(fixef(mGame)[,"Q97.5"], fixef(mGame)[,"Q97.5"]+ranef(mGame)$Country[,,][,"Q97.5"] )

postDrink$lower <- c(fixef(mDrink)[,"Q2.5"], fixef(mDrink)[,"Q2.5"]+ranef(mDrink)$Country[,,][,"Q2.5"] )
postDrink$upper <- c(fixef(mDrink)[,"Q97.5"], fixef(mDrink)[,"Q97.5"]+ranef(mDrink)$Country[,,][,"Q97.5"] )

postJacket$lower <- c(fixef(mJacket)[,"Q2.5"], fixef(mJacket)[,"Q2.5"]+ranef(mJacket)$Country[,,][,"Q2.5"] )
postJacket$upper <- c(fixef(mJacket)[,"Q97.5"], fixef(mJacket)[,"Q97.5"]+ranef(mJacket)$Country[,,][,"Q97.5"] )

postPlay$lower <- c(fixef(mPlay)[,"Q2.5"], fixef(mPlay)[,"Q2.5"]+ranef(mPlay)$Country[,,][,"Q2.5"] )
postPlay$upper <- c(fixef(mPlay)[,"Q97.5"], fixef(mPlay)[,"Q97.5"]+ranef(mPlay)$Country[,,][,"Q97.5"] )

postGym$lower <- c(fixef(mGym)[,"Q2.5"], fixef(mGym)[,"Q2.5"]+ranef(mGym)$Country[,,][,"Q2.5"] )
postGym$upper <- c(fixef(mGym)[,"Q97.5"], fixef(mGym)[,"Q97.5"]+ranef(mGym)$Country[,,][,"Q97.5"] )

postPlane$lower <- c(fixef(mPlane)[,"Q2.5"], fixef(mPlane)[,"Q2.5"]+ranef(mPlane)$Country[,,][,"Q2.5"] )
postPlane$upper <- c(fixef(mPlane)[,"Q97.5"], fixef(mPlane)[,"Q97.5"]+ranef(mPlane)$Country[,,][,"Q97.5"] )

post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% 
  mutate(
    family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

post_OR <- post %>% filter(family=="binomial") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  geom_segment(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), linewidth=1.8,
               aes(x=x-0.2, xend=x+0.2, y=theta, yend=theta), color="#472E7CFF") +
  
  geom_segment(data = post %>% filter(family=="binomial") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:4,
                     labels = post %>% filter(family=="binomial") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_ER <- post %>% filter(family=="binomial1") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  
  geom_segment(data = post %>% filter(family=="binomial1") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_SMD <- post %>% filter(family=="gaussian") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +

  geom_segment(data = post %>% filter(family=="gaussian") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=1) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="white", size=3) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,2), breaks = -1:2) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

cowplot::plot_grid(post_OR, post_ER, post_SMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Compute Bayes Factor
# re-run
compute_bayes_factor <- function(model){
  intercept <- as_draws(model, variable = "b_Intercept")
  posterior <- as.vector(unlist(intercept))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
}

log10_bf <- c(
  round(log10(as.numeric(compute_bayes_factor(mMrAB1))), 2),
  round(log10(as.numeric(compute_bayes_factor(mMrAB2))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGame))), 2),
  round(log10(as.numeric(compute_bayes_factor(mDrink))), 2),
  round(log10(as.numeric(compute_bayes_factor(mJacket))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlay))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGym))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlane))), 2)
)
Code
# re-run
rownames(table_bayesian) <- table_bayesian$Study
 
table_bayesian$`log₁₀(BF)` <- log10_bf
 
table_bayesian$` ` <- row.names(table_bayesian)
row.names(table_bayesian) <- NULL

table_bayesian[,c(5,1:4)] %>%
  select(-Study) %>% 
  flextable() %>% 
  set_caption(caption = "Table 2: Hierarchical Bayesian Meta-Analysis") %>% 
  theme_apa() %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  autofit() %>% 
  save_as_docx(path = "tables/Hierarchical Bayesian Meta-Analysis (Exploratory).docx")

table_bayesian[,c(5,1:4)] %>%
  select(-Study) |>
  kbl(caption="<b>Table 2 | </b> Hierarchical Bayesian Meta-Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 2 | Hierarchical Bayesian Meta-Analysis
Estimate CIs (95%) log₁₀(BF)
MrAB1 1.50 1.33 - 1.67 16.36
MrAB2 2.13 1.98 - 2.28 31.59
Game 1.90 1.66 - 2.13 9.06
Drink 0.76 0.66 - 0.86 12.14
Jacket 0.53 0.43 - 0.63 7.80
Play 0.59 0.42 - 0.76 5.48
Gym 0.73 0.52 - 0.94 4.01
Plane 0.82 0.69 - 0.95 7.83

Number of participants: 5505

Click on the tabs to see the model’s summary for each study

Show codes
# MrAB
mMrAB1 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_noExclusion$MrAB %>% filter(condition=="gain"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB1)[,"Estimate"]
re <- ranef(mMrAB1)$Country[,,][,"Estimate"]
postMrAB1 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 1)

mMrAB2 <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_noExclusion$MrAB %>% filter(condition=="loss"),
              iter = 10000, refresh = 0)

fe <- fixef(mMrAB2)[,"Estimate"]
re <- ranef(mMrAB2)$Country[,,][,"Estimate"]
postMrAB2 <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="MrAB", x = 1.8)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.42 1.28 – 1.57
Random Effects
σ2 0.15
τ00 0.01
ICC 0.93
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.927
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 2.04 1.91 – 2.17
Random Effects
σ2 0.11
τ00 0.01
ICC 0.92
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.921
Show codes
# Game
mGame <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_noExclusion$Game,
             iter = 10000)

fe <- fixef(mGame)[,"Estimate"]
re <- ranef(mGame)$Country[,,][,"Estimate"]
postGame <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Game", x = 1)

sjPlot::tab_model(mGame)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 1.82 1.63 – 2.02
Random Effects
σ2 0.27
τ00 0.01
ICC 0.98
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.981
Show codes
mDrink <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_noExclusion$Drink,
             iter = 10000)

fe <- fixef(mDrink)[,"Estimate"]
re <- ranef(mDrink)$Country[,,][,"Estimate"]
postDrink <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Drink", x = 1)

sjPlot::tab_model(mDrink)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.67 0.57 – 0.77
Random Effects
σ2 0.06
τ00 0.01
ICC 0.83
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.785
Show codes
# re-run
mJacket <- brm(theta|se(se_theta) ~ 1 + (1|Country),
               data = theta_noExclusion$Jacket,
               iter = 10000)

fe <- fixef(mJacket)[,"Estimate"]
re <- ranef(mJacket)$Country[,,][,"Estimate"]
postJacket <- data.frame(post=c(fe, fe+re), 
                         Country=c("all", names(re)), 
                         study="Jacket", x = 2)

sjPlot::tab_model(mJacket)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.54 0.45 – 0.63
Random Effects
σ2 0.04
τ00 0.02
ICC 0.68
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.690
Show codes
# re-run
mPlay <- brm(theta|se(se_theta) ~ 1 + (1|Country),
             data = theta_noExclusion$Play,
             iter = 10000)

fe <- fixef(mPlay)[,"Estimate"]
re <- ranef(mPlay)$Country[,,][,"Estimate"]
postPlay <- data.frame(post=c(fe, fe+re), 
                       Country=c("all", names(re)), 
                       study="Play", x = 3)

sjPlot::tab_model(mPlay)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.54 0.42 – 0.66
Random Effects
σ2 0.08
τ00 0.02
ICC 0.79
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.810
Show codes
mGym <- brm(theta|se(se_theta) ~ 1 + (1|Country),
            data = theta_noExclusion$Gym,
            iter = 10000)

fe <- fixef(mGym)[,"Estimate"]
re <- ranef(mGym)$Country[,,][,"Estimate"]
postGym <- data.frame(post=c(fe, fe+re), 
                      Country=c("all", names(re)), 
                      study="Gym", x = 2)

sjPlot::tab_model(mGym)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.68 0.52 – 0.83
Random Effects
σ2 0.16
τ00 0.01
ICC 0.94
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.944
Show codes
# re-run
mPlane <- brm(theta|se(se_theta) ~ 1 + (1|Country),
              data = theta_noExclusion$Plane,
              iter = 10000)

fe <- fixef(mPlane)[,"Estimate"]
re <- ranef(mPlane)$Country[,,][,"Estimate"]
postPlane <- data.frame(post=c(fe, fe+re), 
                        Country=c("all", names(re)), 
                        study="Plane", x = 4)

sjPlot::tab_model(mPlane)
  theta | se(se_theta)
Predictors Estimates CI (95%)
Intercept 0.77 0.66 – 0.87
Random Effects
σ2 0.06
τ00 0.03
ICC 0.69
N Country 32
Observations 32
Marginal R2 / Conditional R2 0.000 / 0.651
Plot posteriors
# Re-plot1
# Include Credible interval
postMrAB1$lower <- c(fixef(mMrAB1)[,"Q2.5"], fixef(mMrAB1)[,"Q2.5"]+ranef(mMrAB1)$Country[,,][,"Q2.5"] )
postMrAB1$upper <- c(fixef(mMrAB1)[,"Q97.5"], fixef(mMrAB1)[,"Q97.5"]+ranef(mMrAB1)$Country[,,][,"Q97.5"] )

postMrAB2$lower <- c(fixef(mMrAB2)[,"Q2.5"], fixef(mMrAB2)[,"Q2.5"]+ranef(mMrAB2)$Country[,,][,"Q2.5"] )
postMrAB2$upper <- c(fixef(mMrAB2)[,"Q97.5"], fixef(mMrAB2)[,"Q97.5"]+ranef(mMrAB2)$Country[,,][,"Q97.5"] )

postGame$lower <- c(fixef(mGame)[,"Q2.5"], fixef(mGame)[,"Q2.5"]+ranef(mGame)$Country[,,][,"Q2.5"] )
postGame$upper <- c(fixef(mGame)[,"Q97.5"], fixef(mGame)[,"Q97.5"]+ranef(mGame)$Country[,,][,"Q97.5"] )

postDrink$lower <- c(fixef(mDrink)[,"Q2.5"], fixef(mDrink)[,"Q2.5"]+ranef(mDrink)$Country[,,][,"Q2.5"] )
postDrink$upper <- c(fixef(mDrink)[,"Q97.5"], fixef(mDrink)[,"Q97.5"]+ranef(mDrink)$Country[,,][,"Q97.5"] )

postJacket$lower <- c(fixef(mJacket)[,"Q2.5"], fixef(mJacket)[,"Q2.5"]+ranef(mJacket)$Country[,,][,"Q2.5"] )
postJacket$upper <- c(fixef(mJacket)[,"Q97.5"], fixef(mJacket)[,"Q97.5"]+ranef(mJacket)$Country[,,][,"Q97.5"] )

postPlay$lower <- c(fixef(mPlay)[,"Q2.5"], fixef(mPlay)[,"Q2.5"]+ranef(mPlay)$Country[,,][,"Q2.5"] )
postPlay$upper <- c(fixef(mPlay)[,"Q97.5"], fixef(mPlay)[,"Q97.5"]+ranef(mPlay)$Country[,,][,"Q97.5"] )

postGym$lower <- c(fixef(mGym)[,"Q2.5"], fixef(mGym)[,"Q2.5"]+ranef(mGym)$Country[,,][,"Q2.5"] )
postGym$upper <- c(fixef(mGym)[,"Q97.5"], fixef(mGym)[,"Q97.5"]+ranef(mGym)$Country[,,][,"Q97.5"] )

postPlane$lower <- c(fixef(mPlane)[,"Q2.5"], fixef(mPlane)[,"Q2.5"]+ranef(mPlane)$Country[,,][,"Q2.5"] )
postPlane$upper <- c(fixef(mPlane)[,"Q97.5"], fixef(mPlane)[,"Q97.5"]+ranef(mPlane)$Country[,,][,"Q97.5"] )

post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% 
  mutate(
    family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

post_OR <- post %>% filter(family=="binomial") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  geom_segment(data = data_paper %>% filter(study!="MrAB") %>% mutate(x=x-2), linewidth=1.8,
               aes(x=x-0.2, xend=x+0.2, y=theta, yend=theta), color="#472E7CFF") +
  
  geom_segment(data = post %>% filter(family=="binomial") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:4,
                     labels = post %>% filter(family=="binomial") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_ER <- post %>% filter(family=="binomial1") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +
  
  geom_segment(data = post %>% filter(family=="binomial1") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=0.8) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="binomial1") %>%
               filter(Country=="all"), color="white", size=3) +
  
  geom_hline(yintercept = 0, linetype=2, linewidth=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

post_SMD <- post %>% filter(family=="gaussian") %>%
  filter(Country!="all") %>%
  ggplot(aes(x, post, color=Country)) +
  geom_jitter( width = 0.1, alpha=0.7, color="gray", size=2 ) +

  geom_segment(data = post %>% filter(family=="gaussian") %>%
                 filter(Country=="all"), color="#228B8DFF",
               aes(x=x, xend=x, y=lower, yend=upper), linewidth=1) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="#228B8DFF", size=5) +
  geom_point(data = post %>% filter(family=="gaussian") %>%
               filter(Country=="all"), color="white", size=3) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,2), breaks = -1:2) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>%
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") +
  guides(size = "none") +
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

cowplot::plot_grid(post_OR, post_ER, post_SMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Compute Bayes Factor
# re-run
compute_bayes_factor <- function(model){
  intercept <- as_draws(model, variable = "b_Intercept")
  posterior <- as.vector(unlist(intercept))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
}

log10_bf <- c(
  round(log10(as.numeric(compute_bayes_factor(mMrAB1))), 2),
  round(log10(as.numeric(compute_bayes_factor(mMrAB2))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGame))), 2),
  round(log10(as.numeric(compute_bayes_factor(mDrink))), 2),
  round(log10(as.numeric(compute_bayes_factor(mJacket))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlay))), 2),
  round(log10(as.numeric(compute_bayes_factor(mGym))), 2),
  round(log10(as.numeric(compute_bayes_factor(mPlane))), 2)
)
Code
# re-run
rownames(table_bayesian) <- table_bayesian$Study
 
table_bayesian$`log₁₀(BF)` <- log10_bf
 
table_bayesian$` ` <- row.names(table_bayesian)
row.names(table_bayesian) <- NULL

table_bayesian[,c(5,1:4)] %>%
  select(-Study) %>% 
  flextable() %>% 
  set_caption(caption = "Table 2: Hierarchical Bayesian Meta-Analysis") %>% 
  theme_apa() %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  autofit() %>% 
  save_as_docx(path = "tables/Hierarchical Bayesian Meta-Analysis (None).docx")

table_bayesian[,c(5,1:4)] %>%
  select(-Study) |>
  kbl(caption="<b>Table 2 | </b> Hierarchical Bayesian Meta-Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 2 | Hierarchical Bayesian Meta-Analysis
Estimate CIs (95%) log₁₀(BF)
MrAB1 1.42 1.28 - 1.57 17.02
MrAB2 2.04 1.91 - 2.17 33.92
Game 1.82 1.63 - 2.02 20.45
Drink 0.67 0.57 - 0.77 15.02
Jacket 0.54 0.45 - 0.63 9.15
Play 0.54 0.42 - 0.66 8.45
Gym 0.68 0.52 - 0.83 7.58
Plane 0.77 0.66 - 0.87 12.22

Number of participants: 8519

Unpooled Analysis


In this section we perform a Bayesian unpooled analysis. We will compute the effect size for each scenario and country independently. We will then compare each of them with the effect sizes found in the original papers.


Click on the tabs to see the model’s summary for each study

Show codes
ph0 <- 1/9
logit_h0 <- log(ph0 / (1-ph0))

mMrAB1 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                filter(scenario_group=="gain") %>% 
                group_by(subject) %>% 
                mutate(
                  response = ifelse(
                    (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0), 1, 0
                  )
                ) %>% filter(row_number()==1) %>% ungroup(), 
              iter = 20000, refresh = 0, family="bernoulli", cores = 4)


mMrAB2 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                filter(scenario_group=="loss") %>% 
                group_by(subject) %>% 
                mutate(
                  response = as.integer(response[scenario=="loss-loss VS loss"]==1 && response[scenario=="loss-gain VS loss"]==0)
                  ) %>% 
                filter(row_number()==1) %>% ungroup(),
              iter = 20000, refresh = 0, family="bernoulli", cores = 4)
Plot posteriors
# re-run1
post <- prepare_predictions(mMrAB1)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot1 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=1) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB1 <- post_plot1 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB1 <- post_plot1 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")



post <- prepare_predictions(mMrAB2)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot2 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=2) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB2 <- post_plot2 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB2 <- post_plot2 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "none")



cowplot::plot_grid(plMrAB1, plMrAB2, rel_widths = c(1, 0.8), nrow = 1)

Code
# re-run1
post_plot1$log10_bf = NA
for( country in unique(post_plot1$Country) ){
  idx = post_plot1$Country==country
  beta <- post_plot1$theta[idx]
  posterior <- as.vector(unlist(beta))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bf <- bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
  post_plot1$log10_bf[idx] <- round(log10(as.numeric(bf)), 2)
}

table_unpooled <- post_plot1 %>% 
  group_by(Country) %>% mutate(mu=mean(theta)) %>% 
  filter(row_number()==1) %>% 
  select(Country, mu, lower, upper, log10_bf) %>% 
  ungroup() %>% 
  mutate(`CIs (95%)`=str_c(round(lower,2), round(upper,2), sep = ' - '),
         mu=round(mu,2)) %>% 
  rename(Estimate = mu) %>% 
  mutate(` ` = "") %>% 
  .[,c(7,1,2, 6,5)] 


empty <- function(x){ 
  if(x==''){
    return("MrAB1")
    } else {
      return("")
    } 
  }

table_unpooled <- rbind(apply(table_unpooled[1,], 2, empty), table_unpooled)

rmarkdown::paged_table(
  post_plot1 %>% 
    group_by(Country) %>% mutate(mu=mean(theta)) %>% 
    filter(row_number()==1) %>% 
    select(Country, mu, lower, upper) %>% 
    ungroup()
  )
Show codes
mGame <- brm(response ~ buyer * Country,
             prior = prior_string("normal(0,2.5)", class = "b"),
              data = data_Game %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ),
              iter = 20000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mGame)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "buyer" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Game", family="binomial", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGame <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mDrink <- brm(response ~ store * Country,
              prior = prior_string("normal(0,2.5)", class = "b"),
              data = data_Drink %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                # Remove really really extreme outliers
                filter(response<10000 & response>=0) %>% 
                mutate(response=response+1, logResp=log(response)) %>% 
                group_by(Country) %>%
                mutate(response=as.vector(scale(logResp))) %>% 
                ungroup(),
              iter = 20000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mDrink)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "store" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]


post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Drink", family="gaussian", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})
 
postDrink <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>%   
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mJacket <- brm(response ~ price * Country,
               prior = prior_string("normal(0,2.5)", class = "b"),
               data = data_Jacket %>% 
                 # EXCLUSION: Full Exclusion
                 filter( !(Country %in% countries2remove) ) %>% 
                 filter( attention_check_grater_than_3 ),
               iter = 20000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mJacket)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "price" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Jacket", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postJacket <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlay <- brm(response ~ loss * Country,
             prior = prior_string("normal(0,2.5)", class = "b"),
             data = data_Play %>% 
               # EXCLUSION: Full Exclusion
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_3 ) %>% 
               mutate(loss=factor(loss, levels = c("ticket", "cash"))),
             iter = 20000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlay)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "loss" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Play", family="binomial", x=3) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlay <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mGym <- brm(response ~ frame * Country,
            prior = prior_string("normal(0,2.5)", class = "b"),
            data = data_Gym %>% 
              # EXCLUSION: Full Exclusion
              filter( !(Country %in% countries2remove) ) %>% 
              filter( attention_check_grater_than_3 ) %>% 
              group_by(Country) %>%
                mutate(response=as.vector(scale(response))) %>% 
                ungroup(),
             iter = 20000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mGym)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta" #
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "frame" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Gym", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGym <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlane <- brm(response ~ coupon * Country,
              prior = prior_string("normal(0,2.5)", class = "b"),
             data = data_Plane %>% 
               # EXCLUSION: Full Exclusion
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_3 ),
             iter = 20000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlane)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "coupon" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Plane", family="binomial", x=4) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlane <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none") 

We estimated 7 effects for 21 countries, for a total of 147 effects, and found an overall replication rate of 90.5%

Plot posteriors
# re-run
post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% # Recalculate
  mutate(family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

plotOR <- post %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = post %>% filter(family=="binomial") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotER <- post %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotSMD <- post %>% filter(family=="gaussian") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")


cowplot::plot_grid(plotOR, plotER, plotSMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Code
# table_unpooled %>% 
#   kbl(caption="<b>Table 3 | </b> Unpooled Analysis",
#       format = "html", table.attr = "style='width:50%;'") %>% 
#   kable_classic(html_font = "Cambria") %>% 
#   row_spec(0, bold = TRUE) %>%
#   save_kable("tables/png/Unpooled Analysis.png", zoom = 3)
  # save_kable("tables/pdf/Unpooled Analysis.pdf")
  
# re-run1
table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  flextable() %>% 
  set_caption(caption = "Table 3: Unpooled Analysis") %>% 
  theme_apa() %>% 
  width(width=c(0.8, 1,1,1.5, 1)) %>%
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='center') %>% 
  align(align='center', part='header') %>% 
  save_as_docx(path = "tables/Unpooled Analysis.docx")

table_unpooled %>% 
  rename(`log₁₀(BF)` = log10_bf) %>% 
  kbl(caption="<b>Table 3 | </b> Unpooled Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 3 | Unpooled Analysis
Country Estimate CIs (95%) log₁₀(BF)
MrAB1
Austria 1.06 0.79 - 1.33 7.04
Brazil 0.74 0.44 - 1.05 3.23
Canada 1.39 1.13 - 1.63 10.97
China 1.64 1.4 - 1.89 14.82
Denmark 1.26 1 - 1.52 8.28
Egypt 0.99 0.7 - 1.26 5.43
France 1.02 0.74 - 1.29 7.38
Germany 1.86 1.62 - 2.1 19.85
India 1.8 1.55 - 2.05 15.03
Indonesia 2.01 1.77 - 2.26 18.87
Italy 1.41 1.16 - 1.64 11.98
Lithuania 1.71 1.47 - 1.96 13.67
Morocco 0.89 0.59 - 1.17 5.4
Netherlands 1.43 1.16 - 1.68 10.13
Portugal 1.57 1.32 - 1.81 15.52
Romania 1.93 1.68 - 2.17 17.53
Spain 1.87 1.64 - 2.11 18.55
Sweden 1.52 1.29 - 1.76 13.52
Switzerland 1.96 1.72 - 2.19 16.67
USA 1.48 1.22 - 1.73 13.73
Vietnam 1.49 1.22 - 1.74 10.83
MrAB2
Austria 1.95 1.72 - 2.19 19.35
Brazil 1.6 1.34 - 1.85 15.07
Canada 2.47 2.23 - 2.72 25.79
China 2.38 2.14 - 2.63 23.42
Denmark 1.86 1.62 - 2.11 15.35
Egypt 1.56 1.3 - 1.81 14.02
France 1.95 1.71 - 2.19 16.61
Germany 2.37 2.12 - 2.62 22.86
India 1.88 1.63 - 2.12 18.25
Indonesia 2.27 2.04 - 2.52 19.89
Italy 2.39 2.15 - 2.61 22.81
Lithuania 1.94 1.7 - 2.18 16.18
Morocco 1.68 1.44 - 1.94 13.58
Netherlands 2.27 2.02 - 2.52 20.49
Portugal 2.2 1.95 - 2.43 23.5
Romania 1.96 1.72 - 2.2 18.54
Spain 2.48 2.24 - 2.72 25.03
Sweden 2.49 2.27 - 2.73 25.1
Switzerland 2.34 2.1 - 2.57 20.86
USA 2.36 2.12 - 2.62 21.25
Vietnam 2.25 2.01 - 2.5 21.71
Game
Austria 2.02 1.84 - 2.22 28.29
Brazil 1.45 1.25 - 1.66 17.51
Canada 2.04 1.84 - 2.24 50.62
China 2.65 2.39 - 2.94 24.7
Denmark 2.08 1.88 - 2.27 22.04
Egypt 1.51 1.3 - 1.72 15.89
France 2.08 1.88 - 2.27 25.93
Germany 2.36 2.15 - 2.57 28.11
India 1.42 1.21 - 1.64 14.9
Indonesia 0.85 0.67 - 1.02 9.04
Italy 2.22 2.02 - 2.42 25.65
Lithuania 2.1 1.87 - 2.33 22.4
Morocco 1.65 1.45 - 1.86 18.9
Netherlands 2.32 2.11 - 2.53 27.96
Portugal 2.09 1.9 - 2.29 21.25
Romania 1.59 1.41 - 1.78 20.13
Spain 2.46 2.24 - 2.69 27.93
Sweden 2.22 2.03 - 2.41 41.66
Switzerland 2.21 2 - 2.41 25.21
USA 1.79 1.59 - 1.98 20.85
Vietnam 0.94 0.77 - 1.12 10.38
Drink
Austria 0.9 0.75 - 1.05 11.31
Brazil 0.72 0.56 - 0.88 9.56
Canada 0.98 0.82 - 1.13 11.84
China 0.82 0.67 - 0.98 10.06
Denmark 0.69 0.53 - 0.85 8.27
Egypt 1.09 0.93 - 1.24 11.68
France 0.8 0.64 - 0.95 11.33
Germany 0.97 0.81 - 1.13 11.96
India 0.59 0.43 - 0.75 6.02
Indonesia -0.19 -0.46 - 0.09 -0.47
Italy 0.75 0.6 - 0.9 8.37
Lithuania 0.72 0.56 - 0.87 7.53
Morocco 0.84 0.69 - 1 10.53
Netherlands 0.74 0.58 - 0.9 7.84
Portugal 0.83 0.68 - 0.98 10.9
Romania 0.74 0.59 - 0.91 8.29
Spain 0.59 0.44 - 0.74 5.63
Sweden 0.62 0.48 - 0.78 7.04
Switzerland 0.88 0.73 - 1.03 9.94
USA 0.98 0.82 - 1.14 13.39
Vietnam 0.65 0.3 - 0.99 2.12
Play
Austria 0.86 0.54 - 1.18 3.97
Brazil 0.34 -0.07 - 0.73 -0.1
Canada 0.39 0.04 - 0.74 0.31
China 0.04 -0.38 - 0.45 -0.67
Denmark 0.67 0.31 - 1.02 2.12
Egypt 0.48 0.13 - 0.83 0.83
France 0.6 0.26 - 0.94 1.7
Germany 1 0.65 - 1.36 4.62
India -0.03 -0.38 - 0.33 -0.74
Indonesia 0.16 -0.19 - 0.5 -0.57
Italy 0.53 0.19 - 0.86 1.23
Lithuania 0.83 0.47 - 1.19 3.55
Morocco 0.19 -0.15 - 0.53 -0.51
Netherlands 1.22 0.85 - 1.59 5.3
Portugal 0.71 0.36 - 1.07 2.45
Romania 0.22 -0.2 - 0.64 -0.44
Spain 0.75 0.38 - 1.12 2.83
Sweden 1.38 1.02 - 1.75 7.02
Switzerland 0.65 0.31 - 1.01 2.15
USA 0.79 0.44 - 1.15 2.81
Vietnam 0.45 0.09 - 0.8 0.62
Gym
Austria 0.83 0.68 - 0.98 10.03
Brazil -0.66 -0.82 - -0.5 6.35
Canada 1.05 0.88 - 1.19 12.57
China 0.68 0.52 - 0.84 8.83
Denmark 1.07 0.91 - 1.22 12.48
Egypt 0.42 0.26 - 0.57 3.01
France 0.89 0.74 - 1.04 12.87
Germany 1.11 0.96 - 1.26 15.72
India 0.36 0.2 - 0.51 2.5
Indonesia -0.03 -0.18 - 0.12 -1.06
Italy 1.04 0.9 - 1.19 13.86
Lithuania 0.78 0.63 - 0.94 8.94
Morocco 0.37 0.21 - 0.53 3.12
Netherlands 1.18 1.03 - 1.34 16.82
Portugal 0.72 0.57 - 0.87 9.11
Romania 0.59 0.43 - 0.73 6.08
Spain 0.92 0.77 - 1.07 12.98
Sweden 1.37 1.22 - 1.51 18.27
Switzerland 1.08 0.93 - 1.22 13.43
USA 0.95 0.8 - 1.12 9.88
Vietnam 0.42 0.26 - 0.57 3.51
Plane
Austria 1.01 0.64 - 1.38 4.77
Brazil 0.7 0.33 - 1.06 2.31
Canada 1.1 0.74 - 1.47 5.09
China 0.54 0.19 - 0.88 1.28
Denmark 0.97 0.57 - 1.37 3.83
Egypt 1.04 0.7 - 1.41 5.14
France 0.76 0.38 - 1.14 2.48
Germany 1.09 0.71 - 1.49 4.91
India 0.69 0.34 - 1.05 2.42
Indonesia 0.51 0.12 - 0.88 0.82
Italy 0.88 0.5 - 1.28 3.06
Lithuania 1.3 0.94 - 1.67 7
Morocco 0.25 -0.17 - 0.68 -0.39
Netherlands 1 0.57 - 1.44 3.25
Portugal 0.62 0.28 - 0.99 1.81
Romania 0.59 0.2 - 0.96 1.21
Spain 0.73 0.38 - 1.09 2.49
Sweden 0.8 0.43 - 1.18 3.08
Switzerland 1.13 0.75 - 1.52 4.29
USA 1.22 0.83 - 1.6 5.2
Vietnam 0.43 0.08 - 0.79 0.51

Click on the tabs to see the model’s summary for each study

Show codes
mMrAB1 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>% 
                filter(scenario_group=="gain") %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_2 ) %>% 
                group_by(subject) %>% 
                mutate(
                  response = ifelse(
                    (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0), 1, 0
                  )
                ) %>% filter(row_number()==1) %>% ungroup(), 
              iter = 5000, refresh = 0, family="bernoulli", cores = 4)


mMrAB2 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>% 
                filter(scenario_group=="loss") %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_2 ) %>% 
                group_by(subject) %>% 
                mutate(
                  response = as.integer(response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0)
                  ) %>% 
                filter(row_number()==1) %>% ungroup(),
              iter = 5000, refresh = 0, family="bernoulli", cores = 4)
Plot posteriors
# re-run
post <- prepare_predictions(mMrAB1)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot1 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=1) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB1 <- post_plot1 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB1 <- post_plot1 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")



post <- prepare_predictions(mMrAB2)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot2 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=2) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB2 <- post_plot2 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB2 <- post_plot2 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "none")



cowplot::plot_grid(plMrAB1, plMrAB2, rel_widths = c(1, 0.8), nrow = 1)

Code
# re-run
post_plot1$log10_bf = NA
for( country in unique(post_plot1$Country) ){
  idx = post_plot1$Country==country
  beta <- post_plot1$theta[idx]
  posterior <- as.vector(unlist(beta))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bf <- bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
  post_plot1$log10_bf[idx] <- round(log10(as.numeric(bf)), 2)
}

table_unpooled <- post_plot1 %>% 
  group_by(Country) %>% mutate(mu=mean(theta)) %>% 
  filter(row_number()==1) %>% 
  select(Country, mu, lower, upper, log10_bf) %>% 
  ungroup() %>% 
  mutate(`CIs (95%)`=str_c(round(lower,2), round(upper,2), sep = ' - '),
         mu=round(mu,2)) %>% 
  rename(Estimate = mu) %>% 
  mutate(` ` = "") %>% 
  .[,c(7,1,2, 6,5)] 

empty <- function(x){ 
  if(x==''){
    return("MrAB1")
    } else {
      return("")
    } 
  }

table_unpooled <- rbind(apply(table_unpooled[1,], 2, empty), table_unpooled)

rmarkdown::paged_table(
  post_plot1 %>% 
    group_by(Country) %>% mutate(mu=mean(theta)) %>% 
    filter(row_number()==1) %>% 
    select(Country, mu, lower, upper) %>% 
    ungroup()
  )
Show codes
mGame <- brm(response ~ buyer * Country,
              data = data_Game %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_2 ),
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mGame)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "buyer" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Game", family="binomial", x=3) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGame <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mDrink <- brm(response ~ store * Country,
              data = data_Drink %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_2 ) %>% 
                # Remove really really extreme outliers
                filter(response<10000 & response>=0) %>% 
                mutate(response=response+1, logResp=log(response)) %>% 
                group_by(Country) %>%
                mutate(response=as.vector(scale(logResp))) %>% 
                ungroup(),
              iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mDrink)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "store" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]


post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Drink", family="gaussian", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})
 
postDrink <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>%   
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mJacket <- brm(response ~ price * Country,
               data = data_Jacket %>% 
                 # EXCLUSION: Full Exclusion
                 filter( !(Country %in% countries2remove) ) %>% 
                 filter( attention_check_grater_than_2 ),
               iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mJacket)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "price" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Jacket", family="binomial", x=4) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postJacket <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlay <- brm(response ~ loss * Country,
             data = data_Play %>% 
               # EXCLUSION: Full Exclusion
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_2 ) %>% 
               mutate(loss=factor(loss, levels = c("ticket", "cash"))),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlay)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "loss" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Play", family="binomial", x=5) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlay <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mGym <- brm(response ~ frame * Country,
            data = data_Gym %>% 
              # EXCLUSION: Full Exclusion
              filter( !(Country %in% countries2remove) ) %>% 
              filter( attention_check_grater_than_2 ) %>% 
              group_by(Country) %>%
                mutate(response=as.vector(scale(response))) %>% 
                ungroup(),
             iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mGym)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta" #
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "frame" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Gym", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGym <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlane <- brm(response ~ coupon * Country,
             data = data_Plane %>% 
               # EXCLUSION: Full Exclusion
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_2 ),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlane)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "coupon" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Plane", family="binomial", x=6) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlane <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Plot posteriors
# re-run
post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% # Recalculate
  mutate(family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

plotOR <- post %>% filter(family=="binomial") %>% 
  mutate(x=x-2) %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = post %>% filter(family=="binomial") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotER <- post %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotSMD <- post %>% filter(family=="gaussian") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")


cowplot::plot_grid(plotOR, plotER, plotSMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Code
# re-run
table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  flextable() %>% 
  set_caption(caption = "Table 3: Unpooled Analysis") %>% 
  theme_apa() %>% 
  width(width=c(0.8, 1,1,1.5, 1)) %>%
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/Unpooled Analysis (Partial).docx")

table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  kbl(caption="<b>Table 3 | </b> Unpooled Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 3 | Unpooled Analysis
Country Estimate CIs (95%) log₁₀(BF)
MrAB1
Austria 1.01 0.76 - 1.25 6.28
Brazil 0.71 0.43 - 1 2.94
Canada 1.43 1.19 - 1.67 6.04
China 1.67 1.43 - 1.88 15.61
Denmark 1.23 0.98 - 1.48 9.75
Egypt 1.06 0.82 - 1.31 7.08
France 1.02 0.74 - 1.26 6.67
Germany 1.8 1.55 - 2.02 15.21
India 1.76 1.54 - 1.97 19.23
Indonesia 1.95 1.76 - 2.15 17.04
Italy 1.32 1.12 - 1.53 11.11
Lithuania 1.73 1.51 - 1.95 12.95
Morocco 0.88 0.6 - 1.15 4.91
Netherlands 1.39 1.13 - 1.61 10.98
Portugal 1.53 1.31 - 1.76 12.62
Romania 1.89 1.66 - 2.12 16.28
Spain 1.77 1.56 - 1.98 16.29
Sweden 1.53 1.31 - 1.74 11.86
Switzerland 1.94 1.71 - 2.16 15.33
USA 1.44 1.2 - 1.67 9.21
Vietnam 1.46 1.22 - 1.69 13.24
MrAB2
Austria 2 1.79 - 2.22 17.54
Brazil 1.55 1.32 - 1.79 11.8
Canada 2.43 2.19 - 2.66 23.72
China 2.41 2.18 - 2.63 20.65
Denmark 1.86 1.64 - 2.08 16.47
Egypt 1.5 1.27 - 1.73 9.99
France 1.97 1.75 - 2.2 18.07
Germany 2.35 2.12 - 2.58 22.97
India 1.86 1.65 - 2.08 22.28
Indonesia 2.15 1.96 - 2.35 26.74
Italy 2.2 2 - 2.38 26.27
Lithuania 1.92 1.71 - 2.14 17.44
Morocco 1.64 1.4 - 1.89 12.69
Netherlands 2.23 2.01 - 2.47 19.35
Portugal 2.08 1.86 - 2.29 21.55
Romania 1.97 1.73 - 2.18 16.69
Spain 2.44 2.23 - 2.65 32.39
Sweden 2.46 2.25 - 2.68 29.18
Switzerland 2.26 2.04 - 2.49 20.79
USA 2.38 2.15 - 2.61 20.56
Vietnam 2.24 2.02 - 2.47 19.86
Game
Austria 2.11 1.93 - 2.29 23.77
Brazil 1.44 1.25 - 1.65 13.94
Canada 1.98 1.79 - 2.18 24.9
China 2.62 2.38 - 2.86 25.51
Denmark 2.07 1.88 - 2.25 20.99
Egypt 1.53 1.34 - 1.73 16.75
France 2.08 1.89 - 2.26 24.31
Germany 2.28 2.08 - 2.47 24.27
India 1.42 1.25 - 1.62 17.83
Indonesia 0.75 0.6 - 0.89 8
Italy 2.02 1.85 - 2.18 23.99
Lithuania 2.1 1.9 - 2.31 24.6
Morocco 1.62 1.44 - 1.82 21.57
Netherlands 2.28 2.09 - 2.49 28.13
Portugal 2.1 1.93 - 2.28 29.98
Romania 1.56 1.39 - 1.73 21.48
Spain 2.54 2.34 - 2.75 31.56
Sweden 2.15 1.98 - 2.33 29.73
Switzerland 2.21 2.03 - 2.4 39.48
USA 1.76 1.58 - 1.94 25.17
Vietnam 0.97 0.8 - 1.13 13.04
Drink
Austria 0.86 0.73 - 1.01 11.39
Brazil 0.71 0.56 - 0.85 9.4
Canada 0.99 0.84 - 1.14 10.47
China 0.84 0.69 - 0.97 11.49
Denmark 0.68 0.53 - 0.83 8.8
Egypt 1.08 0.94 - 1.22 13.33
France 0.79 0.64 - 0.94 10.88
Germany 0.93 0.77 - 1.07 13.69
India 0.53 0.38 - 0.67 6.49
Indonesia -0.21 -0.43 - 0.01 -0.21
Italy 0.75 0.63 - 0.87 12.98
Lithuania 0.73 0.59 - 0.87 9.11
Morocco 0.75 0.6 - 0.9 9.17
Netherlands 0.72 0.58 - 0.87 9.41
Portugal 0.81 0.66 - 0.94 14.01
Romania 0.75 0.61 - 0.9 8.19
Spain 0.6 0.47 - 0.74 7.56
Sweden 0.65 0.51 - 0.78 7.46
Switzerland 0.88 0.73 - 1.02 13.07
USA 0.92 0.77 - 1.07 14.54
Vietnam 0.67 0.33 - 0.99 2.07
Play
Austria 0.88 0.57 - 1.2 4.81
Brazil 0.33 -0.05 - 0.71 -0.08
Canada 0.46 0.12 - 0.8 0.84
China 0.05 -0.32 - 0.42 -0.72
Denmark 0.63 0.3 - 0.95 2.16
Egypt 0.39 0.09 - 0.7 0.53
France 0.58 0.25 - 0.92 1.61
Germany 0.96 0.63 - 1.31 5
India 0.05 -0.26 - 0.36 -0.77
Indonesia 0.07 -0.21 - 0.35 -0.79
Italy 0.46 0.19 - 0.74 1.46
Lithuania 0.75 0.44 - 1.07 2.94
Morocco 0.2 -0.12 - 0.53 -0.49
Netherlands 1.22 0.89 - 1.58 5.89
Portugal 0.64 0.32 - 0.96 2.24
Romania 0.32 -0.1 - 0.7 -0.18
Spain 0.7 0.36 - 1.02 2.56
Sweden 1.36 1.02 - 1.71 6.82
Switzerland 0.64 0.31 - 0.96 2.08
USA 0.73 0.39 - 1.06 2.42
Vietnam 0.4 0.07 - 0.72 0.45
Gym
Austria 0.77 0.63 - 0.91 11.74
Brazil -0.63 -0.78 - -0.48 7.26
Canada 1.06 0.91 - 1.2 13.73
China 0.72 0.59 - 0.87 11.01
Denmark 1.01 0.87 - 1.16 17.17
Egypt 0.46 0.32 - 0.6 6.26
France 0.87 0.72 - 1.02 13.73
Germany 1.07 0.92 - 1.21 14.35
India 0.31 0.17 - 0.44 2.54
Indonesia -0.01 -0.14 - 0.11 -1.19
Italy 0.93 0.81 - 1.06 16.89
Lithuania 0.71 0.57 - 0.85 10.02
Morocco 0.35 0.2 - 0.5 2.77
Netherlands 1.09 0.95 - 1.24 14.1
Portugal 0.68 0.53 - 0.81 9
Romania 0.59 0.45 - 0.74 7.88
Spain 0.88 0.74 - 1.01 11.29
Sweden 1.35 1.21 - 1.49 24.28
Switzerland 1.06 0.91 - 1.2 15.11
USA 0.92 0.78 - 1.07 12.46
Vietnam 0.41 0.26 - 0.55 3.91
Plane
Austria 0.99 0.61 - 1.35 3.77
Brazil 0.62 0.28 - 0.94 1.92
Canada 1.04 0.69 - 1.39 4.31
China 0.53 0.21 - 0.83 1.61
Denmark 0.97 0.61 - 1.36 3.8
Egypt 0.9 0.58 - 1.2 4.14
France 0.74 0.34 - 1.11 2.11
Germany 1 0.63 - 1.37 3.84
India 0.55 0.23 - 0.85 1.72
Indonesia 0.44 0.14 - 0.74 0.99
Italy 0.72 0.4 - 1.02 3.11
Lithuania 1.19 0.86 - 1.51 6.24
Morocco 0.19 -0.2 - 0.61 -0.5
Netherlands 0.95 0.52 - 1.35 3.45
Portugal 0.57 0.26 - 0.9 1.69
Romania 0.6 0.23 - 0.95 1.6
Spain 0.66 0.34 - 0.97 2.75
Sweden 0.75 0.42 - 1.1 2.93
Switzerland 1.04 0.68 - 1.4 4.5
USA 1.13 0.77 - 1.49 5.03
Vietnam 0.41 0.06 - 0.72 0.51

Click on the tabs to see the model’s summary for each study

Show codes
mMrAB1 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>%
                filter(scenario_group=="gain") %>% 
                # EXCLUSION: Full Exclusion
                filter(native_language_is_country_language | Country!=Residence) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>% 
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                group_by(subject) %>% 
                mutate(
                  response = ifelse(
                    (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0), 1, 0
                  )
                ) %>% filter(row_number()==1) %>% ungroup(), 
              iter = 5000, refresh = 0, family="bernoulli")


mMrAB2 <- brm(response ~ 0 + Country,
              data = data_MrAB %>% 
                filter(scenario_group=="loss") %>% 
                # EXCLUSION: Full Exclusion
                filter(native_language_is_country_language | Country!=Residence) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                group_by(subject) %>% 
                mutate(
                  response = as.integer(response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0)
                  ) %>% 
                filter(row_number()==1) %>% ungroup(),
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
# re-run
post <- prepare_predictions(mMrAB1)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot1 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=1) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB1 <- post_plot1 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB1 <- post_plot1 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")



post <- prepare_predictions(mMrAB2)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot2 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=2) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB2 <- post_plot2 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB2 <- post_plot2 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "none")



cowplot::plot_grid(plMrAB1, plMrAB2, rel_widths = c(1, 0.8), nrow = 1)

Code
# re-run
post_plot1$log10_bf = NA
for( country in unique(post_plot1$Country) ){
  idx = post_plot1$Country==country
  beta <- post_plot1$theta[idx]
  posterior <- as.vector(unlist(beta))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bf <- bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
  post_plot1$log10_bf[idx] <- round(log10(as.numeric(bf)), 2)
}

table_unpooled <- post_plot1 %>% 
  group_by(Country) %>% mutate(mu=mean(theta)) %>% 
  filter(row_number()==1) %>% 
  select(Country, mu, lower, upper, log10_bf) %>% 
  ungroup() %>% 
  mutate(`CIs (95%)`=str_c(round(lower,2), round(upper,2), sep = ' - '),
         mu=round(mu,2)) %>% 
  rename(Estimate = mu) %>% 
  mutate(` ` = "") %>% 
  .[,c(7,1,2, 6,5)] 

empty <- function(x){ 
  if(x==''){
    return("MrAB1")
    } else {
      return("")
    } 
  }

table_unpooled <- rbind(apply(table_unpooled[1,], 2, empty), table_unpooled)

rmarkdown::paged_table(
  post_plot1 %>% 
    group_by(Country) %>% mutate(mu=mean(theta)) %>% 
    filter(row_number()==1) %>% 
    select(Country, mu, lower, upper) %>% 
    ungroup()
  )
Show codes
mGame <- brm(response ~ buyer * Country,
              data = data_Game %>% 
                # EXCLUSION: Full Exclusion
                filter(native_language_is_country_language | Country!=Residence) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ),
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mGame)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "buyer" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Game", family="binomial", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGame <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mDrink <- brm(response ~ store * Country,
              data = data_Drink %>% 
                # EXCLUSION: Full Exclusion
                filter( native_language_is_country_language | Country!=Residence ) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                # Remove really really extreme outliers
                filter(response<10000 & response>=0) %>% 
                mutate(response=response+1, logResp=log(response)) %>% 
                group_by(Country) %>%
                mutate(response=as.vector(scale(logResp))) %>% 
                ungroup(),
              iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mDrink)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "store" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]


post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Drink", family="gaussian", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})
 
postDrink <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>%   
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mJacket <- brm(response ~ price * Country,
               data = data_Jacket %>% 
                 # EXCLUSION: Full Exclusion
                filter( native_language_is_country_language | Country!= Residence ) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
                 filter( !(Country %in% countries2remove) ) %>% 
                 filter( attention_check_grater_than_3 ),
               iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mJacket)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "price" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Jacket", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postJacket <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlay <- brm(response ~ loss * Country,
             data = data_Play %>% 
               # EXCLUSION: Full Exclusion
                filter( native_language_is_country_language | Country!= Residence ) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_3 ) %>% 
               mutate(loss=factor(loss, levels = c("ticket", "cash"))),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlay)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "loss" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Play", family="binomial", x=3) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlay <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mGym <- brm(response ~ frame * Country,
            data = data_Gym %>% 
              # EXCLUSION: Full Exclusion
                filter( native_language_is_country_language | Country!= Residence ) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
              filter( !(Country %in% countries2remove) ) %>% 
              filter( attention_check_grater_than_3 ) %>% 
              group_by(Country) %>%
                mutate(response=as.vector(scale(response))) %>% 
                ungroup(),
             iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mGym)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta" #
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "frame" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Gym", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGym <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlane <- brm(response ~ coupon * Country,
             data = data_Plane %>% 
               # EXCLUSION: Full Exclusion
                filter( native_language_is_country_language | Country!=Residence ) %>% 
                filter( !loi_lower_than_loiX0_33 ) %>%
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_3 ),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlane)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "coupon" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Plane", family="binomial", x=4) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlane <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Plot posteriors
# re-run1
post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% # Recalculate
  mutate(family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

plotOR <- post %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = post %>% filter(family=="binomial") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotER <- post %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotSMD <- post %>% filter(family=="gaussian") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")


cowplot::plot_grid(plotOR, plotER, plotSMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Code
# re-run
table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  flextable() %>% 
  set_caption(caption = "Table 3: Unpooled Analysis") %>% 
  theme_apa() %>% 
  width(width=c(0.8, 1,1,1.5,1)) %>%
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/Unpooled Analysis (Full).docx")

table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  kbl(caption="<b>Table 3 | </b> Unpooled Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 3 | Unpooled Analysis
Country Estimate CIs (95%) log₁₀(BF)
MrAB1
Austria 1.02 0.72 - 1.31 6.05
Brazil 0.72 0.41 - 1.04 2.49
Canada 1.45 1.16 - 1.73 9.07
China 1.62 1.37 - 1.87 13.2
Denmark 1.26 0.99 - 1.55 6.87
Egypt 0.98 0.68 - 1.26 4.55
France 1.04 0.75 - 1.34 6.18
Germany 1.81 1.56 - 2.07 17.21
India 1.87 1.6 - 2.15 13.97
Indonesia 2.06 1.82 - 2.31 16.72
Italy 1.4 1.16 - 1.65 10.5
Lithuania 1.76 1.5 - 2 13.88
Morocco 0.95 0.64 - 1.26 4.31
Netherlands 1.48 1.2 - 1.76 9.05
Portugal 1.58 1.34 - 1.84 10.92
Romania 1.91 1.68 - 2.16 15.73
Spain 1.88 1.63 - 2.14 16.01
Sweden 1.47 1.21 - 1.71 12.67
Switzerland 1.97 1.72 - 2.21 20.17
USA 1.48 1.2 - 1.74 10.6
Vietnam 1.5 1.25 - 1.76 11.86
MrAB2
Austria 1.98 1.71 - 2.23 18.18
Brazil 1.61 1.35 - 1.87 11.62
Canada 2.6 2.3 - 2.88 23.96
China 2.39 2.14 - 2.64 21.66
Denmark 1.83 1.57 - 2.07 12.57
Egypt 1.56 1.29 - 1.82 9.3
France 1.86 1.61 - 2.12 12.83
Germany 2.38 2.12 - 2.63 20.03
India 1.96 1.69 - 2.26 13.58
Indonesia 2.29 2.03 - 2.53 18.81
Italy 2.38 2.14 - 2.61 22.34
Lithuania 2.03 1.78 - 2.28 16.31
Morocco 1.45 1.16 - 1.75 10.28
Netherlands 2.37 2.1 - 2.66 16.24
Portugal 2.21 1.97 - 2.46 20.22
Romania 1.97 1.71 - 2.2 15.1
Spain 2.54 2.29 - 2.79 23.04
Sweden 2.52 2.27 - 2.76 24.02
Switzerland 2.33 2.09 - 2.57 19.22
USA 2.37 2.09 - 2.62 19.54
Vietnam 2.27 2.03 - 2.53 18.4
Game
Austria 2.04 1.84 - 2.24 19.32
Brazil 1.46 1.25 - 1.67 13.74
Canada 1.99 1.76 - 2.22 16.58
China 2.74 2.46 - 3.02 29.02
Denmark 2.11 1.91 - 2.31 22.35
Egypt 1.51 1.3 - 1.73 15.01
France 2 1.79 - 2.21 20.02
Germany 2.33 2.12 - 2.55 27
India 1.41 1.17 - 1.64 11.96
Indonesia 0.83 0.65 - 1.02 7.61
Italy 2.23 2.03 - 2.43 28.36
Lithuania 2.05 1.81 - 2.27 17.85
Morocco 1.39 1.18 - 1.63 11.69
Netherlands 2.31 2.08 - 2.56 27.61
Portugal 2.09 1.9 - 2.29 19.67
Romania 1.6 1.41 - 1.79 20.77
Spain 2.49 2.26 - 2.73 23.87
Sweden 2.26 2.07 - 2.47 25.85
Switzerland 2.22 2.02 - 2.42 29.2
USA 1.76 1.57 - 1.96 18.12
Vietnam 0.95 0.78 - 1.14 9.17
Drink
Austria 0.85 0.68 - 1.02 9.51
Brazil 0.74 0.58 - 0.9 9
Canada 1.01 0.83 - 1.19 10.96
China 0.83 0.67 - 0.99 12.49
Denmark 0.68 0.51 - 0.84 7.34
Egypt 1.05 0.89 - 1.22 14.24
France 0.79 0.62 - 0.96 8.73
Germany 1.02 0.86 - 1.18 11.2
India 0.6 0.41 - 0.77 5.09
Indonesia -0.19 -0.47 - 0.09 -0.47
Italy 0.74 0.59 - 0.9 8.61
Lithuania 0.71 0.54 - 0.87 7.46
Morocco 0.79 0.61 - 0.96 7.75
Netherlands 0.7 0.53 - 0.88 6.36
Portugal 0.83 0.67 - 0.99 9.5
Romania 0.74 0.58 - 0.9 9.69
Spain 0.65 0.49 - 0.8 6.14
Sweden 0.67 0.52 - 0.83 7.39
Switzerland 0.87 0.72 - 1.04 8.47
USA 0.99 0.83 - 1.16 9.49
Vietnam 0.65 0.31 - 0.99 1.95
Play
Austria 1.09 0.72 - 1.48 4.6
Brazil 0.34 -0.06 - 0.76 -0.1
Canada 0.43 0.02 - 0.81 0.32
China 0.02 -0.38 - 0.46 -0.67
Denmark 0.69 0.32 - 1.06 2.15
Egypt 0.48 0.12 - 0.85 0.72
France 0.43 0.07 - 0.82 0.44
Germany 0.97 0.6 - 1.33 3.95
India 0.04 -0.36 - 0.44 -0.68
Indonesia 0.15 -0.19 - 0.51 -0.59
Italy 0.51 0.17 - 0.85 1.15
Lithuania 0.85 0.45 - 1.22 2.9
Morocco 0.3 -0.09 - 0.69 -0.2
Netherlands 1.31 0.9 - 1.72 5.03
Portugal 0.71 0.35 - 1.08 2.52
Romania 0.21 -0.21 - 0.66 -0.46
Spain 0.7 0.3 - 1.07 1.84
Sweden 1.36 0.96 - 1.76 5.23
Switzerland 0.67 0.32 - 1.03 1.95
USA 0.84 0.47 - 1.21 3.12
Vietnam 0.45 0.09 - 0.8 0.58
Gym
Austria 0.87 0.7 - 1.03 11.58
Brazil -0.66 -0.82 - -0.5 6.69
Canada 1.11 0.92 - 1.28 11.63
China 0.7 0.55 - 0.86 8.57
Denmark 1.05 0.89 - 1.21 11.43
Egypt 0.42 0.26 - 0.58 3.69
France 0.88 0.72 - 1.05 9.32
Germany 1.15 0.99 - 1.31 17.04
India 0.36 0.19 - 0.55 2.17
Indonesia -0.04 -0.2 - 0.11 -1.02
Italy 1.04 0.9 - 1.19 14.2
Lithuania 0.75 0.59 - 0.9 10.45
Morocco 0.46 0.28 - 0.63 3.69
Netherlands 1.13 0.96 - 1.31 14.41
Portugal 0.75 0.6 - 0.9 9.67
Romania 0.58 0.43 - 0.74 6.18
Spain 0.92 0.76 - 1.08 9.51
Sweden 1.39 1.24 - 1.54 19.5
Switzerland 1.06 0.91 - 1.22 15.32
USA 0.98 0.82 - 1.15 11.28
Vietnam 0.42 0.26 - 0.58 3.97
Plane
Austria 1.14 0.71 - 1.59 5.03
Brazil 0.73 0.35 - 1.09 2.33
Canada 1.12 0.68 - 1.54 3.75
China 0.54 0.21 - 0.9 1.2
Denmark 0.96 0.55 - 1.37 3.16
Egypt 0.98 0.63 - 1.36 4.18
France 0.79 0.35 - 1.21 2.13
Germany 1.09 0.69 - 1.51 3.75
India 0.74 0.34 - 1.15 1.87
Indonesia 0.48 0.08 - 0.86 0.55
Italy 0.87 0.47 - 1.26 3.08
Lithuania 1.31 0.93 - 1.68 5.05
Morocco 0.2 -0.27 - 0.66 -0.48
Netherlands 0.87 0.39 - 1.37 1.84
Portugal 0.62 0.27 - 0.98 1.63
Romania 0.57 0.18 - 0.96 1.08
Spain 0.73 0.35 - 1.12 2.2
Sweden 0.84 0.45 - 1.25 2.7
Switzerland 1.12 0.75 - 1.52 4.94
USA 1.29 0.9 - 1.69 5.37
Vietnam 0.41 0.05 - 0.77 0.37

Click on the tabs to see the model’s summary for each study

Show codes
mMrAB1 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>% 
                filter(scenario_group=="gain") %>% 
                # EXCLUSION: Exploratory Exclusion
                filter( !loi_lower_than_loiX0_33 ) %>% 
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                group_by(subject) %>% 
                mutate(
                  response = ifelse(
                    (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0), 1, 0
                  )
                ) %>% filter(row_number()==1) %>% ungroup(), 
              iter = 5000, refresh = 0, family="bernoulli")


mMrAB2 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>%
                filter(scenario_group=="loss") %>% 
                # EXCLUSION: Exploratory Exclusion
                filter( !loi_lower_than_loiX0_33 ) %>% 
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>%   
                group_by(subject) %>% 
                mutate(
                  response = ifelse(
                    (response[scenario=="loss-loss VS loss"]==1) && (response[scenario=="loss-gain VS loss"]==0), 1, 0
                  )
                ) %>% 
                filter(row_number()==1) %>% ungroup(),
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
# re-run
post <- prepare_predictions(mMrAB1)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot1 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=1) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB1 <- post_plot1 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB1 <- post_plot1 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")



post <- prepare_predictions(mMrAB2)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot2 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=2) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB2 <- post_plot2 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB2 <- post_plot2 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "none")



cowplot::plot_grid(plMrAB1, plMrAB2, rel_widths = c(1, 0.8), nrow = 1)

Code
# re-run
post_plot1$log10_bf = NA
for( country in unique(post_plot1$Country) ){
  idx = post_plot1$Country==country
  beta <- post_plot1$theta[idx]
  posterior <- as.vector(unlist(beta))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bf <- bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
  post_plot1$log10_bf[idx] <- round(log10(as.numeric(bf)), 2)
}

table_unpooled <- post_plot1 %>% 
  group_by(Country) %>% mutate(mu=mean(theta)) %>% 
  filter(row_number()==1) %>% 
  select(Country, mu, lower, upper, log10_bf) %>% 
  ungroup() %>% 
  mutate(`CIs (95%)`=str_c(round(lower,2), round(upper,2), sep = ' - '),
         mu=round(mu,2)) %>% 
  rename(Estimate = mu) %>% 
  mutate(` ` = "") %>% 
  .[,c(7,1,2, 6,5)] 


empty <- function(x){ 
  if(x==''){
    return("MrAB1")
    } else {
      return("")
    } 
  }

table_unpooled <- rbind(apply(table_unpooled[1,], 2, empty), table_unpooled)

rmarkdown::paged_table(
  post_plot1 %>% 
    group_by(Country) %>% mutate(mu=mean(theta)) %>% 
    filter(row_number()==1) %>% 
    select(Country, mu, lower, upper) %>% 
    ungroup()
  )
Show codes
mGame <- brm(response ~ buyer * Country,
             data = data_Game %>% 
               # EXCLUSION: Exploratory Exclusion
               filter( !loi_lower_than_loiX0_33 ) %>% 
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_3 ),
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mGame)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "buyer" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Game", family="binomial", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGame <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mDrink <- brm(response ~ store * Country,
              data = data_Drink %>% 
                # EXCLUSION: Full Exclusion
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ) %>% 
                # Remove really really extreme outliers
                filter(response<10000 & response>=0) %>% 
                mutate(response=response+1, logResp=log(response)) %>% 
                group_by(Country) %>%
                mutate(response=as.vector(scale(logResp))) %>% 
                ungroup(),
              iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mDrink)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "store" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]


post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Drink", family="gaussian", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})
 
postDrink <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>%   
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mJacket <- brm(response ~ price * Country,
               data = data_Jacket %>% 
                 # EXCLUSION: Exploratory Exclusion
                filter( !loi_lower_than_loiX0_33 ) %>% 
                filter( !(Country %in% countries2remove) ) %>% 
                filter( attention_check_grater_than_3 ),
               iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mJacket)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "price" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Jacket", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postJacket <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlay <- brm(response ~ loss * Country,
             data = data_Play %>% 
               # EXCLUSION: Exploratory Exclusion
               filter( !loi_lower_than_loiX0_33 ) %>% 
               filter( !(Country %in% countries2remove) ) %>% 
               filter( attention_check_grater_than_3 ) %>% 
               mutate(loss=factor(loss, levels = c("ticket", "cash"))),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlay)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "loss" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Play", family="binomial", x=3) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlay <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mGym <- brm(response ~ frame * Country,
            data = data_Gym %>% 
              # EXCLUSION: Exploratory Exclusion
              filter( !loi_lower_than_loiX0_33 ) %>% 
              filter( !(Country %in% countries2remove) ) %>% 
              filter( attention_check_grater_than_3 ) %>%  
              group_by(Country) %>%
                mutate(response=as.vector(scale(response))) %>% 
                ungroup(),
             iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mGym)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta" #
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "frame" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Gym", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGym <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlane <- brm(response ~ coupon * Country,
             data = data_Plane %>% 
               # EXCLUSION: Exploratory Exclusion
              filter( !loi_lower_than_loiX0_33 ) %>% 
              filter( !(Country %in% countries2remove) ) %>% 
              filter( attention_check_grater_than_3 ),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlane)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "coupon" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Plane", family="binomial", x=4) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlane <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Plot posteriors
# re-run1
post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% # Recalculate
  mutate(family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

plotOR <- post %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = post %>% filter(family=="binomial") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotER <- post %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotSMD <- post %>% filter(family=="gaussian") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")


cowplot::plot_grid(plotOR, plotER, plotSMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Code
# re-run
table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  flextable() %>% 
  set_caption(caption = "Table 3: Unpooled Analysis") %>% 
  theme_apa() %>% 
  width(width=c(0.8, 1,1,1.5,1)) %>%
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/Unpooled Analysis (Exploratory).docx")

table_unpooled %>% 
  kbl(caption="<b>Table 3 | </b> Unpooled Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 3 | Unpooled Analysis
Country Estimate CIs (95%) log10_bf
MrAB1
Austria 1.02 0.76 - 1.31 4.54
Brazil 0.75 0.45 - 1.04 2.76
Canada 1.42 1.17 - 1.69 10.69
China 1.63 1.38 - 1.89 11.93
Denmark 1.26 0.98 - 1.51 7.12
Egypt 0.98 0.7 - 1.27 5.05
France 1.02 0.75 - 1.29 6.05
Germany 1.87 1.62 - 2.11 14.94
India 1.81 1.56 - 2.05 15.78
Indonesia 2.03 1.77 - 2.26 17.06
Italy 1.41 1.15 - 1.63 15
Lithuania 1.76 1.52 - 2.01 18.4
Morocco 1.01 0.71 - 1.3 5.06
Netherlands 1.43 1.18 - 1.69 11.96
Portugal 1.57 1.32 - 1.81 13.8
Romania 1.93 1.69 - 2.17 18.64
Spain 1.87 1.63 - 2.09 22.01
Sweden 1.52 1.3 - 1.76 14.4
Switzerland 1.96 1.73 - 2.2 18.57
USA 1.47 1.22 - 1.74 11.34
Vietnam 1.49 1.24 - 1.76 11.46
MrAB2
Austria 2 1.76 - 2.23 15.75
Brazil 1.6 1.36 - 1.87 9.25
Canada 2.5 2.26 - 2.74 28.16
China 2.39 2.14 - 2.63 21.79
Denmark 1.86 1.62 - 2.1 16.11
Egypt 1.57 1.31 - 1.83 11.55
France 1.95 1.69 - 2.17 18.57
Germany 2.35 2.11 - 2.6 21.67
India 1.91 1.66 - 2.15 18.25
Indonesia 2.29 2.05 - 2.53 19.54
Italy 2.39 2.16 - 2.61 32.07
Lithuania 2 1.77 - 2.24 18.35
Morocco 1.46 1.2 - 1.73 9.49
Netherlands 2.28 2.03 - 2.53 17.99
Portugal 2.2 1.98 - 2.45 16.83
Romania 1.96 1.71 - 2.19 14.79
Spain 2.48 2.25 - 2.72 24.8
Sweden 2.49 2.26 - 2.72 25.47
Switzerland 2.34 2.1 - 2.58 24.09
USA 2.37 2.12 - 2.62 20.4
Vietnam 2.26 2.01 - 2.51 20.81
Game
Austria 1.99 1.8 - 2.19 23.79
Brazil 1.46 1.25 - 1.67 14.16
Canada 2.05 1.85 - 2.25 22.71
China 2.75 2.47 - 3.03 24.2
Denmark 2.08 1.87 - 2.27 24.18
Egypt 1.51 1.28 - 1.72 16.2
France 2.08 1.89 - 2.28 25.66
Germany 2.37 2.16 - 2.57 25.65
India 1.41 1.21 - 1.64 13.16
Indonesia 0.83 0.65 - 1.01 8.23
Italy 2.22 2.02 - 2.43 24.18
Lithuania 2.1 1.88 - 2.33 19.94
Morocco 1.38 1.18 - 1.59 13.55
Netherlands 2.32 2.11 - 2.53 29.42
Portugal 2.09 1.9 - 2.29 20.56
Romania 1.59 1.41 - 1.78 18.63
Spain 2.45 2.23 - 2.67 21.5
Sweden 2.22 2.03 - 2.4 29.38
Switzerland 2.21 2.02 - 2.42 21.58
USA 1.81 1.61 - 2 18.89
Vietnam 0.95 0.77 - 1.13 12.27
Drink
Austria 0.91 0.76 - 1.06 10.77
Brazil 0.72 0.56 - 0.88 7.56
Canada 0.98 0.82 - 1.14 14.34
China 0.82 0.67 - 0.98 9.39
Denmark 0.69 0.53 - 0.85 6.87
Egypt 1.09 0.93 - 1.24 16.96
France 0.8 0.64 - 0.95 9.54
Germany 0.97 0.82 - 1.13 11.28
India 0.59 0.43 - 0.75 7.81
Indonesia -0.19 -0.46 - 0.08 -0.47
Italy 0.74 0.6 - 0.9 7.94
Lithuania 0.72 0.57 - 0.88 7.92
Morocco 0.84 0.69 - 1.01 9.32
Netherlands 0.74 0.58 - 0.9 7.9
Portugal 0.83 0.67 - 0.98 9.78
Romania 0.74 0.59 - 0.9 10.31
Spain 0.59 0.45 - 0.75 6.38
Sweden 0.62 0.48 - 0.77 7.07
Switzerland 0.88 0.73 - 1.03 9.33
USA 0.98 0.83 - 1.15 12.35
Vietnam 0.65 0.32 - 0.99 1.99
Play
Austria 0.96 0.59 - 1.31 3.5
Brazil 0.33 -0.07 - 0.73 -0.12
Canada 0.41 0.06 - 0.76 0.43
China 0.02 -0.39 - 0.45 -0.66
Denmark 0.66 0.3 - 1.03 1.82
Egypt 0.5 0.15 - 0.87 0.91
France 0.6 0.24 - 0.92 1.54
Germany 1.01 0.63 - 1.36 5.03
India -0.02 -0.37 - 0.34 -0.74
Indonesia 0.16 -0.19 - 0.5 -0.59
Italy 0.52 0.18 - 0.85 1.14
Lithuania 0.82 0.46 - 1.2 2.31
Morocco 0.21 -0.14 - 0.58 -0.44
Netherlands 1.2 0.82 - 1.58 5.27
Portugal 0.71 0.37 - 1.07 2.35
Romania 0.21 -0.21 - 0.64 -0.47
Spain 0.75 0.37 - 1.12 2.11
Sweden 1.38 1.01 - 1.75 6.27
Switzerland 0.65 0.32 - 1.01 2.18
USA 0.81 0.46 - 1.17 2.94
Vietnam 0.45 0.08 - 0.8 0.55
Gym
Austria 0.86 0.71 - 1.02 11.45
Brazil -0.66 -0.82 - -0.51 7.26
Canada 1.05 0.9 - 1.21 14.15
China 0.7 0.54 - 0.85 7.35
Denmark 1.07 0.91 - 1.22 15.09
Egypt 0.43 0.27 - 0.59 3.67
France 0.89 0.74 - 1.04 10.38
Germany 1.13 0.98 - 1.28 15.17
India 0.37 0.2 - 0.52 2.61
Indonesia -0.03 -0.19 - 0.12 -1.06
Italy 1.04 0.9 - 1.19 13.31
Lithuania 0.75 0.59 - 0.9 8.42
Morocco 0.42 0.26 - 0.59 2.98
Netherlands 1.18 1.02 - 1.33 13.12
Portugal 0.72 0.57 - 0.87 8.24
Romania 0.59 0.44 - 0.74 6.25
Spain 0.93 0.78 - 1.07 12.39
Sweden 1.37 1.23 - 1.51 25.35
Switzerland 1.08 0.93 - 1.24 17.05
USA 0.96 0.8 - 1.11 10.41
Vietnam 0.42 0.27 - 0.58 3.63
Plane
Austria 1.12 0.71 - 1.55 4.27
Brazil 0.71 0.34 - 1.08 2.07
Canada 1.08 0.7 - 1.44 5.13
China 0.54 0.2 - 0.9 1.19
Denmark 0.97 0.56 - 1.36 3.38
Egypt 0.98 0.6 - 1.34 3.76
France 0.75 0.38 - 1.16 2.29
Germany 1.1 0.71 - 1.49 4.12
India 0.69 0.32 - 1.04 2.08
Indonesia 0.5 0.12 - 0.9 0.72
Italy 0.88 0.5 - 1.29 2.7
Lithuania 1.3 0.92 - 1.66 5.77
Morocco 0.25 -0.17 - 0.72 -0.37
Netherlands 1.02 0.56 - 1.45 3.65
Portugal 0.62 0.27 - 0.99 1.67
Romania 0.59 0.19 - 0.95 1.28
Spain 0.73 0.35 - 1.09 2.48
Sweden 0.8 0.42 - 1.18 3.59
Switzerland 1.13 0.73 - 1.5 4.46
USA 1.22 0.83 - 1.62 5.11
Vietnam 0.41 0.06 - 0.76 0.39

Click on the tabs to see the model’s summary for each study

Show codes
mMrAB1 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>% 
                filter(scenario_group=="gain") %>% 
                group_by(subject) %>% 
                mutate(
                  response = ifelse(
                    (response[scenario=="gain-gain VS gain"]==1) && (response[scenario=="gain-loss VS gain"]==0), 1, 0
                  )
                ) %>% filter(row_number()==1) %>% ungroup(), 
              iter = 5000, refresh = 0, family="bernoulli")


mMrAB2 <- brm(response ~ 0 + Country,
              prior = prior_string( str_c("normal(",logit_h0,",2.5)"), class = "b"),
              data = data_MrAB %>%
                filter(scenario_group=="loss") %>% 
                group_by(subject) %>% 
                mutate(
                  response = as.integer(response[scenario=="loss-loss VS loss"]==1 && response[scenario=="loss-gain VS loss"]==0)
                  ) %>% 
                filter(row_number()==1) %>% ungroup(),
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
# re-run
post <- prepare_predictions(mMrAB1)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot1 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=1) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB1 <- post_plot1 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB1 <- post_plot1 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")



post <- prepare_predictions(mMrAB2)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post) <- str_remove( names(post), "b_Country" )
all_countries <- names(post)

post_plot2 <- map_dfr(all_countries, function(country){
    theta <- post[,country] - logit_h0
    
    data.frame(theta, Country=country, study="MrAB", family="binomial1", x=2) %>% 
      mutate(lower = HDInterval::hdi( theta )["lower"],
             upper = HDInterval::hdi( theta )["upper"],
             credible = ifelse(lower<0, "no", "yes"))
})

postMrAB2 <- post_plot2 %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

plMrAB2 <- post_plot2 %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x="Posterior Evidence Ratio", y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_blank(),
        axis.line.y = element_blank(),
        axis.ticks.y = element_blank(),
        legend.position = "none")



cowplot::plot_grid(plMrAB1, plMrAB2, rel_widths = c(1, 0.8), nrow = 1)

Code
# re-run
post_plot1$log10_bf = NA
for( country in unique(post_plot1$Country) ){
  idx = post_plot1$Country==country
  beta <- post_plot1$theta[idx]
  posterior <- as.vector(unlist(beta))
  prior <- distribution_normal(length(posterior),mean=0,sd=1)
  bf <- bayesfactor_parameters(posterior,prior,direction="two-sided",null=0)
  post_plot1$log10_bf[idx] <- round(log10(as.numeric(bf)), 2)
}

table_unpooled <- post_plot1 %>% 
  group_by(Country) %>% mutate(mu=mean(theta)) %>% 
  filter(row_number()==1) %>% 
  select(Country, mu, lower, upper, log10_bf) %>% 
  ungroup() %>% 
  mutate(`CIs (95%)`=str_c(round(lower,2), round(upper,2), sep = ' - '),
         mu=round(mu,2)) %>% 
  rename(Estimate = mu) %>% 
  mutate(` ` = "") %>% 
  .[,c(7,1,2, 6,5)] 

empty <- function(x){ 
  if(x==''){
    return("MrAB1")
    } else {
      return("")
    } 
  }

table_unpooled <- rbind(apply(table_unpooled[1,], 2, empty), table_unpooled)

rmarkdown::paged_table(
  post_plot1 %>% 
    group_by(Country) %>% mutate(mu=mean(theta)) %>% 
    filter(row_number()==1) %>% 
    select(Country, mu, lower, upper) %>% 
    ungroup()
  )
Show codes
mGame <- brm(response ~ buyer * Country,
              data = data_Game,
              iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mGame)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "buyer" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Game", family="binomial", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGame <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mDrink <- brm(response ~ store * Country,
              data = data_Drink %>% 
                # Remove really really extreme outliers
                filter(response<10000 & response>=0) %>% 
                mutate(response=response+1, logResp=log(response)) %>% 
                group_by(Country) %>%
                mutate(response=as.vector(scale(logResp))) %>% 
                ungroup(),
              iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mDrink)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "store" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]


post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Drink", family="gaussian", x=1) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})
 
postDrink <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>%   
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mJacket <- brm(response ~ price * Country,
               data = data_Jacket,
               iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mJacket)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "price" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Jacket", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postJacket <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlay <- brm(response ~ loss * Country,
             data = data_Play %>% 
               mutate(loss=factor(loss, levels = c("ticket", "cash"))),
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlay)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "loss" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Play", family="binomial", x=3) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlay <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mGym <- brm(response ~ frame * Country,
            data = data_Gym %>% 
              group_by(Country) %>% 
              mutate(response=as.vector(scale(response))) %>% 
              ungroup(),
             iter = 5000, refresh = 0)
Plot posteriors
post <- prepare_predictions(mGym)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta" #
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "frame" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Gym", family="binomial", x=2) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postGym <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(SMD), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Show codes
mPlane <- brm(response ~ coupon * Country,
             data = data_Plane,
             iter = 5000, refresh = 0, family="bernoulli")
Plot posteriors
post <- prepare_predictions(mPlane)$dpars$mu$fe$b %>% 
  as.data.frame()

names(post)[1] <- "Austria"
names(post)[2] <- "theta"
names(post) <- str_remove( names(post), "b_" )
names(post) <- str_remove( names(post), "coupon" )
names(post) <- str_remove( names(post), "Country" )
all_countries <- names(post)[-2]
all_countries <- all_countries[-grep(":", all_countries)]

post_plot <- map_dfr(all_countries, function(country){
  if(country=="Austria"){
    theta <- post[,"theta"]
  } else {
    theta <- post[,"theta"] + post[,grep(paste0(":",country), names(post))]
  }
  data.frame(theta, Country=country, study="Plane", family="binomial", x=4) %>% 
    mutate(lower = HDInterval::hdi( theta )["lower"],
           upper = HDInterval::hdi( theta )["upper"],
           credible = ifelse(lower<0, "no", "yes"))
})

postPlane <- post_plot %>% 
  group_by(Country) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1)

post_plot %>% 
  ggplot(aes(x = theta, y = Country)) +
  stat_halfeye(aes(fill=credible, color=credible)) +
  geom_vline(xintercept = 0, linetype=2) +
  theme_pubr() + 
  labs(x=expression(log(OR)), y=NULL) +
  scale_y_discrete(guide = "prism_offset") + 
  scale_x_continuous(guide = "prism_offset") + 
  scale_fill_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  scale_color_manual(values = c("#33628DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.x = element_blank(),
        axis.text.y = element_text(size = 15),
        legend.position = "none")

Plot posteriors
# re-run1
post <- rbind(postMrAB1,postMrAB2,postGame,postDrink,postJacket,postPlay,postGym,postPlane) %>% # Recalculate
  mutate(family=case_when(
      study%in%c("Drink","Gym") ~ "gaussian", 
      study=="MrAB" ~ "binomial1", 
      T ~ "binomial"
      )
    )

plotOR <- post %>% filter(family=="binomial") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior log(Odd-Ratio)") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =1:4, 
                     labels = post %>% filter(family=="binomial") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotER <- post %>% filter(family=="binomial1") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Evidence Ratio") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks =c(1, 1.5, 2), limits = c(0.5, 2.5),
                     labels = c(" ", "MrAB", ""),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")

plotSMD <- post %>% filter(family=="gaussian") %>% 
  ggplot(aes(x, theta, color=credible)) +
  geom_jitter( width = 0.1, alpha=0.7, size=4 ) +
  geom_hline(yintercept = 0, linetype=2, size=1) +
  theme_pubr() + theme(legend.position = "right") +
  labs(x=NULL, y="Posterior Standardized\nMean Difference") +
  scale_y_continuous(guide = "prism_offset", limits = c(-1,3), breaks = -1:5) +
  scale_size(range = c(3, 8)) +
  scale_x_continuous(breaks = 1:2, limits = c(0.5, 2.5),
                     labels = post %>% filter(family=="gaussian") %>% 
                       .[,"study",drop=T] %>% unique(),
                     guide = "prism_offset") + 
  scale_color_manual(values = c("#228B8DFF", "gray"), breaks = c("yes", "no")) +
  guides(size = "none") + 
  theme(text = element_text(size = 15, family="Arial"), legend.position = "none")


cowplot::plot_grid(plotOR, plotER, plotSMD, nrow = 1, rel_widths = c(0.5, .2, .3))

Code
# re-run
table_unpooled %>%
  rename(`log₁₀(BF)` = log10_bf) %>%
  flextable() %>% 
  set_caption(caption = "Table 3: Unpooled Analysis") %>% 
  theme_apa() %>% 
  width(width=c(0.8, 1,1,1.5,1)) %>%
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/Unpooled Analysis (None).docx")

table_unpooled %>% 
  kbl(caption="<b>Table 3 | </b> Unpooled Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 3 | Unpooled Analysis
Country Estimate CIs (95%) log10_bf
MrAB1
Austria 1.03 0.79 - 1.27 7.82
Brazil 0.7 0.4 - 0.98 3.42
Canada 1.42 1.17 - 1.66 13.32
China 1.67 1.45 - 1.88 14.63
Colombia 0.67 0.02 - 1.25 0.5
Denmark 1.21 0.95 - 1.44 8.66
Egypt 1.08 0.85 - 1.31 9.2
France 1.02 0.76 - 1.29 7.14
Germany 1.8 1.56 - 2.01 13.79
Ghana 0.38 -0.09 - 0.82 -0.07
Hungary 1.53 1.03 - 2.05 4.08
India 1.71 1.5 - 1.92 14.39
Indonesia 1.92 1.72 - 2.11 20.02
Iran 1.92 1.59 - 2.27 11.96
Israel 1.66 1.33 - 2 8.61
Italy 1.29 1.1 - 1.49 13.01
Lithuania 1.72 1.51 - 1.94 15.54
Morocco 0.86 0.58 - 1.13 4.3
Netherlands 1.36 1.12 - 1.6 11.19
Portugal 1.51 1.28 - 1.73 10.74
Romania 1.88 1.64 - 2.1 15.1
Russia 1.66 1.36 - 1.95 10.65
Singapore 1.88 1.61 - 2.15 13.74
SouthAfrica 0.87 0.53 - 1.19 3.09
SouthKorea 0.97 0.56 - 1.39 2.98
Spain 1.77 1.57 - 1.99 15.48
Sweden 1.53 1.31 - 1.74 12.7
Switzerland 1.92 1.71 - 2.15 21.99
Turkey 1.77 1.49 - 2.07 9.67
UK 1.32 1 - 1.63 7.34
USA 1.44 1.19 - 1.67 11.43
Vietnam 1.47 1.24 - 1.7 11.22
MrAB2
Austria 2 1.79 - 2.21 20.42
Brazil 1.55 1.31 - 1.78 11.51
Canada 2.43 2.18 - 2.64 28.33
China 2.44 2.21 - 2.64 23.65
Colombia 1.54 1.01 - 2.04 4.06
Denmark 1.85 1.62 - 2.08 17.68
Egypt 1.47 1.25 - 1.7 11.74
France 1.96 1.73 - 2.18 19.23
Germany 2.35 2.13 - 2.58 25
Ghana 0.97 0.6 - 1.36 3.24
Hungary 2.02 1.5 - 2.51 7.17
India 1.86 1.64 - 2.06 18.35
Indonesia 2.13 1.94 - 2.32 21.89
Iran 2.13 1.79 - 2.46 12.94
Israel 2.25 1.92 - 2.58 13.74
Italy 2.15 1.96 - 2.33 29.8
Lithuania 1.91 1.7 - 2.12 15.18
Morocco 1.61 1.37 - 1.83 11.65
Netherlands 2.18 1.94 - 2.4 19.59
Portugal 2.06 1.84 - 2.26 19.62
Romania 1.96 1.72 - 2.18 14.74
Russia 2.26 1.98 - 2.55 19.53
Singapore 2.47 2.21 - 2.74 23.88
SouthAfrica 1.34 1.04 - 1.63 7.57
SouthKorea 2.12 1.76 - 2.48 11.75
Spain 2.45 2.23 - 2.65 23.67
Sweden 2.46 2.25 - 2.68 21.05
Switzerland 2.28 2.06 - 2.5 25.81
Turkey 2.14 1.84 - 2.43 14.71
UK 2.03 1.74 - 2.32 13.99
USA 2.36 2.14 - 2.6 19.31
Vietnam 2.22 2.01 - 2.45 20.54
Game
Austria 2.1 1.93 - 2.28 32.2
Brazil 1.44 1.25 - 1.64 20.11
Canada 1.99 1.8 - 2.19 21.71
China 2.66 2.43 - 2.9 24.43
Colombia 0.84 0.48 - 1.22 2.9
Denmark 2.07 1.88 - 2.25 26.5
Egypt 1.57 1.39 - 1.76 15.71
France 2.07 1.88 - 2.25 26.9
Germany 2.28 2.1 - 2.48 28.53
Ghana 1.02 0.73 - 1.31 5.56
Hungary 1.43 1.06 - 1.83 6.26
India 1.36 1.18 - 1.55 14.68
Indonesia 0.74 0.6 - 0.88 9.04
Iran 1.17 0.9 - 1.45 7.49
Israel 1.99 1.74 - 2.27 16.55
Italy 1.96 1.8 - 2.12 27.88
Lithuania 2.08 1.88 - 2.29 19.8
Morocco 1.59 1.41 - 1.78 21.72
Netherlands 2.28 2.09 - 2.48 25.35
Portugal 2.08 1.91 - 2.25 21.71
Romania 1.56 1.39 - 1.73 17.93
Russia 2.13 1.9 - 2.37 20.31
Singapore 2.7 2.42 - 2.96 18.42
SouthAfrica 1.19 0.96 - 1.42 9.71
SouthKorea 1.84 1.56 - 2.12 12.74
Spain 2.56 2.35 - 2.76 23.34
Sweden 2.15 1.98 - 2.32 27.6
Switzerland 2.21 2.03 - 2.4 24.08
Turkey 2.18 1.89 - 2.46 21.33
UK 2.2 1.94 - 2.45 15.15
USA 1.76 1.58 - 1.93 19.83
Vietnam 0.98 0.82 - 1.14 10.11
Drink
Austria 0.82 0.69 - 0.96 13.97
Brazil 0.71 0.56 - 0.87 7.12
Canada 0.98 0.83 - 1.13 12.3
China 0.83 0.69 - 0.97 16.83
Colombia 0.08 -0.4 - 0.54 -0.6
Denmark 0.69 0.54 - 0.83 7.56
Egypt 1.05 0.91 - 1.19 15.69
France 0.79 0.65 - 0.95 10.4
Germany 0.93 0.79 - 1.08 11.79
Ghana 0.51 0.29 - 0.73 2.81
Hungary 0.7 0.36 - 1.04 2.56
India 0.51 0.38 - 0.65 7.28
Indonesia -0.21 -0.43 - 0.01 -0.2
Iran -0.2 -0.52 - 0.13 -0.48
Israel 0.58 0.37 - 0.79 3.98
Italy 0.73 0.61 - 0.85 9.65
Lithuania 0.73 0.59 - 0.87 9.82
Morocco 0.72 0.58 - 0.87 10.04
Netherlands 0.71 0.56 - 0.86 8.08
Portugal 0.76 0.62 - 0.9 9.74
Romania 0.76 0.61 - 0.9 10.05
Russia 0.97 0.79 - 1.17 10.62
Singapore 0.96 0.79 - 1.13 10.35
SouthAfrica 0.59 0.41 - 0.77 4.83
SouthKorea 0.09 -0.27 - 0.51 -0.66
Spain 0.59 0.46 - 0.72 6.8
Sweden 0.65 0.51 - 0.79 10.46
Switzerland 0.88 0.74 - 1.03 18.58
Turkey 0.48 0.28 - 0.67 4.22
UK 0.82 0.62 - 1 8.64
USA 0.92 0.77 - 1.07 11.64
Vietnam 0.68 0.35 - 1 2.33
Play
Austria 0.89 0.55 - 1.19 4.31
Brazil 0.31 -0.06 - 0.69 -0.14
Canada 0.5 0.16 - 0.83 1.15
China 0.06 -0.28 - 0.41 -0.72
Colombia 0.38 -0.31 - 1.07 -0.21
Denmark 0.63 0.3 - 0.97 2.01
Egypt 0.36 0.06 - 0.67 0.42
France 0.6 0.27 - 0.93 1.99
Germany 0.96 0.63 - 1.29 3.88
Ghana 0.49 0.04 - 0.99 0.29
Hungary 0.51 -0.32 - 1.29 -0.05
India 0.06 -0.25 - 0.35 -0.79
Indonesia 0.09 -0.19 - 0.36 -0.77
Iran 0.43 -0.09 - 1.01 -0.03
Israel 0.71 0.22 - 1.18 1.22
Italy 0.47 0.2 - 0.73 1.48
Lithuania 0.76 0.45 - 1.08 3.4
Morocco 0.21 -0.11 - 0.54 -0.45
Netherlands 1.21 0.87 - 1.55 5.75
Portugal 0.64 0.32 - 0.96 2.64
Romania 0.32 -0.08 - 0.73 -0.18
Russia 0.66 0.24 - 1.09 1.4
Singapore 0.63 0.24 - 1.01 1.45
SouthAfrica 0.08 -0.3 - 0.48 -0.67
SouthKorea 0.71 0.11 - 1.29 0.74
Spain 0.71 0.38 - 1.03 2.64
Sweden 1.36 1.01 - 1.71 6.27
Switzerland 0.61 0.28 - 0.93 1.91
Turkey 0.2 -0.23 - 0.62 -0.49
UK 0.67 0.22 - 1.09 1.25
USA 0.76 0.44 - 1.09 3.23
Vietnam 0.37 0.05 - 0.68 0.38
Gym
Austria 0.77 0.63 - 0.91 11.51
Brazil -0.63 -0.78 - -0.47 6.89
Canada 1.06 0.9 - 1.2 13.56
China 0.71 0.58 - 0.85 9.02
Colombia 0.22 -0.07 - 0.56 -0.38
Denmark 1.01 0.87 - 1.16 20.37
Egypt 0.45 0.32 - 0.6 4.42
France 0.87 0.73 - 1.02 11.12
Germany 1.08 0.93 - 1.23 17.42
Ghana 0.34 0.13 - 0.55 1.06
Hungary 0.29 -0.03 - 0.62 -0.13
India 0.29 0.15 - 0.42 2.24
Indonesia -0.02 -0.14 - 0.11 -1.17
Iran 0.42 0.21 - 0.65 2.07
Israel 1.15 0.93 - 1.36 11.14
Italy 0.92 0.8 - 1.04 14.23
Lithuania 0.71 0.57 - 0.85 10.01
Morocco 0.36 0.21 - 0.51 2.82
Netherlands 1.07 0.92 - 1.21 14.25
Portugal 0.68 0.53 - 0.82 8.63
Romania 0.59 0.44 - 0.73 5.81
Russia 0.96 0.76 - 1.14 9.8
Singapore 1.03 0.86 - 1.2 10.16
SouthAfrica 0.42 0.25 - 0.59 2.93
SouthKorea 0.66 0.42 - 0.89 4.14
Spain 0.87 0.74 - 1 13.71
Sweden 1.35 1.22 - 1.5 20.73
Switzerland 1.06 0.92 - 1.2 13.66
Turkey 0.35 0.15 - 0.54 1.59
UK 1.21 1.02 - 1.4 11.38
USA 0.92 0.78 - 1.08 9.59
Vietnam 0.39 0.25 - 0.53 3.33
Plane
Austria 0.99 0.62 - 1.34 3.72
Brazil 0.62 0.29 - 0.98 1.86
Canada 1.03 0.69 - 1.38 4.58
China 0.54 0.24 - 0.84 1.94
Colombia 0.19 -0.45 - 0.93 -0.38
Denmark 0.98 0.61 - 1.35 3.97
Egypt 0.87 0.58 - 1.18 4.4
France 0.71 0.33 - 1.07 2.19
Germany 1 0.62 - 1.35 4.5
Ghana 0.53 0.03 - 1.01 0.36
Hungary 1.37 0.26 - 2.49 1.13
India 0.54 0.25 - 0.84 1.68
Indonesia 0.43 0.12 - 0.72 0.82
Iran 1.29 0.72 - 1.84 3.61
Israel 1.13 0.66 - 1.63 3.42
Italy 0.67 0.38 - 0.96 3.22
Lithuania 1.19 0.86 - 1.51 6.02
Morocco 0.16 -0.21 - 0.56 -0.56
Netherlands 0.97 0.56 - 1.36 3.43
Portugal 0.55 0.23 - 0.85 1.57
Romania 0.62 0.26 - 0.97 1.68
Russia 1.49 0.96 - 2.02 4.08
Singapore 0.78 0.35 - 1.21 2.14
SouthAfrica 0.53 0.13 - 0.92 0.82
SouthKorea 0.62 0.1 - 1.16 0.58
Spain 0.66 0.32 - 0.98 2.42
Sweden 0.75 0.41 - 1.11 2.97
Switzerland 1.02 0.68 - 1.39 5.19
Turkey 0.6 0.19 - 1.03 1.02
UK 0.95 0.49 - 1.38 2.69
USA 1.15 0.81 - 1.51 5.29
Vietnam 0.42 0.09 - 0.74 0.63

Country-level Analysis

Load Data
# Get Country-level Info
zscore <- function(x) as.vector(scale(x))
info <- 
  read.csv("../Data/Info Countries/data.csv") %>% 
  filter(Country %in% unique(post$Country)) %>% 
  select(Country, GDP.per.capita..current.US.., Democracy.index) %>% 
  rename(
    GDPxCapita = GDP.per.capita..current.US..,
    democracy_index=Democracy.index
  ) %>% 
  mutate(
    # GDPxCapita: Remove (2022) and convert in number
    GDPxCapita = str_replace(GDPxCapita, "\\([^()]{0,}\\)", ""),
    GDPxCapita = str_remove(GDPxCapita, ","),
    GDPxCapita = as.numeric(GDPxCapita),
    democracy_index = str_replace(democracy_index, ",", "."),
    democracy_index=as.numeric(democracy_index)
  )

info <- info %>% 
  mutate(
    flag = case_when(
      Country=="Austria" ~ "at",
      Country=="Brazil" ~ "br",
      Country=="Canada" ~ "ca",
      Country=="China" ~ "cn",
      Country=="Denmark" ~ "dk",
      Country=="Egypt" ~ "eg",
      Country=="France" ~ "fr",
      Country=="Germany" ~ "de",
      Country=="India" ~ "in",
      Country=="Indonesia" ~ "id",
      Country=="Italy" ~ "it",
      Country=="Lithuania" ~ "lt",
      Country=="Morocco" ~ "ma",
      Country=="Netherlands" ~ "nl",
      Country=="Portugal" ~ "pt",
      Country=="Romania" ~ "ro",
      Country=="Spain" ~ "es",
      Country=="Sweden" ~ "se",
      Country=="Switzerland" ~ "ch",
      Country=="USA" ~ "us",
      Country=="Vietnam" ~ "vn",
    )
  )

exchange_rates <- read.csv("scr/exchange-rate/exchange_rates_2022-10-01.csv")


# Create a named vector for all countries
currency_codes <- c(
    "Austria" = "EUR",      # Euro
    "Brazil" = "BRL",       # Brazilian Real
    "Canada" = "CAD",       # Canadian Dollar
    "China" = "CNY",        # Chinese Yuan
    "Denmark" = "DKK",      # Danish Krone
    "Egypt" = "EGP",        # Egyptian Pound
    "France" = "EUR",       # Euro
    "Germany" = "EUR",      # Euro
    "India" = "INR",        # Indian Rupee
    "Indonesia" = "IDR",    # Indonesian Rupiah
    "Italy" = "EUR",        # Euro
    "Lithuania" = "EUR",    # Euro
    "Morocco" = "MAD",      # Moroccan Dirham
    "Netherlands" = "EUR",  # Euro
    "Portugal" = "EUR",     # Euro
    "Romania" = "RON",      # Romanian Leu
    "Spain" = "EUR",        # Euro
    "Sweden" = "SEK",       # Swedish Krona
    "Switzerland" = "CHF",  # Swiss Franc
    "USA" = "USD",          # US Dollar
    "Vietnam" = "VND"       # Vietnamese Dong
)

# Create results dataframe and merge with exchange rates
exchange_rate_df <- data.frame(
    Country = names(currency_codes),
    Currency = currency_codes
) %>%
    left_join(exchange_rates, by = "Currency")

theta <- map_dfr(theta_preregisteredExclusion, function(df) df )

sbj_regressors <- Gym %>% 
  # Tidy
  mutate(Age=as.numeric(Age)) %>%
  filter(Age>0 & Age<99) %>% 
  mutate(Education=as.numeric(Education)) %>% 
  filter(Education<100) %>% 
  filter(Gender%in%c("Male", "Female")) %>% 
  group_by(Country) %>% 
  summarise(FinancialLiteracy=mean(FinancialLiteracy),
            numeric_income=mean(numeric_income, na.rm=T),
            Education=mean(Education),
            Age=mean(Age))

lor2smd = sqrt( 3 / (pi^2) )
df <- left_join(theta[,c("Country", "theta", "se_theta", "family", "study", "x")], info, by="Country") %>% 
  mutate(study = ifelse(family=="binomial1" & x==1, "MrAB1", study),
         study = ifelse(family=="binomial1" & x==2, "MrAB2", study)) %>% 
  left_join(sbj_regressors, by="Country") %>% 
  group_by(study) %>% 
  mutate( zGDPxCapita=zscore(GDPxCapita) ) %>% 
  mutate( choensd = ifelse(family=="binomial", theta*lor2smd, theta),
          choensd = ifelse(family=="binomial1", NA, choensd) ) %>% 
  mutate( se = ifelse(family=="binomial", se_theta*lor2smd, se_theta),
          se = ifelse(family=="binomial1", NA, se) ) %>% 
  left_join(exchange_rate_df, by="Country")
Fit Linear Model
# All ---------------------
fit_and_save_mAll_Others <- function(){
  path2file <- "scr/country-level-analysis/models/Others/mAll.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    m <- brm(
      formula = choensd ~ zGDPxCapita + zFinancialLiteracy + zEducation + zAge + zIncome + (zGDPxCapita + zFinancialLiteracy + zEducation + zAge + zIncome | study), 
      prior = prior_string("normal(0,2.5)", class = "b"),
      data = df %>% group_by(study) %>% 
        mutate(
          zFinancialLiteracy=zscore(FinancialLiteracy),
          zEducation=zscore(Education),
          zAge=zscore(Age),
          zIncome=zscore(numeric_income)
        ),
      iter = 20000, refresh = 100, cores = 4
    )
    saveRDS(m, file = path2file)
  }
  return(m)
}
mAll <- fit_and_save_mAll_Others()
Fit Non-Linear Model
d <- df %>% mutate(x=zscore(GDPxCapita), y=choensd) %>% filter(family!="binomial1")
fit_and_save_nlbmGDPxCapita <- function(){
  path2file <- "scr/country-level-analysis/models/Others/nlbmGDPxCapita.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    
    # Define the nonlinear formula with random effects
    nlform <- bf(
      y ~ K / (1 + exp(-r * (x - x0))),
      K ~ 1 + (1 | study), # Random effect for K
      r ~ 1 + (1 | study), # Random effect for r
      x0 ~ 1 + (1 | study), # Random effect for x0
      nl = TRUE
    )
    
    # Define priors (adjust these based on your knowledge)
    priors <- c(
      prior(normal(1, 1), nlpar = "K"),
      prior(normal(0, 2.5), nlpar = "r"),
      prior(normal(-1, 1), nlpar = "x0")
    )
    
    # Fit the model
    m <- brm(
      formula = nlform,
      data = d,
      prior = priors,
      family = gaussian(),
      control = list(adapt_delta = 0.95),
      chains = 4,
      iter = 20000,
      cores = 4,
      seed = 123
    )
    
    saveRDS(m, file = path2file)
  }
  
  return(m)
}
bm1 <- fit_and_save_nlbmGDPxCapita()
Plot
### Non-Linear GDP -----
f <- function(x, K, r, x0) K / (1 + exp(-r * (x-x0)))

bm1 <- readRDS("scr/country-level-analysis/models/Others/nlbmGDPxCapita.rds")

plot_nlgdp <- df %>% 
  filter(family!="binomial1") %>% 
  group_by(Country) %>% 
  mutate(choensd=mean(choensd)) %>% 
  filter(row_number()==1) %>% 
  ggplot(aes(GDPxCapita, choensd)) +
  geom_line(
    data = data.frame(
      GDPxCapita=seq(-2, 100, .01) * 1000, 
      choensd=f(seq(-2, 100, .01) * 1000, fixef(bm1)[1,1], fixef(bm1)[2,1]/sd(d$GDPxCapita), fixef(bm1)[3,1] * sd(d$GDPxCapita) + mean(d$GDPxCapita))
    ),
    linewidth=2,color="#5f7e96"
  ) +
  geom_point(size=6, shape=1) +
  geom_flag(aes(country=flag)) +
  theme_pubr() +
  coord_cartesian(xlim = c(-5000, 105000), ylim = c(0.05, 1.1)) +
  scale_x_continuous(breaks = c(0, 50000, 100000), labels = c("$0", "$50K", "$100K"), guide = "prism_offset") +
  scale_y_continuous(breaks = seq(0.1, .9, 0.2), guide = "prism_offset") +
  xlab("\nGDP per capita\n") +
  ylab("Mental Accounting\n(Choen's d)") +
  theme(text = element_text(size = 15, family="Arial")); 



### Betas (no GDP) -----
pp1 <- prepare_predictions(mAll)

re <- data.frame( 
  re = c(
    fixef(mAll)[3,1] + ranef(mAll)$study[,1,"zFinancialLiteracy"],
    fixef(mAll)[4,1] + ranef(mAll)$study[,1,"zEducation"],
    fixef(mAll)[5,1] + ranef(mAll)$study[,1,"zAge"],
    fixef(mAll)[6,1] + ranef(mAll)$study[,1,"zIncome"]
  ),
  x = c(rep(1-0.2, 6), rep(2-0.2, 6), rep(3-0.2, 6), rep(4-0.2, 6)),
  study= rep(names(ranef(mAll)$study[,1,"zFinancialLiteracy"]), 4)
) %>% 
  mutate(study=factor(study, labels = c("Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
                      levels = c("Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
  ))


fe <- data.frame(
  fe = fixef(mAll)[3:6,1],
  low=ci(mAll)$CI_low[3:6],
  high=ci(mAll)$CI_high[3:6]
)

plot_betas_nogdp <- pp1$dpars$mu$fe$b %>% 
  as_tibble() %>% 
  select(- c(b_Intercept, b_zGDPxCapita)) %>% 
  reshape2::melt() %>%
  # mutate(issign = ifelse(variable=="b_zGDPxCapita", "yes", "no")) %>% 
  ggplot(aes(variable, value)) +
  stat_halfeye(
    fill="#f6f0e8",
    # adjust bandwidth
    adjust = .5,
    # move to the right
    justification = -0.2,
    # remove the slub interval
    width = .6, 
    .width = 0,
    point_colour = NA
    # fill= c("#d5f8ff", rep("#f6f0e8", 4))
  ) +
  geom_pointinterval(data=fe, aes(1:4 + 0.1, y=fe, ymin=low, ymax=high), color= "#a85100" ) +
  geom_beeswarm(data=re, aes(x, re, color=study), cex=2, size=2, shape=1, stroke=1) +
  geom_line(data=data.frame(x=c(0.2, 4.7), y=c(0, 0)), aes(x, y), linewidth=0.15) +
  scale_color_manual(values = colorspace::qualitative_hcl(7, "Dark 3")[c(2, 4, 7, 6, 1, 3)]) +
  theme_pubr() +
  coord_cartesian(xlim = c(0.9, 4.3), ylim = c(-0.22, .3)) +
  scale_x_discrete(labels = c("Finantial\nLiteracy", "Education", "Age", "Income"),
                   guide = "prism_offset") +
  scale_y_continuous(breaks = c(-0.2, 0, 0.2), guide = "prism_offset") +
  theme(text = element_text(size = 15, family="Arial"),
        legend.position = c(0.65, 0.8), legend.direction = "horizontal",
        axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=.5)
  ) +
  labs(x=NULL, y="Beta Estimate               ", color=NULL) +
  guides(fill = "none");



### Betas (GDP) -----
pp2 <- prepare_predictions(bm1)

re <- data.frame( 
  re = fixef(bm1)[2,1] + ranef(bm1)$study[,1,"r_Intercept"],
  x = rep(1-0.2, 6),
  study= names(ranef(mAll)$study[,1,"zFinancialLiteracy"])
) %>% 
  mutate(study=factor(study, labels = c("Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
                      levels = c("Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
  ))


fe <- data.frame(
  fe = fixef(bm1)[2,1],
  low=ci(bm1)$CI_low[2],
  high=ci(bm1)$CI_high[2]
)

plot_betas_gdp <- data.frame(value=as.numeric(pp2$nlpars$r$fe$b)) %>% as_tibble() %>% 
  mutate(variable="r") %>% 
  ggplot(aes(variable, value)) +
  stat_halfeye(
    fill="#E7ECEF",
    # adjust bandwidth
    adjust = .5,
    # move to the right
    justification = -0.2,
    # remove the slub interval
    width = .6, 
    .width = 0,
    point_colour = NA
    # fill= c("#d5f8ff", rep("#f6f0e8", 4))
  ) +
  geom_pointinterval(data=fe, aes(1 + 0.1, y=fe, ymin=low, ymax=high), color="#234666" ) +
  geom_beeswarm(data=re, aes(x-0.1, re, color=study), cex=8, size=2, shape=1, stroke=1) +
  geom_line(data=data.frame(x=c(0,1.5), y=c(0, 0)), aes(x, y), linewidth=0.15) +
  scale_color_manual(values = colorspace::qualitative_hcl(7, "Dark 3")[c(2, 4, 7, 6, 1, 3)]) +
  theme_pubr() +
  coord_cartesian(xlim = c(0.9, 1.4), ylim=c(-4.5, 6.3)) +
  scale_x_discrete(labels = c("GDP per\nCapita"), guide = "prism_offset") +
  scale_y_continuous(breaks = seq(-4, 4, 2), guide = "prism_offset") +
  theme(text = element_text(size = 15, family="Arial"),
        legend.position = "none", legend.direction = "horizontal",
        axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=.5)
  ) +
  labs(x=NULL, y="Slope Estimate           ", color=NULL) +
  guides(fill = "none"); 


### Betas Linear & Non-Linear -----
betas_linear_and_nonlinear <- cowplot::plot_grid(
  plot_betas_nogdp, plot_betas_gdp, rel_widths = c(0.8, 0.33)
); 

### Betas Linear & Non-Linear -----
betas_linear_and_nonlinear <- cowplot::plot_grid(
  plot_betas_nogdp, plot_betas_gdp, rel_widths = c(0.8, 0.33)
); 

# Non-Linear GDP & Linear & Non-Linear Betas
cowplot::plot_grid(
  betas_linear_and_nonlinear, plot_nlgdp, rel_widths = c(0.7, 0.45), 
  labels = LETTERS[1:2], label_size = 20, label_y = 0.93
)

Plot
### Linear GDP -----
# - Standardize New Input Data
# Assuming you have the means and standard deviations of the original data
mean_GDPxCapita <- mean(df$GDPxCapita, na.rm = TRUE)
sd_GDPxCapita <- sd(df$GDPxCapita, na.rm = TRUE)
# New input data (in original scale)
new_GDPxCapita_values <- seq(0, 90000, length=2) # replace with actual values
# Standardize new input data
new_zGDPxCapita <- (new_GDPxCapita_values - mean_GDPxCapita) / sd_GDPxCapita
# - Make Predictions with the Model
# Prepare the new data for prediction
new_data <- data.frame(zGDPxCapita = new_zGDPxCapita, zFinancialLiteracy=0, zEducation=0, zAge=0, zIncome=0)
# Make predictions using the brm model
predictions <- predict(mAll, newdata = new_data, re_formula = NA)
# - Transform Predictions Back to Original Scale
# Assuming you have the means and standard deviations for choensd
mean_choensd <- mean(df$choensd, na.rm = TRUE)
sd_choensd <- sd(df$choensd, na.rm = TRUE)
# Re-scale predictions
preddf <- cbind(new_data, predictions) %>% 
  mutate(GDPxCapita = new_GDPxCapita_values)

# Plot Flags
plot_gdp <- df %>% 
  filter(family!="binomial1") %>% 
  group_by(Country) %>% 
  mutate(choensd=mean(choensd)) %>% 
  filter(row_number()==1) %>% 
  ggplot(aes(GDPxCapita, choensd)) +
  geom_line(data=preddf, aes(GDPxCapita, Estimate),
            linewidth=2,color="#5f7e96") +
  geom_point(size=6, shape=1) +
  geom_flag(aes(country=flag)) +
  theme_pubr() +
  coord_cartesian(xlim = c(-5000, 102000), ylim = c(-0.05, 1.1)) +
  scale_x_continuous(breaks = c(0, 50000, 100000), labels = c("$0", "$50K\n", "$100K"), guide = "prism_offset") +
  scale_y_continuous(breaks = seq(0., .9, 0.3), guide = "prism_offset") +
  xlab("GDP per Capita\n") +
  ylab("Mental Accounting\n(Choen's d)") +
  theme(text = element_text(size = 15, family="Arial"))


### Betas All Linear -----
pp <- prepare_predictions(mAll)

re <- data.frame( 
  re = c(
    fixef(mAll)[2,1] + ranef(mAll)$study[,1,"zGDPxCapita"],
    fixef(mAll)[3,1] + ranef(mAll)$study[,1,"zFinancialLiteracy"],
    fixef(mAll)[4,1] + ranef(mAll)$study[,1,"zEducation"],
    fixef(mAll)[5,1] + ranef(mAll)$study[,1,"zAge"],
    fixef(mAll)[6,1] + ranef(mAll)$study[,1,"zIncome"]
  ),
  x = c(rep(1-0.2, 6), rep(2-0.2, 6), rep(3-0.2, 6), rep(4-0.2, 6), rep(5-0.2, 6)),
  study= rep(names(ranef(mAll)$study[,1,"zFinancialLiteracy"]), 5)
) %>% 
  mutate(study=factor(study, labels = c("Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
                      levels = c("Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
  ))


fe <- data.frame(
  fe = fixef(mAll)[2:6,1],
  low=ci(mAll)$CI_low[2:6],
  high=ci(mAll)$CI_high[2:6]
)

plot_betas <- pp$dpars$mu$fe$b %>% 
  as_tibble() %>% 
  select(-b_Intercept) %>% 
  reshape2::melt() %>%
  mutate(issign = ifelse(variable=="b_zGDPxCapita", "yes", "no")) %>% 
  ggplot(aes(variable, value)) +
  stat_halfeye(
    aes(fill=issign),
    # adjust bandwidth
    adjust = .5,
    # move to the right
    justification = -0.2,
    # remove the slub interval
    width = .6, 
    .width = 0,
    point_colour = NA
    # fill= c("#d5f8ff", rep("#f6f0e8", 4))
  ) +
  geom_pointinterval(data=fe, aes(1:5 + 0.1, y=fe, ymin=low, ymax=high), color= c("#234666", rep("#a85100", 4)) ) +
  geom_beeswarm(data=re, aes(x, re, color=study), cex=2, size=2, shape=1, stroke=1) +
  geom_line(data=data.frame(x=c(0.2,5.5), y=c(0, 0)), aes(x, y), linewidth=0.1) +
  scale_color_manual(values = colorspace::qualitative_hcl(7, "Dark 3")[c(2, 4, 7, 6, 1, 3)]) +
  theme_pubr() +
  coord_cartesian(xlim = c(0.9, 5.1), ylim = c(-0.3, .45)) +
  scale_x_discrete(labels = c("GDP per\nCapita","Finantial\nLiteracy", "Education", "Age", "Income"),
                   guide = "prism_offset") +
  scale_y_continuous(breaks = c(-0.25, 0, 0.25), guide = "prism_offset") +
  theme(text = element_text(size = 15, family="Arial"),
        legend.position = c(0.6, 0.75), legend.direction = "horizontal",
        axis.text.x = element_text(angle = 45, vjust = 0.5, hjust=.5)
  ) +
  labs(x=NULL, y="Beta Estimate               ", color=NULL) +
  guides(fill = "none") +
  scale_fill_manual(values = c("#f6f0e8", "#E7ECEF"))

cowplot::plot_grid(
  plot_betas, plot_gdp, rel_widths = c(0.55, 0.45), 
  labels = LETTERS[1:2], label_size = 20, label_y = 0.93
)

Show model fit
fit_and_save_mGDPxCapita_Others <- function(){
  path2file <- "scr/country-level-analysis/models/Others/mGDPxCapita.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    m <- brm(
      formula = choensd ~ zGDPxCapita + (zGDPxCapita | study), 
      prior = prior_string("normal(0,2.5)", class = "b"),
      data = df,
      iter = 20000, refresh = 100, cores = 4
    )
    saveRDS(m, file = path2file)
  }
  
  return(m)
}
mGDPxCapita <- fit_and_save_mGDPxCapita_Others()

## Standardize New Input Data ----
# Assuming you have the means and standard deviations of the original data
mean_GDPxCapita <- mean(df$GDPxCapita, na.rm = TRUE)
sd_GDPxCapita <- sd(df$GDPxCapita, na.rm = TRUE)
# New input data (in original scale)
new_GDPxCapita_values <- seq(0, 1e5, length=2) # replace with actual values
# Standardize new input data
new_zGDPxCapita <- (new_GDPxCapita_values - mean_GDPxCapita) / sd_GDPxCapita
# - Make Predictions with the Model
# Prepare the new data for prediction
new_data <- data.frame(zGDPxCapita = new_zGDPxCapita)
# Make predictions using the brm model
predictions <- predict(mGDPxCapita, newdata = new_data, re_formula = NA)
# - Transform Predictions Back to Original Scale
# Assuming you have the means and standard deviations for choensd
mean_choensd <- mean(df$choensd, na.rm = TRUE)
sd_choensd <- sd(df$choensd, na.rm = TRUE)
# Re-scale predictions
preddf <- cbind(new_data, predictions) %>% 
  mutate(GDPxCapita = new_GDPxCapita_values)
Plot
## Compare Linear and Non-Linear Model -----
loo1 <- loo(mGDPxCapita)
loo2 <- loo(bm1)

df_loo <- loo_compare(loo1, loo2) %>% 
  as.data.frame() 
row.names(df_loo) <- c("Non-Linear", "Linear")
df_loo %>% kable 
elpd_diff se_diff elpd_loo se_elpd_loo p_loo se_p_loo looic se_looic
Non-Linear 0.00000 0.000000 18.000716 20.29896 19.43763 7.367054 -36.00143 40.59792
Linear -12.67116 4.457339 5.329554 18.79474 16.05023 5.631817 -10.65911 37.58947
Plot
  # mutate(` `=c("Non-Linear", "Linear")) %>% 

data.frame(looic=c(loo1$estimates["looic","Estimate"], loo2$estimates["looic","Estimate"]), model=c("Linear", "Non-Linear")) %>% 
  ggplot(aes(model, looic)) +
  geom_col(width = 0.7, fill="#5f7e96") +
  theme_pubr() +
  coord_cartesian(ylim = c(-42, 0)) +
  scale_y_continuous(guide = "prism_offset") +
  scale_x_discrete(guide = "prism_offset") +
  geom_hline(yintercept = 0, linewidth=0.2) +
  theme(text = element_text(size = 15, family="Arial")) +
  ylab("LOO-IC")

Show model fit
fit_and_save_mFinancialLiteracy_Others <- function(){
  path2file <- "scr/country-level-analysis/models/Others/mFinancialLiteracy.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    m <- brm(
      formula = choensd ~ zFinancialLiteracy + (zFinancialLiteracy | study), 
      prior = prior_string("normal(0,2.5)", class = "b"),
      data = df %>% group_by(study) %>% mutate(zFinancialLiteracy=zscore(FinancialLiteracy)),
      iter = 20000, refresh = 100, cores = 4
    )
    saveRDS(m, file = path2file)
  }
  return(m)
}
mFinancialLiteracy <- fit_and_save_mFinancialLiteracy_Others()
Plot
df %>% 
  filter(family!="binomial1") %>% 
  group_by(Country) %>% 
  mutate(choensd=mean(choensd)) %>% 
  filter(row_number()==1) %>% 
  ggplot(aes(FinancialLiteracy, choensd)) +
  geom_point(size=6, shape=1) +
  geom_flag(aes(country=flag)) +
  theme_pubr() +
  xlab("") +
  ylab("Mental Accounting\n(Choen's d)") +
  theme(text = element_text(size = 15, family="Arial"))

Show model fit
fit_and_save_mEducation_Others <- function(){
  path2file <- "scr/country-level-analysis/models/Others/mEducation.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    m <- brm(
      formula = choensd ~ zEducation + (zEducation | study), 
      prior = prior_string("normal(0,2.5)", class = "b"),
      data = df %>% group_by(study) %>% mutate(zEducation=zscore(Education)),
      iter = 20000, refresh = 100, cores = 4
    )
    saveRDS(m, file = path2file)
  }
  return(m)
}
mEducation <- fit_and_save_mEducation_Others()
Plot
df %>% 
  filter(family!="binomial1") %>% 
  group_by(Country) %>% 
  mutate(choensd=mean(choensd)) %>% 
  filter(row_number()==1) %>% 
  ggplot(aes(Education, choensd)) +
  geom_point(size=6, shape=1) +
  geom_flag(aes(country=flag)) +
  theme_pubr() +
  xlab("") +
  ylab("Mental Accounting\n(Choen's d)") +
  theme(text = element_text(size = 15, family="Arial"))

Show model fit
fit_and_save_mAge_Others <- function(){
  path2file <- "scr/country-level-analysis/models/Others/mAge.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    m <- brm(
      formula = choensd ~ zAge + (zAge | study), 
      prior = prior_string("normal(0,2.5)", class = "b"),
      data = df %>% group_by(study) %>% mutate(zAge=zscore(Age)),
      iter = 20000, refresh = 100, cores = 4
    )
    saveRDS(m, file = path2file)
  }
  return(m)
}
mAge <- fit_and_save_mAge_Others()
Plot
df %>% 
  filter(family!="binomial1") %>% 
  group_by(Country) %>% 
  mutate(choensd=mean(choensd)) %>% 
  filter(row_number()==1) %>% 
  ggplot(aes(Age, choensd)) +
  geom_point(size=6, shape=1) +
  geom_flag(aes(country=flag)) +
  theme_pubr() +
  xlab("") +
  ylab("Mental Accounting\n(Choen's d)") +
  theme(text = element_text(size = 15, family="Arial"))

Show model fit
fit_and_save_mIncome_Others <- function(){
  path2file <- "scr/country-level-analysis/models/Others/mIncome.rds"
  
  if( file.exists(path2file) ){
    m <- readRDS(file = path2file)
  } else {
    m <- brm(
      formula = choensd ~ zIncome + (zIncome | study), 
      prior = prior_string("normal(0,2.5)", class = "b"),
      data = df %>% group_by(study) %>% mutate(zIncome=zscore(numeric_income)),
      iter = 20000, refresh = 100, cores = 4
    )
    saveRDS(m, file = path2file)
  }
  return(m)
}
mIncome <- fit_and_save_mIncome_Others()
Plot
df %>% 
  filter(family!="binomial1") %>% 
  group_by(Country) %>% 
  mutate(choensd=mean(choensd)) %>% 
  filter(row_number()==1) %>% 
  ggplot(aes(numeric_income, choensd)) +
  geom_point(size=6, shape=1) +
  geom_flag(aes(country=flag)) +
  theme_pubr() +
  xlab("") +
  ylab("Mental Accounting\n(Choen's d)") +
  theme(text = element_text(size = 15, family="Arial"))

Fit Non-Linear Model
#
d <- df %>%
  mutate(
    x = zscore(GDPxCapita),
    y = choensd,
    zdemocracy = zscore(democracy_index),
    zface_value = zscore(log(Rate_to_USD))
  ) %>%
  filter(family != "binomial1")

# Define the nonlinear formula with random effects plus linear face value effect
nlform <- bf(
  y ~ K / (1 + exp(-r * (x - x0))) + betademocracy * zdemocracy + betaface * zface_value,
  K ~ 1 + (1|study),
  r ~ 1 + (1|study),
  x0 ~ 1 + (1|study),
  betademocracy ~ 1 + (1|study),
  betaface ~ 1 + (1|study),
  nl = TRUE
)

# Define priors
priors <- c(
  prior(normal(1, 1), nlpar = "K"),
  prior(normal(0, 2.5), nlpar = "r"),
  prior(normal(-1, 1), nlpar = "x0"),
  prior(normal(0, 2.5), nlpar = "betademocracy"),
  prior(normal(0, 2.5), nlpar = "betaface")
)

# Fit the model
bm2 <- brm(
  formula = nlform,
  data = d,
  prior = priors,
  family = gaussian(),
  control = list(adapt_delta = 0.95),
  chains = 4,
  iter = 20000,
  cores = 4,
  seed = 123
)
Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
using C compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.6)’
using SDK: ‘’
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c foo.c -o foo.o
In file included from <built-in>:1:
In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal error: 'cmath' file not found
  679 | #include <cmath>
      |          ^~~~~~~
1 error generated.
make: *** [foo.o] Error 1
Fit Non-Linear Model
summary(bm2)
 Family: gaussian 
  Links: mu = identity; sigma = identity 
Formula: y ~ K/(1 + exp(-r * (x - x0))) + betademocracy * zdemocracy + betaface * zface_value 
         K ~ 1 + (1 | study)
         r ~ 1 + (1 | study)
         x0 ~ 1 + (1 | study)
         betademocracy ~ 1 + (1 | study)
         betaface ~ 1 + (1 | study)
   Data: d (Number of observations: 126) 
  Draws: 4 chains, each with iter = 20000; warmup = 10000; thin = 1;
         total post-warmup draws = 40000

Multilevel Hyperparameters:
~study (Number of levels: 6) 
                            Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
sd(K_Intercept)                 0.48      0.23     0.22     1.06 1.00    14208
sd(r_Intercept)                 1.92      1.20     0.18     4.84 1.00     6161
sd(x0_Intercept)                0.92      0.70     0.24     2.72 1.00     1411
sd(betademocracy_Intercept)     0.09      0.07     0.01     0.25 1.00     6536
sd(betaface_Intercept)          0.12      0.08     0.03     0.31 1.00    11643
                            Tail_ESS
sd(K_Intercept)                20423
sd(r_Intercept)                11639
sd(x0_Intercept)                 988
sd(betademocracy_Intercept)    14845
sd(betaface_Intercept)         14456

Regression Coefficients:
                        Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
K_Intercept                 0.82      0.22     0.39     1.27 1.00     9555
r_Intercept                 2.56      1.20     0.31     5.14 1.00    10564
x0_Intercept               -1.07      0.47    -2.13    -0.18 1.00     1674
betademocracy_Intercept    -0.07      0.05    -0.16     0.04 1.00    19045
betaface_Intercept         -0.05      0.06    -0.18     0.07 1.00    15410
                        Tail_ESS
K_Intercept                14017
r_Intercept                 6392
x0_Intercept                 300
betademocracy_Intercept    18984
betaface_Intercept         16600

Further Distributional Parameters:
      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma     0.17      0.01     0.15     0.20 1.00    13702    19967

Draws were sampled using sampling(NUTS). 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).
pling)
Chain 1: 
Chain 1:  Elapsed Time: 78.252 seconds (Warm-up)
Chain 1:                60.953 seconds (Sampling)
Chain 1:                139.205 seconds (Total)
Chain 1: 
Chain 2: Iteration: 18000 / 20000 [ 90%]  (Sampling)
Chain 4: Iteration: 18000 / 20000 [ 90%]  (Sampling)
Chain 3: Iteration: 18000 / 20000 [ 90%]  (Sampling)
Chain 2: Iteration: 20000 / 20000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 79.196 seconds (Warm-up)
Chain 2:                86.702 seconds (Sampling)
Chain 2:                165.898 seconds (Total)
Chain 2: 
Chain 3: Iteration: 20000 / 20000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 81.507 seconds (Warm-up)
Chain 3:                87.368 seconds (Sampling)
Chain 3:                168.875 seconds (Total)
Chain 3: 
Chain 4: Iteration: 20000 / 20000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 79.739 seconds (Warm-up)
Chain 4:                90.188 seconds (Sampling)
Chain 4:                169.927 seconds (Total)
Chain 4: 

Multidimensional Scaling Analysis

Fit MDS
# Perform MDS on the correlation matrix
lor2smd = sqrt( 3 / (pi^2) )
df <- theta[,c("Country", "theta", "study", "family")] %>% 
  group_by(study) %>% 
  mutate( theta = ifelse(family=="binomial", theta*lor2smd, theta)) %>% 
  na.omit() %>% ungroup() %>% 
  group_by(Country, study) %>% 
  mutate(theta=mean(theta)) %>% 
  filter(row_number()==1) %>% 
  ungroup() %>% 
  select(Country, study, theta) %>% 
  pivot_wider(
    names_from = study,
    values_from = theta,
    id_cols = Country
  )

dist_matrix <- dist(t(scale(df[,-1])))
mds_fit <- cmdscale(dist_matrix, k = 3, eig = TRUE)

mds_df <- data.frame(
  x = mds_fit$points[,1],
  y = mds_fit$points[,2],
  z = mds_fit$points[,3],
  scenario = colnames(df)[-1]
)
Plot MDS
# Define colors for each scenario
scenario_colors <- colorspace::qualitative_hcl(7, "Dark 3")[c(5, 2, 4, 7, 6, 1, 3)]
names(scenario_colors) <- c("MrAB", "Game", "Play", "Drink", "Jacket", "Plane", "Gym")

# Create 3D plot using plotly
plot_ly(mds_df, 
        x = ~x, 
        y = ~y, 
        z = ~z, 
        type = "scatter3d",
        mode = "markers+text",
        text = ~scenario,
        textposition = "top center",
        color = ~scenario,  # Use scenario for color mapping
        colors = scenario_colors,  # Specify the color palette
        marker = list(size = 5)) %>%
  layout(
    showlegend = FALSE,
    scene = list(
      xaxis = list(title = "Dimension 1", tickvals = -3:3, range=c(-4, 4)), 
      yaxis = list(title = "Dimension 2", tickvals = -3:3, range=c(-4, 4)),
      zaxis = list(title = "Dimension 3", tickvals = -3:3, range=c(-4, 4))
    )
  )

Individual-level Analysis

In this section we perform a Bayesian unpooled analysis to explore the role of financial literacy (i.e., are people with higher levels of financial literacy less susceptible to the mental accounting effect?), age, gender, and income.

Show exploratory model fit
# It will take forever!!

mMrAB1 <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) +
                (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
              data = MrAB %>% 
                # Tidy
                mutate(Age=as.numeric(Age)) %>%
                filter(Age>0 & Age<99) %>% 
                mutate(Education=as.numeric(Education)) %>% 
                filter(Education<100) %>% 
                filter(Gender%in%c("Male", "Female")) %>% 
                mutate(condition_group=ifelse(
                  condition %in% c("gain-gain VS gain", "gain-loss VS gain"),
                  "gain",
                  "loss"
                )) %>% 
                filter(condition_group=="gain") %>% 
                mutate(condition=factor(condition, levels = c("gain-loss VS gain", "gain-gain VS gain") )), 
              iter = 20000, refresh = 1, cores = 2, chains = 2,
              family="bernoulli")

saveRDS(mMrAB1, file = "index_cache/brms_exploratory/mMrAB1.rds")



mMrAB2 <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + (condition+FinancialLiteracy+Age+Education+FinancialLiteracy+Gender+numeric_income | Country),
              data = MrAB %>% 
                # Tidy
                mutate(Age=as.numeric(Age)) %>%
                filter(Age>0 & Age<99) %>% 
                mutate(Education=as.numeric(Education)) %>% 
                filter(Education<100) %>% 
                filter(Gender%in%c("Male", "Female")) %>% 
                mutate(condition_group=ifelse(
                  condition %in% c("gain-gain VS gain", "gain-loss VS gain"),
                  "gain",
                  "loss"
                )) %>% 
                filter(condition_group=="loss") %>% 
                mutate(condition=factor(condition, levels = c("loss-gain VS loss", "loss-loss VS loss") )), 
              
              iter = 20000, refresh = 1, cores = 2, chains = 2,
              family="bernoulli")

saveRDS(mMrAB2, file = "index_cache/brms_exploratory/mMrAB2.rds")

mGame <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + 
               (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
               data = Game %>% 
                 # Tidy
                 mutate(Age=as.numeric(Age)) %>%
                 filter(Age>0 & Age<99) %>% 
                 mutate(Education=as.numeric(Education)) %>% 
                 filter(Education<100) %>% 
                 filter(Gender%in%c("Male", "Female")), 
             
             iter = 20000, refresh = 1, chains = 2, cores = 2,
             family="bernoulli")

saveRDS(mGame, file = "index_cache/brms_exploratory/mGame.rds")

mDrink <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + 
                (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
                data = Drink %>% 
                  # Tidy
                  mutate(Age=as.numeric(Age)) %>%
                  filter(Age>0 & Age<99) %>% 
                  mutate(Education=as.numeric(Education)) %>% 
                  filter(Education<100) %>% 
                  filter(Gender%in%c("Male", "Female")),
              iter = 20000, refresh = 1, chains = 2, cores = 2)
saveRDS(mDrink, file = "index_cache/brms_exploratory/mDrink.rds")


mJacket <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + 
                 (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
                 data = Jacket %>% 
                   # Tidy
                   mutate(Age=as.numeric(Age)) %>%
                   filter(Age>0 & Age<99) %>% 
                   mutate(Education=as.numeric(Education)) %>% 
                   filter(Education<100) %>% 
                   filter(Gender%in%c("Male", "Female")), 
               
                 iter = 20000, refresh = 1, chains = 2, cores = 2,
                 family="bernoulli")

saveRDS(mJacket, file = "index_cache/brms_exploratory/mJacket.rds")

mPlay <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + 
               (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
               data = Play %>% 
                 # Tidy
                 mutate(Age=as.numeric(Age)) %>%
                 filter(Age>0 & Age<99) %>% 
                 mutate(Education=as.numeric(Education)) %>% 
                 filter(Education<100) %>% 
                 filter(Gender%in%c("Male", "Female")) %>% 
                 mutate(condition=factor(condition, levels = c("ticket", "cash"))), 
               
               iter = 20000, refresh = 1, chains = 2, cores = 2,
               family="bernoulli")
saveRDS(mPlay, file = "index_cache/brms_exploratory/mPlay.rds")


mGym <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + 
              (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
            
              data = Gym %>% 
                # Tidy
                mutate(Age=as.numeric(Age)) %>%
                filter(Age>0 & Age<99) %>% 
                mutate(Education=as.numeric(Education)) %>% 
                filter(Education<100) %>% 
                filter(Gender%in%c("Male", "Female")),
            iter = 20000, refresh = 1, chains = 2, cores = 2)
saveRDS(mGym, file = "index_cache/brms_exploratory/mGym.rds")

mPlane <- brm(response ~ condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) + 
                (condition*(Age+Education+FinancialLiteracy+Gender+numeric_income) | Country),
              
                data = Plane %>% 
                  # Tidy
                  mutate(Age=as.numeric(Age)) %>%
                  filter(Age>0 & Age<99) %>% 
                  mutate(Education=as.numeric(Education)) %>% 
                  filter(Education<100) %>% 
                  filter(Gender%in%c("Male", "Female")), 
                
                iter = 20000, refresh = 1, chains = 2, cores = 2,
                 family="bernoulli")
saveRDS(mPlane, file = "index_cache/brms_exploratory/mPlane.rds")
Prepare plot
# re-run
library(stringi)

mMrAB1 <- readRDS("index_cache/brms_exploratory/mMrAB1.rds")
mMrAB2 <- readRDS("index_cache/brms_exploratory/mMrAB2.rds")
mGame <- readRDS("index_cache/brms_exploratory/mGame.rds")
mDrink <- readRDS("index_cache/brms_exploratory/mDrink.rds")
mJacket <- readRDS("index_cache/brms_exploratory/mJacket.rds")
mPlay <- readRDS("index_cache/brms_exploratory/mPlay.rds")
mGym <- readRDS("index_cache/brms_exploratory/mGym.rds")
mPlane <- readRDS("index_cache/brms_exploratory/mPlane.rds")
  
data = MrAB %>% 
  # Tidy
  mutate(Age=as.numeric(Age)) %>%
  filter(Age>0 & Age<99) %>% 
  mutate(Education=as.numeric(Education)) %>% 
  filter(Education<100) %>% 
  filter(Gender%in%c("Male", "Female")) %>% 
  mutate(condition_group=ifelse(
    condition %in% c("gain-gain VS gain", "gain-loss VS gain"),
    "gain",
    "loss"
  )) %>% 
  filter(condition_group=="gain") %>% 
  mutate(condition=factor(condition, levels = c("gain-loss VS gain", "gain-gain VS gain") )) %>% 
  group_by(subject) %>% filter(row_number()==1) %>% ungroup()
  

df_plot <- function(m, x, study_name){
  fe <- fixef(m) %>% as.data.frame()
  fe <- data.frame(beta=fe[,1], lower=fe[,3], upper=fe[,4], var=row.names(fe))
  
  # Bayes Factor
  draws_model <- as_draws(m)
  nm <- names(draws_model[[1]])[1:nrow(fe)]
  vars <- nm[ str_detect(nm, ":") ]
  # Age
  post_age <- lapply( 1:2, function(chain) draws_model[[chain]][vars[1]] ) %>% 
    unlist() %>% as.numeric() * sd(data$Age) 
  prior <- distribution_normal(length(post_age),mean=0,sd=1)
  bf_age <- bayesfactor_parameters(post_age,prior,direction="two-sided",null=0)
  log10_bf_age <- round(log10(as.numeric(bf_age)), 2)
  
  # Education
  post_education <- lapply( 1:2, function(chain) draws_model[[chain]][vars[2]] ) %>% 
    unlist() %>% as.numeric() * sd(data$Education)
  prior <- distribution_normal(length(post_education),mean=0,sd=1)
  bf_education <- bayesfactor_parameters(post_education,prior,direction="two-sided",null=0)
  log10_bf_education <- round(log10(as.numeric(bf_education)), 2)
  
  # Financial Literacy
  post_fintil <- lapply( 1:2, function(chain) draws_model[[chain]][vars[3]] ) %>% 
    unlist() %>% as.numeric() * sd(data$FinancialLiteracy)
  prior <- distribution_normal(length(post_fintil),mean=0,sd=1)
  bf_fintil <- bayesfactor_parameters(post_fintil,prior,direction="two-sided",null=0)
  log10_bf_fintil <- round(log10(as.numeric(bf_fintil)), 2)
  
  # Gender
  post_gender <- lapply( 1:2, function(chain) draws_model[[chain]][vars[4]] ) %>% 
    unlist() %>% as.numeric()
  prior <- distribution_normal(length(post_gender),mean=0,sd=1)
  bf_gender <- bayesfactor_parameters(post_gender,prior,direction="two-sided",null=0)
  log10_bf_gender <- round(log10(as.numeric(bf_gender)), 2)
  
  # Income
  post_income <- lapply( 1:2, function(chain) draws_model[[chain]][vars[5]] ) %>% 
    unlist() %>% as.numeric() * sd(data$numeric_income, na.rm = T)
  prior <- distribution_normal(length(post_income),mean=0,sd=1)
  bf_income <- bayesfactor_parameters(post_income,prior,direction="two-sided",null=0)
  log10_bf_income <- round(log10(as.numeric(bf_income)), 2)
  
  log10_bf <- c(log10_bf_age, log10_bf_education, log10_bf_fintil, log10_bf_gender, log10_bf_income)
  fe %>% 
    filter(stri_detect_fixed(var, ":")) %>% 
    mutate(var=sapply(str_split(var, ":"), function(x) x[2])) %>% 
    mutate(
      x=seq(x-0.2, x+0.2, length=5), 
      study=study_name,
      var=ifelse(var=="FinancialLiteracy", "Financial\nLiteracy",var),
      var=ifelse(var=="GenderMale", "Gender",var),
      var=ifelse(var=="numeric_income", "Income",var),
      `log₁₀(BF)` = log10_bf
      
    ) %>% 
    mutate(is_sign=ifelse(sign(lower)==sign(upper),"yes", "no"))
  
}

df_plot_MrAB <- function(m, x, study_name){
  fe <- fixef(m) %>% as.data.frame()
  fe <- data.frame(beta=fe[,1], lower=fe[,3], upper=fe[,4], var=row.names(fe))
  
  # Bayes Factor
  draws_model <- as_draws(m)
  nm <- names(draws_model[[1]])[1:nrow(fe)]
  vars <- nm[ 2:6 ]
  
  # Age
  post_age <- lapply( 1:2, function(chain) draws_model[[chain]][vars[1]] ) %>% 
    unlist() %>% as.numeric()
  prior <- distribution_normal(length(post_age),mean=0,sd=1)
  bf_age <- bayesfactor_parameters(post_age,prior,direction="two-sided",null=0)
  log10_bf_age <- round(log10(as.numeric(bf_age)), 2)
  
  # Education
  post_education <- lapply( 1:2, function(chain) draws_model[[chain]][vars[2]] ) %>% 
    unlist() %>% as.numeric()
  prior <- distribution_normal(length(post_education),mean=0,sd=1)
  bf_education <- bayesfactor_parameters(post_education,prior,direction="two-sided",null=0)
  log10_bf_education <- round(log10(as.numeric(bf_education)), 2)
  
  # Financial Literacy
  post_fintil <- lapply( 1:2, function(chain) draws_model[[chain]][vars[3]] ) %>% 
    unlist() %>% as.numeric()
  prior <- distribution_normal(length(post_fintil),mean=0,sd=1)
  bf_fintil <- bayesfactor_parameters(post_fintil,prior,direction="two-sided",null=0)
  log10_bf_fintil <- round(log10(as.numeric(bf_fintil)), 2)
  
  # Gender
  post_gender <- lapply( 1:2, function(chain) draws_model[[chain]][vars[4]] ) %>% 
    unlist() %>% as.numeric()
  prior <- distribution_normal(length(post_gender),mean=0,sd=1)
  bf_gender <- bayesfactor_parameters(post_gender,prior,direction="two-sided",null=0)
  log10_bf_gender <- round(log10(as.numeric(bf_gender)), 2)
  
  # Income
  post_income <- lapply( 1:2, function(chain) draws_model[[chain]][vars[5]] ) %>% 
    unlist() %>% as.numeric()
  prior <- distribution_normal(length(post_income),mean=0,sd=1)
  bf_income <- bayesfactor_parameters(post_income,prior,direction="two-sided",null=0)
  log10_bf_income <- round(log10(as.numeric(bf_income)), 2)
  
  log10_bf <- c(log10_bf_age, log10_bf_education, log10_bf_fintil, log10_bf_gender, log10_bf_income)
  fe[2:6,] %>% 
    mutate(
      x=seq(x-0.2, x+0.2, length=5), 
      study=study_name,
      var=ifelse(var=="FinancialLiteracy", "Financial\nLiteracy",var),
      var=ifelse(var=="GenderMale", "Gender",var),
      var=ifelse(var=="numeric_income", "Income",var),
      `log₁₀(BF)` = log10_bf
    ) %>% 
    mutate(is_sign=ifelse(sign(lower)==sign(upper),"yes", "no"))
  
}

df <- rbind(
  df_plot_MrAB(mMrAB1, 1.2, "MrAB1"),
  df_plot_MrAB(mMrAB2, 1.8, "MrAB2"),
  df_plot(mGame, 3, "Game"),
  df_plot(mJacket, 4, "Jacket"),
  df_plot(mPlay, 5, "Play"),
  df_plot(mPlane, 6, "Plane"),
  df_plot(mDrink, 7, "Drink"),
  df_plot(mGym, 8, "Gym")
) 
Plot posteriors
# re-run
df <- df %>% 
  mutate(is_sign=factor(is_sign, levels=c("yes", "no"))) %>% 
  # Age
  mutate(beta=ifelse(var=="Age" & !study%in%c("MrAB1", "MrAB2"), beta*sd(data$Age), beta)) %>% 
  mutate(lower=ifelse(var=="Age" & !study%in%c("MrAB1", "MrAB2"), lower*sd(data$Age), lower)) %>% 
  mutate(upper=ifelse(var=="Age" & !study%in%c("MrAB1", "MrAB2"), upper*sd(data$Age), upper)) %>% 
  # Education
  mutate(beta=ifelse(var=="Education" & !study%in%c("MrAB1", "MrAB2"), beta*sd(data$Education), beta)) %>% 
  mutate(lower=ifelse(var=="Education" & !study%in%c("MrAB1", "MrAB2"), lower*sd(data$Education), lower)) %>% 
  mutate(upper=ifelse(var=="Education" & !study%in%c("MrAB1", "MrAB2"), upper*sd(data$Education), upper)) %>% 
  # Financial Literacy
  mutate(beta=ifelse(var=="Financial\nLiteracy" & !study%in%c("MrAB1", "MrAB2"), beta*sd(data$FinancialLiteracy), beta)) %>% 
  mutate(lower=ifelse(var=="Financial\nLiteracy" & !study%in%c("MrAB1", "MrAB2"), lower*sd(data$FinancialLiteracy), lower)) %>% 
  mutate(upper=ifelse(var=="Financial\nLiteracy" & !study%in%c("MrAB1", "MrAB2"), upper*sd(data$FinancialLiteracy), upper)) %>% 
  # Income
  mutate(beta=ifelse(var=="Income" & !study%in%c("MrAB1", "MrAB2"), beta*sd(data$numeric_income, na.rm=T), beta)) %>% 
  mutate(lower=ifelse(var=="Income" & !study%in%c("MrAB1", "MrAB2"), lower*sd(data$numeric_income, na.rm=T), lower)) %>% 
  mutate(upper=ifelse(var=="Income" & !study%in%c("MrAB1", "MrAB2"), upper*sd(data$numeric_income, na.rm=T), upper)) %>% 
  
  mutate(x = x+rep(c(0.2, 0.1, 0, -0.1, -0.2), 8)) 
  
df %>% 
  mutate(study=ifelse( (study=="MrAB1" | study=="MrAB2"), "MrAB", study)) %>% 
  mutate(study=factor(study, labels = c("MrAB", "Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
                      levels = c("MrAB", "Game", "Jacket", "Play", "Plane", "Drink", "Gym"), 
                      )) %>% 
  ggplot(aes(x, beta, fill=var, color=study, linetype=is_sign)) +
  geom_hline(yintercept = 0, linewidth=0.2) +
  geom_segment(aes(x = x, xend=x, y=lower, yend=upper)) +
  geom_point(stat="identity", size=3) +
  theme_cowplot() +
  scale_x_continuous(breaks = c(1.5, 3:8), 
                     labels = c("MrAB", "Game", "Jacket", "Play", 
                                "Plane", "Drink", "Gym"),
                     guide = "prism_offset") +
  scale_y_continuous(guide = "prism_offset") + 
  labs(fill=NULL, x=NULL, y=expression(Standardized~beta), color="Study") +
  theme(legend.position = c(0.85, 0.25), 
        text = element_text(size = 15, family="Arial"), 
        # strip.background = element_rect(fill="#E2E2E2"),
        strip.background = element_rect(fill="#F9F9F9"),
        # axis.ticks.x = element_blank(), 
        axis.text.x = element_blank()) +
  guides(fill="none", alpha="none", shape="none", linetype="none") +
  facet_wrap(~var) +
  scale_color_manual(values = colorspace::qualitative_hcl(7, "Dark 3")[c(5, 2, 4, 7, 6, 1, 3)])

Code
# re-run
df_table <- df %>%
  rename(Estimate = beta,
         Variable = var) %>% 
  mutate(Estimate=round(Estimate,2),
         lower=round(lower,2),
         upper=round(upper,2),
         `CIs (95%)`=str_c(round(lower,2), round(upper,2), sep = ' - ')) %>% 
    select(study, Variable, Estimate, `CIs (95%)`, `log₁₀(BF)`)
  

reshape_df <- function(study_name){
  df = data.frame(a=study_name, b='', c='', d='', e='')
  names(df) <- names(df_table)
  
  rbind(
    df,
    df_table %>% filter(study==study_name) %>% mutate(study='')
  ) %>% rename(` `=study)  
}

map_dfr(unique(df_table$study), reshape_df) %>% 
  flextable() %>% 
  set_caption(caption = "Table : Exploratory Analysis") %>% 
  theme_apa() %>% 
  width(width=c(0.8, 1,1,1.5,1)) %>%
  
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>% 
  save_as_docx(path = "tables/Exploratory Analysis.docx")

map_dfr(unique(df_table$study), reshape_df) %>% 
  kbl(caption="<b>Table 4 | </b> Exploratory Analysis",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 4 | Exploratory Analysis
Variable Estimate CIs (95%) log₁₀(BF)
1...1 MrAB1
2 Age -0.06 -0.16 - 0.03 -0.91
3 Education 0.07 -0.01 - 0.15 -0.7
4 Financial Literacy 0.03 -0.05 - 0.12 -1.24
5 Gender 0.09 -0.08 - 0.25 -0.85
6 Income 0.03 -0.06 - 0.12 -1.27
1...7 MrAB2
21 Age -0.09 -0.19 - 0.01 -0.58
31 Education 0.1 0.01 - 0.2 -0.21
41 Financial Literacy 0.12 -0.03 - 0.25 -0.53
51 Gender -0.01 -0.2 - 0.17 -1.03
61 Income 0.11 0.01 - 0.21 -0.33
1...13 Game
11...14 Age -0.24 -0.31 - -0.16 3.35
22 Education -0.01 -0.08 - 0.07 -1.47
32 Financial Literacy 0.11 0.01 - 0.2 -0.28
42 Gender 0.21 0.05 - 0.38 0.28
52 Income 0.13 0.04 - 0.21 0.4
1...19 Jacket
11...20 Age -0.08 -0.18 - 0.02 -0.7
23 Education 0.03 -0.06 - 0.12 -1.27
33 Financial Literacy 0.02 -0.07 - 0.12 -1.26
43 Gender -0.04 -0.24 - 0.15 -0.96
53 Income -0.06 -0.16 - 0.04 -0.99
1...25 Play
12 Age -0.06 -0.16 - 0.04 -1.01
24 Education 0.07 -0.02 - 0.17 -0.79
34 Financial Literacy 0.1 0 - 0.2 -0.44
44 Gender -0.02 -0.22 - 0.19 -0.98
54 Income 0.03 -0.08 - 0.14 -1.19
1...31 Plane
13 Age -0.04 -0.14 - 0.06 -1.16
25 Education 0.02 -0.07 - 0.12 -1.27
35 Financial Literacy 0.01 -0.09 - 0.12 -1.27
45 Gender -0.29 -0.49 - -0.09 0.72
55 Income 0.06 -0.05 - 0.17 -0.97
1...37 Drink
14 Age -0.08 -0.12 - -0.03 0.37
26 Education -0.02 -0.06 - 0.02 -1.39
36 Financial Literacy 0 -0.05 - 0.05 -1.61
46 Gender -0.05 -0.14 - 0.05 -1.09
56 Income 0.04 -0.01 - 0.08 -1.13
1...43 Gym
15 Age -0.08 -0.13 - -0.02 0.14
27 Education 0.02 -0.02 - 0.07 -1.41
37 Financial Literacy 0.07 0.02 - 0.12 0.05
47 Gender 0 -0.08 - 0.08 -1.38
57 Income 0.03 -0.02 - 0.08 -1.24
Show plot code
Jacket %>% 
  filter(condition==first(Jacket$condition)) %>% 
  mutate(Age=as.numeric(Age)) %>%
  filter(Age>18 & Age<99) %>% 
  ggplot(aes(Age, Country, color=Country)) +
  geom_boxplot(width = 0.5) +
  geom_jitter(alpha=0.1, width = 0.3, height = 0.2) +
  theme_pubr() + 
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.y = element_text(size = 15),
        legend.position = "none") +
  scale_color_manual(values = color_21countries) +
  labs(y=NULL)

Show plot code
Jacket %>% 
  # Tidy
  filter(condition==first(Jacket$condition)) %>% 
  mutate(Age=as.numeric(Age)) %>%
  filter(Age>0 & Age<99) %>% 
  mutate(Education=as.numeric(Education)) %>% 
  filter(Education<100) %>% 
  # Plot
  ggplot(aes(Education, Country, color=Country)) +
  geom_boxplot(width = 0.5) +
  geom_jitter(alpha=0.1, width = 0.3, height = 0.2) +
  scale_color_manual(values = color_21countries) +
  theme_pubr() +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.y = element_text(size = 15),
        legend.position = "none") +
  labs(y=NULL) 

Show plot code
Jacket %>% 
  # Tidy
  filter(condition==first(Jacket$condition)) %>% 
  mutate(Age=as.numeric(Age)) %>%
  filter(Age>0 & Age<99) %>% 
  mutate(Education=as.numeric(Education)) %>% 
  filter(Education<100) %>% 
  filter(Gender!="Prefer not to say") %>% 
  group_by(Country) %>% 
  summarise(pMale = mean(ifelse(Gender=='Male', 1, 0))) %>% 
  # Plot
  ggplot(aes(pMale, Country, fill=Country)) +
  geom_bar(stat = "identity", width=0.8) +
  geom_boxplot(width = 0.5) +
  scale_fill_manual(values = color_21countries) +
  theme_pubr() +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.y = element_text(size = 15),
        legend.position = "none") +
  labs(x="Proportion of Male", y=NULL)

Show plot code
Jacket %>% 
  # Tidy
  filter(condition==first(Jacket$condition)) %>% 
  mutate(Age=as.numeric(Age)) %>%
  filter(Age>0 & Age<99) %>% 
  mutate(Education=as.numeric(Education)) %>% 
  filter(Education<100) %>% 
  # Plot
  ggplot(aes(numeric_income, Country, color=Country)) +
  geom_jitter(alpha=0.1, width = 0.2, height = 0.2) +
  scale_color_manual(values = color_21countries) +
  theme_pubr() +
  guides(size = "none") + 
  theme(text = element_text(size = 15),
        axis.text.y = element_text(size = 15),
        legend.position = "none") +
  labs(y=NULL, x="Income") +
  scale_x_continuous(breaks = 0:5)

Show plot code
plotlyDat <- data_MrAB %>% 
  group_by(Country, subject) %>% 
  filter(row_number()==1) %>% 
  group_by(Country) %>%
  mutate(N=n()) %>% 
  group_by(Country, FinancialLiteracy) %>% 
  summarise(fqFinLit = n()/N) %>% ungroup()

nCountries <- length(unique(plotlyDat$Country))

fig <- plot_ly(plotlyDat,  type = 'scatter', mode = 'lines',
               x = ~FinancialLiteracy, y = ~fqFinLit, color = ~Country, 
               colors = viridis::viridis_pal()(nCountries)) %>% 
  add_trace(line=list(width = 4)) %>% 
  layout(xaxis = list(title = "Financial Literacy Score", 
                      range=c(-0.5,4.5), zeroline = F, showgrid = FALSE),
         font = list(size=20),
         yaxis = list(title = "Proportion", showgrid = FALSE))

fig

Within-Person Correlation

Prepare Data
# --- MrAB --- #
# - Gain
mrab1_bias <- data_MrAB %>% 
  rename(condition=scenario) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  filter( scenario_group == "gain" ) %>% 
  group_by( subject ) %>% 
  summarise(MrAB1 = ifelse(
    (response[condition=="gain-gain VS gain"]==1) && (response[condition=="gain-loss VS gain"]==0), 1, 0
  ) ) %>% 
  ungroup()

# - Loss
mrab2_bias <- data_MrAB %>% 
  rename(condition=scenario) %>% 
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  filter( scenario_group == "loss" ) %>% 
  group_by( subject ) %>% 
  summarise(MrAB2 = ifelse(
    (response[condition=="loss-loss VS loss"]==1) && (response[condition=="loss-gain VS loss"]==0), 1, 0
    )
  ) %>% 
  ungroup()

# --- Game --- #
game_bias <- Game %>% 
  group_by(subject) %>% 
  reframe(bias = as.integer( response[condition=="Stranger"] > response[condition=="Friend"] ) ) %>% 
  group_by(subject) %>% 
  reframe(Game = mean(bias)) %>% 
  ungroup()

# --- Drink--- #
Drink <- data_Drink %>% 
  # EXCLUSION: Full Exclusion
  filter( !(Country %in% countries2remove) ) %>% 
  filter( attention_check_grater_than_3 ) %>% 
  # Remove really really extreme outliers
  mutate(response = ifelse(response<10000 & response>=0, response, NA)) %>% 
  mutate(response=response+1, logResp=log(response)) %>% 
  group_by(Country) %>%
  mutate(response=as.vector(scale(logResp))) %>% 
  rename(condition=store) %>% 
  ungroup()

drink_bias <- Drink %>% 
  # filter(subject=="R_YbiZdXhcwrYYiUF") %>% 
  group_by(subject) %>%
  reframe(Drink = response[condition=="Resort Hotel"] - response[condition=="Grocery Store"] ) %>% 
  ungroup() %>% 
  mutate(Drink = as.vector(scale(Drink)))

# --- Jacket--- #
jacket_bias <- Jacket %>% 
  # filter(subject=="R_YbiZdXhcwrYYiUF") %>%
  group_by(subject) %>%
  summarise(Jacket = as.integer( response[condition=="low"] > response[condition=="high"] ) ) %>% 
  ungroup()

# --- Play --- #
play_bias <- Play %>% 
  group_by(subject) %>% 
  summarise(Play = as.integer( response[condition=="cash"] > response[condition=="ticket"] ) ) %>% 
  ungroup()


# --- Gym--- #
gym_bias <- Gym %>% 
  group_by(subject) %>%
  reframe(Gym = response[condition=="Yearly"] - response[condition=="Per-session"] ) %>% 
  ungroup() %>% 
  mutate(Gym=as.vector(scale(Gym)))

# --- Plane--- #
plane_bias <- Plane %>% 
  # filter(subject=="R_YbiZdXhcwrYYiUF") %>%
  group_by(subject) %>% 
  reframe(Plane = as.integer( response[condition=="purchased"] > response[condition=="free"] ) )
Plot correlations
list_of_dfs <- list(mrab1_bias, mrab2_bias, game_bias, drink_bias, jacket_bias, play_bias, gym_bias, plane_bias)
df_bias <- reduce(list_of_dfs, ~inner_join(.x, .y, by = "subject"))

library(corrplot)
M = cor( as.matrix( na.omit(df_bias[,2:9]) ) )
testRes = cor.mtest(df_bias[2:9], conf.level = 0.95)

num_colors_each_side <- 150  # Number of colors from blue to white and from white to red


custom_palette <- c(
  rep("#053061", 300),
  colorRampPalette(c("#053061", "white"))(num_colors_each_side),
  colorRampPalette(c("white", "#67001F"))(num_colors_each_side),  # Exclude the first white since we already have it from the blue-to-white transition
  rep("#67001F", 300)
)

corrplot(M * (1-diag(8)), p.mat = testRes$p, method = 'color', diag = FALSE, type = 'lower',
         sig.level = c(0.001, 0.01, 0.05), pch.cex = 0.9, col.lim=c(-0.3, 0.3), 
         insig = 'label_sig', pch.col = 'grey20',
         col = custom_palette,  tl.col = 'black', tl.srt = 45, tl.offset = 0.8)

Code
stars <- ifelse(testRes$p < 0.001, "***", ifelse(testRes$p < 0.01, "**", ifelse(testRes$p < 0.05, "*", "")))
m_text <- matrix(paste0( round(M,2), stars), 8, 8)
m_text[upper.tri(m_text)] <- ""
m_text[ as.logical(diag(8)) ] <- ""
colnames(m_text) <- colnames(M)
row.names(m_text) <- colnames(M)

as.data.frame(m_text)[2:8,1:7] %>%
  rownames_to_column(" ") %>% 
  flextable() %>% 
  set_caption(caption = "Table 6: Correlations of Mental Accounting") %>% 
  theme_apa() %>% 
  padding(padding.top = 0, padding.bottom = 0, part = "all") %>%
  align(align='left') %>% 
  align(align='left', part='header') %>%
  save_as_docx(path = "tables/within-person correlation.docx")


as.data.frame(m_text)[2:8,1:7] %>%
  rownames_to_column(" ") %>% 
  kbl(caption="<b>Table 6 | </b> Correlations of Mental Accounting",
      format = "html", table.attr = "style='width:50%;'") %>% 
  kable_classic(html_font = "Cambria") %>% 
  kable_material(c("striped", "hover"))
Table 6 | Correlations of Mental Accounting
MrAB1 MrAB2 Game Drink Jacket Play Gym
MrAB2 0.27***
Game 0.05** 0.09***
Drink 0.02 0.07*** 0.06***
Jacket 0.03 0 0.02 0.03*
Play 0.02 0.04** 0.06*** 0.01 0.03**
Gym 0.03 0.1*** 0.14*** 0.07*** 0.07*** 0.13***
Plane 0 0.03 0.02 0.09*** 0.01 0.03* 0.06***