prob_cal: Calculate Probabilities

Description Usage Arguments Value Examples

View source: R/prob_cal.R

Description

Use Survival() function from 'rms' pacakge to calculate probabilities after lrm(), cph() or psm() regression. If you want to calculate lrm() probabilities, please leave linear.predictors be TRUE and times be missing. If you want to calculate cph() probabilites, please leave both linear.predictors and surv be TRUE.

Usage

1
prob_cal(reg, times, q, lp)

Arguments

reg

regression results after lrm(), cph() or psm() in 'rms' package.

times

if you want to calculate probabilities for lrm() function, please left times missing.

q

quantile, for example 0.5

lp

linear predictors

Value

lieaner predictors and probabilities as a dataframe

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
set.seed(2018)
n <-2019
age <- rnorm(n,60,20)
sex <- factor(sample(c('female','male'),n,TRUE))
sex <- as.numeric(sex)
weight <- sample(50:100,n,replace = TRUE)
time <- sample(50:800,n,replace = TRUE)
units(time)="day"
death <- sample(c(1,0,0),n,replace = TRUE)
df <- data.frame(time,death,age,sex,weight)

library(rms) #needed for lrm(), cph() and psm()
ddist <- datadist(df)
oldoption <- options(datadist='ddist')

# lrm() function
f <- lrm(death~sex+age+weight,data=df,
         linear.predictors = TRUE)
head(prob_cal(reg = f))

# cph() function
f <- cph(Surv(time,death)~sex+age+weight,data=df,
         linear.predictors=TRUE,surv=TRUE)
head(prob_cal(reg = f,times = c(365,365*2)))

# psm() function
f <- psm(Surv(time,death)~sex+age+weight,data=df)
head(prob_cal(reg = f,times = c(365,365*2)))

nomogramFormula documentation built on Jan. 28, 2020, 5:07 p.m.