简体   繁体   English

将 lmer() 函数用于线性混合效应模型的重复性错误

[英]Recurring error using lmer() function for a linear mixed-effects model

I attempted to construct a linear mixed effects model using lmer function from lme4 package and I ran into a recurring error.我尝试使用lme4包中的lmer函数构建线性混合效应模型,但我遇到了反复出现的错误。 The model uses two fixed effects:该模型使用两个固定效应:

  • DBS_Electrode (factor w/3 levels) and DBS_Electrode (因子 w/3 水平)和
  • PostOp_ICA (continuous variable). PostOp_ICA (连续变量)。

I use (1 | Subject) as a random effect term in which Subject is a factor of 38 levels (38 total subjects).我使用(1 | Subject)作为随机效应项,其中Subject是 38 个级别(总共 38 个主题)的因子。 Below is the line of code I attempted to run:下面是我试图运行的代码行:

LMM.DBS <- lmer(Distal_Lead_Migration ~ DBS_Electrode + PostOp_ICA + (1 | Subject), data = DBS)

I recieved the following error:我收到以下错误:

Number of levels of each grouping factor must be < number of observations.每个分组因子的水平数必须 < 观察数。

I would appreciate any help, I have tried to navigate this issue myself and have been unsuccessful.我将不胜感激,我曾试图自己解决这个问题,但没有成功。

Linear mixed effect model supposes that there is less subjects than observations so it throws an if it is not the case.线性混合效应模型假设主题少于观察值,因此如果不是这种情况,它会抛出一个。

You can think of this formula as telling your model that it should expect that there's going to be multiple responses per subject, and these responses will depend on each subject's baseline level.您可以将此公式视为告诉您的模型,它应该预期每个主题会有多个响应,而这些响应将取决于每个主题的基线水平。

Please consult A very basic tutorial for performing linear mixed effects analyses by B. Winter, p.请参阅B. Winter 执行线性混合效应分析的非常基本的教程,第 12 页。 4 . 4 .

In your case you should increase amount of observations per subject (> 1).在您的情况下,您应该增加每个主题的观察量(> 1)。 Please see the simulation below:请看下面的模拟:

library(lme4)
set.seed(123)
n <- 38
DBS_Electrode <- factor(sample(LETTERS[1:3], n, replace = TRUE))

Distal_Lead_Migration <- 10 * abs(rnorm(n))    # Distal_Lead_Migration in cm
PostOp_ICA <- 5 * abs(rnorm(n))

# amount of observations equals to amout of subjects
Subject <- paste0("X", 1:n)
DBS <- data.frame(DBS_Electrode, PostOp_ICA, Subject, Distal_Lead_Migration)
model <- lmer(Distal_Lead_Migration ~ DBS_Electrode + PostOp_ICA + (1|Subject), data = DBS)
# Error: number of levels of each grouping factor must be < number of observations


# amount of observations more than amout of subjects
Subject <- c(paste0("X", 1:36), "X1", "X37")
DBS <- data.frame(DBS_Electrode, PostOp_ICA, Subject, Distal_Lead_Migration)
model <- lmer(Distal_Lead_Migration ~ DBS_Electrode + PostOp_ICA + (1|Subject), data = DBS)
summary(model)

Output:输出:

Linear mixed model fit by REML ['lmerMod']
Formula: Distal_Lead_Migration ~ DBS_Electrode + PostOp_ICA + (1 | Subject)
   Data: DBS

REML criterion at convergence: 224.5

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-1.24605 -0.73780 -0.07638  0.64381  2.53914 

Random effects:
 Groups   Name        Variance  Std.Dev. 
 Subject  (Intercept) 2.484e-14 1.576e-07
 Residual             2.953e+01 5.434e+00
Number of obs: 38, groups:  Subject, 37

Fixed effects:
               Estimate Std. Error t value
(Intercept)     7.82514    2.38387   3.283
DBS_ElectrodeB  0.22884    2.50947   0.091
DBS_ElectrodeC -0.60940    2.21970  -0.275
PostOp_ICA     -0.08473    0.36765  -0.230

Correlation of Fixed Effects:
            (Intr) DBS_EB DBS_EC
DBS_ElctrdB -0.718              
DBS_ElctrdC -0.710  0.601       
PostOp_ICA  -0.693  0.324  0.219

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM