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

40 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 27 Jun. 2009
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.

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by