0

I am struggling with finding the R package and codes to calculate and plot the cumulative incidence rate/IR (with 95% CI) in R. I have two datasets D1 and D2 with eight events each (E1...E8) and five groups (G1...G5) each and;

In D1, I want to calculate IR (with 95% CI) and then have a separate plot for each group (G1... G5), showing E1 to E8 IR in each. Something like as follows;

enter image description here

And in D2, I want to do same calculations, except my plots should not start at zero for each event as I have prevalent cases for each event at study start date. It should be something like follows;

enter image description here

Should I start with survival analysis? is it suitable?

Tabbi
  • 69
  • 1
  • 9
  • 1
    I would look into kaplan meier curves https://rviews.rstudio.com/2017/09/25/survival-analysis-with-r/ – Schilker Jan 09 '20 at 15:11
  • @Schilker Even if I am not concerned with loss by death or competing risk in the data? can I not compute the incidence rate and plot the graph? – Tabbi Jan 09 '20 at 16:01
  • 1
    yes you could manually calculate the cumulative incidence through time then plot. This just seems like a lot more extra work, but doable. – Schilker Jan 09 '20 at 17:20

1 Answers1

0

Try the following Kaplan-Meier Plot

library(survival)
fit = survfit(Surv(Time_variable, Censor_Variable) ~ as.factor(Stratify_Variable), data=ds)
plot(fit, conf.int=FALSE, lty=1:length(unique(Stratify_Variable)))
Schilker
  • 505
  • 2
  • 11
  • I am not sure how to add image in comment, but I've got survival plot for one event in five groups, now if I'm using `plot(fit, conf.int=F, fun = function(x) 1-x)` I am seeing a plot, is it cumulative incidence (CI) plot as CI = 1-survival probability ()? Also, how would I present each line or group with a different color in the graph and put a legend to it please? – Tabbi Jan 09 '20 at 23:02
  • Thanks much, with a bit of an effort following your suggestion, I was able to find the solution – Tabbi Jan 14 '20 at 12:02