0

This is my data.

'data.frame':   100 obs. of  11 variables:
X        : int  1 2 3 4 5 6 7 8 9 10 ...
Lifestage: chr  "AD" "AD" "AD" "AD" ...
Inac     : int  24 12 2 4 22 20 12 12 16 22 ...
Forg     : int  5 8 0 13 13 2 8 7 7 17 ...
Groom    : int  13 9 9 2 25 25 7 8 19 13 ...
Coop     : int  1 21 0 5 10 11 24 17 16 12 ...
Agr      : int  0 4 1 3 5 4 2 1 6 2 ...
Prov     : int  7 6 0 0 5 0 5 3 3 1 ...
Beg      : int  0 9 1 0 1 2 9 9 7 5 ...
Begg     : logi  TRUE FALSE FALSE TRUE FALSE FALSE ...

HLact   : int  8 40 2 8 21 17 40 30 32 20 ...

I am using mixed model using formula:

> full = glmer.nb(Groom ~ Lifestage + (1 | Inac) * (1 | Coop) * (1 | Agr) * 
                  (1 | Prov) * (1 | Beg), data = d)

But, when I am trying to visualize the model using 'flexplot' package,

visualize(full, plot = "model", sample = 3)

this is showing an error :

Error in model.frame.default(tt, newdata.NA, na.action = na.pass, xlev = orig.random.levs) : variable lengths differ (found for 'Agr')

I am trying to visualize the mixed model, but an error is showing that variable lengths differ. Why and how to fix this error ?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • We really need a [mcve] in order to be able to help (see also https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This kind of error usually occurs because you have copies of some the variables in your global workspace (with different lengths, e.g. because you did some subsetting), or because you used `attach()` in an inadvisable way. Does this happen in a clean R session where all you have done is to load the data? See e.g. https://stackoverflow.com/questions/30227989/using-lme4-glmer-function-for-unbalanced-treatment-comparison-results-in-variabl?rq=2 – Ben Bolker Mar 25 '23 at 23:35
  • Yes, this happens in a clean R session also. Every time i run this code, it's showing "variable lengths differ (found for 'Agr')", or variable lengths differ (found for 'Coop'). – Akash Dutta Mar 27 '23 at 14:17
  • (1) 'multiplying' random effect terms (e.g. `(1|a) * (1|b)`) is very strange, normally they are added - did you mean to do this? If so, what were you trying to accomplish? (2) `flexplot` is not on CRAN, so it would be good to tell us that it's available via `remotes::install_github("dustinfife/flexplot")`; (3) we can't debug this without a reproducible example ... – Ben Bolker Mar 27 '23 at 14:25

0 Answers0