Besides baseline correction, the two main preprocessing methods the pupillometry package offers are interpolation and smoothing (also referred to as filtering).
Interpolation is a method to replace missing values in a time-series. There are various ways one can go about replacing missing values. In pupillometry research, two commonly used methods for interpolation are linear interpolation and cubic-spline interpolation.
Smoothing is a method that attempts to reduce noise in a time-series signal by reducing high frequency changes (sudden increase or decrease in values). In pupillometry research, the two commonly used methods smoothing are moving window average and hanning. Both are very similar and essentially filters out high frequency patterns in the data - thus they are often referred to as low-pass or low frequency filters.
pupil_interpolate(tpye = c("linear", "cubic-spline"), maxgap = Inf, hz = "")
type: What type of interpolation to use? (default: cubic-spline)
There are two interpolation types available, "linear"
and "cubic-spline"
.
"linear"
interpolation is aplied using na.approx()
from the zoo package
Linear interpolation uses a linear trend to replace missing values. Linear produces a straight line through missing values, which is most likely not the true underlying trend.
"cubic-spline"
interpolation is applied using na.spline()
from the zoo package and spline()
.
Spline interpolation uses low-degree polynomials in each of the intervals, and chooses the polynomial pieces such that they fit smoothly together. The resulting function is called a spline. Wikipedia. Cubic-spline produces smoother interpolats than a linear function, and may provide a better representation of the true underlying trend. However, more caution needs to be used when applying a cubic-spline. For instance, the article Comparison of Preprocessing Methods demonstrates that smoothing needs to be performed before applying a cubic-spline interpolation.
maxgap: Maximum duration (milliseconds) of NAs to interpolate over. Any gaps over this value will not be interpolated. (default: Inf)
This can be a good idea to avoid interpolating over large chunks of missing data. The default (Inf) does not have a maxgap limit.
hz: The recording frequency of the eyetracker. (Only needed if using maxgap)
If maxgap is specified, then you need to also specify the recording frequency of the eyetracker. This will be used to convert the maxgap in milliseconds to number of samples (rows) in the dataframe.
pupil_smooth(type = c("hann", "mwa"), window = "", hz = "")
type: What type of smoothing to use? (default: “hann”)
There are two smoothing types available, "hann"
and "mwa"
.
"hann"
is a low-frequency hanning filter that retains the low frequency information. It is applied using hanning()
from the dplR package
"mwa"
is a simple moving window average. It is applied using rollapply()
from the zoo package
window: The duration (milliseconds) of the smoothing window
hz: The recording frequency of the eyetracker.
This will be used to convert the window duration in milliseconds to number of samples (rows) in the dataframe.
This function is what sets blinks as missing values and will extend the blink if specified.
Different eye-tracker systems indicate the presence of a blink or missing data in different ways. Some will insert unrealistic values in the pupil size column, others will insert a missing value and have another column indicating whether the sample is likely to be in a blink or not. Also different eye-tracker systems have their different algorithims to detect whether a blink is occuring or not.
Either way, we need to make sure that blinks are represented as missing values (NA
) in the data file. Furthermore, some eye-tracking systems do not fully capture the beginning and end of a blink. This is critical because pupil size will very quickly start to decrease at the start of a blink and increase again towards the end of a blink (due to the pupil being occluded by the eyelid). If the eye-tracker system did not extend the blink detection long enough, then some of this fast decrease/increase may still be in the data.
Since this is something that varies between eye-trackers you can set a custom value to extend the start and end of a blink period.