Skip to content

Commit bf4f7e1

Browse files
committed
DataWrangling
ATTEMPT CrumpLab#1 - 03/09/19, Satur.
1 parent 03133ac commit bf4f7e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+646
-16
lines changed

DataWrangleFlanker_student.Rmd

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
```{r setup, include=FALSE}
2+
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message = FALSE)
3+
```
4+
5+
## Flanker task
6+
7+
In a flanker task, participants identify a central stimulus (as quickly and accurately) as possible, while ignoring distracting stimuli presented on the left or right of the central stimulus (the flankers).
8+
9+
For example, the stimulus could be "HHH", and the correct response would be H. This is called a compatible (or congruent) stimulus because the flanking Hs are the same as the central stimulus. Alternatively, the stimulus could be "HSH", and the correct resposne would be S. This is called an incompatible (or incongruent) stimulus because the flanking Hs are different from the central stimulus.
10+
11+
The data for this assignment come from a flanker task where participants responded to many flanker stimuli over several trials.
12+
13+
## Load the data and libraries you will use
14+
15+
I will help you with some sample code that compiles all of the text files in a single long format data frame.
16+
17+
The data is contained in this .zip file: [FlankerData.zip](https://crumplab.github.io/psyc7709/Presentations/FlankerData.zip)
18+
19+
The code chunk below assumes that you have placed the folder FlankerData into your R project folder.
20+
21+
```{r}
22+
library(data.table)
23+
library(dplyr)
24+
library(ggplot2)
25+
26+
27+
# get the file names
28+
file_names <- list.files(path="FlankerData")
29+
30+
# create headers for each column
31+
the_headers <- c("stimulus","congruency","proportion",
32+
"block","condition","dualtask","unknown",
33+
"stimulus_onset","response_time","response","subject")
34+
# Load data
35+
# create empty dataframe
36+
all_data<-data.frame()
37+
38+
# loop to add each file to the dataframe
39+
for(i in file_names){
40+
one_subject <- fread(paste("FlankerData/",i, sep=""))
41+
names(one_subject) <- the_headers
42+
one_subject$subject <- rep(i,dim(one_subject)[1])
43+
one_subject <- cbind(one_subject, trial= 1:dim(one_subject)[1])
44+
all_data <- rbind(all_data,one_subject)
45+
}
46+
47+
```
48+
49+
## Pre-processing
50+
51+
### get accuracy for each trial
52+
53+
A correct response occurs when the letter in the response column is the same as the letter in the middle position of item in the stimulus column. Create an accuracy column that codes whether the response was correct or incorrect on each trial (coding can be TRUE/FALSE, 0/1, or some other coding scheme that identifies correct vs incorrect)
54+
55+
```{r}
56+
57+
58+
```
59+
60+
### Get Reaction time on each trial
61+
62+
The stimulus_onset column gives a computer timestamp in milliseconds indicating when the stimulus was presented. The response_time column is a timestamp in milliseconds for the response. The difference between the two (response_time - stimulus_onset) is the reaction time in milliseconds. Add a column that calculates the reaction time on each trial.
63+
64+
**tip:** notice that the numbers in response_time and stimulus_onset have the class integer64. Unfortunately, ggplot does not play nice with integers in this format. you will need to make sure your RT column is in the class integer or numeric.
65+
66+
```{r}
67+
68+
```
69+
70+
71+
## Checks
72+
73+
Check how many trials each subject completed in the congruent and incongruent conditions, the mean accuracy for each subject in each congruency condition, and the mean RT for each subject in each congruency condition.
74+
75+
```{r}
76+
77+
78+
```
79+
80+
81+
82+
### Exclusion
83+
84+
It is common to exclude Reaction times that are very slow. There are many methods and procedures for excluding outlying reaction times. To keep it simple, exclude all RTs that are longer than 2000 ms
85+
86+
```{r}
87+
88+
```
89+
90+
## Analysis
91+
92+
### Reaction Time analysis
93+
94+
1. Get the individual subject mean reaction times for **correct** congruent and incongruent trials.
95+
96+
```{r}
97+
98+
```
99+
100+
2. Get the overall mean RTs and SEMs (standard errors of the mean) for the congruent and incongruent condition. Make a table and graph.
101+
102+
```{r}
103+
104+
105+
106+
```
107+
108+
3. Compute the flanker effect for each subject, taking the difference between their mean incongruent and congruent RT. Then plot the mean flanker effect, along with the SEM of the mean flanker effect
109+
110+
**tip:** Not all problems have an easy solution in dplyr, this is one them. You may have an easier time using logical indexing of the dataframe to solve this part.
111+
112+
```{r}
113+
114+
115+
```
116+
117+
118+
### Exploratory analysis
119+
120+
Multiple questions may often be asked of data, especially questions that may not have been of original interest to the researchers.
121+
122+
In flanker experiments, like this one, it is well known that the flanker effect is modulated by the nature of the previous trial. Specifically, the flanker effect on trial n (the current trial), is larger when the previous trial (trial n-1) involved a congruent item, compared to an incongruent item.
123+
124+
Transform the data to conduct a sequence analysis. The dataframe should already include a factor (column) for the congruency level of trial n. Make another column that codes for the congruency level of trial n-1 (the previous trial). This creates a 2x2 design with trial n congruency x trial n-1 congruency.
125+
126+
First get teh subject means for each condition, then create a table and plot for teh overall means and SEMs in each condition. This should include:
127+
128+
1. trial n congruent : trial n-1 congruent
129+
2. trial n incongruent : trial n-1 congruent
130+
3. trial n congruent : trial n-1 incongruent
131+
4. trial n incongruent : trial n-1 incongruent
132+
133+
**tip:** be careful, note that the first trial in each experiment can not be included, because it had no preceding trial
134+
135+
```{r}
136+
137+
138+
```
139+
140+
141+
142+
143+
144+
145+

FlankerData/1.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/10.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/11.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/12.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/13.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/14.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/15.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/16.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

FlankerData/17.txt

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)