Bidimensional regression can be used to transform the eye gaze data into a the screen coordinate system using a calibration sequence. For this, we use known target coordinates as independent variables. Please note that the example below assumes that participants fixate faithfully for most of the time and that recording artifacts, such as blinks, were already removed. This example will use the example dataset.
ggplot(data= EyegazeData, aes(x= x, y= y, color= target, fill= target)) +
geom_point(data= EyegazeData %>% group_by(target, target_x, target_y) %>% summarise(.groups="drop"),
aes(x= target_x, y= target_y), shape= 21, size= 10, fill= 'white') +
geom_point(alpha= 0.5, shape= 21, show.legend=FALSE) +
ggtitle('Raw eye gaze')
lm2aff <- fit_transformation(target_x + target_y ~ x + y, EyegazeData, transformation = 'affine')
#>
#> SAMPLING FOR MODEL 'tridim_transformation' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 0.000168 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.68 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
#> Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
#> Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
#> Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
#> Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
#> Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
#> Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
#> Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
#> Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
#> Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
#> Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
#> Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 5.639 seconds (Warm-up)
#> Chain 1: 2.882 seconds (Sampling)
#> Chain 1: 8.521 seconds (Total)
#> Chain 1:
adjusted_gaze <- predict(lm2aff, summary=TRUE, probs=NULL)
colnames(adjusted_gaze) <- c('adjX', 'adjY')
adjusted_gaze <- cbind(EyegazeData, adjusted_gaze)
ggplot(data= adjusted_gaze, aes(x= adjX, y= adjY, color= target, fill= target)) +
geom_point(data= adjusted_gaze %>% group_by(target, target_x, target_y) %>% summarise(.groups="drop"),
aes(x= target_x, y= target_y), shape= 21, size= 10, fill= 'white') +
geom_point(alpha= 0.5, shape = 21, show.legend = FALSE) +
xlab('x')+
ylab('y')+
ggtitle('Adjusted eye gaze')