| Title: | Time-to-Event Landmark Analysis using an Array of Longitudinal and Survival Sub-Models |
| Version: | 0.1.1 |
| Description: | Provides a modular end-to-end framework for dynamic risk prediction based on time-to-event and longitudinal data. This allows flexible specifications for the longitudinal and survival sub-models. The 'landmaRk' package enables reproducible benchmarks of different model choices, including cross-validation to assess out-of-sample predictive performance. Methods are described in Velasco-Pardo, Constantine-Cooke, Lees and Vallejos (2026, manuscript under preparation) 'Landmarking with Latent Class Mixed Models for Dynamic Prediction of Time-to-event Data with Heterogeneous Biomarker Trajectories'. |
| License: | GPL (≥ 3) |
| BugReports: | https://github.com/VallejosGroup/landmaRk/issues |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Depends: | R (≥ 4.1.0), survival |
| Imports: | dplyr, ggplot2, lme4, Matrix, methods, pec, riskRegression, rlang, lcmm (≥ 2.2.2), doParallel, foreach, utils, timeROC, prodlim |
| Suggests: | JMbayes2, knitr, rmarkdown, testthat (≥ 3.0.0), xml2, tidyverse, spelling, joineR, survminer, withr |
| Config/testthat/edition: | 3 |
| Config/testthat/parallel: | true |
| LazyData: | true |
| VignetteBuilder: | knitr |
| URL: | https://vallejosgroup.github.io/landmaRk/, https://github.com/VallejosGroup/landmaRk |
| Language: | en-GB |
| NeedsCompilation: | no |
| Packaged: | 2026-05-18 09:12:58 UTC; vvelasco |
| Author: | Victor Velasco-Pardo
|
| Maintainer: | Victor Velasco-Pardo <vvelasco@ed.ac.uk> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-27 10:00:16 UTC |
landmaRk
Description
Provides a modular end-to-end framework for dynamic risk prediction based on time-to-event and longitudinal data. This allows flexible specifications for the longitudinal and survival sub-models. The 'landmaRk' package enables reproducible benchmarks of different model choices, including cross-validation to assess out-of-sample predictive performance. Methods are described in Velasco-Pardo, Constantine-Cooke, Lees and Vallejos (2026, manuscript under preparation) 'Landmarking with Latent Class Mixed Models for Dynamic Prediction of Time-to-event Data with Heterogeneous Biomarker Trajectories'.
Author(s)
Maintainer: Victor Velasco-Pardo vvelasco@ed.ac.uk (ORCID)
Authors:
Nathan Constantine-Cooke nathan.constantine-cooke@ed.ac.uk (ORCID)
Catalina Vallejos catalina.vallejos@ed.ac.uk (ORCID)
Charlie Lees charlie.lees@ed.ac.uk (ORCID)
See Also
Useful links:
Report bugs at https://github.com/VallejosGroup/landmaRk/issues
Creates an S4 class for a landmarking analysis
Description
Creates an S4 class for a landmarking analysis
Usage
LandmarkAnalysis(
data_static,
data_dynamic,
event_indicator,
ids,
event_time,
times,
measurements,
censor_at_landmark = TRUE,
K = 1
)
Arguments
data_static |
A data frame containing subject ids, static covariates, |
data_dynamic |
Data frame in long format with subject ids, measurement values, measurement times and measurement name. |
event_indicator |
Name of the column indicating event or censoring. |
ids |
Name of the column indicating subject ids. |
event_time |
Name of the column indicating time of the event/censoring. |
times |
Name of the column indicating observation time in
|
measurements |
Name of the column indicating measurement values in
|
censor_at_landmark |
Boolean indicating whether to fit a single longitudinal model to the complete dataset (FALSE) or to censor observations at the landmark time prior to fitting the longitudinal model, iterating through landmark times (TRUE; default) |
K |
Number of cross-validation folds (by default, 1). |
Value
An object of class LandmarkAnalysis
S4 class for performing a landmarking analysis
Description
S4 class for performing a landmarking analysis
Slots
landmarksA numeric vector of landmark times.
data_staticA data frame containing subject ids, static covariates,
data_dynamicData frame in long format with subject ids, measurement values, measurement times and measurement name.
event_indicatorName of the column indicating event or censoring.
idsName of the column indicating subject ids.
timesName of the column indicating observation time in
data_dynamic.measurementsName of the column indicating measurement values in
data_dynamic.censor_at_landmarkBoolean indicating whether to fit a single longitudinal model to the complete dataset (FALSE) or to censor observations at the landmark time prior to fitting the longitudinal model, iterating through landmark times (TRUE; default)
event_timeName of the column indicating time of the event/censoring.
risk_setsList of indices.
longitudinal_fitsList of model fits for the specified landmark times and biomarkers.
longitudinal_predictionsList of model predictions for the specified landmark times and biomarkers.
longitudinal_predictions_testList of out-of-sample predictions for the specified landmark times and biomarkers.
survival_datasetsList of survival dataframes used in the survival submodel.
survival_datasets_testList of survival dataframes used for out-of-sample predictions with the survival submodel.
survival_fitsList of survival model fits at each of the specified landmark times.
survival_predictionsList of time-to-event predictions for the specified landmark times and prediction horizons.
survival_predictions_testList of out-of-sample predictions for the time-to-event outcome if K > 1.
KNumber of cross-validation folds (1 by default)
cv_foldsData frame associating individuals to cross-validation folds
Checks convergence of lcmm models
Description
Checks convergence of lcmm models
Usage
check_lcmm_convergence(x)
Arguments
x |
An object of class |
Value
No return value. Issues a message if all lcmm models converged, or a warning for each model that did not converge.
Compute the list of individuals at risk at landmark times
Description
Compute the list of individuals at risk at landmark times
Usage
compute_risk_sets(x, landmarks, .warn_when_less_than = 0, ...)
Arguments
x |
An object of class |
landmarks |
Numeric vector of landmark times |
.warn_when_less_than |
Integer indicating that a warning will be raised when the number of observations prior to a landmark time is less than that integer for certain individuals. |
... |
Additional arguments (not used) |
Details
A risk set describes all subjects still at risk (i.e., not experienced the
event of interest or censored) at a given time. In
LandmarkAnalysis, risk sets define which subjects should be
included in the longitudinal and survival sub-models for each landmark time.
The risk sets are stored in the risk_sets slot of the
LandmarkAnalysis object, where each risk set is a list of
indices corresponding to the subjects at risk at the respective landmark
time.
Value
An object of class LandmarkAnalysis including desired
risk sets for the specified landmark times.
Compute the list of individuals at risk at landmark times
Description
Compute the list of individuals at risk at landmark times
Usage
## S4 method for signature 'LandmarkAnalysis'
compute_risk_sets(x, landmarks, .warn_when_less_than = 0, ...)
Arguments
x |
An object of class |
landmarks |
Numeric vector of landmark times |
.warn_when_less_than |
Integer indicating that a warning will be raised when the number of observations prior to a landmark time is less than that integer for certain individuals. |
... |
Additional arguments (not used) |
Details
A risk set describes all subjects still at risk (i.e., not experienced the
event of interest or censored) at a given time. In
LandmarkAnalysis, risk sets define which subjects should be
included in the longitudinal and survival sub-models for each landmark time.
The risk sets are stored in the risk_sets slot of the
LandmarkAnalysis object, where each risk set is a list of
indices corresponding to the subjects at risk at the respective landmark
time.
Value
An object of class LandmarkAnalysis, including desired
risk sets for the relevant landmark times.
Dose calibration of anti-epileptic drugs data
Description
The SANAD (Standard and New Anti-epileptic Drugs) study (Marson et al., 2007) is a randomized control trial of standard and new anti-epileptic drugs, comparing effects on longer term clinical outcomes. The data consists of longitudinal measurements of calibrated dose for the groups randomized to a standard drug (CBZ) and a new drug (LTG). The objective of the analysis is to investigate the effect of drug titration on the relative effects of LTG and CBZ on treatment failure (withdrawal of the randomized drug). There are several baseline covariates available, and also data on the time to withdrawal from randomized drug. This version of the data has been modified from the joineR package.
Usage
data(epileptic)
Format
This is a data frame in the unbalanced format, that is, with one row per observation. The data consists of columns for patient identifier, time of measurement, calibrated dose, baseline covariates, and survival data. The column names are identified as follows:
idinteger: patient identifier.
timeinteger: timing of clinic visit at which dose recorded (days).
with.timeinteger: time of drug withdrawal/maximum follow up time (days).
with.statuscensoring indicator (
1 =withdrawal of randomized drug and0 =not withdrawn from randomized drug/lost to follow up).dosenumeric: calibrated dose.
treatfactor: randomized treatment (CBZ or LTG).
agenumeric: age of patient at randomization (years).
genderfactor: gender of patient.
F =female,M =male.learn.disfactor: learning disability.
Source
SANAD Trial Group, University of Liverpool. Data modified from the joineR package.
References
Marson AG, Appleton R, Baker GA, et al. A randomised controlled trial examining longer-term outcomes of standard versus new antiepileptic drugs. The SANAD Trial. Health Tech Assess. 2007; 11(37).
Marson AG, Al-Kharusi AM, Alwaidh M, et al. The SANAD study of effectiveness of carbamazepine, gabapentin, lamotrigine, oxcarbazepine, or topiramate for treatment of partial epilepsy: an unblinded randomised controlled trial. Lancet. 2007; 365: 2007-2013.
Williamson PR, Kolamunnage-Dona R, Philipson P, Marson AG. Joint modelling of longitudinal and competing risks data. Stats Med. 2008; 27(30): 6426-6438.
See Also
joineR::epileptic, which this dataset was modified from.
Fits the specified longitudinal model for time-varying covariates up to the landmark times
Description
Fits the specified longitudinal model for time-varying covariates up to the landmark times
Usage
fit_longitudinal(
x,
landmarks,
method,
formula,
dynamic_covariates,
validation_fold = 0,
cores = getOption("Ncpus", 1L),
.warn_when_prop_few_obs = 0.25,
...
)
Arguments
x |
An object of class |
landmarks |
A vector of Landmark times. |
method |
Either |
formula |
A formula to be used in longitudinal sub-model fitting. |
dynamic_covariates |
Vector of time-varying covariates to be modelled as the outcome of a longitudinal model. |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed using the complete dataset. |
cores |
Number of cores/threads to be used for parallel computation on
Linux and MacOS. Defaults to either |
.warn_when_prop_few_obs |
Threshold proportion (0-1) for warning when individuals have 0 or 1 observations. Defaults to 0.25 (i.e., warn when 25% or more individuals have few observations). |
... |
Additional arguments passed to the longitudinal model fitting function (e.g. number of classes/clusters for lcmm). |
Details
Parallel processing
As the longitudinal model for each landmark time is independent of
the longitudinal models for other landmark times, parallel processing can
be used to vastly speed up computation. However, due to issues with
parallel processing in R, currently only Unix-like operating systems
are supported by landmaRk.
Value
An object of class LandmarkAnalysis.
See Also
lcmm::hlme() and lme4::lmer() for additional arguments.
Fits the specified longitudinal model for time-varying covariates up to the landmark times
Description
Fits the specified longitudinal model for time-varying covariates up to the landmark times
Usage
## S4 method for signature 'LandmarkAnalysis'
fit_longitudinal(
x,
landmarks,
method,
formula,
dynamic_covariates,
validation_fold = 0,
cores = getOption("Ncpus", 1L),
.warn_when_prop_few_obs = 0.25,
...
)
Arguments
x |
An object of class |
landmarks |
A vector of Landmark times. |
method |
Either |
formula |
A formula to be used in longitudinal sub-model fitting. |
dynamic_covariates |
Vector of time-varying covariates to be modelled as the outcome of a longitudinal model. |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed using the complete dataset. |
cores |
Number of cores/threads to be used for parallel computation on
Linux and MacOS. Defaults to either |
.warn_when_prop_few_obs |
Threshold proportion (0-1) for warning when individuals have 0 or 1 observations. Defaults to 0.25 (i.e., warn when 25% or more individuals have few observations). |
... |
Additional arguments passed to the longitudinal model fitting function (e.g. number of classes/clusters for lcmm). |
Details
Parallel processing
As the longitudinal model for each landmark time is independent of
the longitudinal models for other landmark times, parallel processing can
be used to vastly speed up computation. However, due to issues with
parallel processing in R, currently only Unix-like operating systems
are supported by landmaRk.
Value
An object of class LandmarkAnalysis.
See Also
lcmm::hlme() and lme4::lmer() for additional arguments.
Fits the specified survival model at the landmark times and up to the horizon times specified by the user
Description
Fits the specified survival model at the landmark times and up to the horizon times specified by the user
Usage
fit_survival(
x,
formula,
landmarks,
horizons,
method,
dynamic_covariates = c(),
include_clusters = FALSE,
censor_at_horizon = FALSE,
validation_fold = 0
)
Arguments
x |
An object of class |
formula |
A formula to be used in survival sub-model fitting. |
landmarks |
Numeric vector of landmark times. |
horizons |
Vector of prediction horizons up to when the survival submodel is fitted. |
method |
Method for survival analysis, either "survfit" or "coxph". |
dynamic_covariates |
Vector of time-varying covariates to be used in the survival model. |
include_clusters |
Boolean indicating whether to propagate cluster membership to survival analysis. |
censor_at_horizon |
Boolean indicating whether to censor observations at horizon times |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed on the complete dataset. |
Details
Mathematical formulation
This function estimates the conditional probability of survival to horizon
s+w, conditioned on having survived to the landmark time, s,
that is
\pi_i(s+w \vert s) = P(T_i > s+w \vert T_i \ge s, \bar{x}_i(s)),
where i denotes an individual's index, T_i is the time to event
outcome for individual i and \bar{x}_i(s) are the covariates
observed for individual i, including the observed history of dynamic
covariates.
Value
An object of class LandmarkAnalysis.
Fits the specified survival model at the landmark times and up to the horizon times specified by the user
Description
Fits the specified survival model at the landmark times and up to the horizon times specified by the user
Usage
## S4 method for signature 'LandmarkAnalysis'
fit_survival(
x,
formula,
landmarks,
horizons,
method,
dynamic_covariates = c(),
include_clusters = FALSE,
censor_at_horizon = FALSE,
validation_fold = 0
)
Arguments
x |
An object of class |
formula |
A formula to be used in survival sub-model fitting. |
landmarks |
Numeric vector of landmark times. |
horizons |
Vector of prediction horizons up to when the survival submodel is fitted. |
method |
Method for survival analysis, either "survfit" or "coxph". |
dynamic_covariates |
Vector of time-varying covariates to be used in the survival model. |
include_clusters |
Boolean indicating whether to propagate cluster membership to survival analysis. |
censor_at_horizon |
Boolean indicating whether to censor observations at horizon times |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed on the complete dataset. |
Details
Mathematical formulation
This function estimates the conditional probability of survival to horizon
s+w, conditioned on having survived to the landmark time, s,
that is
\pi_i(s+w \vert s) = P(T_i > s+w \vert T_i \ge s, \bar{x}_i(s)),
where i denotes an individual's index, T_i is the time to event
outcome for individual i and \bar{x}_i(s) are the covariates
observed for individual i, including the observed history of dynamic
covariates.
Value
An object of class LandmarkAnalysis.
Performance metrics
Description
Computes concordance index (c-index) and Brier scores at the specified landmark times and prediction horizons.
Usage
performance_metrics(
x,
landmarks,
horizons,
c_index = TRUE,
brier = TRUE,
auc_t = FALSE,
train = TRUE,
h_times = c()
)
Arguments
x |
An object of class |
landmarks |
A numeric vector of landmark times. |
horizons |
Vector of prediction horizons up to when the survival submodel is fitted. |
c_index |
A logical. If TRUE (default), C index is reported. |
brier |
A logical. If TRUE (default), Brier score is reported. |
auc_t |
A logical. If TRUE, AUC_t is reported. |
train |
A logical. If TRUE (default), performance metrics are computed in the training set. If FALSE, they are computed in the test set. |
h_times |
A numeric vector of prediction horizon times, specified relative to each landmark time, at which auc_t and Brier scores are calculated. |
Value
Data frame with performance metrics across the specified landmark times and prediction horizons.
Performance metrics
Description
Computes concordance index (c-index) and Brier scores at the specified landmark times and prediction horizons.
Usage
## S4 method for signature 'LandmarkAnalysis'
performance_metrics(
x,
landmarks,
horizons,
c_index = TRUE,
brier = TRUE,
auc_t = FALSE,
train = TRUE,
h_times = c()
)
Arguments
x |
An object of class |
landmarks |
A numeric vector of landmark times. |
horizons |
Vector of prediction horizons up to when the survival submodel is fitted. |
c_index |
A logical. If TRUE (default), C index is reported. |
brier |
A logical. If TRUE (default), Brier score is reported. |
auc_t |
A logical. If TRUE, AUC_t is reported. |
train |
A logical. If TRUE (default), performance metrics are computed in the training set. If FALSE, they are computed in the test set. |
h_times |
A numeric vector of prediction horizon times, specified relative to each landmark time, at which auc_t and Brier scores are calculated. |
Value
Data frame with performance metrics across the specified landmark times and prediction horizons.
Plot longitudinal observations and predicted survival curve for one individual
Description
Produces a single-panel plot with a common time axis. The left of the landmark dashed line shows the individual's observed longitudinal measurements; the right shows their predicted survival curve. The summary value at the landmark that feeds into the survival sub-model is highlighted.
Usage
## S4 method for signature 'LandmarkAnalysis'
plot(x, id, landmark, dynamic_covariate, horizon = NULL, train = TRUE, ...)
Arguments
x |
An object of class |
id |
Identifier of the individual to plot. Must match a value in the
column |
landmark |
Numeric landmark time. |
dynamic_covariate |
Character name of the dynamic covariate to display. |
horizon |
Numeric horizon time. If |
train |
Logical. If |
... |
Additional arguments (not currently used). |
Value
A ggplot object.
Make predictions for time-varying covariates at specified landmark times
Description
Make predictions for time-varying covariates at specified landmark times
Usage
predict_longitudinal(
x,
landmarks,
method,
dynamic_covariates,
validation_fold = 0,
...
)
Arguments
x |
An object of class |
landmarks |
A numeric vector of landmark times. |
method |
Longitudinal data analysis method used to make predictions |
dynamic_covariates |
Vector of time-varying covariates to be modelled as the outcome of a longitudinal model. |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed in the complete dataset. |
... |
Additional arguments passed to the prediction function (e.g. number of classes/clusters for lcmm). |
Value
An object of class LandmarkAnalysis.
Make predictions for time-varying covariates at specified landmark times
Description
Make predictions for time-varying covariates at specified landmark times
Usage
## S4 method for signature 'LandmarkAnalysis'
predict_longitudinal(
x,
landmarks,
method,
dynamic_covariates,
validation_fold = 0,
...
)
Arguments
x |
An object of class |
landmarks |
A numeric vector of landmark times. |
method |
Longitudinal data analysis method used to make predictions |
dynamic_covariates |
Vector of time-varying covariates to be modelled as the outcome of a longitudinal model. |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed in the complete dataset. |
... |
Additional arguments passed to the prediction function (e.g. number of classes/clusters for lcmm). |
Value
An object of class LandmarkAnalysis.
Make predictions for time-to-event outcomes at specified horizon times
Description
Make predictions for time-to-event outcomes at specified horizon times
Usage
predict_survival(
x,
landmarks,
horizons,
method = "survfit",
dynamic_covariates = c(),
include_clusters = FALSE,
censor_at_horizon = FALSE,
validation_fold = 0,
...
)
Arguments
x |
An object of class |
landmarks |
Numeric vector of landmark times. |
horizons |
Vector of prediction horizons up to when the survival submodel is fitted. |
method |
Name of the function that is used to make predictions. At the moment, 'survfit' is the only supported @method. |
dynamic_covariates |
Vector of time-varying covariates to be used in the survival model. |
include_clusters |
Boolean indicating whether to propagate cluster membership to survival analysis. |
censor_at_horizon |
Boolean indicating whether to censor observations at horizon times |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed on the complete dataset. |
... |
Additional arguments passed to the prediction function (e.g. number of classes/clusters for lcmm). |
Value
An object of class LandmarkAnalysis.
Make predictions for time-to-event outcomes at specified horizon times
Description
Make predictions for time-to-event outcomes at specified horizon times
Usage
## S4 method for signature 'LandmarkAnalysis'
predict_survival(
x,
landmarks,
horizons,
method = "survfit",
dynamic_covariates = c(),
include_clusters = FALSE,
censor_at_horizon = FALSE,
validation_fold = 0,
...
)
Arguments
x |
An object of class |
landmarks |
Numeric vector of landmark times. |
horizons |
Vector of prediction horizons up to when the survival submodel is fitted. |
method |
Name of the function that is used to make predictions. At the moment, 'survfit' is the only supported @method. |
dynamic_covariates |
Vector of time-varying covariates to be used in the survival model. |
include_clusters |
Boolean indicating whether to propagate cluster membership to survival analysis. |
censor_at_horizon |
Boolean indicating whether to censor observations at horizon times |
validation_fold |
If positive, cross-validation fold where model is fitted. If 0 (default), model fitting is performed on the complete dataset. |
... |
Additional arguments passed to the prediction function (e.g. number of classes/clusters for lcmm). |
Value
An object of class LandmarkAnalysis.
Prunes a landmark time from a LandmarkAnalysis, removing
the risk set, longitudinal submodel and survival submodel from the object.
Description
Prunes a landmark time from a LandmarkAnalysis, removing
the risk set, longitudinal submodel and survival submodel from the object.
Usage
prune(x, ...)
Arguments
x |
An object of class |
... |
Additional arguments |
Value
An object of class LandmarkAnalysis.
Prunes a landmark time from a LandmarkAnalysis, removing
the risk set, longitudinal submodel and survival submodel from the object.
Description
Prunes a landmark time from a LandmarkAnalysis, removing
the risk set, longitudinal submodel and survival submodel from the object.
Usage
## S4 method for signature 'LandmarkAnalysis'
prune(x, landmark = NULL, ...)
Arguments
x |
An object of class |
landmark |
A numeric indicating the landmark time. |
... |
Additional arguments (not currently used) |
Value
An object of class LandmarkAnalysis.
Prune a set of individuals from a risk set
Description
Prune a set of individuals from a risk set
Usage
prune_risk_sets(x, landmark, individuals)
Arguments
x |
An object of class |
landmark |
a landmark time |
individuals |
Vector of individuals to be pruned from |
Value
An object of class LandmarkAnalysis after having
pruned the individuals indicated in individuals from the risk set
at landmark time landmark.
Prune a set of individuals from a risk set
Description
Prune a set of individuals from a risk set
Usage
## S4 method for signature 'LandmarkAnalysis'
prune_risk_sets(x, landmark, individuals)
Arguments
x |
An object of class |
landmark |
a landmark time |
individuals |
Vector of individuals to be pruned from |
Value
An object of class LandmarkAnalysis after having
pruned the individuals indicated in individuals from the risk set
at landmark time landmark.
Displays an object of class "LandmarkAnalysis"
Description
Displays an object of class "LandmarkAnalysis"
Usage
## S4 method for signature 'LandmarkAnalysis'
show(object)
Arguments
object |
An object of class |
Value
No return value(prints a summary to the console).
Examples
data(epileptic)
epileptic_dfs <- split_wide_df(
epileptic,
ids = "id", times = "time",
static = c("with.time", "with.status", "treat", "age", "gender", "learn.dis"),
dynamic = c("dose"),
measurement_name = "value"
)
x <- LandmarkAnalysis(
data_static = epileptic_dfs$df_static,
data_dynamic = epileptic_dfs$df_dynamic,
event_indicator = "with.status",
ids = "id", event_time = "with.time",
times = "time", measurements = "value"
) |>
compute_risk_sets(365.25)
show(x)
Split a wide dataframe containing static and dynamic covariates and splits in into a dataframe with the static covariates and a list of dataframes, each associated to a dynamic covariate.
Description
Split a wide dataframe containing static and dynamic covariates and splits in into a dataframe with the static covariates and a list of dataframes, each associated to a dynamic covariate.
Usage
split_wide_df(df, ids, times, static, dynamic, measurement_name)
Arguments
df |
A dataframe in wide format. |
ids |
The name of the column that identifies individuals in |
times |
The name of the column that identifies measurement times
in |
static |
A vector with the column names in |
dynamic |
A vector with the column names in |
measurement_name |
The name for the columns where values of dynamic covariates will be stored. |
Value
A data frame with the static covariates, and a list of data frames, one per dynamic covariate.
Summarise a LandmarkAnalysis object
Description
Summarise a LandmarkAnalysis object
Usage
## S4 method for signature 'LandmarkAnalysis'
summary(
object,
type = c("longitudinal", "survival"),
landmark,
horizon = NULL,
dynamic_covariate = NULL
)
Arguments
object |
An object of class |
type |
If |
landmark |
A numeric indicating the landmark time. |
horizon |
For survival submodels, a numeric indicating the horizon time. |
dynamic_covariate |
For longitudinal submodels, a character indicating the dynamic covariate |
Value
A summary of the desired submodel, printed to the console.
Returns NULL invisibly.
Examples
data(epileptic)
epileptic_dfs <- split_wide_df(
epileptic,
ids = "id", times = "time",
static = c("with.time", "with.status", "treat", "age", "gender", "learn.dis"),
dynamic = c("dose"),
measurement_name = "value"
)
x <- LandmarkAnalysis(
data_static = epileptic_dfs$df_static,
data_dynamic = epileptic_dfs$df_dynamic,
event_indicator = "with.status",
ids = "id", event_time = "with.time",
times = "time", measurements = "value"
) |>
compute_risk_sets(365.25) |>
fit_survival(
formula = survival::Surv(event_time, event_status) ~ treat + age,
landmarks = 365.25,
horizons = 2 * 365.25,
method = "coxph"
)
summary(x, type = "survival", landmark = 365.25, horizon = 2 * 365.25)
# Full pipeline including longitudinal submodel
x2 <- LandmarkAnalysis(
data_static = epileptic_dfs$df_static,
data_dynamic = epileptic_dfs$df_dynamic,
event_indicator = "with.status",
ids = "id", event_time = "with.time",
times = "time", measurements = "value"
) |>
compute_risk_sets(365.25) |>
fit_longitudinal(
landmarks = 365.25,
method = "lme4",
formula = value ~ treat + age + gender + learn.dis + (time | id),
dynamic_covariates = c("dose")
) |>
predict_longitudinal(
landmarks = 365.25,
method = "lme4",
allow.new.levels = TRUE,
dynamic_covariates = c("dose")
) |>
fit_survival(
formula = survival::Surv(event_time, event_status) ~
treat + age + gender + learn.dis + dose,
landmarks = 365.25,
horizons = 2 * 365.25,
method = "coxph",
dynamic_covariates = c("dose")
) |>
predict_survival(landmarks = 365.25, horizons = 2 * 365.25)
summary(x2, type = "longitudinal", landmark = 365.25, dynamic_covariate = "dose")
summary(x2, type = "survival", landmark = 365.25, horizon = 2 * 365.25)