What I have tried and done so far:
I am running GLMs and GAMs on my positive, continuous response variable.
I have determined that the Gamma distribution would fit my data best by plotting various QQ plots with
EnvStats::qqPlot() function against possible known distributions (Gaussian, Lognorm, Weibull, Gamma).
Then, I started using the Gamma family with it's canonical link function (which is "inverse" in R) but models were bad. Following several statistics books (e.g. Dunn&Smyth 2018) I tried other links like log link, but that was even worse. Only when I tried the "identity" link within Gamma family argument I finally started to get nicer models where diagnostic plots from
gratia::appraise() are acceptable and in general the model results make sense. Also, plotting the models with
gratia::draw() finally yielded partial effect plots where the residuals actually fall along the smoother lines and mostly inside the confidence bands.
I have learned here, here, here and there that the combination is not ideal as the identity link could potentially yield negative predictions. Yet, it seems to be used in some cases and be regularly tested as one potential option (e.g. Dunn&Smyth 2018). Similar to the cited CV posts I receive these warnings when I run the models:
In log(ifelse(y == 0, 1, y/mu)) : NaNs produced
Unlike the other CV posts, I never get the other part, i.e. the error message:
Error: no valid set of coefficients has been found: please supply starting values
My questions now are as follows:
- Does the missing error message mean I am still kind of okay?
- Considering that all alternatives with other links always perform worse in all regards (explained Deviance, diagnostic plots, plotted models), no matter which other predictors I use and how I try changing the model formula: Can I still keep the identity link, if I am cautious?
- If yes, are there indicators to look out for that would tell me the prediction of negative values turned from a theoretical to an actual problem?
- I have read that negative intercepts are a bad sign: can that be an indicator?
- Would I actually see negative fitted values in the fitted vs residual plot of
gratia::appraise()output if the negative predictions became a real issue?
- If all the above is not an option: What else can I do to get similarly nice results but avoiding the identity link problem?
Please excuse me for not providing a reprex: I can't reproduce my problem with dummy data. But I know that several of my observations have zeros for some of the predictor values. I also know that my predictors are often not normally distributed, therefore have often used transformed predictor variables, but that does not seem to improve the models with log link or inverse link in any way; actually, the models with untransformed predictor vars tend to have higher explained Deviance and adj. R².
For illustrating what I mean when I say that in comparison to log link and inverse link models the identity models look better I have created two graphs derived from 3 versions of one and the same gamma model, fitted with this formula
mgcv::gam(y ~ s(var1) + s(var2) + s(var3) + s(var4) +grouping_factor, family=Gamma(link="xyz"),method="REML",data = data) (whereby they only differ wrt the link specified instead of "xyz")
The first graph has diagnostic plots of all 3 models generated by
gratia::appraise(). I have marked in orange, what looked suspicious to me and in blue what I am starting to suspect looks wrong for you:
The second graph shows the
gratia::draw() outputs for the same 3 models.
Still grateful for any help and suggestions, Thanks in advance!