Calculate standard error of contrast using a linear mixed-effect model (fitlme) in MATLAB

552 views Asked by At

I would like to calculate standard errors of contrasts in a linear mixed-effect model (fitlme) in MATLAB.

y = randn(100,1);
area = randi([1 3],100,1);
mea = randi([1 3],100,1);
sub = randi([1 5],100,1);

data = array2table([area mea sub y],'VariableNames',{'area','mea','sub','y'});
data.area = nominal(data.area,{'A','B','C'});
data.mea = nominal(data.mea,{'Baseline','+1h','+8h'});
data.sub = nominal(data.sub);

lme = fitlme(data,'y~area*mea+(1|sub)')

% Plot Area A on three measurements
coefv = table2array(dataset2table(lme.Coefficients(:,2)));
bar([coefv(1),sum(coefv([1 4])),sum(coefv([1 5]))])

Calculating the contrast means, e.g. area1-measurement1 vs area1-measurement2 vs area1-measurement3 can be done by summing the related coefficient parameters. However, does anyone know how to calculate the related standard errors?

I know a hypothesis test can be done by coefTest(lme,H), but only p values can be extracted.

An example for Area A is shown below:

Example

1

There are 1 answers

0
Alexm On

I have resolved this issue!

Matlab uses the 'predict' function to estimate contrasts. To find confidence intervals for area A, at measurement +8h in this particular example use:

dsnew = dataset();
dsnew.area = nominal('A');
dsnew.mea = nominal('+8h');
dsnew.sub = nominal(1);

[yh yCI] = predict(lme,dsnew,'Conditional',false)

A result is shown below:

enter image description here