diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..6e6b0d3 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1 @@ +^README\.Rmd$ diff --git a/.Rproj.user/A70D84A5/sources/prop/193C080D b/.Rproj.user/A70D84A5/sources/prop/193C080D index 5c36a66..ca2837c 100644 --- a/.Rproj.user/A70D84A5/sources/prop/193C080D +++ b/.Rproj.user/A70D84A5/sources/prop/193C080D @@ -1,4 +1,4 @@ { - "cursorPosition": "31,0", - "scrollLine": "10" + "cursorPosition": "41,13", + "scrollLine": "20" } \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/prop/1ECE0E8B b/.Rproj.user/A70D84A5/sources/prop/1ECE0E8B new file mode 100644 index 0000000..28835b4 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/prop/1ECE0E8B @@ -0,0 +1,5 @@ +{ + "tempName": "Untitled1", + "cursorPosition": "7,15", + "scrollLine": "0" +} \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/prop/61673941 b/.Rproj.user/A70D84A5/sources/prop/61673941 index 6f9497a..ec44fcf 100644 --- a/.Rproj.user/A70D84A5/sources/prop/61673941 +++ b/.Rproj.user/A70D84A5/sources/prop/61673941 @@ -1,5 +1,5 @@ { "tempName": "Untitled1", - "cursorPosition": "95,29", - "scrollLine": "84" + "cursorPosition": "91,0", + "scrollLine": "85" } \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/prop/6B2DD538 b/.Rproj.user/A70D84A5/sources/prop/6B2DD538 new file mode 100644 index 0000000..28835b4 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/prop/6B2DD538 @@ -0,0 +1,5 @@ +{ + "tempName": "Untitled1", + "cursorPosition": "7,15", + "scrollLine": "0" +} \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/prop/DF2C1924 b/.Rproj.user/A70D84A5/sources/prop/DF2C1924 new file mode 100644 index 0000000..19d1042 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/prop/DF2C1924 @@ -0,0 +1,5 @@ +{ + "cursorPosition": "20,114", + "scrollLine": "17", + "source_window_id": "" +} \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/prop/INDEX b/.Rproj.user/A70D84A5/sources/prop/INDEX index 233f069..65edb7c 100644 --- a/.Rproj.user/A70D84A5/sources/prop/INDEX +++ b/.Rproj.user/A70D84A5/sources/prop/INDEX @@ -1,3 +1,5 @@ +~%2FRepositories%2Fcure-pipeline%2F.gitignore.R="1ECE0E8B" +~%2FRepositories%2Fcure-pipeline%2F.gitignore.txt="6B2DD538" ~%2FRepositories%2Fcure-pipeline%2FR%2Fcalibration-curve.R="DDEF45DE" ~%2FRepositories%2Fcure-pipeline%2FR%2Fclean-model-results.R="369CE3C2" ~%2FRepositories%2Fcure-pipeline%2FR%2Fcure-nomo-multi-var.R="0D44D543" @@ -7,4 +9,5 @@ ~%2FRepositories%2Fcure-pipeline%2FR%2Fmodel-fitting.R="61673941" ~%2FRepositories%2Fcure-pipeline%2FR%2Fnomogram.R="3A458D42" ~%2FRepositories%2Fcure-pipeline%2FR%2Fstability-tests.R="B4356C36" +~%2FRepositories%2Fcure-pipeline%2FREADME.Rmd="DF2C1924" ~%2FRepositories%2Fcure-pipeline%2Fexample.R="5F8A5441" diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339 b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339 index 5678a34..af93225 100644 --- a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339 +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339 @@ -11,15 +11,15 @@ "relative_order": 9, "properties": { "tempName": "Untitled1", - "cursorPosition": "95,29", - "scrollLine": "84" + "cursorPosition": "91,0", + "scrollLine": "85" }, "folds": "", - "lastKnownWriteTime": 1610686360, + "lastKnownWriteTime": 1610688000, "encoding": "UTF-8", "collab_server": "", "source_window": "", - "last_content_update": 1610686360971, + "last_content_update": 1610688000193, "read_only": false, "read_only_alternatives": [] } \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339-contents b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339-contents index 6cff063..316b3af 100644 --- a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339-contents +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/1E1A0339-contents @@ -1,7 +1,6 @@ # Functions to Run Cure Models (Once or Multiple Times) ------------------------ # ------------------------------------------------------------------------------ -source(here::here("R", "clean-model-results.R")) # Single Model Run ------------------------------------------------------------- # Wrapper function for smcure to accept multi-level variables and save necessary @@ -96,6 +95,8 @@ multiple_mod_runs <- function(formula, num_repeats = 10, data = mel) { + source(here::here("R", "clean-model-results.R")) + # pull original variables from formula mf <- formula mf <- eval(mf, parent.frame()) @@ -235,28 +236,4 @@ multiple_mod_runs <- function(formula, } -# Examples - -# data <- ISwR::melanom %>% -# mutate(status = case_when(status %in% c(1, 3) ~ 1, -# TRUE ~ 0)) %>% -# mutate(sex = case_when(sex == 2 ~ "male", -# sex == 1 ~ "female"), -# ulc = case_when(ulc == 1 ~ "present", -# ulc == 2 ~ "absent")) -# -# formula <- Surv(days, status) ~ ulc + sex -# -# x <- multiple_mod_runs(formula, -# nboot = 200, -# eps = 0.0001, -# num_repeats = 3, -# data = data) -# x$model_results -# -# x$var_surv_stab -# x$p_surv_stab -# -# x$var_cure_stab -# x$p_cure_stab \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/7C2EB88F b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/7C2EB88F deleted file mode 100644 index dc04432..0000000 --- a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/7C2EB88F +++ /dev/null @@ -1,25 +0,0 @@ -{ - "id": "7C2EB88F", - "path": "~/Repositories/cure-pipeline/R/calibration-curve.R", - "project_path": "R/calibration-curve.R", - "type": "r_source", - "hash": "0", - "contents": "", - "dirty": false, - "created": 1610685136942.0, - "source_on_save": false, - "relative_order": 5, - "properties": { - "tempName": "Untitled1", - "cursorPosition": "84,0", - "scrollLine": "65" - }, - "folds": "", - "lastKnownWriteTime": 1610687075, - "encoding": "UTF-8", - "collab_server": "", - "source_window": "", - "last_content_update": 1610687075666, - "read_only": false, - "read_only_alternatives": [] -} \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/868C082D b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/868C082D new file mode 100644 index 0000000..119c921 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/868C082D @@ -0,0 +1,25 @@ +{ + "id": "868C082D", + "path": "~/Repositories/cure-pipeline/R/clean-model-results.R", + "project_path": "R/clean-model-results.R", + "type": "r_source", + "hash": "0", + "contents": "", + "dirty": false, + "created": 1610687727650.0, + "source_on_save": false, + "relative_order": 6, + "properties": { + "tempName": "Untitled1", + "cursorPosition": "18,0", + "scrollLine": "0" + }, + "folds": "", + "lastKnownWriteTime": 1610677076, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1610677076, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/868C082D-contents b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/868C082D-contents new file mode 100644 index 0000000..b739b49 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/868C082D-contents @@ -0,0 +1,18 @@ + +# Clean Model Results ---------------------------------------------------------- +mmcure <- function(fit_k2_cat) { + enframe(fit_k2_cat$b) %>% + left_join(enframe(fit_k2_cat$b_pvalue), + by = "name") %>% + transmute(name, + value = round(exp(value.x), 2), + pvalue = round(value.y, 2)) +} + +mmsurv <- function(fit_k2_cat) { + enframe(fit_k2_cat$beta) %>% + left_join(enframe(fit_k2_cat$beta_pvalue), by = "name") %>% + transmute(name, + value = round(exp(value.x), 2), + pvalue = round(value.y, 2)) +} diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/91B9DCD1 b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/91B9DCD1 new file mode 100644 index 0000000..f769294 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/91B9DCD1 @@ -0,0 +1,25 @@ +{ + "id": "91B9DCD1", + "path": "~/Repositories/cure-pipeline/README.Rmd", + "project_path": "README.Rmd", + "type": "r_markdown", + "hash": "2669428527", + "contents": "", + "dirty": false, + "created": 1610688405206.0, + "source_on_save": false, + "relative_order": 7, + "properties": { + "cursorPosition": "20,114", + "scrollLine": "17", + "source_window_id": "" + }, + "folds": "", + "lastKnownWriteTime": 1610690234, + "encoding": "UTF-8", + "collab_server": "", + "source_window": "", + "last_content_update": 1610690234968, + "read_only": false, + "read_only_alternatives": [] +} \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/91B9DCD1-contents b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/91B9DCD1-contents new file mode 100644 index 0000000..afe65a5 --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/91B9DCD1-contents @@ -0,0 +1,80 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# Cure Model Pipeline + + + + +The goal of this package is to provide an easy way to build, evaluate and visualize mixture cure models ([link to paper draft](https://docs.google.com/document/d/1Lhom9H7Hxb8_C6d55Trs9JHSfJCn1i6yuu_xsDyYqZQ/edit?usp=sharing)) + + +## Available Functions + +- `fit_cure()` - wrapper for `smcure::smcure()` function that allows you to pass multilevel variables as factors directly (instead of first creating dummy codes). It also saves outputs necessary to create nomogram. +- `nomogram()-` - accepts an object created by `fit_cure()` and creates graphical nomogram based on model fit +- `cure_calibration()` - accepts an object created by `fit_cure()` and creates a calibration curve for uncured patients +- `multiple_mod_runs()`- allows you to check stability of models but running them multiple times and viewing distributions of variables and p-values. +- Coming soon: + - k-index and C-index wrapper functions + - tidyr function to better clean/view coefficients from cure model + +## Example + +```{r, eval = FALSE} +library(smcure) +library(ISwR) +library(gtsummary) +library(tidyverse) + +# Prepare Data -------------------------- +mel <- ISwR::melanom %>% + mutate(status = case_when(status %in% c(1, 3) ~ 1, + TRUE ~ 0)) %>% + mutate(thick_cat = + case_when(thick <= 129 ~ "≤ 129", + thick <= 322 ~ "less equal 322", + thick > 322 ~ "greater 322")) %>% + mutate(thick_cat = fct_relevel(thick_cat, "≤ 129", "≤ 322")) %>% + mutate(sex = case_when(sex == 2 ~ "male", + sex == 1 ~ "female"), + ulc = case_when(ulc == 1 ~ "present", + ulc == 2 ~ "absent")) + +# Run Pipeline -------------------------- +fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick , + data = mel) +cure_nomogram(fit, prediction_time = 300) +cure_calibration(fit, prediction_time = 300) + + +# Check Stability ---- +formula <- Surv(days, status) ~ ulc + sex +x <- multiple_mod_runs(formula, + nboot = 200, + eps = 0.0001, + num_repeats = 3, + data = mel) +x$model_results + +x$var_surv_stab +x$p_surv_stab + +x$var_cure_stab +x$p_cure_stab + +``` + + diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/CD6407BC-contents b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/CD6407BC-contents new file mode 100644 index 0000000..984602d --- /dev/null +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/CD6407BC-contents @@ -0,0 +1,43 @@ +# ignore R data files +.Rproj.user +.Rhistory +.RData +.rds +.Ruserdata +.Rapp.history +.Rhistory.RData + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# ignore other types of data files +*.xlsx +*.xls +*.csv +*.dta +*.sas7bdat +*.sav +*.txt + +# ignore data folder/symbolic link/sensitive file +data +admin +raw-data +secure_data +ext_data +tmp +env.json +archives +outputs/archive + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# ignore misc files +~$*.docx +~$*.xlsx +~$*.pptx +~$*.tmp +Thumbs.db +.DS_Store diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712 b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712 index e842fa7..bad9f15 100644 --- a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712 +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712 @@ -5,20 +5,20 @@ "type": "r_source", "hash": "0", "contents": "", - "dirty": true, + "dirty": false, "created": 1610686895894.0, "source_on_save": false, "relative_order": 5, "properties": { - "cursorPosition": "31,0", - "scrollLine": "10" + "cursorPosition": "41,13", + "scrollLine": "20" }, "folds": "", - "lastKnownWriteTime": 1610687370, + "lastKnownWriteTime": 1610688082, "encoding": "UTF-8", "collab_server": "", "source_window": "", - "last_content_update": 1610687388996, + "last_content_update": 1610688082743, "read_only": false, "read_only_alternatives": [] } \ No newline at end of file diff --git a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712-contents b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712-contents index 51993b8..93b45af 100644 --- a/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712-contents +++ b/.Rproj.user/A70D84A5/sources/s-D23FE8C5/E5780712-contents @@ -18,15 +18,25 @@ mel <- ISwR::melanom %>% ulc == 2 ~ "absent")) # Run Pipeline -------------------------- -fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick + no, +fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick , data = mel) cure_nomogram(fit, prediction_time = 300) cure_calibration(fit, prediction_time = 300) -stability <- multiple_mod_runs(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick + no, - data = mel, - num_repeats = 4) -stability +# Stability example---- +formula <- Surv(days, status) ~ ulc + sex +x <- multiple_mod_runs(formula, + nboot = 200, + eps = 0.0001, + num_repeats = 3, + data = mel) +x$model_results + +x$var_surv_stab +x$p_surv_stab + +x$var_cure_stab +x$p_cure_stab diff --git a/.Rproj.user/shared/notebooks/7EDBDC2F-README/1/A70D84A5D23FE8C5/chunks.json b/.Rproj.user/shared/notebooks/7EDBDC2F-README/1/A70D84A5D23FE8C5/chunks.json new file mode 100644 index 0000000..faaa042 --- /dev/null +++ b/.Rproj.user/shared/notebooks/7EDBDC2F-README/1/A70D84A5D23FE8C5/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[],"doc_write_time":1610688452} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/7EDBDC2F-README/1/s/chunks.json b/.Rproj.user/shared/notebooks/7EDBDC2F-README/1/s/chunks.json new file mode 100644 index 0000000..faaa042 --- /dev/null +++ b/.Rproj.user/shared/notebooks/7EDBDC2F-README/1/s/chunks.json @@ -0,0 +1 @@ +{"chunk_definitions":[],"doc_write_time":1610688452} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/paths b/.Rproj.user/shared/notebooks/paths index 58a4cf0..34a60ff 100644 --- a/.Rproj.user/shared/notebooks/paths +++ b/.Rproj.user/shared/notebooks/paths @@ -1,3 +1,5 @@ +/Users/Whiting/Repositories/cure-pipeline/.gitignore.R="49A77F14" +/Users/Whiting/Repositories/cure-pipeline/.gitignore.txt="2612A3E9" /Users/Whiting/Repositories/cure-pipeline/R/calibration-curve.R="B528D07F" /Users/Whiting/Repositories/cure-pipeline/R/clean-model-results.R="A08AB9C4" /Users/Whiting/Repositories/cure-pipeline/R/cure-nomo-multi-var.R="D92F689D" @@ -7,4 +9,5 @@ /Users/Whiting/Repositories/cure-pipeline/R/model-fitting.R="856F92CF" /Users/Whiting/Repositories/cure-pipeline/R/nomogram.R="EAD810B9" /Users/Whiting/Repositories/cure-pipeline/R/stability-tests.R="230A6CB9" +/Users/Whiting/Repositories/cure-pipeline/README.Rmd="7EDBDC2F" /Users/Whiting/Repositories/cure-pipeline/example.R="270BFC7C" diff --git a/.gitignore.R b/.gitignore.R new file mode 100644 index 0000000..984602d --- /dev/null +++ b/.gitignore.R @@ -0,0 +1,43 @@ +# ignore R data files +.Rproj.user +.Rhistory +.RData +.rds +.Ruserdata +.Rapp.history +.Rhistory.RData + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# ignore other types of data files +*.xlsx +*.xls +*.csv +*.dta +*.sas7bdat +*.sav +*.txt + +# ignore data folder/symbolic link/sensitive file +data +admin +raw-data +secure_data +ext_data +tmp +env.json +archives +outputs/archive + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# ignore misc files +~$*.docx +~$*.xlsx +~$*.pptx +~$*.tmp +Thumbs.db +.DS_Store diff --git a/.gitignore.txt b/.gitignore.txt new file mode 100644 index 0000000..984602d --- /dev/null +++ b/.gitignore.txt @@ -0,0 +1,43 @@ +# ignore R data files +.Rproj.user +.Rhistory +.RData +.rds +.Ruserdata +.Rapp.history +.Rhistory.RData + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# ignore other types of data files +*.xlsx +*.xls +*.csv +*.dta +*.sas7bdat +*.sav +*.txt + +# ignore data folder/symbolic link/sensitive file +data +admin +raw-data +secure_data +ext_data +tmp +env.json +archives +outputs/archive + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# ignore misc files +~$*.docx +~$*.xlsx +~$*.pptx +~$*.tmp +Thumbs.db +.DS_Store diff --git a/R/example-script.R b/R/example-script.R index ee7fb1a..93b45af 100644 --- a/R/example-script.R +++ b/R/example-script.R @@ -18,14 +18,25 @@ mel <- ISwR::melanom %>% ulc == 2 ~ "absent")) # Run Pipeline -------------------------- -fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick + no, +fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick , data = mel) cure_nomogram(fit, prediction_time = 300) cure_calibration(fit, prediction_time = 300) -stability <- multiple_mod_runs(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick + no, - data = mel) -stability +# Stability example---- +formula <- Surv(days, status) ~ ulc + sex +x <- multiple_mod_runs(formula, + nboot = 200, + eps = 0.0001, + num_repeats = 3, + data = mel) +x$model_results + +x$var_surv_stab +x$p_surv_stab + +x$var_cure_stab +x$p_cure_stab diff --git a/R/model-fitting.R b/R/model-fitting.R index 6cff063..316b3af 100644 --- a/R/model-fitting.R +++ b/R/model-fitting.R @@ -1,7 +1,6 @@ # Functions to Run Cure Models (Once or Multiple Times) ------------------------ # ------------------------------------------------------------------------------ -source(here::here("R", "clean-model-results.R")) # Single Model Run ------------------------------------------------------------- # Wrapper function for smcure to accept multi-level variables and save necessary @@ -96,6 +95,8 @@ multiple_mod_runs <- function(formula, num_repeats = 10, data = mel) { + source(here::here("R", "clean-model-results.R")) + # pull original variables from formula mf <- formula mf <- eval(mf, parent.frame()) @@ -235,28 +236,4 @@ multiple_mod_runs <- function(formula, } -# Examples - -# data <- ISwR::melanom %>% -# mutate(status = case_when(status %in% c(1, 3) ~ 1, -# TRUE ~ 0)) %>% -# mutate(sex = case_when(sex == 2 ~ "male", -# sex == 1 ~ "female"), -# ulc = case_when(ulc == 1 ~ "present", -# ulc == 2 ~ "absent")) -# -# formula <- Surv(days, status) ~ ulc + sex -# -# x <- multiple_mod_runs(formula, -# nboot = 200, -# eps = 0.0001, -# num_repeats = 3, -# data = data) -# x$model_results -# -# x$var_surv_stab -# x$p_surv_stab -# -# x$var_cure_stab -# x$p_cure_stab \ No newline at end of file diff --git a/README.Rmd b/README.Rmd new file mode 100644 index 0000000..afe65a5 --- /dev/null +++ b/README.Rmd @@ -0,0 +1,80 @@ +--- +output: github_document +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-", + out.width = "100%" +) +``` + +# Cure Model Pipeline + + + + +The goal of this package is to provide an easy way to build, evaluate and visualize mixture cure models ([link to paper draft](https://docs.google.com/document/d/1Lhom9H7Hxb8_C6d55Trs9JHSfJCn1i6yuu_xsDyYqZQ/edit?usp=sharing)) + + +## Available Functions + +- `fit_cure()` - wrapper for `smcure::smcure()` function that allows you to pass multilevel variables as factors directly (instead of first creating dummy codes). It also saves outputs necessary to create nomogram. +- `nomogram()-` - accepts an object created by `fit_cure()` and creates graphical nomogram based on model fit +- `cure_calibration()` - accepts an object created by `fit_cure()` and creates a calibration curve for uncured patients +- `multiple_mod_runs()`- allows you to check stability of models but running them multiple times and viewing distributions of variables and p-values. +- Coming soon: + - k-index and C-index wrapper functions + - tidyr function to better clean/view coefficients from cure model + +## Example + +```{r, eval = FALSE} +library(smcure) +library(ISwR) +library(gtsummary) +library(tidyverse) + +# Prepare Data -------------------------- +mel <- ISwR::melanom %>% + mutate(status = case_when(status %in% c(1, 3) ~ 1, + TRUE ~ 0)) %>% + mutate(thick_cat = + case_when(thick <= 129 ~ "≤ 129", + thick <= 322 ~ "less equal 322", + thick > 322 ~ "greater 322")) %>% + mutate(thick_cat = fct_relevel(thick_cat, "≤ 129", "≤ 322")) %>% + mutate(sex = case_when(sex == 2 ~ "male", + sex == 1 ~ "female"), + ulc = case_when(ulc == 1 ~ "present", + ulc == 2 ~ "absent")) + +# Run Pipeline -------------------------- +fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick , + data = mel) +cure_nomogram(fit, prediction_time = 300) +cure_calibration(fit, prediction_time = 300) + + +# Check Stability ---- +formula <- Surv(days, status) ~ ulc + sex +x <- multiple_mod_runs(formula, + nboot = 200, + eps = 0.0001, + num_repeats = 3, + data = mel) +x$model_results + +x$var_surv_stab +x$p_surv_stab + +x$var_cure_stab +x$p_cure_stab + +``` + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..103a200 --- /dev/null +++ b/README.md @@ -0,0 +1,74 @@ + + + +# Cure Model Pipeline + + + + + +The goal of this package is to provide an easy way to build, evaluate +and visualize mixture cure models ([link to paper +draft](https://docs.google.com/document/d/1Lhom9H7Hxb8_C6d55Trs9JHSfJCn1i6yuu_xsDyYqZQ/edit?usp=sharing)) + +## Available Functions + + - `fit_cure()` - wrapper for `smcure::smcure()` function that allows + you to pass multilevel variables as factors directly (instead of + first creating dummy codes). It also saves outputs necessary to + create nomogram. + - `nomogram()-` - accepts an object created by `fit_cure()` and + creates graphical nomogram based on model fit + - `cure_calibration()` - accepts an object created by `fit_cure()` and + creates a calibration curve for uncured patients + - `multiple_mod_runs()`- allows you to check stability of models but + running them multiple times and viewing distributions of variables + and p-values. + - Coming soon: + - k-index and C-index wrapper functions + - tidyr function to better clean/view coefficients from cure model + +## Example + +``` r +library(smcure) +library(ISwR) +library(gtsummary) +library(tidyverse) + +# Prepare Data -------------------------- +mel <- ISwR::melanom %>% + mutate(status = case_when(status %in% c(1, 3) ~ 1, + TRUE ~ 0)) %>% + mutate(thick_cat = + case_when(thick <= 129 ~ "≤ 129", + thick <= 322 ~ "less equal 322", + thick > 322 ~ "greater 322")) %>% + mutate(thick_cat = fct_relevel(thick_cat, "≤ 129", "≤ 322")) %>% + mutate(sex = case_when(sex == 2 ~ "male", + sex == 1 ~ "female"), + ulc = case_when(ulc == 1 ~ "present", + ulc == 2 ~ "absent")) + +# Run Pipeline -------------------------- +fit <- fit_cure(formula = Surv(days, status) ~ ulc + sex + thick_cat + thick , + data = mel) +cure_nomogram(fit, prediction_time = 300) +cure_calibration(fit, prediction_time = 300) + + +# Check Stability ---- +formula <- Surv(days, status) ~ ulc + sex +x <- multiple_mod_runs(formula, + nboot = 200, + eps = 0.0001, + num_repeats = 3, + data = mel) +x$model_results + +x$var_surv_stab +x$p_surv_stab + +x$var_cure_stab +x$p_cure_stab +```