-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathMedicalStatisticsSummary.Rnw
4214 lines (3036 loc) · 103 KB
/
MedicalStatisticsSummary.Rnw
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[12pt]{article}
%\usepackage[landscape]{geometry}
\usepackage[landscape,hmargin=2cm,vmargin=1.5cm,headsep=0cm]{geometry}
% See geometry.pdf to learn the layout options. There are lots.
\geometry{a4paper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for for rotated page geometry
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{multicol}
\usepackage{framed}
\usepackage{blkarray}
\usepackage{multirow}
\usepackage{cancel}
\usepackage{tabu}
\usepackage[table]{xcolor}
\newcommand\x{\times}
\newcommand\y{\cellcolor{green!10}}
\newcommand{\pder}[2][]{\frac{\partial#1}{\partial#2}}
\newcommand{\argmin}{\arg\!\min}
\newcommand{\argmax}{\arg\!\max}
\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{fact}{Fact}
\newtheorem{proposition}{Proposition}
% Turn off header and footer
\pagestyle{plain}
% Redefine section commands to use less space
\makeatletter
\renewcommand{\section}{\@startsection{section}{1}{0mm}%
{-1ex plus -.5ex minus -.2ex}%
{0.5ex plus .2ex}%x
{\normalfont\large\bfseries}}
\renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}%
{-1explus -.5ex minus -.2ex}%
{0.5ex plus .2ex}%
{\normalfont\normalsize\bfseries}}
\renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}%
{-1ex plus -.5ex minus -.2ex}%
{1ex plus .2ex}%
{\normalfont\small\bfseries}}
\makeatother
% Define BibTeX command
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
% Don't print section numbers
%\setcounter{secnumdepth}{0}
\setlength{\parindent}{0pt}
\setlength{\parskip}{0pt plus 0.5ex}
\usepackage{Sweave}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
%% taken from http://brunoj.wordpress.com/2009/10/08/latex-the-framed-minipage/
\newsavebox{\fmbox}
\newenvironment{fmpage}[1]
{\begin{lrbox}{\fmbox}\begin{minipage}{#1}}
{\end{minipage}\end{lrbox}\fbox{\usebox{\fmbox}}}
\usepackage{mathtools}
\makeatletter
\newcommand{\explain}[2]{\underset{\mathclap{\overset{\uparrow}{#2}}}{#1}}
\newcommand{\explainup}[2]{\overset{\mathclap{\underset{\downarrow}{#2}}}{#1}}
\makeatother
%\SweaveOpts{prefix.string=MedStatfigs/MedStatfig}
\SweaveOpts{cache=TRUE}
\title{Medical Statistics Summary Sheet}
\author{Shravan Vasishth ([email protected])}
%\date{} % Activate to display a given date or no date
\usepackage{float}
\setkeys{Gin}{width=0.25\textwidth}
\begin{document}
\SweaveOpts{concordance=TRUE}
\footnotesize
\maketitle
\tableofcontents
\newpage
\begin{multicols}{2}
% multicol parameters
% These lengths are set only within the two main columns
%\setlength{\columnseprule}{0.25pt}
\setlength{\premulticols}{1pt}
\setlength{\postmulticols}{1pt}
\setlength{\multicolsep}{1pt}
\setlength{\columnsep}{2pt}
\begin{center}
\normalsize{Medical Statistics Summary Sheet} \\
\footnotesize{
Compiled by: Shravan Vasishth ([email protected])\\
Version dated: \today}
\end{center}
<<echo=F>>=
options(width=60)
options(continue=" ")
@
\section{Types of expt designs}
\subsection{Parallel Group Designs}
To compare k treatments,
divide patients, at random, into k groups,
the $n_i$ patients in group $i$ receive treatment $i$. Each patient receives just one treatment. Comparisons are between patients.
$n_i$ not necessarily the same across groups.
\subsection{In Series Designs}
Each patient receives all k treatments in the same order.
Comparisons made within patients.
Problems:
Patients enter when disease is bad, hence likely to improvement regardless of treatment, so later treatments appear better.
Reverse occurs for a progressive disease, i.e. problems occur if underlying disease is not stable.
Advantages
\begin{enumerate}
\item Need fewer patients than parallel designs
\item Patients can state `preferences' between treatments
\item Might be able to allocate treatments simultaneously e.g. skin cream on left and right hands
\end{enumerate}
Disadvantages
\begin{enumerate}
\item
Treatment effect might depend on when it is given
\item Treatment effect may persist into subsequent periods
and mask/modify effects of later treatments
\item Withdrawals cause problems (i.e. if a patient leaves
before trying all treatments)
\item Not universally applicable, e.g. drug treatment
compared with surgery
\item Can only use for short term effects
\end{enumerate}
\subsection{Crossover trials}
Period, Treatment and Period:Treatment (Carrover) effects
\begin{enumerate}
\item
All patients get all treatments but in different orders.
\item
Period and Carryover effects are nuisance variables, the main interest is in Treatment effects.
\end{enumerate}
\subsection{Factorial designs}
\textbf{Interactions}:
(a) quantitative interaction: what we call additive.
(b) qualitative interaction: what we call cross-over interaction.
\subsection{Sequential designs}
to-do: need to look this up.
Advantages
\begin{enumerate}
\item
Detect large differences quickly
\item
Avoids ethical problem of fixed size designs (no patient
should receive treatment known to be inferior)
\end{enumerate}
Disadvantages
\begin{enumerate}
\item
Responses needed quickly (before next pair arrive)
\item
Drop-outs cause difficulties
\item
Constant surveillance necessary
\item Requires pairing of patients
\item Calculation of boundaries highly complex
\end{enumerate}
\section{Per protocol vs intention to treat analyses}
Per protocol: only analyze patients who conform to original protocol
Intention to treat: analyze all data, including dropouts etc. (This has lower risk of bias).
\section{Randomization}
Randomization protects against accidental and selection bias, and provides a basis for statistical tests
Types of randomization include
\begin{enumerate}
\item
simple (but may be unbalanced over treatments)
\item
blocked (but small blocks may be decoded)
\item
stratified (but may require small blocks)
\item
minimization (but lessens randomness)
\end{enumerate}
\section{Sample size calculations}
\subsection{Two sample}
\paragraph{Binomial}
\textbf{Note: n is each arm}
\begin{equation}
n \approx \frac{\theta_1(1-\theta_1) + \theta_2(1-\theta_2)}{(\theta_2-\theta_1)^2}[\Phi^{-1}(\beta) + \Phi(\alpha/2)]^2
\end{equation}
\paragraph{Continuous}
\textbf{Note: n is each arm}
\begin{equation}
n \approx \frac{2\sigma^2}{(\mu_1-\mu_2)^2}[\Phi^{-1}(\beta) + \Phi(\alpha/2)]^2
\end{equation}
\subsection{One sample}
\paragraph{Binomial}
\begin{equation}
n \approx
\frac{[\Phi^{-1}(\beta)
\sqrt{\theta(1-\theta)} +
\Phi^{-1}(\alpha/2)
\sqrt{\theta_0(1-\theta_0)}
]^2}{(\theta-\theta_0)^2}
\end{equation}
\paragraph{Continuous}
\begin{equation}
n \approx \frac{\sigma^2}{(\mu-\mu_0)^2}
[\Phi^{-1}(\beta)+\Phi^{-1}(\alpha/2)]^2
\end{equation}
\subsection{Computation for patients lost during testing}
Let t be target, p be percent of loss, n the final recruitment number.
\begin{equation}
t - \frac{p}{100}t = n
\end{equation}
\section{Multiple testing}
If we do k indep tests, and compute p-values at $\alpha=0.05$ then actual p-value is $k\times p$.
Corrections:
\begin{enumerate}
\item Bonferroni
\item choose primary outcome measure \textbf{in advance}
\item multivariate analysis
\end{enumerate}
Sequential testing: see p.\ 71.
\section{Combining trials (meta-analysis)}
\subsection{Mantel-Haenszel test}
Assume a data format as follows:
\begin{tabular}{c|ccc}
& \multicolumn{2}{c}{heart problems} & \\
\hline
glucose: & yes & no & Total\\
elevated & $Y_1$ & $n_1 - Y_1$ & $n_1$ \\
not elevated& $Y_2$ & $n_2 - Y_2$ & $n_2$ \\
\hline
Total & $t$ & $n-t$ & $n$\\
\end{tabular}
For each study we can compute the mean and variance using the formulas from the lecture notes:
\begin{equation}
E[Y]_1=\frac{n_1 t}{n} \quad Var(Y_1) = \frac{n_1 n_2 t(n-t)}{n^2(n-1)}
\end{equation}
Then
\begin{equation}
T_{MH} = \frac{(Y_1 - E[Y_1])^2}{V(Y_1)}\sim \chi_1^2
\end{equation}
\textbf{Combining trials for meta-analysis}:
For j studies, compute
\begin{equation}
W=\sum Y_{1j} \quad E[W] = \sum E[Y_{1j}] \quad V(W) = \sum V(Y_{1j})
\end{equation}
and test:
\begin{equation}
\frac{(W-E[W])^2}{V(W)} \sim \chi_1^2
\end{equation}
\textbf{When is this appropriate?}
This summing up procedure avoids Simpson's paradox (combining studies can give different results than separate analyses, due (inter alia) to sample size differences), but not sure why.
Some notes on MH test:
\begin{enumerate}
\item This test is appropriate when treatment differences are consistent across tables.
\item Logistic regression gives you the same results.
\item ``The Mantel-Haenszel test is simpler if one has just two qualitative prognos- tic factors to adjust for and wishes only to assess significance, not magnitude, of a treatment difference.'' (p.\ 97)
\item
``The logistic approach is more general and can include other covariates, further, it can test whether treatment differ- ences are consistent across tables.'' (p.\ 97)
\item If treatments across trials is inconsistent or if success rates differ markedly.
\item Logistic regression can solve Simpson's paradox because we can include trial effect.
\end{enumerate}
\section{Binary data: RR, OR, and logistic regression}
\subsection{Prospective studies: Relative Risk}
\begin{tabular}{cccc}
& positive & negative & total\\
Exposed & a & b & a+b\\
Not Exp & c & d & c+d\\
\end{tabular}
Then, Relative Risk is
\begin{equation}
\begin{split}
~& RR = \frac{a/(a+b)}{(c/(c+d))} \\
~& \Rightarrow \hbox{ compute } log(RR) \\
\end{split}
\end{equation}
The log-transform is for computing CIs using the normal approximation:
\begin{equation}
\begin{split}
SE(log(RR)) =& \sqrt{\frac{1}{a} - \frac{1}{a+b} + \frac{1}{c} - \frac{1}{c+d}} \\
\Rightarrow& log(RR) \pm 2 SE(log(RR))
\end{split}
\end{equation}
Then exponentiate the interval bounds to get intervals on odds.
\subsection{Retrospective studies: Odds ratios}
\begin{tabular}{ccc}
& Observed cases & Obs.\ controls \\
Exposed & a & b\\
Not Exp & c & d\\
\end{tabular}
Then, the Odds Ratio is:
\begin{equation}
OR = \frac{a/c}{b/d}= \frac{ad}{bc} \Rightarrow log(OR)
\end{equation}
\begin{equation}
SE(log(OR)) =
\sqrt{\frac{1}{a}+\frac{1}{b}+\frac{1}{c}+\frac{1}{a}}
\end{equation}
Compute CIs on log odds, and then exponentiate to get back to odds space.
\subsection{Paired data: McNemar's test}
x= no of mismatched pairs (pairs of 0,1 or pairs of 1,0 cases)
n= total no of mismatched pairs
Suppose we have 15 mismatched pairs, of which 3 are 0,1. Then
the p-value is
$2\times P(X\leq 3)$ using binomial distribution:
$2 \sum_{x=0}^3 {15 \choose x} (\frac{1}{2})^{15}$.
For large n, $\frac{(n_{01}-n_{10})^2}{n_{01}+n_{10}} \sim \chi_1^2$.
\subsection{Logistic regression}
See GLM notes.
\section{Crossover trials}
The response is $Y_{ijk}$ with group (reflecting order) i=1,2; period j=1,2; and patient k=1,2,\dots, 8 in group 1, and k=9,\dots,21 for group 2. Let between patient differences be $\alpha_k \sim N(0,\phi^2)$ and let $\epsilon_{ijk}\sim N(0,\sigma^2)$.
\begin{tabular}{ccl}
group 1 & per 1 & $Y_{11k}= \mu + \alpha_k + \tau_A + \pi_1 + \epsilon_{11k}$ \\
& per 2& $Y_{12k} = \mu + \alpha_k + \tau_B + \pi_2 + \lambda_A+ \epsilon_{12k}$ \\
group 2 & per 1 & $Y_{21k} = \mu + \alpha_k + \tau_B + \pi_1 + \epsilon_{21k}$ \\
& per 2 & $Y_{22k} = \mu + \alpha_k + \tau_A + \pi_2 + \lambda_B+ \epsilon_{22k}$\\
\end{tabular}
\subsection{Testing for carryover effects}
Define the average of group 1 and 2 measurements $T_{1k}$ and $T_{2k}$:
\begin{equation}
\begin{split}
T_{1k}=& \frac{1}{2} (Y_{11k}+Y_{21k})\\
=& \frac{1}{2} (2\mu + \lambda_A + \tau_A+\tau_B + \pi_1 + \pi_2)
\end{split}
\end{equation}
If we constrain $\tau_A+\tau_B=0$, and $\pi_1+\pi_2=0$, the expectation of the above becomes:
\begin{equation}
E[T_{1k}] = \mu+ \frac{1}{2}\lambda_A
\end{equation}
Similarly,
\begin{equation}
E[T_{2k}] = \mu+ \frac{1}{2}\lambda_B
\end{equation}
The variances can be computed as follows:
\begin{equation}
\begin{split}
Var(T_{1k})=& Var(\frac{1}{2} (Y_{11k}+Y_{21k}))\\
=& \frac{1}{4} (Var(Y_{11k}) + Var(Y_{21k})) \\
+& 2\frac{1}{4}Cov(Y_{11k},Y_{21k})\\
=& \frac{1}{4} (\phi^2 + \sigma^2 + \phi^2 + \sigma^2) + \frac{1}{2} \phi^2\\
=& \phi^2 + \frac{1}{2}\sigma^2
\end{split}
\end{equation}
[This comes from $Var(aX+bY)=a^2 Var(X)+b^2Var(Y)+2ab Cov(XY)$.]
So, $T_1k \sim N(\mu+\frac{1}{2}\lambda_A,\phi + \frac{1}{2}\sigma^2)$, and similarly, $T_2k \sim N(\mu+\frac{1}{2}\lambda_B,\phi + \frac{1}{2}\sigma^2)$.
Doing a two-sample t-test comparing $\bar{T}_1, \bar{T}_2$ amounts to determining the carryover effect:
\begin{equation}
\frac{\bar{T}_1-\bar{T}_2}{\sqrt{s_{\bar{T}_1}^2/n_1 + s_{\bar{T}_2}^2/n_2}} \sim t_{min(n_1,n_2)}
\end{equation}
\underline{Using sums}:
alternatively: let sum of each group be $S_1$ and $S_2$, and the sd of the respective sum be sd1, sd2.
\begin{equation}
\frac{S_1 - S_2}{\sqrt{sd1^2/n_1 + sd2^2/n_2}}
\end{equation}
\subsection{Testing for treatment effects}
This is a within patients comparison:
\begin{equation}
D_{ik} = Y_{i1k}-Y_{i2k}
\end{equation}
For group i=1:
\begin{equation}
\begin{split}
D_{1k} =& Y_{11k} - Y_{12k}\\
=& \tau_A-\tau_B + \pi_1-\pi_2
\end{split}
\end{equation}
\begin{equation}
D_{1k} \sim N(\tau_A-\tau_B+\pi_1-\pi_2,2\sigma^2)
\end{equation}
For group i=2:
\begin{equation}
\begin{split}
D_{2k} =& Y_{21k} - Y_{22k}\\
=& \tau_B-\tau_A + \pi_1-\pi_2
\end{split}
\end{equation}
So:
\begin{equation}
D_{2k} \sim N(\tau_B-\tau_A+\pi_1-\pi_2,2\sigma^2)
\end{equation}
If we do $D_{1k}-D_{2k}$ we get
\begin{equation}
\tau_A-\tau_B+\pi_1-\pi_2 - (\tau_B-\tau_A+\pi_1-\pi_2)=
2 \tau_A -2\tau_B = \tau_A-\tau_B
\end{equation}
So the null hypothesis being tested is $\tau_A=\tau_B$.
The test is:
\begin{equation}
\frac{\bar{D}_1 - \bar{D}_2}{
\sqrt{s_{\bar{D}_1}^2/n_1 +
s_{\bar{D}_2}^2/n_2}} \sim t_r
\end{equation}
\subsection{Testing for period effects}
If period effect is identical, then $\bar{D}_1$ (group 1 effect), and $-\bar{D}_2$ will have identical distributions.
If we do $D_{1k}- (-D_{2k})$ we get
\begin{equation}
\begin{split}
~& \tau_A-\tau_B+\pi_1-\pi_2 - (-(\tau_B-\tau_A+\pi_1-\pi_2))=\\
~& \tau_A-\tau_B+\pi_1-\pi_2 + (\tau_B-\tau_A+\pi_1-\pi_2))\\
=& \pi_1-\pi_2 +\pi_1-\pi_2 \\
=& 2\pi_1 - 2\pi_2\\
=& \pi_1 - \pi_2\\
\end{split}
\end{equation}
So the null hypothesis being tested is $\pi_1=\pi_2$. The test statistic is:
\begin{equation}
\frac{\bar{D}_1 - (-\bar{D}_2)}{\sqrt{
s_{\bar{D}_1}^2/n_1 +
s_{\bar{D}_2}^2/n_2
}} \sim t_r
\end{equation}
\textbf{Interpretation}
\begin{enumerate}
\item Check for treatment and period effects only if carrover effect not present.
\item If carryover effect is present, then only analyze first period. Should have used a longer washout period.
\end{enumerate}
\subsection{Carryover effects binary responses: Mainland-Gart test}
Mainland-Gart test: p.\ 90
\begin{enumerate}
\item Count how many cases in group 1 had better outcome in first period (for first period trtmt).
\item Count how many cases in group 2 had better outcome in second period (for the same trmt as in group 1).
\item Make contingency table and do chi-sq test.
\end{enumerate}
Example:
\underline{Observed}:
\begin{tabular}{|c|c|c|c|}
\hline
sequence & first period & second period & total\\
\hline
A$\rightarrow$ B & 9 & 0 & 9\\
B$\rightarrow$ A & 1 & 6 & 7\\
\hline
total & 10 & 6 & 16\\
\hline
\end{tabular}
Compute $X^2 = \frac{\sum (o-e)^2}{e}$, where
e = (row sum $\times$ col sums)/total.
\underline{Expected}:
\begin{tabular}{|c|c|c|}
\hline
sequence & first period & second period \\
\hline
A$\rightarrow$ B & $\frac{9\times 10}{16}$ & $\frac{9\times 6}{16}$\\
B$\rightarrow$ A & $\frac{7\times 10}{16}$ & $\frac{7\times 6}{16}$ \\
\hline
\end{tabular}
\begin{equation}
X^2 = \frac{(9 - \frac{9\times 10}{16})^2}{\frac{9\times 10}{16}} +
\frac{(0 - \frac{9\times 6}{16})^2}{\frac{9\times 6}{16}} +
\frac{(1-\frac{7\times 10}{16})^2}{\frac{7\times 10}{16}} + \frac{(6-\frac{7\times 6}{16})^2}{\frac{7\times 6}{16}}
\end{equation}
<<>>=
(9-(9*10/16))^2/(9*10/16) +
(0-(9*6/16))^2/(9*6/16) +
(1-(7*10/16))^2/(7*10/16) +
(6-(7*6/16))^2/(7*6/16)
1-pchisq(12.34,df=1)
@
\section{Randomization}
Historical/database controls: use previous data as control and assign all patients to treatment. As a compromise, one could have a small number of controls to compare with historical controls.
\textbf{Unequal allocation} (4.3.2)
May decide we need most information on B to get more accurate estimates of the B effect; variation A is probably known reasonably well already if it is the standard.
\textbf{Stratified randomization}: Suppose we have patients in different age ranges and either M or F. Then find all possible combinations of each level, and then produce separate randomization lists for each level.
Adaptive randomization/minimization:
to-do
\section{Kappa statistic}
\begin{equation}
\kappa = \frac{A_{obs}-A_{exp}}{1-A_{exp}}
\end{equation}
Conventional scale:
\begin{enumerate}
\item $\kappa > 0.75$ excellent agrmt
\item $0.4 < \kappa <0.75$ fair to good agrmt
\item $<0.4$ moderate to poor agrmt
\end{enumerate}
The $A_{obs}$ is the sum of the diagonals.
The $A_{exp}$ is the (row sums*col sums)/(grand total), calculated only for the diagonals.
\section{Survival analysis}
\begin{verbatim}
right censoring:
t0 ----------o t1 t0 ---------- c
start dead start lost
\end{verbatim}
Survival time $t\geq 0$. Define a random variable $T\sim f(x)$ where the cdf is
\begin{equation}
F(x) = P(T < t) = \int_0^t f(u)\, du
\end{equation}
The probability that survival is $\geq$ t is
\begin{equation}\label{eq:probsurvival}
S(t)= 1- F(t)=P(T\geq t)
\end{equation}
\textbf{Hazard function}: Consider
$P(t \leq T < t+\delta t\mid T \geq t)$. Divide by $\delta t$ to get probability \textit{per unit time} = rate.
\textbf{Hazard rate definition}:
\begin{equation}
h(t) = \lim_{\delta t \to 0} \left\{
\frac{P(t \leq T < t+\delta t \mid T \geq t)}{\delta t} \right\}
\end{equation}
If we rearrange terms, we get:
\begin{equation}
h(t) \delta t = \lim_{\delta t \to 0} \left\{ P(t\leq T < t+\delta t \mid T \geq t) \right\}
\end{equation}
This is the probability of dying during $t+\delta t$; or the risk of death \textit{at time t}.
Focusing on the right-hand side $P(t\leq T < t+\delta t \mid T \geq t)$, we can use the conditional probability rule to determine that:
\begin{equation}
\begin{split}
P(t\leq T < t+\delta t \mid T \geq t) =&
\frac{P(t\leq T < t+\delta t)}{P(T\geq t)}\\
=& \frac{F(t+\delta t)-F(t)}{P(T\geq t)}
\end{split}
\end{equation}
From equation~\ref{eq:probsurvival} we know that $P(T\geq t)=S(t)$. So we can restate $h(t)$ as:
\begin{equation}
h(t) = \lim_{\delta t \to 0} \left\{
\frac{F(t+\delta t)-F(t)}{\delta t} \frac{1}{S(t)} \right\}
\end{equation}
Now,
\begin{equation}
\lim_{\delta t \to 0} \left\{
\frac{F(t+\delta t)-F(t)}{\delta t} \right\}
= \frac{d(F(t))}{dt} = f(t)
\end{equation}
Therefore:
\begin{equation}
\boxed{h(t) = \frac{f(t)}{S(t)}}
\end{equation}
Now,
\begin{equation}
\frac{d(\log(S(t)))}{dt} = -\frac{f(t)}{S(t)}
\end{equation}
\begin{leftbar}
This is because
\begin{equation}
S(t)=1-F(t) = 1 - \int_0^t f(t)\, dt)
\end{equation}
Taking logs:
\begin{equation}
\log S(t)= \log(1-F(t))=\log(1 - \int_0^t f(t)\, dt)
\end{equation}
If we now take the derivative of $\log S(t)$ with respect to $t$:
\begin{equation}
\frac{d(\log S(t))}{dt}= \frac{d(\log(1-F(t)))}{dt}=\frac{d(\log(1 - \int_0^t f(t)\, dt))}{dt}
\end{equation}
We use the chain rule to solve this derivative: Let $u=1 - \int_0^t f(t)\, dt=S(t)$. We can write:
\begin{equation}
\frac{d(\log(1 - \int_0^t f(t)\, dt))}{dt}=
\frac{d(\log(u))}{dt}
\end{equation}
Now, $\frac{du}{dt}= -f(t)$; also, $\frac{d(\log u)}{du}= \frac{1}{u}=\frac{1}{S(t)}$. So, by the chain rule:
\begin{equation}
\frac{d(\log u)}{du} \frac{du}{dt} = \frac{d(\log u)}{dt} = -\frac{f(t)}{S(t)}
\end{equation}
\end{leftbar}
Therefore:
\begin{equation}
h(t)= \frac{f(t)}{S(t)}= -\frac{d(\log(S(t)))}{dt}
\end{equation}
The cumulative distribution function H(t):
\begin{equation}
H(t) = \int_0^t h(u) \, du = - \log (S(t))
\end{equation}
Since $\log (S(t)) = - H(t)$, if we take exponents on both sides:
\begin{equation}
\boxed{S(t) = \exp(-H(t))}
\end{equation}
Since $f(t) = h(t) S(t)$, replacing S(t), we get:
\begin{equation}
\boxed{f(t) = h(t)S(t)=h(t)\exp(-H(t))}
\end{equation}
In summary, for any random variable T, we will define, f(t), S(t), and h(t).
\begin{center}
$\begin{tabu}{lll}
& Exponential & Weibull \\
\hline
f(t) & \lambda \exp(-\lambda t) & \lambda \gamma t^{\gamma -1 } \exp(-\lambda t^{\gamma})\\
S(t) & \exp(-\lambda t) & \exp(-\lambda t^\gamma) \\
h(t) & \lambda & \lambda \gamma t^{\gamma-1}\\
& & Alternative: \lambda \gamma (\lambda t)^{\gamma -1}=
\lambda^\gamma \gamma t^{\gamma -1}\\
\end{tabu}$
\end{center}
In Weibull, if $\gamma>1$ hazard is increasing, and if $\gamma<1$ hazard is decreasing. If $\gamma=1$, then the Weibull reduces to the exponential.
\subsection{Important application of the survival equations (Task 5)}
Reviewing the equations:
\begin{enumerate}
\item Survival function:
\begin{equation}
S(t) = 1- F(t) \Rightarrow F(t) = 1 - S(t)
\end{equation}
Also, since $F'(t)=f(t)$, it follows that $f(t)=-S'(t)$.
\item Hazard function:
\begin{equation}
h(t) = \frac{f(t)}{S(t)} \Rightarrow h(t) = \frac{-S'(t)}{S(t)}
\end{equation}
\item CDF of the Hazard function:
\begin{equation}
H(t) = \int_0^t h(u)\, du = - \log(S(t))
\end{equation}
\end{enumerate}
Suppose that the survivor function for a individual with covariate x satisfies:
\begin{equation}
S(t;x) = S_0(t\exp(-\beta^T x))
\end{equation}
where $S_0$ is some baseline survivor function.
Show that the corresponding hazard function satisfies:
$$h(t;x)=\exp(-\beta^T x) h_0 (t\exp(-\beta^T x)$$
\textbf{Solution}:
\textbf{Step 1}:
The hazard function is:
\begin{equation}
h(t) = \frac{f(t)}{S(t)} \Rightarrow h(t) = \frac{-S'(t)}{S(t)}
\end{equation}
Find the derivative S'(t) and plug the derivative and the expansion of S(t) into this hazard function equation.
$$S'(t) = \exp(-\beta^Tx S_0'(t \exp(-\beta^Tx)$$
\begin{equation}
h(t) = \frac{f(t)}{S(t)} \Rightarrow h(t) = \frac{-S'(t)}{S(t)} = -\frac{\exp(-\beta^Tx S_0'(t \exp(-\beta^Tx)}{S_0(t\exp(-\beta^T x))}
\end{equation}
\textbf{Step 2}:
Notice that the baseline hazard $h_0(t)$ is:
\begin{equation}
h_0(t) = \frac{f(t)}{S_0(t)} \Rightarrow h(t) = \frac{-S_0'(t)}{S_0(t)}
\end{equation}
which is what we have above.
\textbf{Step 3}: Plug in $h_0(t)$:
\begin{equation}
h(t)= -\frac{\exp(-\beta^Tx S_0'(t \exp(-\beta^Tx)}{S_0(t\exp(-\beta^T x))} =
\exp(-\beta^Tx h_0(t)
\end{equation}
\subsection{Life tables}: to-do
\subsection{Kaplan-Meier product estimates of S(t)}
Here, we estimate the survival distribution without making any assumptions. The estimator is a \textbf{non-parametric MLE}.
\begin{enumerate}
\item
k: number of failures
\item
$t_1,\dots,t_k$ unique event times (ordered)
\item
$d_i$: deaths at $t_i$
\item
$n_i$: number at risk (still alive) at $t_i$
\end{enumerate}
\begin{equation}
\hat S(t) = \prod_{i: t_i < t} (1-\frac{d_i}{n_i})=\prod_{i: t_i < t} (n_i - \frac{d_i}{n_i})
\end{equation}
\begin{equation}
\hat H(t) = - \log \hat S(t)
\end{equation}
\underline{With censoring}:
\begin{enumerate}
\item
$j$ is the time index: $j=1,\dots,k$, i.e., $t_1, \dots, t_k$.
\item
$d_j$ is the failure at time index $j$.
\item
$n$ is total number of observations
\item
$I_j$: number of individuals censored during $t_{j-1} < t < t_j$.
\item
$r_j$ is the number at risk (the number alive) just before time $t_j$.
%, so that $r_{j+1} = r_j - d_j$.
\item
Note that $r_1 = n - I_1$.
\item
For $j\geq 2, r_j = r_j - d_j - I_{j+1} = n- (d_1 + \dots + d_{j-i}) - (I_1 + \dots + I_j)$.
\end{enumerate}
\begin{equation}
\hat S(t) = \prod_{j=1}^{s} (1-\frac{d_j}{r_j}) \hbox{ for }
t_{(s)}<t<t_{(s+1)}
\end{equation}
\textbf{Note}:
\begin{enumerate}
\item
This assumes that $I_j$ censoring survive up to the preceding time period $t_{j-1}$ and then are removed immediately; this is different from life tables.
\item
KM estimates are used when the intervals between events are quite short and the number of withdrawals in any interval is therefore quite small.
\end{enumerate}
Greenwood's variance formula:
\begin{equation}
Var(\hat S(t)) = (\hat S(t))^2
\sum_{j=1}^{s} \frac{d_j}{r_j (r_j - d_j)}
\hbox{ for }
t_{(s)}<t<t_{(s+1)}
\end{equation}
\begin{equation}
\hat H(t) =\sum_{j=1}^{s} \frac{d_j}{r_j}
\hbox{ for }
t_{(s)}<t<t_{(s+1)}
\end{equation}
\textbf{Simple example from Harrell's Regression Modeling Strategies (p.\ 402)}
Given failure times (+ denotes censoring): $1, 3, 3, 6^+, 8^+, 9, 10^+$.
\begin{center}
\begin{tabular}{ccccccrr}
j & $t_i$ & $I_j$ & $r_i$ & $d_i$ & $(r_i - d_i)/r_i$ & S(t) & interval \\
0 & 0 & 0 & & & & 1 & $0\leq t< 1$\\
1 & 1 & 0 & 7 & 1 & 6/7 & 6/7=0.85 & $1\leq t< 3$\\
2 & 3 & 0 & 6 & 2 & 4/6 & $(6/7) \times (4/6)=0.57$ & $3\leq t< 9$\\
3 & 9 & 2 & 2 & 1 & 1/2 & $(6/7) \times (4/6) \times (1/2)=0.29$ & $9\leq t< 10$ \\
\end{tabular}
\end{center}
\underline{Variance calculation example}:
For time j=1: $0.85^2 (1/(7\times 6))=0.132^2$.
95\% CI:
For time j=2: $0.57^2 (1/(7\times 6) + 2/(6*4))=0.187^2$.