calculate partial eta squared from fitlme

76 ビュー (過去 30 日間)
Josh Cisler
Josh Cisler 2019 年 8 月 19 日
コメント済み: MM 2023 年 9 月 6 日
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

回答 (1 件)

Nikhil Sonavane
Nikhil Sonavane 2019 年 8 月 22 日
Toolbox can help you compute the eta squared of your data. You may refer to this link for more details.
  2 件のコメント
Lucas Parra
Lucas Parra 2022 年 1 月 11 日
編集済み: Lucas Parra 2023 年 5 月 6 日
The definition of Eta square is where SSE and SST are the sums of squares of the estimate and of the original signal. Say a simple example where x predicts y linearly:
tbl = table(x,y,'VariableNames',{'x','y'})
Unrecognized function or variable 'x'.
model = fitlme(tbl, 'y ~ x')
y_est = fitted(model);
Eta2 = var(y_est)/var(y)
Have used variance here instead of sum of squarease as it amounts to the same except for a common scaling factor N-1. 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 that is explained by the partial term of interest, and SSR is the sum of square of the residual. Note that this is the same formula as above, because . To calcualte SSEp you have to compute the model with the partial term of interest removed and then take difference of SSE for the full model and the model with the part of interest removed: . 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');
y_est = fitted(model);
residual = y-y_est;
% estimate total effect size
Eta2=var(y_est)/var(y)
% estimated the model with the partial term of interest removed, here x2
model_no_p = fitlme(tbl, 'y ~ x1');
y_est_no_p = fitted(model_no_p);
var_p = var(y_est)-var(y_est_no_p);
% partial effect size for effect of x2 on y
Eta2_p=var_p/(var_p+var(residual))
You can do the same for any of the other terms, including an interaction term. I suppose one can also include random effects in the model, but I am no sure. Would love to hear of corrections if I got any of this wrong. Please note that when N is small, the effect size tends to be over-estimated.
A great toolbox to calculate all kinds of effect sizes it this: measures-of-effect-size-toolbox. It includes one and two way anova for categorical variables, but I dont think it includes linear effects for graded varaible nor mixed effects. It is that code where I learned how to compute the SSEp.
MM
MM 2023 年 9 月 6 日
Can this method also be used for 3 independent variables? Where x1,x2,x3 are the independent variables and x4 random effect variable.
tbl = table(x1,x2,y,'VariableNames',{'x1','x2','x3','x4','y'});
model = fitlme(tbl, 'y ~ x1.x2.x3 + (1|x4)')
How can this be done with interactions?

サインインしてコメントする。

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by