Reply To: Can we randomize time with newTimer() ?

PennController for IBEX Forums Support Can we randomize time with newTimer() ? Reply To: Can we randomize time with newTimer() ?

#7973
Larissa_Cury
Participant

Just an update =>

I figure it out that the problem was that when there’s no pressed key, there’s no EventTime for that as well, then R couldn’t work properly…So I’ve research a lot here on the forum and on the documentation and I came up with the solution of adding a var element to compute my reaction time (below) which is working just fine! My only problem is that now I cannot label the trials according to my blocks, the labeling is all messed around, let me show it to you:

new (https://farm.pcibex.net/r/XSJAnP/)

newVar("RT").global().set( v => Date.now() )   <-------------- this is working just fine I guess =)
,
    newKey("keypress1","SK")
        .log()
        .callback( getTimer("timer-RT").stop() )
    ,
    getTimer("timer-RT").wait()
,
    getVar("RT").set( v => Date.now() - v )
....
.log( "ReactionTime" , getVar("RT") )

In R:

#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("results (11).csv")

### add function                                                 <-------------- sth not quite right (maybe because now the EventTime has "never" as valuues, but I don't 
                                                                                                                know how to fix it :(
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)
}

###add blocks with the new function

results_blocks <- results %>%
  group_by(id) %>%
  group_modify(add_blocks)

######################################################## my new filter 

data_results <- results_blocks %>%
  filter(Parameter %in% c("Key","PressedKey")) %>%
  select(id,Label,imagens,Value,Parameter,ReactionTime,block) %>%
  group_by(id) %>%
  mutate(Answer = case_when(is.na(Value) ~ "0",
                            Value == "S" ~ "S",
                            Value == "K" ~ "K")) %>%
  select(-Value) %>%
  select(id,Label,imagens,Answer,ReactionTime,block)

This result file is here => (results (11)) => https://github.com/LariCury/Sample-results.git

I should have 96 items per block, but I guess that the missing values on EventTime are messing the count, I just don’t know how to fix it…Do you have any suggestion?

Best,

  • This reply was modified 2 years, 1 month ago by Larissa_Cury. Reason: add information