У меня есть данные, в которых отсутствуют значения, как я могу заставить модель glmer читать их как 0, чтобы я мог этого избежать ... Я знаю, что у меня меньше наблюдений, чем случайных эффектов, я просто плохо понимаю R достаточно, чтобы исправить это.
Это данные, на которых я пытаюсь запустить модель.
> dput(as.data.frame(wi.age.count))
structure(list(Year = c("2008", "2009", "2010", "2011", "2012",
"2013", "2014", "2015", "2016", "2017", "2018", "2007", "2007",
"2007", "2007", "2008", "2008", "2008", "2009", "2009", "2009",
"2009", "2009", "2009", "2009", "2010", "2010", "2010", "2010",
"2010", "2011", "2011", "2011", "2011", "2011", "2011", "2011",
"2011", "2011", "2012", "2012", "2012", "2012", "2012", "2012",
"2012", "2012", "2013", "2013", "2013", "2013", "2013", "2013",
"2013", "2013", "2014", "2014", "2014", "2014", "2014", "2014",
"2014", "2014", "2014", "2015", "2015", "2015", "2015", "2015",
"2015", "2015", "2015", "2015", "2016", "2016", "2016", "2016",
"2016", "2016", "2016", "2017", "2017", "2017", "2017", "2017",
"2017", "2017", "2018", "2018", "2018", "2018", "2018", "2018",
"2018", "2018"), Age = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 3L, 6L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 2L, 3L, 4L, 5L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 10L, 2L, 3L, 4L, 5L, 6L, 7L, 10L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), .Label = c("0", "1",
"2", "3", "4", "5", "6", "7", "8", "9"), class = "factor"), n = c(166,
28, 34, 77, 170, 18, 3, 22, 43, 50, 151, 1, 8, 17, 1, 4, 19,
1, 1, 46, 37, 52, 5, 1, 1, 19, 41, 15, 16, 1, 1, 13, 4, 26, 12,
11, 1, 1, 1, 1, 87, 15, 13, 27, 13, 17, 1, 1, 32, 30, 3, 4, 1,
1, 1, 1, 24, 15, 23, 6, 2, 1, 2, 2, 4, 18, 13, 31, 28, 3, 3,
6, 1, 4, 6, 1, 5, 9, 1, 1, 1, 16, 16, 8, 1, 1, 4, 1, 12, 4, 7,
2, 1, 2, 1), id = c("YOY", "YOY", "YOY", "YOY", "YOY", "YOY",
"YOY", "YOY", "YOY", "YOY", "YOY", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult", "Adult", "Adult", "Adult",
"Adult", "Adult", "Adult", "Adult"), Cohort = c("2008", "2009",
"2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017",
"2018", "2007", "2006", "2005", "2002", "2007", "2006", "2005",
"2009", "2008", "2007", "2006", "2005", "2004", "2003", "2009",
"2008", "2007", "2006", "2001", "2011", "2010", "2009", "2008",
"2007", "2006", "2005", "2004", "2003", "2012", "2011", "2010",
"2009", "2008", "2007", "2006", "2005", "2013", "2012", "2011",
"2010", "2009", "2008", "2007", "2006", "2014", "2013", "2012",
"2011", "2010", "2009", "2008", "2007", "2006", "2015", "2014",
"2013", "2012", "2011", "2010", "2009", "2008", "2006", "2015",
"2014", "2013", "2012", "2011", "2010", "2007", "2017", "2016",
"2015", "2014", "2013", "2012", "2011", "2018", "2017", "2016",
"2015", "2014", "2013", "2012", "2011")), row.names = c(NA, -95L
), class = "data.frame")
Данные выглядят так, за исключением того, что модели требуются значения, в которых они «отсутствуют» . На самом деле они не пропадают, они должны быть нулями. Есть ли способ добавить их в мой фрейм данных? Данные выглядят так, за исключением того, что модели нужны значения там, где они есть.
Это модель, которую я пытаюсь запустить.
> glmer(n~ Age + (1|Cohort) + (Age|Year), data=wi.age.count, subset=as.numeric(as.character(Cohort))>2005, family=poisson)
Error: number of observations (=84) < number of random effects (=120) for term (Age | Year); the random-effects parameters are probably unidentifiable