I have a simple setting: I simulate demand patterns that are distributed according to a truncated normal distribution with a given mean and variance after truncation. The truncation is from the left at zero (as demand is always positive).
However, all functions that draw from truncated normal distributions require me to specify the mean and variance of the normal distribution before truncation as e.g. the truncnorm function from the truncnorm package in R.
Example:
val = rtruncnorm(10000, a=0, mean = 100, sd = 240) print(mean(val)) [1] 232.2385 print(sd(val)) [1] 162.853
I would like the resulting variable val to have mean 100 and standard deviation 240. Is there any function in R to do this or is there a formula to compute the mean and variance before truncation given the truncation limits and the post-mean and post-variance?
Best Answer
What Jarle Tufto points out is that, if $Xsimmathcal N^+(mu,sigma^2)$, then, defining $$alpha=-mu/sigmaquadtext{and}quadbeta=infty$$ Wikipedia states that $$Bbb E_{mu,sigma}[X]= mu + frac{varphi(alpha)-varphi(beta)}{Phi(beta)-Phi(alpha)}sigma$$ and $$text{var}_{mu,sigma}(X)=sigma^2left[1+frac{alphavarphi(alpha)-betavarphi(beta)}{Phi(beta)-Phi(alpha)} -left(frac{varphi(alpha)-varphi(beta)}{Phi(beta)-Phi(alpha)}right)^2right]$$ That is, $$Bbb E_{mu,sigma}[X]= mu + frac{varphi(mu/sigma)}{1-Phi(-mu/sigma)}sigmatag{1}$$ and $$text{var}_{mu,sigma}(X)=sigma^2left[1-frac{muvarphi(mu/sigma)/sigma}{1-Phi(-mu/sigma)} -left(frac{varphi(mu/sigma)}{1-Phi(-mu/sigma)}right)^2right]tag{2}$$ Given the numerical values of the truncated moments $(Bbb E_{mu,sigma}[X],text{var}_{mu,sigma}(X))$, one can then solve numerically (1) and (2) as a system of two equations in $(mu,sigma)$, assuming $(Bbb E_{mu,sigma}[X],text{var}_{mu,sigma}(X))$ is a possible value for a truncated Normal $mathcal N^+(mu,sigma^2)$.
Similar Posts:
- Solved – Truncated Normal distribution: Theoretical mean outside truncation boundaries
- Solved – Simulate from a truncated mixture normal distribution
- Solved – the difference between a truncated normal distribution and a half normal distribution in a Stochastic Frontier Analysis
- Solved – Calculating the variance of a truncated normally distributed RV given the prob. of a range
- Solved – Folded Normal and truncated Normal