# Install packages
if (!requireNamespace("rms", quietly = TRUE)) {
install.packages("rms")
}if (!requireNamespace("ggplotify", quietly = TRUE)) {
install.packages("ggplotify")
}
# Load packages
library(rms)
library(ggplotify)
Nomogram (Logistic)
Note
Hiplot website
This page is the tutorial for source code version of the Hiplot Nomogram (Logistic)
plugin. You can also use the Hiplot website to achieve no code ploting. For more information please see the following link:
Setup
System Requirements: Cross-platform (Linux/MacOS/Windows)
Programming language: R
Dependent packages:
rms
;ggplotify
Data Preparation
# Load data
<- read.delim("files/Hiplot/130-nomogram-logistic-data.txt", header = T)
data
# Convert data structure
<- datadist(data)
dd options(datadist = "dd")
## Build Logistic model and run nomogram
<- lrm(data=data, as.formula(paste(
logistic_res colnames(data)[1], " ~ ",
paste(colnames(data)[2:length(colnames(data))],
collapse = "+"
)
))
)<- nomogram(logistic_res, maxscale = 100,
logistic_nomo fun= function(x)1/(1+exp(-x)), lp=F, funlabel="Dead Risk",
fun.at=c(.001,.01,.05,seq(.1,.9,by=.1),.95,.99,.999)
)
# View data
head(data)
status age sex ph.ecog ph.karno pat.karno meal.cal wt.loss
1 2 74 1 1 90 100 1175 NA
2 2 68 1 0 90 90 1225 15
3 1 56 1 0 90 90 NA 15
4 2 57 1 1 90 60 1150 11
5 2 60 1 0 100 90 NA 0
6 1 74 1 1 50 80 513 0
Visualization
# Nomogram (Logistic)
<- as.ggplot(function() {
p plot(logistic_nomo,
scale = 1
)title(main = "Nomogram (Logistic)")
})
p
