Search code examples
rlogistic-regressionglmcoefficient-of-determination

Pseudo R-squared for glm.cluster object


I have estimated several glms with cluster robust standard errors using the function glm.cluster() from the miceadds package in R.

Unfortunately, the function does not automatically calculate a pseudo R-squared. Moreover, I am unable to find a package for calculating a pseudo R-squared that is compatible with glm.cluster. So far, I have tried rcompanion's nagelkerke(), fmsb’s NagelkerkeR2() and even psfmi's rsq_nagel().

Did anyone else face this problem before and do you know how to resolve it without writing one's own function?


Solution

  • glm.cluster returns a two-element list, the first element of which (called $glm_res) is the actual glm fit. I used performance::r2_nagelkerke() because that was what I had handy, but any Nagelkerke R2 function will probably work if you apply it to the $glm_res component.

    Set up example:

    data(data.ma01, package = "miceadds")
    dat <- data.ma01
    dat$highmath <- 1 * ( dat$math > 600 )   # create dummy variable
    mod2 <- miceadds::glm.cluster( data=dat, formula=highmath ~ hisei + female,
                         cluster="idschool", family="binomial")
    
    library(performance)
    r2_nagelkerke(mod2$glm_res)
    ## Nagelkerke's R2 
    ## 0.05126081