Matlab中的逆铣削比 [英] Inverse Mills Ratio in Matlab
问题描述
我正在尝试在Matlab中对以下形式的条件期望进行编程:
I am trying to program in Matlab a conditional expectation of the form:
E [x | A< = x< = B]其中X〜N(u,s ^ 2)(对不起,显然这里的数学编辑不是我所习惯的)
E[x|A<=x<=B] where X~N(u,s^2) (sorry, apparently the math editing here isn't what I am used to)
在Matlab中,我编写了以下代码:
In Matlab, I have written up the following code:
Y=u+s*(normpdf(A,u,s)-normpdf(B,u,s))/(normcdf(B,u,s)-normcdf(A,u,s))
问题在于它会在较高的A和B值处分解.例如,让u = 0,s = 1,A = 10和B = 11.简单的逻辑说答案应该在10到11之间,但Matlab却给了我Inf,因为分母在分子为10 ^ -23时实际上变为0.
the problem is that it breaks down at higher values of A and B. For example, let u=0, s=1, A=10 and B=11. Simple logic says the answer should be between 10 and 11, but Matlab gives me back Inf because the denominator essentially becomes 0 while the numerator is 10^-23.
有什么建议可以让公式为所有输入提供实数?
Any suggestions to make the formula give real numbers for all inputs?
推荐答案
一种方法是自己进行数值积分:
One way is to do the numerical integration yourself:
x = linspace(A,B,1000);
trapz(x,x.*normpdf(x,u,s)) / trapz(x,normpdf(x,u,s))
使用您的示例值,得出的结果为10.0981,并且非常快
With your example values, this gives 10.0981, and it is pretty fast
这篇关于Matlab中的逆铣削比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!