Generating Dynamic Nomograms using DynNom

Interested in publishing a one-time post on R-bloggers.com? Press here to learn how.

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.

 

 

Published by

Jaynal Abedin

I am a Ph.D. student at Unit for Biomedical Data Analytics (BDA) of INSIGHT at the National University of Ireland Galway. My research work is focused on sports science and sports medicine area in a partnership project with ORRECO; an Irish start-up company that provides evidence-based advice to individual athletes through biomarker and GPS data. My goal is to develop a statistical model that will help ORRECO to provide individualized advice about training need of athletes based on their own biomarker profile and GPS records. Before joining at INSIGHT as a Ph.D. student I was leading a team of statisticians at an international public health research organization (icddr,b). My primary role there was to develop internal statistical capabilities for researchers who comes from various discipline. I was involved in designing and delivering statistical training to the researchers. I have a Bachelors and Masters in Statistics. During my masters, the thesis I was involved in empirically reviewing various machine learning algorithm and compare their performance. I have written two books in R programming “Data Manipulation with R” and “R Graphs Cookbook” (Second Edition). My current research interests are, 1) Predictive modeling to predict probable injury of an athlete, 2) Scoring extremeness of multivariate data to get an early signal of an anomaly.

2 thoughts on “Generating Dynamic Nomograms using DynNom”

  1. This is really cool. Appreciate the contribution to the community. I noticed that when I ran your code, I needed to library(plotly) before I could use the app. You might want to update your dependencies.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.