Title: | Excel Conversion of R Surival Analysis Output |
---|---|
Description: | Simple and quick method of exporting the most often used survival analysis results to an Excel sheet. |
Authors: | Xuefei Jia |
Maintainer: | Xuefei Jia <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-10-15 06:39:33 UTC |
Source: | CRAN |
This function generates a table of competing risk analysis result with number of patients,number of event, number of competing event,
crisk_cat( csurv, cevent, cvars, gnames, month = 0, y1 = TRUE, y2 = TRUE, y5 = TRUE )
crisk_cat( csurv, cevent, cvars, gnames, month = 0, y1 = TRUE, y2 = TRUE, y5 = TRUE )
csurv |
the duration of follow-up time in months. |
cevent |
the status indicator, which is generally 0 = alive, 1 = event, 2 = other event |
cvars |
a vector, which has the variable's values (categorical only) |
gnames |
a text string, which is the name of the variable. |
month |
a number to get the month-rate of competing risk. |
y1 |
logical value indicating whether the 1-year competing risk rate should be reported. |
y2 |
logical value indicating whether the 2-year competing risk rate should be reported. |
y5 |
logical value indicating whether the 5-year competing risk rate should be reported. |
a tibble of competing risk analysis output.
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 output <- crisk_cat(Dat$time, Dat$status, Dat$ulcer, "ulcer")
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 output <- crisk_cat(Dat$time, Dat$status, Dat$ulcer, "ulcer")
This function generates a table of competing risk analysis result with HR (95% Confidence Interval),P value.
crisk_con(csurv, cevent, cvars, gnames)
crisk_con(csurv, cevent, cvars, gnames)
csurv |
the duration of follow-up time in months. |
cevent |
the status indicator, which is generally 0 = alive, 1 = event, 2 = other event |
cvars |
a matrix, which has the variables' values (continuous and ordinal only) |
gnames |
a text vector, which are the names of the variables. |
a dataframe containing HRs (with 95% Confidence Intervals) and P values
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 X <- cbind(Dat$age, Dat$thickness) Gnames <- c('age', 'thickness') output <- crisk_con(Dat$time, Dat$status, X, Gnames)
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 X <- cbind(Dat$age, Dat$thickness) Gnames <- c('age', 'thickness') output <- crisk_con(Dat$time, Dat$status, X, Gnames)
Create a table with the general multi-variable competing risk analysis results, including the HR (95 percent CI), P value.
crisk_multi(dat, csurv, cevent, convars = NULL, catvars = NULL)
crisk_multi(dat, csurv, cevent, convars = NULL, catvars = NULL)
dat |
a data.frame in which to interpret the variables. |
csurv |
this is the follow up time. |
cevent |
the status indicator, normally 0=alive, 1=dead. |
convars |
a vector of con variable names. |
catvars |
a vector of cat variable names. |
a tibble of competing risk analysis output.
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 con_var <- c("age","thickness") cat_var <- c("sex","ulcer") multi_out <- crisk_multi(Dat, "time", "status", catvars = cat_var, convars =con_var)
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 con_var <- c("age","thickness") cat_var <- c("sex","ulcer") multi_out <- crisk_multi(Dat, "time", "status", catvars = cat_var, convars =con_var)
This function generates a table of competing risk analysis result with number of patients, number of event, number of competing event,
crisk_multiuni( dat, csurv, cevent, catvars = NULL, convars = NULL, ordvars = NULL, y1 = TRUE, y2 = TRUE, y5 = TRUE, month = 0 )
crisk_multiuni( dat, csurv, cevent, catvars = NULL, convars = NULL, ordvars = NULL, y1 = TRUE, y2 = TRUE, y5 = TRUE, month = 0 )
dat |
a data.frame in which to interpret the variables. |
csurv |
this is the follow up time. |
cevent |
the status indicator, normally 0=alive, 1=dead. |
catvars |
a vector of cat variable names. |
convars |
a vector of con variable names. |
ordvars |
a vector of ordinal variable names. |
y1 |
logical value indicating whether the 1-year competing risk rate should be reported. |
y2 |
logical value indicating whether the 2-year competing risk rate should be reported. |
y5 |
logical value indicating whether the 5-year competing risk rate should be reported. |
month |
a number to get the month-rate of competing risk. |
a tibble of competing risk analysis output.
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 Dat$ulcer <- as.factor(Dat$ulcer) con_var <- c("age") ord_var <- c("ulcer") cat_var <- c("sex") uni_out <- crisk_multiuni(Dat, "time", "status",cat_var, con_var, ord_var)
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 Dat$ulcer <- as.factor(Dat$ulcer) con_var <- c("age") ord_var <- c("ulcer") cat_var <- c("sex") uni_out <- crisk_multiuni(Dat, "time", "status",cat_var, con_var, ord_var)
This function generates a table of competing risk analysis result with number of patients, number of event, number of competing event,
crisk_ord( csurv, cevent, cvars, gnames, month = 0, y1 = TRUE, y2 = TRUE, y5 = TRUE )
crisk_ord( csurv, cevent, cvars, gnames, month = 0, y1 = TRUE, y2 = TRUE, y5 = TRUE )
csurv |
the duration of follow-up time in months. |
cevent |
the status indicator, which is generally 0 = alive, 1 = event, 2 = other event |
cvars |
a vector, which has the variable's values (ordinal only) |
gnames |
a text string, which is the name of the variable. |
month |
a number to get the month-rate of competing risk. |
y1 |
logical value indicating whether the 1-year competing risk rate should be reported. |
y2 |
logical value indicating whether the 2-year competing risk rate should be reported. |
y5 |
logical value indicating whether the 5-year competing risk rate should be reported. |
a tibble of competing risk analysis output.
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 output <- crisk_ord(Dat$time, Dat$status, as.factor(Dat$year), "year")
Dat <- MASS::Melanoma Dat$time <- Dat$time/30.5 output <- crisk_ord(Dat$time, Dat$status, as.factor(Dat$year), "year")
Create an indicator matrix of dimension length(x) x (nlevels(x)-1) with the column corresponding to the baseline level removed (by default the first level is used as baseline).
factor2ind(x, baseline)
factor2ind(x, baseline)
x |
a variable. |
baseline |
a string indicating the reference level. |
a matrix
x = gl(4, 2, labels = c( "A", "B", "C", "D")) factor2ind(x) factor2ind(x, "C")
x = gl(4, 2, labels = c( "A", "B", "C", "D")) factor2ind(x) factor2ind(x, "C")
The function saves a dataframe into an excel sheet with a predetermined format.
p2excel( tabname = "Default", datastable, tablename = "Default", filename = "Default.xlsx" )
p2excel( tabname = "Default", datastable, tablename = "Default", filename = "Default.xlsx" )
tabname |
a string with the tab's name. |
datastable |
the dataframe that will be exported to Excel. |
tablename |
a string containing the table label and title, which will appear as the first row |
filename |
the name of the spreadsheet |
a spreadsheet containing an exported tables
The function saves the dataframe as a tab and prepares it for output into an excel sheet with a predetermined format.
p2excel_pre(tabname = "Default", datastable, tablename = "Default", filename)
p2excel_pre(tabname = "Default", datastable, tablename = "Default", filename)
tabname |
a string with the tab's name. |
datastable |
the dataframe that will be exported to Excel. |
tablename |
a string containing the table label and title, which will appear as the first row |
filename |
the name of the spreadsheet |
a spreadsheet containing all of the exported tables
Dat <- survival::lung results <- surv_uni_cat(Dat, "time", "status", "sex", report_index = TRUE) wb <- openxlsx::createWorkbook() wb <- p2excel_pre("survival_results",results,"Table 1. Overall Survival anlaysis",wb) ## Not run: ## saveWorkbook(wb, file = "os.xlsx", overwrite = TRUE) ## End(Not run)
Dat <- survival::lung results <- surv_uni_cat(Dat, "time", "status", "sex", report_index = TRUE) wb <- openxlsx::createWorkbook() wb <- p2excel_pre("survival_results",results,"Table 1. Overall Survival anlaysis",wb) ## Not run: ## saveWorkbook(wb, file = "os.xlsx", overwrite = TRUE) ## End(Not run)
Create a table with the general multi-variable survival analysis results, including the HR (95 percent CI), P value.
surv_multi(...)
surv_multi(...)
... |
arguments will be passed to coxph |
a dataframe containing coxph output that includes variable names, HRs (95
Dat <- survival::lung surv_multi(survival::Surv(time, status) ~ as.factor(sex) + age + meal.cal, data = Dat)
Dat <- survival::lung surv_multi(survival::Surv(time, status) ~ as.factor(sex) + age + meal.cal, data = Dat)
This function generates a table with the general survival analysis results, including the number of total patients, the number of sevents, the estimated median, the 1,2,5 year rate, the HR (95 percent confidence interval), the P value, the AIC, and the C index. This function just modifies the output table's format.
surv_multiuni( dat, stime, sevent, catvars = NULL, convars = NULL, y1 = TRUE, y2 = TRUE, y5 = TRUE, medianCI = FALSE, report_index = FALSE )
surv_multiuni( dat, stime, sevent, catvars = NULL, convars = NULL, y1 = TRUE, y2 = TRUE, y5 = TRUE, medianCI = FALSE, report_index = FALSE )
dat |
a dat.frame. |
stime |
the duration of follow-up time in months. |
sevent |
the status indicator, which is generally 0 = alive, 1 = dead. |
catvars |
a vector of categorical variable names. |
convars |
a vector of continuous variables names. |
y1 |
logical value indicating whether the 1-year survival rate should be reported. |
y2 |
logical value indicating whether the 2-year survival rate should be reported. |
y5 |
logical value indicating whether the 5-year survival rate should be reported. |
medianCI |
logical value indicating whether the 95 percent confidence interval of projected median survival should be reported. |
report_index |
logical value indicating if to report the show AIC and C index. |
A tibble of survival output
Dat <- survival::lung convars <- c("age","meal.cal") catvars <- c("sex") surv_multiuni(Dat, "time", "status", catvars, convars, medianCI = TRUE)
Dat <- survival::lung convars <- c("age","meal.cal") catvars <- c("sex") surv_multiuni(Dat, "time", "status", catvars, convars, medianCI = TRUE)
This function generates a table with the general survival analysis results, including the number of total patients, the number of sevents, the estimated median, the 1,2,5 year rate, the HR (95 percent confidence interval), the P value, the AIC, and the C index. This function just modifies the output table's format.
surv_uni_cat( dat, stime, sevent, svar, month = 0, medianCI = TRUE, y1 = TRUE, y2 = TRUE, y5 = TRUE, report_index = FALSE )
surv_uni_cat( dat, stime, sevent, svar, month = 0, medianCI = TRUE, y1 = TRUE, y2 = TRUE, y5 = TRUE, report_index = FALSE )
dat |
a data.frame. |
stime |
the duration of follow-up time in months. |
sevent |
the status indicator, which is generally 0 = alive, 1 = dead. |
svar |
a variable name. |
month |
a number to get the month-rate of survival. |
medianCI |
logical value indicating whether the 95 percent confidence interval of projected median survival should be reported. |
y1 |
logical value indicating whether the 1-year survival rate should be reported. |
y2 |
logical value indicating whether the 2-year survival rate should be reported. |
y5 |
logical value indicating whether the 5-year survival rate should be reported. |
report_index |
logical value indicating if to report the show AIC and C index. |
a tibble of survival output
Dat <- survival::lung surv_uni_cat(Dat, "time", "status", "sex", report_index = TRUE)
Dat <- survival::lung surv_uni_cat(Dat, "time", "status", "sex", report_index = TRUE)
This function generates a table with the general survival analysis results, including the number of total patients, the number of events, the P value, the AIC, and the C index. This function just modifies the output table's format.
surv_uni_con(dat, stime, sevent, svar, report_index = FALSE)
surv_uni_con(dat, stime, sevent, svar, report_index = FALSE)
dat |
a data.frame. |
stime |
the duration of follow-up time in months. |
sevent |
the status indicator, which is generally 0 = alive, 1 = dead. |
svar |
a variable name. |
report_index |
logical value indicating if to report the show AIC and C index. |
a tibble of survival results.
Dat <- survival::lung surv_uni_con(Dat, "time", "status", "age",report_index = TRUE)
Dat <- survival::lung surv_uni_con(Dat, "time", "status", "age",report_index = TRUE)