# 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+ManyLabs5+Bamberg.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] 51
# 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 <NA> 
##   31    4   16 
## 
## $Q181
## x
##                               1              1.     1. Bachelor 
##              15              15               2               1 
## 1. Fachsemester               3 3. Fachsemester              4. 
##               1              13               1               1 
##               5               7 
##               1               1 
## 
## $Q182
## x
##   18   19   20   21   22   24   29   31   35   42   46 <NA> 
##    6    6   10    3    3    2    2    1    1    1    1   15
# 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", "scenario16_Q228", "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 38 5.54 1.81   1   9     8 0.29
## 
## $scenario2_Q15
##    vars  n mean   sd min max range   se
## X1    1 38 5.87 1.76 2.5   9   6.5 0.29
## 
## $scenario3_Q26
##    vars  n mean  sd min max range   se
## X1    1 39 4.01 1.5   1   7     6 0.24
## 
## $scenario5_Q37
##    vars  n mean   sd min max range   se
## X1    1 38 5.67 1.68   1   9     8 0.27
## 
## $scenario7_Q48
##    vars  n mean   sd min max range  se
## X1    1 39  5.4 1.26   2   8     6 0.2
## 
## $scenario8_Q59
##    vars  n mean  sd min max range  se
## X1    1 39 7.53 1.9   1   9     8 0.3
## 
## $scenario10_Q81
##    vars  n mean   sd min max range   se
## X1    1 38 5.61 1.95   1 8.5   7.5 0.32
## 
## $scenario11_Q92
##    vars  n mean   sd min max range   se
## X1    1 36 6.24 2.11   2   9     7 0.35
## 
## $scenario12_Q103
##    vars  n mean   sd min max range   se
## X1    1 39 5.28 2.38   1   9     8 0.38
## 
## $scenario15_Q114
##    vars  n mean   sd min max range   se
## X1    1 37 4.03 1.59   1   7     6 0.26
## 
## $scenario16_Q228
##    vars  n mean   sd min max range   se
## X1    1 37 6.42 1.43   3   9     6 0.24
## 
## $scenario17_Q125
##    vars  n mean   sd min max range  se
## X1    1 38 6.11 1.86 1.5   9   7.5 0.3
## 
## $scenario18_Q136
##    vars  n mean   sd min max range   se
## X1    1 38 4.46 2.31   1   9     8 0.37
## 
## $scenario19_Q147
##    vars  n mean   sd min max range   se
## X1    1 36 4.57 1.93   1 7.5   6.5 0.32
## 
## $scenario20_Q158
##    vars  n mean   sd min max range   se
## X1    1 39 5.26 2.27   1   9     8 0.36
## 
## $scenario21_Q169
##    vars  n mean   sd min max range   se
## X1    1 37 6.42 1.71   1   9     8 0.28
# 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", "scenario16_Q228", "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 = 1.8337, df = 37, p-value = 0.07475
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.943377 6.135571
## sample estimates:
## mean of x 
##  5.539474 
## 
## 
## $scenario2_Q15
## 
##  One Sample t-test
## 
## data:  x
## t = 3.0386, df = 37, p-value = 0.004344
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.289341 6.447501
## sample estimates:
## mean of x 
##  5.868421 
## 
## 
## $scenario3_Q26
## 
##  One Sample t-test
## 
## data:  x
## t = -4.1161, df = 38, p-value = 0.0001998
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  3.527306 4.498335
## sample estimates:
## mean of x 
##  4.012821 
## 
## 
## $scenario5_Q37
## 
##  One Sample t-test
## 
## data:  x
## t = 2.4598, df = 37, p-value = 0.0187
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.118297 6.223808
## sample estimates:
## mean of x 
##  5.671053 
## 
## 
## $scenario7_Q48
## 
##  One Sample t-test
## 
## data:  x
## t = 1.9656, df = 38, p-value = 0.05669
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.988109 5.806763
## sample estimates:
## mean of x 
##  5.397436 
## 
## 
## $scenario8_Q59
## 
##  One Sample t-test
## 
## data:  x
## t = 8.2925, df = 38, p-value = 4.727e-10
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  6.909072 8.142210
## sample estimates:
## mean of x 
##  7.525641 
## 
## 
## $scenario10_Q81
## 
##  One Sample t-test
## 
## data:  x
## t = 1.9108, df = 37, p-value = 0.06381
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.963434 6.247092
## sample estimates:
## mean of x 
##  5.605263 
## 
## 
## $scenario11_Q92
## 
##  One Sample t-test
## 
## data:  x
## t = 3.5216, df = 35, p-value = 0.001214
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.523521 6.948701
## sample estimates:
## mean of x 
##  6.236111 
## 
## 
## $scenario12_Q103
## 
##  One Sample t-test
## 
## data:  x
## t = 0.73897, df = 38, p-value = 0.4645
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.509380 6.054722
## sample estimates:
## mean of x 
##  5.282051 
## 
## 
## $scenario15_Q114
## 
##  One Sample t-test
## 
## data:  x
## t = -3.7128, df = 36, p-value = 0.0006905
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  3.495553 4.558501
## sample estimates:
## mean of x 
##  4.027027 
## 
## 
## $scenario16_Q228
## 
##  One Sample t-test
## 
## data:  x
## t = 6.0299, df = 36, p-value = 6.339e-07
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.941679 6.896159
## sample estimates:
## mean of x 
##  6.418919 
## 
## 
## $scenario17_Q125
## 
##  One Sample t-test
## 
## data:  x
## t = 3.6549, df = 37, p-value = 0.0007937
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.492528 6.717999
## sample estimates:
## mean of x 
##  6.105263 
## 
## 
## $scenario18_Q136
## 
##  One Sample t-test
## 
## data:  x
## t = -1.4387, df = 37, p-value = 0.1586
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  3.700758 5.220295
## sample estimates:
## mean of x 
##  4.460526 
## 
## 
## $scenario19_Q147
## 
##  One Sample t-test
## 
## data:  x
## t = -1.34, df = 35, p-value = 0.1889
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  3.917166 5.221723
## sample estimates:
## mean of x 
##  4.569444 
## 
## 
## $scenario20_Q158
## 
##  One Sample t-test
## 
## data:  x
## t = 0.70429, df = 38, p-value = 0.4855
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  4.519387 5.993434
## sample estimates:
## mean of x 
##   5.25641 
## 
## 
## $scenario21_Q169
## 
##  One Sample t-test
## 
## data:  x
## t = 5.0476, df = 36, p-value = 1.299e-05
## alternative hypothesis: true mean is not equal to 5
## 95 percent confidence interval:
##  5.848806 6.989032
## sample estimates:
## mean of x 
##  6.418919
# 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", "scenario16_Q228", "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 : 1.015058 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario2_Q15
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.1063537 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario3_Q26
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.007636963 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario5_Q37
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.3494989 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario7_Q48
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.8328306 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario8_Q59
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 5.342173e-08 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario10_Q81
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.9027209 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario11_Q92
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.03603996 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario12_Q103
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 3.352897 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario15_Q114
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.02231179 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario16_Q228
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 4.344729e-05 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario17_Q125
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.02522951 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario18_Q136
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 1.732446 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario19_Q147
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 1.909219 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario20_Q158
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 3.426736 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS
## 
## 
## $scenario21_Q169
## Bayes factor analysis
## --------------
## [1] Null, mu=5 : 0.0006731251 ±0%
## 
## Against denominator:
##   Alternative, r = 0.5, mu =/= 5 
## ---
## Bayes factor type: BFoneSample, JZS