绘制决策曲线decision curve analysis(DCA)

本文介绍决策曲线分析(DCA),一种评估预测模型临床价值的方法。DCA通过计算不同概率阈值下的净收益,对比全治疗或全不治疗策略,判断模型是否优于常规策略。文章提供R语言中决策曲线工具包的安装与使用教程,包括绘图参数详解及示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Decision curve analysis-DCA 论文

《Decision Curve Analysis: A Novel Method for Evaluating Prediction Models》

y轴是计算出的收益

x轴是取不同的概率Pt的值

通过不断变换Pt阈值,计算对应的收益值

横直线和点虚线分别为全手术or全不手术的时候对应的收益。如果绘制的DCA曲线高于这两条曲线,则模型是有价值的

 

绘制步骤

1. Chose a value for pt.
2. Calculate the number of true- and false-positive results using pt as the cut-point for determining a positive or negative result.
3. Calculate the net benefit of the prediction model.
4. Vary pt over an appropriate range and repeat steps 2 and 3.
5. Plot net benefit on the y-axis against pt on the x-axis.
6. Repeat steps 1 through 5 for each model under consideration.
7. Repeat steps 1 through 5 for the strategy of assuming all patients are positive.
8. Draw a straight line parallel to the x-axis at y = 0 representing the net benefit associated with the strategy of assuming that all patients are negative.

 

理想条件:

例子:

黑实线比较好 

 

 

R中安装决策曲线工具包

因为R版本问题decisionCurve工具包已经不能直接安装

原网页百度快照:

http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631047973545438014688c8d443f93db5f93130b015a23b4eb3a6043558a96293040b23f0bbbab77296a5f51f0db8cdf5786e7c47f659f27432a5ad91f069644ef9d4965d620e118bafe40b4efa72593df84848e0f12910e596d8180da1d40509d&p=8b2a971286cc4afd18fbd13416&newp=8b2a975986cc4afa01b9e62c5f53d83348029f3460c8914212d4984e98700d1a2a22b4fb66794d58dcc17b6c04ab4856eaf630723d072ab09ec88b4fc9fdff6978ca28632c4a9a&user=baidu&fm=sc&query=R+pacage+DecisionCurve&qid=d334a02600075234&p1=3

采用github安装

github说明页面 https://github.com/mdbrown/rmda

教程 https://mdbrown.github.io/rmda/

非常详细的步骤教学 还有画出来的图的展示

 

在r环境中输入如下语句进行安装

install.packages("rmda")

install.packages("devtools")

library(devtools) 

install_github("mdbrown/DecisionCurve")

 

查看帮助文档

help(decisionCurve)

example(decisionCurve)

 

Plot the net benefit curves from a decision_curve object or many decision_curve objects

Description

Plot the net benefit curves from a decision_curve object or many decision_curve objects

Usage

plot_decision_curve(x, curve.names, cost.benefit.axis = TRUE,
  n.cost.benefits = 6, cost.benefits, standardize = TRUE,
  confidence.intervals, col, lty, lwd = 2, xlim, ylim, xlab, ylab,
  cost.benefit.xlab, legend.position = c("topright", "right", "bottomright",
  "bottom", "bottomleft", "left", "topleft", "top", "none"), ...)
Arguments

x    
'decision_curve' object to plot or a list of 'decision_curve' objects. Assumes output from function 'decision_curve'
curve.names    
vector of names to use when plotting legends.
cost.benefit.axis    
logical (default TRUE) indicating whether to print an additional x-axis showing relative cost:benefit ratios in addition to risk thresholds.
n.cost.benefits    
number of cost:benefit ratios to print if cost.benefit.axis = TRUE (default n.cost.benefit = 6).
cost.benefits    
Character vector of the form c("c1:b1", "c2:b2", ..., "cn:bn") with integers ci, bi corresponding to specific cost:benefit ratios to print. Default allows the function to calculate these automatically.
standardize    
logical (default TRUE) indicating whether to use the standardized net benefit (NB/disease prevalence) or not.
confidence.intervals    
logical indicating whether to plot confidence intervals.
col    
vector of color names to be used in plotting corresponding to the 'predictors' given. Default colors will be chosen from rainbow(..., v = .8). See details for more information on plot parameters.
lty    
vector of linetypes.
lwd    
vector of linewidths.
xlim    
vector giving c(min, max) of x-axis. Defaults to c(min(thresholds), max(thresholds)).
ylim    
vector giving c(min, max) of y-axis.
xlab    
label of main x-axis.
ylab    
label of y-axis.
cost.benefit.xlab    
label of cost:benefit ratio axis.
legend.position    
character vector giving position of legend. Options are "topright" (default), "right", "bottomright", "bottom", "bottomleft", "left", "topleft", "top", or "none".
...    
other options directly send to plot()
Details

