Package 'horizonclaims'

Title: Claims About the Risk at a Fixed Time from Censored Data
Description: Rules for demonstrating that the cumulative incidence of an event at a fixed time lies below a threshold, from right-censored follow-up data. The package gives the one-sided upper confidence limit of the beta product confidence procedure of Fay, Brittain and Proschan (2013) <doi:10.1093/biostatistics/kxt016> and of its mid-p version of Fay and Brittain (2016) <doi:10.1002/sim.6905>, the Kaplan-Meier estimate with the log-log limit and the number at risk, and exact binomial limits for patients whose potential follow-up reaches the fixed time, including a limit that counts patients lost to follow-up as having had the event. It also gives the smallest number of patients at risk with which a claim can be demonstrated, the number of patients needed for a given power, and a lower confidence bound for the time during which the risk stays below a threshold, obtained by testing prespecified times in a fixed order.
Authors: Satoshi Nakamura [aut, cre, cph]
Maintainer: Satoshi Nakamura <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-11-26 03:13:51 UTC
Source: https://github.com/cran/horizonclaims

Help Index


Claims About the Risk at a Fixed Time from Censored Data

Description

Rules for demonstrating that the cumulative incidence F(τ)F(\tau) of an event at a fixed time τ\tau lies below a threshold cc, from right-censored follow-up data. The claim F(τ)<cF(\tau) < c is treated as the one-sided alternative hypothesis, and it is demonstrated at level α\alpha when a one-sided 1−α1 - \alpha upper confidence limit for F(τ)F(\tau) lies below cc.

Details

claim_low_risk reports the Kaplan-Meier estimate, the number at risk, and the upper limits of the beta product confidence procedure (BPCP) and of its mid-p version at a fixed time. bpcp_upper gives the BPCP limit alone, and km_at_horizon the Kaplan-Meier estimate with the log-log limit.

For planning, n_potential counts the patients whose potential follow-up, the time from entry to the data cutoff date, reaches the fixed time; this number is known from the dates before any outcome is observed. min_at_risk gives the smallest number of such patients with which the claim can be demonstrated, and n_for_power the number needed for a given power when every patient is followed to the fixed time.

exact_upper_admin and exact_upper_losses_as_events give exact binomial limits for the patients whose potential follow-up reaches the fixed time, the second one counting patients lost to follow-up as having had the event. warranty_lower_bound gives a lower confidence bound for the time during which the risk stays below a threshold.

All functions use base R and the package stats only.

Author(s)

Satoshi Nakamura [email protected]

References

Clopper, C. J. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26, 404–413. doi:10.1093/biomet/26.4.404

Fay, M. P., Brittain, E. H. and Proschan, M. A. (2013). Pointwise confidence intervals for a survival distribution with small samples or heavy censoring. Biostatistics, 14, 723–736. doi:10.1093/biostatistics/kxt016

Fay, M. P. and Brittain, E. H. (2016). Finite sample pointwise confidence intervals for a survival distribution with right-censored data. Statistics in Medicine, 35, 2726–2740. doi:10.1002/sim.6905


Upper Limit of the Beta Product Confidence Procedure at a Fixed Time

Description

Gives the one-sided 1−α1 - \alpha upper confidence limit for the cumulative incidence F(τ)F(\tau) by the beta product confidence procedure (BPCP) of Fay, Brittain and Proschan (2013), or by its mid-p version of Fay and Brittain (2016).

Usage

bpcp_upper(time, status, tau, alpha = 0.05, midp = FALSE)

Arguments

time

numeric vector of observed times (event or censoring).

status

numeric vector, 1 for an event and 0 for censoring.

tau

the fixed time, a single positive number.

alpha

one-sided level, strictly between 0 and 1.

midp

logical; if TRUE, the mid-p version is used.

Details

The lower limit of the BPCP for the survival probability S(τ)S(\tau) is the α\alpha quantile of W+=W−BW^{+} = W^{-} B, where W−W^{-} is the product over the event times tj≤τt_j \le \tau of independent beta variables with parameters nj−dj+1n_j - d_j + 1 and djd_j, njn_j and djd_j are the numbers at risk and of events at tjt_j, and BB is an independent beta variable with parameters N+N^{+} and 1, N+N^{+} being the number of patients observed beyond τ\tau. The upper limit for F(τ)F(\tau) is one minus this lower limit. The product is replaced by the beta distribution with the same first two moments, as in the method of moments version of the package bpcp (nmc = 0, Delta = 0).

