Consider the following model modeling nine genotypes (integer numbers) by their growth pattern (The ratio of plant height growth over plant diameter growth) over time (in day of the year).
m2 <- gam(list(Genotype_nr ~ s(Ratio, Doy) +
s(Individual, bs = "re") +
s(Doy, Individual, bs = "re"),
~s(Ratio, Doy) +
s(Individual, bs = "re") +
s(Doy, Individual, bs = "re")),
family = multinom(K = 8),
method = "REML",
data = data2)
This returns the error "Error in gam(list(Genotype_nr ~ s(Ratio, Doy) + s(Individual, bs = "re") + : incorrect number of linear predictors for family"
I´ve tried changing the response variable to numeric and I´ve tried simplifying the model. Ive also tried altering K in the multinom() family argument but nothing helped.
Here is also some info on the structure of the data: Data structure
and some session info: Session info
Does anybody has a suggestion on what might be the cause of this error?
Thanks in advance!
You told the model that there were 9 classes (K = 8
), but you only provided 2 linear predictors, both of which are the same. You need to provide 8 linear predictors. If you want them all to include the same terms we can use the short cut described in ?formula.gam
:
m2 <- gam(list(Genotype_nr ~ s(Ratio, Doy) +
s(Individual, bs = "re") +
s(Doy, Individual, bs = "re"),
~ -1,
~ -1,
~ -1,
~ -1,
~ -1,
~ -1,
~ -1),
family = multinom(K = 8),
method = "REML",
data = data2)
If you want different models, you need to specify the linear predictors separately.