How can I use R to calculate the p-value of a given z-score?

Using R, a statistical programming language, you can easily calculate the p-value of a given z-score. A z-score represents the number of standard deviations a data point is from the mean of a distribution. To calculate the p-value of a z-score, you can use the function “pnorm()” which calculates the cumulative probability from a given z-score. This function takes in the z-score as its input and returns the p-value, which represents the probability of obtaining a value equal to or more extreme than the given z-score. By utilizing this function in R, you can efficiently determine the significance of your z-score in relation to the distribution it is derived from.

Calculate the P-Value of a Z-Score in R


Often in statistics we’re interested in determining the p-value associated with a certain z-score that results from a . If this p-value is below some significance level, we can reject the null hypothesis of our hypothesis test.

To find the p-value associated with a z-score in R, we can use the pnorm() function, which uses the following syntax:

pnorm(q, mean = 0, sd = 1, lower.tail = TRUE)

where:

  • q: The z-score
  • mean: The mean of the normal distribution. Default is 0.
  • sd: The standard deviation of the normal distribution. Default is 1.
  • lower.tail: If TRUE, the probability to the left of in the normal distribution is returned. If FALSE, the probability to the right is returned. Default is TRUE.

The following examples illustrate how to find the p-value associated with a z-score for a left-tailed test, right-tailed test, and a two-tailed test.

Left-tailed test

Suppose we want to find the p-value associated with a z-score of -0.77 in a left-tailed hypothesis test.

#find p-value
pnorm(q=-0.77, lower.tail=TRUE)

[1] 0.2206499

The p-value is 0.2206. If we use a significance level of α = 0.05, we would fail to reject the null hypothesis of our hypothesis test because this p-value is not less than 0.05.

Right-tailed test

Suppose we want to find the p-value associated with a z-score of 1.87 in a right-tailed hypothesis test.

#find p-value
pnorm(q=1.87, lower.tail=FALSE)

[1] 0.03074191

The p-value is 0.0307. If we use a significance level of α = 0.05, we would reject the null hypothesis of our hypothesis test because this p-value is less than 0.05.

Two-tailed test

Suppose we want to find the p-value associated with a z-score of 1.24 in a two-tailed hypothesis test.

#find p-value for two-tailed test
2*pnorm(q=1.24, lower.tail=FALSE)

[1] 0.2149754

The p-value is 0.2149. If we use a significance level of α = 0.05, we would fail to reject the null hypothesis of our hypothesis test because this p-value is not less than 0.05.

Related: You can also use this online to find p-values.

x