1

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!

1 Answers1

0

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.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
  • Thanks for the answer. Should you close the list() for each linear predictor? The formula above results in a new error "Error in terms.formula(formula, data = data) : argument is not a valid model" – Bertold Mariën Mar 22 '23 at 21:34
  • @BertoldMariën My mistake, sorry; no, I shouldn't be closing the list each time (copy/paste bug) – Gavin Simpson Mar 23 '23 at 07:19