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

Python012

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

原文链接:http://tecdat.cn/?p=13033

介绍

布丰投针是几何概率领域中最古老的问题之一。它最早是在1777年提出的。它将针头掷到有平行线的纸上,并确定针和其中一条平行线相交的可能性。令人惊讶的结果是概率与pi的值直接相关。

R程序将根据上段所述的情况估算pi的值并使用gganimate进行动态可视化。

第1部分

对于A部分,我们创建一个数据帧,该数据帧将在3个不同的区间上生成随机值,这些区间将代表x,y的范围以及每个落针点的角度。这是一个易于实现的随机数情况,需要使用runif函数。此功能要求输入数量,后跟一个间隔。生成数字后,我们会将值保存到数据框中。

rneedle <- function(n) {

x = runif(n, 0, 5)

y = runif(n,0, 1)

angle = runif(n,-pi, pi) #从-180到180的角度

values<-data.frame(cbind(x, y, angle))

return(values)

}

values<-rneedle(50)

#检查是否生成50×3矩阵

values

#我们的数据帧已经成功生成。

         x           y      angle

1  4.45796267 0.312440618  1.3718465

2  3.43869230 0.462824677  2.9738367

3  2.55561523 0.596722445 -2.9638285

4  3.68098572 0.670877506 -0.6860502

5  0.03690118 0.202724803 -0.3315141

6  4.64979938 0.180091416 -0.3293093

7  4.92459238 0.172328845 -0.5221133

8  3.50660347 0.752147374  2.9100221

9  2.03787919 0.167897415 -0.3213833

10 0.38647133 0.539615776 -0.1188982

11 3.28149935 0.102886770 -1.6318256

12 3.68811892 0.765077533  1.2459037

13 1.52004894 0.682455494 -0.4219802

14 3.76151379 0.508555610  0.1082087

...

第2部分

我们绘制第一部分中的针。重要的是不要在这个问题上出现超过2条水平线。它使我们可以进行检查以了解此处描绘的几何特性的一般概念。话虽如此,让我们注意我们决定在每个方向上将图形扩展1个单位。原因是想象一个针尾从y = 1开始,其角度为pi / 2。我们需要假设该方向的范围最大为2。

plotneedle(values)

第3部分

在下面,将基于阅读布冯针和基本几何原理的知识,查看pi的估算值。

buffon(values)

第4部分

运行代码后,我们收到以下答案。

>buffon(X)

[1] 3.846154

set.seed(10312013)

X <- rneedle(50)

plotneedle(X)

buffon(X)

>buffon(X)

[1] 3.846154

第5部分

如前几节所述,当我们投掷更多的针头时,我们期望以最小的不确定性获得更准确的答案。从Approxpi函数运行代码后,我们收到了平均值= 3.172314和方差0.04751391的值。对于这样一个简单的实验,它对pi进行了很高的估计。

Approxpi(500)

mean(Approxpi(500))

var(Approxpi(500))

>mean(Approxpi(500))

[1] 3.172314

>var(Approxpi(500))

[1] 0.04751391

接下来对模拟次数从500~600的预测进行动态可视化,红色表示针投放到了直线上:

参考资料

Schroeder,L.(1974年)。布冯针问题:许多数学概念的激动人心的应用。

最受欢迎的见解

1.R语言动态图可视化:如何、创建具有精美动画的图

2.R语言生存分析可视化分析

3.Python数据可视化-seaborn Iris鸢尾花数据

4.r语言对布丰投针(蒲丰投针)实验进行模拟和动态

5.R语言生存分析数据分析可视化案例

6.r语言数据可视化分析案例:探索brfss数据数据分析

7.R语言动态可视化:制作历史全球平均温度的累积动态折线图动画gif视频图

8.R语言高维数据的主成分pca、 t-SNE算法降维与可视化分析案例报告

9.python主题LDA建模和t-SNE可视化

以下选自省心师兄昨天的公众号文章

————————

技巧篇06--R语言绘制全网爆火的动态条形图 (qq.com)

————————

install.packages("gifski")

install.packages("devtools")

library(devtools)

install_github("jl5000/barRacer")

library(barRacer)

library(magrittr)

library(ggplot2)

library(dplyr)

data <- read.csv("China_edited_data.csv")

names(data)[c(1,8)] <- c("Province","Date")

data Date)

data <- data[data$Province != "Hubei",] # 去掉湖北数据;

data Date,"-"),function(x) paste(paste(x[3],x[2],sep = "-"),x[1],sep = "-")))

data Date)

COVID19_Data <- data %>% group_by(Province,Date) %>%

summarise(n=sum(Confirmed))

bar_chart_race(COVID19_Data,

cat_col = Province,

val_col = n,

time_col = Date,

max_bars = 20,

duration = 30,

title = "China COVID19 Data")

gganimate::anim_save("COVID19_Data.gif")

————————

缺陷就是极大数与相差甚远的第二数没有类似于坐标轴的隔断。