搜索以查找覆盖曲线下95%面积的两个数字 [英] Search to find two numbers that cover 95% of the area under a curve
问题描述
plot(dd,yy,ty =l,xlab =dd,ylab =yy,lwd = 2, xaxs =i)
我得到这个:
编码问题: 移动从 - Inf改为0 u ,直到其他点覆盖此曲线下面积的95%? 换句话说,如果箭头覆盖此曲线下方95%的面积,我们希望看到与两个箭头指示符对应的两个数字? 以下是 R代码,可轻松将这些小数据导入您的Rstudio: 编辑:我以前的近似值不是很准确。事实证明, Background: I have two columns of numbers (column "dd", and column "yy", see below to access this data). When I plot "dd" (X-axis) against "yy" (Y-axis), using: I get this: Coding question: Moving from "-Inf" to "0" up until what other point covers 95% of the area under this curve? In other words, we want to see the two numbers that correspond to the two ARROW HEADS TIPS if the arrow is to cover 95% of the area under this curve? Here is the R code to easily import this small data into your Rstudio:
Edit: My previous approximation was not very accurate. It turns out the
这篇关于搜索以查找覆盖曲线下95%面积的两个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
id< - 0B5V8AyEFBTmXM1VIYUYxSG5tSjQ
Data< - read.csv(paste0(https://docs.google.com/uc?id =,id,& export = download))
pracma
包有一个函数, cumtrapz
,它接近梯形积分并输出每个点的和从左边开始。使用该函数可以给出更准确的答案。
library(pracma)
points< - read.csv(paste0 (https://docs.google.com/uc?id=\",id,\"&export=download))
区域< - cumtrapz(积分$ dd,积分$ yy)
ind < - rev(其中(面积[面积(面积)] - 面积> 0.95))[1]
点< - 点数$ dd [ind]
point
#[1] -0.06406406
plot(dd, yy, ty="l", xlab = "dd", ylab ="yy", lwd=2, xaxs="i")
id <- "0B5V8AyEFBTmXM1VIYUYxSG5tSjQ"
Data <- read.csv(paste0("https://docs.google.com/uc?id=",id,"&export=download"))
pracma
package has a function, cumtrapz
, which approximates integrals with trapezoids and outputs the sum at each point starting from the left. Using that function gives a more accurate answer.library(pracma)
points <- read.csv(paste0("https://docs.google.com/uc?id=",id,"&export=download"))
area <- cumtrapz(points$dd, points$yy)
ind <- rev(which(area[length(area)] - area > .95))[1]
point <- points$dd[ind]
point
# [1] -0.06406406