Convert rms::validate into a data.frame
as_df.validate.RdConverts an rms::validate object into a data.frame.
Arguments
- x
An
rms::validateobject.- auc
TRUEorFALSE. IfTRUE(default) will convert Dxy values, when present, into AUC.- keep
A character vector of statistics to keep.
See also
rms::validate
Examples
#----------------------------------------------------------------------------
# as_df.validate() examples
#----------------------------------------------------------------------------
library(bkstat)
library(rms)
n <- 1000 # define sample size
age <- rnorm(n, 50, 10)
blood.pressure <- rnorm(n, 120, 15)
cholesterol <- rnorm(n, 200, 25)
sex <- factor(sample(c('female','male'), n,TRUE))
# Specify population model for log odds that Y=1
L <- .4*(sex=='male') + .045*(age-50) +
(log(cholesterol - 10)-5.2)*(-2*(sex=='female') + 2*(sex=='male'))
# Simulate binary y to have Prob(y=1) = 1/[1+exp(-L)]
y <- ifelse(runif(n) < plogis(L), 1, 0)
f <- rms::lrm(y ~ sex*rms::rcs(cholesterol)+rms::pol(age,2)+blood.pressure, x=TRUE, y=TRUE)
#> number of knots in rcs defaulting to 5
# Validate full model fit
res <- rms::validate(f, B=10)
res
#> index.orig training test optimism index.corrected Lower Upper n
#> Dxy 0.3271 0.3580 0.3119 0.0461 0.2810 0.2170 0.3429 10
#> R2 0.1126 0.1365 0.1014 0.0351 0.0775 0.0315 0.1233 10
#> Intercept 0.0000 0.0000 0.0003 -0.0003 0.0003 -0.0874 0.1265 10
#> Slope 1.0000 1.0000 0.8379 0.1621 0.8379 0.6268 1.0741 10
#> Emax 0.0000 0.0000 0.0463 -0.0463 0.0463 -0.0149 0.1062 10
#> D 0.0871 0.1070 0.0780 0.0290 0.0581 0.0196 0.0963 10
#> U -0.0020 -0.0020 0.0024 -0.0044 0.0024 -0.0051 0.0169 10
#> Q 0.0891 0.1090 0.0756 0.0334 0.0557 0.0065 0.1015 10
#> B 0.2283 0.2237 0.2311 -0.0074 0.2357 0.2256 0.2473 10
#> g 0.7202 0.8090 0.6762 0.1328 0.5874 0.4151 0.7591 10
#> gp 0.1657 0.1814 0.1564 0.0250 0.1408 0.1101 0.1725 10
# Convert object into a data.frame
as_df.validate(res)
#> statistic index.orig training test optimism index.corrected
#> 1 Dxy 0.32713997 0.3580356 0.3119288606 0.0461067274 0.2810332379
#> 2 ROC-AUC 0.66356998 0.6790178 0.6559644303 0.0230533637 0.6405166189
#> 3 R2 0.11256819 0.1365119 0.1014108409 0.0351010345 0.0774671564
#> 4 Intercept 0.00000000 0.0000000 0.0003229044 -0.0003229044 0.0003229044
#> 5 Slope 1.00000000 1.0000000 0.8379485535 0.1620514465 0.8379485535
#> 6 Emax 0.00000000 0.0000000 0.0463140735 -0.0463140735 0.0463140735
#> 7 D 0.08707801 0.1070143 0.0779984823 0.0290158190 0.0580621897
#> 8 U -0.00200000 -0.0020000 0.0023923681 -0.0043923681 0.0023923681
#> 9 Q 0.08907801 0.1090143 0.0756061142 0.0334081871 0.0556698216
#> 10 B 0.22825151 0.2236769 0.2311104096 -0.0074334712 0.2356849842
#> 11 g 0.72022722 0.8090024 0.6761877353 0.1328147039 0.5874125116
#> 12 gp 0.16573068 0.1814135 0.1564368911 0.0249766355 0.1407540470
#> Lower Upper n
#> 1 0.216987550 0.34292087 10
#> 2 NA NA 10
#> 3 0.031544978 0.12334814 10
#> 4 -0.087437255 0.12651801 10
#> 5 0.626837070 1.07407081 10
#> 6 -0.014926403 0.10622260 10
#> 7 0.019573003 0.09632931 10
#> 8 -0.005070680 0.01691517 10
#> 9 0.006451399 0.10147228 10
#> 10 0.225600651 0.24731880 10
#> 11 0.415113459 0.75906415 10
#> 12 0.110106064 0.17250837 10