Statistical Inference on Binomially Distributed Data
The primary purpose of our experiment is to validate hypotheses regarding the population of the subjects under study. As a result, the experimenter must determine whether to accept or reject these hypotheses based on the experiment’s results. In this context, the method of statistical analysis will vary depending on whether the sample data follows a normal distribution or a binomial distribution.
Today, we will introduce statistical testing methods for data that conform to a binomial distribution.
Let’s delve into an example: A university is widely acknowledged to maintain a 1:1 gender ratio. Upon the statistics department’s request, a research company obtained the phone numbers of 50 randomly selected students from the university and verified their genders. The findings revealed that 40 students were male, while 10 students were female. This outcome has triggered suspicions among the university’s statistics students.
How is it possible for the sample gender ratio to be 4:1 when the population gender ratio is 1:1?
Therefore, this student formulates a hypothesis:
A) Our university's gender ratio, as commonly understood, is likely to be 1:1.
B) Our university's gender ratio is unlikely to be 1:1.
In this case, A becomes the null hypothesis (Ho), and B becomes the alternative hypothesis (Ha).
When a sample of 50 individuals is taken, the probability of obtaining a particular number can be calculated using the binomial distribution. According to the binomial distribution formula, the probability of having 40 males out of 50 can be calculated using the following equation. This equation represents the probability of a specific outcome (success) X
occurring exactly k
times, denoted as P(X=k)
.
When calculating using Excel, the formula will be as follows, and the result is 0.00000912.
=FACT(50) * 0.5^40*0.5^10 / (FACT(40)*FACT(10))
This value indicates that when the population gender ratio is 1:1 (p=q=0.5), the probability of randomly obtaining a specific gender ratio of 40 individuals out of 50 is 0.0009%. This translates to a probability of 9 occurrences per million individuals. Due to this exceedingly low probability, the statistics students can reject the null hypothesis and embrace the alternative hypothesis, which asserts that “the gender ratio at our school is not 1:1.”
Validation through R
Calculating the binomial distribution is remarkably straightforward using R.
dbinom(k, size=n, prob=p)
With this code, you can calculate the probability all at once. Here’s the code for the probability of having 40 occurrences (k) out of 50 trials (n) for a specific probability (p):
dbinom(40, size=50, prob=0.5)
[1] 9.123616e-06
The result is displayed in scientific notation. I need to convert it into regular numbers. By adding scientific=FALSE
to the format()
, the result will be displayed as regular numbers instead of in scientific notation.
format(dbinom(40, size=50, prob=0.5),scientific=FALSE)
[1] "0.000009123616"
Alternatively, by including the following code, the result will be shown as regular numbers rather than in scientific notation:
options(scipen=999)
If you want to revert the changes and go back to the default behavior, you can use the following code:
options(scipen=0)
What is the threshold to reject the null hypothesis?
I’m curious here. When assuming a population gender ratio of 1:1, at what point can we reject the null hypothesis (i.e., accept the fact that the university’s gender ratio is not 1:1) when we extract 50 individuals? Rather than simply rejecting the null hypothesis due to the seemingly unrealistic probability of 0.0009%, it would be beneficial to establish some criteria.
For instance, in the case where 40 out of 50 individuals are male, the probability was 0.0009%.
So, the question becomes:
How few males would need to be present for us to accept the null hypothesis (i.e., the university’s gender ratio is 1:1)?
To aid in understanding this, let’s take a visual approach. While there are many programs to present p-values, I believe PQRS is the best one, as it simplifies the comprehension of p-values.
Download
https://pqrs.software.informer.com/3.4/
Please visit the website and download PQRS, then run it. Choose ‘binomial’ in the Distribution section.
Then, input a total of 50 for n, and put the given probability of 50% (male-female ratio of 1:1) for p, and let’s go ahead and run it.
There you go! Let’s proceed to examine the case of P(X=40)
by changing the x-axis to 40.
What this graph illustrates is that when you have a probability of 0.5 and perform 50 trials, the likelihood of obtaining exactly 40 occurrences is nearly 0%. On the other hand, the probability of obtaining fewer than 40 occurrences is almost 100%. We are aware that the probability of exactly 40 occurrences is 0.0009%. Hence, stating that the probability of getting fewer than 40 occurrences is almost 100% is logical!
In R, you can easily calculate this probability.
# The probability of getting 40 occurrences in 50 trials with a probability of 50%.
dbinom(40, size=50, prob=0.5)
[1] 0.000009123616
# The probability of getting fewer than 40 occurrences in 50 trials with a probability of 50%.
pbinom(40, size=50, prob=0.5, lower.tail=TRUE)
[1] 0.9999972
# The probability of getting more than 40 occurrences in 50 trials with a probability of 50%.
pbinom(40, size=50, prob=0.5, lower.tail=FALSE)
or
1- pbinom(40, size=50, prob=0.5, lower.tail=TRUE)
[1] 0.00000280705
As in PQRS, the probability of getting more than 40 occurrences is almost 0%, and the probability of getting fewer than 40 occurrences is calculated to be 99.9%.
Let’s adjust the x-axis to 31 in PQRS and observe the changes. How has the probability changed now?
When conducting 50 trials with a probability of 50%, the likelihood of obtaining 31 occurrences is 2.7%. The probability of obtaining more than 31 occurrences is 3.25%, and the probability of obtaining fewer than 31 occurrences is 94.05%. Summing up these three probabilities yields a total of 100%. Consequently, we can deduce that the combined probability of obtaining 31 or more occurrences is 5.95% (0.027 + 0.0325 = 0.0595).
Let’s calculate this using R.
dbinom(31, size=50, prob=0.5)
pbinom(31, size=50, prob=0.5, lower.tail=TRUE)
pbinom(31, size=50, prob=0.5, lower.tail=FALSE)
Now, this student in the statistics department needs to set a significance level, denoted as α. The significance level represents the probability of making an error, commonly referred to as the “alpha error.” If you set the significance level at 5%, for instance, you are accepting a 5% chance of making an error while simultaneously having a 95% chance of being correct.
In the case of extracting a sample of 50 students, the probability of having a specific gender of more than 31 is 3.25%. This probability is lower than the significance level we are willing to accept as an error. In other words, a probability lower than our accepted error rate implies that there might be some causal relationship rather than a natural process.
[Note 1] In statistical hypothesis testing, researchers often want to determine whether an observed effect or relationship is likely due to a specific cause (e.g., a treatment or intervention) or if it could have occurred by chance. To do this, they set up two hypotheses: 1. Null Hypothesis (H0): This hypothesis suggests that there is no significant effect or relationship; any observed differences or correlations are due to random chance or natural variation. 2. Alternative Hypothesis (H1): This hypothesis proposes that there is a significant effect or relationship, indicating that the observed differences or correlations are not due to random chance but are instead the result of a specific cause. The significance level, often denoted as α (alpha), is the predetermined threshold below which you reject the null hypothesis. Common choices for α include 0.05 or 0.01. It represents the maximum acceptable probability of making a Type I error, which is when you reject the null hypothesis when it's actually true. The p-value is a measure that helps determine whether the observed data is consistent with the null hypothesis. It represents the probability of obtaining results as extreme as or more extreme than what was observed, assuming the null hypothesis is true. If the p-value is smaller than the chosen significance level (α), it suggests that the observed results are unlikely to have occurred due to random chance alone, leading to the rejection of the null hypothesis in favor of the alternative hypothesis. So, when you say "a probability lower than our accepted error rate implies that there might be some causal relationship rather than a natural process," you're essentially referring to the scenario where the p-value is smaller than the significance level. This suggests that the observed effect is statistically significant and may indeed indicate a causal relationship rather than being the result of random chance or natural variation. It's important to note that statistical significance does not imply practical or real-world significance. Even if an effect is statistically significant, it's essential to consider the size of the effect and its practical implications before drawing conclusions or making decisions based solely on statistical results.
This suggests that we could reject the null hypothesis, which is something like “The gender ratio in our university is 1:1,” and accept the alternative hypothesis, which might be “The gender ratio in our university is not 1:1.”
However, in the case of extracting a sample of 50 students, the probability of having a specific gender the same as or more than 31 is 5.95% (0.027 + 0.0325 = 0.0595), and you can conclude, ‘The gender ratio in our university is 1:1.’