-
Notifications
You must be signed in to change notification settings - Fork 2
/
KH2017_analyses.Rmd
160 lines (121 loc) · 4.18 KB
/
KH2017_analyses.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
---
title: "KH2017 analyses (Behavior Research Methods, 2017)"
author: "Pascal J. Kieslich & Felix Henninger"
output:
pdf_document:
fig_height: 4
fig_width: 4
---
# Reference
Kieslich, P. J., & Henninger, F. (2017). Mousetrap: An integrated, open-source mouse-tracking package. _Behavior Research Methods, 49_(5), 1652-1667.
https://doi.org/10.3758/s13428-017-0900-z
# General preparations
## Load libraries
```{r,message=FALSE}
library(mousetrap)
library(ggplot2)
library(dplyr)
```
## Custom ggplot2 theme
```{r}
theme_set(theme_classic()+
theme(
axis.line = element_line(colour = "black"),
axis.ticks = element_line(colour = "black"),
axis.text = element_text(colour = "black"),
panel.border = element_rect(colour = "black", fill=NA)
))
options(width=90)
```
# Data preparation
## Read in merged raw data
```{r}
# Read in raw data from csv.gz file
# (commented out as the raw data are now included in the mousetrap R package)
# raw_data <- read.csv("merged_data/raw_data.csv.gz",stringsAsFactor=FALSE)
# Instead, get raw data directly from data stored in mousetrap package
raw_data <- KH2017_raw
```
## Filter trials
```{r}
# Look at percent of correct responses per Condition
with(raw_data,table(Condition, correct)/c(table(Condition)))
# Exlude incorrect trials
raw_data <- subset(raw_data, correct==1)
# Check that each subject has at least one typical and atypical trial left
table(with(raw_data,table(subject_nr,Condition))>0)
```
## Import mouse-tracking data
```{r}
mt_data <- mt_import_mousetrap(raw_data)
```
## Trajectory preprocessing
```{r}
mt_data <- mt_remap_symmetric(mt_data)
mt_data <- mt_align_start(mt_data)
mt_data <- mt_measures(mt_data)
mt_data <- mt_time_normalize(mt_data)
```
# Analyses
## Logging resolution
```{r}
mt_check_resolution(mt_data, desired = 10)
```
## Plot average time-normalized tajectories
```{r}
mt_plot_aggregate(mt_data, use = "tn_trajectories", points=TRUE,
x = "xpos", y = "ypos", color = "Condition", subject_id = "subject_nr")+
theme(legend.position=c(.2,.2))+
xlab("x coordinate (px)") + ylab("y coordinate (px)")+
scale_color_grey(start = .55, end = .20)
# ggsave("figures/Figure5.png",width=8.5, height=10,unit="cm",dpi=1200)
# ggsave("figures/Figure5.pdf",width=8.5, height=10,unit="cm")
# ggsave("figures/Figure5.eps",width=8.5, height=10,unit="cm")
```
## Comparison of measures based on time-normalized vs. raw trajectories
```{r}
mt_data <- mt_measures(mt_data,use="tn_trajectories",save_as="tn_measures")
diag(cor(mt_data$measures[,-1],mt_data$tn_measures[,-1]))
```
## Comparison of MAD aggregated per participant
```{r}
agg_mad <- mt_aggregate_per_subject(mt_data, subject_id = "subject_nr",
use_variables = "MAD", use2_variables = "Condition")
agg_mad %>%
group_by(Condition) %>%
select(MAD,Condition) %>%
summarize_all(.funs = c("mean","sd"))
t.test(MAD~Condition, data=agg_mad, paired=TRUE)
# Cohen's dz
mad_diff <- with(agg_mad,MAD[Condition=="Atypical"]-MAD[Condition=="Typical"])
mean(mad_diff)/sd(mad_diff)
```
## Bimdality analyses
```{r}
# Standardize MAD per participant
mt_data <- mt_standardize(mt_data,
use_variables = "MAD", within = "subject_nr",prefix = "z_")
# Calculate bimodality coefficient
mt_check_bimodality(mt_data,use_variables = "z_MAD",
grouping_variables = "Condition", methods = "BC")
# Merge trial level data (needed for distribution qplot with facets)
results <- merge(mt_data$data,mt_data$measures,by="mt_id")
# Distribution
qplot(x=z_MAD,data=results,bins=50)+facet_grid(Condition~.)
```
## Repeat analyses without large MAD values
```{r}
# Exclude trials with abs(z_MAD)>1.5
table(abs(mt_data$measures$z_MAD)<=1.5)/nrow(mt_data$measures)
mt_data_sub <- mt_subset(mt_data,abs(z_MAD)<=1.5,check="measures")
# Check that each subject has at least on typical and atypical trial left
table(with(mt_data_sub$data,table(subject_nr,Condition))>0)
# Comparison of MAD aggregated per participant
agg_mad_sub <- mt_aggregate_per_subject(mt_data_sub, subject_id = "subject_nr",
use_variables = "MAD", use2_variables = "Condition")
agg_mad_sub %>%
group_by(Condition) %>%
select(MAD,Condition) %>%
summarize_all(.funs = c("mean","sd"))
t.test(MAD~Condition, data=agg_mad_sub, paired=TRUE)
```