Package {wnpmle}


Title: Weighted NPMLE for Competing Risks and Recurrent Events with a Competing Terminal Event
Version: 0.2.0
Description: Provides regression modeling and prediction for the subdistribution of a competing risk and for the marginal rate of recurrent events with a competing terminal event, using the weighted nonparametric maximum likelihood estimator (wNPMLE) of Bellach, Kosorok, Rüschendorf and Fine (2019) <doi:10.1080/01621459.2017.1401540> and Bellach and Kosorok (2026) <doi:10.48550/arXiv.2605.25934>. Two classes of transformation models are implemented: Box-Cox transformation models and logarithmic transformation models. These include the Fine-Gray model and the proportional means model of Ghosh and Lin (2002) <doi:10.17615/pt0g-y207>, and extend the transformation model framework of Zeng and Lin (2006) <doi:10.1093/biomet/93.3.627>. Parameter estimation is performed using automatic differentiation through the Template Model Builder (TMB) framework. Standard errors are computed using sandwich variance estimators that account for estimation of the inverse-probability censoring weights. Model selection over the transformation parameter is supported by the profile log-likelihood and Takeuchi's information criterion (TIC).
License: GPL (≥ 3)
Encoding: UTF-8
RoxygenNote: 7.3.3
Depends: R (≥ 4.1.0)
Imports: TMB (≥ 1.9.0), survival, methods, MASS, graphics, grDevices, utils
LinkingTo: TMB, RcppEigen
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown
Config/testthat/edition: 3
VignetteBuilder: knitr
URL: https://github.com/abellach/wnpmle
BugReports: https://github.com/abellach/wnpmle/issues
Author: Anna Bellach [aut, cre]
Maintainer: Anna Bellach <abellach.biostat@gmail.com>
NeedsCompilation: yes
Packaged: 2026-12-01 08:22:35 UTC; abell
Repository: CRAN
Date/Publication: 2026-12-01 08:40:02 UTC

wnpmle: Weighted NPMLE for the Subdistribution of a Competing Risk and the Marginal Rate of Recurrent Events with a Competing Terminal Event

Description

Implements the weighted nonparametric maximum likelihood estimator (wNPMLE) for the subdistribution of a competing risk (type = "cmprsk") and for the marginal rate of recurrent events in the presence of a competing terminal event (type = "recurrent"). Two semiparametric transformation models are provided: the Box-Cox transformation model and the logarithmic transformation model. Both use automatic differentiation via TMB for efficient and exact gradient computation.

Details

The main user-facing function is wnpmle_fit.

Author(s)

Maintainer: Anna Bellach abellach.biostat@gmail.com

References

Bellach, A. and Kosorok, M.R. (2026). Pseudo-likelihood regression for the marginal rate of recurrent events with a competing terminal event. arXiv preprint arXiv:2605.25934. doi:10.48550/arXiv.2605.25934

Bellach, A., Kosorok, M.R., Rüschendorf, L. and Fine, J.P. (2019). Weighted NPMLE for the subdistribution of a competing risk. Journal of the American Statistical Association, 114(525), 259-270. doi:10.1080/01621459.2017.1401540

See Also

Useful links:


AIC for wnpmle objects

Description

AIC for wnpmle objects

Usage

## S3 method for class 'wnpmle'
AIC(object, ..., k = 2)

Arguments

object

A wnpmle object.

...

Ignored.

k

Penalty per parameter (default 2 for AIC).

Value

A numeric scalar giving the AIC value.


BIC for wnpmle objects

Description

BIC for wnpmle objects

Usage

## S3 method for class 'wnpmle'
BIC(object, ...)

Arguments

object

A wnpmle object.

...

Ignored.

Value

A numeric scalar giving the BIC value.


Takeuchi information criterion for the weighted NPMLE

Description

Computes Takeuchi's information criterion (TIC) for a fitted wnpmle model. The weighted NPMLE maximizes an inverse probability of censoring weighted log-likelihood, for which the information equality need not hold. TIC therefore replaces the AIC penalty 2p by 2\,\mathrm{tr}(\mathcal{I}_n^{-1}\widehat\Sigma_n), where \mathcal{I}_n is the observed information and \widehat\Sigma_n the censoring-corrected meat of the sandwich estimator:

