| Title: | Sieve Maximum Kernel-Weighted Log-Likelihood Estimation |
|---|---|
| Description: | Estimation and inference when a longitudinal covariate is observed sparsely and intermittently, at times that do not line up with the times at which the outcome is measured. For a survival outcome, fits the transformed hazards family -- proportional hazards, additive hazards, and the Box-Cox transformations between them -- by the Sieve Maximum Kernel-weighted Log-likelihood Estimator (SMKLE) of Sun, Sun, Zhao and Cao (2025) <doi:10.1080/01621459.2025.2476781>, with specialised kernel estimating-equation alternatives for the proportional and additive cases. For a longitudinal outcome recorded on its own time grid, fits generalised linear models by the kernel-weighted estimating equations of Cao, Zeng and Fine (2015) <doi:10.1111/rssb.12086>, with either time-invariant or time-dependent coefficients. Half and full kernels, data simulation, and bandwidth selection by cross-validation are available throughout, and the numerical routines use 'Rcpp', 'RcppArmadillo' and the 'nloptr' C API. |
| Authors: | Dayu Sun [aut, cre, cph] |
| Maintainer: | Dayu Sun <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-12-05 20:01:34 UTC |
| Source: | https://github.com/cran/skmle |
Fitted means belong to covariate occasions. The estimating equation
evaluates the link at each observed covariate vector, and the kernel weight
is what ties that vector to a response occasion. So augment() returns
data_x with a .fitted column, .
## S3 method for class 'kee_async' augment(x, data_x, ...)## S3 method for class 'kee_async' augment(x, data_x, ...)
x |
A |
data_x |
The covariate table the fit was made from. |
... |
Unused. |
The fit does not retain its data, so data_x must be supplied.
data_x as a tibble with a .fitted column added.
set.seed(1) d <- sim_async_data(n = 150) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) augment(fit, d$x)set.seed(1) d <- sim_async_data(n = 150) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) augment(fit, d$x)
Pointwise Wald intervals at each target time.
## S3 method for class 'kee_td' confint(object, parm, level = 0.95, ...)## S3 method for class 'kee_td' confint(object, parm, level = 0.95, ...)
object |
A |
parm |
Coefficients to report, by name or position. Defaults to all. |
level |
Confidence level. |
... |
Unused. |
For skmle and kee fits no method is needed: stats::confint.default()
works once vcov() is available.
A data frame with one row per (target time, coefficient) and columns
time, term, estimate, se, and the two interval endpoints.
set.seed(1) d <- sim_async_data(n = 200, beta = function(tt) cbind(0.5, 1 + tt)) fit <- kee_async_td(d$y, d$x, y ~ x, id = id, time = time, times = c(0.3, 0.5, 0.7), h = 0.3 ) confint(fit)set.seed(1) d <- sim_async_data(n = 200, beta = function(tt) cbind(0.5, 1 + tt)) fit <- kee_async_td(d$y, d$x, y ~ x, id = id, time = time, times = c(0.3, 0.5, 0.7), h = 0.3 ) confint(fit)
One-row summary of a fit
## S3 method for class 'skmle' glance(x, ...) ## S3 method for class 'kee' glance(x, ...) ## S3 method for class 'kee_td' glance(x, ...)## S3 method for class 'skmle' glance(x, ...) ## S3 method for class 'kee' glance(x, ...) ## S3 method for class 'kee_td' glance(x, ...)
x |
A fitted |
... |
Unused. |
A one-row tibble. nobs is the number of subjects.
set.seed(1) d <- sim_async_data(n = 150) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) glance(fit)set.seed(1) d <- sim_async_data(n = 150) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) glance(fit)
Fit the additive hazards model for sparse longitudinal covariate data using a kernel estimating-equation approach.
kee_additive( formula, data, id, obs_times, h = NULL, lq_nodes = 64, one_sided = TRUE, weight = NULL )kee_additive( formula, data, id, obs_times, h = NULL, lq_nodes = 64, one_sided = TRUE, weight = NULL )
formula |
A model formula with a |
data |
Data frame containing all variables used in the fit. |
id |
Subject identifier aligned row-wise with |
obs_times |
Longitudinal observation times aligned row-wise with |
h |
Positive kernel bandwidth. If omitted, one is read off the
observation times as a rule of thumb and reported in a message. Use
|
lq_nodes |
Number of quadrature nodes used in the numerical integration step. |
one_sided |
Logical. |
weight |
Weight function of the standardised lag |
kee_additive() is the specialized additive-hazards counterpart to kee_cox().
It uses a kernel-smoothed martingale estimating equation and typically runs faster
than the general skmle(s = 1) fit because it solves a more specialized problem.
An object of class kee containing coefficient estimates, an estimated
variance-covariance matrix, intermediate matrices used for sandwich variance
estimation, and model metadata.
Sun, Dayu, Zhuowei Sun, Xingqiu Zhao, and Hongyuan Cao. "Kernel Meets Sieve: Transformed Hazards Models with Sparse Longitudinal Covariates." Journal of the American Statistical Association 120(552), 2580-2591. doi:10.1080/01621459.2025.2476781
Sun, Zhuowei, Hongyuan Cao, and Li Chen. "Regression Analysis of Additive Hazards Model with Sparse Longitudinal Covariates." Lifetime Data Analysis (2022). doi:10.1007/s10985-022-09548-6
library(survival) set.seed(123) dat <- sim_skmle_data( n = 80, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 1, cen = 0.7 ) fit_add <- kee_additive( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5 ) summary(fit_add)library(survival) set.seed(123) dat <- sim_skmle_data( n = 80, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 1, cen = 0.7 ) fit_add <- kee_additive( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5 ) summary(fit_add)
Regress a sparsely observed longitudinal response on a sparsely observed longitudinal covariate when the two are measured on different time grids and are never seen together.
Each response occasion is paired with every covariate occasion
of the same subject, and each pair contributes in proportion to
its time separation, so no pair is discarded and no value is carried forward.
The estimator solves the kernel-weighted estimating equation of Cao, Zeng and
Fine (2015),
with and the Epanechnikov kernel.
kee_async( data_y, data_x, formula, id, time, h = NULL, one_sided = FALSE, link = c("identity", "log", "logistic"), intercept = TRUE, maxit = 50L, tol = 1e-08 )kee_async( data_y, data_x, formula, id, time, h = NULL, one_sided = FALSE, link = c("identity", "log", "logistic"), intercept = TRUE, maxit = 50L, tol = 1e-08 )
data_y |
Data frame of response occasions: one row per time the response was recorded. First argument, so the function pipes. |
data_x |
Data frame of covariate occasions: one row per time the
covariates were recorded. Its time grid need not overlap |
formula |
A two-sided formula, |
id |
Subject identifier naming a column present in both tables.
Give it unquoted ( |
time |
Observation time, naming a column present in both tables.
Accepts the same three forms as |
h |
Positive bandwidth, on the same scale as |
one_sided |
Logical. |
link |
One of |
intercept |
Logical, include an intercept. |
maxit, tol
|
Newton-Raphson controls, ignored when |
An object of class kee with components
Named coefficient vector.
Sandwich covariance matrix .
The bread and the meat of the sandwich.
Per-subject score contributions, one row per subject;
Sigma is crossprod(scores).
Number of subjects, the unit the asymptotics are in.
Number of weighted (response, covariate) pairs contributing.
Fit settings.
0 converged, 1 singular, 2 hit maxit.
The matched call.
coef(), vcov(), confint(), nobs(), print() and summary() methods
are available.
h is on the same scale as the observation times. Small h admits few
pairs; large h admits pairs far apart in time. Fit at a few values of h
and compare the estimates. A warning is issued when fewer than 5% of response
occasions have any covariate observation in their window, which usually means
h is on the wrong scale.
one_sided = FALSE, the default, is the full two-sided kernel of the paper.
one_sided = TRUE admits only covariate observations strictly before the
response. It uses roughly half the pairs, so it needs a larger h for the
same effective sample size.
Observation times are assumed independent of the response and covariate processes.
Cao, H., Zeng, D. and Fine, J. P. (2015). Regression analysis of sparse asynchronous longitudinal data. Journal of the Royal Statistical Society, Series B 77, 755-776.
kee_async_td() for a coefficient curve ,
sim_async_data() to simulate.
set.seed(1) d <- sim_async_data(n = 150, beta = c(0.5, 1.5)) # The two tables are on different time grids and share only `id`. head(d$y, 3) head(d$x, 3) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.25) summary(fit) confint(fit) tidy(fit, conf.int = TRUE) # Data comes first, so it pipes. d$y |> kee_async(d$x, y ~ x, id = id, time = time, h = 0.25) |> glance() # Half kernel: only covariate observations preceding the response. kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.25, one_sided = TRUE)set.seed(1) d <- sim_async_data(n = 150, beta = c(0.5, 1.5)) # The two tables are on different time grids and share only `id`. head(d$y, 3) head(d$x, 3) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.25) summary(fit) confint(fit) tidy(fit, conf.int = TRUE) # Data comes first, so it pipes. d$y |> kee_async(d$x, y ~ x, id = id, time = time, h = 0.25) |> glance() # Half kernel: only covariate observations preceding the response. kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.25, one_sided = TRUE)
Fit from asynchronous
sparse longitudinal data, estimating the coefficient curve
pointwise. This is the time-dependent coefficient estimator of Cao, Zeng and
Fine (2015), the companion to kee_async().
At a target time a response occasion and a covariate occasion are
weighted by their separate distances to ,
The lag between the two occasions never enters, only their distances to
. That is the difference from kee_async(), where the lag is
everything.
kee_async_td( data_y, data_x, formula, id, time, times = NULL, h = NULL, h2 = h, one_sided = FALSE, link = c("identity", "log", "logistic"), intercept = TRUE, maxit = 50L, tol = 1e-08 ) ## S3 method for class 'kee_td' print(x, ...)kee_async_td( data_y, data_x, formula, id, time, times = NULL, h = NULL, h2 = h, one_sided = FALSE, link = c("identity", "log", "logistic"), intercept = TRUE, maxit = 50L, tol = 1e-08 ) ## S3 method for class 'kee_td' print(x, ...)
data_y |
Data frame of response occasions: one row per time the response was recorded. First argument, so the function pipes. |
data_x |
Data frame of covariate occasions: one row per time the
covariates were recorded. Its time grid need not overlap |
formula |
A two-sided formula, |
id |
Subject identifier naming a column present in both tables.
Give it unquoted ( |
time |
Observation time, naming a column present in both tables.
Accepts the same three forms as |
times |
Numeric vector of target times at which to estimate
|
h |
Bandwidth for the response side, |
h2 |
Bandwidth for the covariate side, |
one_sided |
Logical. |
link |
One of |
intercept |
Logical, include an intercept. |
maxit, tol
|
Newton-Raphson controls, ignored when |
x |
A |
... |
Ignored. |
An object of class kee_td:
length(times) by p matrix of .
Pointwise standard errors and Wald statistics, the
same shape as coefficients.
List of sandwich matrices, one per target time.
Fit settings.
Covariate rows carrying nonzero weight at each target time.
Per target time: 0 converged, 1 singular, 2 hit
maxit, 3 no data in the window.
coef(), vcov(), confint(), nobs(), print() and plot() methods are
available.
se holds sandwich standard errors at each target time; the bands drawn by
plot.kee_td() are pointwise. Keep times inside the observed time range.
Both time arguments are smoothed, so the curve needs more data than a
time-invariant fit from kee_async().
The product weight factorises over the two occasion indices, so no pair is
ever enumerated: the response side collapses to two per-subject scalars and
the covariate side to one weight per row. Each target time costs
. Fits at successive target times are warm-started from
the previous solution when the link is nonlinear.
Cao, H., Zeng, D. and Fine, J. P. (2015). Regression analysis of sparse asynchronous longitudinal data. Journal of the Royal Statistical Society, Series B 77, 755-776.
set.seed(1) d <- sim_async_data(n = 200, beta = function(tt) cbind(0.5, 1 + tt)) fit <- d$y |> kee_async_td(d$x, y ~ x, id = id, time = time, times = seq(0.2, 0.8, by = 0.1), h = 0.3 ) coef(fit) tidy(fit)set.seed(1) d <- sim_async_data(n = 200, beta = function(tt) cbind(0.5, 1 + tt)) fit <- d$y |> kee_async_td(d$x, y ~ x, id = id, time = time, times = seq(0.2, 0.8, by = 0.1), h = 0.3 ) coef(fit) tidy(fit)
Fit the proportional hazards model for sparse longitudinal covariate data using a kernel estimating-equation approach.
kee_cox( formula, data, id, obs_times, h = NULL, one_sided = TRUE, weight = NULL )kee_cox( formula, data, id, obs_times, h = NULL, one_sided = TRUE, weight = NULL )
formula |
A model formula with a |
data |
Data frame containing all variables used in the fit. |
id |
Subject identifier aligned row-wise with |
obs_times |
Longitudinal observation times aligned row-wise with |
h |
Positive kernel bandwidth. If omitted, one is read off the
observation times as a rule of thumb and reported in a message. Use
|
one_sided |
Logical. |
weight |
Weight function of the standardised lag |
kee_cox() targets the proportional hazards case without estimating a nonparametric
baseline component. It is therefore a useful specialized alternative to skmle()
when the scientific model is Cox-type and the main interest is in the regression
coefficients.
An object of class kee containing coefficient estimates, the estimated
variance-covariance matrix, the estimating-equation matrices W and
Sigma, the per-subject score contributions scores (one row per subject,
so that Sigma is crossprod(scores) / n^2), convergence status, and the
original function call.
obs_times may be negative. Event times may not, and a negative event time
is an error: in skmle() and kee_additive() the sieve basis and the
cumulative-hazard quadrature are built on [0, max(X)], and every estimator
takes the time origin to be zero. Observation times carry no such
constraint. They enter the score only through the lag X - obs_times, and
the half kernel admits a row on the sign of that lag rather than on the sign
of the time, so a covariate observed at -180 and an event at 30 sit a lag
of 210 apart and are handled like any other pair.
A pre-origin observation contributes only where it falls within h of an
event time. Use negative times for ordinary measurements taken before entry
on the same scale, such as a run-in visit or a screening draw.
Sun, Dayu, Zhuowei Sun, Xingqiu Zhao, and Hongyuan Cao. "Kernel Meets Sieve: Transformed Hazards Models with Sparse Longitudinal Covariates." Journal of the American Statistical Association 120(552), 2580-2591. doi:10.1080/01621459.2025.2476781
Cao, Hongyuan, Mathew M. Churpek, Donglin Zeng, and Jason P. Fine. "Analysis of the Proportional Hazards Model with Sparse Longitudinal Covariates." Journal of the American Statistical Association 110(511), 1187-1196 (2015). doi:10.1080/01621459.2014.957289
library(survival) set.seed(123) dat <- sim_skmle_data( n = 80, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit_cox <- kee_cox( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5 ) summary(fit_cox)library(survival) set.seed(123) dat <- sim_skmle_data( n = 80, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit_cox <- kee_cox( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5 ) summary(fit_cox)
A weight function says how much a covariate observation at lag u from a
time contributes to the estimating equation at that time, where u is the
lag divided by the bandwidth. Every estimator in this package takes one
through its weight argument, and any R function of u will do: the
Epanechnikov kernels here are a starting point, not the only option.
w_epan_half() w_epan_full()w_epan_half() w_epan_full()
A function of one argument, the standardised lag
as a vector or a matrix, returning the weight with the
shape of its argument preserved and carrying a support attribute.
w_epan_half(): The Epanechnikov half kernel
on , the default for the survival
estimators and the weight every published result in this package was
computed with.
w_epan_full(): The Epanechnikov full kernel
on , the default for the asynchronous
longitudinal estimators and the kernel of Cao, Zeng and Fine (2015).
Symmetry kills the first moment, so it is order 2.
A weight is a function of one argument, the standardised lag
, returning a value of the same shape. It is called on
vectors and on matrices, and it must preserve the shape it is given: the
sieve quadrature evaluates it on a matrix of node-by-observation lags. Zero
outside its own support is the function's own responsibility.
gauss_half <- function(u) exp(-u^2 / 2) * (u >= 0 & u <= 3)
kee_cox(Surv(X, delta) ~ z, data, id = id, obs_times = r,
h = 0.3, weight = gauss_half)
Nothing about the function has to be polynomial, nonnegative or symmetric. A weight that takes negative values is supported throughout: the estimating equations admit a row on whether its weight is nonzero, not on whether it is positive.
support is the one attribute worth setting, as a length-2 numeric giving
the interval outside which the weight is zero. It is used to enumerate pairs
in the asynchronous estimators, where scanning every pair would otherwise be
quadratic, and to choose the rows that carry a feasibility constraint in
skmle() with s != 0. Without it a default of [-1, 1] is assumed; the
constraint rows also include every row whose weight is nonzero, so a
missing attribute never leaves a weighted row unconstrained.
The same weight is used in every term of each estimating equation: the row
weights, the risk-set averages and, for skmle(), the cumulative-hazard
integral and both sandwich matrices. Nothing in the package falls back to a
built-in kernel.
The weight is used as . A weight that integrates to something
other than 1 is not wrong: the normalisation cancels wherever the weight
appears in a ratio, which is everywhere in the risk-set averages, and is
absorbed into h elsewhere. w_epan_half() integrates to 1/2 for that
reason and is the weight every published result in this package used.
one_sided is a modelling choice, not a property of the weight. It is the
risk-set restriction of a hazard model: only covariate observations strictly
before a time may inform it. It is applied on the sign of the lag after the
weight has been evaluated, so a two-sided weight under one_sided = TRUE is
truncated at zero rather than rejected.
W <- w_epan_half() W(c(-0.5, 0, 0.5, 1, 1.5)) attr(W, "support") # Any function of the standardised lag is a weight. tri <- function(u) pmax(1 - abs(u), 0) tri(c(-0.5, 0, 0.5))W <- w_epan_half() W(c(-0.5, 0, 0.5, 1, 1.5)) attr(W, "support") # Any function of the standardised lag is a weight. tri <- function(u) pmax(1 - abs(u), 0) tri(c(-0.5, 0, 0.5))
Returns the number of subjects, which is what summary() prints as n.
## S3 method for class 'skmle' nobs(object, ...) ## S3 method for class 'kee' nobs(object, ...) ## S3 method for class 'kee_td' nobs(object, ...)## S3 method for class 'skmle' nobs(object, ...) ## S3 method for class 'kee' nobs(object, ...) ## S3 method for class 'kee_td' nobs(object, ...)
object |
A fitted |
... |
Unused. |
An integer, the number of subjects.
set.seed(1) d <- sim_async_data(n = 120) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) nobs(fit)set.seed(1) d <- sim_async_data(n = 120) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) nobs(fit)
The held-out loss against the candidate bandwidths, with the selected value marked. Worth a glance every time: if the curve is still falling at an endpoint of the grid, the "selected" bandwidth is where you stopped looking rather than a minimum, and the grid should be widened.
## S3 method for class 'cv.skmle' plot(x, ...)## S3 method for class 'cv.skmle' plot(x, ...)
x |
A |
... |
Passed to |
x, invisibly. Called for the plot.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) cv <- skmle_cv(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, K = 3, seed = 2026, quiet = TRUE) plot(cv)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) cv <- skmle_cv(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, K = 3, seed = 2026, quiet = TRUE) plot(cv)
Draws against t with pointwise Wald bands, one panel
per coefficient.
## S3 method for class 'kee_td' plot(x, which = seq_len(ncol(x$coefficients)), level = 0.95, ...)## S3 method for class 'kee_td' plot(x, which = seq_len(ncol(x$coefficients)), level = 0.95, ...)
x |
A |
which |
Integer or character vector selecting coefficients to draw. Defaults to all. |
level |
Confidence level for the pointwise bands. |
... |
Passed to |
x, invisibly. Called for the plot.
set.seed(1) d <- sim_async_data(n = 200, beta = function(tt) cbind(0.5, 1 + tt)) fit <- d$y |> kee_async_td(d$x, y ~ x, id = id, time = time, times = seq(0.2, 0.8, by = 0.05), h = 0.3 ) plot(fit)set.seed(1) d <- sim_async_data(n = 200, beta = function(tt) cbind(0.5, 1 + tt)) fit <- d$y |> kee_async_td(d$x, y ~ x, id = id, time = time, times = seq(0.2, 0.8, by = 0.05), h = 0.3 ) plot(fit)
Plot the estimated baseline function for skmle model
## S3 method for class 'skmle' plot(x, t_seq = NULL, ...)## S3 method for class 'skmle' plot(x, t_seq = NULL, ...)
x |
An object of class |
t_seq |
Time points at which to evaluate the baseline. Defaults to 100 points spanning the follow-up the model was fitted on. |
... |
Further arguments passed to or from other methods. |
A ggplot object showing the estimated nonparametric baseline
function evaluated on t_seq.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) plot(fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) plot(fit)
Print kee object
## S3 method for class 'kee' print(x, ...)## S3 method for class 'kee' print(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. |
x, invisibly. Called for its side effect of printing a brief
summary of the call and estimated coefficients.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- kee_cox(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5) print(fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- kee_cox(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5) print(fit)
Print skmle object
## S3 method for class 'skmle' print(x, ...)## S3 method for class 'skmle' print(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. |
x, invisibly. Called for its side effect of printing a brief
summary of the call and estimated coefficients.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) print(fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) print(fit)
Print summary of kee object
## S3 method for class 'summary.kee' print(x, ...)## S3 method for class 'summary.kee' print(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. |
x, invisibly. Called for its side effect of printing the
summary table.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- kee_cox(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5) print(summary(fit))library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- kee_cox(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5) print(summary(fit))
Print summary of skmle object
## S3 method for class 'summary.skmle' print(x, ...)## S3 method for class 'summary.skmle' print(x, ...)
x |
An object of class |
... |
Further arguments passed to or from other methods. |
x, invisibly. Called for its side effect of printing the
summary table.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) print(summary(fit))library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) print(summary(fit))
Draw a sparse longitudinal response and a sparse longitudinal covariate whose
observation times are independent, so the two are never seen together.
This is the design of Cao, Zeng and Fine (2015), Section 4: response times and
covariate times are independent Poisson streams on , the covariate
is a mean-zero Gaussian process, and the error is a second, independent
Gaussian process.
sim_async_data( n, beta = c(0.5, 1.5), lambda_y = 5, lambda_x = 5, link = c("identity", "log", "logistic"), x_cov = function(s, t) exp(-abs(s - t)), e_cov = function(s, t) 2^(-abs(s - t)) )sim_async_data( n, beta = c(0.5, 1.5), lambda_y = 5, lambda_x = 5, link = c("identity", "log", "logistic"), x_cov = function(s, t) exp(-abs(s - t)), e_cov = function(s, t) 2^(-abs(s - t)) )
n |
Number of subjects. |
beta |
Either a numeric vector |
lambda_y, lambda_x
|
Poisson rates for the response and covariate
observation streams on |
link |
One of |
x_cov, e_cov
|
Covariance functions of two times, vectorised, for the covariate and error processes. |
The default covariate covariance is the Ornstein-
Uhlenbeck covariance. Its diagonal has a kink, so it is only one-sided
differentiable, which is exactly the case Cao, Zeng and Fine's Section 6
leaves open. Supply a smooth
x_cov, for instance function(s, t) exp(-(s - t)^2), to generate data
inside their stated assumptions instead.
beta may be a numeric vector, giving time-invariant coefficients suitable
for kee_async(), or a function of time returning one row per supplied time,
giving a coefficient curve suitable for kee_async_td(). In both cases the
first element is the intercept and the remaining p elements multiply the p
covariate coordinates.
A list of two tibbles on different time grids:
id, time, y – one row per response occasion.
id, time, and one column per covariate coordinate – named
x when there is a single covariate, x1, x2, ... otherwise. One row
per covariate occasion, on a time grid independent of y's.
Cao, H., Zeng, D. and Fine, J. P. (2015). Regression analysis of sparse asynchronous longitudinal data. Journal of the Royal Statistical Society, Series B 77, 755-776.
set.seed(1) d <- sim_async_data(n = 50) str(d) # The two tables share `id` and nothing else; their `time` grids are # independent draws, which is what makes the data asynchronous. head(d$y, 3) head(d$x, 3) # A coefficient curve, for kee_async_td(). d2 <- sim_async_data(n = 50, beta = function(tt) cbind(0.5, 1 + tt))set.seed(1) d <- sim_async_data(n = 50) str(d) # The two tables share `id` and nothing else; their `time` grids are # independent draws, which is what makes the data asynchronous. head(d$y, 3) head(d$x, 3) # A coefficient curve, for kee_async_td(). d2 <- sim_async_data(n = 50, beta = function(tt) cbind(0.5, 1 + tt))
Simulate right-censored survival data with sparsely and intermittently observed longitudinal covariates under a transformed hazards model.
sim_skmle_data(n, mu, mu_bar, alpha, beta, s, cen, nstep = 20)sim_skmle_data(n, mu, mu_bar, alpha, beta, s, cen, nstep = 20)
n |
Number of subjects to simulate. |
mu |
Function giving the intensity of the observation-time process for the longitudinal covariates. |
mu_bar |
Numeric upper bound for |
alpha |
Function giving the baseline component of the transformed hazards model. |
beta |
Numeric vector of true regression coefficients. The current simulator
supports exactly two covariates, so |
s |
Box-Cox transformation parameter. Use |
cen |
Positive censoring parameter controlling the follow-up window. |
nstep |
Number of grid intervals used to generate the latent piecewise-constant time-varying covariate process. |
The simulated data are returned in long format, with one row per subject-visit pair. Each row contains the observed event or censoring time, the event indicator, the observation time for the longitudinal covariate, and the covariate values observed at that visit.
The first covariate is generated as a latent step function over time. The second covariate is a binary subject-level indicator. Event times are generated by numerically inverting the cumulative transformed hazard, and observation times are generated from a non-homogeneous Poisson process.
A tibble in long format with columns:
id: subject identifier.
X: observed event or censoring time.
delta: event indicator.
covariates: a two-column matrix of observed covariates at obs_times.
obs_times: longitudinal observation time.
censoring: subject-specific censoring time.
set.seed(123) sim_data <- sim_skmle_data( n = 50, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) head(sim_data) table(sim_data$delta) # The `covariates` column is a matrix; use it directly in model formulas # or split it into explicit columns if preferred. sim_data$Z1 <- sim_data$covariates[, 1] sim_data$Z2 <- sim_data$covariates[, 2] head(sim_data[, c("id", "X", "delta", "obs_times", "Z1", "Z2")])set.seed(123) sim_data <- sim_skmle_data( n = 50, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) head(sim_data) table(sim_data$delta) # The `covariates` column is a matrix; use it directly in model formulas # or split it into explicit columns if preferred. sim_data$Z1 <- sim_data$covariates[, 1] sim_data$Z2 <- sim_data$covariates[, 2] head(sim_data[, c("id", "X", "delta", "obs_times", "Z1", "Z2")])
Fit a transformed hazards model for survival data with sparsely and intermittently observed longitudinal covariates using the sieve maximum kernel-weighted log-likelihood estimator (SMKLE).
skmle( formula, data, id, obs_times, s = 0, h = NULL, nknots = 3, lq_nodes = 64, maxeval = 10000, xtol_rel = 1e-06, one_sided = TRUE, weight = NULL, optimizer = c("slsqp", "barrier") )skmle( formula, data, id, obs_times, s = 0, h = NULL, nknots = 3, lq_nodes = 64, maxeval = 10000, xtol_rel = 1e-06, one_sided = TRUE, weight = NULL, optimizer = c("slsqp", "barrier") )
formula |
A model formula. The left-hand side must be a |
data |
Data frame containing the variables used in |
id |
Subject identifier. Non-numeric identifiers are allowed and are internally converted to integer subject codes. |
obs_times |
Longitudinal observation times aligned row-wise with |
s |
Box-Cox transformation parameter, defaulting to |
h |
Positive kernel bandwidth. If omitted, one is read off the
observation times as a rule of thumb and reported in a message. Use
|
nknots |
Number of interior knots used in the sieve approximation of the
baseline component. Knots are placed at |
lq_nodes |
Number of Legendre-Gauss quadrature nodes used in numerical integration. |
maxeval |
Maximum number of optimizer evaluations. |
xtol_rel |
Relative convergence tolerance passed to the optimizer. |
one_sided |
Logical. |
weight |
Weight function of the standardised lag |
optimizer |
|
skmle() is the main model-fitting function in the package. It combines:
kernel weighting to handle intermittently observed longitudinal covariates,
a sieve approximation for the unknown baseline component, and
a C++-backed numerical optimizer for the joint estimation problem.
The returned object follows the usual R model pattern: print the fitted coefficients
with print(), obtain inferential output with summary(), and visualize the
estimated baseline component with plot().
An object of class skmle containing:
coefficients: regression coefficient estimates,
var: estimated variance-covariance matrix for the regression coefficients,
gamma: estimated spline coefficients for the baseline component,
loglik: maximized log-likelihood,
convergence: optimizer status code,
scores: per-subject contributions to the score for the coefficients
(one row per subject), from which the sandwich's B is formed,
model metadata such as n, s, h, and call.
Sun, Dayu, Zhuowei Sun, Xingqiu Zhao, and Hongyuan Cao. "Kernel Meets Sieve: Transformed Hazards Models with Sparse Longitudinal Covariates." Journal of the American Statistical Association 120(552), 2580-2591. doi:10.1080/01621459.2025.2476781
library(survival) set.seed(123) dat <- sim_skmle_data( n = 80, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3 ) summary(fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 80, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3 ) summary(fit)
Perform K-fold cross-validation to select the kernel bandwidth for skmle().
skmle_cv( formula, data, id, obs_times, s = 0, K = 5, h_grid = NULL, n_h = 10, nknots = 3, lq_nodes = 64, maxeval = 10000, xtol_rel = 1e-06, seed = NULL, quiet = FALSE, one_sided = TRUE, weight = NULL ) ## S3 method for class 'cv.skmle' print(x, ...)skmle_cv( formula, data, id, obs_times, s = 0, K = 5, h_grid = NULL, n_h = 10, nknots = 3, lq_nodes = 64, maxeval = 10000, xtol_rel = 1e-06, seed = NULL, quiet = FALSE, one_sided = TRUE, weight = NULL ) ## S3 method for class 'cv.skmle' print(x, ...)
formula |
A model formula. The left-hand side must be a |
data |
Data frame containing the variables used in |
id |
Subject identifier. Non-numeric identifiers are allowed and are internally converted to integer subject codes. |
obs_times |
Longitudinal observation times aligned row-wise with |
s |
Box-Cox transformation parameter, defaulting to |
K |
Number of folds. |
h_grid |
Optional numeric vector of candidate bandwidth values. If |
n_h |
Number of candidate bandwidths to generate when |
nknots |
Number of interior knots used in the sieve approximation of the
baseline component. Knots are placed at |
lq_nodes |
Number of Legendre-Gauss quadrature nodes used in numerical integration. |
maxeval |
Maximum number of optimizer evaluations. |
xtol_rel |
Relative convergence tolerance passed to the optimizer. |
seed |
Optional integer seed for the random subject-to-fold assignment.
If |
quiet |
Logical; if |
one_sided |
Logical. |
weight |
Weight function of the standardised lag |
x |
A |
... |
Ignored. |
An object of class cv.skmle with components:
h_cv: selected bandwidth,
fit: skmle fit refit on the full data,
cv_results: data frame of candidate bandwidths, their CV losses, and the
standard error of each loss across the folds,
h_grid: bandwidth grid used in the search,
fold_id: the subject-to-fold assignment vector (length n),
seed: the value of seed supplied by the user, or NULL,
call: the matched call.
one_sided is used inside the fold loop as well as being passed through to
the refit, so the bandwidth is selected under the same kernel the final fit
uses.
skmle_cv() splits subjects across folds. Several rows belong to the same
subject in long format, so splitting by row would put one subject on both
sides of the split.
After choosing the bandwidth with the smallest average validation loss, the
function refits skmle() on the full data set using the selected value.
Because the fold assignment is random, pass seed (or set.seed() before
calling) to make the grid selection reproducible.
Each training fold is fitted at the candidate bandwidth, and the fit is scored on the held-out subjects by the log-likelihood per subject,
where is the covariate carried forward from the last observation
at or before . This loss does not depend on the bandwidth itself, so
it compares candidates on an equal footing.
When h_grid is NULL the grid is log-spaced over
, with
, so it adapts to the scale of the times on its own.
If the selected value is an endpoint of the grid, skmle_cv() warns; supply
a wider h_grid.
cv_results lists the loss and its standard error across folds for every
candidate.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) cv_fit <- skmle_cv( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, K = 3, seed = 2026, quiet = TRUE ) cv_fit$h_cv # Read the whole table, not just the selection: a minimum on the edge of the # grid is a boundary artefact and warns. cv_fit$cv_results summary(cv_fit$fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) cv_fit <- skmle_cv( Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, K = 3, seed = 2026, quiet = TRUE ) cv_fit$h_cv # Read the whole table, not just the selection: a minimum on the edge of the # grid is a boundary artefact and warns. cv_fit$cv_results summary(cv_fit$fit)
Summary for kee object
## S3 method for class 'kee' summary(object, ...)## S3 method for class 'kee' summary(object, ...)
object |
An object of class |
... |
Further arguments passed to or from other methods. |
An object of class summary.kee containing the call,
a coefficient table with estimates, standard errors, z-statistics
and p-values, the convergence code, and the sample size n.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- kee_cox(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5) summary(fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- kee_cox(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, h = 0.5) summary(fit)
Summary for skmle object
## S3 method for class 'skmle' summary(object, ...)## S3 method for class 'skmle' summary(object, ...)
object |
An object of class |
... |
Further arguments passed to or from other methods. |
An object of class summary.skmle containing the call,
a coefficient table with estimates, standard errors, z-statistics
and p-values, the log-likelihood, convergence status, and the sample
size n.
library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) summary(fit)library(survival) set.seed(123) dat <- sim_skmle_data( n = 60, mu = function(tt) 8 * (0.75 + (0.5 - tt)^2), mu_bar = 8, alpha = function(tt) 0.5 * 0.75 + 0.75 * (tt * (1 - sin(2 * pi * (tt - 0.25)))), beta = c(1, -0.5), s = 0, cen = 0.7 ) fit <- skmle(Surv(X, delta) ~ covariates, data = dat, id = id, obs_times = obs_times, s = 0, h = 0.5, nknots = 3) summary(fit)
One row per coefficient for skmle and kee fits, and one row per
(target time, coefficient) for kee_td, so a coefficient curve goes
straight into ggplot2 without reshaping.
## S3 method for class 'skmle' tidy(x, conf.int = FALSE, conf.level = 0.95, ...) ## S3 method for class 'kee' tidy(x, conf.int = FALSE, conf.level = 0.95, ...) ## S3 method for class 'kee_td' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)## S3 method for class 'skmle' tidy(x, conf.int = FALSE, conf.level = 0.95, ...) ## S3 method for class 'kee' tidy(x, conf.int = FALSE, conf.level = 0.95, ...) ## S3 method for class 'kee_td' tidy(x, conf.int = FALSE, conf.level = 0.95, ...)
x |
A fitted |
conf.int |
Logical, add |
conf.level |
Confidence level for those columns. |
... |
Unused. |
A tibble with columns term, estimate, std.error, statistic
and p.value, preceded by time for a kee_td fit, and followed by
conf.low and conf.high when conf.int = TRUE.
set.seed(1) d <- sim_async_data(n = 150) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) tidy(fit, conf.int = TRUE)set.seed(1) d <- sim_async_data(n = 150) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) tidy(fit, conf.int = TRUE)
Extract the covariance matrix of a fitted model
## S3 method for class 'skmle' vcov(object, ...) ## S3 method for class 'kee' vcov(object, ...) ## S3 method for class 'kee_td' vcov(object, time = NULL, ...)## S3 method for class 'skmle' vcov(object, ...) ## S3 method for class 'kee' vcov(object, ...) ## S3 method for class 'kee_td' vcov(object, time = NULL, ...)
object |
A fitted |
... |
Unused. |
time |
For a |
For skmle and kee, the estimated covariance matrix of the
regression coefficients. For kee_td, see time.
set.seed(1) d <- sim_async_data(n = 120) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) vcov(fit)set.seed(1) d <- sim_async_data(n = 120) fit <- kee_async(d$y, d$x, y ~ x, id = id, time = time, h = 0.3) vcov(fit)