With midp = TRUE, the lower limit qq solves 0.5P(W−≤q)+0.5P(W+≤q)=α0.5 P(W^{-} \le q) + 0.5 P(W^{+} \le q) = \alpha, each product again replaced by its moment-matched beta distribution.

Without censoring at or before τ\tau, the BPCP limit equals the exact Clopper-Pearson limit and the mid-p limit equals the binomial mid-p limit. When no patient is observed beyond τ\tau, the upper limit is 1.

Value

A number, the one-sided upper limit for F(τ)F(\tau). NA is returned for the mid-p version when the moment-matched beta distribution of W−W^{-} does not exist.

References

Fay, M. P., Brittain, E. H. and Proschan, M. A. (2013). Pointwise confidence intervals for a survival distribution with small samples or heavy censoring. Biostatistics, 14, 723–736. doi:10.1093/biostatistics/kxt016

Fay, M. P. and Brittain, E. H. (2016). Finite sample pointwise confidence intervals for a survival distribution with right-censored data. Statistics in Medicine, 35, 2726–2740. doi:10.1002/sim.6905

See Also

claim_low_risk, min_at_risk

Examples

set.seed(2)
event <- rexp(300, rate = 0.01)
followup <- runif(300, 1, 10)
time <- pmin(event, followup)
status <- as.numeric(event <= followup)
bpcp_upper(time, status, tau = 5)
bpcp_upper(time, status, tau = 5, midp = TRUE)

## without censoring the limit equals the Clopper-Pearson limit
t0 <- c(runif(3, 0, 5), runif(97, 6, 10))
bpcp_upper(t0, rep(1, 100), tau = 5)
1 - qbeta(0.05, 97, 4)

Demonstrate a Claim of Low Risk at a Fixed Time

Description

Tests the claim that the cumulative incidence F(τ)F(\tau) lies below the threshold cc, and returns the summaries that a report of the claim should contain.

Usage

claim_low_risk(time, status, tau, c, alpha = 0.05)

Arguments

time

numeric vector of observed times (event or censoring).

status

numeric vector, 1 for an event and 0 for censoring.

tau

the fixed time, a single positive number.

c

threshold of the claim F(τ)<cF(\tau) < c, strictly between 0 and 1.

alpha

one-sided level, strictly between 0 and 1.

Details

The claim is demonstrated at level α\alpha when the one-sided 1−α1 - \alpha upper limit of the beta product confidence procedure (bpcp_upper) lies below cc; the decision of the mid-p version is returned as well. The Kaplan-Meier estimate and its log-log limit (km_at_horizon) are returned as descriptions, because the coverage of the log-log limit can fall below the nominal level when few patients remain at risk or many are censored.

Value

A data frame with one row and the columns

tau, c

the fixed time and the threshold.

F_km

Kaplan-Meier estimate of F(τ)F(\tau).

F_upper_loglog

one-sided log-log upper limit.

n_at_risk

number at risk at τ\tau.

n_beyond

number of patients observed beyond τ\tau.

min_at_risk

smallest number at risk mcm_c with which the claim can be demonstrated (min_at_risk).

F_upper_bpcp, demonstrated_bpcp

upper limit of the BPCP and whether it lies below cc.

F_upper_bpcp_midp, demonstrated_bpcp_midp

the same for the mid-p BPCP.

See Also

warranty_lower_bound

Examples

set.seed(2)
event <- rexp(300, rate = 0.01)
followup <- runif(300, 1, 10)
time <- pmin(event, followup)
status <- as.numeric(event <= followup)
claim_low_risk(time, status, tau = 5, c = 0.10)

Exact Upper Limits for Patients Whose Potential Follow-Up Reaches a Fixed Time

Description

Exact one-sided 1−α1 - \alpha upper confidence limits for the cumulative incidence F(τ)F(\tau), computed from the patients whose potential follow-up reaches τ\tau. exact_upper_admin applies when censoring before τ\tau is administrative only, and exact_upper_losses_as_events counts patients lost to follow-up before τ\tau as having had the event.

Usage

exact_upper_admin(x, m, alpha = 0.05)
exact_upper_losses_as_events(time, status, potential_followup, tau,
                             alpha = 0.05)

Arguments

x

number of events by τ\tau among the m patients.

m

number of patients whose potential follow-up reaches τ\tau.

alpha

one-sided level, strictly between 0 and 1.

time

numeric vector of observed times (event or censoring).

status

