-
Notifications
You must be signed in to change notification settings - Fork 5
/
lec04.tex
1348 lines (1223 loc) · 45.6 KB
/
lec04.tex
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
\documentclass[table,10pt]{beamer}\usepackage[]{graphicx}\usepackage[]{color}
%% maxwidth is the original width if it is less than linewidth
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
\makeatletter
\def\maxwidth{ %
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\let\hlipl\hlkwb
\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
\def\at@end@of@kframe{}%
\ifinner\ifhmode%
\def\at@end@of@kframe{\end{minipage}}%
\begin{minipage}{\columnwidth}%
\fi\fi%
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
\colorbox{shadecolor}{##1}\hskip-\fboxsep
% There is no \\@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\@totalleftmargin\z@ \linewidth\hsize
\@setminipage}}%
{\par\unskip\endMakeFramed%
\at@end@of@kframe}
\makeatother
\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
\usepackage{alltt}
\mode<presentation>{
%\usetheme{Goettingen}
\usetheme{Boadilla}
\usecolortheme{default}
}
\usepackage{CJK}
\usepackage{graphicx}
\usepackage{amsmath, amsopn}
\usepackage{xcolor}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{enumerate}
\usepackage{multirow}
\usepackage{url}
\ifx\hypersetup\undefined
\AtbBeginDocument{%
\hypersetup{unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false}
}
\else
\hypersetup{unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
breaklinks=false,pdfborder={0 0 0},pdfborderstyle={},backref=false,colorlinks=false}
\fi
\usepackage{breakurl}
\usepackage{color}
\usepackage{times}
\usepackage{xcolor}
\usepackage{listings}
\lstset{
language=R,
keywordstyle=\color{blue!70}\bfseries,
basicstyle=\ttfamily,
commentstyle=\ttfamily,
showspaces=false,
showtabs=false,
frame=shadowbox,
rulesepcolor=\color{red!20!green!20!blue!20},
breaklines=true}
\setlength{\parskip}{.5em}
\title[BI476]{BI476: Biostatistics - Case Studies}
\subtitle[anova]{Lec04: Clinical Trial Data Analysis}
\author[Maoying Wu]{Maoying,Wu\\{\small ricket.woo@gmail.com}}
\institute[CBB] % (optional, but mostly needed)
{
\inst{}
Dept. of Bioinformatics \& Biostatistics\\
Shanghai Jiao Tong University
}
\date{Spring, 2018}
\AtBeginSection[]
{
\begin{frame}<beamer>{Next Section ...}
\tableofcontents[currentsection]
\end{frame}
}
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\begin{document}
\begin{CJK*}{UTF8}{gbsn}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}
\frametitle{Outline}
\tableofcontents
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{A Clinical Trial on Diastolic Blood Pressure (DBP)}
Here we present a data set of diastolic blood pressure measured in
small clinical trials in hypertension from the mid-to-late 1960s and
for approximately a decade thereafter. Diastolic blood pressure (DBP)
was measured (mmHg) in the supine position at baseline (i.e., ``DBP1'')
before randomization and monthly thereafter up to 4 months as indicated
by \texttt{DBP2}, \texttt{DBP3}, \texttt{DBP4} and \texttt{DBP5}.
Patients' age and sex were recorded at baseline and represent potential
covariates.
The primary objective in the analysis of this dataset is to test
whether treatment A (new drug) may be effective in lowering DBP as
compared to B (placebo) and to describe changes in DBP across the times
at which it was measured.
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Importing the dataset}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{dbp} \hlkwb{<-} \hlkwd{read.table}\hlstd{(}\hlstr{"data/dbp.txt"}\hlstd{,} \hlkwc{header}\hlstd{=T)}
\hlstd{dbp}\hlopt{$}\hlstd{diff} \hlkwb{<-} \hlstd{dbp}\hlopt{$}\hlstd{DBP5} \hlopt{-} \hlstd{dbp}\hlopt{$}\hlstd{DBP1}
\hlkwd{head}\hlstd{(dbp)}
\end{alltt}
\begin{verbatim}
## Subject TRT DBP1 DBP2 DBP3 DBP4 DBP5 Age Sex diff
## 1 1 A 114 115 113 109 105 43 F -9
## 2 2 A 116 113 112 103 101 51 M -15
## 3 3 A 119 115 113 104 98 48 F -21
## 4 4 A 115 113 112 109 101 42 F -14
## 5 5 A 116 112 107 104 105 49 M -11
## 6 6 A 117 112 113 104 102 47 M -15
\end{verbatim}
\begin{alltt}
\hlkwd{table}\hlstd{(dbp}\hlopt{$}\hlstd{TRT)}
\end{alltt}
\begin{verbatim}
##
## A B
## 20 20
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Baseline Information}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{par}\hlstd{(}\hlkwc{mfrow}\hlstd{=}\hlkwd{c}\hlstd{(}\hlnum{1}\hlstd{,}\hlnum{2}\hlstd{))}
\hlkwd{boxplot}\hlstd{(DBP1} \hlopt{~} \hlstd{TRT,} \hlkwc{data}\hlstd{=dbp)}
\hlkwd{barplot}\hlstd{(}\hlkwd{table}\hlstd{(dbp}\hlopt{$}\hlstd{Sex, dbp}\hlopt{$}\hlstd{TRT))}
\end{alltt}
\end{kframe}
{\centering \includegraphics[width=0.60\textwidth]{figure/beamer-unnamed-chunk-2-1}
}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Pairwise plot}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{pairs}\hlstd{(dbp)}
\end{alltt}
\end{kframe}
{\centering \includegraphics[width=0.60\textwidth]{figure/beamer-unnamed-chunk-3-1}
}
\end{knitrout}
\end{frame}
\section{Parametric tests}
\begin{frame}[t]
\frametitle{Parametric tests}
\begin{itemize}
\item 2-groups: t-test for continuous outcome in completely randomized
parallel design.
\item 2-groups: Paired t-test for continuous outcome in crossover design.
\item 3+-groups: One-way ANOVA for continuous outcome in completely
randomized parallel design.
\item 2+-groups: Two-way ANOVA for continuous outcome in factorial design.
\item 3+-groups: One-way repeated-measures ANOVA for continuous outcome
in randomized block design.
\item 2-groups: Chisquare test or Fisher's exact test for binary outcome in
completely randomized parallel design.
\item 2-groups: McNemar's test for binary outcome in crossover design.
\item 3+-groups: Cochrane's Q-test for binary outcome in crossover design.
\end{itemize}
\end{frame}
\subsection{t-test}
\begin{frame}[t, containsverbatim]
\frametitle{Student's t-test for parallel design}
\framesubtitle{Comparing two treament group means with equal variances}
\begin{itemize}
\item \textbf{Assumption}: $Y_1$ and $Y_2$ are independent
and normally distributed with common variance
$\sigma^2$.
\item \textbf{Design}: Randomized parallel design
\item \textbf{Hypothesis}: $H_0: \mu_1 = \mu_2$ vs. $H_1: \mu_1 \neq \mu_2$
\item \textbf{Process}
\begin{itemize}
\item Compute the test statistic:
$$t = \frac{\bar{y}_1 - \bar{y}_2}{s\sqrt{1/n_1 + 1/n_2}}$$,
where
$$
\bar{y}_i = \sum_{j=1}^{n_i} y_{ij}/n_i, s = \sqrt{\frac{(n_1-1)s_1^2 + (n_2-1)s_2^2}{n_1+n_2-2}},
s_i^2 = \sum_{j=1}^{n_i} (y_{ij} - \bar{y}_i)^2/(n_i - 1)$$.
\item Reject $H_0$ if $t > t_{\alpha/2,n_1+n_2-2}$
\end{itemize}
\end{itemize}
\begin{lstlisting}
t.test(..., var.equal=TRUE)
\end{lstlisting}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{$t$-test with equal variances}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{t.test}\hlstd{(diff} \hlopt{~} \hlstd{TRT,} \hlkwc{data}\hlstd{=dbp,} \hlkwc{var.equal}\hlstd{=}\hlnum{TRUE}\hlstd{)}
\end{alltt}
\begin{verbatim}
##
## Two Sample t-test
##
## data: diff by TRT
## t = -12.15, df = 38, p-value = 1.169e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -12.132758 -8.667242
## sample estimates:
## mean in group A mean in group B
## -15.2 -4.8
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Welch's t-test for parallel design}
\framesubtitle{Comparing two treatment group means with unequal variances}
\begin{enumerate}
\item Compute the $t$ statistic
$$
T = \frac{\bar{y}_1 - \bar{y}_2}{\sqrt{s_1^2/n_1 + s_2^2/n_2}}
$$
\item The degree of freedom
$$
\nu = \left[ \frac{c}{n_1-1} + \frac{(1-c)^2}{n_2-1}\right]^{-1}
$$
where
$$
c = \frac{s_1^2/n_1}{s_1^2/n_1 + s_2^2/n_2}
$$
\item Reject $H_0$ if $|T| > t_{\alpha/2, \nu}$
\end{enumerate}
\begin{lstlisting}
t.test(..., var.equal=FALSE)
\end{lstlisting}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{$t$-test with unequal variances}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{t.test}\hlstd{(diff} \hlopt{~} \hlstd{TRT,} \hlkwc{data}\hlstd{=dbp,} \hlkwc{var.equal}\hlstd{=}\hlnum{FALSE}\hlstd{)}
\end{alltt}
\begin{verbatim}
##
## Welch Two Sample t-test
##
## data: diff by TRT
## t = -12.15, df = 36.522, p-value = 2.149e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -12.135063 -8.664937
## sample estimates:
## mean in group A mean in group B
## -15.2 -4.8
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Wait...Are the two variances equal?}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{var.test}\hlstd{(diff} \hlopt{~} \hlstd{TRT,} \hlkwc{data}\hlstd{=dbp)}
\end{alltt}
\begin{verbatim}
##
## F test to compare two variances
##
## data: diff by TRT
## F = 1.5036, num df = 19, denom df = 19, p-value = 0.3819
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.595142 3.798764
## sample estimates:
## ratio of variances
## 1.503597
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t, containsverbatim]
\frametitle{One-sided t-test}
Since ``B'' is a placebo, the one-sided t-test may be more appropriate
to test the treatment effect:
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# data from treatment A and B}
\hlstd{diff.A} \hlkwb{<-} \hlstd{dbp}\hlopt{$}\hlstd{diff[dbp}\hlopt{$}\hlstd{TRT}\hlopt{==}\hlstr{'A'}\hlstd{]}
\hlstd{diff.B} \hlkwb{<-} \hlstd{dbp}\hlopt{$}\hlstd{diff[dbp}\hlopt{$}\hlstd{TRT}\hlopt{==}\hlstr{'B'}\hlstd{]}
\hlcom{# call t.test for one-sided test}
\hlkwd{t.test}\hlstd{(diff.A, diff.B,} \hlkwc{alternative}\hlstd{=}\hlstr{"less"}\hlstd{)}
\end{alltt}
\begin{verbatim}
##
## Welch Two Sample t-test
##
## data: diff.A and diff.B
## t = -12.15, df = 36.522, p-value = 1.074e-14
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
## -Inf -8.955466
## sample estimates:
## mean of x mean of y
## -15.2 -4.8
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\subsection{ANOVA}
\begin{frame}[t]
\frametitle{One-way ANOVA}
The single factor $A$ has $k$ levels: $A_1, A_2, \dots, A_r$, and $k$ patients are allocated to
each treatment group. We can obtain the samples:
$$
y_{i1}, \dots, y_{in}, i=1, \dots, k
$$
\uncover<2->{\begin{block}{\center Fundamental statistics}
\footnotesize
\begin{itemize}
\item<3-> Grand mean: $\bar{y}_{*} = \frac{1}{kn}\sum_{i=1}^k \sum_{j=1}^n y_{ij}$
\item<3-> Marginal mean: $\bar{y}_i = \frac{1}{n}\sum_{j=1}^n y_{ij}$;
\item<4-> Total sum of squares (SST): $\mathrm{SS}_T = \sum_{i=1}^k \sum_{j=1}^n (y_{ij} - \bar{y}_*)^2$;
\item<4-> Between-group sum of squares (SSB): $\mathrm{SS}_B = \sum_{i=1}^k (\bar{y}_i - \bar{y}_*)^2$;
\item<4-> Resitual sum of squares (SSE): $\mathrm{SS}_E = \sum_{i=1}^k \sum_{j=1}^n (y_{ij} - \bar{y}_i)^2$;
\end{itemize}
\end{block}
}
\end{frame}
\begin{frame}[t]
\frametitle{One-way ANOVA Table}
\begin{table}
\caption{One-way ANOVA Table with $k$ groups and $n$ subjects}
\begin{tabular}{lcccc}
\hline
Variance & $\textrm{SS}$ & $\textrm{DF}$ & $\textrm{MS}$ & $F$-value\\
\hline
Between-groups & $\textrm{SS}_b$ & $k-1$ & $\textrm{MS}_b$ & $F = \textrm{MS}_b/\textrm{MS}_w$\\
Within-groups & $\textrm{SS}_w$ & $n-k$ & $\textrm{MS}_w$ & \\
Total & $\textrm{SS}_T$ & $n-1$ & $\textrm{MS}_T$ & \\
\hline
\end{tabular}
\end{table}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{One-way ANOVA for Time Changes}
Since the treatment period in the DBP trial was measured at months 1,
2, 3 and 4 post baseline. To see the mean changes over the periods:
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{aggregate}\hlstd{(dbp[,}\hlnum{3}\hlopt{:}\hlnum{7}\hlstd{],} \hlkwd{list}\hlstd{(}\hlkwc{TRT}\hlstd{=dbp}\hlopt{$}\hlstd{TRT), mean)}
\end{alltt}
\begin{verbatim}
## TRT DBP1 DBP2 DBP3 DBP4 DBP5
## 1 A 116.55 113.5 110.70 106.25 101.35
## 2 B 116.75 115.2 114.05 112.45 111.95
\end{verbatim}
\end{kframe}
\end{knitrout}
Now we can employ the one-way ANOVA to test the change over time. But the first thing is to ``reshape'' the data:
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{Dbp} \hlkwb{<-} \hlkwd{reshape}\hlstd{(dbp,} \hlkwc{direction}\hlstd{=}\hlstr{"long"}\hlstd{,}
\hlkwc{varying}\hlstd{=}\hlkwd{paste}\hlstd{(}\hlstr{"DBP"}\hlstd{,} \hlnum{1}\hlopt{:}\hlnum{5}\hlstd{,} \hlkwc{sep}\hlstd{=}\hlstr{""}\hlstd{),}
\hlkwc{idvar} \hlstd{=} \hlkwd{c}\hlstd{(}\hlstr{"Subject"}\hlstd{,} \hlstr{"TRT"}\hlstd{,} \hlstr{"Age"}\hlstd{,} \hlstr{"Sex"}\hlstd{,} \hlstr{"diff"}\hlstd{),} \hlkwc{sep}\hlstd{=}\hlstr{""}\hlstd{)}
\hlkwd{colnames}\hlstd{(Dbp)} \hlkwb{<-} \hlkwd{c}\hlstd{(}\hlstr{"Subject"}\hlstd{,} \hlstr{"TRT"}\hlstd{,} \hlstr{"Age"}\hlstd{,} \hlstr{"Sex"}\hlstd{,} \hlstr{"diff"}\hlstd{,} \hlstr{"Time"}\hlstd{,} \hlstr{"DBP"}\hlstd{)}
\hlkwd{rownames}\hlstd{(Dbp)} \hlkwb{<-} \hlkwa{NULL}
\hlstd{Dbp}\hlopt{$}\hlstd{Time} \hlkwb{<-} \hlkwd{as.factor}\hlstd{(Dbp}\hlopt{$}\hlstd{Time)}
\hlkwd{head}\hlstd{(Dbp,} \hlnum{3}\hlstd{)}
\end{alltt}
\begin{verbatim}
## Subject TRT Age Sex diff Time DBP
## 1 1 A 43 F -9 1 114
## 2 2 A 51 M -15 1 116
## 3 3 A 48 F -21 1 119
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{One-way ANOVA for Two Treatments}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# test for treatment A}
\hlstd{dbpA} \hlkwb{<-} \hlstd{Dbp[Dbp}\hlopt{$}\hlstd{TRT}\hlopt{==}\hlstr{'A'}\hlstd{,]}
\hlstd{test.A} \hlkwb{<-} \hlkwd{aov}\hlstd{(DBP} \hlopt{~} \hlstd{Time, dbpA)}
\hlkwd{summary}\hlstd{(test.A)}
\end{alltt}
\begin{verbatim}
## Df Sum Sq Mean Sq F value Pr(>F)
## Time 4 2879.7 719.9 127 <2e-16 ***
## Residuals 95 538.5 5.7
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# test for treatment B}
\hlstd{dbpB} \hlkwb{<-} \hlstd{Dbp[Dbp}\hlopt{$}\hlstd{TRT}\hlopt{==}\hlstr{'B'}\hlstd{, ]}
\hlstd{test.B} \hlkwb{<-} \hlkwd{aov}\hlstd{(DBP} \hlopt{~} \hlstd{Time, dbpB)}
\hlkwd{summary}\hlstd{(test.B)}
\end{alltt}
\begin{verbatim}
## Df Sum Sq Mean Sq F value Pr(>F)
## Time 4 311.6 77.89 17.63 7.5e-11 ***
## Residuals 95 419.8 4.42
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Post-hoc Tests for ANOVA of treatment A}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{TukeyHSD}\hlstd{(test.A)}
\end{alltt}
\begin{verbatim}
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = DBP ~ Time, data = dbpA)
##
## $Time
## diff lwr upr p adj
## 2-1 -3.05 -5.143586 -0.9564144 0.0009687
## 3-1 -5.85 -7.943586 -3.7564144 0.0000000
## 4-1 -10.30 -12.393586 -8.2064144 0.0000000
## 5-1 -15.20 -17.293586 -13.1064144 0.0000000
## 3-2 -2.80 -4.893586 -0.7064144 0.0030529
## 4-2 -7.25 -9.343586 -5.1564144 0.0000000
## 5-2 -12.15 -14.243586 -10.0564144 0.0000000
## 4-3 -4.45 -6.543586 -2.3564144 0.0000005
## 5-3 -9.35 -11.443586 -7.2564144 0.0000000
## 5-4 -4.90 -6.993586 -2.8064144 0.0000000
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Post-hoc Tests for ANOVA of treatment B}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{TukeyHSD}\hlstd{(test.B)}
\end{alltt}
\begin{verbatim}
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = DBP ~ Time, data = dbpB)
##
## $Time
## diff lwr upr p adj
## 2-1 -1.55 -3.398584 0.2985843 0.1440046
## 3-1 -2.70 -4.548584 -0.8514157 0.0009333
## 4-1 -4.30 -6.148584 -2.4514157 0.0000000
## 5-1 -4.80 -6.648584 -2.9514157 0.0000000
## 3-2 -1.15 -2.998584 0.6985843 0.4207789
## 4-2 -2.75 -4.598584 -0.9014157 0.0007122
## 5-2 -3.25 -5.098584 -1.4014157 0.0000400
## 4-3 -1.60 -3.448584 0.2485843 0.1223788
## 5-3 -2.10 -3.948584 -0.2514157 0.0176793
## 5-4 -0.50 -2.348584 1.3485843 0.9433857
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Two-way ANOVA With Interaction}
The DBP trial has two factors: treatment and Time. Under this
situation, one-way ANOVA (within treatment groups across Time)
cannot capture the interaction between these two factors.
Therefore, a two-way or multi-way ANOVA is needed to analyze the
interaction before making statistical inferences about the main
effects.
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlstd{mod} \hlkwb{<-} \hlkwd{aov}\hlstd{(DBP} \hlopt{~} \hlstd{TRT}\hlopt{*}\hlstd{Time, Dbp)}
\hlkwd{summary}\hlstd{(mod)}
\end{alltt}
\begin{verbatim}
## Df Sum Sq Mean Sq F value Pr(>F)
## TRT 1 972.4 972.4 192.81 <2e-16 ***
## Time 4 2514.1 628.5 124.62 <2e-16 ***
## TRT:Time 4 677.1 169.3 33.56 <2e-16 ***
## Residuals 190 958.3 5.0
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Plot Interaction Between Time and Treatment}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{par}\hlstd{(}\hlkwc{mfrow}\hlstd{=}\hlkwd{c}\hlstd{(}\hlnum{2}\hlstd{,}\hlnum{1}\hlstd{),} \hlkwc{mar}\hlstd{=}\hlkwd{c}\hlstd{(}\hlnum{5}\hlstd{,}\hlnum{3}\hlstd{,}\hlnum{1}\hlstd{,}\hlnum{1}\hlstd{))}
\hlkwd{with}\hlstd{(Dbp,} \hlkwd{interaction.plot}\hlstd{(Time,TRT,DBP,}\hlkwc{las}\hlstd{=}\hlnum{1}\hlstd{,}\hlkwc{legend}\hlstd{=T))}
\hlkwd{with}\hlstd{(Dbp,} \hlkwd{interaction.plot}\hlstd{(TRT,Time,DBP,}\hlkwc{las}\hlstd{=}\hlnum{1}\hlstd{,}\hlkwc{legend}\hlstd{=T))}
\end{alltt}
\end{kframe}
{\centering \includegraphics[width=0.60\textwidth]{figure/beamer-unnamed-chunk-15-1}
}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Post-Hoc Analysis}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlkwd{TukeyHSD}\hlstd{(}\hlkwd{aov}\hlstd{(DBP} \hlopt{~} \hlstd{TRT}\hlopt{*}\hlstd{Time, Dbp))}
\end{alltt}
\begin{verbatim}
## Tukey multiple comparisons of means
## 95% family-wise confidence level
##
## Fit: aov(formula = DBP ~ TRT * Time, data = Dbp)
##
## $TRT
## diff lwr upr p adj
## B-A 4.41 3.783529 5.036471 0
##
## $Time
## diff lwr upr p adj
## 2-1 -2.300 -3.683042 -0.9169576 0.0000816
## 3-1 -4.275 -5.658042 -2.8919576 0.0000000
## 4-1 -7.300 -8.683042 -5.9169576 0.0000000
## 5-1 -10.000 -11.383042 -8.6169576 0.0000000
## 3-2 -1.975 -3.358042 -0.5919576 0.0011017
## 4-2 -5.000 -6.383042 -3.6169576 0.0000000
## 5-2 -7.700 -9.083042 -6.3169576 0.0000000
## 4-3 -3.025 -4.408042 -1.6419576 0.0000001
## 5-3 -5.725 -7.108042 -4.3419576 0.0000000
## 5-4 -2.700 -4.083042 -1.3169576 0.0000022
##
## $`TRT:Time`
## diff lwr upr p adj
## B:1-A:1 0.20 -2.0737649 2.4737649 0.9999998
## A:2-A:1 -3.05 -5.3237649 -0.7762351 0.0011351
## B:2-A:1 -1.35 -3.6237649 0.9237649 0.6684315
## A:3-A:1 -5.85 -8.1237649 -3.5762351 0.0000000
## B:3-A:1 -2.50 -4.7737649 -0.2262351 0.0188264
## A:4-A:1 -10.30 -12.5737649 -8.0262351 0.0000000
## B:4-A:1 -4.10 -6.3737649 -1.8262351 0.0000014
## A:5-A:1 -15.20 -17.4737649 -12.9262351 0.0000000
## B:5-A:1 -4.60 -6.8737649 -2.3262351 0.0000000
## A:2-B:1 -3.25 -5.5237649 -0.9762351 0.0003579
## B:2-B:1 -1.55 -3.8237649 0.7237649 0.4723958
## A:3-B:1 -6.05 -8.3237649 -3.7762351 0.0000000
## B:3-B:1 -2.70 -4.9737649 -0.4262351 0.0072480
## A:4-B:1 -10.50 -12.7737649 -8.2262351 0.0000000
## B:4-B:1 -4.30 -6.5737649 -2.0262351 0.0000003
## A:5-B:1 -15.40 -17.6737649 -13.1262351 0.0000000
## B:5-B:1 -4.80 -7.0737649 -2.5262351 0.0000000
## B:2-A:2 1.70 -0.5737649 3.9737649 0.3355035
## A:3-A:2 -2.80 -5.0737649 -0.5262351 0.0043660
## B:3-A:2 0.55 -1.7237649 2.8237649 0.9988534
## A:4-A:2 -7.25 -9.5237649 -4.9762351 0.0000000
## B:4-A:2 -1.05 -3.3237649 1.2237649 0.8990806
## A:5-A:2 -12.15 -14.4237649 -9.8762351 0.0000000
## B:5-A:2 -1.55 -3.8237649 0.7237649 0.4723958
## A:3-B:2 -4.50 -6.7737649 -2.2262351 0.0000001
## B:3-B:2 -1.15 -3.4237649 1.1237649 0.8372192
## A:4-B:2 -8.95 -11.2237649 -6.6762351 0.0000000
## B:4-B:2 -2.75 -5.0237649 -0.4762351 0.0056388
## A:5-B:2 -13.85 -16.1237649 -11.5762351 0.0000000
## B:5-B:2 -3.25 -5.5237649 -0.9762351 0.0003579
## B:3-A:3 3.35 1.0762351 5.6237649 0.0001963
## A:4-A:3 -4.45 -6.7237649 -2.1762351 0.0000001
## B:4-A:3 1.75 -0.5237649 4.0237649 0.2948066
## A:5-A:3 -9.35 -11.6237649 -7.0762351 0.0000000
## B:5-A:3 1.25 -1.0237649 3.5237649 0.7590918
## A:4-B:3 -7.80 -10.0737649 -5.5262351 0.0000000
## B:4-B:3 -1.60 -3.8737649 0.6737649 0.4247400
## A:5-B:3 -12.70 -14.9737649 -10.4262351 0.0000000
## B:5-B:3 -2.10 -4.3737649 0.1737649 0.0975920
## B:4-A:4 6.20 3.9262351 8.4737649 0.0000000
## A:5-A:4 -4.90 -7.1737649 -2.6262351 0.0000000
## B:5-A:4 5.70 3.4262351 7.9737649 0.0000000
## A:5-B:4 -11.10 -13.3737649 -8.8262351 0.0000000
## B:5-B:4 -0.50 -2.7737649 1.7737649 0.9994658
## B:5-A:5 10.60 8.3262351 12.8737649 0.0000000
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\subsection{ANCOVA}
\begin{frame}[t]
\frametitle{What is Analysis of Covariance (ANCOVA)?}
\begin{itemize}[<+->]
\item One-way/two-way/Multi-way ANOVA with uncontrollable but measurable
independent variable $X$;
\item The outcome $Y$ is continuous;
\item $Y$ and $X$ (covariate) has linear relationship;
\item Regression analysis is used to adjust for the effect of $X$ on $Y$.
\item Here we does not control for $X$ in the trials, but conduct a post-hoc
analysis.
\end{itemize}
\uncover<6->{
\begin{alertblock}{\center Example}
\begin{itemize}
\item Initial blood pressure ($X$) for the BP reductions ($Y$) in comparing different
blood pressure medications ($G$).
\item Parallel-group clinical trials with pre-treatment baselines.
\end{itemize}
\end{alertblock}
}
\end{frame}
\begin{frame}[t]
\frametitle{One-way ANCOVA}
The single factor $A$ has $r$ levels: $A_1, A_2, \dots, A_r$, and $s$ patients are allocated to
each treatment group. We can obtain the samples:
$$
(x_{i1}, y_{i1}), \dots, (x_{is}, y_{is}), i=1, \dots, r
$$
\uncover<2->{\begin{block}{\center Fundamental statistics}
\footnotesize
\begin{itemize}
\item<3-> $\bar{x}_{i*} = \frac{1}{s}\sum_{j=1}^s x_{ij}; \bar{x}_{**} = \frac{1}{rs}\sum_{i=1}^r \sum_{j=1}^s x_{ij}$
\item<3-> $\bar{y}_{i*} = \frac{1}{s}\sum_{j=1}^s y_{ij}; \bar{y}_{**} = \frac{1}{rs}\sum_{i=1}^r \sum_{j=1}^s y_{ij}$
\item<4-> $\mathrm{SST}(x) = \sum_{i=1}^r \sum_{j=1}^s (x_{ij} - x_{**})^2$;
\item<4-> $\mathrm{SSA}(x) = \sum_{i=1}^r (x_{i*} - x_{**})^2$;
\item<4-> $\mathrm{SSE}(x) = \sum_{i=1}^r \sum_{j=1}^s (x_{ij} - x_{i*})^2$;
\item<5-> $\mathrm{SST}(y) = \sum_{i=1}^r \sum_{j=1}^s (y_{ij} - y_{**})^2$;
\item<5-> $\mathrm{SSA}(y) = \sum_{i=1}^r (y_{i*} - y_{**})^2$;
\item<5-> $\mathrm{SSE}(y) = \sum_{i=1}^r \sum_{j=1}^s (y_{ij} - y_{i*})^2$;
\item<6-> $\mathrm{SPT} = \sum_{i=1}^r \sum_{j=1}^s (x_{ij}-x_{**})(y_{ij}-y_{**})^2$;
\item<6-> $\mathrm{SPA} = \sum_{i=1}^r (x_{i*} - x_{**})(y_{i*} - y_{**})$;
\item<6-> $\mathrm{SPE} = \sum_{i=1}^r \sum_{j=1}^s (x_{ij}-x_{i*})(y_{ij} - y_{i*})$.
\end{itemize}
\end{block}
}
\end{frame}
\begin{frame}[t]
\frametitle{One-way ANCOVA: Procedure}
\begin{enumerate}[<+->]
\item Compute the above statistics and group them into a table:
\begin{table}
\footnotesize
\begin{tabular}{l|c|c|c|c}
\hline
Variance & $\textrm{SS}(x)$ & $\textrm{SS}(y)$ & $\textrm{SP}$ & $\textrm{DF}$\\
\hline
inter-group & $\textrm{SSA}(x)$ & $\textrm{SSA}(y)$ & $\textrm{SPA}$ & $r-1$\\
intra-group & $\textrm{SSE}(x)$ & $\textrm{SSE}(y)$ & $\textrm{SPE}$ & $r(s-1)$\\
Total & $\textrm{SST}(x)$ & $\textrm{SST}(y)$ & $\textrm{SPT}$ & $rs-1$\\
\hline
\end{tabular}
\end{table}
\item Compute the intra-group regresson coefficient $\beta = \frac{\textrm{SPE}}{\textrm{SSE}(x)}$;
\item If significant, adjust for the linear regression:
$$
\bar{y}_{i*}(x = \bar{x}_{**}) = \bar{y}_{i*} - \beta(\bar{x}_{i*} - \bar{x}_{**})
$$
\item $Q_E = \textrm{SSE}(y) - \frac{(\textrm{SPE})^2}{\textrm{SSE}(x)}$;
\item $Q_T = \textrm{SST}(y) - \frac{(\textrm{SPT})^2}{\textrm{SST}(x)}$;
\item $Q_A = Q_T - Q_E$;
\item $MQ_A = \frac{Q_A}{r-1}$; $MQ_E = \frac{Q_E}{r(s-1)}$
\item $F=\frac{MQ_A}{MQ_E} \sim F_{r-1, r(s-1)-1}$
\end{enumerate}
\end{frame}
\begin{frame}[t]
\frametitle{One-way ANCOVA: Procedure}
\uncover<1->{\begin{table}
\footnotesize
\begin{tabular}{l|c|c|c|c}
\hline
Variance & $\textrm{SS}(x)$ & $\textrm{SS}(y)$ & $\textrm{SP}$ & $\textrm{DF}$\\
\hline
inter-group & $\textrm{SSA}(x)$ & $\textrm{SSA}(y)$ & $\textrm{SPA}$ & $r-1$\\
intra-group & $\textrm{SSE}(x)$ & $\textrm{SSE}(y)$ & $\textrm{SPE}$ & $r(s-1)$\\
Total & $\textrm{SST}(x)$ & $\textrm{SST}(y)$ & $\textrm{SPT}$ & $rs-1$\\
\hline
\end{tabular}
\end{table}}
\uncover<2->{
\alert{\begin{center} $\Downarrow$ \end{center}}
}
\uncover<3->{\begin{table}
\footnotesize
\caption{Adjusted ANCOVA Table}
\begin{tabular}{l|c|c|c|c|c}
\hline
Variance & $\textrm{SS}$ & $\textrm{DF}$ & $\textrm{MSS}$ & $\textrm{F}$ & Significance\\
\hline
inter-group & $Q_A$ & $r-1$ & $MQ_A$ & $F$ & \\
intra-group & $Q_E$ & $r(s-1)-1$ & $MQ_E$ & & \\
Total & $Q_T$ & $rs-2$ & & & \\
\hline
\end{tabular}
\end{table}}
\uncover<4->{\begin{alertblock}{\center Conclusion}
\end{alertblock}}
\end{frame}
\begin{frame}[t]
\frametitle{Two-way ANCOVA: No Interaction}
\begin{itemize}[<+->]
\item Two factors $A: A_1, \dots, A_r$ and $B: B_1, \dots, B_s$;
\item Continuous covariate $X$;
\item Continuous outcome $Y$;
\end{itemize}
\uncover<4->{\begin{table}
\footnotesize
\caption{Adjusted ANCOVA Table Without Interaction}
\begin{tabular}{l|c|c|c|c|c}
\hline
Variance & $\textrm{SS}$ & $\textrm{DF}$ & $\textrm{MSS}$ & $\textrm{F}$ & Significance\\
\hline
inter-A & $Q_A$ & $r-1$ & $MQ_A$ & $F_A$ & \\
inter-B & $Q_B$ & $s-1$ & $MQ_B$ & $F_B$ & \\
intra-group & $Q_E$ & $(r-1)(s-1)-1$ & $MQ_E$ & & \\
Total & $Q_T$ & $rs-2$ & & & \\
\hline
\end{tabular}
\end{table}}
\end{frame}
\begin{frame}[t]
\frametitle{Two-way ANCOVA: With Interaction}
\begin{itemize}[<+->]
\item Two factors $A: A_1, \dots, A_r$ and $B: B_1, \dots, B_s$;
\item Continuous covariate $X$;
\item Continuous outcome $Y$;
\item Each cell with $m$ observations.
\end{itemize}
\uncover<5->{\begin{table}
\footnotesize
\caption{Adjusted ANCOVA Table With Interaction}
\begin{tabular}{l|c|c|c|c|c}
\hline
Variance & $\textrm{SS}$ & $\textrm{DF}$ & $\textrm{MSS}$ & $\textrm{F}$ & Significance\\
\hline
inter-A & $Q_A$ & $r-1$ & $MQ_A$ & $F_A$ & \\
inter-B & $Q_B$ & $s-1$ & $MQ_B$ & $F_B$ & \\
inter-AB & $Q_{AB}$ & $(r-1)(s-1)$ & $MQ_{AB}$ & $F_{AB}$ & \\
intra-group & $Q_E$ & $rs(m-1)-1$ & $MQ_E$ & & \\
Total & $Q_T$ & $rsm-2$ & & & \\
\hline
\end{tabular}
\end{table}}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{Analysis of DBP Change from Baseline with ANCOVA}
\begin{itemize}
\item We now analyze the change from baseline in DBP at the
end of trial which is defined as ``diff''.
\item We start from the full model containing all
``covariates''.
\item Perform backward stepwise model selection to simplify
the model:
\end{itemize}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# start with the full model}
\hlstd{m0} \hlkwb{<-} \hlkwd{lm}\hlstd{(diff} \hlopt{~} \hlstd{TRT}\hlopt{*}\hlstd{Age}\hlopt{*}\hlstd{Sex, dbp)}
\hlcom{# stepwise model selection}
\hlstd{m1} \hlkwb{=} \hlkwd{step}\hlstd{(m0)}
\end{alltt}
\begin{verbatim}
## Start: AIC=79.52
## diff ~ TRT * Age * Sex
##
## Df Sum of Sq RSS AIC
## - TRT:Age:Sex 1 2.7059 198.47 78.07
## <none> 195.76 79.52
##
## Step: AIC=78.07
## diff ~ TRT + Age + Sex + TRT:Age + TRT:Sex + Age:Sex
##
## Df Sum of Sq RSS AIC
## - TRT:Sex 1 1.3256 199.79 76.336
## - TRT:Age 1 9.5638 208.03 77.952
## <none> 198.47 78.070
## - Age:Sex 1 17.0694 215.53 79.370
##
## Step: AIC=76.34
## diff ~ TRT + Age + Sex + TRT:Age + Age:Sex
##
## Df Sum of Sq RSS AIC
## <none> 199.79 76.336
## - TRT:Age 1 10.272 210.06 76.341
## - Age:Sex 1 16.164 215.96 77.448
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\begin{frame}[t,containsverbatim]
\frametitle{ANCOVA Analysis of the Changes from Baseline}
\begin{knitrout}\footnotesize
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{alltt}
\hlcom{# fit the reduced model}
\hlstd{m2} \hlkwb{<-} \hlkwd{lm}\hlstd{(diff} \hlopt{~} \hlstd{TRT} \hlopt{+} \hlstd{Age, dbp)}
\hlcom{# output the anova result}
\hlkwd{anova}\hlstd{(m2)}
\end{alltt}
\begin{verbatim}
## Analysis of Variance Table
##
## Response: diff
## Df Sum Sq Mean Sq F value Pr(>F)
## TRT 1 1081.60 1081.60 176.0395 1.228e-15 ***
## Age 1 51.07 51.07 8.3119 0.006525 **
## Residuals 37 227.33 6.14
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
\subsection{Repeated Measure ANOVA}
\begin{frame}[t]
\frametitle{What is repeated-measure ANOVA?}
\begin{itemize}
\item<1-> The equivalent of the one-way ANOVA for correlated/non-independent groups
\begin{itemize}
\item Extension of paired $t$-test;
\item Within-subjects ANOVA;
\item ANOVA for correlated samples;
\end{itemize}
\item<2-> Here we only consider the one-way repeated measure ANOVA:
\begin{itemize}
\item One independent categorical variable (nominal or ordinal)
\item One continuous dependent variable (interval or ratio)
\end{itemize}
\end{itemize}
\only<2>{\begin{figure}
\includegraphics[width=0.50\textwidth]{images/repanova-time.png}
\end{figure}}
\only<3>{\begin{figure}
\includegraphics[width=0.50\textwidth]{images/repanova-treatment.png}
\end{figure}}
\uncover<4->{\begin{alertblock}{\center When to use repeated-measure ANOVA?}
\begin{itemize}
\item Changes in mean scores over three or more time points;
\item Differences in mean scores under three or more different conditions.
\end{itemize}
\end{alertblock}}
\end{frame}
\begin{frame}[t]
\frametitle{Logics of Repeated Measures ANOVA}
\begin{itemize}
\item<1-> ANOVA partitions total variability ($\textrm{SS}_T$) into between-groups
variability ($\textrm{SS}_b$) and within-groups variability ($\textrm{SS}_w$)
\item<2-> Within-group variability ($\textrm{SS}_w$) is defined as the error variability
($\textrm{SS}_{error}$).
\item<3-> Mean sum of squares for between-groups ($\textrm{MS}_w$) and within-groups
($\textrm{MS}_w$)
\item<4-> \alert{Independent ANOVA: $F = \frac{\textrm{MS}_b}{\textrm{MS}_w} = \frac{\textrm{MS}_b}{\textrm{MS}_{error}}$}
\item<5-> \alert{Repeated measures ANOVA: $F = \frac{\textrm{MS}_b}{\textrm{MS}_w} = \frac{\textrm{MS}_{condition}}{\textrm{MS}_{error}}$}
\item<6-> $\textrm{SS}_{error} = \textrm{SS}_w - \text{SS}_{subject} = \textrm{SS}_T - \textrm{SS}_{condition} - \textrm{SS}_{subject}$
\item<7-> $\textrm{MS}_{error} = \textrm{SS}_{error}/(k-1)(n-1)$, where $k$ is the numer of groups (time points or treatments), and $n$ is
the number of subjects.
\item<8> $\textrm{SS}_{subject} = k \times \sum_{i=1}^n (\bar{x}_i - \bar{x})^2$, where $\bar{x}_i$ is the mean for subject $i$.
\end{itemize}
\only<4>{
\begin{figure}
\includegraphics[width=0.6\textwidth]{images/anova-partition-ss-ind.png}