Azzera filtri
Azzera filtri

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

9 visualizzazioni (ultimi 30 giorni)
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 Commenti
Aditya Patil
Aditya Patil il 17 Nov 2020
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 il 17 Nov 2020
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

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by