numeric vector, 1 for an event and 0 for censoring.

potential_followup

numeric vector of potential follow-up times, the times from entry to the data cutoff date.

tau

the fixed time, a single positive number.

Details

When every patient whose potential follow-up reaches τ\tau is followed to τ\tau, the number of events by τ\tau among them is binomial, and exact_upper_admin returns the Clopper-Pearson upper limit qbeta(1 - alpha, x + 1, m - x).

exact_upper_losses_as_events counts, among the patients with potential_followup >= tau, those with an event by τ\tau and those with an observed time before τ\tau, and applies the same exact limit. Counting a lost patient as an event can only increase the count, so the limit remains valid for any mechanism of loss, provided that entry is independent of the event time.

Value

A number, the one-sided upper limit for F(τ)F(\tau); it is 1 when m = 0 or x = m.

References

Clopper, C. J. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26, 404–413. doi:10.1093/biomet/26.4.404

See Also

n_potential, bpcp_upper

Examples

exact_upper_admin(0, 59)
exact_upper_admin(3, 200)

set.seed(3)
potential <- runif(400, 1, 11)
event <- rexp(400, rate = 0.01)
loss <- rexp(400, rate = 0.05)
time <- pmin(event, potential, loss)
status <- as.numeric(event <= pmin(potential, loss))
exact_upper_losses_as_events(time, status, potential, tau = 5)

Kaplan-Meier Estimate and Log-Log Upper Limit at a Fixed Time

Description

Gives the Kaplan-Meier estimate of the cumulative incidence F(τ)F(\tau), the one-sided 1−α1 - \alpha upper limit based on the log-log transformation and the Greenwood variance, and the number at risk at τ\tau.

Usage

km_at_horizon(time, status, tau, alpha = 0.05)

Arguments

time

numeric vector of observed times (event or censoring).

status

numeric vector, 1 for an event and 0 for censoring.

tau

the fixed time, a single positive number.

alpha

one-sided level, strictly between 0 and 1.

Details

The number at risk at τ\tau counts the patients with time >= tau. When no event occurs by τ\tau, the estimate and the upper limit are returned as 0; the log-log limit is then undefined, and bpcp_upper gives a limit that uses the number at risk. The coverage of the log-log limit can fall below the nominal level when few patients remain at risk or many are censored (Fay, Brittain and Proschan, 2013), so the limit of bpcp_upper is preferable for demonstrating a claim.

Value

A list with components

F

Kaplan-Meier estimate of F(τ)F(\tau).

upper

one-sided 1−α1 - \alpha upper limit for F(τ)F(\tau) on the log-log scale.

n_at_risk

number of patients at risk at τ\tau.

greenwood

Greenwood sum ∑dj/{nj(nj−dj)}\sum d_j / \{n_j (n_j - d_j)\} over the event times up to τ\tau.

References

Fay, M. P., Brittain, E. H. and Proschan, M. A. (2013). Pointwise confidence intervals for a survival distribution with small samples or heavy censoring. Biostatistics, 14, 723–736. doi:10.1093/biostatistics/kxt016

See Also

bpcp_upper, claim_low_risk

Examples

set.seed(2)
event <- rexp(300, rate = 0.01)
followup <- runif(300, 1, 10)
time <- pmin(event, followup)
status <- as.numeric(event <= followup)
km_at_horizon(time, status, tau = 5)

Smallest Number at Risk That Can Demonstrate a Claim of Low Risk

Description

Gives the smallest number mcm_c of patients for which zero events give an exact one-sided 1−α1 - \alpha upper confidence limit below the threshold cc, that is, the smallest mm with 1−α1/m<c1 - \alpha^{1/m} < c.

Usage

min_at_risk(c, alpha = 0.05)

Arguments

c

threshold of the claim F(τ)<cF(\tau) < c, strictly between 0 and 1.

alpha

one-sided level, strictly between 0 and 1.

Details

The upper limit of the beta product confidence procedure at τ\tau is at least 1−α1/N+1 - \alpha^{1/N^{+}}, where N+N^{+} is the number of patients observed beyond τ\tau. A claim F(τ)<cF(\tau) < c can therefore be demonstrated with bpcp_upper only if at least mcm_c patients are observed beyond τ\tau. With α=0.05\alpha = 0.05, mcm_c is 59 for c=0.05c = 0.05 and 299 for c=0.01c = 0.01.

Value

A whole number, the smallest number at risk mcm_c.

See Also

n_potential, n_for_power

