The ggrcs package version 2.9 is released - adding the singlercs function for drawing separate rcs curves (restricted cubic splines)

At present, the new 2.8 version of the ggrcs package written by me has been launched on CRAN, and currently supports logistic regression (logistic regression), cox regression and multiple linear regression. Added singlercs function to draw separate rcs curves (restricted cubic splines).
insert image description here
You can use the code to install if you need it

install.packages("ggrcs")

If an old version is installed, you can upgrade it through Rstudio
insert image description here
insert image description here
so that you can upgrade to the latest version.
Some fans sent me private messages saying that the density function of the histogram is not needed, and they hope to create a function that draws rcs alone. Therefore, the singlercs function was added in version 2.9. Single means single and simple, that is, simply draws RCS, and the drawing method is basically the same as ggrcs, just without the histogram and left axis. Let's demonstrate it below. We only introduce new functions. For other functions, please refer to previous articles.
First import the package and data, here use the smoking data that comes with the ggrcs package

library(rms)
library(ggplot2)
library(scales)
library(ggrcs)
dt<-smoke
dd<-datadist(dt)
options(datadist='dd')
fit<- cph(Surv(time,status==1) ~ rcs(age,4)+gender, x=TRUE, y=TRUE,data=dt)

insert image description here
This is the smoking data that comes with the R package. Suppose we want to understand the relationship between age and smoking incidence

singlercs(data=dt,fit=fit,x="age")

insert image description here
Originally, I wanted to add a horizontal line at the beginning, but it is not convenient for you to modify it in the later stage. After thinking about it, I don’t want to add it. You can add it after generating a picture. This is also very convenient, and it is also convenient for you to modify the style of the line, which is flexible.

p<-singlercs(data=dt,fit=fit,x="age")
p+geom_hline(yintercept=1, linetype=2,linewidth=1)

insert image description here
You can also use my self-written cut.tab function to generate turning points

fit1 <-coxph(Surv(time,status==1) ~ age,data=dt)
cut.tab(fit1,"age",dt)

insert image description here
Then add the turning dotted line

p+geom_vline(aes(xintercept=38.449),colour="#BB0000", linetype="dashed")+
  geom_hline(yintercept=1, linetype=2,linewidth=1)

insert image description here
Generate a table of the turning points, showing that the age turns here at 38.449 years, with an OR of 0.956 before and 1.055 after. A likelihood ratio test of less than 0.05 indicates that the curve is meaningful.
For the specific usage of the cut.tab function, please refer to " cox regression RCS threshold effect function cut.tab1.3 release "
insert image description here
Singlercs function can also be flexibly modified to change the color of lines and credible intervals

singlercs(data=dt,fit=fit,x="age",ribcol="green")

insert image description here
Change Credible Interval Transparency

singlercs(data=dt,fit=fit,x="age",ribcol="green",ribalpha=0.2)

insert image description here
Change axes and titles

singlercs(data=dt,fit=fit,x="age",histcol="blue",
          histbinwidth=1,ribcol="green",ribalpha=0.5,xlab ="年龄",ylab="死亡率",title ='年龄与死亡率关系')

insert image description here
add p value

singlercs(data=dt,fit=fit,x="age",histcol="blue",
          histbinwidth=1,ribcol="green",ribalpha=0.5,xlab ="年龄",
          ylab="死亡率",title ='年龄与死亡率关系',P.Nonlinear=T,Pvalue="<0.05")

insert image description here
Adjust the position of the P value display

singlercs(data=dt,fit=fit,x="age",histcol="blue",
          histbinwidth=1,ribcol="green",ribalpha=0.5,xlab ="年龄",
          ylab="死亡率",title ='年龄与死亡率关系',P.Nonlinear=T,Pvalue="<0.05",xP.Nonlinear=25,yP.Nonlinear=10)

insert image description here
Let's introduce the classification (two) RCS curves. If you don't set the color, the default is red and green.

singlercs(data=dt,fit=fit,x="age",group="gender")

insert image description here
change color

singlercs(data=dt,fit=fit,x="age",group="gender",groupcol=c("red","blue"))

insert image description here
change transparency

singlercs(data=dt,fit=fit,x="age",group="gender",groupcol=c("red","blue"),ribalpha=0.5)

insert image description here
Change axes and titles

singlercs(data=dt,fit=fit,x="age",group="gender",groupcol=c("red","blue"),ribalpha=0.5,
          xlab ="年龄",ylab="死亡率",title ='年龄与死亡率关系')

insert image description here
Add P value and modify the position of P value in the picture

singlercs(data=dt,fit=fit,x="age",group="gender",groupcol=c("red","blue"),ribalpha=0.5,
          xlab ="年龄",ylab="死亡率",title ='年龄与死亡率关系',P.Nonlinear=T,Pvalue="<0.05",
          xP.Nonlinear=25,yP.Nonlinear=7)

insert image description here
Change tab name

singlercs(data=dt,fit=fit,x="age",group="gender",groupcol=c("red","blue"),ribalpha=0.5,
          xlab ="年龄",ylab="死亡率",title ='年龄与死亡率关系',P.Nonlinear=T,Pvalue="<0.05",
          xP.Nonlinear=25,yP.Nonlinear=7,twotag.name= c("m","f"))

insert image description here
Well, the new version is introduced here, and I introduced the cox regression model here. The method of logistic regression and linear regression is also the same. It is worth mentioning that because there is no need to draw a density map, the rcs of linear regression drawn by the singlercs function is better than that of ggrcs. If using ggrcs to make a linear regression rcs curve is not ideal, you can consider it Use the singlercs function at once.
If you have any suggestions or if there is something wrong with the R package, you are welcome to let me know.

Guess you like

Origin blog.csdn.net/dege857/article/details/130213650