从GLMM中提取方差分量

时间:2019-08-18 10:38:13

标签: r glm mixed-models variance

有很多方法可以从线性混合效应模型(LME)中提取方差分量,但是我无法确定哪种代码适合从广义线性混合效应模型(GLMM)中提取方差分量。

我具有以下格式的数据,并且我试图了解哪个因素比其他因素更能解释数据的差异,具体来说,我需要进行差异成分分析。

data <- rbind(data.frame(data = "1", factor1 = "no", factor2 = "w"),      
     data.frame(data = "1", factor1 = "no", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "h"),
     data.frame(data = "0", factor1 = "yes", factor2 = "w"),
     data.frame(data = "0", factor1 = "yes", factor2 = "h"),
     data.frame(data = "1", factor1 = "yes", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "w"),
     data.frame(data = "0", factor1 = "yes", factor2 = "w"),
     data.frame(data = "0", factor1 = "yes", factor2 = "h"),
     data.frame(data = "1", factor1 = "no", factor2 = "h"),
     data.frame(data = "0", factor1 = "yes", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "w"),
     data.frame(data = "1", factor1 = "yes", factor2 = "h"),
     data.frame(data = "0", factor1 = "yes", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "h"),
     data.frame(data = "0", factor1 = "yes", factor2 = "h"),
     data.frame(data = "1", factor1 = "no", factor2 = "w"),
     data.frame(data = "0", factor1 = "yes", factor2 = "w"),
     data.frame(data = "1", factor1 = "no", factor2 = "h"),
     data.frame(data = "1", factor1 = "yes", factor2 = "w"),
     data.frame(data = "0", factor1 = "yes", factor2 = "h"))


glmer

通过在lme4(https://cran.r-project.org/web/packages/lme4/index.html)中使用建议的方法;

library(lme4)
mod1 <- glmer(data~(1|factor1) +(1|factor2), family = binomial, data = data)
summary(mod1)

我获得了有关数据集差异的结果(我们叫 dataset1 );

Random effects:
 Groups   Name       Variance Std.Dev.
 factor1 (Intercept) 0.001584 0.0398  
 factor2 (Intercept) 0.354064 0.5950 

并获得另一个数据集(即 dataset2 );

Random effects:
 Groups  Name        Variance Std.Dev.
 factor1 (Intercept) 0.7770   0.8815  
 factor2 (Intercept) 0.2811   0.5302  

我期望方差值factor1 + factor2 + residual = 1.0,但在第二种情况下,它已经超过1.0,有两个因素。因此,我想在GLMM中,我们不能像在LME中那样将这些方差值解释为精确的“方差分量”。


具有getME功能

通过在lme4中对{i> dataset1 ,

使用getME函数
library(lme4)
mod1 <- glmer(data~(1|factor1) +(1|factor2), family = binomial, data = data)
getME(mod1, "theta")^2

我在上面获得了完全相同的结果。


glmm

运行时,通过在glmm软件包(https://cran.r-project.org/web/packages/glmm/index.html)中使用glmm功能

library(glmm)
m <- 1000
data$data <- ifelse(data$data=="1", 1, 0)
mod1 <- glmm(data~1, random=list(~1+factor1, ~1+factor2), varcomps.names=c("factor1", "factor2"), data=data, family.glmm=binomial.glmm, m=m, debug=TRUE)
varcomps(mod1)

然后,我得到了(用于 dataset1

     factor1      factor2
8.581048e-06 3.634846e-01 

是不同的值,但是用lme4中的代码说相同的话(我的意思是factor2> factor1)。

以及 dataset2

  factor1   factor2
0.7427292 0.5572225 

此结果与使用带有 dataset2 的lme4中的代码进行的分析稍有不同(我的意思是,factor1似乎可以解释更多,但仍然是factor1> factor2)。


我的第一个问题是,即使我获得的方差值也不是精确的“方差分量”,我们可以将这些值用于factor1和factor2之间的比较吗?

我的第二个问题是,下面的哪些代码适合进行此类分析,还有其他方法可以做到吗?

0 个答案:

没有答案