calculate partial eta squared from fitlme
40 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
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'})
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
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?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!