Truncated mean for truncated gaussian distribution
Afficher commentaires plus anciens
Hello,
Is there any way to write the function
G(x) = int_{-inf}^{x} z * pdf(z) dz
where pdf(z) is a normal distribution with mean mu and std sigma (perhaps some way involving erf or erfc)? Note that G(inf) = mu.
Thanks in advance.
Ita
Réponses (1)
Tom Lane
le 27 Avr 2012
Consider using the Symbolic Toolbox, if you have it:
>> syms x z
>> pi = sym('pi');
>> zmean = int(x*exp(-x^2/2)/sqrt(2*pi),-Inf,z)/int(exp(-x^2/2)/sqrt(2*pi),-Inf,z)
zmean =
-2^(1/2)/(2*pi^(1/2)*exp(z^2/2)*(erf((2^(1/2)*z)/2)/2 + 1/2))
>> subs(zmean,1.5)
ans =
-0.1388
>> t = randn(1e6,1); mean(t(t<1.5))
ans =
-0.1376
>> t = randn(1e6,1); mean(t(t<1.5))
ans =
-0.1383
>> t = randn(1e6,1); mean(t(t<1.5))
ans =
-0.1399
Catégories
En savoir plus sur Matrix Computations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!