Generalized Linear Mixed Effect Model

Summary

グループ構造のあるデータに対して適用される統計モデリングの枠組み。正規分布に従うグループレベルの誤差を加えることで、グループ間の違いを考慮しながら説明変数の効果(偏回帰係数)を推定する。

Sponsored link

function “lmer”

確率分布:正規分布
パッケージ:lme4
その他:なし

# sample data plot: points are colored by group
Col <- rainbow(10)
plot(Y ~ X, data = dat1, pch = 21, bg = Col[dat1$groupID], col = NA)

plot of chunk lmer

# run lmer
fit <- lmer(Y ~ X + (1|factor(dat1$groupID)), data = dat1)
summary(fit)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Y ~ X + (1 | factor(dat1$groupID))
##    Data: dat1
## 
## REML criterion at convergence: -92.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.18657 -0.65569 -0.01559  0.47664  2.59009 
## 
## Random effects:
##  Groups               Name        Variance Std.Dev.
##  factor(dat1$groupID) (Intercept) 0.52432  0.7241  
##  Residual                         0.01156  0.1075  
## Number of obs: 100, groups:  factor(dat1$groupID), 10
## 
## Fixed effects:
##             Estimate Std. Error t value
## (Intercept) 0.900439   0.230086   3.913
## X           0.102362   0.003581  28.584
## 
## Correlation of Fixed Effects:
##   (Intr)
## X -0.086

function “glmer”

確率分布:ポアソン分布、二項分布、ガンマ分布など
パッケージ:lme4
その他:なし

Poisson

# sample data plot: points are colored by group
Col <- rainbow(10)
plot(Y ~ X, data = dat2, pch = 21, bg = Col[dat2$groupID], col = NA)

plot of chunk glmer_poisson

# run glmer
fit <- glmer(Y ~ X + (1|factor(dat2$groupID)), data = dat2, family = poisson)
summary(fit)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: poisson  ( log )
## Formula: Y ~ X + (1 | factor(dat2$groupID))
##    Data: dat2
## 
##      AIC      BIC   logLik deviance df.resid 
##    481.7    489.5   -237.8    475.7       97 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.72217 -0.65979 -0.05568  0.56604  2.67057 
## 
## Random effects:
##  Groups               Name        Variance Std.Dev.
##  factor(dat2$groupID) (Intercept) 1.187    1.09    
## Number of obs: 100, groups:  factor(dat2$groupID), 10
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  0.61515    0.35750   1.721   0.0853 .  
## X            0.20356    0.01223  16.638   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##   (Intr)
## X -0.218

Binomial

# sample data plot: points are colored by group
Col <- rainbow(10)
plot(Y ~ X, data = dat3, pch = 21, bg = Col[dat3$groupID], col = NA)

plot of chunk glmer_binomial

# run glmer
fit <- glmer(Y ~ X + (1|factor(dat3$groupID)), data = dat3, family = poisson)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl =
## control$checkConv, : Model failed to converge with max|grad| = 0.00493791
## (tol = 0.001, component 1)
summary(fit)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: poisson  ( log )
## Formula: Y ~ X + (1 | factor(dat3$groupID))
##    Data: dat3
## 
##      AIC      BIC   logLik deviance df.resid 
##    359.2    367.0   -176.6    353.2       97 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.4552 -0.7819 -0.2008  0.4063  2.2327 
## 
## Random effects:
##  Groups               Name        Variance Std.Dev.
##  factor(dat3$groupID) (Intercept) 0.08707  0.2951  
## Number of obs: 100, groups:  factor(dat3$groupID), 10
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -0.86604    0.21124   -4.10 4.14e-05 ***
## X            0.33065    0.02421   13.66  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##   (Intr)
## X -0.858
## convergence code: 0
## Model failed to converge with max|grad| = 0.00493791 (tol = 0.001, component 1)

function “glmer.nb”

確率分布:負の二項分布
パッケージ:lme4
その他:なし

# sample data plot: points are colored by group
Col <- rainbow(10)
plot(Y ~ X, data = dat4, pch = 21, bg = Col[dat4$groupID], col = NA)

plot of chunk glmer_negbin

# run glmer.nb
fit <- glmer.nb(Y ~ X + (1|factor(dat4$groupID)), data = dat4, family = poisson)
summary(fit)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: Negative Binomial(1.4135)  ( log )
## Formula: Y ~ X + (1 | factor(dat4$groupID))
##    Data: dat4
## 
##      AIC      BIC   logLik deviance df.resid 
##    910.1    920.5   -451.0    902.1       96 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.1658 -0.7114 -0.2650  0.4356  2.8117 
## 
## Random effects:
##  Groups               Name        Variance Std.Dev.
##  factor(dat4$groupID) (Intercept) 1.166    1.08    
## Number of obs: 100, groups:  factor(dat4$groupID), 10
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  0.69477    0.41093   1.691   0.0909 .  
## X            0.47894    0.03663  13.075   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##   (Intr)
## X -0.510
Posted in: R

Leave a Reply

Your email address will not be published. Required fields are marked *