When k decision_curve objects are input, the first k elements of col, lty, lwd ... correspond to the curves provided. The next two elements (..., k+1, k+2) correspond to the attributes of the 'all' and 'none' curves. See below for an example.

Examples

data(dcaData)
set.seed(123)
baseline.model <- decision_curve(Cancer~Age + Female + Smokes,
                                data = dcaData,
                                thresholds = seq(0, .4, by = .005),
                                bootstraps = 10)

#plot using the defaults
plot_decision_curve(baseline.model,  curve.names = "baseline model")

set.seed(123)
full.model <- decision_curve(Cancer~Age + Female + Smokes + Marker1 + Marker2,
                            data = dcaData,
                            thresholds = seq(0, .4, by = .005),
                            bootstraps = 10)

# for lwd, the first two positions correspond to the decision curves, then 'all' and 'none'
plot_decision_curve( list(baseline.model, full.model),
                    curve.names = c("Baseline model", "Full model"),
                    col = c("blue", "red"),
                    lty = c(1,2),
                    lwd = c(3,2, 2, 1),
                    legend.position = "bottomright")


plot_decision_curve( list(baseline.model, full.model),
                    curve.names = c("Baseline model", "Full model"),
                    col = c("blue", "red"),
                    confidence.intervals = FALSE,  #remove confidence intervals
                    cost.benefit.axis = FALSE, #remove cost benefit axis
                    legend.position = "none") #remove the legend

#Set specific cost:benefit ratios.

plot_decision_curve( list(baseline.model, full.model),
                    curve.names = c("Baseline model", "Full model"),
                    col = c("blue", "red"),
                    cost.benefits = c("1:1000", "1:4", "1:9", "2:3", "1:3"),
                    legend.position = "bottomright")

#Plot net benefit instead of standardize net benefit.

plot_decision_curve( list(baseline.model, full.model),
                    curve.names = c("Baseline model", "Full model"),
                    col = c("blue", "red"),
                    ylim = c(-0.05, 0.15), #set ylim
                    lty = c(2,1),
                    standardize = FALSE, #plot Net benefit instead of standardized net benefit
                   legend.position = "topright")

 

### 回答1: 您好!关于怎样绘制结局为四分类的Decision Curve Analysis,以下是示例代码,仅供参考: ``` r #1. 安装必要的包 install.packages("dca.R") #2. 加载数据并分为测试集和训练集 library(dca.R) data(heart) heart$train <- sample(1:nrow(heart), replace = TRUE) #3. 训练模型并预测测试集 heart_model <- glm(chd~., data = heart[heart$train, ], family = binomial) heart_pred <- predict(heart_model, heart[-heart$train, ], type = "response") #4. 绘制Decision Curve Analysis library(pROC) roc_data <- roc(heart$chd[-heart$train], heart_pred, levels = rev(levels(as.factor(heart$chd)))) plot.roc(roc_data, print.auc = TRUE, ci = TRUE, main = "四分类 Decision Curve Analysis") ``` 以上是一个简单的R代码示例,用于绘制结局为四分类的Decision Curve Analysis。希望对您有帮助!如果您还有其他问题,请随时提出。 ### 回答2: Decision Curve AnalysisDCA)是一种统计方法,用于评估预测模型在不同阈值下的临床决策价值。当结局变量有四个可能结果时,可以使用DCA来评估模型的性能。 以下是使用R语言绘制结局为四分类的DCA的示例代码: ```R # 安装并加载所需的包 install.packages("DCA") library(DCA) # 假设已有一组真实值和预测概率 true_values <- c(1, 0, 2, 3, 1, 2, 3) predicted_probabilities <- c(0.2, 0.6, 0.3, 0.7, 0.4, 0.8, 0.9) # 创建一个数据框 data <- data.frame(TRUE_OUTCOME = true_values, PREDICTED_PROB = predicted_probabilities) # 运行DCA分析 dca_results <- dca(data = data) # 绘制DCA曲线 plot(dca_results) # 添加标题和标签 title("Decision Curve Analysis") ``` 在上面的示例中,首先安装并加载了`DCA`包。然后,创建一个包含真实值和预测概率的数据框。使用`dca`函数运行DCA分析,并将结果存储在`dca_results`变量中。最后,使用`plot`函数绘制DCA曲线,并使用`title`函数添加标题。 请注意,以上只是一个简单的示例代码,实际应用中可能需要根据具体数据和研究问题进行相应的调整。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值