I am trying to understand how to solve the following error when I try and run a glmer
in R using the lme4
package:
Error: number of levels of each grouping factor must be < number of observations.
To give some background, I am asking the question of whether having a certain amount of a specific phylum of bacteria is associated with relative mass gain in a population of animals I am studying. I have a pretty small sample size, 20 unique individuals. My fixed effects are relative mass gain, bacterial phyla 1, phyla 2, age, and date with the random effect of individual, colony area, and year. This is the code I am running:
Model1 <- glmer(relative_growth ~ firmicutes + bacteroidetes + age_class + date +
(1|uid) + (1|col_area) + (1|year), data = microbiome)
Here is a sample subset of my data:
dput(microbiome[1:5],)
structure(list(uid = structure(c(5L, 8L, 11L, 13L, 9L, 10L, 1L,
12L, 16L, 17L, 18L, 14L, 20L, 19L, 7L, 4L, 15L, 6L, 2L, 3L), .Label = c("6127_7339",
"6385_6342", "6609_7388", "6835_6898", "7131_7126", "7187_7189",
"7279_7197", "7365_7368", "7640_7641", "7753_7754", "7755_7756",
"7780_7781", "7783_7793", "7828_7874", "7830_7849", "8005_8009",
"8111_8107", "8476_8478", "8491_8492", "8497_8488"), class = "factor"),
year = c(2015L, 2015L, 2016L, 2016L, 2016L, 2016L, 2016L,
2016L, 2017L, 2017L, 2018L, 2018L, 2018L, 2018L, 2016L, 2016L,
2018L, 2018L, 2018L, 2015L), col_area = structure(c(4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 3L, 2L, 3L, 3L, 4L, 1L, 2L,
2L, 3L, 1L), .Label = c("boulder", "gothictown", "mm_maintalus",
"picnic_lower"), class = "factor"), date = structure(c(10L,
8L, 5L, 4L, 15L, 15L, 4L, 2L, 12L, 1L, 14L, 9L, 14L, 14L,
7L, 3L, 11L, 6L, 13L, 16L), .Label = c("11-Jun-17", "13-Jul-16",
"14-Jun-16", "15-Jun-16", "16-Jun-16", "18-Jun-18", "2-Jun-16",
"20-Jul-15", "21-May-18", "22-Jun-15", "22-May-18", "25-Jun-17",
"27-Jun-18", "28-May-18", "3-Jun-16", "9-Jul-15"), class = "factor"),
age_class = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L), .Label = c("A",
"Y"), class = "factor")), row.names = c(NA, -20L), class = "data.frame")