Type: | Package |
Title: | Draw Histograms and Restricted Cubic Splines (RCS) |
Version: | 0.4.3 |
Maintainer: | Qiang LIU <dege857@163.com> |
Description: | You can use this function to easily draw a combined histogram and restricted cubic spline. The function draws the graph through 'ggplot2'. RCS fitting requires the use of the rcs() function of the 'rms' package. Can fit cox regression, logistic regression. This method was described by Per Kragh (2003) <doi:10.1002/sim.1497>. |
License: | GPL-3 |
Depends: | R (≥ 4.2.0) |
Imports: | rms, ggplot2, scales, cowplot |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.2.1 |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-02-12 01:18:47 UTC; liu |
Author: | Qiang LIU [aut, cre] |
Repository: | CRAN |
Date/Publication: | 2025-02-12 12:00:11 UTC |
ggrcs
Description
A Function to Draw Histograms and Restricted Cubic Splines (RCS)
Arguments
data |
need a dataframe |
fit |
You need the fitted model.Must be lrm or coxph. |
x |
The target variable you wish to fit. It is displayed on the X-axis when plotting. |
Details
You can use this function to easily draw a combined.histogram and restricted cubic spline.The function draws the graph through ggplot2.RCS fitting requires the use of the rcs function of the RMS package.Can fit cox regression,logistic regression and linear regression models.
Value
a picture
Examples
library(rms)
library(ggplot2)
library(scales)
library(cowplot)
dt<-smoke
dd<-datadist(dt)
options(datadist='dd')
fit<- cph(Surv(time,status==1) ~ rcs(age,4)+gender, x=TRUE, y=TRUE,data=dt)
###single group
ggrcs(data=dt,fit=fit,x="age")
##two groups
ggrcs(data=dt,fit=fit,x="age",group="gender")
ggrcs2
Description
A Function to Draw Histograms and Restricted Cubic Splines (RCS)
Arguments
data |
need a dataframe |
fit |
You need the fitted model.Must be lrm or coxph. |
x |
The target variable you wish to fit. It is displayed on the X-axis when plotting. |
Details
You can use this function to easily draw a combined.histogram and restricted cubic spline.The function draws the graph through ggplot2.RCS fitting requires the use of the rcs function of the RMS package.Can fit cox regression,logistic regression and linear regression models.
Value
a picture
predata
Description
Generate the predicted data for the function. This is needed for drawing.
Usage
predata(fit, variables, y, group = NULL)
Arguments
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Value
Data required for plotting.
predata.coxph
Description
Generate the predicted data for the function. This is needed for drawing.
Usage
## S3 method for class 'coxph'
predata(fit, variables, y, group = NULL)
Arguments
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Value
Data required for plotting.
predata.lrm
Description
Generate the predicted data for the function. This is needed for drawing.
Usage
## S3 method for class 'lrm'
predata(fit, variables, y, group = NULL)
Arguments
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Value
Data required for plotting.
predata.ols
Description
Generate the predicted data for the function. This is needed for drawing.
Usage
## S3 method for class 'ols'
predata(fit, variables, y, group = NULL)
Arguments
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Value
Data required for plotting.
singlercs
Description
A Function to Draw Restricted Cubic Splines (RCS)
Arguments
data |
need a dataframe |
fit |
You need the fitted model.Must be lrm , ols or coxph. |
x |
The target variable you wish to fit. It is displayed on the X-axis when plotting. |
Details
You can use this function to easily draw a restricted cubic spline.The function draws the graph through ggplot2.RCS fitting requires the use of the rcs function of the RMS package.Can fit cox regression,logistic regression and linear regression models.
Value
a picture
Examples
library(rms)
library(ggplot2)
library(scales)
dt<-smoke
dd<-datadist(dt)
options(datadist='dd')
fit<- cph(Surv(time,status==1) ~ rcs(age,4)+gender, x=TRUE, y=TRUE,data=dt)
###one group
singlercs(data=dt,fit=fit,x="age")
##two groups
singlercs(data=dt,fit=fit,x="age",group="gender")
A data on age and smoking rates.
Description
A data on age and smoking rates.
Usage
data(smoke)
Format
An object of class data.frame
with 995 rows and 5 columns.
Examples
data(smoke)