### Install tidycmprsk Package in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/README.md Provides instructions for installing the tidycmprsk R package from CRAN and the development version from GitHub. It requires the devtools package for GitHub installation. ```r install.packages("tidycmprsk") ``` ```r # install.packages("devtools") devtools::install_github("MSKCC-Epi-Bio/tidycmprsk") ``` -------------------------------- ### Basic tbl_cuminc() Usage and Common Errors Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/tests/testthat/_snaps/tbl_cuminc.md This section showcases basic usage of the tbl_cuminc() function and common error conditions that arise from incorrect argument values for 'outcomes', 'statistic', and 'label'. It also demonstrates an error when trying to add p-values without stratification. ```r library(cmprsk) library(gtsummary) # Example data (assuming 'trial' is a data frame with appropriate columns) trial <- list(ttdeath = c(1, 2, 3, 4, 5), death_cr = c(0, 1, 0, 0, 1)) trial <- data.frame(trial) # Incorrect outcomes argument cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>% tbl_cuminc(outcomes = letters) # Incorrect statistic argument cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>% tbl_cuminc(statistic = letters) # Incorrect label argument cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>% tbl_cuminc(label = letters) # Error adding p-value without stratification cuminc(Surv(ttdeath, death_cr) ~ 1, trial) %>% tbl_cuminc() %>% add_p() ``` -------------------------------- ### Customize Statistic Format in Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This example demonstrates customizing the format of cumulative incidence estimates and their confidence intervals within a summary table. It also shows how to apply custom formatting to the estimates using `style_sigfig`. ```r # Customize statistic format tbl3 <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc( times = c(12, 24), statistic = "{estimate}% (95% CI: {conf.low}%, {conf.high}%)", label_header = "**{time} Months**", estimate_fun = function(x) gtsummary::style_sigfig(x * 100, digits = 3) ) ``` -------------------------------- ### Create Basic Cumulative Incidence Summary Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Generates a basic publication-ready summary table of cumulative incidence estimates at specified time points using `tbl_cuminc`. This example shows a single cohort without stratification. ```r # Basic table for single cohort tbl1 <- cuminc(Surv(ttdeath, death_cr) ~ 1, data = trial) %>% tbl_cuminc(times = c(12, 24), label_header = "**Month {time}**") print(tbl1) ``` -------------------------------- ### Customize P-value Formatting in Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This example demonstrates how to customize the formatting of p-values added to a cumulative incidence summary table using the `add_p` function and a custom `pvalue_fun`. ```r # Customize p-value formatting tbl_custom_p <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc(times = c(12, 24)) %>% add_p(pvalue_fun = function(x) gtsummary::style_pvalue(x, digits = 3)) ``` -------------------------------- ### Estimate Cumulative Incidence with cuminc() in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/README.md Illustrates the use of the `cuminc()` function from `tidycmprsk` to estimate the cumulative incidence of competing events. The example shows a model with no covariates and displays the resulting time-dependent estimates. ```r cuminc(Surv(ttdeath, death_cr) ~ 1, trial) #> #> ── cuminc() ──────────────────────────────────────────────────────────────────── #> • Failure type "death from cancer" #> time n.risk estimate std.error 95% CI #> 5.00 199 0.000 0.000 NA, NA #> 10.0 189 0.030 0.012 0.012, 0.061 #> 15.0 158 0.120 0.023 0.079, 0.169 #> 20.0 116 0.215 0.029 0.161, 0.274 #> • Failure type "death other causes" #> time n.risk estimate std.error 95% CI #> 5.00 199 0.005 0.005 0.000, 0.026 #> 10.0 189 0.025 0.011 0.009, 0.054 #> 15.0 158 0.090 0.020 0.055, 0.135 #> 20.0 116 0.205 0.029 0.152, 0.264 ``` -------------------------------- ### Get Gray's Test Statistics with glance.tidycuminc() Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Returns Gray's test statistics for comparing cumulative incidence curves across strata. The output includes the test statistic, degrees of freedom, and p-value for each competing event, presented in a wide format with one column per outcome. ```r library(tidycmprsk) # Fit the cumulative incidence model ci_fit <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) # Get Gray's test statistics glance(ci_fit) ``` -------------------------------- ### Create Cumulative Incidence Summary Table with gtsummary in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/README.md Shows how to generate a summary table of cumulative incidence estimates at specific time points using `tbl_cuminc` from `gtsummary`. It allows for customization of time points, headers, and inclusion of p-values and sample sizes. ```r tbl <- cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>% tbl_cuminc(times = c(12, 24), label_header = "**Month {time}**") %>% add_p() %>% add_n() ``` -------------------------------- ### Create Regression Table with gtsummary and crr() Output in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/README.md Shows how to create a formatted regression table from a `crr()` model object using the `gtsummary` package. It demonstrates chaining functions like `tbl_regression`, `add_global_p`, and `add_n` for comprehensive table generation. ```r tbl <- crr_mod %>% gtsummary::tbl_regression(exponentiate = TRUE) %>% gtsummary::add_global_p() %>% add_n(location = "level") ``` -------------------------------- ### tbl_regression method for tidycrr models in gtsummary Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/NEWS.md Adds a method to use `gtsummary::tbl_regression()` with `tidycmprsk::crr()` models. The {tidycmprsk} package must be loaded to access the S3 methods. Includes adding {broom.helpers}, {cardx}, and {aod} to Suggests field and a `global_pvalue_fun.tidycrr()` method, which changes the default calculation in `gtsummary::add_global_p(anova_fun)` to use the Wald test. ```R tbl_regression.tidycrr() global_pvalue_fun.tidycrr() ``` -------------------------------- ### Visualize Cumulative Incidence with ggsurvfit Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Creates publication-quality cumulative incidence plots using the ggsurvfit package. Supports confidence bands, risk tables, and customizable aesthetics for survival data with competing risks. ```r library(ggsurvfit) # Basic cumulative incidence plot ci_fit <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) p1 <- ci_fit %>% ggcuminc() %>% add_confidence_interval() %>% add_risktable() %>% scale_ggsurvfit(x_scales = list(breaks = seq(0, 24, by = 6))) print(p1) #> Creates plot with CI bands and risk table below # Customize plot appearance p2 <- ci_fit %>% ggcuminc(outcome = "death from cancer") %>% add_confidence_interval() %>% add_risktable() %>% labs( title = "Cumulative Incidence of Death from Cancer", x = "Time (months)", y = "Cumulative Incidence" ) %>% theme_minimal() # Plot both outcomes separately p3 <- ci_fit %>% ggcuminc() %>% add_confidence_interval() %>% facet_wrap(~ outcome) %>% theme_bw() ``` -------------------------------- ### Generate Regression Tables with gtsummary Integration Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Provides seamless integration with the gtsummary package for creating publication-ready regression tables from competing risk regression models (crr objects). Supports standard gtsummary modifications and inline text extraction. ```r library(gtsummary) # Create formatted regression table crr_mod <- crr(Surv(ttdeath, death_cr) ~ age + trt + grade, data = trial) tbl_reg <- crr_mod %>% tbl_regression(exponentiate = TRUE) %>% add_global_p() %>% add_n(location = "level") %>% bold_p(t = 0.05) %>% modify_header(label = "**Variable**") %>% modify_footnote(everything() ~ NA, abbreviation = TRUE) print(tbl_reg) #> Formatted regression table with SDHRs, CIs, and p-values # Extract inline text from regression table inline_text(tbl_reg, variable = age) #> "1.01 (95% CI 0.99, 1.03; p=0.6)" inline_text(tbl_reg, variable = trt, level = "Drug B") #> "1.52 (95% CI 0.88, 2.62; p=0.13)" # Combine multiple models in one table tbl_merge <- tbl_merge( list( crr(Surv(ttdeath, death_cr) ~ age, trial) %>% tbl_regression(exponentiate = TRUE), crr(Surv(ttdeath, death_cr) ~ age + trt, trial) %>% tbl_regression(exponentiate = TRUE) ), tab_spanner = c("**Unadjusted**", "**Adjusted**") ) ``` -------------------------------- ### tbl_cuminc() function and related methods Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/NEWS.md Adds the `tbl_cuminc()` function (similar to `gtsummary::tbl_survfit()`). Also added related methods, `add_n.tbl_cuminc()`, `add_nevent.tbl_cuminc()`, `add_p.tbl_cuminc()`, and `inline_text.tbl_cuminc()`. These functions provide tabular summaries for cumulative incidence estimation. ```R tbl_cuminc() add_n.tbl_cuminc() add_nevent.tbl_cuminc() add_p.tbl_cuminc() inline_text.tbl_cuminc() ``` -------------------------------- ### Fit Competing Risk Regression Model with crr() in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/README.md Demonstrates how to fit a Fine and Gray competing risks regression model using the `crr()` function from the `tidycmprsk` package. It utilizes the `Surv()` function for time-to-event data and shows how to inspect the model output. ```r library(tidycmprsk) crr_mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, trial) #> 11 cases omitted due to missing values crr_mod #> #> ── crr() ─────────────────────────────────────────────────────────────────────── #> • Call Surv(ttdeath, death_cr) ~ age + trt #> • Failure type of interest "death from cancer" #> #> Variable Coef SE HR 95% CI p-value #> age 0.006 0.010 1.01 0.99, 1.03 0.56 #> trtDrug B 0.417 0.279 1.52 0.88, 2.62 0.13 ``` -------------------------------- ### Create Stratified Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Creates a cumulative incidence summary table stratified by a treatment group (`trt`), including multiple outcomes. It allows customization of time points and outcome labels. ```r # Table stratified by treatment with both outcomes tbl2 <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc( times = c(12, 24), outcomes = c("death from cancer", "death other causes"), label_header = "**Month {time}**" ) print(tbl2) ``` -------------------------------- ### Plot Cumulative Incidence Curves with ggcuminc() in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/README.md Demonstrates how to plot cumulative incidence curves using the `cuminc()` function output combined with the `ggsurvfit` package. It includes options for adding confidence intervals, risk tables, and customizing the x-axis. ```r library(ggsurvfit) #> Loading required package: ggplot2 cuminc(Surv(ttdeath, death_cr) ~ trt, trial) %>% ggcuminc() + add_confidence_interval() + add_risktable() + scale_ggsurvfit(x_scales = list(breaks = seq(0, 24, by = 6))) #> Plotting outcome "death from cancer". ``` -------------------------------- ### Generate Regression Table with tidycrr in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/tests/testthat/_snaps/gtsummary_s3_methods.md This snippet shows how to use the tbl_regression function with the crr function from the tidycmprsk package to generate a regression table for competing risks data. It requires the survival package for the crr function and expects survival objects as input. The output is a data frame summarizing the regression results. ```r as.data.frame(tbl_regression(crr(Surv(ttdeath, death_cr) ~ age + grade, trial))) ``` -------------------------------- ### Select Specific Outcome for Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This snippet shows how to generate a cumulative incidence summary table for a single, specific outcome, while still allowing for stratification by treatment group. It customizes the label for the outcome. ```r # Select specific outcome only tbl4 <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc( times = 24, outcomes = "death from cancer", label = "Treatment Arm" ) ``` -------------------------------- ### Add Sample Size (N) Columns to Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This code snippet illustrates adding sample size (N) columns to cumulative incidence summary tables. The `add_n` function can display total N or stratum-specific N, controlled by the `location` argument. ```r # Add total N at label row tbl1 <- cuminc(Surv(ttdeath, death_cr) ~ 1, data = trial) %>% tbl_cuminc(times = c(12, 24)) %>% add_n() # Default: location = "label" #> Adds column showing N for entire cohort # Add N at both label and level rows tbl2 <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc(times = c(12, 24)) %>% add_n(location = c("label", "level")) #> Shows total N and N for each treatment group # Add stratum-level N only tbl3 <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc(times = 12) %>% add_n(location = "level") #> Shows N for Drug A and Drug B separately ``` -------------------------------- ### Extract Inline Statistics from Cumulative Incidence Tables Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Extracts formatted statistics from cumulative incidence tables for inline reporting. It can select specific times, strata, outcomes, and columns, returning character strings ready for R Markdown or Quarto. ```r tbl <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc( times = c(12, 24), outcomes = c("death from cancer", "death other causes"), label_header = "**Month {time}**" ) %>% add_p() %>% add_n(location = c("label", "level")) # Extract estimate at specific time and level inline_text(tbl, time = 12, level = "Drug A") #> "5.1% (95% CI 1.4%, 12.0%)" # Extract from different outcome inline_text(tbl, time = 24, level = "Drug B", outcome = "death other causes") #> "20.8% (95% CI 13.0%, 30.0%)" # Extract p-value column inline_text(tbl, column = p.value) #> "p=0.7" # Use in R Markdown # The 12-month cumulative incidence was `r inline_text(tbl, time = 12, level = "Drug A")` ``` -------------------------------- ### Extract Global P-values from tidycrr Output in R Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/tests/testthat/_snaps/gtsummary_s3_methods.md This snippet demonstrates how to extract global p-values from a tidycmprsk regression table using the global_pvalue_fun function. It takes a regression table object (tbl) as input and can optionally suppress column labels. The output is a data frame containing labels, estimates, confidence intervals, and p-values. ```r as.data.frame(tbl, col_labels = FALSE) ``` -------------------------------- ### Tidy Competing Risk Regression Results with tidy.tidycrr() in R Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Extracts model coefficients, standard errors, and optionally confidence intervals from a `crr()` object into a tidy tibble format using `tidy()`. The `exponentiate` argument allows conversion of log hazard ratios to hazard ratios for easier interpretation. ```r mod <- crr(Surv(ttdeath, death_cr) ~ age + grade, data = trial) # Get tidy coefficient table tidy(mod) #> # A tibble: 3 × 5 #> term estimate std.error statistic p.value #> #> 1 age 0.00574 0.00962 0.597 0.551 #> 2 gradeII 0.122 0.314 0.390 0.697 #> 3 gradeIII -0.170 0.308 -0.551 0.581 # Exponentiate to get subdistribution hazard ratios tidy(mod, exponentiate = TRUE) #> # A tibble: 3 × 5 #> term estimate std.error statistic p.value #> #> 1 age 1.01 0.00962 0.597 0.551 #> 2 gradeII 1.13 0.314 0.390 0.697 #> 3 gradeIII 0.844 0.308 -0.551 0.581 # Include confidence intervals tidy(mod, exponentiate = TRUE, conf.int = TRUE, conf.level = 0.95) #> # A tibble: 3 × 7 #> term estimate std.error conf.low conf.high statistic p.value #> #> 1 age 1.01 0.00962 0.991 1.03 0.597 0.551 #> 2 gradeII 1.13 0.314 0.613 2.09 0.390 0.697 #> 3 gradeIII 0.844 0.308 0.461 1.54 -0.551 0.581 ``` -------------------------------- ### vcov() method for crr() models Source: https://github.com/mskcc-epi-bio/tidycmprsk/blob/main/NEWS.md Adds a `vcov()` method for `crr()` models. This function calculates the variance-covariance matrix of the estimated coefficients in the competing risks regression model. It enhances the ability to perform statistical inference on the model parameters. ```R vcov(crr()) ``` -------------------------------- ### Add Event Count Columns to Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This code shows how to add columns displaying the total number of events or stratum-specific event counts to cumulative incidence summary tables using the `add_nevent` function. This helps in understanding the number of competing events observed. ```r # Add total events at label row tbl1 <- cuminc(Surv(ttdeath, death_cr) ~ 1, data = trial) %>% tbl_cuminc(times = c(12, 24)) %>% add_nevent() # Default: location = "label" #> Adds column showing total number of events # Comprehensive table with N, events, and p-values tbl_full <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc( times = c(12, 24), outcomes = c("death from cancer", "death other causes"), label_header = "**Month {time}**" ) %>% add_p() %>% add_nevent(location = c("label", "level")) %>% add_n(location = c("label", "level")) #> Complete publication-ready table with all statistics ``` -------------------------------- ### Extract Model Coefficients and Statistics from crr() in R Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Extracts standard model components from a `crr()` object using base R functions. This includes coefficient estimates, variance-covariance matrices, model matrices, and model frames, facilitating further analysis or integration into other workflows. ```r # Fit a model mod <- crr(Surv(ttdeath, death_cr) ~ age + grade, data = trial) # Extract coefficients coef(mod) #> Named numeric vector of coefficient estimates # Extract variance-covariance matrix vcov(mod) #> Variance-covariance matrix # Get model matrix (design matrix) head(model.matrix(mod)) #> age gradeII gradeIII #> 1 63 0 0 #> 2 63 0 1 #> 3 58 0 1 # Get model frame (original data used in model) head(model.frame(mod)) #> Data frame with Surv object and predictor variables # Extract model terms terms(mod) #> Terms object with formula information ``` -------------------------------- ### Fit Competing Risk Regression Model with crr() in R Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Fits a Fine and Gray competing risks regression model using the `crr()` function. It requires a formula with a `Surv()` object and a factor for event status where the first level is censoring. The function can also specify which competing event to model. ```r library(tidycmprsk) # Fit competing risks regression model # death_cr is a factor: first level = censor, subsequent levels = competing events crr_mod <- crr(Surv(ttdeath, death_cr) ~ age + trt, data = trial) # View model summary print(crr_mod) #> ── crr() ────────────────────────────────────────────────────────────────── #> • Call Surv(ttdeath, death_cr) ~ age + trt #> • Failure type of interest "death from cancer" #> #> Variable Coef SE HR 95% CI p-value #> age 0.006 0.010 1.01 0.99, 1.03 0.56 #> trtDrug B 0.417 0.279 1.52 0.88, 2.62 0.13 # Fit model with categorical predictors crr_grade <- crr(Surv(ttdeath, death_cr) ~ age + grade, data = trial) print(crr_grade) # Specify which competing event to model (by default uses first) crr_mod2 <- crr( Surv(ttdeath, death_cr) ~ age + trt, data = trial, failcode = "death other causes" ) ``` -------------------------------- ### Tidy Cumulative Incidence Results with tidy.tidycuminc() Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Extracts cumulative incidence estimates into a tidy data frame. The function can return estimates at all observed times or user-specified times, including standard errors and confidence intervals. It also provides risk set information for each competing event and stratum. ```r library(tidycmprsk) # Fit the cumulative incidence model ci_fit <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) # Get estimates at all observed times tidy(ci_fit) # Get estimates at specific times only tidy(ci_fit, times = c(12, 24)) # Exclude confidence intervals tidy(ci_fit, times = c(12, 24), conf.int = FALSE) # Change confidence level tidy(ci_fit, times = 12, conf.level = 0.90) ``` -------------------------------- ### Summarize Competing Risks Regression Model with glance.tidycrr() Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Generates a one-row tibble with overall model statistics for a crr() model, including convergence and fit metrics. This function is useful for quickly assessing the global performance of the fitted model. ```r library(survival) library(cmprsk) library(tidycmprsk) # Fit a competing risks regression model mod <- crr(Surv(ttdeath, death_cr) ~ age + grade, data = trial) # Get model-level statistics glance(mod) ``` -------------------------------- ### Estimate Cumulative Incidence Functions with cuminc() Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Estimates cumulative incidence functions nonparametrically for each competing risk. It can compute estimates for the entire cohort or stratified by grouping variables. The function returns estimates at all observed event times and includes Gray's test for comparing cumulative incidence across strata. ```r library(tidycmprsk) # Calculate cumulative incidence for entire cohort ci_overall <- cuminc(Surv(ttdeath, death_cr) ~ 1, data = trial) print(ci_overall) # Calculate cumulative incidence by treatment group ci_by_trt <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) print(ci_by_trt) # Stratified analysis with additional strata variable ci_strat <- cuminc( Surv(ttdeath, death_cr) ~ trt, data = trial, strata = trial$stage # stratify test by stage ) ``` -------------------------------- ### Restructure Cumulative Incidence Data to Long Format (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This code snippet demonstrates how to restructure a wide-format tibble of cumulative incidence statistics into a long format, where each row represents an outcome. It uses `tidyr::pivot_longer` to achieve this. ```r glance(ci_fit) %> tidyr::pivot_longer( everything(), names_to = c(".value", "outcome_id"), names_pattern = "(.*)_(.*)" ) ``` -------------------------------- ### Add P-values (Gray's Test) to Cumulative Incidence Table (R) Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt This code adds a column of p-values from Gray's test to a cumulative incidence summary table. Gray's test compares cumulative incidence curves across different strata. It is only applicable for stratified analyses. ```r tbl <- cuminc(Surv(ttdeath, death_cr) ~ trt, data = trial) %>% tbl_cuminc( times = c(12, 24), outcomes = c("death from cancer", "death other causes"), label_header = "**Month {time}**" ) %>% add_p() # Add Gray's test p-values print(tbl) ``` -------------------------------- ### Predict Cumulative Incidence from crr() Models Source: https://context7.com/mskcc-epi-bio/tidycmprsk/llms.txt Generates predicted cumulative incidence probabilities from a crr() model. Predictions can be made for specified times or time points, for the original data or new observations. The output can be directly used with augment() to add predictions to a data frame. ```r library(survival) library(cmprsk) library(tidycmprsk) # Fit a competing risks regression model mod <- crr(Surv(ttdeath, death_cr) ~ age, data = trial) # Predict cumulative incidence at specific times for first 10 patients pred_times <- predict(mod, times = c(12, 24), newdata = trial[1:10, ]) head(pred_times) # Get time at which specific probabilities are reached pred_probs <- predict(mod, probs = c(0.1, 0.25, 0.5), newdata = trial[1:10, ]) head(pred_probs) # Use with augment to add predictions to data frame augment(mod, times = 12, newdata = trial[1:10, ]) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.