How to find critical values and p-values from the normal distribution
Description
Some statistical techniques require computing critical values or $p$-values from the normal distribution. For example, we need to do this when constructing a confidence interval or conducting a hypothesis test. How do we compute such values?
Related tasks:
Solution, in Julia
If we choose a value $0 \le \alpha \le 1$ as our Type 1 error rate,
then we can find the critical value from the normal distribution using the
quantile()
function in Julia’s Distributions package.
If you don’t have that package installed, first run using Pkg
and then
Pkg.add( "Distributions" )
from within Julia.
The code below shows how to do this for left-tailed, right-tailed, and two-tailed hypothesis tests.
1
2
3
4
using Distributions
alpha = 0.05 # Replace with your alpha value
standard_normal = Normal( 0, 1 )
quantile( standard_normal, alpha ) # Critical value for a left-tailed test
1
-1.6448536269514724
1
quantile( standard_normal, 1 - alpha ) # Critical value for a right-tailed test
1
1.6448536269514717
1
quantile( standard_normal, alpha / 2 ) # Critical value for a two-tailed test
1
-1.9599639845400592
We can also compute $p$-values from the normal distribution to compare to a test statistic. As an example, we’ll use a test statistic of 2.67, but you can substitute your test statistic’s value instead.
We can find the $p$-value for this test statistic using the cdf()
function
in Julia’s Distributions package.
Again, we show code for left-tailed, right-tailed, and two-tailed tests.
1
2
test_statistic = 2.67 # Replace with your test statistic
cdf( standard_normal, test_statistic ) # p-value for a left-tailed test
1
0.9962074376523146
1
1 - cdf( standard_normal, test_statistic ) # p-value for a right-tailed test
1
0.0037925623476854353
1
2 * ( 1 - cdf( standard_normal, test_statistic ) ) # p-value for a two-tailed test
1
0.007585124695370871
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Solution, in R
If we choose a value $0 \le \alpha \le 1$ as our Type 1 error rate,
then we can find the critical value from the normal distribution using R’s
qnorm()
function. The code below shows how to do this for left-tailed,
right-tailed, and two-tailed hypothesis tests.
1
2
3
4
alpha <- 0.05 # Replace with your alpha value
qnorm(p = alpha, lower.tail = TRUE) # Critical value for a left-tailed test
qnorm(p = alpha, lower.tail = FALSE) # Critical value for a right-tailed test
qnorm(p = alpha/2, lower.tail = FALSE) # Critical value for a two-tailed test
1
2
3
4
5
6
7
8
9
[1] -1.644854
[1] 1.644854
[1] 1.959964
We can also compute $p$-values from the normal distribution to compare to a test statistic. As an example, we’ll use a test statistic of 2.67, but you can substitute your test statistic’s value instead.
We can find the $p$-value for this test statistic using R’s pnorm()
function.
Again, we show code for left-tailed, right-tailed, and two-tailed tests.
1
2
3
4
test_statistic <- 2.67 # Replace with your test statistic
pnorm(test_statistic, lower.tail = TRUE) # p-value for a left-tailed test
pnorm(test_statistic, lower.tail = FALSE) # p-value for a right-tailed test
2*pnorm(test_statistic, lower.tail = FALSE) # p-value for a two-tailed test
1
2
3
4
5
6
7
8
9
[1] 0.9962074
[1] 0.003792562
[1] 0.007585125
Content last modified on 24 July 2023.
See a problem? Tell us or edit the source.
Topics that include this task
Opportunities
This website does not yet contain a solution for this task in any of the following software packages.
- Python
- Excel
If you can contribute a solution using any of these pieces of software, see our Contributing page for how to help extend this website.