-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
21-ANOVA.Rmd
2878 lines (2101 loc) · 89.7 KB
/
21-ANOVA.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
# Analysis of Variance (ANOVA)
ANOVA is using the same underlying mechanism as linear regression. However, the angle that ANOVA chooses to look at is slightly different from the traditional linear regression. It can be more useful in the case with **qualitative variables** and **designed experiments**.
Experimental Design
- **Factor**: explanatory or predictor variable to be studied in an investigation
- **Treatment** (or Factor Level): "value" of a factor applied to the experimental unit
- **Experimental Unit**: person, animal, piece of material, etc. that is subjected to treatment(s) and provides a response
- **Single Factor Experiment**: one explanatory variable considered
- **Multifactor Experiment**: more than one explanatory variable
- **Classification Factor**: A factor that is not under the control of the experimenter (observational data)
- **Experimental Factor**: assigned by the experimenter
Basics of experimental design:
- Choices that a statistician has to make:
- set of treatments
- set of experimental units
- treatment assignment (selection bias)
- measurement (measurement bias, blind experiments)
- Advancements in experimental design:
1. **Factorial Experiments**:\
consider multiple factors at the same time (interaction)
2. **Replication**: repetition of experiment
- assess mean squared error
- control over precision of experiment (power)
3. **Randomization**
- Before R.A. Fisher (1900s), treatments were assigned systematically or subjectively
- randomization: assign treatments to experimental units at random, which averages out systematic effects that cannot be control by the investigator
4. **Local control**: Blocking or Stratification
- Reduce experimental errors and increase power by placing restrictions on the randomization of treatments to experimental units.
Randomization may also eliminate correlations due to time and space.
## Completely Randomized Design (CRD)
Treatment factor A with $a\ge2$ treatments levels. Experimental units are randomly assigned to each treatment. The number of experimental units in each group can be
- equal (balanced): n
- unequal (unbalanced): $n_i$ for the i-th group (i = 1,...,a).
The total sample size is $N=\sum_{i=1}^{a}n_i$
Possible assignments of units to treatments are $k=\frac{N!}{n_1!n_2!...n_a!}$
Each has probability 1/k of being selected. Each experimental unit is measured with a response $Y_{ij}$, in which j denotes unit and i denotes treatment.
Treatment
+-------------+----------------+----------------+------------+----------------+
| | 1 | 2 | ... | a |
+:============+:==============:+:==============:+:==========:+:==============:+
| | $Y_{11}$ | $Y_{21}$ | ... | $Y_{a1}$ |
+-------------+----------------+----------------+------------+----------------+
| | $Y_{12}$ | ... | ... | ... |
+-------------+----------------+----------------+------------+----------------+
| | ... | ... | ... | ... |
+-------------+----------------+----------------+------------+----------------+
| Sample Mean | $\bar{Y_{1.}}$ | $\bar{Y_{2.}}$ | ... | $\bar{Y_{a.}}$ |
+-------------+----------------+----------------+------------+----------------+
| Sample SD | $s_1$ | $s_2$ | ... | $s_a$ |
+-------------+----------------+----------------+------------+----------------+
where $\bar{Y_{i.}}=\frac{1}{n_i}\sum_{j=1}^{n_i}Y_{ij}$
$s_i^2=\frac{1}{n_i-1}\sum_{j=1}^{n_i}(Y_{ij}-\bar{Y_i})^2$
And the grand mean is $\bar{Y_{..}}=\frac{1}{N}\sum_{i}\sum_{j}Y_{ij}$
### Single Factor Fixed Effects Model
also known as Single Factor (One-Way) ANOVA or ANOVA Type I model.
Partitioning the Variance
The total variability of the $Y_{ij}$ observation can be measured as the deviation of $Y_{ij}$ around the overall mean $\bar{Y_{..}}$: $Y_{ij} - \bar{Y_{..}}$
This can be rewritten as:
$$
\begin{aligned}
Y_{ij} - \bar{Y_{..}}&=Y_{ij} - \bar{Y_{..}} + \bar{Y_{i.}} - \bar{Y_{i.}} \\
&= (\bar{Y_{i.}}-\bar{Y_{..}})+(Y_{ij}-\bar{Y_{i.}})
\end{aligned}
$$
where
- the first term is the *between* treatment differences (i.e., the deviation of the treatment mean from the overall mean)
- the second term is *within* treatment differences (i.e., the deviation of the observation around its treatment mean)
$$
\begin{aligned}
\sum_{i}\sum_{j}(Y_{ij} - \bar{Y_{..}})^2 &= \sum_{i}n_i(\bar{Y_{i.}}-\bar{Y_{..}})^2+\sum_{i}\sum_{j}(Y_{ij}-\bar{Y_{i.}})^2 \\
SSTO &= SSTR + SSE \\
total~SS &= treatment~SS + error~SS \\
(N-1)~d.f. &= (a-1)~d.f. + (N - a) ~ d.f.
\end{aligned}
$$
we lose a d.f. for the total corrected SSTO because of the estimation of the mean ($\sum_{i}\sum_{j}(Y_{ij} - \bar{Y_{..}})=0$)\
And, for the SSTR $\sum_{i}n_i(\bar{Y_{i.}}-\bar{Y_{..}})=0$
Accordingly, $MSTR= \frac{SST}{a-1}$ and $MSR=\frac{SSE}{N-a}$
**ANOVA Table**
+---------------------------+---------------------------------------------+------------+------------+
| Source of Variation | SS | df | MS |
+===========================+:===========================================:+:==========:+:==========:+
| Between Treatments | $\sum_{i}n_i (\bar{Y_{i.}}-\bar{Y_{..}})^2$ | a-1 | SSTR/(a-1) |
+---------------------------+---------------------------------------------+------------+------------+
| Error (within treatments) | $\sum_{i}\sum_{j}(Y_{ij}-\bar{Y_{i.}})^2$ | N-a | SSE/(N-a) |
+---------------------------+---------------------------------------------+------------+------------+
| Total (corrected) | $\sum_{i}n_i (\bar{Y_{i.}}-\bar{Y_{..}})^2$ | N-1 | |
+---------------------------+---------------------------------------------+------------+------------+
Linear Model Explanation of ANOVA
#### Cell means model
$$
Y_{ij}=\mu_i+\epsilon\_{ij}
$$
where
- $Y_{ij}$ response variable in $j$-th subject for the $i$-th treatment
- $\mu_i$: parameters (fixed) representing the unknown population mean for the i-th treatment
- $\epsilon_{ij}$ independent $N(0,\sigma^2)$ errors
- $E(Y_{ij})=\mu_i$ $var(Y_{ij})=var(\epsilon_{ij})=\sigma^2$
- All observations have the same variance
Example:
$a = 3$ (3 treatments) $n_1=n_2=n_3=2$
$$
\begin{aligned}
\left(\begin{array}{c}
Y_{11}\\
Y_{12}\\
Y_{21}\\
Y_{22}\\
Y_{31}\\
Y_{32}\\
\end{array}\right) &=
\left(\begin{array}{ccc}
1 & 0 & 0 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1 \\
0 & 0 & 1 \\
\end{array}\right)
\left(\begin{array}{c}
\mu_1 \\
\mu_2 \\
\mu_3 \\
\end{array}\right) + \left(\begin{array}{c}
\epsilon_{11} \\
\epsilon_{12} \\
\epsilon_{21} \\
\epsilon_{22} \\
\epsilon_{31} \\
\epsilon_{32} \\
\end{array}\right)\\
\mathbf{y} &= \mathbf{X\beta} +\mathbf{\epsilon}
\end{aligned}
$$
$X_{k,ij}=1$ if the $k$-th treatment is used
$X_{k,ij}=0$ Otherwise
**Note**: no intercept term.
\begin{equation}
\begin{aligned}
\mathbf{b}= \left[\begin{array}{c}
\mu_1 \\
\mu_2 \\
\mu_3 \\
\end{array}\right] &=
(\mathbf{x}'\mathbf{x})^{-1}\mathbf{x}'\mathbf{y} \\
& =
\left[\begin{array}{ccc}
n_1 & 0 & 0\\
0 & n_2 & 0\\
0 & 0 & n_3 \\
\end{array}\right]^{-1}
\left[\begin{array}{c}
Y_1\\
Y_2\\
Y_3\\
\end{array}\right] \\
& =
\left[\begin{array}{c}
\bar{Y_1}\\
\bar{Y_2}\\
\bar{Y_3}\\
\end{array}\right]
\end{aligned}
(\#eq:betaorigin)
\end{equation}
is the BLUE (best linear unbiased estimator) for $\beta=[\mu_1 \mu_2\mu_3]'$
$$
E(\mathbf{b})=\beta
$$
$$
var(\mathbf{b})=\sigma^2(\mathbf{X'X})^{-1}=\sigma^2
\left[\begin{array}{ccc}
1/n_1 & 0 & 0\\
0 & 1/n_2 & 0\\
0 & 0 & 1/n_3\\
\end{array}\right]
$$
$var(b_i)=var(\hat{\mu_i})=\sigma^2/n_i$ where $\mathbf{b} \sim N(\beta,\sigma^2(\mathbf{X'X})^{-1})$
$$
\begin{aligned}
MSE &= \frac{1}{N-a} \sum_{i}\sum_{j}(Y_{ij}-\bar{Y_{i.}})^2 \\
&= \frac{1}{N-a} \sum_{i}[(n_i-1)\frac{\sum_{i}(Y_{ij}-\bar{Y_{i.}})^2}{n_i-1}] \\
&= \frac{1}{N-a} \sum_{i}(n_i-1)s_1^2
\end{aligned}
$$
We have $E(s_i^2)=\sigma^2$
$E(MSE)=\frac{1}{N-a}\sum_{i}(n_i-1)\sigma^2=\sigma^2$
Hence, MSE is an unbiased estimator of $\sigma^2$, regardless of whether the treatment means are equal or not.
$E(MSTR)=\sigma^2+\frac{\sum_{i}n_i(\mu_i-\mu_.)^2}{a-1}$\
where $\mu_.=\frac{\sum_{i=1}^{a}n_i\mu_i}{\sum_{i=1}^{a}n_i}$\
If all treatment means are equals (=$\mu_.$), $E(MSTR)=\sigma^2$.
Then we can use an $F$-test for the equality of all treatment means:
$$H_0:\mu_1=\mu_2=..=\mu_a$$
$$H_a: not~al l~ \mu_i ~ are ~ equal $$
$F=\frac{MSTR}{MSE}$\
where large values of F support $H_a$ (since MSTR will tend to exceed MSE when $H_a$ holds)\
and F near 1 support $H_0$ (upper tail test)
**Equivalently**, when $H_0$ is true, $F \sim f_{(a-1,N-a)}$
- If $F \leq f_{(a-1,N-a;1-\alpha)}$, we cannot reject $H_0$
- If $F \geq f_{(a-1,N-a;1-\alpha)}$, we reject $H_0$
Note: If $a = 2$ (2 treatments), $F$-test = two sample $t$-test
#### Treatment Effects (Factor Effects)
Besides Cell means model, we have another way to formalize one-way ANOVA: $$Y_{ij} = \mu + \tau_i + \epsilon_{ij}$$ where
- $Y_{ij}$ is the $j$-th response for the $i$-th treatment
- $\tau_i$ is $i$-th treatment effect
- $\mu$ constant component, common to all observations
- $\epsilon_{ij}$ independent random errors \~ $N(0,\sigma^2)$
For example, $a = 3$, $n_1=n_2=n_3=2$
\begin{equation}
\begin{aligned}
\left(\begin{array}{c}
Y_{11}\\
Y_{12}\\
Y_{21}\\
Y_{22}\\
Y_{31}\\
Y_{32}\\
\end{array}\right) &=
\left(\begin{array}{cccc}
1 & 1 & 0 & 0 \\
1 & 1 & 0 & 0 \\
1 & 0 & 1 & 0 \\
1 & 0 & 1 & 0 \\
1 & 0 & 0 & 1 \\
1 & 0 & 0 & 1 \\
\end{array}\right)
\left(\begin{array}{c}
\mu \\
\tau_1 \\
\tau_2 \\
\tau_3\\
\end{array}\right) + \left(\begin{array}{c}
\epsilon_{11} \\
\epsilon_{12} \\
\epsilon_{21} \\
\epsilon_{22} \\
\epsilon_{31} \\
\epsilon_{32} \\
\end{array}\right)\\
\mathbf{y} &= \mathbf{X\beta} +\mathbf{\epsilon}
\end{aligned}
(\#eq:unsolvable)
\end{equation}
However,
$$
\mathbf{X'X} =
\left(
\begin{array}
{cccc}
\sum_{i}n_i & n_1 & n_2 & n_3 \\
n_1 & n_1 & 0 & 0 \\
n_2 & 0 & n_2 & 0 \\
n_3 & 0 & 0 & n_3 \\
\end{array}
\right)
$$
is **singular** thus does not exist, $\mathbf{b}$ is insolvable (infinite solutions)
Hence, we have to impose restrictions on the parameters to a model matrix $\mathbf{X}$ of full rank.
Whatever restriction we use, we still have:
$E(Y_{ij})=\mu + \tau_i = \mu_i = mean ~ response ~ for ~ i-th ~ treatment$
##### Restriction on sum of tau {#restriction-on-sum-of-tau}
$\sum_{i=1}^{a}\tau_i=0$
implies
$$
\mu= \mu +\frac{1}{a}\sum_{i=1}^{a}(\mu+\tau_i)
$$
is the average of the treatment mean (grand mean) (overall mean)
$$
\begin{aligned}
\tau_i &=(\mu+\tau_i) -\mu = \mu_i-\mu \\
&= \text{treatment mean} - \text{grand~mean} \\
&= \text{treatment effect}
\end{aligned}
$$
$$
\tau_a=-\tau_1-\tau_2-...-\tau_{a-1}
$$
Hence, the mean for the a-th treatment is
$$
\mu_a=\mu+\tau_a=\mu-\tau_1-\tau_2-...-\tau_{a-1}
$$
Hence, the model need only "a" parameters:
$$
\mu,\tau_1,\tau_2,..,\tau_{a-1}
$$
Equation \@ref(eq:unsolvable) becomes
\begin{equation}
\begin{aligned}
\left(\begin{array}{c}
Y_{11}\\
Y_{12}\\
Y_{21}\\
Y_{22}\\
Y_{31}\\
Y_{32}\\
\end{array}\right) &=
\left(\begin{array}{ccc}
1 & 1 & 0 \\
1 & 1 & 0 \\
1 & 0 & 1 \\
1 & 0 & 1 \\
1 & -1 & -1 \\
1 & -1 & -1 \\
\end{array}\right)
\left(\begin{array}{c}
\mu \\
\tau_1 \\
\tau_2 \\
\end{array}\right) + \left(\begin{array}{c}
\epsilon_{11} \\
\epsilon_{12} \\
\epsilon_{21} \\
\epsilon_{22} \\
\epsilon_{31} \\
\epsilon_{32} \\
\end{array}\right)\\
\mathbf{y} &= \mathbf{X\beta} +\mathbf{\epsilon}
\end{aligned}
\end{equation}
where $\beta\equiv[\mu,\tau_1,\tau_2]'$
Equation \@ref(eq:betaorigin) with $\sum_{i}\tau_i=0$ becomes
$$
\begin{aligned}
\mathbf{b}= \left[\begin{array}{c}
\hat{\mu} \\
\hat{\tau_1} \\
\hat{\tau_2} \\
\end{array}\right] &=
(\mathbf{x}'\mathbf{x})^{-1}\mathbf{x}'\mathbf{y} \\
& =
\left[\begin{array}{ccc}
\sum_{i}n_i & n_1-n_3 & n_2-n_3\\
n_1-n_3 & n_1+n_3 & n_3\\
n_2-n_3 & n_3 & n_2-n_3 \\
\end{array}\right]^{-1}
\left[\begin{array}{c}
Y_{..}\\
Y_{1.}-Y_{3.}\\
Y_{2.}-Y_{3.}\\
\end{array}\right] \\
& =
\left[\begin{array}{c}
\frac{1}{3}\sum_{i=1}^{3}\bar{Y_{i.}}\\
\bar{Y_{1.}}-\frac{1}{3}\sum_{i=1}^{3}\bar{Y_{i.}}\\
\bar{Y_{2.}}-\frac{1}{3}\sum_{i=1}^{3}\bar{Y_{i.}}\\
\end{array}\right]\\
& =
\left[\begin{array}{c}
\hat{\mu}\\
\hat{\tau_1}\\
\hat{\tau_2}\\
\end{array}\right]
\end{aligned}
$$
and $\hat{\tau_3}=-\hat{\tau_1}-\hat{\tau_2}=\bar{Y_3}-\frac{1}{3} \sum_{i}\bar{Y_{i.}}$
##### Restriction on first tau {#restriction-on-first-tau}
In R, `lm()` uses the restriction $\tau_1=0$
For the previous example, for $n_1=n_2=n_3=2$, and $\tau_1=0$.
Then the treatment means can be written as:
$$
\begin{aligned}
\mu_1 &= \mu + \tau_1 = \mu + 0 = \mu \\
\mu_2 &= \mu + \tau_2 \\
\mu_3 &= \mu + \tau_3
\end{aligned}
$$
Hence, $\mu$ is the mean response for the first treatment
In the matrix form,
$$
\begin{aligned}
\left(\begin{array}{c}
Y_{11}\\
Y_{12}\\
Y_{21}\\
Y_{22}\\
Y_{31}\\
Y_{32}\\
\end{array}\right) &=
\left(\begin{array}{ccc}
1 & 0 & 0 \\
1 & 0 & 0 \\
1 & 1 & 0 \\
1 & 1 & 0 \\
1 & 0 & 1 \\
1 & 0 & 1 \\
\end{array}\right)
\left(\begin{array}{c}
\mu \\
\tau_2 \\
\tau_3 \\
\end{array}\right) + \left(\begin{array}{c}
\epsilon_{11} \\
\epsilon_{12} \\
\epsilon_{21} \\
\epsilon_{22} \\
\epsilon_{31} \\
\epsilon_{32} \\
\end{array}\right)\\
\mathbf{y} &= \mathbf{X\beta} +\mathbf{\epsilon}
\end{aligned}
$$
$\beta = [\mu,\tau_2,\tau_3]'$
$$
\begin{aligned}
\mathbf{b}= \left[\begin{array}{c}
\hat{\mu} \\
\hat{\tau_2} \\
\hat{\tau_3} \\
\end{array}\right] &=
(\mathbf{x}'\mathbf{x})^{-1}\mathbf{x}'\mathbf{y} \\
& =
\left[\begin{array}{ccc}
\sum_{i}n_i & n_2 & n_3\\
n_2 & n_2 & 0\\
n_3 & 0 & n_3 \\
\end{array}\right]^{-1}
\left[\begin{array}{c}
Y_{..}\\
Y_{2.}\\
Y_{3.}\\
\end{array}\right] \\
& =
\left[
\begin{array}{c}
\bar{Y_{1.}} \\
\bar{Y_{2.}} - \bar{Y_{1.}} \\
\bar{Y_{3.}} - \bar{Y_{1.}}\\
\end{array}\right]
\end{aligned}
$$
$$
E(\mathbf{b})= \beta =
\left[\begin{array}{c}
{\mu}\\
{\tau_2}\\
{\tau_3}\\
\end{array}\right]
=
\left[\begin{array}{c}
\mu_1\\
\mu_2-\mu_1\\
\mu_3-\mu_1\\
\end{array}\right]
$$
$$
\begin{aligned}
var(\mathbf{b}) &= \sigma^2(\mathbf{X'X})^{-1} \\
var(\hat{\mu}) &= var(\bar{Y_{1.}})=\sigma^2/n_1 \\
var(\hat{\tau_2}) &= var(\bar{Y_{2.}}-\bar{Y_{1.}}) = \sigma^2/n_2 + \sigma^2/n_1 \\
var(\hat{\tau_3}) &= var(\bar{Y_{3.}}-\bar{Y_{1.}}) = \sigma^2/n_3 + \sigma^2/n_1
\end{aligned}
$$
**Note** For all three parameterization, the ANOVA table is the same
- [Model 1](#cell-means-model-1): $Y_{ij} = \mu_i + \epsilon_{ij}$
- [Model 2](#restriction-on-sum-of-tau): $Y_{ij} = \mu + \tau_i + \epsilon_{ij}$ where $\sum_{i} \tau_i=0$
- [Model 3](#restriction-on-first-tau): $Y_{ij}= \mu + \tau_i + \epsilon_{ij}$ where $\tau_1=0$
All models have the same calculation for $\hat{Y}$ as
$$
\mathbf{\hat{Y} = X(X'X)^{-1}X'Y=PY = Xb}
$$
**ANOVA Table**
+---------------------+------------------------------------------------------------------------------+---------+--------------------+--------------------+
| Source of Variation | SS | df | MS | F |
+=====================+:============================================================================:+:=======:+:==================:+:==================:+
| Between Treatments | $\sum_{i} n _ i (\bar { Y_ {i .} } -\bar{Y_{..}})^2 = \mathbf{Y ' (P-P_1)Y}$ | a-1 | $\frac{SSTR}{a-1}$ | $\frac{MSTR}{MSE}$ |
+---------------------+------------------------------------------------------------------------------+---------+--------------------+--------------------+
| Error | $\sum_{i}\sum_{j}(Y_{ij} -\bar{Y_{i.}})^2=\mathbf{e'e}$ | N-a | $\frac{SSE}{N-a}$ | |
| | | | | |
| (within treatments) | | | | |
+---------------------+------------------------------------------------------------------------------+---------+--------------------+--------------------+
| Total (corrected) | $\sum_{i } n_i(\bar{Y_{i.}}-\bar{Y_{..}})^2=\mathbf{Y'Y - Y'P_1Y}$ | N-1 | | |
+---------------------+------------------------------------------------------------------------------+---------+--------------------+--------------------+
where $\mathbf{P_1} = \frac{1}{n}\mathbf{J}$
The $F$-statistic here has $(a-1,N-a)$ degrees of freedom, which gives the same value for all three parameterization, but the hypothesis test is written a bit different:
$$
\begin{aligned}
&H_0 : \mu_1 = \mu_2 = ... = \mu_a \\
&H_0 : \mu + \tau_1 = \mu + \tau_2 = ... = \mu + \tau_a \\
&H_0 : \tau_1 = \tau_2 = ...= \tau_a
\end{aligned}
$$
The $F$-test here serves as a preliminary analysis, to see if there is any difference at different factors. For more in-depth analysis, we consider different testing of treatment effects.
#### Testing of Treatment Effects
- A [Single Treatment Mean] $\mu_i$
- A [Differences Between Treatment Means]
- A [Contrast Among Treatment Means]
- A [Linear Combination of Treatment Means]
##### Single Treatment Mean
We have $\hat{\mu_i}=\bar{Y_{i.}}$ where
- $E(\bar{Y_{i.}})=\mu_i$
- $var(\bar{Y_{i}})=\sigma^2/n_i$ estimated by $s^2(\bar{Y_{i.}})=MSE / n_i$
Since $\frac{\bar{Y_{i.}}-\mu_i}{s(\bar{Y_{i.}})} \sim t_{N-a}$ and the confidence interval for $\mu_i$ is $\bar{Y_{i.}} \pm t_{1-\alpha/2;N-a}s(\bar{Y_{i.}})$,\
then we can do a t-test for the means difference with some constant $c$
$$
\begin{aligned}
&H_0: \mu_i = c \\
&H_1: \mu_i \neq c
\end{aligned}
$$
where
$$
T =\frac{\bar{Y_{i.}}-c}{s(\bar{Y_{i.}})}
$$
follows $t_{N-a}$ when $H_0$ is true.\
If $|T| > t_{1-\alpha/2;N-a}$, we can reject $H_0$
##### Differences Between Treatment Means
Let $D=\mu_i - \mu_i'$, also known as **pairwise comparison**\
$D$ can be estimated by $\hat{D}=\bar{Y_{i}}-\bar{Y_{i}}'$ is unbiased ($E(\hat{D})=\mu_i-\mu_i'$)
Since $\bar{Y_{i}}$ and $\bar{Y_{i}}'$ are independent, then
$$
var(\hat{D})=var(\bar{Y_{i}}) + var(\bar{Y_{i'}}) = \sigma^2(1/n_i + 1/n_i')
$$
can be estimated with
$$
s^2(\hat{D}) = MSE(1/n_i + 1/n_i')
$$
With the single treatment inference,
$$
\frac{\hat{D}-D}{s(\hat{D})} \sim t_{N-a}
$$
hence,
$$
\hat{D} \pm t_{(1-\alpha/2;N-a)}s(\hat{D})
$$
Hypothesis tests:
$$
\begin{aligned}
&H_0: \mu_i = \mu_i' \\
&H_a: \mu_i \neq \mu_i'
\end{aligned}
$$
can be tested by the following statistic
$$
T = \frac{\hat{D}}{s(\hat{D})} \sim t_{1-\alpha/2;N-a}
$$
reject $H_0$ if $|T| > t_{1-\alpha/2;N-a}$
##### Contrast Among Treatment Means
generalize the comparison of two means, we have **contrasts**
A contrast is a linear combination of treatment means:
$$
L = \sum_{i=1}^{a}c_i \mu_i
$$
where each $c_i$ is non-random constant and sum to 0:
$$
\sum_{i=1}^{a} c_i = 0
$$
An unbiased estimator of a contrast L is
$$
\hat{L} = \sum_{i=1}^{a}c_i \bar{Y}_{i.}
$$
and $E(\hat{L}) = L$. Since the $\bar{Y}_{i.}$, i = 1,..., a are independent.
$$
\begin{aligned}
var(\hat{L}) &= var(\sum_{i=1}^a c_i \bar{Y}_{i.}) = \sum_{i=1}^a var(c_i \bar{Y}_i) \\
&= \sum_{i=1}^a c_i^2 var(\bar{Y}_i) = \sum_{i=1}^a c_i^2 \sigma^2 /n_i \\
&= \sigma^2 \sum_{i=1}^{a} c_i^2 /n_i
\end{aligned}
$$
Estimation of the variance:
$$
s^2(\hat{L}) = MSE \sum_{i=1}^{a} \frac{c_i^2}{n_i}
$$
$\hat{L}$ is normally distributed (since it is a linear combination of independent normal random variables).
Then, since $SSE/\sigma^2$ is $\chi_{N-a}^2$
$$
\frac{\hat{L}-L}{s(\hat{L})} \sim t_{N-a}
$$
A $1-\alpha$ confidence limits are given by
$$
\hat{L} \pm t_{1-\alpha/2; N-a}s(\hat{L})
$$
Hypothesis testing
$$
\begin{aligned}
&H_0: L = 0 \\
&H_a: L \neq 0
\end{aligned}
$$
with
$$
T = \frac{\hat{L}}{s(\hat{L})}
$$
reject $H_0$ if $|T| > t_{1-\alpha/2;N-a}$
##### Linear Combination of Treatment Means
just like contrast $L = \sum_{i=1}^a c_i \mu_i$ but no restrictions on the $c_i$ coefficients.
Tests on a single treatment mean, two treatment means, and contrasts can all be considered form the same perspective.
$$
\begin{aligned}
&H_0: \sum c_i \mu_i = c \\
&H_a: \sum c_i \mu_i \neq c
\end{aligned}
$$
The test statistics ( $t$-stat) can be considered equivalently as $F$-tests; $F = (T)^2$ where $F \sim F_{1,N-a}$. Since the numerator degrees of freedom is always 1 in these cases, we refer to them as single-degree-of-freedom tests.
**Multiple Contrasts**
To test simultaneously $k \ge 2$ contrasts, let $T_1,...,T_k$ be the t-stat. The joint distribution of these random variables is a multivariate t-distribution (the tests are dependent since they re based on the same data).
Limitations for comparing multiple contrasts:
1. The confidence coefficient $1-\alpha$ only applies to a particular estimate, not a series of estimates; similarly, the Type I error rate, $\alpha$, applies to a particular test, not a series of tests. Example: 3 $t$-tests at $\alpha = 0.05$, if tests are independent (which they are not), $0.95^3 = 0.857$ (thus $\alpha - 0.143$ not 0.05)\
2. The confidence coefficient $1-\alpha$ and significance level $\alpha$ are appropriate only if the test was not suggest by the data.
- often, the results of an experiment suggest important (i.e.,..g, potential significant) relationships.
- the process of studying effects suggests by the data is called **data snooping**
Multiple Comparison Procedures:
- [Tukey]
- [Scheffe]
- [Bonferroni]
###### Tukey
All pairwise comparisons of factor level means. All pairs $D = \mu_i - \mu_i'$ or all tests of the form:
$$
\begin{aligned}
&H_0: \mu_i -\mu_i' = 0 \\
&H_a: \mu_i - \mu_i' \neq 0
\end{aligned}
$$
- When all sample sizes are equal ($n_1 = n_2 = ... = n_a$) then the Tukey method family confidence coefficient is exactly $1-\alpha$ and the significance level is exactly $\alpha$\
- When the sample sizes are not equal, the family confidence coefficient is greater than $1-\alpha$ (i.e., the significance level is less than $\alpha$) so the test **conservative**\
- Tukey considers the **studentized range distribution**. If we have $Y_1,..,Y_r$, observations from a normal distribution with mean $\alpha$ and variance $\sigma^2$. Define: $$
w = max(Y_i) - min(Y_i)
$$ as the range of the observations. Let $s^2$ be an estimate of $\sigma^2$ with v degrees of freedom. Then, $$
q(r,v) = \frac{w}{s}
$$ is called the studentized range. The distribution of q uses a special table.
**Notes**
- when we are not interested in testing all pairwise comparison,s the confidence coefficient for the family of comparisons under consideration will be greater than $1-\alpha$ (with the significance level less than $\alpha$)
- Tukey can be used for "data snooping" as long as the effects to be studied on the basis of preliminary data analysis are pairwise comparisons.
###### Scheffe
This method applies when the family of interest is the set of possible contrasts among the treatment means:
$$
L = \sum_{i=1}^a c_i \mu_i
$$
where $\sum_{i=1}^a c_i =0$
That is, the family of all possible contrasts $L$ or
$$
\begin{aligned}
&H_0: L = 0 \\
&H_a: L \neq 0
\end{aligned}
$$
The family confidence level for the Scheffe procedure is exactly $1-\alpha$ (i.e., significance level = $\alpha$) whether the sample sizes are equal or not.
For simultaneous confidence intervals,
$$
\hat{L} \pm Ss(\hat{L})
$$
where $\hat{L}=\sum c_i \bar{Y}_{i.},s^2(\hat{L}) = MSE \sum c_i^2/n_i$ and $S^2 = (a-1)f_{1-\alpha;a-1,N-a}$
The Scheffe procedure considers
$$
F = \frac{\hat{L}^2}{(a-1)s^2(\hat{L})}
$$
where we reject $H_0$ at the family significance level $\alpha$ if $F > f_{(1-\alpha;a-1,N-a)}$
**Note**
- Since applications of the Scheffe never involve all conceivable contrasts, the **finite family** confidence coefficient will be larger than $1-\alpha$, so $1-\alpha$ is a lower bound. Thus, people often consider a larger $\alpha$ (e.g., 90% confidence interval)
- Scheffe can be used for "data scooping" since the family of statements contains all possible contrasts.
- If only pairwise comparisons are to be considered, The Tukey procedure gives narrower confidence limits.
###### Bonferroni
Applicable whether the sample sizes are equal or unequal.
For the confidence intervals,
$$
\hat{L} \pm B s(\hat{L})
$$
where $B= t_{(1-\alpha/(2g);N-a)}$ and g is the number of comparisons in the family.
Hypothesis testing
$$
\begin{aligned}
&H_0: L = 0 \\
&H_a: L \neq 0
\end{aligned}
$$
Let $T= \frac{\hat{L}}{s(\hat{L})}$ and reject $H_0$ if $|T|>t_{1-\alpha/(2g),N-a}$
**Notes**
- If all pairwise comparisons are of interest, the Tukey procedure is superior (narrower confidence intervals). If not, Bonferroni may be better.
- Bonferroni is better than Scheffe when the number of contrasts is about the same as the treatment levels (or less).
- Recommendation: compute all threes and pick the smallest.
- Bonferroni can't be used for **data snooping**
###### Fisher's LSD
does not control for family error rate
use $t$-stat for testing
$$
H_0: \mu_i = \mu_j
$$
t-stat
$$
t = \frac{\bar{y}_i - \bar{y}_j}{\sqrt{MSE(\frac{1}{n_i}+ \frac{1}{n_j})}}
$$
###### Newman-Keuls
Do not recommend using this test since it has less power than ANOVA.
##### Multiple comparisons with a control
###### Dunnett
We have $a$ groups where the last group is the control group, and the $a-1$ treatment groups.
Then, we compare treatment groups to the control group. Hence, we have $a-1$ contrasts (i.e., $a-1$ pairwise comparisons)
##### Summary
When choosing a multiple contrast method:
- Pairwise
- Equal groups sizes: [Tukey]
- Unequal groups sizes: [Tukey], [Scheffe]
- Not pairwise
- with control: [Dunnett]
- general: [Bonferroni], [Scheffe]
### Single Factor Random Effects Model
Also known as ANOVA Type II models.
Treatments are chosen at from from larger population. We extend inference to all treatments in the population and not restrict our inference to those treatments that happened to be selected for the study.
#### Random Cell Means
$$
Y_{ij} = \mu_i + \epsilon_{ij}
$$
where
- $\mu_i \sim N(\mu, \sigma^2_{\mu})$ and independent
- $\epsilon_{ij} \sim N(0,\sigma^2)$ and independent
$\mu_i$ and $\epsilon_{ij}$ are mutually independent for $i =1,...,a; j = 1,...,n$
With all treatment sample sizes are equal
$$
\begin{aligned}
E(Y_{ij}) &= E(\mu_i) = \mu \\
var(Y_{ij}) &= var(\mu_i) + var(\epsilon_i) = \sigma^2_{\mu} + \sigma^2
\end{aligned}
$$
Since $Y_{ij}$ are not independent
$$
\begin{aligned}
cov(Y_{ij},Y_{ij'}) &= E(Y_{ij}Y_{ij'}) - E(Y_{ij})E(Y_{ij'}) \\
&= E(\mu_i^2 + \mu_i \epsilon_{ij'} + \mu_i \epsilon_{ij} + \epsilon_{ij}\epsilon_{ij'}) - \mu^2 \\
&= \sigma^2_{\mu} + \mu^2 - \mu^2 & \text{if} j \neq j' \\
&= \sigma^2_{\mu} & \text{if} j \neq j'
\end{aligned}
$$
$$
\begin{aligned}
cov(Y_{ij},Y_{i'j'}) &= E(\mu_i \mu_{i'} + \mu_i \epsilon_{i'j'}+ \mu_{i'}\epsilon_{ij}+ \epsilon_{ij}\epsilon_{i'j'}) - \mu^2 \\
&= \mu^2 - \mu^2 & \text{if } i \neq i' \\
&= 0 \\
\end{aligned}
$$
Hence,
- all observations have the same variance
- any two observations from the same treatment have covariance $\sigma^2_{\mu}$
- The correlation between any two responses from the same treatment:\
$$
\begin{aligned}
\rho(Y_{ij},Y_{ij'}) &= \frac{\sigma^2_{\mu}}{\sigma^2_{\mu}+ \sigma^2} && \text{$j \neq j'$}
\end{aligned}
$$
**Inference**
**Intraclass Correlation Coefficient**
$$
\frac{\sigma^2_{\mu}}{\sigma^2 + \sigma^2_{\mu}}
$$
which measures the proportion of total variability of $Y_{ij}$ accounted for by the variance of $\mu_i$
$$
\begin{aligned}