PennController for IBEX › Forums › Support › Can we randomize time with newTimer() ? › Reply To: Can we randomize time with newTimer() ?
March 24, 2022 at 7:37 am
#7969

Participant
Dear Jeremy,
My R code was running just fine for this same code before I had to make the timing alterations. My guess is that before the timeout alteration, I had to had a pressed key such as S or K, but now, because of the required timeout, it is not necessarialy anymore…I guess that the code is struggling with the NAs. Would you have any recommendations?
This is an example results file from the code with the timing alterations => https://github.com/LariCury/Sample-results.git
##install.packages("ddlyr","tidyverse")
library(dplyr)
library(tidyverse)
library(writexl)
#Read PciBex's function
read.pcibex <- function(filepath, auto.colnames=TRUE, fun.col=function(col,cols){cols[cols==col]<-paste(col,"Ibex",sep=".");return(cols)}) {
n.cols <- max(count.fields(filepath,sep=",",quote=NULL),na.rm=TRUE)
if (auto.colnames){
cols <- c()
con <- file(filepath, "r")
while ( TRUE ) {
line <- readLines(con, n = 1, warn=FALSE)
if ( length(line) == 0) {
break
}
m <- regmatches(line,regexec("^# (\\d+)\\. (.+)\\.$",line))[[1]]
if (length(m) == 3) {
index <- as.numeric(m[2])
value <- m[3]
if (is.function(fun.col)){
cols <- fun.col(value,cols)
}
cols[index] <- value
if (index == n.cols){
break
}
}
}
close(con)
return(read.csv(filepath, comment.char="#", header=FALSE, col.names=cols))
}
else{
return(read.csv(filepath, comment.char="#", header=FALSE, col.names=seq(1:n.cols)))
}
}
# Read in results file
results <- read.pcibex("Result_Example.csv")
add_blocks <- function (df,id) {
PRACTICE_TO_FIRST <- max(df$EventTime[df$Label=="instructions_E"])
FIRST_TO_SECOND <- max(df$EventTime[df$Label=="instructions_F"])
SECOND_TO_THIRD <- max(df$EventTime[df$Label=="instructions_G"])
df$block <- 0
df$block[df$EventTime>PRACTICE_TO_FIRST] <- 1
df$block[df$EventTime>FIRST_TO_SECOND] <- 2
df$block[df$EventTime>SECOND_TO_THIRD] <- 3
return(df)
}
results_blocks <- results %>%
group_by(id) %>%
group_modify(add_blocks)
##the DF name is results_blocks
#Filter the relevant collumns and create the Reaction_Time collumn
data_results <- results_blocks %>%
filter(Parameter %in% c("Print","PressedKey")) %>%
select(id,Label,imagens,block,Value,EventTime,Parameter) %>%
group_by(id) %>%
mutate(event = case_when(Parameter == "Print" ~ "Time1",
Parameter == "PressedKey" ~ "Time2")) %>%
ungroup() %>%
#select(-Parameter) %>%
pivot_wider(names_from = event, values_from = EventTime)
## Omit NA from Time2 and Time1:
a <- na.omit(data_results$Time2)
b <- na.omit(data_results$Time1)
## Reaction_Time = Time2-Time1:
RT <- a-b
## Create the REACTION_TIME collumn:
data_results_final <- data_results %>%
filter(Value %in% c("S","K")) %>%
data_results_final$newRT <- RT
## Omit irrelevant colluns (Time1 and Time2)
clean_data <- subset(data_results_final, select = -c(Time1,Time2))
This is an example results file from the code with the timing alterations => https://github.com/LariCury/Sample-results.git
-
This reply was modified 3 years ago by
Larissa_Cury. Reason: typo