MATLAB Answers

Ita Atz
0

Truncated mean for truncated gaussian distribution

Asked by Ita Atz
on 26 Apr 2012
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

  0 Comments

Sign in to comment.

1 Answer

Answer by Tom Lane
on 27 Apr 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

  0 Comments

Sign in to comment.