\mathrm{TIC} = -2\,\ell(\hat\theta) + 2\,\mathrm{tr}(\mathcal{I}_n^{-1}\widehat\Sigma_n).

Usage

TIC(object, ...)

## S3 method for class 'wnpmle'
TIC(object, fisher = NULL, details = FALSE, ...)

Arguments

object

A wnpmle object fitted with a sandwich variance estimator (se = "sandwich_adj", the default, or "sandwich").

...

Ignored.

fisher

Optional wnpmle object for the same model and data, fitted with se = "fisher". If NULL (default), the model is refitted with se = "fisher"; this requires that the data used in the original call are still available.

details

Logical; if TRUE, also return the penalty, the number of parameters, AIC and the log-likelihood (default FALSE).

Details

The trace is computed from the full covariance matrices of (\beta, \Lambda): \mathrm{tr}(\mathcal{I}_n^{-1}\widehat\Sigma_n) = \mathrm{tr}(V_S V_F^{-1}), with V_S = \mathcal{I}_n^{-1}\widehat\Sigma_n\mathcal{I}_n^{-1} the sandwich and V_F = \mathcal{I}_n^{-1} the inverse Fisher information. The trace is invariant to the parametrization of the baseline (jumps or cumulative values).

For a correctly specified model with a genuine likelihood the penalty equals p asymptotically, and TIC reduces to AIC. Since all Box-Cox and logarithmic transformation models have the same number of parameters, AIC compares log-likelihoods only, whereas TIC can give different transformations different penalties. The trace is estimated, so TIC is noisier than AIC in small samples.

The penalty should not exceed p by much; a penalty clearly larger than p points to a problem with the variance estimate.

Value

A numeric scalar giving the TIC value. With details = TRUE, a named vector with TIC, penalty (the trace \mathrm{tr}(\mathcal{I}_n^{-1}\widehat\Sigma_n)), p (the number of parameters, including the baseline jumps), AIC (-2\ell + 2p with this p) and loglik.

References

Takeuchi, K. (1976). Distribution of informational statistics and a criterion of model fitting. Suri-Kagaku (Mathematical Sciences), 153, 12-18 (in Japanese).

Konishi, S. and Kitagawa, G. (1996). Generalised information criteria in model selection. Biometrika, 83, 875-890.

See Also

wnpmle_fit, AIC.wnpmle

Examples


  dat <- bladder_prep()
  fit <- wnpmle_fit(Surv(time, status) ~ treat + num + size, data = dat,
                    id = "id", model = "boxcox", rho = 1)
  TIC(fit)
  TIC(fit, details = TRUE)



Extract the estimated baseline mean function

Description

Returns a data frame with the estimated cumulative baseline mean function Lambda(t) and its increments lambda(t), together with standard errors and pointwise 95% confidence intervals.

Usage

baseline(object, conf_level = 0.95, ...)

Arguments

object

A wnpmle object.

conf_level

Confidence level for the pointwise intervals (default 0.95).

...

Ignored.

Value

A data frame with columns:

time

Recurrent event times.

lambda

Estimated baseline increments.

Lambda

Estimated cumulative baseline mean.

se_Lambda

Standard error of Lambda (if SE was estimated).

lower

Lower pointwise confidence band for Lambda.

upper

Upper pointwise confidence band for Lambda.

Examples


bdata <- bladder_prep()
bdata_clean <- bdata[, c("id", "time", "status", "treat", "num", "size")]
fit <- wnpmle_fit(Surv(time, status) ~ treat + num + size,
                  data = bdata_clean, id = "id", model = "log", r = 1)
bl <- baseline(fit)
head(bl)


Prepare bladder cancer data for wnpmle analysis

Description

Prepares the bladder1 dataset from the survival package for use with wnpmle_fit. Subjects randomised to pyridoxine are excluded (only placebo and thiotepa arms are retained). Status codes are recoded to 0 (censored), 1 (recurrent tumour), 2 (terminal/dropout), and event times beyond tau are truncated to tau.

