# Loading required package, setting working directory, and reading the data file.
require(psych)
## Loading required package: psych
require(BayesFactor)
## Loading required package: BayesFactor
## Loading required package: coda
## Loading required package: Matrix
## ************
## Welcome to BayesFactor 0.9.12-2. If you have questions, please contact Richard Morey (richarddmorey@gmail.com).
## 
## Type BFManual() to open the manual.
## ************
setwd("/Users/ivanropovik/OneDrive/MANUSCRIPTS/2016 Many Labs 5/Pilot 1/Analyses/")
pilot1 <- read.csv(file = "Pilot_1_Kozminski.csv", header = TRUE, sep = ";")

# Computing means of the two scale items for each scenario
# If one of the two target items is missing,
# the score of the other item is used as the estimate for the given scenario
pilot1$scenario1_Q3 <- rowMeans(pilot1[,c("Q9", "Q12")], na.rm = TRUE)
pilot1$scenario2_Q15 <- rowMeans(pilot1[,c("Q20", "Q23")], na.rm = TRUE)
pilot1$scenario3_Q26 <- rowMeans(pilot1[,c("Q31", "Q34")], na.rm = TRUE)
#pilot1$scenario4_Q239 <- rowMeans(pilot1[,c("Q244", "Q247")], na.rm = TRUE)
pilot1$scenario5_Q37 <- rowMeans(pilot1[,c("Q42", "Q45")], na.rm = TRUE)
#pilot1$scenario6_Q250 <- rowMeans(pilot1[,c("Q255", "Q258")], na.rm = TRUE)
pilot1$scenario7_Q48 <- rowMeans(pilot1[,c("Q53", "Q56")], na.rm = TRUE)
pilot1$scenario8_Q59 <- rowMeans(pilot1[,c("Q64", "Q67")], na.rm = TRUE)
#pilot1$scenario9_Q261 <- rowMeans(pilot1[,c("Q266", "Q269")], na.rm = TRUE)
pilot1$scenario10_Q81 <- rowMeans(pilot1[,c("Q86", "Q89")], na.rm = TRUE)
pilot1$scenario11_Q92 <- rowMeans(pilot1[,c("Q97", "Q100")], na.rm = TRUE)
pilot1$scenario12_Q103 <- rowMeans(pilot1[,c("Q108", "Q111")], na.rm = TRUE)
#pilot1$scenario13_Q272 <- rowMeans(pilot1[,c("Q277", "Q280")], na.rm = TRUE)
#pilot1$scenario14_Q283 <- rowMeans(pilot1[,c("Q288", "Q291")], na.rm = TRUE)
pilot1$scenario15_Q114 <- rowMeans(pilot1[,c("Q119", "Q122")], na.rm = TRUE)
#pilot1$scenario16_Q228 <- rowMeans(pilot1[,c("Q233", "Q236")], na.rm = TRUE)
pilot1$scenario17_Q125 <- rowMeans(pilot1[,c("Q130", "Q133")], na.rm = TRUE)
pilot1$scenario18_Q136 <- rowMeans(pilot1[,c("Q141", "Q144")], na.rm = TRUE)
pilot1$scenario19_Q147 <- rowMeans(pilot1[,c("Q152", "Q155")], na.rm = TRUE)
pilot1$scenario20_Q158 <- rowMeans(pilot1[,c("Q163", "Q166")], na.rm = TRUE)
pilot1$scenario21_Q169 <- rowMeans(pilot1[,c("Q174", "Q177")], na.rm = TRUE)

# Sample size
nrow(pilot1)
## [1] 52
# Frequencies for demographic variables
# Q180 = Gender
# Q181 = Year of study
# Q182 = Age
lapply(pilot1[,c("Q180", "Q181", "Q182")],
       function(x){table(x, useNA = "ifany")})
