Compute conditional cumulative incidences from fitted Cox models
Source:R/compute_psi_dx.R
predict_from_model_0.Rd
These functions compute the conditional day- and covariate-specific cumulative
incidence for each row of newdata
.
predict_from_model_0()
computes \(\psi_0(t_0; d, x) = 1 - S_0(d+t_0 \mid x)/S_0(d+\tau \mid x)\) by callingpredict(fit_0, newdata, type = "survival")
at eval_timesd + t0
andd + tau
.
predict_from_model_1()
computes \(\psi_1(t_0; d, x) = 1 - S_1(t_0 \mid d, x)/S_1(\tau \mid d, x)\)
by calling
predict(fit_1, newdata, type = "survival")at eval_times
t0and
tau`.
Usage
predict_from_model_0(fit_0, exposure_time, t0, tau, newdata)
predict_from_model_1(fit_1, exposure_time, t0, tau, newdata)
Value
The newdata
data frame with three additional columns:
predict_from_model_0()
:surv_0_d_plus_tau
,surv_0_d_plus_t0
, andpsi_0_dx
predict_from_model_1()
:surv_1_tau
,surv_1_t0
, andpsi_1_dx
Examples
# Fit hazard model under no vaccine
fit_0 <- fit_model_0(
data = simdata,
outcome_time = "Y",
outcome_status = "event",
exposure = "V",
exposure_time = "D_obs",
covariates = covariates
)
#> Error: object 'covariates' not found
# Fit hazard model under vaccine
fit_1 <- fit_model_1(
data = simdata,
outcome_time = "Y",
outcome_status = "event",
exposure = "V",
exposure_time = "D_obs",
tau = tau
)
#> Error in fit_model_1(data = simdata, outcome_time = "Y", outcome_status = "event", exposure = "V", exposure_time = "D_obs", tau = tau): argument "covariates" is missing, with no default
# Define dataset for prediction,
# e.g. vaccinated indiviudals at risk tau days after vaccination
newdata <- simdata[simdata$V == 1 & (simdata$Y - simdata$D_obs) > 14,]
# Predict from hazard model under no vaccine
predict_from_model_0(
fit_0,
exposure_time = "D_obs",
t0 = 90,
tau = 14,
newdata = newdata
)
#> Error: object 'fit_0' not found
# Predict from hazard model under vaccine
predict_from_model_1(
fit_1,
exposure_time = "D_obs",
t0 = 90,
tau = 14,
newdata = newdata
)
#> Error in predict_from_model_1(fit_1, exposure_time = "D_obs", t0 = 90, tau = 14, newdata = newdata): could not find function "predict_from_model_1"