Usage

bladder_prep(tau = 59)

Arguments

tau

Follow-up truncation time (default: 59 months). Event times beyond tau are set to tau.

Details

The bladder cancer trial (Veterans Administration Cooperative Urological Research Group) randomised patients to placebo, pyridoxine, or thiotepa. Only the placebo and thiotepa arms are used here (pyridoxine arm excluded). Subjects with event times equal to tau and status 0 have their times truncated to tau, consistent with administrative censoring.

Value

A data frame with columns:

id

Subject identifier (integer).

status

Event status: 0 = censored, 1 = recurrent event, 2 = terminal event.

status0

Indicator: 1 if censored.

status1

Indicator: 1 if recurrent event.

status2

Indicator: 1 if terminal event.

time

Event time (months).

treat

Treatment indicator: 1 = thiotepa, 0 = placebo.

num

Initial number of tumours.

size

Initial tumour size (cm).

References

Byar, D.P. (1980). The Veterans Administration study of chemoprophylaxis for recurrent stage I bladder tumors. In Bladder Tumors and Other Topics in Urological Oncology, 363-370. Plenum, New York.

Examples

bdata <- bladder_prep(tau = 59)
head(bdata)
table(bdata$status)


Extract coefficients from a wnpmle object

Description

Extract coefficients from a wnpmle object

Usage

## S3 method for class 'wnpmle'
coef(object, ...)

Arguments

object

A wnpmle object.

...

Ignored.

Value

A named numeric vector of regression coefficients.


Log-likelihood for wnpmle objects

Description

Log-likelihood for wnpmle objects

Usage

## S3 method for class 'wnpmle'
logLik(object, ...)

Arguments

object

A wnpmle object.

...

Ignored.

Value

An object of class "logLik" with the log-likelihood value, degrees of freedom (df) equal to the number of regression coefficients plus the number of baseline jumps, and number of observations (nobs).


Plot method for wnpmle objects

Description

Plots the estimated cumulative baseline mean function Lambda(t) with optional pointwise confidence bands.

Usage

## S3 method for class 'wnpmle_cmprsk'
plot(x, conf_bands = TRUE, ...)

## S3 method for class 'wnpmle'
plot(x, conf_bands = TRUE, ...)

Arguments

x

A wnpmle object.

conf_bands

Logical; if TRUE (default), adds pointwise 95\ confidence bands when available.

...

Additional graphical parameters passed to plot.

Value

No return value, called for side effects (produces a plot).


Plot predicted cumulative incidences or marginal means

Description

Plots the result of predict() for a wnpmle fit: one curve per row of newdata, with pointwise confidence bands. For competing-risks fits (type = "cmprsk") the curves are cumulative incidences, for recurrent events marginal means.

Usage

## S3 method for class 'wnpmle_pred'
plot(
  x,
  conf_int = !add,
  add = FALSE,
  xscale = 1,
  type = c("s", "l"),
  col = NULL,
  lty = NULL,
  lwd = NULL,
  band_col = NULL,
  band_alpha = 0.15,
  labels = NULL,
  legend = if (add) FALSE else "auto",
  xlab = NULL,
  ylab = NULL,
  main = NULL,
  xlim = NULL,
  ylim = NULL,
  ...
)

Arguments

x

Result of predict() for a wnpmle fit.

conf_int

Logical; draw the pointwise confidence bands, if available (default TRUE, FALSE with add = TRUE).

add

Logical; add the curves to the current plot, e.g. to compare two models (default FALSE). Added curves are dashed by default.

xscale

The time axis is divided by xscale, e.g. xscale = 365.25 to show days in years (default 1).

type

"s" (step function, default) or "l" (lines).

col, lty, lwd

Colour, line type and line width, recycled over the curves. Default: grey shades from black, solid lines (dashed with add = TRUE).

band_col

Colour of the confidence bands (default: col).

band_alpha

Transparency of the confidence bands (default 0.15).

