Skip to contents

Calculates sample size or power for a cox proportional hazards model.

Usage

coxph_size(
  hr,
  hr0 = NULL,
  delta = NULL,
  pE,
  pA,
  alpha,
  beta = NULL,
  n = NULL,
  test_type = "2-side"
)

Arguments

hr

Numeric. True hazard ratio.

hr0

Numeric (optional). Null hypothesis hazard ratio. Required for "2-side", "non-inferiority" test.

delta

Numeric (optional). Margin for "equivalence test". Required for "equivalence" test.

pE

Numeric. Overall event probability.

pA

Numeric. Proportion of group A.

alpha

Numeric. Type I error rate.

beta

Numeric (optional). Type II error rate. Required for sample size calculation.

n

Integer (optional). Sample size. Required for power calculation.

test_type

Character. "2-side", "non-inferiority", or "equivalence". Default is "2-side".

Value

Numeric. Returns sample size (if beta is given), or power (if n is given).

Note

Only one of beta (for sample size calculation) or n (for power calculation) should be specified.

Required arguments by test_type:

  • "2-side"/"non-inferiority:

    • For sample size: hr, hr0, pE, pA, alpha, beta

    • For power: hr, hr0, pE, pA, alpha, n

  • "equivalence":

    • For sample size: hr, delta, pE, pA, alpha, beta

    • For power: hr, delta, pE, pA, alpha, n

Examples

# Sample size for a `"2-side"` test
coxph_size(hr = 2, hr0 = 1, pE = 0.8, pA = 0.5,
           alpha = 0.05, beta = 0.2, test_type = "2-side")
#> [1] 82

# Power of `"2-side"` test
coxph_size(hr = 2, hr0 = 1, pE = 0.8, pA = 0.5,
           alpha = 0.05, n = 82, test_type = "2-side")
#> [1] 0.8015214

# Sample size for `"non-inferiority"` test
coxph_size(hr = 2, hr0 = 1, pE = 0.8, pA = 0.5,
           alpha = 0.025, beta = 0.2, test_type = "non-inferiority")
#> [1] 82

# Power of `"non-inferiority"` test
coxph_size(hr = 2, hr0 = 1, pE = 0.8, pA = 0.5,
           alpha = 0.025, n = 82, test_type = "non-inferiority")
#> [1] 0.8015214

# Sample size for `"equivalence"` test
coxph_size(hr = 1, delta = 0.5, pE = 0.8, pA = 0.5,
           alpha = 0.05, beta = 0.2, test_type = "equivalence")
#> [1] 172

# Power of `"equivalence"` test
coxph_size(hr = 1, delta = 0.5, pE = 0.8, pA = 0.5,
           alpha = 0.05, n = 172, test_type = "equivalence")
#> [1] 0.8021573