Examples

min_at_risk(0.05)
min_at_risk(0.01)
min_at_risk(0.05, alpha = 0.025)

Power and Sample Size for a Claim of Low Risk

Description

power_exact gives the probability that the exact binomial rule demonstrates F(τ)<cF(\tau) < c when N patients are followed to τ\tau and the true risk is F_true. n_for_power gives the smallest N for which this power is at least power at N and at every number up to N + window.

Usage

power_exact(N, F_true, c, alpha = 0.05)
n_for_power(F_true, c, power = 0.8, alpha = 0.05, window = 100, nmax = 4000)

Arguments

N

number of patients followed to τ\tau, a positive integer.

F_true

true cumulative incidence at τ\tau, between 0 and 1.

c

threshold of the claim F(τ)<cF(\tau) < c, strictly between 0 and 1.

alpha

one-sided level, strictly between 0 and 1.

power

required power, strictly between 0 and 1.

window

number of further sample sizes over which the power must stay at least power; the power of an exact test is not monotone in the sample size.

nmax

largest sample size searched.

Details

The exact rule demonstrates the claim when the Clopper-Pearson upper limit lies below cc. Without censoring at or before τ\tau, the limit of bpcp_upper equals this limit, so these numbers apply to a cohort in which every patient is followed to τ\tau. With censoring before τ\tau, the power of the BPCP depends on the whole pattern of follow-up, and these numbers serve as a reference for planning.

Value

power_exact returns a number, the power. n_for_power returns the sample size, or NA if no sample size up to nmax qualifies.

See Also

min_at_risk

Examples

power_exact(434, F_true = 0.025, c = 0.05)
n_for_power(F_true = 0.025, c = 0.05)

Number of Patients Whose Potential Follow-Up Reaches a Fixed Time

Description

Counts the patients whose potential follow-up, the time from entry to the data cutoff date, is at least τ\tau.

Usage

n_potential(potential_followup, tau)

Arguments

potential_followup

numeric vector of potential follow-up times, in the same unit as tau.

tau

the fixed time, a single positive number.

Details

The potential follow-up depends only on the dates of entry and data cutoff, so this number is known before any outcome is observed. Comparing it with min_at_risk shows at the planning stage whether a claim at τ\tau can be demonstrated at all.

Value

An integer, the number of patients with potential_followup >= tau.

See Also

min_at_risk

Examples

set.seed(1)
entry <- as.Date("2015-01-01") + sort(sample(0:2900, 300))
cutoff <- as.Date("2023-12-31")
potential <- as.numeric(cutoff - entry) / 365.25
n_potential(potential, tau = 5)
n_potential(potential, tau = 5) >= min_at_risk(0.05)

Lower Confidence Bound for the Time During Which the Risk Stays Low

Description

Tests the claims F(tk)<ckF(t_k) < c_k at prespecified times t1<⋯<tKt_1 < \dots < t_K in increasing order and stops at the first time at which the claim is not demonstrated. The last time with a demonstrated claim is a lower confidence bound for the time during which the risk stays below the thresholds, often called the warranty period of a negative test.

Usage

warranty_lower_bound(time, status, horizons, thresholds, alpha = 0.05,
                     rule = c("bpcp", "bpcp_midp"))

Arguments

time

numeric vector of observed times (event or censoring).

status

numeric vector, 1 for an event and 0 for censoring.

horizons

strictly increasing numeric vector of prespecified times.

thresholds

numeric vector of thresholds, one for each time.

alpha

one-sided level, strictly between 0 and 1.

rule

"bpcp" for the beta product confidence procedure or "bpcp_midp" for its mid-p version.

Details

Each claim is tested with claim_low_risk at level α\alpha. Testing in a fixed order keeps the probability of any false claim at most α\alpha when each test is valid, so no adjustment for the number of times is needed. The times and the thresholds must be chosen before the outcome data are seen.

Value

A list with components

table

data frame with one row of claim_low_risk for each time.

lower_bound

the last time, in the prespecified order, up to which every claim is demonstrated, or 0 if the claim at the first time is not demonstrated.

See Also

claim_low_risk

Examples

set.seed(2)
event <- rexp(600, rate = 0.005)
followup <- runif(600, 1, 10)
time <- pmin(event, followup)
status <- as.numeric(event <= followup)
warranty_lower_bound(time, status, horizons = 1:5,
                     thresholds = c(0.02, 0.03, 0.04, 0.05, 0.06))$lower_bound