-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
08-linear-mixed-models.Rmd
1787 lines (1348 loc) · 45 KB
/
08-linear-mixed-models.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Linear Mixed Models
## Dependent Data
Forms of dependent data:
- Multivariate measurements on different individuals: (e.g., a person's blood pressure, fat, etc are correlated)
- Clustered measurements: (e.g., blood pressure measurements of people in the same family can be correlated).
- Repeated measurements: (e.g., measurement of cholesterol over time can be correlated) "If data are collected repeatedly on experimental material to which treatments were applied initially, the data is a repeated measure." [@Schabenberger_2001]
- Longitudinal data: (e.g., individual's cholesterol tracked over time are correlated): "data collected repeatedly over time in an observational study are termed longitudinal." [@Schabenberger_2001]
- Spatial data: (e.g., measurement of individuals living in the same neighborhood are correlated)
Hence, we like to account for these correlations.
**Linear Mixed Model** (LMM), also known as **Mixed Linear Model** has 2 components:
- **Fixed effect** (e.g, gender, age, diet, time)
- **Random effects** representing individual variation or auto correlation/spatial effects that imply **dependent (correlated) errors**
Review [Two-Way Mixed Effects ANOVA]
We choose to model the random subject-specific effect instead of including dummy subject covariates in our model because:
- reduction in the number of parameters to estimate
- when you do inference, it would make more sense that you can infer from a population (i.e., random effect).
**LLM Motivation**
In a repeated measurements analysis where $Y_{ij}$ is the response for the $i$-th individual measured at the $j$-th time,
$i =1,…,N$ ; $j = 1,…,n_i$
$$
\mathbf{Y}_i =
\left(
\begin{array}
{c}
Y_{i1} \\
. \\
.\\
.\\
Y_{in_i}
\end{array}
\right)
$$
is all measurements for subject $i$.
[*Stage 1: (Regression Model)*]{.underline} how the response changes over time for the $i$-th subject
$$
\mathbf{Y_i = Z_i \beta_i + \epsilon_i}
$$
where
- $Z_i$ is an $n_i \times q$ matrix of known covariates
- $\beta_i$ is an unknown $q \times 1$ vector of subjective -specific coefficients (regression coefficients different for each subject)
- $\epsilon_i$ are the random errors (typically $\sim N(0, \sigma^2 I)$)
We notice that there are two many $\beta$ to estimate here. Hence, this is the motivation for the second stage
[*Stage 2: (Parameter Model)*]{.underline}
$$
\mathbf{\beta_i = K_i \beta + b_i}
$$
where
- $K_i$ is a $q \times p$ matrix of known covariates
- $\beta$ is a $p \times 1$ vector of unknown parameter
- $\mathbf{b}_i$ are independent $N(0,D)$ random variables
This model explain the observed variability between subjects with respect to the subject-specific regression coefficients, $\beta_i$. We model our different coefficient ($\beta_i$) with respect to $\beta$.
Example:
Stage 1:
$$
Y_{ij} = \beta_{1i} + \beta_{2i}t_{ij} + \epsilon_{ij}
$$
where
- $j = 1,..,n_i$
In the matrix notation,
$$
\mathbf{Y_i} =
\left(
\begin{array}
{c}
Y_{i1} \\
.\\
Y_{in_i}
\end{array}
\right); \mathbf{Z}_i =
\left(
\begin{array}
{cc}
1 & t_{i1} \\
. & . \\
1 & t_{in_i}
\end{array}
\right)
$$
$$
\beta_i =
\left(
\begin{array}
{c}
\beta_{1i} \\
\beta_{2i}
\end{array}
\right); \epsilon_i =
\left(
\begin{array}
{c}
\epsilon_{i1} \\
. \\
\epsilon_{in_i}
\end{array}
\right)
$$
Thus,
$$
\mathbf{Y_i = Z_i \beta_i + \epsilon_i}
$$
Stage 2:
$$
\begin{aligned}
\beta_{1i} &= \beta_0 + b_{1i} \\
\beta_{2i} &= \beta_1 L_i + \beta_2 H_i + \beta_3 C_i + b_{2i}
\end{aligned}
$$
where $L_i, H_i, C_i$ are indicator variables defined to 1 as the subject falls into different categories.
Subject specific intercepts do not depend upon treatment, with $\beta_0$ (the average response at the start of treatment), and $\beta_1 , \beta_2, \beta_3$ (the average time effects for each of three treatment groups).
$$
\begin{aligned}
\mathbf{K}_i &= \left(
\begin{array}
{cccc}
1 & 0 & 0 & 0 \\
0 & L_i & H_i & C_i
\end{array}
\right) \\
\beta &= (\beta_0 , \beta_1, \beta_2, \beta_3)' \\
\mathbf{b}_i &=
\left(
\begin{array}
{c}
b_{1i} \\
b_{2i} \\
\end{array}
\right) \\
\beta_i &= \mathbf{K_i \beta + b_i}
\end{aligned}
$$
To get $\hat{\beta}$, we can fit the model sequentially:
1. Estimate $\hat{\beta_i}$ in the first stage
2. Estimate $\hat{\beta}$ in the second stage by replacing $\beta_i$ with $\hat{\beta}_i$
However, problems arise from this method:
- information is lost by summarizing the vector $\mathbf{Y}_i$ solely by $\hat{\beta}_i$
- we need to account for variability when replacing $\beta_i$ with its estimate
- different subjects might have different number of observations.
To address these problems, we can use **Linear Mixed Model** [@laird1982random]
Substituting stage 2 into stage 1:
$$
\mathbf{Y}_i = \mathbf{Z}_i \mathbf{K}_i \beta + \mathbf{Z}_i \mathbf{b}_i + \mathbf{\epsilon}_i
$$
Let $\mathbf{X}_i = \mathbf{Z}_i \mathbf{K}_i$ be an $n_i \times p$ matrix . Then, the LMM is
$$
\mathbf{Y}_i = \mathbf{X}_i \beta + \mathbf{Z}_i \mathbf{b}_i + \mathbf{\epsilon}_i
$$
where
- $i = 1,..,N$
- $\beta$ are the fixed effects, which are common to all subjects
- $\mathbf{b}_i$ are the subject specific random effects. $\mathbf{b}_i \sim N_q (\mathbf{0,D})$
- $\mathbf{\epsilon}_i \sim N_{n_i}(\mathbf{0,\Sigma_i})$
- $\mathbf{b}_i$ and $\epsilon_i$ are independent
- $\mathbf{Z}_{i(n_i \times q})$ and $\mathbf{X}_{i(n_i \times p})$ are matrices of known covariates.
Equivalently, in the hierarchical form, we call **conditional** or **hierarchical** formulation of the linear mixed model
$$
\begin{aligned}
\mathbf{Y}_i | \mathbf{b}_i &\sim N(\mathbf{X}_i \beta+ \mathbf{Z}_i \mathbf{b}_i, \mathbf{\Sigma}_i) \\
\mathbf{b}_i &\sim N(\mathbf{0,D})
\end{aligned}
$$
for $i = 1,..,N$. denote the respective functions by $f(\mathbf{Y}_i |\mathbf{b}_i)$ and $f(\mathbf{b}_i)$
In general,
$$
\begin{aligned}
f(A,B) &= f(A|B)f(B) \\
f(A) &= \int f(A,B)dB = \int f(A|B) f(B) dB
\end{aligned}
$$
In the LMM, the marginal density of $\mathbf{Y}_i$ is
$$
f(\mathbf{Y}_i) = \int f(\mathbf{Y}_i | \mathbf{b}_i) f(\mathbf{b}_i) d\mathbf{b}_i
$$
which can be shown
$$
\mathbf{Y}_i \sim N(\mathbf{X_i \beta, Z_i DZ'_i + \Sigma_i})
$$
This is the **marginal** formulation of the linear mixed model
Notes:
We no longer have $Z_i b_i$ in the mean, but add error in the variance (marginal dependence in Y). kinda of averaging out the common effect. Technically, we shouldn't call it averaging the error b (adding it to the variance covariance matrix), it should be called adding random effect
Continue with our example
$$
Y_{ij} = (\beta_0 + b_{1i}) + (\beta_1L_i + \beta_2 H_i + \beta_3 C_i + b_{2i})t_{ij} + \epsilon_{ij}
$$
for each treatment group
$$
Y_{ik}=
\begin{cases}
\beta_0 + b_{1i} + (\beta_1 + \ b_{2i})t_{ij} + \epsilon_{ij} & L \\
\beta_0 + b_{1i} + (\beta_2 + \ b_{2i})t_{ij} + \epsilon_{ij} & H\\
\beta_0 + b_{1i} + (\beta_3 + \ b_{2i})t_{ij} + \epsilon_{ij} & C
\end{cases}
$$
- Intercepts and slopes are all subject specific
- Different treatment groups have different slops, but the same intercept.
**In the hierarchical model form**
$$
\begin{aligned}
\mathbf{Y}_i | \mathbf{b}_i &\sim N(\mathbf{X}_i \beta + \mathbf{Z}_i \mathbf{b}_i, \mathbf{\Sigma}_i)\\
\mathbf{b}_i &\sim N(\mathbf{0,D})
\end{aligned}
$$
X will be in the form of
$$
\beta = (\beta_0, \beta_1, \beta_2, \beta_3)'
$$
$$
\begin{aligned}
\mathbf{X}_i &= \mathbf{Z}_i \mathbf{K}_i \\
&=
\left[
\begin{array}
{cc}
1 & t_{i1} \\
1 & t_{i2} \\
. & . \\
1 & t_{in_i}
\end{array}
\right]
\times
\left[
\begin{array}
{cccc}
1 & 0 & 0 & 0 \\
0 & L_i & H_i & C_i \\
\end{array}
\right] \\
&=
\left[
\begin{array}
{cccc}
1 & t_{i1}L_i & t_{i1}H_i & T_{i1}C_i \\
1 & t_{i2}L_i & t_{i2}H_i & T_{i2}C_i \\
. &. &. &. \\
1 & t_{in_i}L_i & t_{in_i}H_i & T_{in_i}C_i \\
\end{array}
\right]\end{aligned}
$$
$$
\mathbf{b}_i =
\left(
\begin{array}
{c}
b_{1i} \\
b_{2i}
\end{array}
\right)
$$
$$
D =
\left(
\begin{array}
{cc}
d_{11} & d_{12}\\
d_{12} & d_{22}
\end{array}
\right)
$$
Assuming $\mathbf{\Sigma}_i = \sigma^2 \mathbf{I}_{n_i}$, which is called **conditional independence**, meaning the response on subject i are independent conditional on $\mathbf{b}_i$ and $\beta$
**In the marginal model form**
$$
Y_{ij} = \beta_0 + \beta_1 L_i t_{ij} + \beta_2 H_i t_{ij} + \beta_3 C_i t_{ij} + \eta_{ij}
$$
where $\eta_i \sim N(\mathbf{0},\mathbf{Z}_i\mathbf{DZ}_i'+ \mathbf{\Sigma}_i)$
Equivalently,
$$
\mathbf{Y_i \sim N(X_i \beta, Z_i DZ_i' + \Sigma_i})
$$
In this case that $n_i = 2$
$$
\begin{aligned}
\mathbf{Z_iDZ_i'} &=
\left(
\begin{array}
{cc}
1 & t_{i1} \\
1 & t_{i2}
\end{array}
\right)
\left(
\begin{array}
{cc}
d_{11} & d_{12} \\
d_{12} & d_{22}
\end{array}
\right)
\left(
\begin{array}
{cc}
1 & 1 \\
t_{i1} & t_{i2}
\end{array}
\right) \\
&=
\left(
\begin{array}
{cc}
d_{11} + 2d_{12}t_{i1} + d_{22}t_{i1}^2 & d_{11} + d_{12}(t_{i1} + t_{i2}) + d_{22}t_{i1}t_{i2} \\
d_{11} + d_{12}(t_{i1} + t_{i2}) + d_{22} t_{i1} t_{i2} & d_{11} + 2d_{12}t_{i2} + d_{22}t_{i2}^2
\end{array}
\right)
\end{aligned}
$$
$$
var(Y_{i1}) = d_{11} + 2d_{12}t_{i1} + d_{22} t_{i1}^2 + \sigma^2
$$
On top of correlation in the errors, the marginal implies that the variance function of the response is quadratic over time, with positive curvature $d_{22}$
### Random-Intercepts Model
If we remove the random slopes,
- the assumption is that all variability in subject-specific slopes can be attributed to treatment differences
- the model is random-intercepts model. This has subject specific intercepts, but the same slopes within each treatment group.
$$
\begin{aligned}
\mathbf{Y}_i | b_i &\sim N(\mathbf{X}_i \beta + 1 b_i , \Sigma_i) \\
b_i &\sim N(0,d_{11})
\end{aligned}
$$
The marginal model is then ($\mathbf{\Sigma}_i = \sigma^2 \mathbf{I}$)
$$
\mathbf{Y}_i \sim N(\mathbf{X}_i \beta, 11'd_{11} + \sigma^2 \mathbf{I})
$$
The marginal covariance matrix is
$$
\begin{aligned}
cov(\mathbf{Y}_i) &= 11'd_{11} + \sigma^2I \\
&=
\left(
\begin{array}
{cccc}
d_{11}+ \sigma^2 & d_{11} & ... & d_{11} \\
d_{11} & d_{11} + \sigma^2 & d_{11} & ... \\
. & . & . & . \\
d_{11} & ... & ... & d_{11} + \sigma^2
\end{array}
\right)
\end{aligned}
$$
the associated correlation matrix is
$$
corr(\mathbf{Y}_i) =
\left(
\begin{array}
{cccc}
1 & \rho & ... & \rho \\
\rho & 1 & \rho & ... \\
. & . & . & . \\
\rho & ... & ... & 1 \\
\end{array}
\right)
$$
where $\rho \equiv \frac{d_{11}}{d_{11} + \sigma^2}$
Thu, we have
- constant variance over time
- equal, positive correlation between any two measurements from the same subject
- a covariance structure that is called **compound symmetry**, and $\rho$ is called the **intra-class correlation**
- that when $\rho$ is large, the **inter-subject variability** ($d_{11}$) is large relative to the intra-subject variability ($\sigma^2$)
### Covariance Models
If the conditional independence assumption, ($\mathbf{\Sigma_i= \sigma^2 I_{n_i}}$). Consider, $\epsilon_i = \epsilon_{(1)i} + \epsilon_{(2)i}$, where
- $\epsilon_{(1)i}$ is a "serial correlation" component. That is, part of the individual's profile is a response to time-varying stochastic processes.
- $\epsilon_{(2)i}$ is the measurement error component, and is independent of $\epsilon_{(1)i}$
Then
$$
\mathbf{Y_i = X_i \beta + Z_i b_i + \epsilon_{(1)i} + \epsilon_{(2)i}}
$$
where
- $\mathbf{b_i} \sim N(\mathbf{0,D})$
- $\epsilon_{(2)i} \sim N(\mathbf{0,\sigma^2 I_{n_i}})$
- $\epsilon_{(1)i} \sim N(\mathbf{0,\tau^2H_i})$
- $\mathbf{b}_i$ and $\epsilon_i$ are mutually independent
To model the structure of the $n_i \times n_i$ correlation (or covariance ) matrix $\mathbf{H}_i$. Let the (j,k)th element of $\mathbf{H}_i$ be $h_{ijk}= g(t_{ij}t_{ik})$. that is a function of the times $t_{ij}$ and $t_{ik}$ , which is assumed to be some function of the "distance' between the times.
$$
h_{ijk} = g(|t_{ij}-t_{ik}|)
$$
for some decreasing function $g(.)$ with $g(0)=1$ (for correlation matrices).
Examples of this type of function:
- Exponential function: $g(|t_{ij}-t_{ik}|) = \exp(-\phi|t_{ij} - t_{ik}|)$
- Gaussian function: $g(|t_{ij} - t_{ik}|) = \exp(-\phi(t_{ij} - t_{ik})^2)$
Similar structures could also be used for $\mathbf{D}$ matrix (of $\mathbf{b}$)
Example: Autoregressive Covariance Structure
A first order Autoregressive Model (AR(1)) has the form
$$
\alpha_t = \phi \alpha_{t-1} + \eta_t
$$
where $\eta_t \sim iid N (0,\sigma^2_\eta)$
Then, the covariance between two observations is
$$
cov(\alpha_t, \alpha_{t+h}) = \frac{\sigma^2_\eta \phi^{|h|}}{1- \phi^2}
$$
for $h = 0, \pm 1, \pm 2, ...; |\phi|<1$
Hence,
$$
corr(\alpha_t, \alpha_{t+h}) = \phi^{|h|}
$$
If we let $\alpha_T = (\alpha_1,...\alpha_T)'$, then
$$
corr(\alpha_T) =
\left[
\begin{array}
{ccccc}
1 & \phi^1 & \phi^2 & ... & \phi^2 \\
\phi^1 & 1 & \phi^1 & ... & \phi^{T-1} \\
\phi^2 & \phi^1 & 1 & ... & \phi^{T-2} \\
. & . & . & . &. \\
\phi^T & \phi^{T-1} & \phi^{T-2} & ... & 1
\end{array}
\right]
$$
Notes:
- The correlation decreases as time lag increases
- This matrix structure is known as a **Toeplitz** structure
- More complicated covariance structures are possible, which is critical component of spatial random effects models and time series models.
- Often, we don't need both random effects $\mathbf{b}$ and $\epsilon_{(1)i}$
More in the [Time Series] section
## Estimation
$$
\mathbf{Y}_i = \mathbf{X}_i \beta + \mathbf{Z}_i \mathbf{b}_i + \epsilon_i
$$
where $\beta, \mathbf{b}_i, \mathbf{D}, \mathbf{\Sigma}_i$ we must obtain estimation from the data
- $\mathbf{\beta}, \mathbf{D}, \mathbf{\Sigma}_i$ are unknown, but fixed, parameters, and must be estimated from the data
- $\mathbf{b}_i$ is a random variable. Thus, we can't estimate these values, but we can predict them. (i.e., you can't estimate a random thing).
If we have
- $\hat{\beta}$ as an estimator of $\beta$
- $\hat{\mathbf{b}}_i$ as a predictor of $\mathbf{b}_i$
Then,
- The population average estimate of $\mathbf{Y}_i$ is $\hat{\mathbf{Y}_i} = \mathbf{X}_i \hat{\beta}$
- The subject-specific prediction is $\hat{\mathbf{Y}_i} = \mathbf{X}_i \hat{\beta} + \mathbf{Z}_i \hat{b}_i$
According to [@henderson1975best], estimating equations known as the mixed model equations:
$$
\left[
\begin{array}
{c}
\hat{\beta} \\
\hat{\mathbf{b}}
\end{array}
\right]
=
\left[
\begin{array}
{cc}
\mathbf{X'\Sigma^{-1}X} & \mathbf{X'\Sigma^{-1}Z} \\
\mathbf{Z'\Sigma^{-1}X} & \mathbf{Z'\Sigma^{-1}Z +B^{-1}}
\end{array}
\right]
\left[
\begin{array}
{cc}
\mathbf{X'\Sigma^{-1}Y} \\
\mathbf{Z'\Sigma^{-1}Y}
\end{array}
\right]
$$
where
$$
\begin{aligned}
\mathbf{Y}
&=
\left[
\begin{array}
{c}
\mathbf{y}_1 \\
. \\
\mathbf{y}_N
\end{array}
\right] ;
\mathbf{X}
=
\left[
\begin{array}
{c}
\mathbf{X}_1 \\
. \\
\mathbf{X}_N
\end{array}
\right];
\mathbf{b} =
\left[
\begin{array}
{c}
\mathbf{b}_1 \\
. \\
\mathbf{b}_N
\end{array}
\right] ;
\epsilon =
\left[
\begin{array}
{c}
\epsilon_1 \\
. \\
\epsilon_N
\end{array}
\right]
\\
cov(\epsilon) &= \mathbf{\Sigma},
\mathbf{Z} =
\left[
\begin{array}
{cccc}
\mathbf{Z}_1 & 0 & ... & 0 \\
0 & \mathbf{Z}_2 & ... & 0 \\
. & . & . & . \\
0 & 0 & ... & \mathbf{Z}_n
\end{array}
\right],
\mathbf{B} =
\left[
\begin{array}
{cccc}
\mathbf{D} & 0 & ... & 0 \\
0 & \mathbf{D} & ... & 0 \\
. & . & . & . \\
0 & 0 & ... & \mathbf{D}
\end{array}
\right]
\end{aligned}
$$
The model has the form
$$
\begin{aligned}
\mathbf{Y} &= \mathbf{X \beta + Z b + \epsilon} \\
\mathbf{Y} &\sim N(\mathbf{X \beta, ZBZ' + \Sigma})
\end{aligned}
$$
If $\mathbf{V = ZBZ' + \Sigma}$, then the solutions to the estimating equations can be
$$
\begin{aligned}
\hat{\beta} &= \mathbf{(X'V^{-1}X)^{-1}X'V^{-1}Y} \\
\hat{\mathbf{b}} &= \mathbf{BZ'V^{-1}(Y-X\hat{\beta}})
\end{aligned}
$$
The estimate $\hat{\beta}$ is a generalized least squares estimate.
The predictor, $\hat{\mathbf{b}}$ is the best linear unbiased predictor (BLUP), for $\mathbf{b}$
$$
\begin{aligned}
E(\hat{\beta}) &= \beta \\
var(\hat{\beta}) &= (\mathbf{X'V^{-1}X})^{-1} \\
E(\hat{\mathbf{b}}) &= 0
\end{aligned}
$$
$$
var(\mathbf{\hat{b}-b}) = \mathbf{B-BZ'V^{-1}ZB + BZ'V^{-1}X(X'V^{-1}X)^{-1}X'V^{-1}B}
$$
The variance here is the variance of the prediction error (mean squared prediction error, MSPE), which is more meaningful than $var(\hat{\mathbf{b}})$, since MSPE accounts for both variance and bias in the prediction.
To derive the mixed model equations, consider
$$
\mathbf{\epsilon = Y - X\beta - Zb}
$$
Let $T = \sum_{i=1}^N n_i$ be the total number of observations (i.e., the length of $\mathbf{Y},\epsilon$) and $Nq$ the length of $\mathbf{b}$. The joint distribution of $\mathbf{b, \epsilon}$ is
$$
f(\mathbf{b,\epsilon})= \frac{1}{(2\pi)^{(T+ Nq)/2}}
\left|
\begin{array}
{cc}
\mathbf{B} & 0 \\
0 & \mathbf{\Sigma}
\end{array}
\right| ^{-1/2}
\exp
\left(
-\frac{1}{2}
\left[
\begin{array}
{c}
\mathbf{b} \\
\mathbf{Y - X \beta - Zb}
\end{array}
\right]'
\left[
\begin{array}
{cc}
\mathbf{B} & 0 \\
0 & \mathbf{\Sigma}
\end{array}
\right]^{-1}
\left[
\begin{array}
{c}
\mathbf{b} \\
\mathbf{Y - X \beta - Zb}
\end{array}
\right]
\right)
$$
Maximization of $f(\mathbf{b},\epsilon)$ with respect to $\mathbf{b}$ and $\beta$ requires minimization of
$$
\begin{aligned}
Q &=
\left[
\begin{array}
{c}
\mathbf{b} \\
\mathbf{Y - X \beta - Zb}
\end{array}
\right]'
\left[
\begin{array}
{cc}
\mathbf{B} & 0 \\
0 & \mathbf{\Sigma}
\end{array}
\right]^{-1}
\left[
\begin{array}
{c}
\mathbf{b} \\
\mathbf{Y - X \beta - Zb}
\end{array}
\right] \\
&= \mathbf{b'B^{-1}b+(Y-X \beta-Zb)'\Sigma^{-1}(Y-X \beta-Zb)}
\end{aligned}
$$
Setting the derivatives of Q with respect to $\mathbf{b}$ and $\mathbf{\beta}$ to zero leads to the system of equations:
$$
\begin{aligned}
\mathbf{X'\Sigma^{-1}X\beta + X'\Sigma^{-1}Zb} &= \mathbf{X'\Sigma^{-1}Y}\\
\mathbf{(Z'\Sigma^{-1}Z + B^{-1})b + Z'\Sigma^{-1}X\beta} &= \mathbf{Z'\Sigma^{-1}Y}
\end{aligned}
$$
Rearranging
$$
\left[
\begin{array}
{cc}
\mathbf{X'\Sigma^{-1}X} & \mathbf{X'\Sigma^{-1}Z} \\
\mathbf{Z'\Sigma^{-1}X} & \mathbf{Z'\Sigma^{-1}Z + B^{-1}}
\end{array}
\right]
\left[
\begin{array}
{c}
\beta \\
\mathbf{b}
\end{array}
\right]
=
\left[
\begin{array}
{c}
\mathbf{X'\Sigma^{-1}Y} \\
\mathbf{Z'\Sigma^{-1}Y}
\end{array}
\right]
$$
Thus, the solution to the mixed model equations give:
$$
\left[
\begin{array}
{c}
\hat{\beta} \\
\hat{\mathbf{b}}
\end{array}
\right]
=
\left[
\begin{array}
{cc}
\mathbf{X'\Sigma^{-1}X} & \mathbf{X'\Sigma^{-1}Z} \\
\mathbf{Z'\Sigma^{-1}X} & \mathbf{Z'\Sigma^{-1}Z + B^{-1}}
\end{array}
\right] ^{-1}
\left[
\begin{array}
{c}
\mathbf{X'\Sigma^{-1}Y} \\
\mathbf{Z'\Sigma^{-1}Y}
\end{array}
\right]
$$
Equivalently,
Bayes' theorem
$$
f(\mathbf{b}| \mathbf{Y}) = \frac{f(\mathbf{Y}|\mathbf{b})f(\mathbf{b})}{\int f(\mathbf{Y}|\mathbf{b})f(\mathbf{b}) d\mathbf{b}}
$$
where
- $f(\mathbf{Y}|\mathbf{b})$ is the "likelihood"
- $f(\mathbf{b})$ is the prior
- the denominator is the "normalizing constant"
- $f(\mathbf{b}|\mathbf{Y})$ is the posterior distribution
In this case
$$
\begin{aligned}
\mathbf{Y} | \mathbf{b} &\sim N(\mathbf{X\beta+Zb,\Sigma}) \\
\mathbf{b} &\sim N(\mathbf{0,B})
\end{aligned}
$$
The posterior distribution has the form
$$
\mathbf{b}|\mathbf{Y} \sim N(\mathbf{BZ'V^{-1}(Y-X\beta),(Z'\Sigma^{-1}Z + B^{-1})^{-1}})
$$
Hence, the best predictor (based on squared error loss)
$$
E(\mathbf{b}|\mathbf{Y}) = \mathbf{BZ'V^{-1}(Y-X\beta)}
$$
### Estimating $\mathbf{V}$
If we have $\tilde{\mathbf{V}}$ (estimate of $\mathbf{V}$), then we can estimate:
$$
\begin{aligned}
\hat{\beta} &= \mathbf{(X'\tilde{V}^{-1}X)^{-1}X'\tilde{V}^{-1}Y} \\
\hat{\mathbf{b}} &= \mathbf{BZ'\tilde{V}^{-1}(Y-X\hat{\beta})}
\end{aligned}
$$
where ${\mathbf{b}}$ is **EBLUP** (estimated BLUP) or **empirical Bayes estimate**
Note:
- $\hat{var}(\hat{\beta})$ is a consistent estimator of $var(\hat{\beta})$ if $\tilde{\mathbf{V}}$ is a consistent estimator of $\mathbf{V}$
- However, $\hat{var}(\hat{\beta})$ is biased since the variability arises from estimating $\mathbf{V}$ is not accounted for in the estimate.
- Hence, $\hat{var}(\hat{\beta})$ underestimates the true variability
Ways to estimate $\mathbf{V}$
- [Maximum Likelihood Estimation (MLE)](#maximum-likelihood-estimation-mle)
- [Restricted Maximum Likelihood (REML)](#restricted-maximum-likelihood-reml)
- [Estimated Generalized Least Squares]
- [Bayesian Hierarchical Models (BHM)](#bayesian-hierarchical-models-bhm)
#### Maximum Likelihood Estimation (MLE) {#maximum-likelihood-estimation-mle}
Grouping unknown parameters in $\Sigma$ and $B$ under a parameter vector $\theta$. Under MLE, $\hat{\theta}$ and $\hat{\beta}$ maximize the likelihood $\mathbf{y} \sim N(\mathbf{X\beta, V(\theta))}$. Synonymously, $-2\log L(\mathbf{y;\theta,\beta})$:
$$
-2l(\mathbf{\beta,\theta,y}) = \log |\mathbf{V(\theta)}| + \mathbf{(y-X\beta)'V(\theta)^{-1}(y-X\beta)} + N \log(2\pi)
$$
- Step 1: Replace $\beta$ with its maximum likelihood (where $\theta$ is known $\hat{\beta}= (\mathbf{X'V(\theta)^{-1}X)^{-1}X'V(\theta)^{-1}y}$
- Step 2: Minimize the above equation with respect to $\theta$ to get the estimator $\hat{\theta}_{MLE}$
- Step 3: Substitute $\hat{\theta}_{MLE}$ back to get $\hat{\beta}_{MLE} = (\mathbf{X'V(\theta_{MLE})^{-1}X)^{-1}X'V(\theta_{MLE})^{-1}y}$
- Step 4: Get $\hat{\mathbf{b}}_{MLE} = \mathbf{B(\hat{\theta}_{MLE})Z'V(\hat{\theta}_{MLE})^{-1}(y-X\hat{\beta}_{MLE})}$
Note:
- $\hat{\theta}$ are typically negatively biased due to unaccounted fixed effects being estimated, which we could try to account for.
#### Restricted Maximum Likelihood (REML) {#restricted-maximum-likelihood-reml}
REML accounts for the number of estimated mean parameters by adjusting the objective function. Specifically, the likelihood of linear combination of the elements of $\mathbf{y}$ is accounted for.
We have $\mathbf{K'y}$, where $\mathbf{K}$ is any $N \times (N - p)$ full-rank contrast matrix, which has columns orthogonal to the $\mathbf{X}$ matrix (that is $\mathbf{K'X} = 0$). Then,
$$
\mathbf{K'y} \sim N(0,\mathbf{K'V(\theta)K})
$$
where $\beta$ is no longer in the distribution
We can proceed to maximize this likelihood for the contrasts to get $\hat{\theta}_{REML}$, which does not depend on the choice of $\mathbf{K}$. And $\hat{\beta}$ are based on $\hat{\theta}$
Comparison REML and MLE
- Both methods are based upon the likelihood principle, and have desired properties for the estimates:
- consistency
- asymptotic normality
- efficiency
- ML estimation provides estimates for fixed effects, while REML can't
- In balanced models, REML is identical to ANOVA
- REML accounts for df for the fixed effects int eh model, which is important when $\mathbf{X}$ is large relative to the sample size
- Changing $\mathbf{\beta}$ has no effect on the REML estimates of $\theta$
- REML is less sensitive to outliers than MLE
- MLE is better than REML regarding model comparisons (e.g., AIC or BIC)
#### Estimated Generalized Least Squares
MLE and REML rely upon the Gaussian assumption. To overcome this issue, EGLS uses the first and second moments.
$$
\mathbf{Y}_i = \mathbf{X}_i \beta + \mathbf{Z}_i \mathbf{b}_i + \epsilon_i
$$
where
- $\epsilon_i \sim (\mathbf{0,\Sigma_i})$
- $\mathbf{b}_i \sim (\mathbf{0,D})$
- $cov(\epsilon_i, \mathbf{b}_i) = 0$
Then the EGLS estimator is
$$
\begin{aligned}
\hat{\beta}_{GLS} &= \{\sum_{i=1}^n \mathbf{X'_iV_i(\theta)^{-1}X_i} \}^{-1} \sum_{i=1}^n \mathbf{X'_iV_i(\theta)^{-1}Y_i} \\
&=\{\mathbf{X'V(\theta)^{-1}X} \}^{-1} \mathbf{X'V(\theta)^{-1}Y}
\end{aligned}
$$
depends on the first two moments
- $E(\mathbf{Y}_i) = \mathbf{X}_i \beta$
- $var(\mathbf{Y}_i)= \mathbf{V}_i$
EGLS use $\hat{\mathbf{V}}$ for $\mathbf{V(\theta)}$
$$
\hat{\beta}_{EGLS} = \{ \mathbf{X'\hat{V}^{-1}X} \}^{-1} \mathbf{X'\hat{V}^{-1}Y}
$$
Hence, the fixed effects estimators for the MLE, REML, and EGLS are of the same form, except for the estimate of $\mathbf{V}$
In case of non-iterative approach, EGLS can be appealing when $\mathbf{V}$ can be estimated without much computational burden.
#### Bayesian Hierarchical Models (BHM) {#bayesian-hierarchical-models-bhm}
Joint distribution cane be decomposed hierarchically in terms of the product of conditional distributions and a marginal distribution
$$
f(A,B,C) = f(A|B,C) f(B|C)f(C)
$$
Applying to estimate $\mathbf{V}$
$$
\begin{aligned}
f(\mathbf{Y, \beta, b, \theta}) &= f(\mathbf{Y|\beta,b, \theta})f(\mathbf{b|\theta,\beta})f(\mathbf{\beta|\theta})f(\mathbf{\theta}) & \text{based on probability decomposition} \\
&= f(\mathbf{Y|\beta,b, \theta})f(\mathbf{b|\theta})f(\mathbf{\beta})f(\mathbf{\theta}) & \text{based on simplifying modeling assumptions}
\end{aligned}
$$
elaborate on the second equality, if we assume conditional independence (e.g., given $\theta$, no additional info about $\mathbf{b}$ is given by knowing $\beta$), then we can simply from the first equality