## run this chunk to produce md code for chunks
library('desmon')

txt <- sapply(rawr::lsp(desmon, 'exports'), function(x)
  tryCatch(
    c(sprintf('## `%s`: %s', x, rawr::helpExtract(x, show.sections = TRUE)[1]),
      '',
      rawr::helpExtract(x, section = 'desc'),
      '', '',
      gsub('`r', '`{r}', rawr::helpExtract(x, section = 'exam',
                                           type = 'md_code')),
      '', ''),
    error = function(e) x))

cat('\014')
for (ii in txt)
  cat(ii, sep = '\n')

# devtools::build_vignettes()
library('desmon')

acondpow: Compute Approximate Conditional Power

Computes an approximation to the conditional power of a sequential test based on the asymptotic normality of the statistic.

acondpow(2.0, 0.85, 0.32, 0.41)

Comparing binomials

b2diff

Given combined sample size and response probability, b2diff calculates the difference corresponding to a specified power.

b2diff(0.3, 0.1, 400)

b2n: sample size

Calculates sample size for a two sample binomial test based on a normal approximation with and without continuity correction. ‘b2p’ also computes the exact power of Fisher's exact test and the exact UMP unbiased test.

b2n(0.4, 0.2)

b2p: power

Calculates power for a two sample binomial test based on a normal approximation with and without continuity correction.

b2p(0.4, 0.2, 100, 100)

bin1samp: Sample Size for One-sample Exact Binomial Tests

Determines the minimum sample size for a one-sided, one-sample exact binomial test with specified alpha (type I) and beta (type II) errors

bin1samp(0.9, 0.95, n.min = 100)
bin1samp(0.1, 0.05, n.min = 100)

binci: Exact Binomial Confidence Limits

Calculates exact confidence bounds on a single binomial probability

binci(54, 88)

binsim: Simulation for Power of a Sequential Fisher's Exact Test

Performs a simulation to estimate the power of Fisher's Exect under group sequential monitoring.

set.seed(2)
binsim(20, 50, 0.1, 0.5, c(0.5, 1), c(0.05, 0.05), c(0.5, 0.5), alt = 'less')

condpow: Perform Simulation to Calculate Conditional Power of a Logrank Test

Performs a simulation to calculate conditional power of a logrank test in a group sequential experiment with exponential failure times.

## current data
set.seed(3)
ft <- c(rexp(100), rexp(100) / 0.95)
ct <- runif(200) * 3
fi <- ifelse(ct < ft, 0, 1)
ft <- pmin(ft, ct)
rx <- c(rep(0, 100), rep(1, 100))

## currently at 0.43 information -- assume no prior interim analyses
critv <- sequse(c(0.43, 0.7, 1))[-1]

condpow(ft, fi, rx, nsamp = 10, crit.val = critv, control.rate = 1, test.rate = 0.75,
        inf.time = c(0.7, 1), total.inf = 300, add.acc = 200, add.acc.period = 1)

#use larger nsamp in practice, eg
condpow(ft, fi, rx, nsamp = 1000, crit.val = critv, control.rate = 1, test.rate = 0.75,
        inf.time = c(0.7, 1), total.inf = 300, add.acc = 200, add.acc.period = 1)

condpowcure: Perform Simulation to Calculate Conditional Power of a Logrank Test

Performs a simulation to calculate conditional power of a logrank test in a group sequential experiment with failure times generated from a cure rate model.

## current data
set.seed(3)
ft <- c(ifelse(runif(100) < 0.6, rexp(100), 100), ifelse(runif(100) < 0.55,
        rexp(100) / 0.95, 100))
ct <- runif(200) * 4
fi <- ifelse(ct < ft, 0, 1)
ft <- pmin(ft, ct)
rx <- c(rep(0, 100), rep(1, 100))

## currently at .375 information -- assume no prior interim analyses
critv <- sequse(c(0.375, 0.7, 1))[-1]

condpowcure(ft, fi, rx, nsamp = 10, crit.val = critv, control.cure = 0.4,
            control.rate = 1, test.cure = 0.6, test.rate = 0.75,
            inf.time = c(0.7, 1), total.inf = 200, add.acc = 200, add.acc.period = 1)

## use larger nsamp in practice:
condpowcure(ft, fi, rx, nsamp = 1000, crit.val = critv, control.cure = 0.4,
            control.rate = 1, test.cure = 0.6, test.rate = 0.75,
            inf.time = c(0.7, 1), total.inf = 200, add.acc = 200, add.acc.period = 1)

Correlative studies

Computes power or difference for the logrank test for a correlative study comparing failure time distributions between groups defined by two levels of a correlative marker when there is a known amount of information (number of events).

Given a specified ratio, correl.power computes the power. Given a specified power, correl.ratio computes the corresponding hazard ratio (two ratios are computed, one for the difference in each direction).

correl.power, correl.ratio

correl.power(355, 172, 1.54, 0.4, 7, 4)
correl.power(355, 172, 3.36, 0.92, 7, 4)
correl.power(355, 172, 1.67, 0.7, 7, 4)

# check symmetry
correl.power(355, 172, 2 / 3, 0.5, 7, 4)
correl.power(355, 172, 1.5, 0.5, 7, 4)
correl.power(355, 172, 2/3, 0.25, 7, 4)
correl.power(355, 172, 1.5, 0.75, 7, 4)

correl.ratio(1000, 150, 0.2, 2, 3.635, int = c(0.0001, 20))

Approximate Power of Cox Model Interaction Tests

Approximates the power of the large sample partial likelihood tests for a treatment by biologic marker interaction test in a Cox model using the normal approximation, assuming exponential distributions.

hazsf: hazards meeting the constraints on the ratios and average hazard

hazs <- hazsf(prx = 0.5, prz = 0.25, ri = 0.6, rt = 0.8, rf = 2, l0 = 0.045)
hazs

expinf: expected information matrix per subject

expinf(prx = 0.5, prz = 0.25, hazs = hazs, acc.per = 2.5, add.fu = 3)

intpow: Approximate Power of Cox Model Interaction Tests

Calculates the power for the Wald test for the null hypothesis that coefficient of the interaction term equals 0 using the large sample normal approximation.

In large samples, this test is equivalent to the score and partial likelihood ratio tests for this hypothesis.

intpow(n = 2800, prx = 0.5, prz = 0.25, ri = 0.6, rt = 0.8, rf = 2, 
       l0 = 0.045, acc.per = 2.5, add.fu = 3)

Group sequential designs

Computes operating characteristics (seqopr) and sample size (seqss) for group sequential logrank tests in the setting of phase III studies with failure time endpoints.

lr.inf: computes the total planned information and the Brownian motion mean parameter eta

lr.inf(3, 200, 2, 0.1, 50)

seqopr: operating characteristics

seqopr(3, 200, 0.1, 50, c(2, 3, 4, 5))

seqss: sample size

seqss(0.8, c(2, 6), 200, 2, 0.5, 2, 0.1, 50)

seqp: Compute Boundary Crossing Probabilities

Computes probabilities of crossing arbitrary user specified upper and/or lower boundaries

seqp((1:4) / 4, c(2, 2, 3, 2), eta = 3)
seqp((1:4) / 4, c(2, 2, 3, 2), eta = 0)

sequse: Compute Group Sequential Use Function Boundaries

Computes the one-sided group sequential boundary for a specified use function at specified analysis times. Optionally, also computes an asymmetric lower boundary based on repeated confidence interval (RCI) monitoring for early stopping in favor of the null hypothesis.

sequse((1:4) / 4)
sequse((1:4) / 4, use = 6)
sequse((1:4) / 4, use = 6, alphal = 0.025, eta = 2)

mcnemar.pow: Calculate Power for McNemar's Test

Given a specified alternative distribution, this function computes the exact power for NcNemar's Test

mcnemar.pow(100, 0.9, 0.2, delta = 0.095)

nevents: Calculates the expected number of events exponential failure models

