Besides baseline correction, the two main preprocessing methods the pupillometry package offers are smoothing (also referred to as filtering) and 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.

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

pupil_smooth(type = c("hann", "mwa"), n = "")

  • 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(n = n) from the dplR package

    "mwa" is a simple moving window average. It is applied using rollapply(width = n) from the zoo package

  • n: The size (in pupil samples) of the smoothing window

Interpolation

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.