labels

Legend labels, one per curve. By default built from the covariates that differ between the rows of newdata.

legend

Position of the legend, e.g. "topleft"; "auto" (default) puts it in the emptiest corner, FALSE draws no legend (default with add = TRUE).

xlab, ylab, main, xlim, ylim

Axis labels, title and axis limits. The y-axis label depends on the type of prediction.

...

Further graphical parameters passed to plot() (not used with add = TRUE).

Value

x, invisibly.

Examples


library(survival)
tp <- survival::transplant
tp <- tp[tp$futime > 0 & complete.cases(tp), ]
tp$status <- ifelse(tp$event == "ltx", 1, ifelse(tp$event == "censored", 0, 2))
fit <- wnpmle_fit(Surv(futime, status) ~ age + sex + abo, data = tp,
                  type = "cmprsk", model = "boxcox", rho = 1)
nd <- data.frame(age = 50, sex = factor("m", levels = levels(tp$sex)),
                 abo = factor(c("A", "O"), levels = levels(tp$abo)))
p <- predict(fit, newdata = nd)
plot(p, xscale = 365.25, xlab = "Years on the waiting list")


Plot the results of plot_loglik() or plot_tic() again

Description

plot_loglik and plot_tic return their results (invisibly) as an object of class "wnpmle_profile". plot() redraws the figure from these results without refitting any model, e.g. with a different layout or into a PDF file.

Usage

## S3 method for class 'wnpmle_profile'
plot(
  x,
  layout = NULL,
  relative = TRUE,
  show_loglik = TRUE,
  mark_points = TRUE,
  legend = TRUE,
  file = NULL,
  width = NULL,
  height = NULL,
  ...
)

Arguments

x

An object of class "wnpmle_profile", returned by plot_loglik or plot_tic.

layout

"joint" (default) or "panels"; see plot_loglik.

relative

Logical; show each criterion relative to its optimum (-\Delta\mathrm{AIC}/2, -\Delta\mathrm{TIC}/2; default TRUE), or on the log-likelihood scale.

show_loglik

Logical; for results of plot_tic(), also show AIC (default TRUE).

mark_points, legend, file

As in plot_loglik.

width, height

Size of the PDF in inches; default 3.6 x 2.8 (with pointsize 9, as in Bellach and Kosorok, 2026) for layout = "joint" and 7 x 4.5 for "panels".

...

Ignored.

Value

x, invisibly.

Examples


bdata <- bladder_prep()
res <- plot_loglik(Surv(time, status) ~ treat + num + size, data = bdata,
                   id = "id", rho_grid = seq(0.2, 1.2, by = 0.2),
                   r_grid = seq(0.2, 1.2, by = 0.2))
plot(res, layout = "panels")        # redrawn without refitting


Log-likelihood profile plot for the transformation parameter

Description

Fits the model over a fine grid of transformation parameter values and plots the profile log-likelihood for both the Box-Cox and logarithmic transformation models in one panel (layout = "joint", default): the log transformation parameter r to the left and the Box-Cox parameter rho to the right of a dotted line at zero, where the families meet (\rho \to 0 is the log model with r = 1, r \to 0 the Box-Cox model with \rho = 1). layout = "panels" gives two panels side by side. Curves are natural splines through the grid points. For competing risks the plot refers to the event coded 1; for another event, recode the status and call the function again.

Usage

plot_loglik(
  formula,
  data,
  id = "id",
  rho_grid = seq(0.01, 1.2, by = 0.01),
  r_grid = seq(0.01, 1.2, by = 0.01),
  tau = NULL,
  mark_points = TRUE,
  layout = NULL,
  legend = TRUE,
  file = NULL,
  width = NULL,
  height = NULL,
  verbose = TRUE,
  ...
)

Arguments

formula

A formula as passed to wnpmle_fit.

data

A data frame.

id

Name of the subject identifier column.

rho_grid

A numeric vector of rho values for the Box-Cox model (default: seq(0.01, 1.2, by = 0.01)).

r_grid

A numeric vector of r values for the log model (default: seq(0.01, 1.2, by = 0.01)).

