Package 'ggrcs'

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

Help Index


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)