Unable to retrieve initiation times
Hi,
I am currently conducting an online mouse tracking experiment via Gorilla. This is what the mouse tracking data (from performing the task myself) for one trial looks like:
I have been using the following code to analyse the data in R:
library(mousetrap)
library(readxl)
library(data.table)
library(dplyr)
library(ggplot2)
#Getting the mouse tracking files from all the subfolders
xslxfiles<-list.files(pattern="*.xlsx", recursive = TRUE)
#Import all the excel files containing the mouse trajectories in the list.
xlsx.df.list<-lapply(xslxfiles,read_excel)
#Combine all these imported excel files into a single data frame.
gorilla.traj<-rbindlist(xlsx.df.list)
###### Preparing the data for importation as an mousetrap object. ##############
#Drop all the rows that contain coordinates for the zones. In these rows there is no mouse tracking data, so we do not need
#them for now.
gorilla.traj<-gorilla.traj[gorilla.traj$type=="mouse",]
#Removing normalised data leaving the raw ones behind
gorilla.traj<-within(gorilla.traj,rm(x_normalised,y_normalised))
### keep just the relevant columns
gorilla.traj <- gorilla.traj[,c(2, 3, 5, 7, 8)]
######### Importing Gorilla data as a mousetrap object ##############
gorilla.mt<-mt_import_long(gorilla.traj,xpos_label="x",ypos_label = "y",timestamps_label = "time_stamp", mt_id_label=c("participant_id","spreadsheet_row"))
gorilla.mt<-mt_measures(gorilla.mt, use = "trajectories",save_as="measures",
dimensions = c("xpos", "ypos"), timestamps = "timestamps",
verbose = FALSE)
When I use the mt_measures function, the initiation times for most of the trials are recorded as 0 which seems highly unlikely. The initiation times for a very small minority of the trials are recorded accurately. I was wondering whether anyone can help me understand what has gone wrong?
Best wishes,
Hayley
Comments
Hi Hayley,
one note regarding the data import: you could try out the readbulk package to make reading in the data more efficient - with your data it should work like this:
Regarding the initiation times:
First off, I don't know how Gorilla implements mouse-tracking so I can only speculate what might cause the issue.
If they collect mouse-tracking data with standard JavaScript functions I would speculate that the problem is that the mouse cursor position is only recorded when the cursor moves. That is unlike standard lab software (e.g. MouseTracker or our mousetrap plugin for OpenSesame) you cannot simply record the position at a constant rate but only get updates whenever the mouse moves. It probably also means that the first position that is recorded by Gorilla is the one after the first movement.
By default, mt_import_long resets the timestamps during data import so it assumes that you started moving directly at timestamp 0. You could set the reset_timestamps argument of the function to FALSE to use the absolute timestamps - but then again this only makes sense if the timestamp indicate the time since the start of the trial (which based on your spreadsheet I think does not seem to be the case).
So in case my speculations are correct (which you should ideally verify with the Gorilla developers or the documentation), what you would need to do is to preprocess the timestamps in a way that they indicate the time since trial start. Then you could set the reset_timestamps argument to FALSE for the mt_import_long function. Afterwards, I would hope that the initiation time returned by mt_measures is correct. If not, you could us mt_resample first to resample your trajectories so that they contain a log of the position at a constant time interval and - if you know the sampling rate that Gorilla achieves (probably either 8 or 16 ms) you could set the contant_interval argument of that function to this sampling rate. Then, mt_resample automatically adds constant positions for those parts of the trial where there was no movement.
Hope this helps!
Best,
Pascal
Hi Pascal,
Thank you so much for your speedy response! Your speculations about Gorilla was absolutely right. I just tried out your advice and it worked like a charm!
Best wishes,
Hayley