tau

Optional truncation time. If NULL (default), uses the maximum observed time in the data.

mark_points

Logical; if TRUE (default), marks reference points at rho=1 (open circle; Ghosh-Lin model, or Fine-Gray model for type = "cmprsk") and r=1 (filled circle, proportional odds model).

layout

"joint" (default: one panel, logarithmic left and Box-Cox right of a dotted line at zero, where the families meet) or "panels" (two panels side by side with a common y-axis).

legend

Logical; add a legend (default TRUE). The curves are shown relative to their optimum (0 = best; -\Delta\mathrm{AIC}/2), with a dotted line at -1, i.e. a difference of 2 in AIC; all transformations have the same number of parameters, so the largest log-likelihood is the smallest AIC. The layout "joint" is that of Figure 2 in Bellach and Kosorok (2026).

file

Optional path to save the plot as a PDF (e.g. "loglik_profile.pdf"). If NULL (default), plots to the current device.

width, height

Size of the PDF in inches; default 3.6 x 2.8 (pointsize 9, as Figure 2 of Bellach and Kosorok, 2026) for layout = "joint", 7 x 4.5 for "panels"; only used when file is given.

verbose

Logical; print progress (default TRUE).

...

Additional arguments passed to wnpmle_fit.

Value

A data frame of class "wnpmle_profile" with columns model, param and loglik, invisibly. Save it (res <- plot_loglik(...)) to redraw the figure with plot.wnpmle_profile without refitting.

Examples


bdata <- bladder_prep()
bdata_clean <- bdata[, c("id", "time", "status", "treat", "num", "size")]
# a coarse grid keeps the example short; use finer grids in practice
plot_loglik(Surv(time, status) ~ treat + num + size,
            data = bdata_clean, id = "id",
            rho_grid = seq(0.2, 1.2, by = 0.2),
            r_grid   = seq(0.2, 1.2, by = 0.2))


Takeuchi information criterion over the transformation parameter

Description

Fits the Box-Cox and logarithmic transformation models over grids of the transformation parameter and plots TIC and AIC on the log-likelihood scale, relative to their optimum: -\Delta\mathrm{TIC}/2 (solid, filled circles) and -\Delta\mathrm{AIC}/2 (dashed, open circles), as in Figure 2 of Bellach and Kosorok (2026); see TIC. The maximum of the solid curve is the model with the smallest TIC. r \to 0 and \rho = 1 give the Ghosh-Lin model (the Fine-Gray model for type = "cmprsk"), and \rho \to 0 and r = 1 the proportional odds model. Further arguments such as type = "cmprsk" are passed to wnpmle_fit via ....

Usage

plot_tic(
  formula,
  data,
  id = "id",
  rho_grid = seq(0.05, 1.2, by = 0.05),
  r_grid = seq(0.05, 1.2, by = 0.05),
  tau = NULL,
  mark_points = TRUE,
  show_loglik = TRUE,
  layout = NULL,
  legend = TRUE,
  file = NULL,
  width = NULL,
  height = NULL,
  verbose = TRUE,
  ...
)

Arguments

formula

A formula as passed to wnpmle_fit.

data

A data frame.

id

Name of the subject identifier column.

rho_grid

Box-Cox parameter values (default seq(0.05, 1.2, by = 0.05)).

r_grid

Logarithmic parameter values (default seq(0.05, 1.2, by = 0.05)).

tau

Optional truncation time. If NULL (default), uses the maximum observed time in the data.

mark_points

Logical; if TRUE (default), marks reference points at rho=1 (open circle; Ghosh-Lin model, or Fine-Gray model for type = "cmprsk") and r=1 (filled circle, proportional odds model).

show_loglik

Logical; if TRUE (default), AIC (the ordinary log-likelihood, as in plot_loglik) is added in grey.

layout

"joint" (default: one panel, logarithmic left and Box-Cox right of a dotted line at zero, where the families meet) or "panels" (two panels side by side with a common y-axis).

legend

