S******y 发帖数: 1123 | 1 How can I compute the area between my curve and diagonal line?
Thanks.
Is MCMC a good solution?
> x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1)
> y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1)
> plot(x,y,type='l')
> abline(0,1) | o****o 发帖数: 8077 | 2 man, you got 8 Ti Xing, and you know how to calculate Ti Xing area
x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1)
y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1)
plot(x,y,type='l')
abline(0,1)
xl<-length(x)
z<-1:(xl-1)
l<-x;
for (i in 1:(xl-1)){
d1<-l[i]-y[i]; d2<-l[i+1]-y[i+1]; h<-x[i+1]-x[i];
z[i]<-0.5*h*(d1+d2);
}
sum(z)
correct me if I am wrong
【在 S******y 的大作中提到】 : How can I compute the area between my curve and diagonal line? : Thanks. : Is MCMC a good solution? : > x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1) : > y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1) : > plot(x,y,type='l') : > abline(0,1)
| D******n 发帖数: 2836 | 3 ppl also use the zigzag version of AUC calculation too
【在 o****o 的大作中提到】 : man, you got 8 Ti Xing, and you know how to calculate Ti Xing area : x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1) : y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1) : plot(x,y,type='l') : abline(0,1) : xl<-length(x) : z<-1:(xl-1) : l<-x; : for (i in 1:(xl-1)){ : d1<-l[i]-y[i]; d2<-l[i+1]-y[i+1]; h<-x[i+1]-x[i];
| s*r 发帖数: 2757 | 4 应该尽量用vector操作
【在 o****o 的大作中提到】 : man, you got 8 Ti Xing, and you know how to calculate Ti Xing area : x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1) : y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1) : plot(x,y,type='l') : abline(0,1) : xl<-length(x) : z<-1:(xl-1) : l<-x; : for (i in 1:(xl-1)){ : d1<-l[i]-y[i]; d2<-l[i+1]-y[i+1]; h<-x[i+1]-x[i];
| S******y 发帖数: 1123 | 5 Thank both of you!
I just found out this code seems working too -
x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1)
y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1)
n <- length(x)
0.5 * abs(sum(x[-1] * y[-n]) - sum(x[-n] * y[-1]) ) | o****o 发帖数: 8077 | 6 就是想给个quick solution。vectorized的程序还没想好,实际问题已经解决了
【在 s*r 的大作中提到】 : 应该尽量用vector操作
| a********s 发帖数: 188 | 7 It is a simple case here. Using the quadrilateral idea to get the area is
quick. If you want the area for any one-dimensional function, you may use "
integrate" in R once you know the explicit function. But it is slow. | o****o 发帖数: 8077 | 8 这个不错
【在 S******y 的大作中提到】 : Thank both of you! : I just found out this code seems working too - : x<-c(0,0.2,0.4,0.6,.8,.9,.95,.99,1) : y<-c(0,0.1,0.15,0.3,0.7,.9,.94,.98,1) : n <- length(x) : 0.5 * abs(sum(x[-1] * y[-n]) - sum(x[-n] * y[-1]) )
| S******y 发帖数: 1123 | 9 Thanks oloolo!
How can I prove that my approch is equivalent to yours mathematically? | o****o 发帖数: 8077 | 10 呵呵,我不知道R可以用负值小标代表去掉这个元素,又学习了
这么算来,我的那个loopy可以写成这个向量表达式(满足sir一下)
(x[-n]-y[-n]+x[-1]-y[-1])*(x[-1]-x[-n])
全部展开,并且注意到你的x和y向量的首尾元素是一样的,这样
(x[n]^2-x[1]^2 )-(x[n]*y[n] - x[1]*y[1])=0
最后剩下的就是你那个命令了
【在 S******y 的大作中提到】 : Thanks oloolo! : How can I prove that my approch is equivalent to yours mathematically?
|
|