Calculate the p-Value from Z-Score in R

[This article was first published on Data Science Tutorials, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post Calculate the p-Value from Z-Score in R appeared first on
Data Science Tutorials

Calculate the p-Value from Z-Score in R, In statistics, we frequently want to know the p-value associated with a specific z-score obtained from a hypothesis test.

We can reject the null hypothesis of our hypothesis test if this p-value is less than a certain level of significance.

How to create contingency tables in R? – Data Science Tutorials

In R, we may use the pnorm() function to find the p-value associated with a z-score, which has the following syntax.

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

where:

q: The z-score

mean: The normal distribution’s mean. The default value is 0.

sd: The normal distribution’s standard deviation. The default value is 1.

lower.tail: If TRUE, the probability in the normal distribution to the left of q is returned. The probability to the right is returned if FALSE. TRUE is the default value.

How to add labels at the end of each line in ggplot2? (datasciencetut.com)

For a left-tailed test, right-tailed test, and two-tailed test, the following examples show how to get the p-value associated with a z-score.

Test with one tail on the left

In a left-tailed hypothesis test, let’s say we wish to calculate the p-value associated with a z-score of -1.8.

To find p-value

pnorm(q=-1.8, lower.tail=TRUE)
0.03593032

0.03593032 is the p-value. We would reject the null hypothesis based on a significance level of = 0.05 because the p-value is less than 0.05.

Test with the right tail

In a right-tailed hypothesis test, let’s say we wish to calculate the p-value associated with a z-score of 1.8.

To find p-value

pnorm(q=1.8, lower.tail=FALSE)
0.03593032

0.03593032 is the p-value. We would reject the null hypothesis if we used a significance level of = 0.05 because the p-value is less than 0.05.

Dealing With Missing Values in R – Data Science Tutorials

Test with two tails

In a two-tailed hypothesis test, let’s say we wish to calculate the p-value associated with a z-score of 1.24.

To find the p-value for the two-tailed test

2*pnorm(q=1.24, lower.tail=FALSE)
[1] 0.2149754

We simply multiplied the one-tailed p-value by two to get the two-tailed p-value.

How to perform the Kruskal-Wallis test in R? – Data Science Tutorials

0.2149 is the p-value. We would fail to reject the null hypothesis of our hypothesis test if we used a significance level of = 0.05 because the p-value is not less than 0.05.

The post Calculate the p-Value from Z-Score in R appeared first on Data Science Tutorials

To leave a comment for the author, please follow the link and comment on their blog: Data Science Tutorials.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)