Logical; add a legend (default TRUE). The curves are shown relative to their optimum (0 = best; -\Delta\mathrm{AIC}/2), with a dotted line at -1, i.e. a difference of 2 in AIC; all transformations have the same number of parameters, so the largest log-likelihood is the smallest AIC. The layout "joint" is that of Figure 2 in Bellach and Kosorok (2026).

file

Optional path to save the plot as a PDF (e.g. "loglik_profile.pdf"). If NULL (default), plots to the current device.

width, height

Size of the PDF in inches; default 3.6 x 2.8 (pointsize 9, as Figure 2 of Bellach and Kosorok, 2026) for layout = "joint", 7 x 4.5 for "panels"; only used when file is given.

verbose

Logical; print progress (default TRUE).

...

Additional arguments passed to wnpmle_fit.

Details

Every grid point needs a fit with the censoring-corrected sandwich and a fit with the inverse Fisher information, so this is much slower than plot_loglik; the default grids are therefore coarser.

Value

A data frame of class "wnpmle_profile" with columns model, param, loglik, penalty, p, AIC and TIC, invisibly. Save it (res <- plot_tic(...)) to redraw the figure with plot.wnpmle_profile without refitting.

See Also

TIC, plot_loglik

Examples


  dat <- bladder_prep()
  res <- plot_tic(Surv(time, status) ~ treat + num + size, data = dat,
                  id = "id", rho_grid = c(0.5, 1), r_grid = c(0.5, 1))
  res



Predict marginal mean for new covariate values

Description

Evaluates the estimated marginal mean number of recurrent events, \hat\mu(t \mid z) = G\{e^{\hat\beta^T z} \hat\Lambda(t)\}, at new covariate values, with pointwise confidence limits.

Usage

## S3 method for class 'wnpmle_cmprsk'
predict(
  object,
  newdata = NULL,
  times = NULL,
  conf_int = TRUE,
  conf_level = 0.95,
  ...
)

## S3 method for class 'wnpmle'
predict(
  object,
  newdata = NULL,
  times = NULL,
  conf_int = TRUE,
  conf_level = 0.95,
  ...
)

Arguments

object

A wnpmle object.

newdata

A data frame with the same covariates used in fitting (factors may be given as factors or character strings). If NULL, returns the estimated Lambda(t) for the baseline (all covariates = 0).

times

Time points at which to evaluate the marginal mean. If NULL, uses the observed recurrent event times.

conf_int

Logical; if TRUE (default) and standard errors are available, adds pointwise confidence limits.

conf_level

Confidence level (default 0.95).

...

Ignored.

Details

For competing-risks fits (type = "cmprsk"), predict returns the cumulative incidence of the event of interest, \hat F_1(t \mid z) = 1 - \exp[-G\{e^{\hat\beta^T z} \hat\Lambda(t)\}], in columns cif_i; the confidence limits are those of G\{e^{\beta^T z}\Lambda(t)\} (delta method, log scale) mapped through 1 - \exp(-\cdot), so they stay within (0, 1).

The confidence limits are computed with the delta method from the estimated covariance matrix of (\beta, \Lambda) (vcov(object)), on the log scale so that they stay positive.

Value

A data frame with column time and, for each row i of newdata, columns mu_i and (if conf_int) lower_i and upper_i; or columns mu (and lower, upper) for the baseline.


Print method for wnpmle objects

Description

Print method for wnpmle objects

Usage

## S3 method for class 'wnpmle_cmprsk'
print(x, ...)

## S3 method for class 'wnpmle'
print(x, ...)

Arguments

x

A wnpmle object.

...

Ignored.

Value

Invisibly returns x.


Prepare the colorectal cancer readmission data for wnpmle analysis

Description

Reads the hospital readmission data of 403 colorectal cancer patients (Gonzalez et al., 2005), shipped with wnpmle as a copy of the readmission data from the frailtypack package, and converts them to the format used by wnpmle_fit: one row per readmission (status 1), plus a final row for death (status 2) or censoring (status 0) unless the follow-up of a surviving patient ends with a readmission.

Usage

readmission_prep(tau = NULL)

