Analyzing Pupil Dilation Data in R

One of the measures we can analyze using eye tracking is pupil dilation. It is typically correlated with emotional activation and mental effort. [REF1; REF2; An old but useful review] However, this type of analysis usually requires manual processing. Here I will try to share some tips and example R script on how to do such analysis.

First off, we need to decide the time segments from which we will extract the baseline pupil diameter (baseline segment), and the pupil diameter data that will be analyzed (stimulus segment).

Having an individual baseline for each participant is important because it corrects for individual and situational differences; for example, a participant might be thinking about something emotional that is irrelevant to our experimental manipulation, affecting their pupil dilation.

After having decided the time segments, we need to select data points falling in each segment and start the baseline correction. To get the baseline value we need to average all data points that are in our baseline segment. This segment is typically just before the stimulus segment and it goes from about half a second up to five seconds or more, depending on the experimental design. During the baseline segments participants should be presented with a static stimulus that does not activate them neither cognitively nor emotionally (e.g. a fixation cross).

After obtaining our baseline value, we need to subtract it from our data points during the stimulus segment. Then, depending on the type of analysis we want to do, we either work directly on the “corrected” pupil data, or we average that, to use it in an analysis of variance or similar.

Researchers typically do signal corrections before analyzing the data, such as missing data interpolation and noise reduction. There are different methods for each and it’s usually best consulting the relevant literature to our research to see what is accepted in our field in order not to get into trouble publishing our results later on. It is however good practice, in case you have binocular pupil data, to do the filtering and interpolation for each eye before you average left and right pupil diameter.

For a practical example you can follow this link to download an R script and a dataset collected doing a variation of the Posner task. You can see how segment selection and baseline correction are done and finally you can see the effect of cue validity on pupil diameter.

I hope this helps. If you have any questions, need help with your analysis or looking for references please feel free to contact me.