# R squared formula for Generalized Linear Models with GAMMA distribution

I am running a generalized linear model with Gamma distribution in R (glm, family=gamma) for my data (gene expression as response variable and few predictors). I want to calculate r-squared for this model.

I have been reading about it online and found there are multiple formulas for calculating $R^2$ (psuedo) for glm (in R) with Gaussian (r2 from linear model), logistic regression (1-deviance/null deviance), Poisson distribution (using pR2 in the pscl package, D-squared value from the modEvA R package). But I could not find anything specific to Gamma distributions.

Can pscl and modEVA packages be used for the Gamma distribution as well, or is there any other formula for doing the same?

Your question- yes they can be. Technically, you can use a normal r squared measurement as your goodness of fit measure. It might not be a very good fit measure, but you can certainly use it. Further, you have to ask yourself if your increase in precision is worth the loss of readability of your findings. For example, moving from r-squared to an adjusted r-square is likely to be a meaningful increase in precision at the sacrifice of readability. I personally like McKelvey & Zavoina and other similar approaches (e.g. xu's r squared for mixed models). That does not mean they are the best or only approaches.

• Thanks for the clarification. Since I have to incorporate this calculation into a script, I will go with the R packages (pscl or modEvA). When you say it might not be a good fit measure, how accurate and reliable these measures are? Do the actual measures deviate a lot form these calculations or they are close but not accurate estimates?
– aan
Jun 2, 2017 at 15:32
• the key thing to understand is that R squared is an estimation of goodness of fit. Depending on how you calculate it, that estimation might get better or worse. You have your model and you test that against your sample. You can then calculate an R squared value based off of how well your model fit your sample. Different R square calculations will give you different measures of goodness of fit. In general, though, most of these all converge at infinity (i.e. you have a big enough sample and it probably does not matter all that much). Jun 3, 2017 at 0:27
• to directly answer your questions: 1.) when I say goodness of fit, I mean how reliable the evidence they provide about your models "true" fit to the population. 2.) as for the measures deviating, again, it depends. depends on your model and your sample size. But yes, they can and will. Its best to interpret the r-squared value in context of other values. Nothing stops you from using more than one fit measure. Its common in things like structural equation modeling where they use the CLI, TLI, RMSEA, etc in combination to determine goodness of fit. Jun 3, 2017 at 0:32

Pseudo-$R^2$ formulas aren't specific to distributions. Any generalized linear model will have a likelihood associated with it, and those likelihoods can be used to construct whichever pseudo-$R^2$ you prefer. There is a list of pseudo-$R^2$s with their formulas and a description of their nature here.

• Couple of things: 1) In my data the response variable is also a continuous variable, since these pseudo R2 are for logistic regression, will they work in my case as well? 2) According to the link you provided: "A pseudo R-squared only has meaning when compared to another pseudo R-squared of the same type, on the same data, predicting the same outcome."Can I use the pseudo R2 for reporting amount of variability explained rather than comparing purposes? 3) Since R2 values vary a lot for the same model (as in example), which one to prefer for my question.
– aan
Jun 2, 2017 at 18:01
• The psR2 don't necessarily have to be "for logistic regression", they're for GLiMs. You have a GLM, so you could use McFadden's, which is analogous to the amount of variability explained. Jun 2, 2017 at 19:30
• what does a McFadden R2 value of -1.20 mean
– aan
Jun 2, 2017 at 19:44
• can I use DSquared value instead of McFadden R2, as in my case that seem to make more sense (0.14) as compared to McFadden R2 value (-1.20).
– aan
Jun 2, 2017 at 19:52
• You shouldn't be getting a negative number. Which DSquared? Jun 2, 2017 at 20:12