我正在尝试对某些数据运行混合效应模型,但在其中一个固定效应中苦苦挣扎,我认为主要是因为它是一个因素?!
样本数据:
data4<-structure(list(code = structure(1:10, .Label = c("10888", "10889",
"10890", "10891", "10892", "10893", "10894", "10896", "10897",
"10898", "10899", "10900", "10901", "10902", "10903", "10904",
"10905", "10906", "10907", "10908", "10909", "10910", "10914",
"10916", "10917", "10919", "10920", "10922", "10923", "10924",
"10925", "10927"), class = "factor"), speed = c(0.0296315046039244,
0.0366986630049636, 0.0294297725505692, 0.048316183511095, 0.0294275666501456,
0.199924957584131, 0.0798850288176711, 0.0445886457047146, 0.0285993712316451,
0.0715158276875623), meanflow = c(0.657410742496051, 0.608271363339857,
0.663241108786611, 0.538259450171821, 0.666299529534762, 0.507156583629893,
0.762448863636364, 37.6559178370787, 50.8557196935557, 31.6601587837838
), length = c(136, 157, 132, 140, 135, 134, 144, 149, 139, 165
), river = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L
), .Label = c("c", "f"), class = "factor")), .Names = c("code",
"speed", "meanflow", "length", "river"), row.names = c(2L, 4L,
6L, 8L, 10L, 12L, 14L, 16L, 18L, 20L), class = "data.frame")
我的模型是这样的:
model1<-lmer(speed ~ river + length +(1|meanflow)+(1|code), data4)
当运行返回错误信息时:
Error in checkNlevels(reTrms$flist, n = n, control) :
number of levels of each grouping factor must be < number of observations
在互联网上搜索后,我发现了一个回复
但是对于我的生活,我不明白这个问题的答案!