Remove track loss trials from visual world eye-tracking data

One step of cleaning visual world eye-tracking data is to exclude track loss trials. These are trials where for an extensive amount of time, no eye gaze was detected on any objects in the visual display. There are multiple reasons for track loss. For example, the participant may not have paid attention to the visual display, or the eye-tracker may have been ‘drifting’. On this page, I share an R function that removes track loss trials from visual world eye-tracking data.

My method is inspired by the eyetrackingR package.

Step 1: Preparation

Download the R script.

Prepare your data. As an R data frame, your data should contain at least three columns:

sample_data

Step 2: Source the function

Open your IDE for R. Here, I’m using RStudio. Open remove_trackloss.R, and source it by pressing source. The function should be loaded to your R environment.

source

Step 3: Run the function

Next, load your data and remove track loss trials by running:

cleaned_data <- remove_trackloss(data=data, subject_col = 'subject', trial_col = 'trial', trackloss_col = 'tracked', threshold = 0.5)

Where:

The function is going to return a data frame that has all the track loss trials removed.

cleaned

In addition, the console output tells you the data frame it was working with, the number of trials excluded, the (original) total number of trials, and the percentage excluded. It should look like something like this:

output

Back to Top ↑