View source: R/add_median_survival.R
add_median_survival | R Documentation |
Fitting a survival fit for each subgroup defined by var and extracting median survival times. Additionally the total survival time for the whole sample is calculated. This function fits a survival curve for each subgroup defined by var and extracts the median survival times. Additionally the median survival time for the whole sample is calculated.
add_median_survival(
data,
time,
status,
var,
round = 1,
statistics = TRUE,
weights = NULL,
conf.type = "log-log"
)
data |
data.frame or data.table containing survival data. |
time |
The time interval from start of observation until date of event (e.g. disease progression or death) or censoring. |
status |
Variable specifying if event occured or data has been censored. Default behaviour inherited from the |
var |
Variable tested for Influence on outcome. |
round |
rounds the results to the specified number of decimal places (default 1) |
statistics |
Logical value. If TRUE pvalue is printed. Default is TRUE. Statistical test is log-rank test. |
weights |
character variable specifying the name of the weights column. Weights (numerical vector) have to be added to the original dataframe in order to be applied correctly. |
conf.type |
Method to calculate confidence intervals. Log-log method is the default in SAS and was therefore set as the default here too. |
# example survival calculation with the lung dataset
df <- survival::lung
add_median_survival(data = df, time = "time", status = "status", var = "ph.ecog")
# calculate median survival with inverse propensity score weighting for sex
df$sex <- factor(df$sex)
df$ph.ecog <- ifelse(is.na(df$ph.ecog), "Missing", df$ph.ecog)
df$ph.karno <- ifelse(is.na(df$ph.karno), "Missing", df$ph.karno)
df$weights.ate <- ate_weights(data = df, vars = c("age", "ph.ecog", "ph.karno"), prop.var = "sex")
# the internal logrank test (logrank_IPSW_RISCA) needs a status variable of 0 and 1
df$status <- ifelse(df$status == 2, 1, 0)
add_median_survival(data = df, time = "time", status = "status",
var = "sex", weights = "weights.ate")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.