How can I find the expected value of a random variable using the Statistics Toolbox 7.0 (R2008b) given its distribution and a constraint?

23 ビュー (過去 30 日間)
I would like to find the expected value of a random variable given a distribution and a constraint. For example, given a normal distribution, what is the expected value of x with the constraint that x > 0.
The unconditional expected value would be x = 0.

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
MATLAB is an excellent tool for this type of calculation .
To calculate the expected value of x given x>0 and a normal distribution, you can use two methods. First, you can simulate the data set and then select the mean of only the values of x which satisfy the constraint. For example:
Generate some normal data, and compute the unconditional mean
x = randn(10000,1);
mean(x)
ans =
5.5206e-004
Compute the conditional mean by simulation. Generate data from the conditional distribution and take the mean.
mean(x(x>0))
ans =
0.7955
The second method is to use a numerical computation of the expected value over the conditional distribution. This conditional distribution has the normal pdf over the region above 0, scaled by 1 minus the cdf evaluated at 0. The integral should go to +Inf, but I know the probability is very small for high values so I stop at 10.
quadgk(@(x) x.*normpdf(x)./(1-normcdf(0)), 0, 10)
ans =
0.7979
The second method is extendable to many of the distributions that MATLAB supports.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by