calculate partial eta squared from fitlme

48 views (last 30 days)
Josh Cisler
Josh Cisler on 19 Aug 2019
Edited: Lucas Parra on 11 Jan 2022
Hello,
I am hoping to calculate the partial eta squared for an interaction term in a linear mixed effects model. It does not seem matlab's fitlme provides measures of effect sizes. For example, in R, a model summary function on the lme structure, ie modelEffectSizes (lme), provides a partial eta squared for each variable indicating the partial eta squared. Is there a comparable way to get these values, or calculate them, from the lme structure provided by fitlme?
Thanks,
Josh

Answers (1)

Nikhil Sonavane
Nikhil Sonavane on 22 Aug 2019
Toolbox can help you compute the eta squared of your data. You may refer to this link for more details.
  1 Comment
Lucas Parra
Lucas Parra on 11 Jan 2022
The definition of Eta square is where SSE and SST are the estimated and total sums of squares. Say a simple example where x predicts y linearly:
tbl = table(x,y,'VariableNames',{'x','y'})
model = fitlme(tbl, 'y ~ x')
y_est = fitted(model)
Eta2=var(y_est)/var(y)
If you want the partial Eta square you have to compute the portion that the partial factor explains. The definition is , where SSEp is the sum of squares for the part of y that is explained by the variable of interest, and SSR is the sum of square of the residual. Note that this is the same formula as above as . To calcualte SSEp you have to compute the estimate yourself and keep only the part that interests you. Say x1 and x2 explain y, and you are interested in Eta square for the partial effect of x2 on y. Here the code with some simulated data ...
% simulate some data
N=100;
x1 = randn(N,1);
x2 = randn(N,1);
y = 1*x1 + 1*x2 + randn(N,1);
% build model
tbl = table(x1,x2,y,'VariableNames',{'x1','x2','y'});
model = fitlme(tbl, 'y ~ x1 + x2 + x1*x2'); % allowing for interaction here
% estimate effect size
beta = fixedEffects(model);
y_est= [x1 x2 x1.*x2]*beta(2:4);
y_x2 = [ x2 ]*beta(3);
residual = y - y_est;
Eta2=var(y_est)/var(y) % total effect size
Eta2_x2=var(y_x2)/(var(y_x2)+var(residual)) % partial effect size for effect of x2 on y
You can do the same for any of the other terms, including the interaction term. Would love to hear of corrections if I got any of this wrong.

Sign in to comment.

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!