Type: | Package |
Title: | Design and Analysis of Non-Inferiority Trials |
Version: | 0.1-1 |
Date: | 2020-01-20 |
Author: | Matteo Quartagno |
Maintainer: | Matteo Quartagno <m.quartagno@ucl.ac.uk> |
Description: | Provides tools to help the design and analysis of resilient non-inferiority trials. These include functions for sample size calculations and analyses of trials, with either a risk difference, risk ratio or arc-sine difference margin, and a function to run simulations to design a trial with the methods described in Quartagno et al. (2019) <doi:10.48550/arXiv.1905.00241>. |
License: | GPL-2 |
Depends: | Epi |
NeedsCompilation: | no |
Packaged: | 2020-01-20 11:53:31 UTC; rmjlmqu |
Repository: | CRAN |
Date/Publication: | 2020-01-20 12:20:02 UTC |
Plot power and type 1 error of a "Modify margin" Non-inferiority trial design
Description
A function for plotting power and type 1 error of a "Modify margin" Non-inferiority trial design after running simulations .
Usage
figure.modify.margin(simulations, nominal=NULL, col=NULL,
pch=16, lty=NULL, xlim=NULL, ylim=NULL)
Arguments
simulations |
A list obtained as an output from function simulations.modify.margin. |
nominal |
An optional argument to draw a red horizontal line specifying the nominal power or type 1 error. |
col |
A vector with colors of the different lines. See help file for the general plot function. |
pch |
A vector with plotting characters of the different lines. See help file for the general plot function. |
lty |
A vector with line types of the different lines. See help file for the general plot function. |
xlim , ylim |
numeric vectors of length 2, giving the x and y coordinates ranges. |
Details
This is a function to plot power (type 1 error) of the modify margin procedures for different values of actual control event risk.
Examples
n.sim<-100 # In real applications use at least n.sim <- 10000
p0.expected<-0.05 # Expected control event rate
p1.expected<-p0.expected # Same as expected active event rate
p1.tolerable<-0.1 # Maximum tolerable active event rate
NI.marg<-p1.tolerable-p0.expected
r<-1 # Allocation ratio
power<-0.9 # Power
alph<-0.025 # Significance level
alph.an<-c(0.01,0.015,0.02,0.025) # Significance level
range.of.p0<-seq(0.005,0.20,0.005)
# Power - risk difference
res<-simulations.modify.margin(p0.expected, p1.expected, p1.tolerable,
thresholds=c(Inf, 0.0125,0.025,0.05),
range.of.p0=range.of.p0, sig.level.design=alph, sig.level.analysis=alph, power=power,
r=r, scale="RD", print.out=TRUE, ran.seed=1, n.sim=n.sim)
figure.modify.margin(res, 0.9)
res2<-simulations.modify.margin(p0.expected, p1.expected, p1.tolerable,
thresholds=c(Inf, 0.0125,0.025,0.05),
range.of.p0=range.of.p0, sig.level.design=alph, sig.level.analysis=alph, power=power,
r=r, scale="RD", print.out=TRUE, ran.seed=1, n.sim=n.sim, perf.measure="type1error")
figure.modify.margin(res2, 0.025)
Sample size calculation tool for Non-Inferiority trials
Description
A function for calculating sample size of a non-inferiority trial.
Usage
sample.size.NI(p0.expected, p1.expected, p1.tolerable, sig.level=0.025, power=0.9, r=1,
scale="RD", print.out=TRUE)
Arguments
p0.expected |
Expected event risk in the control arm. |
p1.expected |
Expected event risk in the active arm. |
p1.tolerable |
Maximum tolerable active event risk for declaring non-inferiority. |
sig.level |
One-sided significance level for testing. Default is 0.025, i.e. 2.5%. |
power |
Power of the trial, i.e. one minus type-II error of the study. Default is 0.9, i.e.90%. |
r |
Allocation ratio, i.e. ratio between sample sizes in the active and control goups. Deafault is 1. |
scale |
The scale on which we define the non-inferiority trial. Can be one of "RD" (Risk difference), "RR" (log-risk ratio) or "AS" (arc-sine difference). |
print.out |
Logical. If FALSE, no output is printed. |
Details
This is a function to calculate sample size needed to test non-inferiority of an active treatment against the control within a specific NI margin. The margin can be specified on a number of different scales, which give different answers.
Value
The output is a vector ss, containing the sample sizes for the control and active arms respectively.
Examples
p0.expected<-0.05 # Expected control event rate
p1.expected<-p0.expected # Same as expected active event rate
p1.tolerable<-0.1 # Maximum tolerable active event rate
r<-1 # Allocation ratio
power<-0.9 # Power
alph<-0.025 # Significance level
sample.size.RD<-sample.size.NI(sig.level=alph, power=power,
p0.expected=p0.expected, p1.expected=p1.expected,
p1.tolerable=p1.tolerable, r=r) # Risk difference scale
sample.size.lRR<-sample.size.NI(sig.level=alph, power=power,
p0.expected=p0.expected, p1.expected=p1.expected,
p1.tolerable=p1.tolerable, r=r, scale="RR") # Log-risk ratio scale
sample.size.AS<-sample.size.NI(sig.level=alph, power=power,
p0.expected=p0.expected, p1.expected=p1.expected,
p1.tolerable=p1.tolerable, r=r, scale="AS") # Arc-sine difference scale
Power and type 1 error of a "Modify margin" Non-inferiority trial design
Description
A function for running simulations to investigate power and type 1 error of a "Modify margin" Non-inferiority trial design.
Usage
simulations.modify.margin(p0.expected, p1.expected, p1.tolerable, thresholds=c(0, Inf),
range.of.p0=NULL, sig.level.design=0.025, sig.level.analysis=0.025,
power=0.9, r=1, scale="RD", print.out=TRUE, ran.seed=1, n.sim=10000,
perf.measure="power")
Arguments
p0.expected |
Expected event risk in the control arm. |
p1.expected |
Expected event risk in the active arm. |
p1.tolerable |
Maximum tolerable event risk in the active arm. |
thresholds |
A vector with the thresholds for modifying the non-inferiority margin to be compared. Inf indicates the never modify margin procedure, while 0 the always modify margin. |
range.of.p0 |
The values of true control event risk on which to explore the inferential properties of the methods. |
sig.level.design |
One-sided significance level for testing used at the design stage. Default is 0.025, i.e. 2.5%. |
sig.level.analysis |
A vector with all the one-sided significance level(s) used for testing at the analysis stage. Default is a single level: 0.025, i.e. 2.5%. |
power |
Power of the trial, i.e. one minus type-II error of the study. Default is 0.9, i.e.90%. |
r |
Allocation ratio, i.e. ratio between sample sizes in the active and control goups. Deafault is 1. |
scale |
The scale on which we define the non-inferiority trial. Can be one of "RD" (Risk difference) or "RR" (log-risk ratio). |
print.out |
Logical. If FALSE, no output is printed. |
ran.seed |
The value to be used to initialise the random seed to obtain replicable results. |
n.sim |
Number of simulations to be performed. Defaults to 10000. |
perf.measure |
The performance measure to be used. It can be one of "power" or "type1error". |
Details
This is a function to perform simulations that can help the design of a non-inferiority trial by making it more resilient to unexpected control event risks. This is done by making use of the so-called "modify margin" procedure. The trial is designed as usual, using a certain value for the expected control event risk and defining the non-inferiority margin on either the risk difference or risk ratio scale. Then, when the trial is completed, the observed control event risk is compared with its a priori expectation and if the difference exceeds a certain threshold the margin is changed to a new value. The new value is chosen so that it reflects the so-called power-stabilising non-inferiority frontier (see paper in the references). At the design stage, this function can be used to find the optimal values of the threshold and of the significance level to be used in the analysis of the trial. First, it has to be run for different values of possible thresholds and for a fixed value of significance level for the analysis, equal to that used at the design stage. Then, if the preferred procedure inflates type 1 error in some areas, this function has to be re-run for different values of significance level, fixing the threshold to the one selected at the previous step.
Value
The output is a list containing:
- A matrix with the estimated power (or type-1 error) of each procedure in each scenario;
- A matrix with the proportion of margins that have been modified using each procedure in each scenario;
- A character variable, type, equal to "a" if the function has been used to find the optimal significance testing level and "t" if it has been used to find the optimal threshold;
- A variable with the scale on which the non-inferiority margin was defined at the design stage;
- A variable stating whetehr the function was used to estimate power or type 1 error.
Examples
n.sim<-30 # Note in applications we would used higher values, i.e. >=10000
p0.expected<-0.05 # Expected control event rate
p1.expected<-p0.expected # Same as expected active event rate
p1.tolerable<-0.1 # Maximum tolerable active event rate
r<-1 # Allocation ratio
power<-0.9 # Power
alph<-0.025 # Significance level
range.of.p0<-seq(0.005,0.20,0.005)
# Risk difference
res<-simulations.modify.margin(p0.expected, p1.expected, p1.tolerable,
thresholds=c(Inf, 0.0125,0.025,0.05), range.of.p0=range.of.p0, sig.level.design=alph,
sig.level.analysis=alph, power=power, r=r, scale="RD", print.out=TRUE,
ran.seed=1, n.sim=n.sim)
alph.an<-c(0.01,0.015,0.02,0.025) # Significance level
res2<-simulations.modify.margin(p0.expected, p1.expected, p1.tolerable, thresholds=c(0.0125),
range.of.p0=range.of.p0, sig.level.design=alph, sig.level.analysis=alph.an,
power=power, r=r, scale="RD", print.out=TRUE, ran.seed=1, n.sim=n.sim)
# Risk ratio
res3<-simulations.modify.margin(p0.expected, p1.expected, p1.tolerable,
thresholds=c(Inf, log(1.25),log(1.5),log(2)), range.of.p0=range.of.p0,
sig.level.design=alph, sig.level.analysis=alph, power=power, r=r,
scale="RR", print.out=TRUE, ran.seed=1, n.sim=n.sim)
res4<-simulations.modify.margin(p0.expected, p1.expected, p1.tolerable, thresholds=log(1.25),
range.of.p0=range.of.p0, sig.level.design=alph, sig.level.analysis=alph.an,
power=power, r=r, scale="RR", print.out=TRUE, ran.seed=1, n.sim=n.sim)
Non-inferiority test on different scales
Description
A function for testing non-inferiority on either the risk difference, log-risk ratio or arc-sine difference scale.
Usage
test.NI(n0, n1, e0, e1, NIm, sig.level=0.025, scale="RD", print.out=TRUE)
Arguments
e0 |
Number of events in the control arm. |
e1 |
Number of events in the active arm. |
n0 |
Total sample size of the control arm. |
n1 |
Total sample size of the active arm. |
NIm |
Non-inferiority margin on the specified scale. |
sig.level |
One-sided significance level for testing. Default is 0.025, i.e. 2.5%. |
scale |
The scale on which we define the non-inferiority margin. Can be one of "RD" (Risk difference), "RR" (log-risk ratio) or "AS" (arc-sine difference). |
print.out |
Logical. If FALSE, no output is printed. |
Details
This is a function to test non-inferiority of an active treatment against the control within a specific NI margin. The margin can be specified on a number of different scales.
Value
The output is a list, containing the estimate, standard error, cofidence interval (two-sided 2*alpha level), Z statistic and p-value. For the riskdifference scale, the CI is provided both with the standard normal approximation and using newcombe 10 method, as per function ci.pd in package Epi.
Examples
n0<-1000
n1<-1000
e0<-0.05*n0
e1<-0.05*n1
NImRD=0.05
NImRR=log(2)
NImAS=asin(sqrt(0.1))-asin(sqrt(0.05))
alpha=0.025
test<-test.NI(n0=n0, n1=n1, e0=e0, e1=e1, NIm=NImRD, sig.level=alpha, scale = "RD")
test2<-test.NI(n0=n0, n1=n1, e0=e0, e1=e1, NIm=NImRR, sig.level=alpha, scale = "RR")
test3<-test.NI(n0=n0, n1=n1, e0=e0, e1=e1, NIm=NImAS, sig.level=alpha, scale = "AS")