library(here)
## here() starts at /Users/caoanjie/Desktop/projects/CCRR-CogSci
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.3 ✓ purrr 0.3.4
## ✓ tibble 3.1.0 ✓ dplyr 1.0.5
## ✓ tidyr 1.1.1 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.4.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(BayesFactor)
## Loading required package: coda
## Loading required package: Matrix
##
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
##
## expand, pack, unpack
## ************
## Welcome to BayesFactor 0.9.12-4.2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
##
## Type BFManual() to open the manual.
## ************
library(brms)
## Loading required package: Rcpp
## Loading 'brms' package (version 2.15.0). Useful instructions
## can be found by typing help('brms'). A more detailed introduction
## to the package is available through vignette('brms_overview').
##
## Attaching package: 'brms'
## The following object is masked from 'package:stats':
##
## ar
d <- read_csv(here("main/cogsci_data/tidy_main.csv"))
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_double(),
## subject = col_character(),
## culture = col_character(),
## task_name = col_character(),
## task_info = col_character(),
## trial_info = col_double(),
## resp_type = col_character(),
## resp = col_double()
## )
## Warning: 16937 parsing failures.
## row col expected actual file
## 8705 trial_info a double RMTS '/Users/caoanjie/Desktop/projects/CCRR-CogSci/main/cogsci_data/tidy_main.csv'
## 8706 trial_info a double RMTS '/Users/caoanjie/Desktop/projects/CCRR-CogSci/main/cogsci_data/tidy_main.csv'
## 8707 trial_info a double RMTS '/Users/caoanjie/Desktop/projects/CCRR-CogSci/main/cogsci_data/tidy_main.csv'
## 8708 trial_info a double RMTS '/Users/caoanjie/Desktop/projects/CCRR-CogSci/main/cogsci_data/tidy_main.csv'
## 8709 trial_info a double RMTS '/Users/caoanjie/Desktop/projects/CCRR-CogSci/main/cogsci_data/tidy_main.csv'
## .... .......... ........ ...... .............................................................................
## See problems(...) for more details.
load(here("main/cogsci_data/bayesian_model_fit.RData"))
summary(full_b_rmts_model)
## Family: binomial
## Links: mu = logit
## Formula: choice ~ culture + (1 | subject)
## Data: rmts_df (Number of observations: 1024)
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
## total post-warmup samples = 4000
##
## Group-Level Effects:
## ~subject (Number of levels: 256)
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept) 1.10 0.11 0.90 1.32 1.00 1278 1983
##
## Population-Level Effects:
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept 1.02 0.12 0.78 1.27 1.00 2303 2897
## cultureUS -0.17 0.18 -0.52 0.17 1.00 2382 3029
##
## Samples were drawn 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).
plot(full_b_rmts_model)
plot(conditional_effects(full_b_rmts_model))
## Using the maximum response value as the number of trials.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Using the maximum response value as the number of trials.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
### bayes factor
BF_RMTS = bayes_factor(full_b_rmts_model, null_b_rmts_model)
## Using the maximum response value as the number of trials.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Using the maximum response value as the number of trials.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Iteration: 1
## Iteration: 2
## Iteration: 3
## Iteration: 4
## Iteration: 5
## Iteration: 6
## Iteration: 7
## Iteration: 8
## Iteration: 9
## Iteration: 10
## Iteration: 11
## Iteration: 12
## Iteration: 13
## Iteration: 14
## Iteration: 15
## Iteration: 16
## Iteration: 17
## Iteration: 18
## Iteration: 19
## Iteration: 20
## Iteration: 21
## Iteration: 22
## Iteration: 23
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Iteration: 1
## Iteration: 2
## Iteration: 3
## Iteration: 4
## Iteration: 5
## Iteration: 6
## Iteration: 7
## Iteration: 8
## Iteration: 9
## Iteration: 10
## Iteration: 11
## Iteration: 12
## Iteration: 13
## Iteration: 14
## Iteration: 15
BF_RMTS$bf
## [1] 0.351067
BF_fd_firstmention = bayes_factor(full_b_fd_firstmention_model, null_b_fd_firstmention_model)
## Using the maximum response value as the number of trials.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Using the maximum response value as the number of trials.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Iteration: 1
## Iteration: 2
## Iteration: 3
## Iteration: 4
## Iteration: 5
## Iteration: 6
## Iteration: 7
## Iteration: 8
## Iteration: 9
## Iteration: 10
## Iteration: 11
## Iteration: 12
## Iteration: 13
## Iteration: 14
## Warning: Using 'binomial' families without specifying 'trials' on the left-hand
## side of the model formula is deprecated.
## Iteration: 1
## Iteration: 2
## Iteration: 3
## Iteration: 4
## Iteration: 5
## Iteration: 6
## Iteration: 7
## Iteration: 8
## Iteration: 9
## Iteration: 10
## Iteration: 11
## Iteration: 12
## Iteration: 13
BF_fd_firstmention$bf
## [1] 7.92654e+17
summary(full_b_fd_firstmention_model)
## Family: binomial
## Links: mu = logit
## Formula: first_mention ~ culture + (1 | subject)
## Data: mention_df (Number of observations: 2681)
## Samples: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
## total post-warmup samples = 4000
##
## Group-Level Effects:
## ~subject (Number of levels: 232)
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept) 1.87 0.15 1.59 2.17 1.01 1001 1901
##
## Population-Level Effects:
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept 0.35 0.16 0.04 0.66 1.00 728 1526
## cultureUS 3.08 0.36 2.42 3.81 1.00 1232 2338
##
## Samples were drawn 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).
plot(full_b_fd_firstmention_model)
fd_imada <- d %>%
filter(task_name == "FD") %>%
filter(grepl("imada", resp_type)) %>%
mutate(description_num = as.numeric(resp),
scene = trial_info,
description_type = factor(resp_type)) %>%
select(-resp, -task_info, -resp_type, -trial_info)