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

조회 수: 3 (최근 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개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by