Description Usage Arguments Details Note Author(s) References See Also Examples
Display a graph explaining how the risk prediction for a new observation is obtained from the risk prediction model. All contributions are added in a cumulative way to end up with the linear predictor that is transformed into a risk estimate.
1 2 |
x |
|
obs |
A data.frame containing the predictor values of the observation for which the chart should be made. |
filename |
The name of the resulting file (default: ccchart). |
zerolevel |
The value of the contributions that should be put to zero. If "zero", the contributions are represented as they are. If "min", for each predictor or set of predictors contributing to an interaction, the minimal observed value of the contribution in the training data is substracted from the contribution to ensure that the contribution is always positive. If "median" or "mean", the median or mean value is substracted from the contributions, respectively (default="zero"). See below for more details. |
risklabel |
A character string representing the label for the represented risk. For multinomial logistic regression models, a vector of risk labels should be provided. See the examples for an illustration of the approach. |
riskcutoff |
A value between 0 and 1, indicating the change in color for the represented score and risk bars (default: 0.1). A risk lower than the riskcutoff is visualized in green, a risk higher than the riskcutoff is visualized in red. |
type |
A string specifying the type of plot: "logistic" for logistic regression models, and "survival" for cox proportional hazard models. This should generally not be provided by the user. |
sorted |
logical. If TRUE the contributions are sorted in increasing order (default=FALSE). |
time |
The time at which the estimated survival should be calculated. As default, the estimated survival at median survival time is reported. If the median
survival time can not be calculated, the estimated survival at the latest event time is reported. For objects that are not a member of the |
xmin |
Minimal values of input variables to be represented on the visualization. These values only have an influence on continuous input variables. |
xmax |
Maximal values of input variables to be represented on the visualization. These values only have an influence on continuous input variables. |
The cumulative contribution chart constitutes from different bars, representing the contribution of the predictors to the
score (translated linear predictor) in a cumulative way. Depending on the value of zerolevel
, the visualized contributions are slightly different.
If zerolevel
="zero", the contribution for variable x^p is β_pf_p(x^p), with β_p the model
coefficient corresponding to this predictor and f_p(x^p) a (possible) transformation of x^p. If zerolevel
is "min", "median" or "mean", a value equal to
the minimum, median and mean of the contribution β_pf_p(x^p) in the training data, respectively, is substracted from the contribution. See the references for more information.
At the bottom of the chart, the score (i.e. the translated linear predictor or latant variable) of this observation is reported next to the maximal score observed in the training
data. The risk corresponding to both of these scores are represented as well. Risk predictions above the riskcutoff result in red
bars, risk predictions below this cutoff result in green bars.
This graph can not be used for cox proportional hazard regression including strata.
For coxph
models, it is necessary to include model=TRUE
in the model fit.
For multinom
models, it is necessary to include model=TRUE
in the model fit.
For multinom
models, more than one output file is generated. A first series of plots visualizes how the linear predictors are obtained. The files
are named "filename_outcome_level_cchart", with "outcome_level" the name of the outcome level for which the linear predictor is visualized. A second series of plots
visualizes how the linear predictors are transformed into a risk prediction for each outcome level. The files are named "filename_p_outcome_level_cchart".
For multinom
models, a vector of risk labels needs to be made and provided to the ccchart()
function. See the examples for an illustration of the approach.
For ksvm
models, it is necessary to include prob.model=TRUE
in the model fit.
The plot is not shown in a graphical window but saved in the current working directory.
Vanya Van Belle
Van Belle V., Van Calster B., Visualizing risk prediction models, PLoS ONE, 10(7):e0132614. doi:10.1371/journal.pone.0132614 (2015).
Van Belle V., Van Calster B., Suykens J.A.K., Van Huffel S. and Lisboa P., Explaining support vector machines: a color based nomogram, Internal Report 16-27, ESAT-Stadius, KU Leuven (Leuven, Belgium), 2016
Van Belle V., Van Huffel S., Timmerman D., Froyman W., Bourne T. and Van Calster B., A color based nomogram for Multinomial Logistic Regression, Internal Report 16-28, ESAT-Stadius, KU Leuven (Leuven, Belgium), 2016
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #### logistic regression
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
mydata$rank <- factor(mydata$rank)
fit <- glm(admit ~ gre + gpa + rank, data = mydata, family = "binomial")
patient1=data.frame(gre=386,gpa=3.58,rank=3)
ccchart(fit,obs=patient1,filename="ccchart1")
#### cox proportional hazard regression
library(mfp)
data(GBSG)
fit<-coxph(Surv(rfst, cens) ~ age+tumsize+posnodal+prm+esm+menostat+tumgrad, data = GBSG,
model=TRUE)
patient1=data.frame(age=52,tumsize=45,posnodal=23,prm=1025,esm=562,menostat=2,tumgrad=3)
ccchart(fit,patient1,time=500,filename="ccchart2")
#### multinomial logistic regression model
library(nnet)
library(VGAMdata)
data(xs.nz)
marital.nz <- xs.nz[,c("marital","sex","age","height","weight")]
mydata <- marital.nz[complete.cases(marital.nz),]
fit <- multinom(marital ~ sex + age + height + weight, data = mydata,model=TRUE)
# for multinimial logistic regression, a vector of risk labels needs to be made
# and provided to the colplot function
outnames=colnames(fitted(fit))
labels=c(paste("Linear predictor for",outnames[-1]),paste
("Predicted chance of being",outnames))
patient1=data.frame(sex="F",age=27,height=1.68,weight=58.6)
ccchart(fit,obs=patient1,filename="multinom_ccchart",risklabel=labels,zerolevel="zero")
#### Support Vector Machine classifier
## Not run:
library(kernlab)
data(iris)
levels(iris$Species)[levels(iris$Species)=="setosa"] <- "other"
levels(iris$Species)[levels(iris$Species)=="virginica"] <- "other"
names(iris)=c("SL","SW","PL","PW","Species")
set.seed(100)
model <-ksvm(Species ~ ., data = iris,prob.model=TRUE,kpar=list(0.03),C=10)
obs1=data.frame(SL=5.2,SW=3.0,PL=1.5,PW=0.3)
# The plot should be based on all training data, so the following code should be used:
newmodel=preplotperf(model,iris,indy=5,zerolevel="min")
ccchart(newmodel,obs=obs1,filename="iris_ccchart",risklabel="Chance on versicolor",
zerolevel="median")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.