Problem with a random effect with 2 levels in fitExtractVarPartModel() from the the variancePartition package?

56 Views Asked by At

I'm running a variance decomposition to understand how different predictors contribute to explaining the variance in a variable of interest. I'm using fitExtractVarPartModel from the variancePartition package in R (which I realize is old at this point, but I'm trying to keep with the code I have since it works nicely with figures I made a while back). I'm trying to understand the variance contributions for each term below:

var2 ~ var1 + (1|age) + (1|species) + (1|year) + (1|plant), where var1 is a continuous variable and the rest are categorical.

However, I'm wondering if I can do this, given that 'age' only has two levels, and a random effect should typically have > 10 levels. Is this rule not relevant when running a variance decomposition as I am now?

The following works, except for the issue of only two levels in the random effect 'age':

form <- ~ var1 + (1|age) + (1|species) + (1|year) + (1|plant)

matrix <- df %>% 
  ungroup() %>% 
  mutate(id = row_number()) %>% 
  select(id, log_lfm) %>% 
  pivot_wider(names_from = id, 
              values_from = log_lfm) 

varPart <- fitExtractVarPartModel(matrix, form, df)
varPart

When I try treating that as a fixed effect, such that the form is:

form <- ~ var1 + age + (1|species) + (1|year) + (1|plant)

Then I get this message:

Error in checkModelStatus(fitInit, showWarnings = showWarnings, colinearityCutoff = colinearityCutoff) : Categorical variables modeled as fixed effect: age_new The results will not behave as expected and may be very wrong!!

Can I just go with the original version?

0

There are 0 best solutions below