0

can I make "number at risk "table for cox plot if I have more than one independent variable? if it possible where can I find the relevant code (I searched but couldn't find) the code I used on my data:

fit <- coxph(Surv(time,event) ~chr1q21_status+CCND1+CRTM1+IRF4,data = myeloma)

ggsurvplot(fit, data = myeloma,
  risk.table=TRUE, break.time.by=365, xlim = c(0,4000),
  risk.table.y.text=FALSE, legend.labs =  c("2","3","4+"))

got this message- object 'ggsurv' not found' although for only one variable and the function survfit it worked.

alan ocallaghan
  • 3,116
  • 17
  • 37
Sveta
  • 1
  • 2
  • Have you looked at the package [`survminer`](https://cran.r-project.org/web/packages/survminer/index.html)? – alan ocallaghan Feb 19 '20 at 16:06
  • yes, I used that package for the KM n at risk plot but it didn't work for cox with more than one variable – Sveta Feb 19 '20 at 16:31
  • Post some of the data and code you've used so far, and explain what you want to accomplish in more detail – alan ocallaghan Feb 19 '20 at 16:32
  • Put your code in the question, not a comment. Also it may help to create a similar analysis using a dataset that's built-in to R so people can test your code more easily. – alan ocallaghan Feb 19 '20 at 16:55

1 Answers1

0

"number at risk "table for cox plot

It's not a Cox plot, it's a Kaplan-Meier plot. You're trying to plot a Cox model, when what you want is to fit KM curves using survfit and then to plot the resulting fit:

library("survival")
library("survminer")
fit <- survfit(Surv(time,status) ~ ph.ecog + sex , data = lung)
ggsurvplot(fit, data = lung, risk.table = TRUE)

Since you now mention that you have continuous predictors, perhaps you could think about what you expect an at-risk table or KM plot to show. Here's an example of binning a continuous measure (age):

library("survival")
library("survminer")
#> Loading required package: ggplot2
#> Loading required package: ggpubr
#> Loading required package: magrittr
lung$age_bin <- cut(lung$age, quantile(lung$age))
fit <- survfit(Surv(time,status) ~ age_bin + sex , data = lung)
ggsurvplot(fit, data = lung, risk.table = TRUE)

alan ocallaghan
  • 3,116
  • 17
  • 37
  • Thank you but I tried that too before I did the cox model, it didn't work, I have 4 variables and 2 of them are continuous not sure if that is the problem – Sveta Feb 19 '20 at 17:28
  • What do you expect a KM plot or at risk table for a numeric covariate to look like? – alan ocallaghan Feb 19 '20 at 17:34
  • I've updated my answer with an example for continuous covariates. – alan ocallaghan Feb 19 '20 at 17:38
  • I know KM isn't right in this case, but I was asked to make n at risk for cox model (just the number of people who died in each period) so that was my question if I can do it? so there is no way to make a table of people who died in each period for the cox model is that right? – Sveta Feb 19 '20 at 17:42
  • sorry I saw your second answer after I answered , thank you I will try that! – Sveta Feb 19 '20 at 17:44