-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocessing.R
59 lines (41 loc) · 1.45 KB
/
preprocessing.R
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
#### CREATE RAW DATA ----
library(dplyr)
# combine files to one df
files_names = dir("./data/collected_data/")
df = data.frame()
for (file in files_names) {
df <- rbind(df, read.csv(paste0("./data/collected_data/",file)))
}
# take only the columns we need
df <- df |>
mutate(
task = ifelse(grepl("ink_naming", condition), "ink_naming", "word_reading"),
congruency = ifelse(grepl("incong", condition), "congruent", "incongruent"),
acc = ifelse(participant_response == correct_response, 1, 0)
) |>
mutate(
subject = as.factor(subject),
task = as.factor(task),
congruency = as.factor(congruency),
block = as.numeric(block),
trial = as.numeric(trial),
acc = as.numeric(acc),
rt = as.numeric(rt)
) |>
select(subject, block, trial, task, congruency, participant_response, correct_response, acc, rt)
summary(df)
#check factors
contrasts(df$task)<-c(1,0)
contrasts(df$task)
contrasts(df$congruency)
save(df, file = "./data/raw_data.rdata")
#### CREATE FILTERD DATA ----
load("./data/raw_data.rdata")
cat("Number of unique subjects:", length(unique(df$subject)))
# Remove NA
df <- df |> filter(!is.na(rt))
# Remove RT outliers (below 300 or above 3000)
df <- df |> filter(rt >= 300 & rt <= 3000)
#check the percentage of remaining trials
df |> group_by(subject) |> summarise(percentage = 1 - (n() / 400)) |> print(n = Inf)
save(df, file = "./data/filtered_data.rdata")