Fit standard parametric survival models with a treatment covariate
Source:R/quick_fit_joint.R
quick_fit_joint.Rd
This function fits standard joint parametric survival models with a treatment covariate, after checking for convergence, and generates various plots and fit information.
Usage
quick_fit_joint(
data,
time,
event,
strata,
dists,
times = NULL,
strata_labels = NULL,
formula = NULL,
weights = NULL,
xlab = "Time",
font.family = "Roboto Condensed",
plot.theme = theme_easysurv(),
add_interactive_plots = FALSE,
plot_predictions = "flexsurv",
include_ci = TRUE,
get_mean = FALSE
)
Arguments
- data
A tibble or data frame containing the survival data with columns for
time
,event
andstrata
.- time
The name of the time variable in data
- event
The name of the event variable in data
- strata
The name of the strata variable in data
- dists
A (vector of) string(s) containing the name(s) of the model(s) to be fitted. Available options are:
"exponential"
,"gamma"
,"genf"
,"gengamma"
,"gompertz"
,"weibull"
,"weibullPH"
,"loglogistic"
,"lognormal"
.- times
Optional. A set of times at which to calculate predicted survival. The default is
seq(from = 0, to = ceiling(max(data$time)*2.5), length.out = 200)
- strata_labels
Optional. A character vector containing the names of the stratas (default is NULL). Provide in a consistent order with
levels(as.factor(data$strata))
.- formula
Optional. Surv() formula specifying the survival model. Default is
survival::Surv(time,event) ~ as.factor(strata)
- weights
Optional for case weights. The function expects a string corresponding to a variable name within the data.
- xlab
The x-axis label for plots. Default is "Time".
- font.family
The name of the font for the plots. Default is "Roboto Condensed".
- plot.theme
ggplot2 theme for the plots. Default is
theme_easysurv()
.- add_interactive_plots
Optional. Whether to include
plotly
outputs for hazard and fit plots. Default is FALSE.- plot_predictions
Optional. Whether to plot the predictions using the
flexsurv
package orsurvHE
package. Default is "flexsurv".- include_ci
Logical indicating whether to include confidence intervals in the survival probability predictions. Default is TRUE.
- get_mean
Optional. Whether to attempt to calculate mean survival times for the fit_averages object. Defaults to FALSE.
Value
An object of class quick_fit_joint
containing the following
elements:
- converged
A list of the distributions that converged
- fits
The
survHE::fit.models
output- hazard_plots
Smoothed hazard plots for each strata
- hazard_plotly
Interactive hazard plots (if add_interactive_plots = TRUE)
- fit_plots
Plot of extrapolations over the specified
times
parameter- fit_plotly
Interactive fit plots (if add_interactive_plots = TRUE)
- goodness_of_fit
AIC and BIC output, alongside ranks, for each distribution
- surv_params
The flexsurv parameters for each model and their vcov matrix
- fit_averages
The median, mean and restricted mean survival times for each distribution
- predicted_fits
Predicted survival proportions over the
times
parameter, if provided
Examples
if (FALSE) {
# Load required packages
library(survival)
input_data <- survival::lung
surv_data <- tibble(
time = input_data$time,
event = input_data$status - 1,
strata = as.factor(input_data$sex)
)
fit_check_joint <- quick_fit_joint(
data = surv_data,
time = "time",
event = "event",
strata = "strata",
dists = c("weibull", "exp")
)
}