Statistical Inference in People Analytics
Statistical Inference in People Analytics
Introduction to Probability
Randomness and uncertainty exist all around us. In probability theory, random
phenomena refer to events or experiments whose outcomes cannot be predicted
with certainty (Pishro-Nik, 2014). If you have taken a course in probability, there
is a good chance you have considered the case of a fair coin flip—one of the most
intuitive applications of probability. In the absence of information on how the coin
is flipped, we cannot be certain of the outcome. What we can be certain of is that
with a large number of coin flips, the proportion of heads will become increasingly
close to 50%, or . 12 .
The Law of Large Numbers (LLN) is an important theorem for building
an intuitive understanding of how probability relates to the statistical inference
concepts we will cover. In the case of a fair coin flip, it is possible to observe
many consecutive heads by chance. This is because small samples can lend to
anomalies. However, as the number of flips increases, we will undoubtedly observe
an increasing number of tails; we expect a roughly equal number of heads and tails
with a large enough number of flips.
Probability Distributions
# Load library
library(peopleanalytics)
# Load data
data("employees")
# Load library
library(ggplot2)
0.100
0.075
Density
0.050
0.025
0.000
0 20 40 60
Org Tenure
You can likely imagine the shape of probability distributions for many common
events. If we consider the probability of employees exiting an organization, the
outcome is binary. That is, employees either leave or stay; there are no options
between these extremes. However, the distribution of performance scores will
likely look quite different. Most organizations have expected –or even forced–
distributions in which an average rating is awarded most frequently and low and
high performance ratings less frequently. This would start to look more like a bell
curve as the number of performance levels increases.
Just as we grouped variables into discrete and continuous categories in chapter
“Measurement and Sampling”, this is also how probability distributions are cat-
egorized. If you read chapter “Measurement and Sampling”, you likely already
have some a priori expectations about the characteristics of discrete and continuous
distributions.
The shape of a probability distribution is defined by parameters, which represent
its essential properties (e.g., measures of central tendency and spread). These
probability distributions underpin the many types of statistical tests covered in this
book.
124 Statistical Inference
400 75
100
count
count
count
300
50
200
50
25
100
0 0 0
0.00 0.25 0.50 0.75 1.00 40 50 60 60 80 100 120 140 160
x x x
count
count
100
50
500
50
0 0 0
0 1 2 3 4 5 10 15 20 0 10 20 30
x x x
# Load library
library(ggpubr)
if (type == "discrete"){
126 Statistical Inference
# Discrete distribution
viz <- ggplot2::ggplot() +
ggplot2::aes(data) +
ggplot2::labs(title = paste(title), x = "x", y =
→ "count") +
ggplot2::geom_histogram(fill = "#414141") +
ggplot2::theme_bw() +
ggplot2::theme([Link] = element_text(hjust =
→ 0.5))
} else {
# Continuous distribution
viz <- ggplot2::ggplot() +
ggplot2::aes(data) +
ggplot2::labs(title = paste(title), x = "x", y =
→ "density") +
ggplot2::geom_histogram(aes(y = ..density..), fill
→ = "#414141") +
ggplot2::geom_density(fill = "#ADD8E6", alpha =
→ 0.6) +
ggplot2::theme_bw() +
ggplot2::theme([Link] = element_text(hjust =
→ 0.5))
}
return(viz)
}
# Simulate F distribution
f_dist <- rf(1000, df1 = 5, df2 = 200)
Next, we will visualize each distribution. Since these continuous distributions are
probability density functions, we will superimpose density plots over each (Fig. 3):
0.075
0.4 0.010
density
density
density
0.050
0.2 0.005
0.025
Student's T Chi−Square F
0.15 0.8
0.3 0.6
0.10
density
density
density
0.2 0.4
0.05
0.1 0.2
Conditional Probability
P (B|A)P (A)
P (A|B) =
. ,
P (B)
where:
• .A = an event
• .B = another event
• .P (A|B) = conditional probability that event A occurs, given event B occurs
(posterior)
• .P (B|A) = conditional probability that event B occurs, given event A occurs
(likelihood)
130 Statistical Inference
doors at random, the probabilities would be equal (and he may end up opening the
door that contains the prize).
Seeing is believing, so let us prove this with a simulation in R:
for (n in 1:trials){
decision = decision,
result = ifelse(correct_door ==
→ selected_door, "win", "lose")))
}
}
## [1] 45
As we can see, wins occur nearly 50% more often when contestants switch doors.
This exercise hopefully demonstrates the importance of conditional probability and
statistical assumptions like randomness. Also, if ever you find yourself playing Let’s
Make a Deal, switch doors.
The Central Limit Theorem (CLT) is a mainstay of statistics and probability and
fundamental to understanding the mechanics of statistical inference.
Coined by a French-born mathematician named Abraham De Moivre in the
1700s, the CLT states that given a sufficiently large sample size, the average of
independent random variables tends to follow a normal (or Gaussian) distribution
as the number of samples increases. The distribution of sample means approaches
a normal distribution regardless of the shape of the population distribution from
which the samples are drawn. This is important because the normal distribution has
properties that can be used to test the likelihood that an observed value, difference,
or relationship in a sample is also present in the population (Fig. 4).
Let us begin with an intuitive example of CLT. Imagine that we have a reliable
way to measure how fun a population is on a 100-point scale, where 100 indicates
maximum fun (life of the party) and 1 indicates maximum boringness. Consider that
a small statistics conference is in progress at a nearby convention center, and there
are 40 statisticians in attendance. In a separate room at the same convention center,
there is also a group of 40 random people (non-statisticians) who are gathered to
discuss some less interesting topic. Our job is to walk into one of the rooms and
Central Limit Theorem 133
determine –based on the fun factor alone– whether we have entered the statistics
conference or the other, less interesting gathering of non-statisticians.
Instinctively, we already know the statisticians will be more fun than the other
group. However, let us assume we need the mean fun score and standard deviation of
these two groups for this example. The group of statisticians have, on average, a fun
score of 85 with a standard deviation of 2, while the group of non-statisticians are
a bit less fun with a mean score of 65 and a standard deviation of 4. With a known
population mean and standard deviation, the standard error (SE) –the standard
deviation of sample means– provides the ability to calculate the probability that
the sample (the room of 40 people) belongs to the population of interest (fellow
statisticians).
The SE is defined by:
σ
SE = √
.
n
Herein lies the beauty of the CLT: roughly 68% of sample means will lie
within one standard error of the population mean, roughly 95% within two standard
errors of the population mean, and roughly 99% within three standard errors of the
population mean. Therefore, any room whose members have an average fun score
that is not within two standard errors of the population mean (between 84.37 and
85.63 for our statisticians) is statistically unlikely to be the group of statisticians
for which we are searching. This is because in less than 5 in 100 cases could we
randomly draw a reasonably sized sample of statisticians with an average fun score
so extremely different from the population average.
Because small samples lend to anomalies, we could –by chance– select a single
person who happens to fall in the tails (extremely boring or extremely fun); however,
as the sample size increases, it becomes more and more likely that the observed
average reflects the average of the larger population. It would be virtually impossible
(in less than 1 in 100 cases) to draw a random sample of statisticians from the
population with average funness that is not within three standard errors of the
population mean (between 84.05 and 85.95). Therefore, if we find that the room
of people have an average fun score of 75, we will likely have far more fun in the
other room!
Let us now see the CLT in action by simulating a random uniform population
distribution from which we can draw random samples. Remember, the shape of the
134 Statistical Inference
0.010
Density
0.005
0.000
0 25 50 75 100
x
## [1] 51.22007
## [1] 830.3155
Central Limit Theorem 135
1 2 3
0.100
0.075
0.050
0.025
0.000
4 5 10
0.100
0.075
Density
0.050
0.025
0.000
0 25 50 75 100
25 50
0.100
0.075
0.050
0.025
0.000
0 25 50 75 100 0 25 50 75 100
x−bar
ggplot2::geom_histogram(aes(y = ..density..),
→ fill = "#414141") +
ggplot2::geom_density(fill = "#ADD8E6", alpha
→ = 0.6) +
ggplot2::theme_bw() +
ggplot2::facet_wrap(~n)
Per the CLT, we can see that as n increases, the sample means become more
normally distributed (Fig. 6).
Confidence Intervals
A Confidence Interval (CI) is a range of values that likely contains the value of an
unknown population parameter. These unknown population parameters are often .μ
or .σ , though we will also leverage CIs in later chapters for regression coefficients,
proportions, rates, and differences.
If we draw random samples from a population, we can compute a CI for each
sample. Building on the CLT, for a given confidence level (usually 95%, though 99%
or 90% are sometimes used), the specified percent of sample intervals is expected
to include the estimated population parameter. For example, for a 95% CI we would
Confidence Intervals 137
expect 19 in every 20 (or 95 in every 100) intervals across the samples to include
the true population parameter. This is illustrated in Fig. 7.
It is important to note that CIs should not be applied to the distribution of sample
values; CIs relate to population parameters. A common misinterpretation of a CI is
that it represents an interval within which a certain percent of sample values exists.
Because this misinterpretation is so prevalent, there is a good chance you will be
tested on your understanding of CIs when applying to positions involving statistical
analyses!
The standard error is fundamental to estimating CIs. While the standard deviation
is a measure of variability for a random variable, the variability captured by the SE
reflects how well a sample represents the population. Since sample statistics will
approach the actual population parameters as the size of the sample increases, the
SE and sample size are inversely related; that is, the SE decreases as the sample size
increases.
Since the CLT is fundamental to inferential statistics, let us validate that our
simulated distribution of sample means adheres to the properties of normally
distributed data per the Empirical Rule:
## [1] 95.35
95% of sample means are within 2 SEs, which is what we expect per the
characteristics of the normal distribution.
138 Statistical Inference
## [1] 99.79
Nearly all of the sample means are within 3 SEs, indicating that it would be
highly unlikely –nearly impossible even– to observe a sample mean from the same
population that falls outside this interval.
Now, let us illustrate the relationship between CIs and standard errors using
sample data from our uniform population distribution. In our example, both .μ and
.σ are known and our sample size n is at least 30; therefore, we can use a Z-test to
calculate the 95% CI. A z score of 1.96 corresponds to the 95% CI for a two-tailed
distribution; that is, we are looking for significantly different values in either the
larger or smaller direction. The 95% CI represents the range of values we would
expect to include .μ in at least 95 of 100 random samples taken from the population.
The CI in this case is defined by:
σ
CI = x̄ ± zα/2 √
.
n
Let us randomly take n = 100 from the population and compute sample statistics
to estimate the 95% CI:
# Calculate 95% CI
ci95_lower_bound <- mean(x) - 1.96 * (sd(x) / sqrt(100))
ci95_upper_bound <- mean(x) + 1.96 * (sd(x) / sqrt(100))
## [1] 47.90733
## [1] 58.98773
Our known .μ is 51.2, which is covered by our 95% CI (47.9–59.0). Per the CLT, in
less than 5% of cases would we expect to draw a random sample from the population
that results in a 95% CI which does not include .μ. Note that our CI narrows with
larger samples since our confidence that the range includes .μ increases with more
data.
Next, let us look at a 99% CI. We will enter 2.576 for z:
# Calculate 99% CI
ci99_lower_bound <- mean(x) - 2.576 * (sd(x) / sqrt(100))
ci99_upper_bound <- mean(x) + 2.576 * (sd(x) / sqrt(100))
## [1] 46.16612
## [1] 60.72893
Like the 95% CI, this slightly wider 99% CI (46.2–60.7) also includes our .μ of
51.2.
If .σ is not known, and/or we have a small sample (n < 30), we need to use a
t-test to calculate the CIs. In a people analytics setting, the reality is that population
parameters are often unknown. For example, if we knew how engagement scores
vary in the employee population, there would be no need to survey a sample of
employees and make inferences about said population.
As we will see, the t-test underpins many statistical tests and models germane to
the people analytics discipline since we are often working with small data sets, so
it is important to understand the mechanics. As shown in Fig. 8, the t distribution
is increasingly wider and shorter relative to the normal distribution as the sample
size decreases; this is also characteristic of the sampling distribution of means for
smaller samples we observed in our CLT example. Specifically, degrees of freedom
(df) is used to determine the shape of the probability distribution. Degrees of
freedom represents the number of observations in the data that are free to vary when
estimating statistical parameters, which is a function of the sample size (.n − 1). For
example, if we could choose 1 of 5 projects to work on each day between Monday
and Friday, we would only be able to choose 4 out of the 5 days; on Friday, only 1
project would remain to be selected, so our degrees of freedom (the number of days
in which we have a choice between projects) would be 4.
140 Statistical Inference
When estimating the CI for smaller samples, we need to leverage the wider, more
platykurtic t distribution to achieve greater accuracy. Therefore, the CI for a two-
tailed test in this case is defined by:
σ
CI = x̄ ± tα/2 √
.
n
Let us compare CIs calculated using a t-test to those calculated using the Z-Test.
While a fixed z score can be used for each CI level when n > 30, the t statistic varies
based on both the CI level and df . Though R will determine the correct t statistic
for us, let us reference the table shown in Fig. 9 to manually lookup the t statistic.
For illustrative purposes, let us draw a smaller sample of n = 25 from our uniform
population distribution and calculate the 95% CI using the t statistic from the table
(df = 24). The t statistic for this CI and df is 2.064:
# Calculate 95% CI
ci95_lower_bound <- mean(x) - 2.064 * (sd(x) / sqrt(25))
ci95_upper_bound <- mean(x) + 2.064 * (sd(x) / sqrt(25))
## [1] 35.24305
Confidence Intervals 141
## [1] 59.60959
As expected, the 95% CI using the t statistic is much wider (35.2–59.6),
acknowledging the increased uncertainty in estimating population parameters given
the limited information in this smaller sample. To increase our confidence to the
99% level, the interval widens even further (30.9–63.9):
# Calculate 99% CI
ci99_lower_bound <- mean(x) - 2.797 * (sd(x) / sqrt(25))
ci99_upper_bound <- mean(x) + 2.797 * (sd(x) / sqrt(25))
142 Statistical Inference
## [1] 30.91633
## [1] 63.93631
Hypothesis Testing
H0 : μA = μB
.
HA : μA = μB
.
HA : μA < μB
.
HA : μA > μB
.
Confidence Intervals 143
Alpha
The alpha level of a hypothesis test, denoted by .α, represents the probability of
obtaining observed results due to chance if the null hypothesis is true. In other
words, .α is the probability of rejecting the null hypothesis (and therefore claiming
that there is a significant difference or relationship) when in fact we should fail to
reject it because there is insufficient evidence to support the alternative hypothesis.
.α is often set at 0.05 but is sometimes set at a more rigorous 0.01, depending
upon the context and tolerance for error. An .α of 0.05 corresponds to a 95% CI (1–
0.05), and 0.01 to a 99% CI (1–0.01). With non-directional alternative hypotheses,
we must divide .α by 2 (i.e., we could observe a significant result in either tail of the
distribution), while one-tailed tests position the rejection region entirely within one
tail based on what is being hypothesized.
At the 0.05 level, we would conclude that a finding is statistically significant if
the chance of observing a value at least as extreme as the one observed is less than
1 in 20 if the null hypothesis is true. Recall that we observed this behavior with
our simulated distribution of sample means. While we could observe more extreme
values by chance with repeated attempts, in less than 1 in every 20 times would we
expect a 95% CI that does not capture .μ. Moreover, in less than 1 in every 100 times
should we expect a sample with a 99% CI that does not capture .μ.
p-Values
In statistical tests, the p-value is referenced to determine whether the null hypothesis
can be rejected. We generally rely on the availability of a theoretical null
distribution to obtain a p-value associated with a particular test statistic. The p-
value represents the probability of obtaining a result at least as extreme as the
one observed if the null hypothesis is true. As a general rule, if p < 0.05, we can
confidently reject the null hypothesis and conclude that the observed difference or
relationship was unlikely a chance observation.
While statistical significance helps us understand the probability of observing
results by chance when there is no difference or effect in the population, it does
not tell us anything about the size of the difference or effect. Analyses should never
be reduced to inspecting p-values; in fact, p-values have been the subject of much
controversy among researchers and practitioners in recent years. Later chapters will
cover how to interpret results of statistical tests to surface the story and determine if
there is anything “practically” significant among statistically significant findings.
Bonferroni Correction
αF W = 1 − (1 − αP C )C
.
where c is equal to the number of comparisons (or statistical tests) performed, and
.αP C is equal to the specified per analysis error rate (usually 0.05). For example, if
.α = 0.05 per analysis, the probability of a Type I error with three tests on the same
The most common method of adjusting the familywise error rate down to the
specified per analysis error rate is the Bonferroni Correction. To implement this
correction, we can simply divide .α by the number of analyses performed on the
data set—such as .α/3 = 0.017 in the case of three analyses with .α = 0.05. This
means that for each statistical test, we must achieve p < 0.017 to report a statistically
significant result. An alternative which allows us to achieve the same number of
statistically significant results is to multiply the unadjusted per analysis p-values for
each statistical test by the number of tests. For example, if we run three statistical
tests and receive .p = 0.014, .p = 0.047, and .p = 0.125, we would achieve one
significant result with the first method (p < 0.017) as well as with the alternative
since the first statistical test satisfies the per analysis error rate (p < 0.05): .p =
0.014 ∗ 3 = 0.042.
Perneger (1998) is one of many who oppose the use of the Bonferroni Correction,
suggesting that these “adjustments are, at best, unnecessary and, at worst, dele-
terious to sound statistical inference.” The Bonferroni Correction is controversial
among researchers because while applying the correction reduces the chance of a
Type I error, it also increases the chance of a Type II error. Because this correction
makes it more difficult to detect significant results, it is rare to find such a correction
reported in published research—though research often involves multiple testing
on the same sample. Perneger suggests that simply describing the statistical tests
that were performed, and why, is sufficient for dealing with potential problems
introduced by multiple testing.
Statistical Power
Whereas .α is the probability of a Type I error, Beta .β is the opposite: the probability
of accepting .H0 when it is false (Type II error).
.β is related to the power of the analysis, which is calculated by 1—.β and reflects
our ability to detect a difference or relationship if one exists. If a study has 80%
power, for example, it has an 80% chance of detecting an effect if one actually
exists in the population. Power analysis helps with defining the optimal n-count
for detecting a population effect in sample data (i.e., correctly rejecting a false .H0 ).
Increasing the power of a statistical test decreases the probability that we will fail to
detect a significant effect present in the population.
At this point, it should be intuitive that larger samples increase our chances of
detecting significant results when they exist. As we observed in the t-test example,
CIs for small samples (n < 30) are quite wide relative to those for large samples;
therefore, the power of the analysis to detect significance is limited given how
different the values of x must be to observe non-overlapping CIs.
146 Statistical Inference
# Load library
library(pwr)
##
## Balanced one-way analysis of variance power calculation
##
## k = 4
## n = 44.59927
## f = 0.25
## [Link] = 0.05
## power = 0.8
##
## NOTE: n is number in each group
The power analysis for this one-way ANOVA shows that we need a minimum
of .n = 45 within each of the four groups to achieve an 80% chance of detecting a
medium population effect across the four groups when setting .α = 0.05.
Review Questions
9. When population parameters are unknown, which test would be appropriate for
testing the following null hypothesis: μA = μB ?
10. According to the Empirical Rule, 95% of normally distributed data lie within
how many standard deviations of the mean?
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0
International License ([Link] which permits use, sharing,
adaptation, distribution, and reproduction in any medium or format, as long as you give appropriate
credit to the original author(s) and the source, provide a link to the Creative Commons license and
indicate if changes were made.
The images or other third party material in this chapter are included in the chapter’s Creative
Commons license, unless indicated otherwise in a credit line to the material. If material is not
included in the chapter’s Creative Commons license and your intended use is not permitted by
statutory regulation or exceeds the permitted use, you will need to obtain permission directly from
the copyright holder.