Given a uniform accrual period, specified accrual rate and follow-up period, and specified parameters for the exponential failure distribution, computes the expected number of failures

acc.per <- 2.2
add.fu <- 3.2
nevents(240, acc.per, add.fu, med = 1.7)

nevents.cure: Calculates the expected number of events for cure rate failure models

Given a uniform accrual period, specified accrual rate and follow-up period, and specified parameters for the exponential cure rate failure model, computes the expected number of failures

acc.per <- 2.2
add.fu <- 3.2
nevents.cure(240, acc.per, add.fu, cure.rate = 0.38, med = 1.7)
nevents.cure(240, acc.per, add.fu, cure.rate = 0.38, med = 1.7, haz.ratio = 0.667)

onearm: One Sample Binomial Design

Determines the critical value and power for an exact one sample binomial test

onearm(30, 0.1, 0.3)

pickwin: Two-Stage Randomized Phase II Designs

Calculates operating characteristics of pick the winner rules for two stage randomized phase II designs

pickwin(14, 18, 0.1, 0.2, 0, 3)

powexp2: Power for two sample exponential (or logrank)

Computes power for a stratified test comparing two groups with exponential failure time distributions. The power can also be used for the logrank test under proportional hazards.

powexp2(200, 2, 3, log(2) / 4, 1.5, 0.5)
powexp2(200, 2, 3, log(2) / 4, 1.33, 0.5)
powexp2(200, 2, 3, log(2) / 4, c(1.5, 1), 0.5, c(0.7, 0.3))
powexp2(10, 31.5, 13.75, c(log(2) / 6, log(2) / 8), c(1.4, 1.2), 0.5, c(0.9, 0.1))
powexp2(c(9, 1), 31.5, 13.75, c(log(2) / 6, log(2) / 8), c(1.4, 1.2), 0.5)

powlgrnk: Computes the power of the logrank test

Computes the power of the two-group logrank test for arbitrary failure time distributions in a standard clinical trials setting

# Exponential distributions
powlgrnk(5, 200, 3, control.rate = 0.1, test.rate = 0.075)

# Cure rate
powlgrnk(3, 200, 3, control.rate = log(2) / 3, test.rate = log(2) / 4,
         control.cure = 0.3, test.cure = 0.4)

# Exponential cure-rate with proportional hazards alternative
ht <- function(x, rat, ...) rat * hc(x, ...)
st <- function(x, rat, ...) sc(x, ...) ^ rat
sc <- function(x, pic, lic, ...) pic + (1 - pic) * exp(-lic * x)
hc <- function(x, pic, lic, ...) {u <- (1 - pic) * exp(-lic * x); lic * u / (pic + u)}

powlgrnk(5, 200, 3, hazcon = hc, survcon = sc, haztst = ht,
         survtst = st, lic = log(2) / 3, pic = 0.3, rat = 0.5)

powlgrnk6: Calculate the Power of a Group Sequential Logrank Test

Performs a simulation to calculate the power of a group sequential logrank test using an error spending rate function upper boundary with repeated confidence intervals for early stopping in favor of the null hypothesis. Assumes exponential distributions for the failure times.

## power under the alternative; 7 years accrual, analyses every 1/2 year
## one-sided .025 test, with an 80% RCI used for early stopping in
## favor of H0
## use larger nsamp (examples for illustration only)
out <- powlgrnk6(210, 0.11889, 0.11889 / 1.5, 7, 233, 0.5, nsamp = 10, conf = 0.80)
table(out[1, ]) / ncol(out)
apply(out[3:5, ], 1, mean)
out

## size under H0; note specification of ratio to keep the stopping rule
## the same as under the alternative
out <- powlgrnk6(210, 0.11889, 0.11889, 7, 233, 0.5, nsamp = 10, conf = 0.80,
                 ratio = 1.5)
table(out[1, ]) / ncol(out)
apply(out[3:5, ], 1, mean)

## power without RCI
out <- powlgrnk6(210, 0.11889, 0.11889 / 1.5, 7, 233, 0.5, nsamp = 10, conf = 1)
table(out[1, ]) / ncol(out)
apply(out[3:5, ], 1, mean)

