R语言基于DynNom包绘制动态列线图

Python017

R语言基于DynNom包绘制动态列线图,第1张

以下为该包的帮助文件内容

Dynamic nomogram to visualise statistical models

Description

DynNom is a generic function to display the results of statistical model objects as a dynamic nomogram in an 'RStudio' panel or web browser. DynNom supports a large number of model objects from a variety of packages.

Usage

DynNom(model, data = NULL, clevel = 0.95, m.summary = c("raw", "formatted"),

covariate = c("slider", "numeric"), ptype = c("st", "1-st"),

DNtitle = NULL, DNxlab = NULL, DNylab = NULL, DNlimits = NULL,

KMtitle = NULL, KMxlab = NULL, KMylab = NULL)

DynNom.core(model, data, clevel, m.summary, covariate, DNtitle, DNxlab, DNylab, DNlimits)

DynNom.surv(model, data, clevel, m.summary, covariate,

ptype, DNtitle, DNxlab, DNylab, KMtitle, KMxlab, KMylab)

Arguments

model

an lm, glm, coxph, ols, Glm, lrm, cph, mgcv::gam or gam::gam model objects.

data

a dataframe of the accompanying dataset for the model (if required).

clevel

a confidence level for constructing the confidence interval. If not specified, a 95% level will be used.

m.summary

an option to choose the type of the model output represented in the 'Summary Model' tab. "raw" (the default) returns an unformatted summary of the model"formatted" returns a formatted table of the model summary using stargazer package.

covariate

an option to choose the type of input control widgets used for numeric values. "slider" (the default) picks out sliderInput"numeric" picks out numericInput.

ptype

an option for coxph or cph model objects to choose the type of plot which displays in "Survival plot" tab. "st" (the default) returns plot of estimated survivor probability (S(t)). "1-st" returns plot of estimated failure probability (1-S(t)).

DNtitle

a character vector used as the app's title. If not specified, "Dynamic Nomogram" will be used.

DNxlab

a character vector used as the title for the x-axis in "Graphical Summary" tab. If not specified, "Probability" will be used for logistic model and Cox proportional model objectsor "Response variable" for other model objects.

DNylab

a character vector used as the title for the y-axis in "Graphical Summary" tab (default is NULL).

DNlimits

a vector of 2 numeric values used to set x-axis limits in "Graphical Summary" tab. Note: This also removes the 'Set x-axis ranges' widget in the sidebar panel.

KMtitle

a character vector used as KM plot's title in "Survival plot" tab. If not specified, "Estimated Survival Probability" for ptype = "st" and "Estimated Probability" for ptype = "1-st" will be used.

KMxlab

a character vector used as the title for the x-axis in "Survival plot" tab. If not specified, "Follow Up Time" will be used.

KMylab

a character vector used as the title for the y-axis in "Survival plot" tab. If not specified, "S(t)" for ptype = "st" and "F(t)" for ptype = "1-st" will be used.

Value

A dynamic nomogram in a shiny application providing individual predictions which can be used as a model visualisation or decision-making tools.

The individual predictions with a relative confidence interval are calculated using the predict function, displaying either graphically as an interactive plot in the Graphical Summary tab or a table in the Numerical Summary tab. A table of model output is also available in the Model Summary tab. In the case of the Cox proportional hazards model, an estimated survivor/failure function will be additionally displayed in a new tab.

Please cite as:

Jalali, A., Roshan, D., Alvarez-Iglesias, A., Newell, J. (2019). Visualising statistical models using dynamic nomograms. R package version 5.0.

Author(s)

Amirhossein Jalali, Davood Roshan, Alberto Alvarez-Iglesias, John Newell

Maintainer: Amirhossein Jalali [email protected]

References

Banks, J. 2006. Nomograms. Encyclopedia of Statistical Sciences. 8.

Easy web applications in R. http://shiny.rstudio.com

Frank E Harrell Jr (2017). rms: Regression Modeling Strategies. R package version 4.5-0. https://CRAN.R-project.org/package=rms

See Also

DNbuilder, getpred.DN

rm(list=ls())##清除之前数据

library(rms)  ###加载rms包#

library(foreign)

library(survival)

library(rmda)

##install.packages("DynNom")

library(DynNom)

setwd("C://Users//zhanglingyu//Desktop//测试")  #设置工作目录

rt<- read.table('测试.txt',header=T,sep="\t")

head(rt)  #查看前5行的数据

str(rt)

##接着对所有变量数据进行打包

ddist <- datadist(rt)  #将数据打包

options(datadist='ddist')

model1<- lrm(rt$fustat ~ Age+Gender+Tau+EMPG+Glu+HCY+VB12+ALB, data =  rt)

summary(model1)

par(mgp=c(1.6,0.6,0),mar=c(2,2,2,2))  ##设置画布

nomogram <- nomogram(model1,fun=function(x)1/(1+exp(-x)), ##逻辑回归计算公式

                    fun.at = c(0.001,0.01,0.05,seq(0.1,0.9,by=0.1),0.95,0.99,0.999),#风险轴刻度

                    funlabel = "Risk of Alzheimer Disease", #风险轴便签

                    lp=T,  ##是否显示系数轴

                    conf.int = F, ##每个得分的置信度区间,用横线表示,横线越长置信度越

                    abbrev = F#是否用简称代表因子变量

)

plot(nomogram,

    #1.变量与图形的占比

    xfrac=.35,

    #2.变量字体加粗

    cex.var=1,

    #3.数轴:字体的大小

    cex.axis=0.8,

    #4.数轴:刻度的长度

    tcl=-0.5,

    #5.数轴:文字与刻度的距离

    lmgp=0.3,

    #6.数轴:刻度下的文字,1=连续显示,2=隔一个显示一个

    label.every=1,

    #7.1个页面有几个数轴(这个可以压缩行间距)

    naxes=13,

    #8.垂直线的颜色.

    col.grid=gray(c(0.8, 0.95)),

    #9.线性预测轴名字

    lplabel="Linear Predictorlp",

    #10变量分数名字

    points.label='Points',

    #11总分名字

    total.points.label='Total Points',

    force.label=F#没啥用TRUE强制标记的每个刻度线都绘制标签,我也没研究明白

)

#运行以展示Nomogram每个变量的分数

model1

##生成改良诺模图

plot(nomogram,col.grid = c("Tomato2","DodgerBlue"))