24.5 细菌数据集

流感嗜血杆菌的细菌与中耳炎患儿

data(bacteria, package = "MASS")
# 惩罚拟似然
fit_glmmpql <- MASS::glmmPQL(y ~ trt + I(week > 2),
  random = ~ 1 | ID, verbose = FALSE,
  family = binomial, data = bacteria
)
summary(fit_glmmpql)
## Linear mixed-effects model fit by maximum likelihood
##   Data: bacteria 
##   AIC BIC logLik
##    NA  NA     NA
## 
## Random effects:
##  Formula: ~1 | ID
##         (Intercept)  Residual
## StdDev:    1.410637 0.7800511
## 
## Variance function:
##  Structure: fixed weights
##  Formula: ~invwt 
## Fixed effects:  y ~ trt + I(week > 2) 
##                     Value Std.Error  DF   t-value p-value
## (Intercept)      3.412014 0.5185033 169  6.580506  0.0000
## trtdrug         -1.247355 0.6440635  47 -1.936696  0.0588
## trtdrug+        -0.754327 0.6453978  47 -1.168779  0.2484
## I(week > 2)TRUE -1.607257 0.3583379 169 -4.485311  0.0000
##  Correlation: 
##                 (Intr) trtdrg trtdr+
## trtdrug         -0.598              
## trtdrug+        -0.571  0.460       
## I(week > 2)TRUE -0.537  0.047 -0.001
## 
## Standardized Within-Group Residuals:
##        Min         Q1        Med         Q3        Max 
## -5.1985361  0.1572336  0.3513075  0.4949482  1.7448845 
## 
## Number of Observations: 220
## Number of Groups: 50
# 拉普拉斯近似
fit_glmer <- lme4::glmer(y ~ trt + I(week > 2) + (1 | ID),
  family = binomial, data = bacteria
)
summary(fit_glmer)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: y ~ trt + I(week > 2) + (1 | ID)
##    Data: bacteria
## 
##      AIC      BIC   logLik deviance df.resid 
##    202.3    219.2    -96.1    192.3      215 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.5615  0.1359  0.3022  0.4217  1.1276 
## 
## Random effects:
##  Groups Name        Variance Std.Dev.
##  ID     (Intercept) 1.543    1.242   
## Number of obs: 220, groups:  ID, 50
## 
## Fixed effects:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)       3.5479     0.6958   5.099 3.41e-07 ***
## trtdrug          -1.3667     0.6770  -2.019 0.043516 *  
## trtdrug+         -0.7826     0.6831  -1.146 0.251926    
## I(week > 2)TRUE  -1.5985     0.4759  -3.359 0.000783 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) trtdrg trtdr+
## trtdrug     -0.593              
## trtdrug+    -0.537  0.487       
## I(wk>2)TRUE -0.656  0.126  0.064