# How to transform count response variable including zero values to non-negative values for fitting a GAM analysis?

I am trying to fit a GAM model that the response variable is count var (species richness) and the predictor variable is elevation. In my dataset there are some zero values for richness in some elevation. This is my model:

mod2 <- gam(Richness ~ s(Elevation, bs="cr"), family=poisson(), data=Palvar.env, method = "REML", scale= 1)


This is the result of gam.check:

 k'  edf k-index p-value
s(Elevation) 9.00 8.75    0.78   0.015 *


and the residuals plots are not bad, but not satisfying! The graph resulting of "plot(mod2)"is different from the ggplot graph after doing "predict" function.

My question would be, can this problem as a result of zero values of response variable? I tried to transform the richness with log and sqrt, but the error is:


negative values not allowed for the 'Poisson' family or

Error in if (abs(old.score - score) > score.scale * conv.tol) { :
missing value where TRUE/FALSE needed
In addition: There were 50 or more warnings (use warnings() to see the first 50)


I really appreciate it if anyone could help me for solving this problem.

• Greetings! Can you show the plots you mentioned so it is easier for people to answer the question? Commented Feb 21, 2023 at 13:01
• The error message may make more sense to people familiar with software, but -- apart from transformation not being a good idea here, as explained in answers -- log of zero is not defined in any case. Commented Feb 22, 2023 at 11:55

The Poisson distribution isn't a very flexible distribution because it is defined by a simple location parameter $$\lambda$$, the expected rate (or count). The variance of a Poisson is also $$\lambda$$. Many types of data that otherwise look like a count (species abundances, richness) can exhibit more variance than implied by a Poisson distribution with a given $$\lambda$$.
It's really hard to tell from your diagnostic plots (render to a physically larger device) but it looks like your data have more variance than expected from an assumption that the data are conditionally distributed Poisson with expected (mean) count $$\exp(\mu_i)$$, where $$\mu_i$$ is the fitted value of the model for the $$i$$th observation on the scale of the linear predictor.