Pre-processing of eye-tracking data for analysis in the 'eyetrackingR' package

418 views Asked by At

The 'eyetrackingR' package seems promising for the analysis of eye-tracking data but I am encountering an issue when trying to get the data in the appropriate format.

The area of interest (aoi) is set with left, right, bottom, and top bounds, and I want to assess whether the x-y coordinates on any trial fall within the given area. This area differs across participants (based on their screen resolution) but remains the same across trials. I have attempted to simplify the data as much as possible in the first step below.

Here, I create two dataframes. One being the original eye-tracking data with the estimated eye positions in columns 'gaze_x' and 'gaze_y'. Two being the aoi dataset that serves as an input to the 'add_aoi' function later on that assesses whether the estimated position falls within the specified area.

library(eyetrackingR)

datRep <- data.frame(
  stringsAsFactors = FALSE,
  res_x = c(1920L,1920L,1920L),
  res_y = c(969L,969L,969L),
  mid_x = c(960L,960L,960L),
  mid_y = c(484.5,484.5,484.5),
  gaze_x = c(1103.6,1103.6,1103.6),
  gaze_y = c(525.8,525.8,525.8),
  cond = c("fixation","image display","response"),
  pair = c(3L, 3L, 3L),
  trial_time = c(0.00105,0.00105,0.02798),
  selection = c(NA, NA, "right")
)

aoi_left <- data.frame(
  Trial = c(3L,2L, 1L),
  Left = c(0L,0L,0L),
  Right = c(960L,960L,960L),
  Top = c(969L,969L,969L),
  Bottom = c(0L,0L,0L)
)

Now that the sample dataset and the area of interest have been specified, I want to add the latter to the former. This is done according to the example provided here: http://www.eyetracking-r.com/vignettes/preparing_your_data.

datRepAoi <- add_aoi(data = datRep, aoi_dataframe = aoi_left,
                     x_col = "gaze_x", y_col = "gaze_y",
                     aoi_name = "aoi_left",
                     x_min_col = "Left", x_max_col = "Right",
                     y_min_col = "Bottom", y_max_col = "Top")

#> Error in add_aoi(data = datRep, aoi_dataframe = aoi_left, x_col = "gaze_x", : 
Your `aoi_dataframe` has more than one row, but it doesn't have any columns that match the
columns in your data, so it's not clear how to map these rows onto this data.

Created on 2021-04-23 by the reprex package (v2.0.0)

This error persists even if the eye-tracking dataframe's column names are equal to that of the aoi dataframe. Any thoughts as to how this could be solved are greatly appreciated!

1

There are 1 answers

0
Lukas On

It turns out the trial column of the aoi dataframe needs to correspond to the trial column in the raw dataset (i.e. 'Trial'). This is not the case for any of the other columns of the aoi dataframe (e.g. left, right ...).