## size without truncation
out <- powlgrnk6(210, 0.11889, 0.11889, 7, 233, 0.5, nsamp = 10, conf = 0.80,
                 ratio = 1.5, trunc=0)
table(out[1, ]) / ncol(out)
apply(out[3:5, ], 1, mean)

rci: Repeated Confidence Interval

Computes a repeated confidence interval on the hazard ratio for a group sequential study with a failure-time endpoint.

set.seed(3)
ft <- c(rexp(100), rexp(100) / 0.67)
ct <- runif(200) * 3
fi <- ifelse(ct < ft, 0, 1)
ft <- pmin(ft, ct)
rx <- c(rep(0, 100), rep(1, 100))
rci(ft, fi, rx, inf = c(0.25, 0.54))
rci(ft, fi, rx, crit = 2.4)

rp21: Outcome Probabilities for Randomized Phase II Designs

For a single stage randomized phase II study, computes the probability that the difference in the number of responses is larger than a specified critical value.

rp21(32, 0.2, 0.1)

siminf: Approximate Power of Cox Model Interaction Tests

Approximates the power of the large sample partial likelihood tests for a treatment by biologic marker interaction test in a Cox model using the normal approximation, assuming exponential distributions.

intpow(n = 2800, prx = 0.5, prz = 0.25, ri = 0.6, rt = 0.8, rf = 2,
       l0 = 0.045, acc.per = 2.5, add.fu = 3)

simon: Optimal Two-Stage Single-Arm Designs

For studies with binary endpoints, searches for two-stage sampling designs that minimize the expected number of subjects under the null, subject to various constraints.

simon(0.05, 0.20)
simon(0.05, 0.20, minimax = TRUE)

surv1samp: Sample Size Calculation for a One-Sample Exponential

Computes the sample size for a given size and power for the test for a specified improvement in the exponential rate parameter.

surv1samp(-1.333 * log(0.96) / 5, 33.3, 4, 3, alpha = 0.1, power = 0.95)
surv1samp(-log(0.95) / 5, 100 * (log(0.95) / log(0.96) - 1), 4, 3,
          alpha = 0.1, power = 0.95)
surv1samp(-log(0.955) / 5, 100 * (log(0.955) / log(0.965) - 1), 4, 3,
          alpha = 0.1, power = 0.95)

surv1sel: Compute selection probabilities in a randomized phase II study with a

Uses simulations with exponential failure times and uniform accrual to estimate the probability of each arm being the best in a randomized phase II study, where best is defined as the lowest hazard rate in a Cox proportional hazards model.

surv1sel(6, 55, 12, 40 * 6, log(2) / c(7.2, 4.8, 4.8, 4.8, 4.8, 4.8))

twocon: Confidence Interval on the Response Rate from a Two Stage Study

Computes a confidence interval and several estimators of the response rate using data from a phase II study with two-stage sampling

twocon(14, 18, 3, 4, dp = 0)
twocon(14, 18, 3, 4, dp = 1)

twostg: Operating Characteristics of Two-Stage Phase II Designs

Calculates the operating characteristics of single arm, two-stage phase II designs.

twostg(14, 18, 0.1, 1, 4)
twostg(14, 18, 0.3, 1, 4)

twostg3: Compute operating characteristics of two-stage trinomial-outcome

For a phase II study with three possible ordered outcomes (e.g., response, stable, progression), computes the probability of not rejecting the null hypothesis for a specified two-stage design.

twostg3(20, 40, 0.05, 0.10, 1, 3, 5, 22)

wilcox.pow: Compute Power for the Wilcoxon and T Tests

Computes an approximation to the power of the Wilcoxon signed rank or two-sample Wilcoxon rank sum test and one- or two-sample t-tests

wilcox.pow(24, 24, 1)
wilcox.pow(24, 10, 1)
wilcox.pow(10, NULL, 0.5)
within.list(sessionInfo(), loadedOnly <- NULL)


raredd/desmon documentation built on May 7, 2024, 3:46 p.m.