Mixed Model with MATLAB

Example

migraines interictal: subjects 1,2,3,4,5,6,7,8
migraine prodrome: subjects 1,2,9,10,11,12

So there are two subjects that have data in both conditions and I just want to see if the groups are different

Create Excel file with variables

The outcome (dependent) variable can be "Y", then a single variable for group and variables for each subject.

For simplicity, save as "T.xlsx"

Import as a Table into MATLAB
  1. Select T.xlsx
  2. Change group and subject variable types to "Categorical" 
  3. Set variable names to first row, import as table (both default), then select the numeric data (not 1st row), and "Import Selection"  
  4. This will import the data into a table "T" (name is based on the Excel filename). You can check by typing "T" at the command prompt, or looking at the workspace: 


Create a mixed effects model
>> lme = fitlme(T,'Y~Interictal+(1|Subject1)+(1|Subject2)')

The "T" is the table just imported.

The formula is based on the variable names in the table. "Y" is the output variable, and "Y~Interictal"  indicates treating the group variable "Interictal" as a fixed effect. Each "1|Subject1" indicates that the variable "Subject1" is a random effect. The output gives assessment of the model: