Your second expression evaluates a mathematical "expectation".
In other words, you are calculating, through Monte Carlo simulation, the
expectation of the random variable X*1(X<0), where X follows a standard
normal distribution. If you let Y=X*1(X<0), you'll find that the density
function of Y is 2*dnorm(x).
On Mon, 2003-12-22 at 16:10, Agin.Patrick@hydro.qc.ca wrote:
> Hi,
>
> Could anyone tell me why the two following expressions don't give the
> same result:
>
> integrate(function(x) x*dnorm(x),-Inf,0) equals -0.3989
> and
> tmp <- rnorm(1000000); mean(tmp[tmp<0]) approximately equals -0.79
> (two times -0.3989)
>
> I noticed that -0.3989 is the result of mean(pmin(0,tmp)), the mean of
> all the normal deviates with a cap of zero.
>
> If I'm interested in the expected value of all the negatives under the
> standard normal, the good result seems to be -0.79. Am I wrong? Why
> the integrate() expression above doesn't give this number?
>
> Thank you,
> Patrick
>
> P.S. I'm using S-Plus 4.5 on Windows XP.
--
Ping Zhang
Data Analysis Research Department
Avaya Labs
233 Mt.Airy Rd., Basking Ridge, NJ
(908)696-5138
|