Using the mills ratio result, let X∼N(μ,σ2), then

E(X|X<α)=μ−σϕ(a−μσ)Φ(a−μσ)

However, when calculating it in R. I don't obtain the correct results as

`> mu <- 1 > sigma <- 2 > a <- 3 > x <- rnorm(1000000, mu, sigma) > x <- x[x < a] > mean(x) [1] 0.4254786 > > mu - sigma * dnorm(a, mu, sigma) / pnorm(a, mu, sigma) [1] 0.7124`

What am I doing wrong?

**Answer**

Your formula implementation is wrong because,

ϕ(x−μσ)=1√2πe−12(x−μσ)2≠fX,μ,σ(x)=1√2πσe−12(x−μσ)2

As you can see, we have an extra σ in the denominator of fX,μ,σ(x), which yields:

ϕ(x−μσ)=σfX,μ,σ(x)

`dnorm`

method gives you fX,μ,σ(x), where you need to multiply it with σ to obtain ϕ. Since your σ=2, this can be practically done via subtracting the second term again, which is 1−0.7124=0.2876:

1−0.2876−0.2876=0.4247

which is close to your estimate.

**Attribution***Source : Link , Question Author : Kozolovska , Answer Author : gunes*