Arguments

tau

Optional end of follow-up (days). If given, readmissions after tau are removed and patients still under observation at tau (including deaths after tau) are censored at tau. Default NULL: full follow-up.

Details

The data contain 403 patients with 458 readmissions and 109 deaths. All covariates are taken at baseline (the first record of each patient), as required by the marginal rate model with external covariates; the Charlson index recorded later in follow-up is not used. This is the data set analysed in Bellach and Kosorok (2026).

Value

A data frame with columns:

id

Patient identifier.

time

Days since surgery of the readmission, death or censoring.

status

0 = censored, 1 = readmission (recurrent event), 2 = death (terminal event).

chemo

Chemotherapy: factor with levels "NonTreated", "Treated".

sex

Factor with levels "Male", "Female".

dukes

Dukes' tumour stage: factor with levels "A-B", "C", "D".

charlson

Charlson comorbidity index at baseline: factor with levels "0", "1-2", "3".

Source

Copy of the readmission data from the frailtypack package (Rondeau et al.; GPL (>= 2)).

References

Gonzalez, J.R., Fernandez, E., Moreno, V., Ribes, J., Peris, M., Navarro, M., Cambray, M. and Borras, J.M. (2005). Sex differences in hospital readmission among colorectal cancer patients. Journal of Epidemiology and Community Health, 59(6), 506-511. doi:10.1136/jech.2004.028902

Examples

rdata <- readmission_prep()
head(rdata)
table(rdata$status)
table(readmission_prep(tau = 1460)$status)


Summary method for wnpmle objects

Description

Summary method for wnpmle objects

Usage

## S3 method for class 'wnpmle_cmprsk'
summary(object, tau_grid = TRUE, times = NULL, ...)

## S3 method for class 'wnpmle'
summary(object, tau_grid = TRUE, times = NULL, ...)

Arguments

object

A wnpmle object.

tau_grid

Logical; if TRUE (default), also show Lambda at tau/4, tau/2, and tau.

times

Optional numeric vector of time points at which the cumulative baseline is shown instead of tau/4, tau/2 and tau, e.g. times = c(365, 730).

...

Ignored.

Value

An object of class summary.wnpmle, printed with the coefficient table and Lambda at tau/4, tau/2 and tau.


Extract variance-covariance matrix from a wnpmle object

Description

Returns the full variance-covariance matrix for (beta, Lambda). To get only the beta part, use vcov(fit)[1:p, 1:p].

Usage

## S3 method for class 'wnpmle'
vcov(object, ...)

Arguments

object

A wnpmle object.

...

Ignored.

Value

A numeric matrix containing the variance-covariance matrix for the regression coefficients and cumulative baseline mean function. Returns an error if se = "none" was used in wnpmle_fit.


Fit Weighted NPMLE for Survival Data with Recurrent or Competing Events

Description

Estimates the weighted nonparametric maximum likelihood estimator (wNPMLE) for the marginal mean function of recurrent events in the presence of a competing terminal event (type = "recurrent"), or for the subdistribution of a competing risk (type = "cmprsk"). Two transformation models are supported: the Box-Cox model and the logarithmic model.

Usage

wnpmle_fit(
  formula,
  data,
  id = "id",
  type = c("recurrent", "cmprsk", "cmprsk_ltrc"),
  model = c("boxcox", "log"),
  rho = 1,
  r = NULL,
  tau = NULL,
  se = c("sandwich_adj", "sandwich", "fisher", "none"),
  init_beta = NULL,
  control = list(),
  silent = TRUE
)

Arguments

formula

A formula of the form Surv(time, status) ~ covariates, where status takes value 1 for a recurrent event (type = "cmprsk": the event of interest), 2 for the terminal event (type = "cmprsk": the competing event), and 0 for censoring.

data

A data frame containing the variables in formula and an id column identifying subjects.

id

Name of the subject identifier column in data (default: "id").

type

Type of analysis: "recurrent" (default; recurrent events with a competing terminal event, one or more rows per subject) or "cmprsk" (competing risks, one row per subject). A future version will add "cmprsk_ltrc" (competing risks with left truncation and right censoring).

