3
df <- data.frame(PatientID = c("0002" ,"0002", "0005", "0005" ,"0009" ,"0009" ,"0018", "0018" ,"0039" ,"0039" , "0043" ,"0043", "0046", "0046" ,"0048" ,"0048"),
                 time = c( 1961.810 , 929.466 , 978.166, 1005.820 , 925.752 , 969.469  ,943.398 ,  965.292 , 1996.404 ,  967.047 ,  NA , 893.428 , 921.606 , 976.192 , 929.590 , 950.493),
                 event = c(1 , 1 , 0 , 1 , 0 ,  1 , 0 , 0   ,  1 , 0 , 1 ,1 , 0 ,0  ,0 , 1),
                 BMI = c( 10.140 , 20.810 , 24.466 , 31.166, 26.469 , 40.398  ,20.034,  23.292 , 50.404 , 19.610 , 20.047, 37.517 , 36.428 , 19.606 , 20.590  ,29.493), stringsAsFactors = F)

A bit of an abstract question but I would like to create a plot where in the X axis I have body mass index (continuous variable) and in the Y axis I want to plot the hazard ratios of BMI associated to the risk of experiencing an event (we'll call the event df$event)

I have attached a plot that is an example of what I want to plot and the link to the paper from where this is from: https://www.thelancet.com/journals/landia/article/PIIS2213-8587%2818%2930288-2/fulltext

enter image description here

I have found this document but I don't really understand it properly: https://blogs.bu.edu/gagnon/files/2021/02/README-Restricted-Cubic-Spline-Plots.pdf

I would like to do this plot in R software.

ALTERNATIVE "DIRTY" WAY OF PLOTTING THIS:

Do univariate cox regressions of 5 cutt-offs (bmi >10, >20, >30, >40, >50) and then plot that in a x,y plot. But in this case, how could we introduce the CI that are derived from the cox regression?

Thank you so much for your help!

Lili
  • 547
  • 6
  • 19
  • Could you please share some code you tried and data using `dput`? – Quinten Jul 28 '22 at 16:56
  • Thank you! I hope that helps.... I didn't try any code, I literally don't know where to start :( – Lili Jul 28 '22 at 17:04
  • The "Statistical Analysis" section explains: "Cox regression models with an age timescale were fitted for all-cause mortality and for each cause-specific mortality outcome, censoring deaths from competing causes." Your question should be: How do I do a Cox regression with a restricted cubic spline for time? – dipetkov Jul 28 '22 at 19:25
  • This analysis is not easy. You may learn more in F.E. Harrell's "Regression Modeling Strategies" [book](https://www.amazon.com/Regression-Modeling-Strategies-Applications-Statistics/dp/3319194240) and [course notes](https://hbiostat.org/rms/). – dipetkov Jul 28 '22 at 19:28
  • I am not sure if cubic splines would be the way to go (I thought so). Let say that what I want is to produce a plot with the HR on the Y axis and the variable in the x axis (continuous). I do cox regressions and I get the HR, but I do them for 1 threshold at the time rather than in a continuos way. - not sure this makes sense. – Lili Jul 29 '22 at 08:49

0 Answers0