Example 4.1 from Generalized Linear Mixed Models: Modern Concepts, Methods and Applications by Walter W. Stroup(p-138)
Source:R/Exam4.1.R
Exam4.1.Rd
Exam4.1 REML vs ML criterion is used keeping block effects random
References
Stroup, W. W. (2012). Generalized Linear Mixed Models: Modern Concepts, Methods and Applications. CRC Press.
Author
Muhammad Yaseen (myaseen208@gmail.com)
Adeela Munawar (adeela.uaf@gmail.com)
Examples
DataSet4.1$trt <- factor(x = DataSet4.1$trt)
DataSet4.1$block <- factor(x = DataSet4.1$block)
#---REML estimates on page 138(article 4.4.3.3)
library(lmerTest)
#> Loading required package: lme4
#>
#> Attaching package: ‘lme4’
#> The following object is masked from ‘package:nlme’:
#>
#> lmList
#>
#> Attaching package: ‘lmerTest’
#> The following object is masked from ‘package:lme4’:
#>
#> lmer
#> The following object is masked from ‘package:stats’:
#>
#> step
Exam4.1REML <- lmer(formula = y~ trt +( 1|block ), data = DataSet4.1)
library(parameters)
model_parameters(Exam4.1REML)
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | t(43) | p
#> ------------------------------------------------------------------
#> (Intercept) | 28.18 | 1.66 | [24.82, 31.53] | 16.93 | < .001
#> trt [2] | -4.12 | 2.22 | [-8.60, 0.36] | -1.86 | 0.070
#> trt [3] | -3.63 | 2.22 | [-8.10, 0.85] | -1.63 | 0.110
#> trt [4] | -0.34 | 2.22 | [-4.82, 4.14] | -0.15 | 0.880
#> trt [5] | -0.13 | 2.22 | [-4.60, 4.35] | -0.06 | 0.955
#> trt [6] | 0.93 | 2.27 | [-3.65, 5.51] | 0.41 | 0.684
#> trt [7] | -0.29 | 2.22 | [-4.76, 4.19] | -0.13 | 0.898
#> trt [8] | -0.36 | 2.22 | [-4.84, 4.12] | -0.16 | 0.872
#> trt [9] | 0.74 | 2.22 | [-3.74, 5.22] | 0.33 | 0.741
#> trt [10] | -3.26 | 2.22 | [-7.74, 1.21] | -1.47 | 0.149
#> trt [11] | 0.81 | 2.27 | [-3.77, 5.39] | 0.36 | 0.723
#> trt [12] | 2.35 | 2.22 | [-2.13, 6.83] | 1.06 | 0.295
#> trt [13] | -2.00 | 2.22 | [-6.48, 2.48] | -0.90 | 0.373
#> trt [14] | -3.26 | 2.22 | [-7.74, 1.22] | -1.47 | 0.149
#> trt [15] | 0.42 | 2.22 | [-4.06, 4.90] | 0.19 | 0.852
#>
#> # Random Effects
#>
#> Parameter | Coefficient | SE | 95% CI
#> ---------------------------------------------------------
#> SD (Intercept: block) | 2.16 | 0.66 | [1.18, 3.93]
#> SD (Residual) | 2.93 | 0.37 | [2.28, 3.75]
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
print(VarCorr(x = Exam4.1REML), comp = c("Variance"))
#> Groups Name Variance
#> block (Intercept) 4.6522
#> Residual 8.5559
##---ML estimates on page 138(article 4.4.3.3)
Exam4.1ML <- lmer(formula = y ~ trt + (1|block), data = DataSet4.1, REML = FALSE)
model_parameters(Exam4.1ML)
#> # Fixed Effects
#>
#> Parameter | Coefficient | SE | 95% CI | t(43) | p
#> ------------------------------------------------------------------
#> (Intercept) | 28.23 | 1.44 | [25.33, 31.12] | 19.66 | < .001
#> trt [2] | -4.16 | 1.88 | [-7.95, -0.37] | -2.21 | 0.032
#> trt [3] | -3.68 | 1.88 | [-7.47, 0.11] | -1.96 | 0.057
#> trt [4] | -0.58 | 1.88 | [-4.37, 3.21] | -0.31 | 0.760
#> trt [5] | -0.17 | 1.88 | [-3.96, 3.62] | -0.09 | 0.927
#> trt [6] | 0.87 | 1.93 | [-3.02, 4.75] | 0.45 | 0.655
#> trt [7] | -0.37 | 1.88 | [-4.16, 3.42] | -0.20 | 0.844
#> trt [8] | -0.35 | 1.88 | [-4.14, 3.44] | -0.19 | 0.851
#> trt [9] | 0.76 | 1.88 | [-3.03, 4.55] | 0.41 | 0.686
#> trt [10] | -3.27 | 1.88 | [-7.06, 0.52] | -1.74 | 0.089
#> trt [11] | 0.68 | 1.93 | [-3.21, 4.56] | 0.35 | 0.728
#> trt [12] | 2.22 | 1.88 | [-1.57, 6.01] | 1.18 | 0.243
#> trt [13] | -1.95 | 1.88 | [-5.74, 1.84] | -1.04 | 0.305
#> trt [14] | -3.24 | 1.88 | [-7.03, 0.55] | -1.72 | 0.092
#> trt [15] | 0.35 | 1.88 | [-3.44, 4.14] | 0.18 | 0.855
#>
#> # Random Effects
#>
#> Parameter | Coefficient | SE | 95% CI
#> ---------------------------------------------------------
#> SD (Intercept: block) | 2.12 | 0.52 | [1.31, 3.44]
#> SD (Residual) | 2.46 | 0.26 | [2.00, 3.02]
#>
#> Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed
#> using a Wald t-distribution approximation.
print(VarCorr(x = Exam4.1ML), comp = c("Variance"))
#> Groups Name Variance
#> block (Intercept) 4.5030
#> Residual 6.0371
Exam4.1.lm <- lm(formula = y~ trt + block, data = DataSet4.1)
anova(object = Exam4.1.lm)
#> Analysis of Variance Table
#>
#> Response: y
#> Df Sum Sq Mean Sq F value Pr(>F)
#> trt 14 299.43 21.3881 2.4825 0.017187 *
#> block 14 333.42 23.8159 2.7643 0.009004 **
#> Residuals 31 267.08 8.6154
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1