model

Transformation model: "boxcox" (default) or "log".

rho

Box-Cox parameter rho for model = "boxcox" (default 1: the Ghosh-Lin model, or the Fine-Gray model for type = "cmprsk"). For model = "log", use r; rho is still accepted there for backward compatibility.

r

Parameter r of the logarithmic model, G(x) = log(1 + r*x) / r, for model = "log" (default 1: the proportional odds model). Not used for model = "boxcox".

tau

Follow-up truncation time. Kaplan-Meier censoring weights are truncated at tau. If NULL (default), uses the maximum observed time.

se

Variance estimation method: "sandwich_adj" (default, sandwich with censoring correction), "sandwich" (plain sandwich), "fisher" (inverse Hessian), or "none".

init_beta

Initial values for regression coefficients (default: all zeros).

control

A list of control parameters passed to nlminb.

silent

Suppress TMB output (default: TRUE).

Details

Analysis types: type = "recurrent" models the marginal mean \mu(t \mid z) = G\{e^{\beta^T z}\Lambda(t)\} of recurrent events with a competing terminal event (Bellach and Kosorok, 2026). type = "cmprsk" models the cumulative incidence of the event of interest, F_1(t \mid z) = 1 - \exp[-G\{e^{\beta^T z}\Lambda(t)\}] (Bellach, Kosorok, Rüschendorf and Fine, 2019); \rho = 1 in the Box-Cox model is the Fine-Gray model. For type = "cmprsk", subjects observed beyond tau, and the last subjects once the Kaplan-Meier estimate of the censoring distribution drops below 0.05, are censored just after tau; the result has class c("wnpmle_cmprsk", "wnpmle"), and predict() returns cumulative incidences.

Transformation models: The two models differ in the link function G:

Both are estimated via automatic differentiation using TMB. The sandwich variance estimator accounts for the estimation of the censoring weights. The censoring-corrected sandwich adds an influence function correction for the Kaplan-Meier censoring weight estimation.

Value

An object of class "wnpmle" with components:

coefficients

Estimated regression coefficients (beta).

se

Standard errors for the regression coefficients.

Lambda

Estimated cumulative baseline mean function, evaluated at the recurrent event times.

lambda

Estimated baseline increments.

event_times

Recurrent event times at which Lambda is estimated.

loglik

Log-likelihood at the optimum.

vcov

Full variance-covariance matrix for (beta, Lambda).

model

Transformation model used.

rho

Transformation parameter used.

tau

Truncation time used.

n

Number of subjects.

n_events

Named vector: recurrent events, terminal events, censored.

convergence

Convergence message from nlminb.

call

The matched call.

References

Bellach, A. and Kosorok, M.R. (2026). Pseudo-likelihood regression for the marginal rate of recurrent events with a competing terminal event. arXiv preprint arXiv:2605.25934. doi:10.48550/arXiv.2605.25934

Bellach, A., Kosorok, M.R., Rüschendorf, L. and Fine, J.P. (2019). Weighted NPMLE for the subdistribution of a competing risk. Journal of the American Statistical Association, 114(525), 259-270. doi:10.1080/01621459.2017.1401540

Examples

 
  library(survival)
  data("bladder2", package = "survival")
  bladder2_prepped <- bladder_prep()

  fit <- wnpmle_fit(Surv(time, status) ~ treat + num + size,
                    data = bladder2_prepped, id = "id",
                    model = "log", r = 1)
  summary(fit)

  # competing risks: liver transplant (event of interest) versus
  # death or withdrawal from the waiting list (competing events)
  tp <- survival::transplant
  tp <- tp[tp$futime > 0 & complete.cases(tp), ]
  tp$status <- ifelse(tp$event == "ltx", 1,
                      ifelse(tp$event == "censored", 0, 2))
  fit_fg <- wnpmle_fit(Surv(futime, status) ~ age + sex + abo, data = tp,
                       type = "cmprsk", model = "boxcox", rho = 1)  # Fine-Gray
  summary(fit_fg)