Generating Dynamic Nomograms using DynNom

April 17, 2017
By

(This article was first published on R-posts.com, and kindly contributed to R-bloggers)

Nomograms are useful computational tools for model visualisation, graphical assessment of variable importance and the calculation of predicted values.  The nomogram function in the rms package is a popular way of creating (static) nomograms for a variety of regression models. For example, the following code will generate a nomogram from a logistic regression model used to model the probability of survival on the titanic (http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic.html)

library(PASWR)

data(titanic3)

library("rms")

t.data <- datadist(titanic3)

options(datadist = 't.data')

fit <- lrm(formula = survived ~ age + pclass + sex, data = titanic3)

plot(nomogram(fit, fun = function(x)plogis(x)))

C:\Users\Amir\Dropbox\Projects\thesis\DynNom paper\RBlogger\static nomogram.jpeg

This nomogram is a graphical calculator of the probability of surviving the Titanic, based on three explanatory variables, sex, age and passenger class.  The nomogram can become more cumbersome to read and use when higher order interaction terms and smoothers are present in the model. For example, consider the following nomogram of the model containing all possible interactions of the three main effects.

The DynNom package (Jalali, A, Newell, J), built on shiny, allows the creation of dynamic nomograms from any Generalised Linear models or Cox Proportional hazards models.  DynNom supports model objects created by the lm, glm and coxph functions. It also supports models generated using the Ols, Glm, lrm and cph in the rms package which allows the inclusion of smoothing splines. For example, the following R code will build a dynamic nomogram for the corresponding higher order logistic regression model using the DynNom package.

fit2 <- glm(survived ~ (age + pclass + sex) ^ 3, titanic3, family = "binomial")
library(DynNom)
DynNom(fit2, titanic3)

The resulting dynamic nomogram allows the prediction of the probability of survival (and corresponding 95% Confidence interval) for any chosen set of values of the explanatory variables.  The shiny tabs display the corresponding predicted values graphically and numerically and the underlying model summary.

 

C:\Users\Amir\Dropbox\Projects\thesis\DynNom paper\RBlogger\DynNom-titanic.jpg

The ability to interact with a model, in terms of the effect of changes in the explanatory variables on the predicted response, is a useful translational tool.  In theory all published model summaries could be accompanied with a hyperlink directing the reader to the corresponding model nomogram.  In order to do this the DNbuilder function within DynNom will generate the necessary ui.R, server.R and global.r files needed to share the nomogram online in any server (e.g.  http://shinyapps.io).

For example, the dynamic nomogram created for the titanic dataset, published using the DNbuilder function, is available at https://amir.shinyapps.io/titanic.

 

 

To leave a comment for the author, please follow the link and comment on their blog: R-posts.com.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)