##################################
# Loading R libraries
##################################
library(moments)
library(car)
library(multcomp)
library(effects)
library(psych)
library(ggplot2)
library(dplyr)
library(ggpubr)
library(rstatix)
library(ggfortify)
library(trend)
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
=seq(0.4,0.6,0.05)
p_ResponseRate
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.15
p_Reference
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha/2)+qnorm(1-beta_1))/(p_ResponseRate-p_Reference))^2) ((
## [1] 23.700737 16.973184 12.596055 9.547416 7.315042
ceiling(n_Beta30)
## [1] 24 17 13 10 8
=(p_ResponseRate-p_Reference)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30)
z_Beta30Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha/2))+pnorm(-z_Beta30-qnorm(1-alpha/2))) (
## [1] 0.7000044 0.7000044 0.7000044 0.7000044 0.7000044
=beta[2]
beta_2n_Beta20=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha/2)+qnorm(1-beta_2))/(p_ResponseRate-p_Reference))^2) ((
## [1] 30.139698 21.584419 16.018122 12.141236 9.302376
ceiling(n_Beta20)
## [1] 31 22 17 13 10
=(p_ResponseRate-p_Reference)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20)
z_Beta20Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha/2))+pnorm(-z_Beta20-qnorm(1-alpha/2))) (
## [1] 0.800001 0.800001 0.800001 0.800001 0.800001
=beta[3]
beta_3n_Beta10=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha/2)+qnorm(1-beta_3))/(p_ResponseRate-p_Reference))^2) ((
## [1] 40.34850 28.89541 21.44372 16.25367 12.45324
ceiling(n_Beta10)
## [1] 41 29 22 17 13
=(p_ResponseRate-p_Reference)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10)
z_Beta10Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha/2))+pnorm(-z_Beta10-qnorm(1-alpha/2))) (
## [1] 0.9000001 0.9000001 0.9000001 0.9000001 0.9000001
<- as.data.frame(cbind(p_ResponseRate,n_Beta30,n_Beta20,n_Beta10))
OneSampleDesign.Equality names(OneSampleDesign.Equality) <- c("Posttreatment.True.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(OneSampleDesign.Equality,
OneSampleDesign.Equality.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("OSD_EQUALITY",nrow(OneSampleDesign.Equality.Reshaped))
OneSampleDesign.Equality.Reshaped
OneSampleDesign.Equality.Reshaped
## Posttreatment.True.Response.Rate Power Sample.Size Label
## 1 0.40 Power=70% 23.700737 OSD_EQUALITY
## 2 0.45 Power=70% 16.973184 OSD_EQUALITY
## 3 0.50 Power=70% 12.596055 OSD_EQUALITY
## 4 0.55 Power=70% 9.547416 OSD_EQUALITY
## 5 0.60 Power=70% 7.315042 OSD_EQUALITY
## 6 0.40 Power=80% 30.139698 OSD_EQUALITY
## 7 0.45 Power=80% 21.584419 OSD_EQUALITY
## 8 0.50 Power=80% 16.018122 OSD_EQUALITY
## 9 0.55 Power=80% 12.141236 OSD_EQUALITY
## 10 0.60 Power=80% 9.302376 OSD_EQUALITY
## 11 0.40 Power=90% 40.348505 OSD_EQUALITY
## 12 0.45 Power=90% 28.895413 OSD_EQUALITY
## 13 0.50 Power=90% 21.443721 OSD_EQUALITY
## 14 0.55 Power=90% 16.253670 OSD_EQUALITY
## 15 0.60 Power=90% 12.453242 OSD_EQUALITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(OneSampleDesign.Equality.Reshaped,
(OneSampleDesign.Equality.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("One-Sample Design : Test for Equality"))
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
=seq(0.4,0.6,0.05)
p_ResponseRate
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.15
p_Reference
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the non-inferiority delta
##################################
=-0.05
delta
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_1))/(p_ResponseRate-p_Reference-delta))^2) ((
## [1] 12.548436 9.507361 7.352599 5.751367 4.517437
ceiling(n_Beta30)
## [1] 13 10 8 6 5
=(p_ResponseRate-p_Reference-delta)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30)
z_Beta30Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha))+pnorm(-z_Beta30-qnorm(1-alpha))) (
## [1] 0.7000683 0.7000683 0.7000683 0.7000683 0.7000683
=beta[2]
beta_2n_Beta20=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_2))/(p_ResponseRate-p_Reference-delta))^2) ((
## [1] 16.486819 12.491289 9.660246 7.556459 5.935255
ceiling(n_Beta20)
## [1] 17 13 10 8 6
=(p_ResponseRate-p_Reference-delta)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20)
z_Beta20Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha))+pnorm(-z_Beta20-qnorm(1-alpha))) (
## [1] 0.800018 0.800018 0.800018 0.800018 0.800018
=beta[3]
beta_3n_Beta10=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_3))/(p_ResponseRate-p_Reference-delta))^2) ((
## [1] 22.836926 17.302467 13.381011 10.466925 8.221293
ceiling(n_Beta10)
## [1] 23 18 14 11 9
=(p_ResponseRate-p_Reference-delta)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10)
z_Beta10Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha))+pnorm(-z_Beta10-qnorm(1-alpha))) (
## [1] 0.9000024 0.9000024 0.9000024 0.9000024 0.9000024
<- as.data.frame(cbind(p_ResponseRate,n_Beta30,n_Beta20,n_Beta10))
OneSampleDesign.NonInferiority names(OneSampleDesign.NonInferiority) <- c("Posttreatment.True.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(OneSampleDesign.NonInferiority,
OneSampleDesign.NonInferiority.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("OSD_NONINFERIORITY",nrow(OneSampleDesign.NonInferiority.Reshaped))
OneSampleDesign.NonInferiority.Reshaped
OneSampleDesign.NonInferiority.Reshaped
## Posttreatment.True.Response.Rate Power Sample.Size Label
## 1 0.40 Power=70% 12.548436 OSD_NONINFERIORITY
## 2 0.45 Power=70% 9.507361 OSD_NONINFERIORITY
## 3 0.50 Power=70% 7.352599 OSD_NONINFERIORITY
## 4 0.55 Power=70% 5.751367 OSD_NONINFERIORITY
## 5 0.60 Power=70% 4.517437 OSD_NONINFERIORITY
## 6 0.40 Power=80% 16.486819 OSD_NONINFERIORITY
## 7 0.45 Power=80% 12.491289 OSD_NONINFERIORITY
## 8 0.50 Power=80% 9.660246 OSD_NONINFERIORITY
## 9 0.55 Power=80% 7.556459 OSD_NONINFERIORITY
## 10 0.60 Power=80% 5.935255 OSD_NONINFERIORITY
## 11 0.40 Power=90% 22.836926 OSD_NONINFERIORITY
## 12 0.45 Power=90% 17.302467 OSD_NONINFERIORITY
## 13 0.50 Power=90% 13.381011 OSD_NONINFERIORITY
## 14 0.55 Power=90% 10.466925 OSD_NONINFERIORITY
## 15 0.60 Power=90% 8.221293 OSD_NONINFERIORITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(OneSampleDesign.NonInferiority.Reshaped,
(OneSampleDesign.NonInferiority.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("One-Sample Design : Test for Non-Inferiority"))
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
=seq(0.4,0.6,0.05)
p_ResponseRate
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.15
p_Reference
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the Superiority delta
##################################
=0.05
delta
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_1))/(p_ResponseRate-p_Reference-delta))^2) ((
## [1] 28.233981 18.634428 13.071288 9.507361 7.058495
ceiling(n_Beta30)
## [1] 29 19 14 10 8
=(p_ResponseRate-p_Reference-delta)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30)
z_Beta30Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha))+pnorm(-z_Beta30-qnorm(1-alpha))) (
## [1] 0.7000683 0.7000683 0.7000683 0.7000683 0.7000683
=beta[2]
beta_2n_Beta20=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_2))/(p_ResponseRate-p_Reference-delta))^2) ((
## [1] 37.095343 24.482927 17.173770 12.491289 9.273836
ceiling(n_Beta20)
## [1] 38 25 18 13 10
=(p_ResponseRate-p_Reference-delta)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20)
z_Beta20Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha))+pnorm(-z_Beta20-qnorm(1-alpha))) (
## [1] 0.800018 0.800018 0.800018 0.800018 0.800018
=beta[3]
beta_3n_Beta10=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_3))/(p_ResponseRate-p_Reference-delta))^2) ((
## [1] 51.38308 33.91284 23.78846 17.30247 12.84577
ceiling(n_Beta10)
## [1] 52 34 24 18 13
=(p_ResponseRate-p_Reference-delta)/sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10)
z_Beta10Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha))+pnorm(-z_Beta10-qnorm(1-alpha))) (
## [1] 0.9000024 0.9000024 0.9000024 0.9000024 0.9000024
<- as.data.frame(cbind(p_ResponseRate,n_Beta30,n_Beta20,n_Beta10))
OneSampleDesign.Superiority names(OneSampleDesign.Superiority) <- c("Posttreatment.True.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(OneSampleDesign.Superiority,
OneSampleDesign.Superiority.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("OSD_SUPERIORITY",nrow(OneSampleDesign.Superiority.Reshaped))
OneSampleDesign.Superiority.Reshaped
OneSampleDesign.Superiority.Reshaped
## Posttreatment.True.Response.Rate Power Sample.Size Label
## 1 0.40 Power=70% 28.233981 OSD_SUPERIORITY
## 2 0.45 Power=70% 18.634428 OSD_SUPERIORITY
## 3 0.50 Power=70% 13.071288 OSD_SUPERIORITY
## 4 0.55 Power=70% 9.507361 OSD_SUPERIORITY
## 5 0.60 Power=70% 7.058495 OSD_SUPERIORITY
## 6 0.40 Power=80% 37.095343 OSD_SUPERIORITY
## 7 0.45 Power=80% 24.482927 OSD_SUPERIORITY
## 8 0.50 Power=80% 17.173770 OSD_SUPERIORITY
## 9 0.55 Power=80% 12.491289 OSD_SUPERIORITY
## 10 0.60 Power=80% 9.273836 OSD_SUPERIORITY
## 11 0.40 Power=90% 51.383084 OSD_SUPERIORITY
## 12 0.45 Power=90% 33.912836 OSD_SUPERIORITY
## 13 0.50 Power=90% 23.788465 OSD_SUPERIORITY
## 14 0.55 Power=90% 17.302467 OSD_SUPERIORITY
## 15 0.60 Power=90% 12.845771 OSD_SUPERIORITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(OneSampleDesign.Superiority.Reshaped,
(OneSampleDesign.Superiority.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("One-Sample Design : Test for Superiority"))
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
=seq(0.4,0.6,0.05)
p_ResponseRate
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.15
p_Reference
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the Equivalence delta
##################################
=0.05
delta
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_1/2))/(abs(p_ResponseRate-p_Reference)-delta))^2) ((
## [1] 43.13580 28.46963 19.97028 14.52532 10.78395
ceiling(n_Beta30)
## [1] 44 29 20 15 11
=(abs(p_ResponseRate-p_Reference)-delta)/
z_Beta30sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30)
Power_Beta30=2*(pnorm(z_Beta30-qnorm(1-alpha))+pnorm(-z_Beta30-qnorm(1-alpha)))-1) (
## [1] 0.7000152 0.7000152 0.7000152 0.7000152 0.7000152
=beta[2]
beta_2n_Beta20=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_2/2))/(abs(p_ResponseRate-p_Reference)-delta))^2) ((
## [1] 51.38308 33.91284 23.78846 17.30247 12.84577
ceiling(n_Beta20)
## [1] 52 34 24 18 13
=(abs(p_ResponseRate-p_Reference)-delta)/
z_Beta20sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20)
Power_Beta20=2*(pnorm(z_Beta20-qnorm(1-alpha))+pnorm(-z_Beta20-qnorm(1-alpha)))-1) (
## [1] 0.8000048 0.8000048 0.8000048 0.8000048 0.8000048
=beta[3]
beta_3n_Beta10=p_ResponseRate*(1-p_ResponseRate)*
(qnorm(1-alpha)+qnorm(1-beta_3/2))/(abs(p_ResponseRate-p_Reference)-delta))^2) ((
## [1] 64.93304 42.85581 30.06159 21.86521 16.23326
ceiling(n_Beta10)
## [1] 65 43 31 22 17
=(abs(p_ResponseRate-p_Reference)-delta)/
z_Beta10sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10)
Power_Beta10=2*(pnorm(z_Beta10-qnorm(1-alpha))+pnorm(-z_Beta10-qnorm(1-alpha)))-1) (
## [1] 0.9000008 0.9000008 0.9000008 0.9000008 0.9000008
<- as.data.frame(cbind(p_ResponseRate,n_Beta30,n_Beta20,n_Beta10))
OneSampleDesign.Equivalence names(OneSampleDesign.Equivalence) <- c("Posttreatment.True.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(OneSampleDesign.Equivalence,
OneSampleDesign.Equivalence.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("OSD_EQUIVALENCE",nrow(OneSampleDesign.Equivalence.Reshaped))
OneSampleDesign.Equivalence.Reshaped
OneSampleDesign.Equivalence.Reshaped
## Posttreatment.True.Response.Rate Power Sample.Size Label
## 1 0.40 Power=70% 43.13580 OSD_EQUIVALENCE
## 2 0.45 Power=70% 28.46963 OSD_EQUIVALENCE
## 3 0.50 Power=70% 19.97028 OSD_EQUIVALENCE
## 4 0.55 Power=70% 14.52532 OSD_EQUIVALENCE
## 5 0.60 Power=70% 10.78395 OSD_EQUIVALENCE
## 6 0.40 Power=80% 51.38308 OSD_EQUIVALENCE
## 7 0.45 Power=80% 33.91284 OSD_EQUIVALENCE
## 8 0.50 Power=80% 23.78846 OSD_EQUIVALENCE
## 9 0.55 Power=80% 17.30247 OSD_EQUIVALENCE
## 10 0.60 Power=80% 12.84577 OSD_EQUIVALENCE
## 11 0.40 Power=90% 64.93304 OSD_EQUIVALENCE
## 12 0.45 Power=90% 42.85581 OSD_EQUIVALENCE
## 13 0.50 Power=90% 30.06159 OSD_EQUIVALENCE
## 14 0.55 Power=90% 21.86521 OSD_EQUIVALENCE
## 15 0.60 Power=90% 16.23326 OSD_EQUIVALENCE
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(OneSampleDesign.Equivalence.Reshaped,
(OneSampleDesign.Equivalence.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("One-Sample Design : Test for Equivalence"))
##################################
# Consolidating the power analyses charts
##################################
<- ggplot(OneSampleDesign.Equality.Reshaped,
OSD_EQUALITY.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(OneSampleDesign.NonInferiority.Reshaped,
OSD_NONINFERIORITY.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(OneSampleDesign.Superiority.Reshaped,
OSD_SUPERIORITY.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(OneSampleDesign.Equivalence.Reshaped,
OSD_EQUIVALENCE.PowerAnalysis aes(x=Posttreatment.True.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Post-Treatment True Response Rate",
limits=c(0.40,0.60),
breaks=seq(0.40,0.60,
by=0.05)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggarrange(OSD_EQUALITY.PowerAnalysis,
OSD_PowerAnalysis
OSD_NONINFERIORITY.PowerAnalysis,
OSD_SUPERIORITY.PowerAnalysis,
OSD_EQUIVALENCE.PowerAnalysis,ncol=2, nrow=2)
annotate_figure(OSD_PowerAnalysis,
top = text_grob("One-Sample Design Power Analysis by Statistical Hypothesis",
color = "black",
face = "bold",
size = 14))
##################################
# Defining a range of possible hypothesized values for epsilon
##################################
=seq(0.20,0.30,0.02)
epsilon
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.65
p_Reference
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
p_ResponseRate=p_Reference + epsilon) (
## [1] 0.85 0.87 0.89 0.91 0.93 0.95
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining a fixed hypothesized value for kappa
##################################
=1.0
kappa
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha/2)+qnorm(1-beta_1))/
(-p_Reference))^2) (p_ResponseRate
## [1] 54.77709 43.43401 34.86789 28.24908 23.03504 18.85909
ceiling(n_Beta30)
## [1] 55 44 35 29 24 19
=(p_ResponseRate-p_Reference)/
z_Beta30sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30/kappa+p_Reference
*(1-p_Reference)/n_Beta30)
Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha/2))+pnorm(-z_Beta30-qnorm(1-alpha/2))) (
## [1] 0.7000044 0.7000044 0.7000044 0.7000044 0.7000044 0.7000044
=beta[2]
beta_2n_Beta20=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha/2)+qnorm(1-beta_2))/
(-p_Reference))^2) (p_ResponseRate
## [1] 69.65881 55.23406 44.34072 35.92372 29.29314 23.98269
ceiling(n_Beta20)
## [1] 70 56 45 36 30 24
=(p_ResponseRate-p_Reference)/
z_Beta20sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20/kappa+p_Reference
*(1-p_Reference)/n_Beta20)
Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha/2))+pnorm(-z_Beta20-qnorm(1-alpha/2))) (
## [1] 0.800001 0.800001 0.800001 0.800001 0.800001 0.800001
=beta[3]
beta_3n_Beta10=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha/2)+qnorm(1-beta_3))/
(-p_Reference))^2) (p_ResponseRate
## [1] 93.25338 73.94273 59.35964 48.09167 39.21520 32.10601
ceiling(n_Beta10)
## [1] 94 74 60 49 40 33
=(p_ResponseRate-p_Reference)/
z_Beta10sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10/kappa+p_Reference
*(1-p_Reference)/n_Beta10)
Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha/2))+pnorm(-z_Beta10-qnorm(1-alpha/2))) (
## [1] 0.9000001 0.9000001 0.9000001 0.9000001 0.9000001 0.9000001
<- as.data.frame(cbind(epsilon,n_Beta30,n_Beta20,n_Beta10))
TwoSampleUnpairedDesign.Equality names(TwoSampleUnpairedDesign.Equality) <- c("Cure.Rate.Change",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(TwoSampleUnpairedDesign.Equality,
TwoSampleUnpairedDesign.Equality.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("TSUD_EQUALITY",nrow(TwoSampleUnpairedDesign.Equality.Reshaped))
TwoSampleUnpairedDesign.Equality.Reshaped
TwoSampleUnpairedDesign.Equality.Reshaped
## Cure.Rate.Change Power Sample.Size Label
## 1 0.20 Power=70% 54.77709 TSUD_EQUALITY
## 2 0.22 Power=70% 43.43401 TSUD_EQUALITY
## 3 0.24 Power=70% 34.86789 TSUD_EQUALITY
## 4 0.26 Power=70% 28.24908 TSUD_EQUALITY
## 5 0.28 Power=70% 23.03504 TSUD_EQUALITY
## 6 0.30 Power=70% 18.85909 TSUD_EQUALITY
## 7 0.20 Power=80% 69.65881 TSUD_EQUALITY
## 8 0.22 Power=80% 55.23406 TSUD_EQUALITY
## 9 0.24 Power=80% 44.34072 TSUD_EQUALITY
## 10 0.26 Power=80% 35.92372 TSUD_EQUALITY
## 11 0.28 Power=80% 29.29314 TSUD_EQUALITY
## 12 0.30 Power=80% 23.98269 TSUD_EQUALITY
## 13 0.20 Power=90% 93.25338 TSUD_EQUALITY
## 14 0.22 Power=90% 73.94273 TSUD_EQUALITY
## 15 0.24 Power=90% 59.35964 TSUD_EQUALITY
## 16 0.26 Power=90% 48.09167 TSUD_EQUALITY
## 17 0.28 Power=90% 39.21520 TSUD_EQUALITY
## 18 0.30 Power=90% 32.10601 TSUD_EQUALITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(TwoSampleUnpairedDesign.Equality.Reshaped,
(TwoSampleUnpairedDesign.Equality.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Two-Sample Unpaired Design : Test for Equality"))
##################################
# Defining a range of possible hypothesized values for epsilon
##################################
=seq(0.20,0.30,0.02)
epsilon
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.65
p_Reference
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
p_ResponseRate=p_Reference + epsilon) (
## [1] 0.85 0.87 0.89 0.91 0.93 0.95
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the non-inferiority delta
##################################
=-0.10
delta
##################################
# Defining a fixed hypothesized value for kappa
##################################
=1.0
kappa
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_1))/
(-p_Reference-delta))^2) (p_ResponseRate
## [1] 18.561228 15.651846 13.245873 11.234045 9.535160 8.087859
ceiling(n_Beta30)
## [1] 19 16 14 12 10 9
=(p_ResponseRate-p_Reference-delta)/
z_Beta30sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30/kappa+p_Reference
*(1-p_Reference)/n_Beta30)
Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha))+pnorm(-z_Beta30-qnorm(1-alpha))) (
## [1] 0.7000683 0.7000683 0.7000683 0.7000683 0.7000683 0.7000683
=beta[2]
beta_2n_Beta20=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_2))/
(-p_Reference-delta))^2) (p_ResponseRate
## [1] 24.38675 20.56425 17.40315 14.75990 12.52781 10.62627
ceiling(n_Beta20)
## [1] 25 21 18 15 13 11
=(p_ResponseRate-p_Reference-p_Reference-delta)/
z_Beta20sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20/kappa+p_Reference
*(1-p_Reference)/n_Beta20)
Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha))+pnorm(-z_Beta20-qnorm(1-alpha))) (
## [1] 0.8954509 0.8210496 0.7331493 0.6400130 0.5488149 0.4645128
=beta[3]
beta_3n_Beta10=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_3))/
(-p_Reference-delta))^2) (p_ResponseRate
## [1] 33.77962 28.48483 24.10619 20.44486 17.35306 14.71911
ceiling(n_Beta10)
## [1] 34 29 25 21 18 15
=(p_ResponseRate-p_Reference-delta)/
z_Beta10sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10/kappa+p_Reference
*(1-p_Reference)/n_Beta10)
Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha))+pnorm(-z_Beta10-qnorm(1-alpha))) (
## [1] 0.9000024 0.9000024 0.9000024 0.9000024 0.9000024 0.9000024
<- as.data.frame(cbind(epsilon,n_Beta30,n_Beta20,n_Beta10))
TwoSampleUnpairedDesign.NonInferiority names(TwoSampleUnpairedDesign.NonInferiority) <- c("Cure.Rate.Change",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(TwoSampleUnpairedDesign.NonInferiority,
TwoSampleUnpairedDesign.NonInferiority.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("TSUD_NONINFERIORITY",nrow(TwoSampleUnpairedDesign.NonInferiority.Reshaped))
TwoSampleUnpairedDesign.NonInferiority.Reshaped
TwoSampleUnpairedDesign.NonInferiority.Reshaped
## Cure.Rate.Change Power Sample.Size Label
## 1 0.20 Power=70% 18.561228 TSUD_NONINFERIORITY
## 2 0.22 Power=70% 15.651846 TSUD_NONINFERIORITY
## 3 0.24 Power=70% 13.245873 TSUD_NONINFERIORITY
## 4 0.26 Power=70% 11.234045 TSUD_NONINFERIORITY
## 5 0.28 Power=70% 9.535160 TSUD_NONINFERIORITY
## 6 0.30 Power=70% 8.087859 TSUD_NONINFERIORITY
## 7 0.20 Power=80% 24.386754 TSUD_NONINFERIORITY
## 8 0.22 Power=80% 20.564248 TSUD_NONINFERIORITY
## 9 0.24 Power=80% 17.403150 TSUD_NONINFERIORITY
## 10 0.26 Power=80% 14.759901 TSUD_NONINFERIORITY
## 11 0.28 Power=80% 12.527813 TSUD_NONINFERIORITY
## 12 0.30 Power=80% 10.626270 TSUD_NONINFERIORITY
## 13 0.20 Power=90% 33.779620 TSUD_NONINFERIORITY
## 14 0.22 Power=90% 28.484828 TSUD_NONINFERIORITY
## 15 0.24 Power=90% 24.106193 TSUD_NONINFERIORITY
## 16 0.26 Power=90% 20.444864 TSUD_NONINFERIORITY
## 17 0.28 Power=90% 17.353059 TSUD_NONINFERIORITY
## 18 0.30 Power=90% 14.719113 TSUD_NONINFERIORITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(TwoSampleUnpairedDesign.NonInferiority.Reshaped,
(TwoSampleUnpairedDesign.NonInferiority.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Two-Sample Unpaired Design : Test for NonInferiority"))
##################################
# Defining a range of possible hypothesized values for epsilon
##################################
=seq(0.20,0.30,0.02)
epsilon
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.65
p_Reference
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
p_ResponseRate=p_Reference + epsilon) (
## [1] 0.85 0.87 0.89 0.91 0.93 0.95
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the non-inferiority delta
##################################
= 0.02
delta
##################################
# Defining a fixed hypothesized value for kappa
##################################
=1.0
kappa
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_1))/
(-p_Reference-delta))^2) (p_ResponseRate
## [1] 51.55897 40.06872 31.63684 25.27660 20.36801 16.50584
ceiling(n_Beta30)
## [1] 52 41 32 26 21 17
=(p_ResponseRate-p_Reference-delta)/
z_Beta30sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30/kappa+p_Reference
*(1-p_Reference)/n_Beta30)
Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha))+pnorm(-z_Beta30-qnorm(1-alpha))) (
## [1] 0.7000683 0.7000683 0.7000683 0.7000683 0.7000683 0.7000683
=beta[2]
beta_2n_Beta20=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_2))/
(-p_Reference-delta))^2) (p_ResponseRate
## [1] 67.74098 52.64447 41.56620 33.20978 26.76060 21.68627
ceiling(n_Beta20)
## [1] 68 53 42 34 27 22
=(p_ResponseRate-p_Reference-delta)/
z_Beta20sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20/kappa+p_Reference
*(1-p_Reference)/n_Beta20)
Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha))+pnorm(-z_Beta20-qnorm(1-alpha))) (
## [1] 0.800018 0.800018 0.800018 0.800018 0.800018 0.800018
=beta[3]
beta_3n_Beta10=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_3))/
(-p_Reference-delta))^2) (p_ResponseRate
## [1] 93.83228 72.92116 57.57595 46.00094 37.06778 30.03901
ceiling(n_Beta10)
## [1] 94 73 58 47 38 31
=(p_ResponseRate-p_Reference-delta)/
z_Beta10sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10/kappa+p_Reference
*(1-p_Reference)/n_Beta10)
Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha))+pnorm(-z_Beta10-qnorm(1-alpha))) (
## [1] 0.9000024 0.9000024 0.9000024 0.9000024 0.9000024 0.9000024
<- as.data.frame(cbind(epsilon,n_Beta30,n_Beta20,n_Beta10))
TwoSampleUnpairedDesign.Superiority names(TwoSampleUnpairedDesign.Superiority) <- c("Cure.Rate.Change",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(TwoSampleUnpairedDesign.Superiority,
TwoSampleUnpairedDesign.Superiority.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("TSUD_SUPERIORITY",nrow(TwoSampleUnpairedDesign.Superiority.Reshaped))
TwoSampleUnpairedDesign.Superiority.Reshaped
TwoSampleUnpairedDesign.Superiority.Reshaped
## Cure.Rate.Change Power Sample.Size Label
## 1 0.20 Power=70% 51.55897 TSUD_SUPERIORITY
## 2 0.22 Power=70% 40.06872 TSUD_SUPERIORITY
## 3 0.24 Power=70% 31.63684 TSUD_SUPERIORITY
## 4 0.26 Power=70% 25.27660 TSUD_SUPERIORITY
## 5 0.28 Power=70% 20.36801 TSUD_SUPERIORITY
## 6 0.30 Power=70% 16.50584 TSUD_SUPERIORITY
## 7 0.20 Power=80% 67.74098 TSUD_SUPERIORITY
## 8 0.22 Power=80% 52.64447 TSUD_SUPERIORITY
## 9 0.24 Power=80% 41.56620 TSUD_SUPERIORITY
## 10 0.26 Power=80% 33.20978 TSUD_SUPERIORITY
## 11 0.28 Power=80% 26.76060 TSUD_SUPERIORITY
## 12 0.30 Power=80% 21.68627 TSUD_SUPERIORITY
## 13 0.20 Power=90% 93.83228 TSUD_SUPERIORITY
## 14 0.22 Power=90% 72.92116 TSUD_SUPERIORITY
## 15 0.24 Power=90% 57.57595 TSUD_SUPERIORITY
## 16 0.26 Power=90% 46.00094 TSUD_SUPERIORITY
## 17 0.28 Power=90% 37.06778 TSUD_SUPERIORITY
## 18 0.30 Power=90% 30.03901 TSUD_SUPERIORITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(TwoSampleUnpairedDesign.Superiority.Reshaped,
(TwoSampleUnpairedDesign.Superiority.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Two-Sample Unpaired Design : Test for Superiority"))
##################################
# Defining a range of possible hypothesized values for epsilon
##################################
=seq(0.20,0.30,0.02)
epsilon
##################################
# Defining a fixed hypothesized value for p_Reference
##################################
=0.65
p_Reference
##################################
# Defining a range of possible hypothesized values for p_ResponseRate
##################################
p_ResponseRate=p_Reference + epsilon) (
## [1] 0.85 0.87 0.89 0.91 0.93 0.95
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the non-inferiority delta
##################################
= 0.02
delta
##################################
# Defining a fixed hypothesized value for kappa
##################################
=1.0
kappa
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_1/2))/
(abs(p_ResponseRate-p_Reference)-delta))^2) (
## [1] 78.77165 61.21689 48.33467 38.61752 31.11818 25.21757
ceiling(n_Beta30)
## [1] 79 62 49 39 32 26
=(abs(p_ResponseRate-p_Reference)-delta)/
z_Beta30sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta30/kappa+p_Reference
*(1-p_Reference)/n_Beta30)
Power_Beta30=2*(pnorm(z_Beta30-qnorm(1-alpha))+pnorm(-z_Beta30-qnorm(1-alpha)))-1) (
## [1] 0.7000152 0.7000152 0.7000152 0.7000152 0.7000152 0.7000152
=beta[2]
beta_2n_Beta20=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_2/2))/
(abs(p_ResponseRate-p_Reference)-delta))^2) (
## [1] 93.83228 72.92116 57.57595 46.00094 37.06778 30.03901
ceiling(n_Beta20)
## [1] 94 73 58 47 38 31
=(abs(p_ResponseRate-p_Reference)-p_Reference-delta)/
z_Beta20sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta20/kappa+p_Reference
*(1-p_Reference)/n_Beta20)
Power_Beta20=2*(pnorm(z_Beta20-qnorm(1-alpha))+pnorm(-z_Beta20-qnorm(1-alpha)))-1) (
## [1] 1.0000000 0.9999992 0.9999540 0.9992047 0.9939444 0.9737290
=beta[3]
beta_3n_Beta10=(p_ResponseRate*(1-p_ResponseRate)/kappa+p_Reference*
(1-p_Reference))*((qnorm(1-alpha)+qnorm(1-beta_3/2))/
(abs(p_ResponseRate-p_Reference)-delta))^2) (
## [1] 118.57629 92.15081 72.75900 58.13161 46.84272 37.96043
ceiling(n_Beta10)
## [1] 119 93 73 59 47 38
=(abs(p_ResponseRate-p_Reference)-delta)/
z_Beta10sqrt(p_ResponseRate*(1-p_ResponseRate)/n_Beta10/kappa+p_Reference
*(1-p_Reference)/n_Beta10)
Power_Beta10=2*(pnorm(z_Beta10-qnorm(1-alpha))+pnorm(-z_Beta10-qnorm(1-alpha)))-1) (
## [1] 0.9000008 0.9000008 0.9000008 0.9000008 0.9000008 0.9000008
<- as.data.frame(cbind(epsilon,n_Beta30,n_Beta20,n_Beta10))
TwoSampleUnpairedDesign.Equivalence names(TwoSampleUnpairedDesign.Equivalence) <- c("Cure.Rate.Change",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(TwoSampleUnpairedDesign.Equivalence,
TwoSampleUnpairedDesign.Equivalence.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("TSUD_EQUIVALENCE",nrow(TwoSampleUnpairedDesign.Equivalence.Reshaped))
TwoSampleUnpairedDesign.Equivalence.Reshaped
TwoSampleUnpairedDesign.Equivalence.Reshaped
## Cure.Rate.Change Power Sample.Size Label
## 1 0.20 Power=70% 78.77165 TSUD_EQUIVALENCE
## 2 0.22 Power=70% 61.21689 TSUD_EQUIVALENCE
## 3 0.24 Power=70% 48.33467 TSUD_EQUIVALENCE
## 4 0.26 Power=70% 38.61752 TSUD_EQUIVALENCE
## 5 0.28 Power=70% 31.11818 TSUD_EQUIVALENCE
## 6 0.30 Power=70% 25.21757 TSUD_EQUIVALENCE
## 7 0.20 Power=80% 93.83228 TSUD_EQUIVALENCE
## 8 0.22 Power=80% 72.92116 TSUD_EQUIVALENCE
## 9 0.24 Power=80% 57.57595 TSUD_EQUIVALENCE
## 10 0.26 Power=80% 46.00094 TSUD_EQUIVALENCE
## 11 0.28 Power=80% 37.06778 TSUD_EQUIVALENCE
## 12 0.30 Power=80% 30.03901 TSUD_EQUIVALENCE
## 13 0.20 Power=90% 118.57629 TSUD_EQUIVALENCE
## 14 0.22 Power=90% 92.15081 TSUD_EQUIVALENCE
## 15 0.24 Power=90% 72.75900 TSUD_EQUIVALENCE
## 16 0.26 Power=90% 58.13161 TSUD_EQUIVALENCE
## 17 0.28 Power=90% 46.84272 TSUD_EQUIVALENCE
## 18 0.30 Power=90% 37.96043 TSUD_EQUIVALENCE
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(TwoSampleUnpairedDesign.Equivalence.Reshaped,
(TwoSampleUnpairedDesign.Equivalence.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Two-Sample Unpaired Design : Test for Equivalence"))
<- ggplot(TwoSampleUnpairedDesign.Equality.Reshaped,
TSUD_EQUALITY.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(TwoSampleUnpairedDesign.NonInferiority.Reshaped,
TSUD_NONINFERIORITY.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(TwoSampleUnpairedDesign.Superiority.Reshaped,
TSUD_SUPERIORITY.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(TwoSampleUnpairedDesign.Equivalence.Reshaped,
TSUD_EQUIVALENCE.PowerAnalysis aes(x=Cure.Rate.Change,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Cure Rate Change",
limits=c(0.2,0.3),
breaks=seq(0.2,0.3,by=0.02)) +
scale_y_continuous(name="Sample Size Per Group",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggarrange(TSUD_EQUALITY.PowerAnalysis,
TSUD_PowerAnalysis
TSUD_NONINFERIORITY.PowerAnalysis,
TSUD_SUPERIORITY.PowerAnalysis,
TSUD_EQUIVALENCE.PowerAnalysis,ncol=2, nrow=2)
annotate_figure(TSUD_PowerAnalysis,
top = text_grob("Two-Sample Unpaired Design Power Analysis by Statistical Hypothesis",
color = "black",
face = "bold",
size = 14))
##################################
# Defining a range of possible hypothesized values for P10
##################################
=seq(0.50,0.60,0.02)
p_10
##################################
# Defining a fixed hypothesized value for P01
##################################
=0.20
p_01
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Computing the categorical shifts
##################################
=p_10 + p_01
p_Disc=p_10 - p_01
p_Diff
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=((qnorm(1-alpha/2)*sqrt(p_Disc)+qnorm(1-beta_1)*sqrt(p_Disc-p_Diff^2))/p_Diff)^2) (
## [1] 46.66682 42.05514 38.16335 34.84341 31.98406 29.50026
ceiling(n_Beta30)
## [1] 47 43 39 35 32 30
=( p_Diff*sqrt(n_Beta30)-qnorm(1-alpha/2)*sqrt(p_Disc))/sqrt(p_Disc-p_Diff^2)
x1_Beta30=(-p_Diff*sqrt(n_Beta30)-qnorm(1-alpha/2)*sqrt(p_Disc))/sqrt(p_Disc-p_Diff^2)
x2_Beta30Power_Beta30 = pnorm(x1_Beta30)+pnorm(x2_Beta30)) (
## [1] 0.7000012 0.7000010 0.7000008 0.7000007 0.7000006 0.7000005
=beta[2]
beta_2n_Beta20=((qnorm(1-alpha/2)*sqrt(p_Disc)+qnorm(1-beta_2)*sqrt(p_Disc-p_Diff^2))/p_Diff)^2) (
## [1] 58.63224 52.76633 47.81581 43.59246 39.95477 36.79460
ceiling(n_Beta20)
## [1] 59 53 48 44 40 37
=( p_Diff*sqrt(n_Beta20)-qnorm(1-alpha/2)*sqrt(p_Disc))/sqrt(p_Disc-p_Diff^2)
x1_Beta20=(-p_Diff*sqrt(n_Beta20)-qnorm(1-alpha/2)*sqrt(p_Disc))/sqrt(p_Disc-p_Diff^2)
x2_Beta20Power_Beta20 = pnorm(x1_Beta20)+pnorm(x2_Beta20)) (
## [1] 0.8000002 0.8000002 0.8000002 0.8000001 0.8000001 0.8000001
=beta[3]
beta_3n_Beta10=((qnorm(1-alpha/2)*sqrt(p_Disc)+qnorm(1-beta_3)*sqrt(p_Disc-p_Diff^2))/p_Diff)^2) (
## [1] 77.48385 69.62986 63.00128 57.34612 52.47493 48.24297
ceiling(n_Beta10)
## [1] 78 70 64 58 53 49
=( p_Diff*sqrt(n_Beta10)-qnorm(1-alpha/2)*sqrt(p_Disc))/sqrt(p_Disc-p_Diff^2)
x1_Beta10=(-p_Diff*sqrt(n_Beta10)-qnorm(1-alpha/2)*sqrt(p_Disc))/sqrt(p_Disc-p_Diff^2)
x2_Beta10Power_Beta10 = pnorm(x1_Beta10)+pnorm(x2_Beta10)) (
## [1] 0.9 0.9 0.9 0.9 0.9 0.9
<- as.data.frame(cbind(p_01,p_10,n_Beta30,n_Beta20,n_Beta10))
TwoSamplePairedDesign.CategoricalShift names(TwoSamplePairedDesign.CategoricalShift) <- c("Categorical.Shift.P01",
"Categorical.Shift.P10",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(TwoSamplePairedDesign.CategoricalShift,
TwoSamplePairedDesign.CategoricalShift.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("TSPD_CATEGORICALSHIFT",nrow(TwoSamplePairedDesign.CategoricalShift.Reshaped))
TwoSamplePairedDesign.CategoricalShift.Reshaped
TwoSamplePairedDesign.CategoricalShift.Reshaped
## Categorical.Shift.P01 Categorical.Shift.P10 Power Sample.Size
## 1 0.2 0.50 Power=70% 46.66682
## 2 0.2 0.52 Power=70% 42.05514
## 3 0.2 0.54 Power=70% 38.16335
## 4 0.2 0.56 Power=70% 34.84341
## 5 0.2 0.58 Power=70% 31.98406
## 6 0.2 0.60 Power=70% 29.50026
## 7 0.2 0.50 Power=80% 58.63224
## 8 0.2 0.52 Power=80% 52.76633
## 9 0.2 0.54 Power=80% 47.81581
## 10 0.2 0.56 Power=80% 43.59246
## 11 0.2 0.58 Power=80% 39.95477
## 12 0.2 0.60 Power=80% 36.79460
## 13 0.2 0.50 Power=90% 77.48385
## 14 0.2 0.52 Power=90% 69.62986
## 15 0.2 0.54 Power=90% 63.00128
## 16 0.2 0.56 Power=90% 57.34612
## 17 0.2 0.58 Power=90% 52.47493
## 18 0.2 0.60 Power=90% 48.24297
## Label
## 1 TSPD_CATEGORICALSHIFT
## 2 TSPD_CATEGORICALSHIFT
## 3 TSPD_CATEGORICALSHIFT
## 4 TSPD_CATEGORICALSHIFT
## 5 TSPD_CATEGORICALSHIFT
## 6 TSPD_CATEGORICALSHIFT
## 7 TSPD_CATEGORICALSHIFT
## 8 TSPD_CATEGORICALSHIFT
## 9 TSPD_CATEGORICALSHIFT
## 10 TSPD_CATEGORICALSHIFT
## 11 TSPD_CATEGORICALSHIFT
## 12 TSPD_CATEGORICALSHIFT
## 13 TSPD_CATEGORICALSHIFT
## 14 TSPD_CATEGORICALSHIFT
## 15 TSPD_CATEGORICALSHIFT
## 16 TSPD_CATEGORICALSHIFT
## 17 TSPD_CATEGORICALSHIFT
## 18 TSPD_CATEGORICALSHIFT
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(TwoSamplePairedDesign.CategoricalShift.Reshaped,
(TwoSamplePairedDesign.CategoricalShift.PowerAnalysis aes(x=Categorical.Shift.P10,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Categorical Shift (Hypoglycaemia to Normal)",
limits=c(0.5,0.6),
breaks=seq(0.5,0.6,by=0.02)) +
scale_y_continuous(name="Sample Size for Both Groups",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Two-Sample Paired Design : Test for Categorical Shift"))
<- ggplot(TwoSamplePairedDesign.CategoricalShift.Reshaped,
TSPD_CATEGORICALSHIFT.PowerAnalysis aes(x=Categorical.Shift.P10,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Categorical Shift (Hypoglycaemia to Normal)",
limits=c(0.5,0.6),
breaks=seq(0.5,0.6,by=0.02)) +
scale_y_continuous(name="Sample Size for Both Groups",
limits=c(0,120),
breaks=seq(0,120,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggarrange(TSPD_CATEGORICALSHIFT.PowerAnalysis,
TSPD_PowerAnalysis ncol=2, nrow=2)
annotate_figure(TSPD_PowerAnalysis,
top = text_grob("Two-Sample Paired Design Power Analysis by Statistical Hypothesis",
color = "black",
face = "bold",
size = 14))
##################################
# Defining a fixed hypothesized value for p_A
##################################
=0.20
p_AF
##################################
# Defining a range of hypothesized values for p_B
##################################
=seq(0.40,0.50,0.02)
p_BR
##################################
# Defining a fixed hypothesized value for p_B
# using the highest value from the range
##################################
=0.50
p_BF
##################################
# Defining a range of hypothesized values for p_C
##################################
=seq(0.70,0.80,0.02)
p_CR
##################################
# Defining a fixed hypothesized value for the Type I error
##################################
=0.05
alpha
##################################
# Defining a range of possible hypothesized values for the Type II error
##################################
=c(0.30,0.20,0.10)
beta
##################################
# Defining the number of treatments
##################################
=3
tau
##################################
# Conducting a pairwise comparison
# between Treatments A and B
##################################
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_AF*(1-p_AF)+p_BR*(1-p_BR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_1))/(p_AF-p_BR))^2) ((
## [1] 85.16944 71.02146 60.09177 51.45443 44.49669 38.79941
ceiling(n_Beta30)
## [1] 86 72 61 52 45 39
=(p_AF-p_BR)/sqrt(p_AF*(1-p_AF)/n_Beta30+p_BR*(1-p_BR)/n_Beta30)
z_Beta30Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha/2/tau))+pnorm(-z_Beta30-qnorm(1-alpha/2/tau))) (
## [1] 0.7000001 0.7000001 0.7000001 0.7000001 0.7000001 0.7000001
=beta[2]
beta_2n_Beta20=(p_AF*(1-p_AF)+p_BR*(1-p_BR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_2))/(p_AF-p_BR))^2) ((
## [1] 104.69114 87.30030 73.86542 63.24832 54.69578 47.69263
ceiling(n_Beta20)
## [1] 105 88 74 64 55 48
=(p_AF-p_BR)/sqrt(p_AF*(1-p_AF)/n_Beta20+p_BR*(1-p_BR)/n_Beta20)
z_Beta20Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha/2/tau))+pnorm(-z_Beta20-qnorm(1-alpha/2/tau))) (
## [1] 0.8 0.8 0.8 0.8 0.8 0.8
=beta[3]
beta_3n_Beta10=(p_AF*(1-p_AF)+p_BR*(1-p_BR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_3))/(p_AF-p_BR))^2) ((
## [1] 135.09531 112.65386 95.31725 81.61675 70.58041 61.54342
ceiling(n_Beta10)
## [1] 136 113 96 82 71 62
=(p_AF-p_BR)/sqrt(p_AF*(1-p_AF)/n_Beta10+p_BR*(1-p_BR)/n_Beta10)
z_Beta10Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha/2/tau))+pnorm(-z_Beta10-qnorm(1-alpha/2/tau))) (
## [1] 0.9 0.9 0.9 0.9 0.9 0.9
<- as.data.frame(cbind(p_AF,p_BR,n_Beta30,n_Beta20,n_Beta10))
MultipleSampleDesign.AB.Equality names(MultipleSampleDesign.AB.Equality) <- c("Treatment_A.Response.Rate",
"Treatment_B.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(MultipleSampleDesign.AB.Equality,
MultipleSampleDesign.AB.Equality.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("MSDOWAP_AB_EQUALITY",nrow(MultipleSampleDesign.AB.Equality.Reshaped))
MultipleSampleDesign.AB.Equality.Reshaped
MultipleSampleDesign.AB.Equality.Reshaped
## Treatment_A.Response.Rate Treatment_B.Response.Rate Power Sample.Size
## 1 0.2 0.40 Power=70% 85.16944
## 2 0.2 0.42 Power=70% 71.02146
## 3 0.2 0.44 Power=70% 60.09177
## 4 0.2 0.46 Power=70% 51.45443
## 5 0.2 0.48 Power=70% 44.49669
## 6 0.2 0.50 Power=70% 38.79941
## 7 0.2 0.40 Power=80% 104.69114
## 8 0.2 0.42 Power=80% 87.30030
## 9 0.2 0.44 Power=80% 73.86542
## 10 0.2 0.46 Power=80% 63.24832
## 11 0.2 0.48 Power=80% 54.69578
## 12 0.2 0.50 Power=80% 47.69263
## 13 0.2 0.40 Power=90% 135.09531
## 14 0.2 0.42 Power=90% 112.65386
## 15 0.2 0.44 Power=90% 95.31725
## 16 0.2 0.46 Power=90% 81.61675
## 17 0.2 0.48 Power=90% 70.58041
## 18 0.2 0.50 Power=90% 61.54342
## Label
## 1 MSDOWAP_AB_EQUALITY
## 2 MSDOWAP_AB_EQUALITY
## 3 MSDOWAP_AB_EQUALITY
## 4 MSDOWAP_AB_EQUALITY
## 5 MSDOWAP_AB_EQUALITY
## 6 MSDOWAP_AB_EQUALITY
## 7 MSDOWAP_AB_EQUALITY
## 8 MSDOWAP_AB_EQUALITY
## 9 MSDOWAP_AB_EQUALITY
## 10 MSDOWAP_AB_EQUALITY
## 11 MSDOWAP_AB_EQUALITY
## 12 MSDOWAP_AB_EQUALITY
## 13 MSDOWAP_AB_EQUALITY
## 14 MSDOWAP_AB_EQUALITY
## 15 MSDOWAP_AB_EQUALITY
## 16 MSDOWAP_AB_EQUALITY
## 17 MSDOWAP_AB_EQUALITY
## 18 MSDOWAP_AB_EQUALITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(MultipleSampleDesign.AB.Equality.Reshaped,
(MultipleSampleDesign.AB.Equality.PowerAnalysis aes(x=Treatment_B.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Clinical Response Rate for Treatment B",
limits=c(0.40,0.50),
breaks=seq(0.40,0.50,by=0.02)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,160),
breaks=seq(0,160,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Multiple-Sample Design : Test for Equality Between A Versus B"))
##################################
# Conducting a pairwise comparison
# between Treatments A and C
##################################
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_AF*(1-p_AF)+p_CR*(1-p_CR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_1))/(p_AF-p_CR))^2) ((
## [1] 12.605077 11.389522 10.292767 9.299112 8.395418 7.570617
ceiling(n_Beta30)
## [1] 13 12 11 10 9 8
=(p_AF-p_CR)/sqrt(p_AF*(1-p_AF)/n_Beta30+p_CR*(1-p_CR)/n_Beta30)
z_Beta30Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha/2/tau))+pnorm(-z_Beta30-qnorm(1-alpha/2/tau))) (
## [1] 0.7000001 0.7000001 0.7000001 0.7000001 0.7000001 0.7000001
=beta[2]
beta_2n_Beta20=(p_AF*(1-p_AF)+p_CR*(1-p_CR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_2))/(p_AF-p_CR))^2) ((
## [1] 15.494289 14.000117 12.651975 11.430563 10.319733 9.305879
ceiling(n_Beta20)
## [1] 16 15 13 12 11 10
=(p_AF-p_CR)/sqrt(p_AF*(1-p_AF)/n_Beta20+p_CR*(1-p_CR)/n_Beta20)
z_Beta20Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha/2/tau))+pnorm(-z_Beta20-qnorm(1-alpha/2/tau))) (
## [1] 0.8 0.8 0.8 0.8 0.8 0.8
=beta[3]
beta_3n_Beta10=(p_AF*(1-p_AF)+p_CR*(1-p_CR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_3))/(p_AF-p_CR))^2) ((
## [1] 19.99411 18.06600 16.32633 14.75020 13.31677 12.00847
ceiling(n_Beta10)
## [1] 20 19 17 15 14 13
=(p_AF-p_CR)/sqrt(p_AF*(1-p_AF)/n_Beta10+p_CR*(1-p_CR)/n_Beta10)
z_Beta10Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha/2/tau))+pnorm(-z_Beta10-qnorm(1-alpha/2/tau))) (
## [1] 0.9 0.9 0.9 0.9 0.9 0.9
<- as.data.frame(cbind(p_AF,p_CR,n_Beta30,n_Beta20,n_Beta10))
MultipleSampleDesign.AC.Equality names(MultipleSampleDesign.AC.Equality) <- c("Treatment_A.Response.Rate",
"Treatment_B.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(MultipleSampleDesign.AC.Equality,
MultipleSampleDesign.AC.Equality.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("MSDOWAP_AC_EQUALITY",nrow(MultipleSampleDesign.AC.Equality.Reshaped))
MultipleSampleDesign.AC.Equality.Reshaped
MultipleSampleDesign.AC.Equality.Reshaped
## Treatment_A.Response.Rate Treatment_B.Response.Rate Power Sample.Size
## 1 0.2 0.70 Power=70% 12.605077
## 2 0.2 0.72 Power=70% 11.389522
## 3 0.2 0.74 Power=70% 10.292767
## 4 0.2 0.76 Power=70% 9.299112
## 5 0.2 0.78 Power=70% 8.395418
## 6 0.2 0.80 Power=70% 7.570617
## 7 0.2 0.70 Power=80% 15.494289
## 8 0.2 0.72 Power=80% 14.000117
## 9 0.2 0.74 Power=80% 12.651975
## 10 0.2 0.76 Power=80% 11.430563
## 11 0.2 0.78 Power=80% 10.319733
## 12 0.2 0.80 Power=80% 9.305879
## 13 0.2 0.70 Power=90% 19.994106
## 14 0.2 0.72 Power=90% 18.066000
## 15 0.2 0.74 Power=90% 16.326333
## 16 0.2 0.76 Power=90% 14.750202
## 17 0.2 0.78 Power=90% 13.316767
## 18 0.2 0.80 Power=90% 12.008472
## Label
## 1 MSDOWAP_AC_EQUALITY
## 2 MSDOWAP_AC_EQUALITY
## 3 MSDOWAP_AC_EQUALITY
## 4 MSDOWAP_AC_EQUALITY
## 5 MSDOWAP_AC_EQUALITY
## 6 MSDOWAP_AC_EQUALITY
## 7 MSDOWAP_AC_EQUALITY
## 8 MSDOWAP_AC_EQUALITY
## 9 MSDOWAP_AC_EQUALITY
## 10 MSDOWAP_AC_EQUALITY
## 11 MSDOWAP_AC_EQUALITY
## 12 MSDOWAP_AC_EQUALITY
## 13 MSDOWAP_AC_EQUALITY
## 14 MSDOWAP_AC_EQUALITY
## 15 MSDOWAP_AC_EQUALITY
## 16 MSDOWAP_AC_EQUALITY
## 17 MSDOWAP_AC_EQUALITY
## 18 MSDOWAP_AC_EQUALITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(MultipleSampleDesign.AC.Equality.Reshaped,
(MultipleSampleDesign.AC.Equality.PowerAnalysis aes(x=Treatment_B.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Clinical Response Rate for Treatment C",
limits=c(0.70,0.80),
breaks=seq(0.70,0.80,by=0.02)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,160),
breaks=seq(0,160,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Multiple-Sample Design : Test for Equality Between A Versus C"))
##################################
# Conducting a pairwise comparison
# between Treatments B and C
##################################
##################################
# Computing the range of samples sizes based on different levels of Type II errors
##################################
=beta[1]
beta_1n_Beta30=(p_BF*(1-p_BF)+p_CR*(1-p_CR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_1))/(p_BF-p_CR))^2) ((
## [1] 97.94485 79.46801 65.41486 54.47820 45.80030 38.79941
ceiling(n_Beta30)
## [1] 98 80 66 55 46 39
=(p_BF-p_CR)/sqrt(p_BF*(1-p_BF)/n_Beta30+p_CR*(1-p_CR)/n_Beta30)
z_Beta30Power_Beta30=pnorm(z_Beta30-qnorm(1-alpha/2/tau))+pnorm(-z_Beta30-qnorm(1-alpha/2/tau))) (
## [1] 0.7000001 0.7000001 0.7000001 0.7000001 0.7000001 0.7000001
=beta[2]
beta_2n_Beta20=(p_BF*(1-p_BF)+p_CR*(1-p_CR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_2))/(p_BF-p_CR))^2) ((
## [1] 120.39481 97.68289 80.40861 66.96516 56.29819 47.69263
ceiling(n_Beta20)
## [1] 121 98 81 67 57 48
=(p_BF-p_CR)/sqrt(p_BF*(1-p_BF)/n_Beta20+p_CR*(1-p_CR)/n_Beta20)
z_Beta20Power_Beta20=pnorm(z_Beta20-qnorm(1-alpha/2/tau))+pnorm(-z_Beta20-qnorm(1-alpha/2/tau))) (
## [1] 0.8 0.8 0.8 0.8 0.8 0.8
=beta[3]
beta_3n_Beta10=(p_BF*(1-p_BF)+p_CR*(1-p_CR))*
(qnorm(1-alpha/2/tau)+qnorm(1-beta_3))/(p_BF-p_CR))^2) ((
## [1] 155.35960 126.05174 103.76070 86.41303 72.64819 61.54342
ceiling(n_Beta10)
## [1] 156 127 104 87 73 62
=(p_BF-p_CR)/sqrt(p_BF*(1-p_BF)/n_Beta10+p_CR*(1-p_CR)/n_Beta10)
z_Beta10Power_Beta10=pnorm(z_Beta10-qnorm(1-alpha/2/tau))+pnorm(-z_Beta10-qnorm(1-alpha/2/tau))) (
## [1] 0.9 0.9 0.9 0.9 0.9 0.9
<- as.data.frame(cbind(p_BF,p_CR,n_Beta30,n_Beta20,n_Beta10))
MultipleSampleDesign.BC.Equality names(MultipleSampleDesign.BC.Equality) <- c("Treatment_A.Response.Rate",
"Treatment_B.Response.Rate",
"Power=70%",
"Power=80%",
"Power=90%")
##################################
# Restructuring the data
##################################
<- gather(MultipleSampleDesign.BC.Equality,
MultipleSampleDesign.BC.Equality.Reshaped "Power=70%","Power=80%","Power=90%",
key="Power",
value="Sample.Size")
$Label <- rep("MSDOWAP_BC_EQUALITY",nrow(MultipleSampleDesign.BC.Equality.Reshaped))
MultipleSampleDesign.BC.Equality.Reshaped
MultipleSampleDesign.BC.Equality.Reshaped
## Treatment_A.Response.Rate Treatment_B.Response.Rate Power Sample.Size
## 1 0.5 0.70 Power=70% 97.94485
## 2 0.5 0.72 Power=70% 79.46801
## 3 0.5 0.74 Power=70% 65.41486
## 4 0.5 0.76 Power=70% 54.47820
## 5 0.5 0.78 Power=70% 45.80030
## 6 0.5 0.80 Power=70% 38.79941
## 7 0.5 0.70 Power=80% 120.39481
## 8 0.5 0.72 Power=80% 97.68289
## 9 0.5 0.74 Power=80% 80.40861
## 10 0.5 0.76 Power=80% 66.96516
## 11 0.5 0.78 Power=80% 56.29819
## 12 0.5 0.80 Power=80% 47.69263
## 13 0.5 0.70 Power=90% 155.35960
## 14 0.5 0.72 Power=90% 126.05174
## 15 0.5 0.74 Power=90% 103.76070
## 16 0.5 0.76 Power=90% 86.41303
## 17 0.5 0.78 Power=90% 72.64819
## 18 0.5 0.80 Power=90% 61.54342
## Label
## 1 MSDOWAP_BC_EQUALITY
## 2 MSDOWAP_BC_EQUALITY
## 3 MSDOWAP_BC_EQUALITY
## 4 MSDOWAP_BC_EQUALITY
## 5 MSDOWAP_BC_EQUALITY
## 6 MSDOWAP_BC_EQUALITY
## 7 MSDOWAP_BC_EQUALITY
## 8 MSDOWAP_BC_EQUALITY
## 9 MSDOWAP_BC_EQUALITY
## 10 MSDOWAP_BC_EQUALITY
## 11 MSDOWAP_BC_EQUALITY
## 12 MSDOWAP_BC_EQUALITY
## 13 MSDOWAP_BC_EQUALITY
## 14 MSDOWAP_BC_EQUALITY
## 15 MSDOWAP_BC_EQUALITY
## 16 MSDOWAP_BC_EQUALITY
## 17 MSDOWAP_BC_EQUALITY
## 18 MSDOWAP_BC_EQUALITY
##################################
# Plotting the sample sizes and power curves
##################################
<- ggplot(MultipleSampleDesign.BC.Equality.Reshaped,
(MultipleSampleDesign.BC.Equality.PowerAnalysis aes(x=Treatment_B.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Clinical Response Rate for Treatment C",
limits=c(0.70,0.80),
breaks=seq(0.70,0.80,by=0.02)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,160),
breaks=seq(0,160,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50)) +
ggtitle("Multiple-Sample Design : Test for Equality Between B Versus C"))
##################################
# Consolidating the power analyses charts
##################################
<- ggplot(MultipleSampleDesign.AB.Equality.Reshaped,
MSDOWAP.AB.Equality.PowerAnalysis aes(x=Treatment_B.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Clinical Response Rate for Treatment B",
limits=c(0.40,0.50),
breaks=seq(0.40,0.50,by=0.02)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,160),
breaks=seq(0,160,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(MultipleSampleDesign.AC.Equality.Reshaped,
MSDOWAP.AC.Equality.PowerAnalysis aes(x=Treatment_B.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Clinical Response Rate for Treatment C",
limits=c(0.70,0.80),
breaks=seq(0.70,0.80,by=0.02)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,160),
breaks=seq(0,160,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggplot(MultipleSampleDesign.BC.Equality.Reshaped,
MSDOWAP.BC.Equality.PowerAnalysis aes(x=Treatment_B.Response.Rate,
y=Sample.Size,
color=Power)) +
geom_line(size=1)+
geom_point(size=4)+
theme_bw() +
facet_grid(. ~ Label) +
scale_color_brewer(palette="Paired") +
scale_x_continuous(name="Hypothesized Clinical Response Rate for Treatment C",
limits=c(0.70,0.80),
breaks=seq(0.70,0.80,by=0.02)) +
scale_y_continuous(name="Treatment Group Sample Size",
limits=c(0,160),
breaks=seq(0,160,by=10)) +
theme(axis.title.x=element_text(color="black",face="bold",size=12),
legend.position="top",
axis.title.y=element_text(color="black",face="bold",size=12),
plot.title=element_text(color="black",size=14,face="bold",hjust=0.50))
<- ggarrange(MSDOWAP.AB.Equality.PowerAnalysis,
MSDOWAP_PowerAnalysis
MSDOWAP.AC.Equality.PowerAnalysis,
MSDOWAP.BC.Equality.PowerAnalysis,ncol=2, nrow=2)
annotate_figure(MSDOWAP_PowerAnalysis,
top = text_grob("Multiple-Sample Design One-Way ANOVA Power Analysis by Pairwise Comparison",
color = "black",
face = "bold",
size = 14))