Load packages
library(tidyverse)
library(lsr)Motivation
Recently, I listened to the great Paul Meehl in the audioscripts of some lectures of him. There, he asked the students
what’s the mean value of the upper half of a Gaussian distribution?
Let’s explore that using simulation techniques.
Simulation time
Let’s draw some instances from a standard Normal distribution, \(X\).
n <- 1e05
x <- rnorm(n)Mean and SD in our sample are quite close to what can be expected:
mean(x)
#> [1] -0.03428717
sd(x)
#> [1] 0.979225
aad(x)
#> [1] 0.782511Note that the aad is 0.8 in a standard normal distribution.
Upper half
Let’s put the data into a tibble.
df <- tibble(x = x,
upper_half = ifelse(x >= 0, TRUE, FALSE))df %>%
group_by(upper_half) %>%
summarise(avg_half = mean(x),
sd_half = sd(x),
var_half = var(x),
md_half = median(x),
iqr_half = IQR(x),
aad_half = aad(x),
n_hlaf = n())
#> # A tibble: 2 x 8
#> upper_half avg_half sd_half var_half md_half iqr_half aad_half n_hlaf
#> <lgl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 FALSE -0.798 0.607 0.368 -0.674 0.832 0.487 512
#> 2 TRUE 0.767 0.569 0.324 0.654 0.771 0.450 488As can be seen the average in the halves is about 0.8 standard units away from the cut point (zero).
Some theory: Half normal distribution
The half-normal distribution has this expected value: \(E[Y]=\mu ={\frac {\sigma {\sqrt {2}}}{\sqrt {\pi }}}\).
From the Wikipedia page:
In more simple terms, we have this expected value:
E = 1 * sqrt(2) / sqrt(pi)
E
#> [1] 0.7978846In other words, about 0.8 standard units, just as we saw above.
Note that 1 refers to the variance of \(X\) which is 1.
Regarding the variance, according to the Wikipedia page sited above, \((Y)=\sigma ^{2}\left(1-{\frac {2}{\pi }}\right)\)
Var = 1 * (1 - (2/pi))
Var
#> [1] 0.3633802Note that this parameter is proportional to the Variance of \(X\).
This value does match nicely the simulated value from above.
However, according to Math Wolfram, \(V = \frac{-2 + \pi}{2 \theta^2}\).
Wikipedia states that Wolfram Math uses this parametrization:
\[\theta = \sqrt{\pi/2}\].
That is,
theta = sqrt(pi/2)
theta
#> [1] 1.253314Var2 = (-2+pi) / (2 * theta^2)
Var2
#> [1] 0.3633802Parameter estimation
According to Wikipedia, the \(\sigma\) can be estimated as such:
sigma_hat = sqrt((1/n) * sum(x^2))
sigma_hat
#> [1] 1.002571