Here we show how to fit a linear model to single subject’s data. We’ll use the data from the LIMO EEG dataset. S1

The linear model fitting function in eegUtils uses the epochs field of the data structures. To use these for linear modelling here, we’ll add the categorical and continuous predictors to the epochs structure.

The first argument to fit_glm() is a standard R formula, using Wilkinson notation. Unusually, the left hand side of the ~ is omitted, since we’ll be fitting the model to every electrode at every timepoint. On the right hand side, we put our predictors. In this case, we have two: face, a categorical predictor; and phase_coherence, a continuous predictor. The appropriate formula is thus ~face + phase_coherence.

The function fits whatever contrasts. R’s default contrasts are treatment or dummy contrasts, so we’ expect the model to return three coefficients: an intercept, which will be the amplitude when the categorical predictor is at its first level (i.e. Face A); a face term, which will be the difference in amplitude from the intercept when the level of Face is Face B; and a phase_coherence term, which will be the increase in amplitude when image phase coherence increases from 0 to 1.

An alternative paramterization would be to remove the intercept term. The function would then return separate coefficients represent Face A and Face B. This would be particularly helpful if you are planning to take these coefficients forwards to a second-level analysis.

Continuous predictors can be rescaled using the scale() function, which converts them to z-scores (i.e. standard deviation units).

The function also provide additional information. For example, we can get the \(r^2\) value representing model fit: