曲线下面积

时间:2014-10-11 23:19:23

标签: r auc

curve(-12 * log(x) - (415 / x), 25, 50)
abline(h = -55, lty = 2)

我想绘制曲线和实线之间的区域并将其遮蔽,但是无法做到。我尝试使用pracma包中的trapz函数。任何建议都会受到赞赏吗?

1 个答案:

答案 0 :(得分:1)

然后你可以使用polygon(),你基本上定义了足够点的x坐标和y坐标,使它看起来很平滑。我会去120:

ff <- function(x) -12 * log(x) - (415 / x)  ## define curve

# get a vector or potential x values for the polygon
x1 <- seq(from=25, to=50, length.out=120)
x1 <- x1[ff(x1) >= -55]  ## filter only relevant section

x2 <- rev(x1)    ## reverse the vector for the return trip
xx <- c(x1, x2)  ## concatenate to get all x coordinates
yy <- c(rep(-55, length(x1)), ff(x2))

curve(ff, 25, 50)
abline(h = -55, lty = 2)
# join the dots and fill the space orange
polygon(xx, yy, col='orange')

编辑:在整个程序中添加了代码以反映来自@epsilone的评论