Why R-squares are different between "fitglm" and "fitglme"? or how do "fitglme" and "fitglm" calculate R-squared?

9 次查看(过去 30 天)
Hi,
I am using "fitglme" for fitting a mixed-effect logistic regression model.
I could have R-squared from the fitted model.
glme.Rsqaured.Adjusted
Then, I tried to have individual-subject R-squared by using "fitglm" for each subject.
But, the subjectwise-averaged R-squared from "fitglm" was so different from the R-squared of "fitglme".
Why are they so different?
I found that the "fitglm"s R-squared can be derived by the definition of R-squred:
y = glm.Variable.y;
yhat = glm.predict;
ybar = mean(y);
SST = sum((y-ybar).^2);
SSR = sum((yhat-ybar).^2);
R_square = SSR/SST;
R_square_glm = glm.Rsquared.Ordinary;
R_square = R_square_glm;
However, "fitglme"s R-squred is different from the derived R-squared;
y = glme.Variable.y;
yhat = glme.predict;
ybar = mean(y);
SST = sum((y-ybar).^2);
SSR = sum((yhat-ybar).^2);
R_square = SSR/SST;
R_square_glm = glme.Rsquared.Ordinary;
R_square ~= R_square_glm;
How shoud I understand this inconsistency?
I will highly appreciate for you help!
  4 个评论
Aditya Patil
Aditya Patil 2020-11-17
How different is it? Some small differences might be present due to floating point accuracy. Can you provide complete code to reproduce the issue?
Heeseung Lee
Heeseung Lee 2020-11-17
Hi Aditya!
Here is the code
x = rand(100,1);
y = (x*2 + normrnd(0,1,100,1))>1;
Reg = cell2table(num2cell([x y]),'variablenames',{'x','y'});
glm = fitglm(Reg,'y~1+x','distribution','binomial','link','logit');
glme = fitglme(Reg,'y~1+x','Distribution','Binomial','Link','Logit');
glm.Rsquared
glme.Rsquared
and the output printed in the command window
>> glm.Rsquared
ans =
struct with fields:
Ordinary: 0.1766
Adjusted: 0.1682
LLR: 0.1309
Deviance: 0.1309
AdjGeneralized: 0.2199
>> glme.Rsquared
ans =
struct with fields:
Ordinary: 0.1968
Adjusted: 0.1886

请先登录,再进行评论。

回答(0 个)

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by