## $Q180
## x
##  1  2 
## 31 21 
## 
## $Q181
## x
##  1  2  3  4  5 
##  1 37  6  5  3 
## 
## $Q182
## x
##   18   19   20   21   22   23   24   29 <NA> 
##    1    1   21   18    5    3    1    1    1
# Descriptive statistics for each scenario
lapply(pilot1[,c("scenario1_Q3", "scenario2_Q15", "scenario3_Q26", "scenario5_Q37",
                 "scenario7_Q48", "scenario8_Q59", "scenario10_Q81", "scenario11_Q92",
                 "scenario12_Q103", "scenario15_Q114", "scenario17_Q125", "scenario18_Q136",
                 "scenario19_Q147", "scenario20_Q158", "scenario21_Q169")],
       function(x){describe(x, na.rm = TRUE, fast = TRUE)})
## $scenario1_Q3
##    vars  n mean   sd min max range   se
## X1    1 51    5 1.37 1.5   9   7.5 0.19
## 
## $scenario2_Q15
##    vars  n mean   sd min max range   se
## X1    1 52 5.97 1.62   3   9     6 0.22
## 
## $scenario3_Q26
##    vars  n mean   sd min max range   se
## X1    1 51 4.86 1.85   1   9     8 0.26
## 
## $scenario5_Q37
##    vars  n mean   sd min max range   se
## X1    1 50 5.89 1.83   2   9     7 0.26
## 
## $scenario7_Q48
##    vars  n mean  sd min max range   se
## X1    1 50 5.29 1.2   3   9     6 0.17
## 
## $scenario8_Q59
##    vars  n mean   sd min max range  se
## X1    1 50 6.66 2.11   1   9     8 0.3
## 
## $scenario10_Q81
##    vars  n mean   sd min max range   se
## X1    1 51 5.77 1.66   3   9     6 0.23
## 
## $scenario11_Q92
##    vars  n mean   sd min max range   se
## X1    1 50 5.11 2.01   1   9     8 0.28
## 
## $scenario12_Q103
##    vars  n mean   sd min max range   se
## X1    1 52 6.04 1.92   1   9     8 0.27
## 
## $scenario15_Q114
##    vars  n mean   sd min max range   se
## X1    1 49  4.7 1.62   1   9     8 0.23
## 
## $scenario17_Q125
##    vars  n mean  sd min max range   se
## X1    1 50 5.79 1.9 2.5   9   6.5 0.27
## 
## $scenario18_Q136
##    vars  n mean   sd min max range   se
## X1    1 49 4.81 1.84   1   9     8 0.26
## 
## $scenario19_Q147
##    vars  n mean   sd min max range   se
## X1    1 51 4.54 1.91   1   9     8 0.27
## 
## $scenario20_Q158
##    vars  n mean   sd min max range   se
## X1    1 52 4.82 1.61   1   9     8 0.22
## 
## $scenario21_Q169
##    vars  n mean   sd min max range   se
## X1    1 50 5.99 1.83 2.5   9   6.5 0.26
# One-sample t-test for each scenario with population parameter mu set at 5.
lapply(pilot1[,c("scenario1_Q3", "scenario2_Q15", "scenario3_Q26", "scenario5_Q37",
                 "scenario7_Q48", "scenario8_Q59", "scenario10_Q81", "scenario11_Q92",
                 "scenario12_Q103", "scenario15_Q114", "scenario17_Q125", "scenario18_Q136",
                 "scenario19_Q147", "scenario20_Q158", "scenario21_Q169")],
       function(x){t.test(x, data = pilot1, mu = 5, na.rm = TRUE)})
