搜索以查找覆盖曲线下95%面积的两个数字 [英] Search to find two numbers that cover 95% of the area under a curve

查看:198
本文介绍了搜索以查找覆盖曲线下95%面积的两个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两列数字(列 dd )和列 strong> yy ,请参阅下面的链接以访问此数据)。当我针对 yy Y轴)绘制dd X轴)时, :

plot(dd,yy,ty =l,xlab =dd,ylab =yy,lwd = 2, xaxs =i)



我得到这个:



编码问题:

移动从 - Inf改为0 u ,直到其他点覆盖此曲线下面积的95%? 换句话说,如果箭头覆盖此曲线下方95%的面积,我们希望看到与两个箭头指示符对应的两个数字



以下是 R代码,可轻松将这些小数据导入您的Rstudio:

  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


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:

plot(dd, yy, ty="l", xlab = "dd", ylab ="yy", lwd=2, xaxs="i")

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:

id <- "0B5V8AyEFBTmXM1VIYUYxSG5tSjQ"

Data <- read.csv(paste0("https://docs.google.com/uc?id=",id,"&export=download")) 

解决方案

Edit: My previous approximation was not very accurate. It turns out the 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

这篇关于搜索以查找覆盖曲线下95%面积的两个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