Title: | Draw Histograms and Restricted Cubic Splines (RCS) |
---|---|
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>. |
Authors: | Qiang LIU [aut, cre] |
Maintainer: | Qiang LIU <[email protected]> |
License: | GPL-3 |
Version: | 0.4.2 |
Built: | 2024-11-24 06:54:18 UTC |
Source: | CRAN |
A Function to Draw Histograms and Restricted Cubic Splines (RCS)
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. |
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.
a picture
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")
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")
A Function to Draw Histograms and Restricted Cubic Splines (RCS)
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. |
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.
a picture
Generate the predicted data for the function. This is needed for drawing.
predata(fit, variables, y, group = NULL)
predata(fit, variables, y, group = NULL)
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Data required for plotting.
Generate the predicted data for the function. This is needed for drawing.
## S3 method for class 'coxph' predata(fit, variables, y, group = NULL)
## S3 method for class 'coxph' predata(fit, variables, y, group = NULL)
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Data required for plotting.
Generate the predicted data for the function. This is needed for drawing.
## S3 method for class 'lrm' predata(fit, variables, y, group = NULL)
## S3 method for class 'lrm' predata(fit, variables, y, group = NULL)
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Data required for plotting.
Generate the predicted data for the function. This is needed for drawing.
## S3 method for class 'ols' predata(fit, variables, y, group = NULL)
## S3 method for class 'ols' predata(fit, variables, y, group = NULL)
fit |
Model function required for prediction. |
variables |
variable name. |
y |
the value of the variable. |
group |
Variables that need to be grouped. |
Data required for plotting.
A Function to Draw Restricted Cubic Splines (RCS)
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. |
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.
a picture
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")
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.
data(smoke)
data(smoke)
An object of class data.frame
with 995 rows and 5 columns.
data(smoke)
data(smoke)