## $scenario1_Q3
## 
##  One Sample t-test
## 
## data:  x
## t = 0, df = 50, p-value = 1
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.614363 5.385637
## sample estimates:
## mean of x 
##         5 
## 
## 
## $scenario2_Q15
## 
##  One Sample t-test
## 
## data:  x
## t = 4.3332, df = 51, p-value = 6.91e-05
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.521219 6.421089
## sample estimates:
## mean of x 
##  5.971154 
## 
## 
## $scenario3_Q26
## 
##  One Sample t-test
## 
## data:  x
## t = -0.5292, df = 50, p-value = 0.599
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.341795 5.383695
## sample estimates:
## mean of x 
##  4.862745 
## 
## 
## $scenario5_Q37
## 
##  One Sample t-test
## 
## data:  x
## t = 3.4437, df = 49, p-value = 0.001185
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.370635 6.409365
## sample estimates:
## mean of x 
##      5.89 
## 
## 
## $scenario7_Q48
## 
##  One Sample t-test
## 
## data:  x
## t = 1.703, df = 49, p-value = 0.0949
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.947794 5.632206
## sample estimates:
## mean of x 
##      5.29 
## 
## 
## $scenario8_Q59
## 
##  One Sample t-test
## 
## data:  x
## t = 5.5558, df = 49, p-value = 1.123e-06
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  6.059566 7.260434
## sample estimates:
## mean of x 
##      6.66 
## 
## 
## $scenario10_Q81
## 
##  One Sample t-test
## 
## data:  x
## t = 3.3274, df = 50, p-value = 0.00165
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.306989 6.242030
## sample estimates:
## mean of x 
##   5.77451 
## 
## 
## $scenario11_Q92
## 
##  One Sample t-test
## 
## data:  x
## t = 0.3868, df = 49, p-value = 0.7006
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.538505 5.681495
## sample estimates:
## mean of x 
##      5.11 
## 
## 
## $scenario12_Q103
## 
##  One Sample t-test
## 
## data:  x
## t = 3.9011, df = 51, p-value = 0.0002813
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.504049 6.572874
## sample estimates:
## mean of x 
##  6.038462 
## 
## 
## $scenario15_Q114
## 
##  One Sample t-test
## 
## data:  x
## t = -1.2787, df = 48, p-value = 0.2071
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.238785 5.169378
## sample estimates:
## mean of x 
##  4.704082 
## 
## 
## $scenario17_Q125
## 
##  One Sample t-test
## 
## data:  x
## t = 2.9346, df = 49, p-value = 0.00507
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.249027 6.330973
## sample estimates:
## mean of x 
##      5.79 
## 
## 
## $scenario18_Q136
## 
##  One Sample t-test
## 
## data:  x
## t = -0.73667, df = 48, p-value = 0.4649
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.276964 5.335281
## sample estimates:
## mean of x 
##  4.806122 
## 
## 
## $scenario19_Q147
## 
##  One Sample t-test
## 
## data:  x
## t = -1.7204, df = 50, p-value = 0.09154
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.001259 5.077172
## sample estimates:
## mean of x 
##  4.539216 
## 
## 
## $scenario20_Q158
## 
##  One Sample t-test
## 
## data:  x
## t = -0.81729, df = 51, p-value = 0.4176
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.368543 5.266072
## sample estimates:
## mean of x 
##  4.817308 
## 
## 
## $scenario21_Q169
## 
##  One Sample t-test
## 
## data:  x
## t = 3.8353, df = 49, p-value = 0.0003588
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.47127 6.50873
## sample estimates:
## mean of x 
##      5.99
# Bayes factor in favour of the null (BF01) for each scenario
# with population parameter mu set at 5 and prior width of 0.5.
lapply(pilot1[,c("scenario1_Q3", "scenario2_Q15", "scenario3_Q26", "scenario5_Q37",
                 "scenario7_Q48", "scenario8_Q59", "scenario10_Q81", "scenario11_Q92",
                 "scenario12_Q103", "scenario15_Q114", "scenario17_Q125", "scenario18_Q136",
                 "scenario19_Q147", "scenario20_Q158", "scenario21_Q169")],
       function(x){1/ttestBF(x[!is.na(x)], mu = 5, rscale = 0.5,  na.rm = TRUE)})
## $scenario1_Q3
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 4.785326 ±0.04%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario2_Q15
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.003060549 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario3_Q26
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 4.219296 ±0.01%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario5_Q37
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.03712297 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario7_Q48
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 1.328027 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario8_Q59
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 7.27325e-05 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario10_Q81
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.04956036 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario11_Q92
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 4.435315 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario12_Q103
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.01064857 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario15_Q114
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 2.279411 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario17_Q125
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.1282007 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario18_Q136
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 3.688975 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario19_Q147
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 1.302357 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario20_Q158
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 3.576393 ±0.01%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario21_Q169
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.01311812 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS