Let’s start with an interesting question. If I split a normal distribution in half and find the center for each half and then subtract the left center from the center of the right half what will I get?
Surprisingly, I have run into this problem twice in my daily work and I thought it would make an interesting blog post. The first time I had to solve this problem was when I was implementing this paper. The analytical form of this solution is relatively easy to derive, but we will end up doing some simplifications.
The 2 in the numerator for is there to transfrom the half-normal distribution into a proper probability distribution that adds up to one. The expression can now be simplified to
mu and sigma are constant parameters therefore
There is no analytical solution for this (you would end up with the error function). However, we can easily realize that mu is not going to change the results and the expression will have the same value for any arbitrary value of mu. We can basically transfer the two half-normal distributions along the x axis such that the final normal distribution is zero-mean. For an standard normal (mu =0 , sigma = 1), we arrive at the following expression that is easily solvable.
This expression will result in
It is therefore easy to show that for any other normal distribution with sigma = σ the expression for the mean will be as the following:
I usually evaluate my analytical solution with a little simulation code. The following code, although not optimized for performance, can show us that the analytical solution is correct.
means <- c()
nsamples <- 20000
sims <- 1000
for (i in 1:sims)
samples <- rnorm(n = nsamples, mean = 0, sd = sd)
samples <- samples[order(samples)]
means <- c(means, mean(samples2)-mean(samples1))
cat(mean(means), "---", 2*sd*sqrt(2)/sqrt(pi))
The output of this little code is as follows. And it is sufficiently close to 1.595769, the theoretical value.
Simulation: 1.595739 --- Theoretical Value: 1.595769
The absolute value of the normal distribution follows a distribution called the half-normal distribution. Using the same method, it is easy to show that the mean value for the half-normal distribution is