lmer error: grouping factor must be < number of observations

Salmo salar

I am attempting to run a mixed effect model on some data but struggling with one of the fixed effects, I think primarily due to it a factor?!

Sample data:

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")

My model is as such:

model1<-lmer(speed ~ river + length +(1|meanflow)+(1|code), data4)

and when run returns error message:

Error in checkNlevels(reTrms$flist, n = n, control) : 
number of levels of each grouping factor must be < number of observations

Having trawled the internet I have found one response

but for the life of me do not understand the responses to the question!

Ben Bolker

You have two problems here:

  • It looks like you have one observation for every value of code. That means that you can't estimate both a residual variance (which is built in to lmer, and linear mixed models more generally) and an among-code variance -- both of these parameters will be trying to estimate the same variance component, and any combination of var(residual) and var(code) that adds up to the same value will represent an equally good fit to the data.

  • You also have one observation for every value of meanflow; this is because meanflow is a continuous variable, which is not usually something you want to use as a grouping variable in the model. I'm not sure what you're trying to capture with this term.

You can actually fit these models if you insist by using lmerControl to bypass the checks, but you won't necessarily get a sensible result!

model2 <- lmer(speed ~ river + length +(1|meanflow)+(1|code), data4,
    control=lmerControl(check.nobs.vs.nlev = "ignore",
     check.nobs.vs.rankZ = "ignore",
     check.nobs.vs.nRE="ignore"))

Here the variance has been divided approximately in equal thirds:

 VarCorr(model2)
 ##  Groups   Name        Std.Dev.
 ##  meanflow (Intercept) 0.035354
 ##  code     (Intercept) 0.032898
 ##  Residual             0.033590

If we use only one (still inappropriate) random effect,

model0 <- lmer(speed ~ river + length +(1|meanflow), data4,
    control=lmerControl(check.nobs.vs.nlev = "ignore",
     check.nobs.vs.rankZ = "ignore",
     check.nobs.vs.nRE="ignore"))

Now the variance is divided exactly in halves:

VarCorr(model0)
##  Groups   Name        Std.Dev.
##  meanflow (Intercept) 0.041596
##  Residual             0.041596

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Ember.js - Error - "Assertion failed: You must include an `id` in a hash passed to `push`"

来自分类Dev

Android : Error com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation

来自分类Dev

增加新版本的lmer的迭代次数?

来自分类Dev

transitionFromViewController:toViewController error: children view controllers must have a common parent view controller

来自分类Dev

Method to find a factor of a number

来自分类Dev

lmer模型的标准化系数

来自分类Dev

LMER的替代优化算法

来自分类Dev

Java error: Implicit super constructor is undefined. Must explicitly invoke another constructor

来自分类Dev

ActiveRecord::StatementInvalid: PG::Error: ERROR: must be owner of database

来自分类Dev

Index and length must refer to a location within the string error in substring

来自分类Dev

rspec stub giving wrong number of arguments error

来自分类Dev

C , Error: Expression must be a modifiable lvalue

来自分类Dev

Likert grouping error in R

来自分类Dev

error: expression must have integral or enum type

来自分类Dev

在多面ggplot中绘制lmer结果

来自分类Dev

如何动态构造lmer公式?

来自分类Dev

lmer的分组错误

来自分类Dev

Tensorflow error: Invalid argument: shape must be a vector

来自分类Dev

GLMER警告消息以使用LMER

来自分类Dev

如何绘制lmer模型的某些术语

来自分类Dev

嵌套随机效应的lmer模型的预测

来自分类Dev

LMER测试来自何处?

来自分类Dev

如何摆脱lmer警告信息?

来自分类Dev

Yii2 SluggableBehavior "attribute" or "value" property must be specified error

来自分类Dev

如何动态构造lmer公式?

来自分类Dev

Elixir /凤凰查询错误(grouping_error)

来自分类Dev

lmer 与 gls 中的缺失值

来自分类Dev

Mocha with Selenium The Error: TypeError: Wait condition must be a promise-like object, function, or a Condition object

来自分类Dev

Scipy interpolate 2d error m >= (kx+1)(ky+1) must hold

Related 相关文章

  1. 1

    Ember.js - Error - "Assertion failed: You must include an `id` in a hash passed to `push`"

  2. 2

    Android : Error com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation

  3. 3

    增加新版本的lmer的迭代次数?

  4. 4

    transitionFromViewController:toViewController error: children view controllers must have a common parent view controller

  5. 5

    Method to find a factor of a number

  6. 6

    lmer模型的标准化系数

  7. 7

    LMER的替代优化算法

  8. 8

    Java error: Implicit super constructor is undefined. Must explicitly invoke another constructor

  9. 9

    ActiveRecord::StatementInvalid: PG::Error: ERROR: must be owner of database

  10. 10

    Index and length must refer to a location within the string error in substring

  11. 11

    rspec stub giving wrong number of arguments error

  12. 12

    C , Error: Expression must be a modifiable lvalue

  13. 13

    Likert grouping error in R

  14. 14

    error: expression must have integral or enum type

  15. 15

    在多面ggplot中绘制lmer结果

  16. 16

    如何动态构造lmer公式?

  17. 17

    lmer的分组错误

  18. 18

    Tensorflow error: Invalid argument: shape must be a vector

  19. 19

    GLMER警告消息以使用LMER

  20. 20

    如何绘制lmer模型的某些术语

  21. 21

    嵌套随机效应的lmer模型的预测

  22. 22

    LMER测试来自何处?

  23. 23

    如何摆脱lmer警告信息?

  24. 24

    Yii2 SluggableBehavior "attribute" or "value" property must be specified error

  25. 25

    如何动态构造lmer公式?

  26. 26

    Elixir /凤凰查询错误(grouping_error)

  27. 27

    lmer 与 gls 中的缺失值

  28. 28

    Mocha with Selenium The Error: TypeError: Wait condition must be a promise-like object, function, or a Condition object

  29. 29

    Scipy interpolate 2d error m >= (kx+1)(ky+1) must hold

热门标签

归档