我知道这有点棘手,但我希望你能为它做好准备。
给出两条正常曲线,我正在计算两条曲线平均值之间重叠的AUC。
首先,我计算两条曲线的截距的x值,如下所示:
gaussIsect = function(mu1,mu2,sd1,sd2){
sd12 = sd1**2
sd22 = sd2**2
sqdi = sd12-sd22
x1 = (mu2 * sd12 - sd2*( mu1*sd2 + sd1*sqrt( (mu1-mu2)**2 + 2*sqdi * log(sd1/sd2) ) )) / sqdi
x2 = (mu2 * sd12 - sd2*( mu1*sd2 - sd1*sqrt( (mu1-mu2)**2 + 2*sqdi * log(sd1/sd2) ) )) / sqdi
return(c(x1,x2))
}
然后我计算合并的AUC并找到x值,其中有一半:
gaussSplitOlap = function(mu1,mu2,sd1,sd2){
# Make sure that mu1 < mu2
if( mu1 > mu2 ){
tmp = c(mu1,mu2)
mu1 = tmp[2]
mu2 = tmp[1]
tmp = c(sd1,sd2)
sd1 = tmp[2]
sd2 = tmp[1]
}
# Get the intersect of the two normal curves
isct = gaussIsect(mu1=mu1,mu2=mu2,sd1=sd1,sd2=sd2)
# and make sure we have the intersect between the means
isct = isct[which(mu1 < isct & isct < mu2)]
# Calculate left curve AUC, i.e. from isct to inf
a1 = 1-pnorm(isct,mean=mu1,sd=sd1)
# Calculate right curve AUC, i.e. from -inf to isct
a2 = pnorm(isct,mean=mu2,sd=sd2)
# Calculate the total area
A = a1 + a2
# Calculate the left curve x-value, which halfes the total area
v1 = qnorm(1-A/2,mean=mu1,sd=sd1)
# Calculate the right curve x-value, which halfes the total area
v2 = qnorm(A/2,mean=mu2,sd=sd2)
# Create and return list of results
results = list(isct=isct,A=A,v1=v1,v2=v2)
return(results)
}
test = gaussSplitOlap(mu1 = 10,sd1 = 0.9,mu2 = 12,sd2 = 0.6)
print(test)
如果我运行这个,那么测试就是
$isct
[1] 11.09291
$A
[1] 0.1775984
$v1
[1] 11.21337
$v2
[1] 11.19109
我无法弄明白,为什么v1!= v2?在我看来,它是从两个不同的参考点计算的相同值?