I am following a code snippet someone provided for calculating Nagelkerke R2:
N <- my_prevalence ##base model glm0 <- glm(as.formula(paste("my base model")), data = dat, family = binomial(logit)) # logistic full model glm1 <- glm(as.formula(paste("my full model")), data = dat, family = binomial(logit)) # Calculate Cox & Snell R2 using log Likelihoods LL1 <- logLik(glm1) LL0 <- logLik(glm0) CSr2 <- round(1 - exp((2 / N) * (LL0 - LL1)), 6) # Calculate Nagelkerke's R2 NKr2 <- round(CSr2 / (1 - exp((2 / N) * LL0)), 6) # Test whether NKr2 is significantly different from 0 devdiff <- round(glm0$deviance - glm1$deviance, 1) df <- glm0$df.residual - glm1$df.residual degree of freedom NKr2_pval <- pchisq(devdiff, df, lower.tail = F)
To check my understanding, this link mentions that
- "Deviance is a number that measures the goodness of fit of a logistic regression"
- "deviance = 0 means that the logistic regression model describes the data perfectly"
Here it looks like what they are doing is taking the difference of the deviance from each model and testing that for significance. Is that right?
What I don't understand is that they mention testing "whether NKr2 is significantly different from 0",how would saying that be different from saying that they are testing if the difference of the deviance from each model is significant?