Professional Documents
Culture Documents
R Project - Page178,179,180, Etc
R Project - Page178,179,180, Etc
Complete Randomization
Simple Randomization is referred to as the procedure in which no restriction are enforced on the nature
of Randomization sequence except for the no. of patients required for achieving the desired statistical
power and the ratio of patient allocation between treatments. For clinical trial with N patients com-
paring a test drug and placebo, the method of complete Randomization is called a complete binomial
design or a simply Complete Randomization if it has the following properties:
1. The chance that the patient receives either the test drug or the placebo is 50%.
> x=c(1,2,3,4)
> P=c(0.2,0.4,0.3,0.1);
> drug=sample(x,100,replace=T,prob=P)
> d1=data.frame(`subject'=seq(1,100,1),drug)
> tx=table(drug); tx
drug
1 2 3 4
15 38 31 16
175
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
1 R 15
2 T 15
Adaptive Randomization
In practice, in addition to enforcing a balanced allocation among treatments to some degree, it is also
of interest to adjust the probability of assignment of patients to treatments during the study. This type
of randomisation is called adaptive randomization because the probability of the treatment to which a
current patient being assign is adjusted based on the assignment of previous patient.
The treatment Adaptive randomization adjust for the assigning probability of current patient with re-
spect to the number of patient who have been randomize to each treatment group.
> tre=rep(0,10)
> drug=c(`T',`R')
> p=0.5;s=0.02;
> tre[1]=sample(drug,1,prob=c(p,1-p))
> for(a in 2:10)
{ p=ifelse(`T'==tre[a-1],p-s,p+s);
tre[a]=sample(drug,1,prob=c(p,1-p)); }
> subject=1:10;
> d=data.frame(Sub=subject,Drug=tre);d
Sub Drug
1 1 R
2 2 R
:::
9 9 R
10 10 R
Another adaptive randomization is to adjust for the assigning probability according to the success or
failure of the treatment to which previous patients were assigned.
> tre=rep(0,10);res=rep(0,10);
> drug=c(`T',`R')
> p=0.5;s=0.02;q=0.6;
> tre[1]=rbinom(1,1,p);
> res[1]=rbinom(1,1,q);
> for(a in 2:10)
+ {p=ifelse(tre[a-1]==res[a-1], p+s, p-s);
+ tre[a]=rbinom(1,1,p);res[1]=rbinom(1,1,q); #readline can be used
+ }
> subject=1:10;
> d=data.frame(Sub=subject,Drug=drug[tre+1]);d
Sub Drug
1 1 T
2 2 T
:::
9 9 T
10 10 R
176 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
A Clinical study is conducted on 20 patients, assign two drugs (Active drug and placebo) to all patients
using covariate adaptive randomization.
Patient no. 1 2 3 4 5 6 7 8 8 10
Gender M M F M F F F M M F
Smoker No Yes Yes No No Yes No No No Yes
Patient no. 11 12 13 14 15 16 17 18 19 20
Gender F M M M F M F M M M
Smoker Yes Yes No Yes No Yes No Yes Yes No
> sub=c(1:20)
> gender=c(`M',`M',`F',`M',`F',`F',`F',`M',`M',`F',`F',`M',`M',
`M',`F',`M',`F',`M',`M',`M')
> smoke=c(`No',`Yes',`Yes',`No',`No',`Yes',`No',`No',`No',`Yes',
`Yes',`Yes',`No',`Yes',`No',`Yes',`No',`Yes',`Yes',`No')
> FS=sub[gender==`F'& smoke==`Yes'];
> nFS=length(FS);Y1=sample(c(rep(c(`T',`R'),nFS/2)),replace=F)
> FN=sub[gender==`F'& smoke==`No'];
> nFN=length(FN);Y2=sample(c(rep(c(`T',`R'),nFN/2)),replace=F)
> MS=sub[gender==`M'& smoke==`Yes'];
> nMS=length(MS);Y3=sample(c(rep(c(`T',`R'),nMS/2)),replace=F)
> MN=sub[gender==`M'& smoke==`No'];
> nMN=length(MN);Y4=sample(c(rep(c(`T',`R'),nMN/2)),replace=F)
> da=data.frame(subject=c(FS,FN,MS,MN),drug=c(Y1,Y2,Y3,Y4))
> da
subject drug
1 3 R
2 6 T
:::
19 13 T
20 20 R
Diet A 2.5 2.25 2.35 2.60 2.10 2.45 2.50 2.1 2.2 –
Diet B 2.45 2.50 2.60 2.77 2.60 2.55 2.65 2.75 2.45 2.50
> x=c(2.5,2.25,2.35,2.60,2.10,2.45,2.50,2.1,2.2)
> y=c(2.45,2.50,2.60,2.77,2.60,2.55,2.65,2.75,2.45,2.50)
> t.test(x,y,alt="less",var.equal=TRUE)
data: x and y
t = -3.4842, df = 17, p-value = 0.00142
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 177
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
data: x and y
t = -3.3986, df = 13.089, p-value = 0.002357
alternative hypothesis: true difference in means is less than 0
95 percent confidence interval:
-Inf -0.1164977
sample estimates:
mean of x mean of y
2.338889 2.582000
For one sample:
A sample 12 student from a school has the following scores in an IQ. test. 89, 87, 76, 78, 79, 86, 74, 83, 75,
71, 76 and 92. Do this data support that the mean IQ marks of the school students is 80. Test at 5%level
> x=c(89,87,76,78,79,86,74,83,75,71,76,92)
> t.test(x,mu=80,alt="two.sided",conf.level = 0.95)
data: x
t = 0.2582, df = 11, p-value = 0.801
alternative hypothesis: true mean is not equal to 80
95 percent confidence interval:
76.23781 84.76219
sample estimates:
mean of x
80.5
Favourable Unfavourable
Week 1 45 35
Week 2 56 47
> x = matrix(c(45,56,35,47),ncol=2)
> prop.test(x,alternative = "two.sided")
178 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
data: x
X-squared = 0.010813, df = 1, p-value = 0.9172
alternative hypothesis: two.sided
95 percent confidence interval:
-0.1374478 0.1750692
sample estimates:
prop 1 prop 2
0.5625000 0.5436893
A total of 168, 182, 165 and 188 patients were entered in the 0 mg C, 400 mg C, 800 mg C, and 1600 mg C
groups, respectively. The corresponding cumulative number of patients whose ulcers healed by the end
(Week 4) of the trial were 69, 113, 120, and 145, respectively.
data: x out of n
X-squared = 57.799, df = 3, p-value = 1.735e-12
alternative hypothesis: two.sided
sample estimates:
prop 1 prop 2 prop 3 prop 4
0.4107143 0.6208791 0.7272727 0.7712766
Analysis of Variance
> y1=c(12,12.3,15,14.5,15.2,13.6,14.6,12.5,12.4);n1=length(y1);
> y2=c(24.2,26.3,20.4,21.5,24.3,22,25.6,23.5);n2=length(y2);
> y3=c(24.3,22,24,25.1,21.4,20,12);n3=length(y3);
> y4=c(30.4,29.4,28.4,25.45,27.12,20.4,28,29.2,30.4);n4=length(y4);
> yield=c(y1,y2,y3,y4);
> fact=factor(c(rep(1,n1),rep(2,n2),rep(3,n3),rep(4,n4)));
> model1<- aov(yield~fact);
> summary(model1)
Df Sum Sq Mean Sq F value Pr(>F)
fact 3 937.4 312.4 37.63 3.98e-10 ***
Residuals 29 240.8 8.3
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> TukeyHSD(model1,conf.level=0.99)
Tukey multiple comparisons of means
99% family-wise confidence level
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 179
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
$fact
diff lwr upr p adj
2-1 9.908333 5.1421205 14.674546 0.0000005
3-1 7.690476 2.7473131 12.633639 0.0000631
4-1 14.074444 9.4505388 18.698350 0.0000000
3-2 -2.217857 -7.2943858 2.858671 0.4579386
4-2 4.166111 -0.6001018 8.932324 0.0282474
4-3 6.383968 1.4408052 11.327131 0.0007419
> boxplot(yield~fact,xlab=`Treatments',ylab=`Yield');
> title(`Treatment comparison using Boxplot')
180 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
-15.2 -4.8
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 181
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> attach(dat)
> # create the changes from baseline
> df2to1 = DBP2-DBP1
> df3to1 = DBP3-DBP1
> df4to1 = DBP4-DBP1
> df5to1 = DBP5-DBP1
> # call "manova" to fit a manova
> maov1=manova(cbind(df2to1,df3to1,df4to1,df5to1)~TRT,dat)
> # then F-test with Pillai (default in R)
> summary(maov1)
Df Pillai approx F num Df den Df Pr(>F)
TRT 1 0.82098 40.128 4 35 1.295e-12 ***
Residuals 38
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
> # F-test with Hotelling-Lawley, Wilks and Roy
> summary(maov1, test="Hotelling-Lawley")
> summary(maov1, test="Wilks")
> summary(maov1, test="Roy")
Response: diff
Df Sum Sq Mean Sq F value Pr(>F)
TRT 1 1081.60 1081.60 176.8042 1.401e-14 ***
Age 1 51.07 51.07 8.3481 0.006876 **
Sex 1 1.06 1.06 0.1725 0.680701
TRT:Age 1 10.32 10.32 1.6869 0.203286
TRT:Sex 1 0.42 0.42 0.0687 0.794872
Age:Sex 1 17.07 17.07 2.7903 0.104593
TRT:Age:Sex 1 2.71 2.71 0.4423 0.510772
Residuals 32 195.76 6.12
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
182 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
• Tmax : Time of maximum measured plasma concentration. If maximum value occurs at more than
one point, Tmax is defined as the first point with this value in each period.
• AUC (0−t ) : The area under the plasma concentration versus time curve from time zero to the last
measurable concentration, as calculated by the linear trapezoidal method.
• K e : Rate of elimination.
• AUC (0−∞) :The area under the plasma concentration versus time curve, from zero to infinity.
AUC (0−∞) is calculated as the sum of the AUC (0−t ) plus the ratio of the last measurable concen-
tration to the elimination rate constant. In short AUC (0−∞) is the area covered by the drug till the
drug totally removed from the body. Therefore if the concentration takes value zero till we record
then AUC (0−t ) = AUC (0−∞) otherwise we estimate with help of given formula in section.
> t=c(0,0.5,1,1.5,2,3,4,6,8,12,16,24,32)
> conc=c(0,0,2.8,4.4,4.4,4.7,4.1,4,3.6,3,2.5,2,1.6)
> plot(t,conc,xlab = "Time",ylab="Concentration",type = `l')
> title(`Area under Curve (AUC)')
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 183
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
> n=length(t)
> c_max=max(conc)
> a=which.max(conc)
> t_max=t[a]
> AUCt=sum((conc[2:n]+conc[1:n-1])*(t[2:n]-t[1:n-1]))/2;
> Ke=-2.303*coefficients(lm(log10(conc[a+1:n])~t[a+1:n]))[2]
> AUCinf=AUCt+conc[n]/Ke
> thalf=0.693/Ke
> d=data.frame(t_max,c_max,AUCt,AUCinf,Ke,thalf, row.names = "PKparameters");d
t_max c_max AUCt AUCinf Ke thalf
PKparameters 3 4.7 85.95 131.728 0.03495131 19.82758
184 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
Analysis of Variance
> Data = data.frame(subj = as.factor(dat$Subject),
+ drug = as.factor(dat$Formulation),
+ seq = as.factor(dat$Sequence),
+ prd = as.factor(dat$Period),
+ AUC = dat$AUC)
> # cat("Then call R function aov for ANOVA Table", "\n")
> summary(aov(AUC ~ seq*drug + Error(subj), data = Data))
Error: subj
Df Sum Sq Mean Sq F value Pr(>F)
seq 1 276 276.0 0.375 0.547
Residuals 22 16211 736.9
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
drug 1 63 62.79 0.375 0.546
seq:drug 1 36 35.97 0.215 0.647
Residuals 22 3679 167.25
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 185
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
drug 1 0.0743 0.07427 1.905 0.181
seq:drug 1 0.0351 0.03509 0.900 0.353
Residuals 22 0.8579 0.03899
> summary(aov(log(AUCinf) ~ seq*drug + Error(subj), data = dat3))
Error: subj
Df Sum Sq Mean Sq F value Pr(>F)
seq 1 0.0179 0.01788 0.607 0.444
Residuals 22 0.6483 0.02947
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
drug 1 0.0685 0.06852 1.794 0.194
seq:drug 1 0.0409 0.04094 1.072 0.312
Residuals 22 0.8405 0.03820
186 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
Error: subj
Df Sum Sq Mean Sq F value Pr(>F)
seq 1 0.0750 0.07501 2.91 0.102
Residuals 22 0.5671 0.02578
Error: Within
Df Sum Sq Mean Sq F value Pr(>F)
drug 1 0.0001 0.00009 0.003 0.958
seq:drug 1 0.0800 0.08005 2.515 0.127
Residuals 22 0.7003 0.03183
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 187
Chapter 9. Design and Analysis of Clinical Trials M.Sc.(Statistics) Project Report
R Function power.t.test
> power.t.test(delta=0.8, sd=1.3, power=0.9)
Two-sample t test power calculation
n = 56.47019
delta = 0.8
sd = 1.3
sig.level = 0.05
power = 0.9
alternative = two.sided
NOTE: n is number in *each* group
> power.t.test(delta=0.8, sd=1.3, power=0.9, alternative = "one.sided")
Two-sample t test power calculation
n = 45.92039
delta = 0.8
sd = 1.3
sig.level = 0.05
power = 0.9
alternative = one.sided
NOTE: n is number in *each* group
R Function power.prop.test
> power.prop.test(p1 = .5, p2 = .7, power = .80)
Two-sample comparison of proportions power calculation
n = 92.99884
p1 = 0.5
p2 = 0.7
sig.level = 0.05
power = 0.8
alternative = two.sided
NOTE: n is number in *each* group
188 Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon
M.Sc.(Statistics) Project Report Chapter 9. Design and Analysis of Clinical Trials
Reference: Practical Sheets based ST-305(D) Design and Analysis of Clinical Trials prepared by Mr.
Manoj C. Patil
Department of Statistics, Kavayitri Bahinabai Chaudhari North Maharashtra University, Jalgaon 189