I'm trying to create a GAM model using environmental variables and mean abundance data.
and the code I'm using to create the model is so:
imod2 <- gam(mean ~ s(BO_chlomean, bs="cr"), data = envgroup2, family = poisson, method="REML", na.action = na.fail, select=T)
(ideally I want to add the other 2 variables but one thing at a time.)
however when I run the code I get:
Error in if (abs(old.score - score) > score.scale * conv.tol) { :
missing value where TRUE/FALSE needed
I also get 50 or more warnings, consisting of:
1: In dpois(y, y, log = TRUE) : non-integer x = 0.200000
i'm very new to R and finding to hard to understand. any help to sort this issue would be amazing
You're asking gam()
to fit a model assuming an integer response and passing it a real-valued (decimal) variable.
If you have replicate counts and averaged them to get the mean
variable, then don't do the averaging. Include all rows of data and deal with the clustering by subject with a random effect term.
If you got mean
by scaling by an effort variable, you should fit the model with the original count/integer values and add offset(log(effort_var))
to the formula where effort_var
is the variable you divided the original response by to get mean
.