########################################
# xx
########################################
### argss:
# xxData analysis all studies
1 Notes
2 global variables
Define your global variables (e.g., to reduce run time):
3 functions
4 load packages
### load packages (also packages loaded, which are not needed for data preperation)
require(pacman)
p_load('tidyverse', 'jsonlite',
'stargazer', 'DT', 'psych',
'writexl', 'associatoR',
'ggstatsplot')
# devtools::install_github("samuelae/associatoR")5 load prepared data
setwd("outputs/questionnaire")
ques_study <- readRDS(file = paste0("ques_study", ".rds"))setwd("outputs/associations")
ass_study <- readRDS(file = paste0("ass_study", ".rds"))6 Check and summarize scales
6.1 compute mean scores
ques_study$mean_AIAS <- rowMeans(x = ques_study[, str_subset(string = colnames(ques_study), pattern = "^AIAS")], na.rm = FALSE) # no missing
ques_study$mean_PTTA <- rowMeans(x = ques_study[, str_subset(string = colnames(ques_study), pattern = "^PTTA")], na.rm = FALSE) # no missinghist(ques_study$mean_AIAS)hist(ques_study$mean_PTTA)cor(ques_study$mean_AIAS, ques_study$mean_PTTA)[1] 0.6921071
7 Analyze data
ggstatsplot::ggbetweenstats(data = ques_study, x = study_condition, y = mean_AIAS, type = "parametric")ggstatsplot::ggbetweenstats(data = ques_study, x = study_condition, y = mean_PTTA, type = "parametric")library(afex)Lade nötiges Paket: lme4
Lade nötiges Paket: Matrix
Attache Paket: 'Matrix'
Die folgenden Objekte sind maskiert von 'package:tidyr':
expand, pack, unpack
************
Welcome to afex. For support visit: http://afex.singmann.science/
- Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
- Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
- 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
- Get and set global package options with: afex_options()
- Set sum-to-zero contrasts globally: set_sum_contrasts()
- For example analyses see: browseVignettes("afex")
************
Attache Paket: 'afex'
Das folgende Objekt ist maskiert 'package:lme4':
lmer
# Run the Between-Subjects ANOVA
model_anova <- aov_ez(
id = "PROLIFIC_PID", # Replace with your subject ID column name
dv = "mean_PTTA", # Your Dependent Variable
data = ques_study,
between = "study_condition" # Your Independent Variable
)Contrasts set to contr.sum for the following variables: study_condition
# Print the ANOVA table
print(model_anova)Anova Table (Type 3 tests)
Response: mean_PTTA
Effect df MSE F ges p.value
1 study_condition 6, 507 0.52 1.80 + .021 .097
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
library(emmeans)Welcome to emmeans.
Caution: You lose important information if you filter this package's results.
See '? untidy'
# Get the marginal means
ls_means <- emmeans(model_anova, specs = "study_condition")
# Perform pairwise comparisons
post_hocs <- pairs(ls_means, adjust = "tukey")
# View results
print(post_hocs) contrast estimate SE df t.ratio p.value
AutonomousWeapons - CourtDecision -0.15221 0.119 507 -1.280 0.8609
AutonomousWeapons - CriticalInfrastructure -0.13699 0.121 507 -1.136 0.9168
AutonomousWeapons - Diagnostic -0.25681 0.108 507 -2.384 0.2073
AutonomousWeapons - Grading -0.12774 0.114 507 -1.116 0.9232
AutonomousWeapons - Migration -0.18371 0.109 507 -1.692 0.6220
AutonomousWeapons - PersonnelSelection -0.37311 0.126 507 -2.961 0.0499
CourtDecision - CriticalInfrastructure 0.01521 0.130 507 0.117 1.0000
CourtDecision - Diagnostic -0.10460 0.118 507 -0.886 0.9746
CourtDecision - Grading 0.02447 0.124 507 0.197 1.0000
CourtDecision - Migration -0.03151 0.119 507 -0.265 1.0000
CourtDecision - PersonnelSelection -0.22090 0.135 507 -1.637 0.6586
CriticalInfrastructure - Diagnostic -0.11981 0.120 507 -1.000 0.9539
CriticalInfrastructure - Grading 0.00926 0.126 507 0.074 1.0000
CriticalInfrastructure - Migration -0.04672 0.121 507 -0.387 0.9997
CriticalInfrastructure - PersonnelSelection -0.23611 0.136 507 -1.730 0.5962
Diagnostic - Grading 0.12907 0.114 507 1.136 0.9168
Diagnostic - Migration 0.07309 0.108 507 0.679 0.9937
Diagnostic - PersonnelSelection -0.11630 0.125 507 -0.929 0.9679
Grading - Migration -0.05598 0.114 507 -0.489 0.9990
Grading - PersonnelSelection -0.24537 0.131 507 -1.872 0.5003
Migration - PersonnelSelection -0.18939 0.126 507 -1.503 0.7430
P value adjustment: tukey method for comparing a family of 7 estimates