-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.Rmd
380 lines (314 loc) · 10.4 KB
/
Project.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
---
title: " Appendix: Leistungsnachweis: fortgeschrittene Datenanalyse mit R"
author: "Mirko Bristle"
date: "27 10 2017"
output: word_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,eval=F)
```
# Setup:
Always run this Chunk first.
```{r eval=F, include=T}
#create Operating System Path prefix
if (Sys.info()['sysname'] == "Darwin" ) {
SysDir="/Volumes/SNFAue/"} else {
SysDir = "N:/"}
# load necessary library files
if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(readr)
p_load(lme4)
p_load(tableone)
p_load(tidyverse)
p_load(ggplot2)
p_load(merTools)
p_load(brms)
p_load(shinystan)
p_load(ggeffects)
p_load(ggeffects)
```
### Einlesen der physiologischen Daten:
```{r eval=F, include=T}
options(max.print = 99999999)
PhysioData_org<-read_rds(paste0(SysDir,"SoOp/deprecated/Soccer deprecated/original/analysis/ECG/AggregatedData/PhysioData_org_noArt_3sdMarked_.rds"))
#exclude Bsp trails
PhysioData<-PhysioData_org %>% filter(!grepl("Bsp",Spielfeld))
#create condition
PhysioData$Factor1<-if_else(
grepl(paste(c("Selbst","Ingroup1","Ingroup2"),collapse="|"),PhysioData$Gruppe),
"Us","Them")
PhysioData$Factor2<-if_else(grepl(paste(c("Selbst","Konkurrent"),
collapse="|"),PhysioData$Gruppe),"Single",
if_else(grepl(paste(c("Ingroup1","Outgroup1"),
collapse="|"),PhysioData$Gruppe),
"Team_1","Team_2"))
#make Participant ID unique by adding the between group to the name
PhysioData$BiopacSubject<-paste0(
if_else(PhysioData$betweenCond=="soccerPlayer","sp","nsp"),
"_",PhysioData$BiopacSubject) %>% as.character()
PhysioData<-PhysioData %>% filter(BiopacSubject!="sp_9")
PhysioData<-PhysioData %>% filter(BiopacSubject!="sp_10")
#aggregate spielfeld
PhysioData$Spielfeld<-as.numeric(
as.character(
unlist(PhysioData$Spielfeld)))%%16+1
#drop biopactrail (only from merging)
col <- c("Target","Measurement", "BiopacSubject","BiopacTrail",
"Time","Gruppe","betweenCond","Spielfeld",
"Factor1","Factor2")
PhysioData["Time"]<-as.numeric(as.character(
unlist((PhysioData["Time"]))))
PhysioData[col]<-lapply(PhysioData[col],factor)
sapply(PhysioData, class)
if(F){
tbo<-CreateTableOne(data = PhysioData )
summary(tbo)
}
rm(col,PhysioData_org)
```
#### Plots Measurement by Subject und Ausschluss von VPn
```{r eval=F, include=T}
plotMeasurementBySubject<- function(measurement,string){
measurement<-measurement %>% filter(Measurement==string)
ggplot(data = drop_na(measurement),mapping = aes(x = BiopacSubject,
y = Value,
fill = Measurement)) +
geom_violin() +
geom_jitter(width = 0.2, alpha = 0.6) +
theme_classic()
}
#Phight:
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("Phight")
#PRQ
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("STev")
#QT
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("QT")
#QTwidth
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("QTwidth")
#RRi
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("RRi")
#Rhight
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("Rhight")
#ST
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
filter(Value<=3) %>% plotMeasurementBySubject("ST")
#STev
PhysioData %>% filter(BiopacSubject!="nsp_14") %>%
plotMeasurementBySubject("STev")
#exclude:
PhysioData_1 <- PhysioData %>%
filter(BiopacSubject!="nsp_14") %>%
filter(BiopacSubject!="nsp_3") %>%
filter(BiopacSubject!="nsp_7") %>%
filter(Measurement == "RRi")
# Set 0 Values to NA ->
# these trails were either not anwsered or the trail timedout ->
#may lead to skrewed distribution!
PhysioData_1$VasSlide.RT<-if_else(
PhysioData_1$VasSlide.RT!=0,PhysioData_1$VasSlide.RT,NULL)
saveRDS(PhysioData_1,"physio.RT")
```
Phight:
- nsp_14: grosse varianz nach oben - exclude
- nsp_17/20 bottem effekt - 0
- nsp_7: alles null
PRQ:
nicht interpretierbare Verteilungen
QT:
- nsp_14 riesige varianz exclude
- nsp_7 alles null
QTwidth:
sehr komische Verteilungen, viele nullen, bei 100 beschränkt ?? komisch
Rhight:
- nsp_3 viele 0
- nsp_7 alles 0
- nsp_14 riesige varianz exclude
- nsp_4 grosse varianz
RRi:
- nsp_3 lot of values at 0 --> exclude
- nsp_14 grosse varianz
ST:
- nsp_7 alles 0
- ausreisser bei nsp_16, nsp_4 und sp_14 (Werte zwischen 10 und 70) -> filtern
- nsp4,5,6 grosse varianz
STev:
- prakisch alle nsp haben bottem effekt
- nsp_4 grosse varianz
- nsp_14 riesen varianz exclude
--> nur analyse von RRi, da nur für dieses Mass eine Hypothese besteht.
Aussschluss von VP: nsp_14,nsp_3,nsp_7
### TimePlot RRi and condition
```{r eval=F, include=T}
PhysioData_1<-read_rds("physio.RT")
physio_RRi<-na.omit(filter(PhysioData_1,
(Measurement=="RRi")&(grepl("Stimulus",Target))
&(Time!=-2)))
qplot(Time, Value, data=physio_RRi, geom=c("boxplot"),
fill=Time, main="Kategorial Time (s) against BPM",
xlab="Time(s)", ylab="BPM")
if (F){
mg <- ggplot(physio_RRi, aes(x = VasSlide.RT, y =VasSlide.VAS ,
colour = factor(BiopacSubject)))
+ geom_point()
mg + facet_grid(Factor1 + Factor2 ~ betweenCond)
}
```
### Behavior
```{r eval=FALSE, include=T}
p_load(readxl)
sp<-read_excel(paste0(SysDir,
"SoOp/deprecated/Soccer deprecated/original/rawDaten/soccerPlayer/E-Prime Daten/Merge_VP01_VP30.xlsx"))
sp$betweenCond<-"soccerPlayer"
nsp<-read_excel(paste0(SysDir,
"SoOp/deprecated/Soccer deprecated/original/rawDaten/nonSoccerPlayer/E-Prime Daten/Merge_VP01_VP30.xlsx"))
nsp$betweenCond<-"nonSoccerPlayer"
behaviorData<-rbind(sp,nsp) %>%
select(c(Name,Gruppe,betweenCond,
Spielfeld,VasSlide.RT,VasSlide.VAS))
behaviorData<-behaviorData %>%
filter(!grepl("Bsp",Spielfeld))
#create condition
behaviorData$Factor1<-if_else(
grepl(paste(c("Selbst","Ingroup1","Ingroup2"),
collapse="|"),behaviorData$Gruppe),"Us","Them")
behaviorData$Factor2<-if_else(
grepl(paste(c("Selbst","Konkurrent"),collapse="|"),
behaviorData$Gruppe),"Single",
if_else(grepl(paste(c("Ingroup1","Outgroup1"),
collapse="|"),behaviorData$Gruppe),
"Team_1","Team_2"))
#aggregate spielfeld
behaviorData$Spielfeld<-as.numeric(
as.character(unlist(behaviorData$Spielfeld)))%%16+1
behaviorData$VasSlide.RT<-if_else(
behaviorData$VasSlide.RT!=0,behaviorData$VasSlide.RT,NULL)
#Modeling
saveRDS(behaviorData,"behavior.rds")
```
```{r include=FALSE, eval=F}
#plot
behaviorData<-read_rds("behavior.rds")
mg <- ggplot(behaviorData,
aes(x = VasSlide.RT, y =VasSlide.VAS ,
colour = factor(Name))) + geom_point()
mg + facet_grid(Factor1 + Factor2 ~ betweenCond)
```
# Baysian Modelling
Modelle müssen zuerst berechnet werden. Dazu bitte die entsprechenden R Scripte ausführen.
#### Modeling Function (getBRMModel.R)
```{r eval=FALSE, code = readLines('mod/getBRMModel.R')}
```
#### Behavior (brms_b.R)
```{r eval=FALSE, code = readLines('mod/brms_b.R')}
```
#### Reaktion Times (brms_RT.R)
```{r eval=FALSE, code = readLines('mod/brms_RT.R')}
```
#### RRi (brms_RRi.R)
```{r eval=FALSE, code = readLines('mod/brms_RRi.R')}
```
### Behavior
```{r eval=F, include=T}
# EXECUTE brms_b.R to generate Models!
models<-data_frame(list("m0",
"m1a",
"m1b",
"m2",
"m2a",
"m2b",
"m2c"
))
colnames(models)[1]<-"names"
models$measurement<-"VAS"
models <- split(models, seq(nrow(models)))
M<- lapply(models,
function(x){read_rds(
paste0("models/",x$measurement,
"_",x$names,".rds"))})
if (F){
loo_behavior<- loo(M$`1`,M$`2`,M$`3`,M$`4`,M$`5`,M$`6`,M$`7`,
pointwise = F,
cores = parallel::detectCores ())
saveRDS(loo_behavior,"models/loo_behavior.rds")
} else{
loo_behavior<-read_rds("models/loo_behavior.rds")
}
lapply(M,function(x){x$formula})
loo_behavior
summary(M$`6`)
dat <- ggpredict(M$`6`,
terms = c("Factor1", "Factor2","betweenCond"),ppd=T)
saveRDS(dat,"Verhaltensdaten_plot.rds")
plot(dat,alpha = 0.05, dodge = 0.5) + labs(title = "Verhaltensdaten") +
ylab("Visual Analoge Scale (1-100)")
```
### Reaction Times
```{r eval=F, include=T}
# EXECUTE brms_RT.R to generate Models!
models<-data_frame(list("m0",
"m1a",
"m1b",
"m2",
"m2a",
"m2b",
"m2c"
))
colnames(models)[1]<-"names"
models$measurement<-"RT"
models <- split(models, seq(nrow(models)))
M_RT<- lapply(models,
function(x){read_rds(
paste0("models/",
x$measurement,"_",x$names,".rds"))})
if (F){
loo_RT<- loo(M_RT$`1`,M_RT$`2`,M_RT$`3`,M_RT$`4`,
M_RT$`5`,M_RT$`6`,M_RT$`7`,
pointwise = F,
cores = parallel::detectCores ())
saveRDS(loo_RT,"models/loo_RT.rds")
} else{
loo_RT<-read_rds("models/loo_RT.rds")
}
lapply(M_RT,function(x){x$formula})
loo_RT
summary(M_RT$`2`)
```
### RRi
```{r eval=F, include=T}
# EXECUTE brms_RRi.R to generate Models!
models<-data_frame(c(1:13))
colnames(models)[1]<-"names"
models$measurement<-"RRi"
models <- split(models, seq(nrow(models)))
M_RRi<- lapply(models,
function(x){read_rds(
paste0("models/",
x$measurement,"_",
x$names,".rds"))})
if (F){
loo_RRi<- loo(M_RRi$`1`,M_RRi$`2`,M_RRi$`3`,M_RRi$`4`,
M_RRi$`5`,M_RRi$`6`,M_RRi$`7`,M_RRi$`8`,
M_RRi$`9`,M_RRi$`10`,M_RRi$`11`,M_RRi$`12`,
pointwise = F,cores = parallel::detectCores ())
saveRDS(loo_RRi,"models/loo_RRi.rds")
} else {
loo_RRi<-read_rds("models/loo_RRi.rds")
}
lapply(M_RRi,function(x){x$formula})
loo_RRi
print(M_RRi$`12`,digits=2)
p_load(ggeffects)
dat <- ggpredict(M_RRi$`12`,
terms = c("Factor1", "Factor2","betweenCond"),ppd=T)
plot(dat,alpha = 0.05, dodge = 0.5 )+ labs(title = "Physiologie (RRi)") +
ylab("Herzrate in BPM")
saveRDS(dat,"RRi_plot.rds")
read_rds("models/RRi_12.rds")
```