Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Highlight duration offset or remove timestamps

I did an experiment in which participants listened to audio files. I would like to know

1). How can I highlight the offset of the audio file in the plots, i.e. mark the point in time at which listeners will have heard the audio file?

Since this might lead to potentially messy plots, perhaps a better alternative would be to remove timestamps before that time, hence question two:

2). How can I remove all timestamps in the trajectories that occur before the audio file has completed playing?

I assume 2). is also a bit tricky, as the duration of the audio file is different for each of the items.

Comments

  • Hi there,

    I think this question is somewhat similar to the following thread: https://forum.cogsci.nl/discussion/4412/selecting-data-for-mouse-measures

    However, here the difference is that the duration that should be excluded in a trial varies between trials. I have a potential workaround for implemeting 2 using mousetrap, assuming that the duration of the audio file is recorded in the trial data and stored within mt_data.

    Here is an example script. Please make sure to run it with the most recent version of mousetrap (3.2.0 on CRAN at the time of this post).

    library(mousetrap)
    
    # Get example data from mousetrap package
    mt_data <- mt_example
    
    # Create random time variable between 200 and 300 ms for example
    mt_data$data$random_time <- sample(200:300, size = nrow(mt_data$data))
    
    # Set xpos and ypos before this random time variable to constant value
    # (pick unusual value so it does not coincide with typical start position)
    mt_data$trajectories[,,"xpos"][mt_data$trajectories[,,"timestamps"]<mt_data$data$random_time] <- 9999
    mt_data$trajectories[,,"ypos"][mt_data$trajectories[,,"timestamps"]<mt_data$data$random_time] <- 9999
    
    # Check that implementation worked
    mt_data$data$random_time[3]
    mt_data$trajectories[3,,]
    
    # Remove initial phase in trial with constant position
    # (which removes all but the last of the recently set constant values in a trial)
    mt_data <- mt_exclude_initiation(mt_data, reset_timestamps = TRUE)
    
    # Set value of first position to second position
    # (to ensure that start position makes sense and does not resemble our weird values set above)
    mt_data$trajectories[,1,"xpos"] <- mt_data$trajectories[,2,"xpos"]
    mt_data$trajectories[,1,"ypos"] <- mt_data$trajectories[,2,"ypos"]
    

    Please note that this solution introduces an artifial constant interval of one logged position at the beginning of the trial (see last four lines of example code), however, assuming a constant high frequency recording of the cursor position (as is common in typical lab software like OpenSesame with the mousetrap plugin) this should not be an issue.

    Hope this helps!

    Best,

    Pascal

Sign In or Register to comment.