formula_lp: Explore the Formula of Total Points and Linear Predictors

Description Usage Arguments Value Examples

View source: R/formula_lp.R

Description

Explore the formula of total points and linear predictors by the best power.

Usage

1
formula_lp(nomogram, power, digits = 6)

Arguments

nomogram

results of nomogram() function in 'rms' package

power

power can be automatically selected based on all R2 equal 1

digits

default is 6

Value

formula is the formula of total points and linear predictors. test is the R2 and RMSE which are used to test the fitted points. diff is difference between nomogram points and fitted points

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
library(rms)  # needed for nomogram
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)
ddist <- datadist(df)
oldoption <- options(datadist='ddist')
f <- cph(formula(Surv(time,death)~sex+age+weight),data=df,
         x=TRUE,y=TRUE,surv=TRUE,time.inc=3)
surv <- Survival(f)
nomo <- nomogram(f,
                 lp=TRUE,
                 fun=list(function(x) surv(365,x),
                          function(x) surv(365*2,x)),
                 funlabel=c("1-Year Survival Prob",
                            "2-Year Survival Prob"))
options(oldoption)
formula_lp(nomogram = nomo)
formula_lp(nomogram = nomo,power = 1)
formula_lp(nomogram = nomo,power = 3,digits=6)

Example output

Loading required package: Hmisc
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package:HmiscThe following objects are masked frompackage:base:

    format.pval, units

Loading required package: SparseM

Attaching package:SparseMThe following object is masked frompackage:base:

    backsolve

$formula
                       b0      x^1
linear predictor 131.9182 821.7001

$test
                 R2 RMSE
linear predictor  1    0

$diff
              -0.2    -0.15     -0.1   -0.05        0     0.05      0.1
nomogram -32.42182 8.663185 49.74819 90.8332 131.9182 173.0032 214.0882
fit      -32.42182 8.663185 49.74819 90.8332 131.9182 173.0032 214.0882
diff       0.00000 0.000000  0.00000  0.0000   0.0000   0.0000   0.0000
             0.15
nomogram 255.1732
fit      255.1732
diff       0.0000

$formula
                       b0      x^1
linear predictor 131.9182 821.7001

$test
                 R2 RMSE
linear predictor  1    0

$diff
              -0.2    -0.15     -0.1   -0.05        0     0.05      0.1
nomogram -32.42182 8.663185 49.74819 90.8332 131.9182 173.0032 214.0882
fit      -32.42182 8.663185 49.74819 90.8332 131.9182 173.0032 214.0882
diff       0.00000 0.000000  0.00000  0.0000   0.0000   0.0000   0.0000
             0.15
nomogram 255.1732
fit      255.1732
diff       0.0000

$formula
                       b0      x^1 x^2 x^3
linear predictor 131.9182 821.7001   0   0

$test
                 R2 RMSE
linear predictor  1    0

$diff
              -0.2    -0.15     -0.1   -0.05        0     0.05      0.1
nomogram -32.42182 8.663185 49.74819 90.8332 131.9182 173.0032 214.0882
fit      -32.42182 8.663185 49.74819 90.8332 131.9182 173.0032 214.0882
diff       0.00000 0.000000  0.00000  0.0000   0.0000   0.0000   0.0000
             0.15
nomogram 255.1732
fit      255.1732
diff       0.0000

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