rrateplots.jl

How to calculate and plot cumulative incidence rate (incidence rate) over a data of 30 years and include baseline occurrence in R


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?


Solution

  • 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)))