PennController for IBEX › Forums › Support › Pre-processing self-paced reading data in R › Reply To: Pre-processing self-paced reading data in R
Hi Rosa,
EDIT: well, I read your message too fast and didn’t realize you were asking about self-paced reading specifically—I’d be happy to adapt the example in this message to self-paced reading trials if it helps
For this example, I’ll be working from an extremely minimal trial structure:
newTrial( "experimental" , newScale("comprehensionanswer", "Yes", "No") .print() .wait() .log() ) .log("id", GetURLParameter("id")) .log("correct", "Yes") .log("itemnumber" , 1 )
I’m assuming all experimental trials are labeled experimental and that itemnumber uniquely identifies your trials. Let’s first load the results in a table:
results <- read.pcibex( "results_comprehension" )
We’ll be comparing Value and correct a lot, so we’ll de-factorize those columns:
results$Value <- as.character(results$Value) results$correct <- as.character(results$correct)
Now let’s load dplyr and do our magic:
library("dplyr") results <- results %>% group_by(id) %>% mutate(accuracy=mean(Value[Label=="experimental"&Parameter=="Choice"] ==correct[Label=="experimental"&Parameter=="Choice"])) %>% group_by(id,itemnumber) %>% mutate(RT=EventTime[Parameter=="Choice"] - EventTime[Parameter=="_Trial_"&Value=="Start"])
The first mutate
compares Value against correct for the rows of the experimental trials where Parameter is “Choice” (= rows reporting which option was selected on the scale) and outputs the mean for each participant (see group_by(id)
)
The second mutate
simply subtracts the EventTime corresponding to the start of the trial from the EventTime corresponding to the choice on the scale, for each trial for each participant (see group_by(id,itemnumber)
).
Now that we have added the accuracy column which reports the proportion of correct answers to the experimental trials for each participant, and the RT column which reports how long they took to make a decision for each trial, we can proceed to the filtering:
results_filtered <- results %>% filter(Label=="experimental" & accuracy>=3/4 & Value==correct & RT<=3000)
Let me know if you have questions
Jeremy