# Install necessary packages
if (!requireNamespace("changeofevidence")) {
if (!requireNamespace("remotes")) install.packages("remotes")
remotes::install_github("mrzdcmps/changeofevidence")
}
if (!requireNamespace("psych")) install.packages("psych")
# load libraries
library(psych)
library(changeofevidence)
## read files
df <- read.csv2("psyscanner-data.csv")
## convert to correct var types
df$date <- as.POSIXct(df$date)
df$Sex <- as.factor(df$Sex)
# calculate questionnaire scores
df$score.de <- rowMeans(df[,c(10,12,15,20:21,23:24,26,32,35)])
df$score.av <- rowMeans(df[,c(14,17,18,22,25,27,29:30,33,36)])
df$score.oc <- rowMeans(df[,c(8,9,11,13,16,19,28,31,34,37)])
df$score.t <- rowMeans(df[,c(42:44)])
# specify high vs low characteristic based on questionnaire score
df$de.group <- ifelse(df$score.de >= 2, "high", "low") #dependent
df$av.group <- ifelse(df$score.av >= 2, "high", "low") #avoidant
df$oc.group <- ifelse(df$score.oc >= 2, "high", "low") #obsessive-compulsive
# create groups
de.h <- subset(df, df$de.group == "high")
de.l <- subset(df, df$de.group == "low")
av.h <- subset(df, df$av.group == "high")
av.l <- subset(df, df$av.group == "low")
oc.h <- subset(df, df$oc.group == "high")
oc.l <- subset(df, df$oc.group == "low")
# Gender
prop.table(table(df$Sex))*100
##
## D F M
## 0.1677852 56.0402685 43.7919463
# Age
prop.table(table(df$Age))*100
##
## A1 A2 A3 A4 A5
## 62.005826 17.436538 7.865169 9.321681 3.370787
describeBy(df$de.sum, df$de.group) #dependent
##
## Descriptive statistics by group
## group: high
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 1400 15.18 2.68 15 15.16 2.97 6 24 18 0.05 0.11 0.07
## ------------------------------------------------------------
## group: low
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 1003 15.06 2.69 15 15.07 2.97 7 26 19 0 -0.12 0.08
describeBy(df$av.sum, df$av.group) #avoidant
##
## Descriptive statistics by group
## group: high
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 1308 15.06 2.71 15 15.06 2.97 7 24 17 0.04 -0.29 0.07
## ------------------------------------------------------------
## group: low
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 1095 15.17 2.74 15 15.15 2.97 7 23 16 0.02 -0.16 0.08
describeBy(df$oc.sum, df$oc.group) #obsessive-compulsive
##
## Descriptive statistics by group
## group: high
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 1462 15.05 2.74 15 15.05 2.97 4 22 18 -0.07 0.16 0.07
## ------------------------------------------------------------
## group: low
## vars n mean sd median trimmed mad min max range skew kurtosis se
## X1 1 941 14.88 2.64 15 14.88 2.97 6 23 17 0.01 -0.1 0.09
de.h.bf <- bfttest(de.h$de.sum, mu=15, alternative="greater", prior.loc = 0.05, prior.r = 0.05)
de.l.bf <- bfttest(de.l$de.sum, mu=15, alternative="two.sided", prior.loc = 0.05, prior.r = 0.05)
av.h.bf <- bfttest(av.h$av.sum, mu=15, alternative="greater", prior.loc = 0.05, prior.r = 0.05)
av.l.bf <- bfttest(av.l$av.sum, mu=15, alternative="two.sided", prior.loc = 0.05, prior.r = 0.05)
oc.h.bf <- bfttest(oc.h$oc.sum, mu=15, alternative="greater", prior.loc = 0.05, prior.r = 0.05)
oc.l.bf <- bfttest(oc.l$oc.sum, mu=15, alternative="two.sided", prior.loc = 0.05, prior.r = 0.05)
# Dependent High
print(de.h.bf)
##
## Sequential Bayesian Testing
## --------------------------------
## Test type: one-sample
## Sample size: 1400
## Final Bayes Factor: BF10=10.415; BF01=0.096
## Parameter prior: Cauchy(0.05, 0.05)
## Directionality of H1 analysis prior: greater
## Orthodox Test: t-value=2.514; p=0.006
##
# Avoidant High
print(av.h.bf)
##
## Sequential Bayesian Testing
## --------------------------------
## Test type: one-sample
## Sample size: 1308
## Final Bayes Factor: BF10=0.498; BF01=2.009
## Parameter prior: Cauchy(0.05, 0.05)
## Directionality of H1 analysis prior: greater
## Orthodox Test: t-value=0.776; p=0.219
##
# Obsessive-compulsive High
print(oc.h.bf)
##
## Sequential Bayesian Testing
## --------------------------------
## Test type: one-sample
## Sample size: 1462
## Final Bayes Factor: BF10=0.415; BF01=2.411
## Parameter prior: Cauchy(0.05, 0.05)
## Directionality of H1 analysis prior: greater
## Orthodox Test: t-value=0.679; p=0.249
##
plotbf(list("DE-PT high"=de.h.bf$BF, "AV-PT high"=av.h.bf$BF, "OC-PT high"=oc.h.bf$BF))
##
## Attache Paket: 'ggplot2'
## Die folgenden Objekte sind maskiert von 'package:psych':
##
## %+%, alpha
# Dependent Low
print(de.l.bf)
##
## Sequential Bayesian Testing
## --------------------------------
## Test type: one-sample
## Sample size: 1003
## Final Bayes Factor: BF10=0.46; BF01=2.172
## Parameter prior: Cauchy(0.05, 0.05)
## Directionality of H1 analysis prior: two.sided
## Orthodox Test: t-value=0.727; p=0.467
##
# Avoidant Low
print(av.l.bf)
##
## Sequential Bayesian Testing
## --------------------------------
## Test type: one-sample
## Sample size: 1095
## Final Bayes Factor: BF10=3.275; BF01=0.305
## Parameter prior: Cauchy(0.05, 0.05)
## Directionality of H1 analysis prior: two.sided
## Orthodox Test: t-value=2.084; p=0.037
##
# Obsessive-compulsive Low
print(oc.l.bf)
##
## Sequential Bayesian Testing
## --------------------------------
## Test type: one-sample
## Sample size: 941
## Final Bayes Factor: BF10=0.352; BF01=2.841
## Parameter prior: Cauchy(0.05, 0.05)
## Directionality of H1 analysis prior: two.sided
## Orthodox Test: t-value=-1.372; p=0.17
##
plotbf(list("DE-PT low"=de.l.bf$BF, "AV-PT low"=av.l.bf$BF, "OC-PT low"=oc.l.bf$BF))