| Type: | Package |
| Title: | Claims About the Risk at a Fixed Time from Censored Data |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Depends: | R (≥ 3.5.0) |
| Imports: | stats |
| Suggests: | bpcp |
| NeedsCompilation: | no |
| Packaged: | 2026-11-05 10:02:30 UTC; nakamura |
| Author: | Satoshi Nakamura [aut, cre, cph] |
| Maintainer: | Satoshi Nakamura <s-nakamura@med.mie-u.ac.jp> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-25 20:30:22 UTC |
Claims About the Risk at a Fixed Time from Censored Data
Description
Rules for demonstrating that the cumulative incidence F(\tau) of an
event at a fixed time \tau lies below a threshold c, from
right-censored follow-up data. The claim F(\tau) < c is treated as the
one-sided alternative hypothesis, and it is demonstrated at level
\alpha when a one-sided 1 - \alpha upper confidence limit for
F(\tau) lies below c.
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 s-nakamura@med.mie-u.ac.jp
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 - \alpha upper confidence limit for the
cumulative incidence 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 |
Details
The lower limit of the BPCP for the survival probability S(\tau) is
the \alpha quantile of W^{+} = W^{-} B, where W^{-} is the
product over the event times t_j \le \tau of independent beta variables
with parameters n_j - d_j + 1 and d_j, n_j and d_j are
the numbers at risk and of events at t_j, and B is an independent
beta variable with parameters N^{+} and 1, N^{+} being the number
of patients observed beyond \tau. The upper limit for 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 q solves
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(\tau). NA is returned
for the mid-p version when the moment-matched beta distribution of
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
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(\tau) lies below the
threshold c, 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 |
alpha |
one-sided level, strictly between 0 and 1. |
Details
The claim is demonstrated at level \alpha when the one-sided
1 - \alpha upper limit of the beta product confidence procedure
(bpcp_upper) lies below c; 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_upper_loglog |
one-sided log-log upper limit. |
n_at_risk |
number at risk at |
n_beyond |
number of patients observed beyond |
min_at_risk |
smallest number at risk |
F_upper_bpcp, demonstrated_bpcp |
upper limit of the BPCP and whether
it lies below |
F_upper_bpcp_midp, demonstrated_bpcp_midp |
the same for the mid-p BPCP. |
See Also
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 - \alpha upper confidence limits for the cumulative
incidence 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 |
m |
number of patients whose potential follow-up reaches |
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(\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
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(\tau),
the one-sided 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 |
upper |
one-sided |
n_at_risk |
number of patients at risk at |
greenwood |
Greenwood sum |
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
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 m_c of patients for which zero events give an
exact one-sided 1 - \alpha upper confidence limit below the threshold
c, that is, the smallest m with 1 - \alpha^{1/m} < c.
Usage
min_at_risk(c, alpha = 0.05)
Arguments
c |
threshold of the claim |
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 - \alpha^{1/N^{+}}, where N^{+} is the number of patients
observed beyond \tau. A claim F(\tau) < c can therefore be
demonstrated with bpcp_upper only if at least m_c
patients are observed beyond \tau. With \alpha = 0.05,
m_c is 59 for c = 0.05 and 299 for c = 0.01.
Value
A whole number, the smallest number at risk m_c.
See Also
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(\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 |
F_true |
true cumulative incidence at |
c |
threshold of the claim |
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 |
nmax |
largest sample size searched. |
Details
The exact rule demonstrates the claim when the Clopper-Pearson upper limit
lies below c. 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
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 |
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
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(t_k) < c_k at prespecified times
t_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 |
|
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 |
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
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