-
Notifications
You must be signed in to change notification settings - Fork 0
/
EPAR VPC Blocks Section 2.Rmd
326 lines (234 loc) · 11.5 KB
/
EPAR VPC Blocks Section 2.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
---
title: "EPAR VPC Blocks Section 2"
output: html_notebook
---
*Kate Dixon, 2018*
Code takes a csv file of hand-coded (using Datavyu), frame-by-frame left/right looks and transforms it into a final data file that has total look time to each stimuli pair and look time to each stimulus within that pair *BY BLOCKS*.
For cells 7-12 & 19-24
## Set working directory
```{r}
setwd("C:/Users/Kate/Desktop/VPC")
```
## Load packages
```{r load-packages, message = FALSE}
library(ggplot2)
library(dplyr)
library(plyr)
library(readxl)
```
## Load data- *CHANGE NAME OF FILE HERE*
```{r load-data}
df <- read.csv("238352 VPC.csv", header=TRUE)
cell_orders <- read_excel("VPC cell orders.xlsx")
```
## Create new duration variables for individual left and right looks
```{r}
df <- df %>%
mutate(LeftLookDuration = LeftLook.offset - LeftLook.onset)
df <- df %>%
mutate(RightLookDuration = RightLook.offset - RightLook.onset)
```
## Making a new dataframe for the combined look times
```{r}
total_look_timeXtrial <- data.frame(matrix(vector(), 0, 2))
```
## Combining all left/right look durations for each test trial (i.e., TT1, TT2...)
```{r}
left_look_timeXtrial <- ddply(df, .(LeftLook.code01), numcolwise(sum))
right_look_timeXtrial <- ddply(df, .(RightLook.code01), numcolwise(sum))
left_look_timeXtrial <-left_look_timeXtrial$LeftLookDuration
right_look_timeXtrial <- right_look_timeXtrial$RightLookDuration
left_look_timeXtrial <- as.data.frame(left_look_timeXtrial)
right_look_timeXtrial <- as.data.frame(right_look_timeXtrial)
```
## Total left and right look times per trial
```{r}
left_look_timeXtrial <- slice(left_look_timeXtrial, 1:12)
right_look_timeXtrial <- slice(right_look_timeXtrial, 1:12)
total_look_timeXtrial <- cbind(left_look_timeXtrial,right_look_timeXtrial)
```
## Adding cell order information to total look time- *CHANGE CELL NUMBER HERE*
```{r}
total_look_timeXtrial <- cbind(total_look_timeXtrial, cell_orders$`Cell 9`)
```
## Calculating total look time per trial
```{r}
total_look_timeXtrial <- total_look_timeXtrial %>%
mutate(TotalLT = left_look_timeXtrial + right_look_timeXtrial)
```
## Separating total look time by trial df into block 1 and block 2
```{r}
# Rename columns
names(total_look_timeXtrial) <- c("LLXtrial", "RLXtrial", "Stimuli", "TotalLT")
block1 <- slice(total_look_timeXtrial, 1:6)
block2 <- slice(total_look_timeXtrial, 7:12)
```
## Creating empty data frames for the finished data
```{r}
final_data_block1 <- data.frame(matrix(vector(), 1, 30))
names(final_data_block1) <- c("TLT_AH/HA", "LT2H_A/H", "LT2A_A/H", "perctH_A/H", "perctA_A/H", "TLT_FA/AF", "LT2F_F/A", "LT2A_F/A", "perctF_F/A", "perctA_F/A", "TLT_HN/NH", "LT2H_H/N", "LT2N_H/N", "perctH_H/N", "perctN_H/N", "TLT_HF/FH", "LT2H_H/F", "LT2F_H/F", "perctH_H/F", "perctF_H/F", "TLT_NF/FN", "LT2N_N/F", "LT2F_N/F", "perctN_N/F", "perctF_N/F", "TLT_AN/NA", "LT2A_A/N", "LT2N_A/N", "perctA_A/N", "perctN_A/N")
final_data_block2 <- data.frame(matrix(vector(), 1, 30))
names(final_data_block2) <- c("TLT_AH/HA", "LT2H_A/H", "LT2A_A/H", "perctH_A/H", "perctA_A/H", "TLT_FA/AF", "LT2F_F/A", "LT2A_F/A", "perctF_F/A", "perctA_F/A", "TLT_HN/NH", "LT2H_H/N", "LT2N_H/N", "perctH_H/N", "perctN_H/N", "TLT_HF/FH", "LT2H_H/F", "LT2F_H/F", "perctH_H/F", "perctF_H/F", "TLT_NF/FN", "LT2N_N/F", "LT2F_N/F", "perctN_N/F", "perctF_N/F", "TLT_AN/NA", "LT2A_A/N", "LT2N_A/N", "perctA_A/N", "perctN_A/N")
```
## Finding total look times and proportions of look time to Happy and Angry for A/H trial for Block 2
```{r}
## Finding total look time to H and A on A/H trial
final_data_block2$`LT2H_A/H` <- block2 %>%
filter(Stimuli == "A/H") %>%
select(RLXtrial)
final_data_block2$`LT2A_A/H` <- block2 %>%
filter(Stimuli == "A/H") %>%
select(LLXtrial)
final_data_block2$`TLT_AH/HA` <- final_data_block2$`LT2H_A/H` + final_data_block2$`LT2A_A/H`
final_data_block2$`perctH_A/H` <- final_data_block2$`LT2H_A/H`/final_data_block2$`TLT_AH/HA`
final_data_block2$`perctA_A/H` <- final_data_block2$`LT2A_A/H`/final_data_block2$`TLT_AH/HA`
```
## Finding total look times and proportions of look time to Happy and Angry for H/A trials for Block 1
```{r}
## Finding total look time to H and A on H/A trial
final_data_block1$`LT2H_A/H` <- block1 %>%
filter(Stimuli == "H/A") %>%
select(LLXtrial)
final_data_block1$`LT2A_A/H` <- block1 %>%
filter(Stimuli == "H/A") %>%
select(RLXtrial)
final_data_block1$`TLT_AH/HA` <- final_data_block1$`LT2H_A/H` + final_data_block1$`LT2A_A/H`
final_data_block1$`perctH_A/H` <- final_data_block1$`LT2H_A/H`/final_data_block1$`TLT_AH/HA`
final_data_block1$`perctA_A/H` <- final_data_block1$`LT2A_A/H`/final_data_block1$`TLT_AH/HA`
```
## Finding total look times and proportions of look time to Fearful and Angry for F/A trial for Block 2
```{r}
## Finding total look time to F and A on F/A trial
final_data_block2$`LT2F_F/A` <- block2 %>%
filter(Stimuli == "F/A") %>%
select(LLXtrial)
final_data_block2$`LT2A_F/A` <- block2 %>%
filter(Stimuli == "F/A") %>%
select(RLXtrial)
final_data_block2$`TLT_FA/AF` <- final_data_block2$`LT2F_F/A` + final_data_block2$`LT2A_F/A`
final_data_block2$`perctA_F/A` <- final_data_block2$`LT2A_F/A`/final_data_block2$`TLT_FA/AF`
final_data_block2$`perctF_F/A` <- final_data_block2$`LT2F_F/A`/final_data_block2$`TLT_FA/AF`
```
## Finding total look times and proportions of look time to Fearful and Angry for A/F trial for Block 1
```{r}
## Finding total look time to A and F on A/F trial
final_data_block1$`LT2A_F/A` <- block1 %>%
filter(Stimuli == "A/F") %>%
select(LLXtrial)
final_data_block1$`LT2F_F/A` <- block1 %>%
filter(Stimuli == "A/F") %>%
select(RLXtrial)
final_data_block1$`TLT_FA/AF` <- final_data_block1$`LT2F_F/A` + final_data_block1$`LT2A_F/A`
final_data_block1$`perctA_F/A` <- final_data_block1$`LT2A_F/A`/final_data_block1$`TLT_FA/AF`
final_data_block1$`perctF_F/A` <- final_data_block1$`LT2F_F/A`/final_data_block1$`TLT_FA/AF`
```
## Finding total look times and proportions of look time to Neutral and Happy for N/H trial for Block 2
```{r}
## Finding total look time to N and H on N/H trial
final_data_block2$`LT2N_H/N` <- block2 %>%
filter(Stimuli == "N/H") %>%
select(LLXtrial)
final_data_block2$`LT2H_H/N` <- block2 %>%
filter(Stimuli == "N/H") %>%
select(RLXtrial)
final_data_block2$`TLT_HN/NH` <- final_data_block2$`LT2N_H/N` + final_data_block2$`LT2H_H/N`
final_data_block2$`perctH_H/N` <- final_data_block2$`LT2H_H/N`/final_data_block2$`TLT_HN/NH`
final_data_block2$`perctN_H/N` <- final_data_block2$`LT2N_H/N`/final_data_block2$`TLT_HN/NH`
```
## Finding total look times and proportions of look time to Neutral and Happy for H/N trial for Block 1
```{r}
## Finding total look time to N and H on H/N trial
final_data_block1$`LT2N_H/N` <- block1 %>%
filter(Stimuli == "H/N") %>%
select(RLXtrial)
final_data_block1$`LT2H_H/N` <- block1 %>%
filter(Stimuli == "H/N") %>%
select(LLXtrial)
final_data_block1$`TLT_HN/NH` <- final_data_block1$`LT2N_H/N` + final_data_block1$`LT2H_H/N`
final_data_block1$`perctH_H/N` <- final_data_block1$`LT2H_H/N`/final_data_block1$`TLT_HN/NH`
final_data_block1$`perctN_H/N` <- final_data_block1$`LT2N_H/N`/final_data_block1$`TLT_HN/NH`
```
## Finding total look times and proportions of look time to Fearful and Happy for H/F trial for Block 2
```{r}
## Finding total look time to F and H on H/F trial
final_data_block2$`LT2H_H/F` <- block2 %>%
filter(Stimuli == "H/F") %>%
select(LLXtrial)
final_data_block2$`LT2F_H/F` <- block2 %>%
filter(Stimuli == "H/F") %>%
select(RLXtrial)
final_data_block2$`TLT_HF/FH` <- final_data_block2$`LT2H_H/F` + final_data_block2$`LT2F_H/F`
final_data_block2$`perctF_H/F` <- final_data_block2$`LT2F_H/F`/final_data_block2$`TLT_HF/FH`
final_data_block2$`perctH_H/F` <- final_data_block2$`LT2H_H/F`/final_data_block2$`TLT_HF/FH`
```
## Finding total look times and proportions of look time to Fearful and Happy for F/H trial for Block 1
```{r}
## Finding total look time to F and H on H/F trial
final_data_block1$`LT2H_H/F` <- block1 %>%
filter(Stimuli == "F/H") %>%
select(RLXtrial)
final_data_block1$`LT2F_H/F` <- block1 %>%
filter(Stimuli == "F/H") %>%
select(LLXtrial)
final_data_block1$`TLT_HF/FH` <- final_data_block1$`LT2H_H/F` + final_data_block1$`LT2F_H/F`
final_data_block1$`perctF_H/F` <- final_data_block1$`LT2F_H/F`/final_data_block1$`TLT_HF/FH`
final_data_block1$`perctH_H/F` <- final_data_block1$`LT2H_H/F`/final_data_block1$`TLT_HF/FH`
```
## Finding total look times and proportions of look time to Neutral and Fearful for N/F trial for Block 2
```{r}
## Finding total look time to F and N on N/F trial
final_data_block2$`LT2N_N/F` <- block2 %>%
filter(Stimuli == "N/F") %>%
select(LLXtrial)
final_data_block2$`LT2F_N/F` <- block2 %>%
filter(Stimuli == "N/F") %>%
select(RLXtrial)
final_data_block2$`TLT_NF/FN` <- final_data_block2$`LT2N_N/F` + final_data_block2$`LT2F_N/F`
final_data_block2$`perctF_N/F` <- final_data_block2$`LT2F_N/F` / final_data_block2$`TLT_NF/FN`
final_data_block2$`perctN_N/F` <- final_data_block2$`LT2N_N/F` / final_data_block2$`TLT_NF/FN`
```
## Finding total look times and proportions of look time to Neutral and Fearful for F/N trial for Block 1
```{r}
## Finding total look time to F and N on F/N trial
final_data_block1$`LT2N_N/F` <- block1 %>%
filter(Stimuli == "F/N") %>%
select(RLXtrial)
final_data_block1$`LT2F_N/F` <- block1 %>%
filter(Stimuli == "F/N") %>%
select(LLXtrial)
final_data_block1$`TLT_NF/FN` <- final_data_block1$`LT2N_N/F` + final_data_block1$`LT2F_N/F`
final_data_block1$`perctF_N/F` <- final_data_block1$`LT2F_N/F` / final_data_block1$`TLT_NF/FN`
final_data_block1$`perctN_N/F` <- final_data_block1$`LT2N_N/F` / final_data_block1$`TLT_NF/FN`
```
## Finding total look times and proportions of look time to Neutral and Angry for A/N trial for Block 2
```{r}
## Finding total look time to A and N on A/N trial
final_data_block2$`LT2A_A/N` <- block2 %>%
filter(Stimuli == "A/N") %>%
select(LLXtrial)
final_data_block2$`LT2N_A/N` <- block2 %>%
filter(Stimuli == "A/N") %>%
select(RLXtrial)
final_data_block2$`TLT_AN/NA` <- final_data_block2$`LT2N_A/N` + final_data_block2$`LT2A_A/N`
final_data_block2$`perctA_A/N` <- final_data_block2$`LT2A_A/N`/final_data_block2$`TLT_AN/NA`
final_data_block2$`perctN_A/N`<- final_data_block2$`LT2N_A/N`/final_data_block2$`TLT_AN/NA`
```
## Finding total look times and proportions of look time to Neutral and Angry for N/A trial for Block 1
```{r}
## Finding total look time to A and N on N/A trial
final_data_block1$`LT2A_A/N` <- block1 %>%
filter(Stimuli == "N/A") %>%
select(RLXtrial)
final_data_block1$`LT2N_A/N` <- block1 %>%
filter(Stimuli == "N/A") %>%
select(LLXtrial)
final_data_block1$`TLT_AN/NA` <- final_data_block1$`LT2N_A/N` + final_data_block1$`LT2A_A/N`
final_data_block1$`perctA_A/N` <- final_data_block1$`LT2A_A/N`/final_data_block1$`TLT_AN/NA`
final_data_block1$`perctN_A/N`<- final_data_block1$`LT2N_A/N`/final_data_block1$`TLT_AN/NA`
```
## Writing final data into a csv file- *CHANGE NAME OF OUTPUT FILES HERE*
```{r}
# Write CSV in R
write.csv(final_data_block1, file = "238352 VPC block1.csv", row.names = TRUE)
write.csv(final_data_block2, file = "238352 VPC block2.csv", row.names = TRUE)
```