Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • Change ggplot2 Theme Color in R
    Change ggplot2 Theme Color in R ggthemr Package R
  • Crosstab calculation in R
    Crosstab calculation in R R
  • How to handle Imbalanced Data
    How to handle Imbalanced Data? R
  • Defensive Programming Strategies in R
    Defensive Programming Strategies in R Machine Learning
  • Comparison between Statistics and Luck
    Lottery Prediction-Comparison between Statistics and Luck Machine Learning
  • How to Use the Multinomial Distribution in R
    How to Use the Multinomial Distribution in R? R
  • Subset rows based on their integer locations
    Subset rows based on their integer locations-slice in R R
  • Error in sum(List) : invalid 'type' (list) of argument
    Error in sum(List) : invalid ‘type’ (list) of argument R
one-sample-proportion-test-in-r

One sample proportion test in R-Complete Guide

Posted on May 25May 25 By Jim No Comments on One sample proportion test in R-Complete Guide
Tweet
Share
Share
Pin

One sample proportion test in R, when there are just two categories, the one proportion Z-test is used to compare an observed proportion to a theoretical one.

This article explains the fundamentals of the one-proportion z-test and gives examples using R software.

For example, we have a population that is half male and half female (p = 0.5 = 50%). Some of these total (n = 160), including 100 males and 60 females, acquired a spontaneous malignancy.

Artificial Intelligence Examples-Quick View – Data Science Tutorials

We’d like to know if cancer affects more men than women.

The success rate (males with cancer) is 100 percent.

The observed male proportion (po) is 100/160.

The observed female percentage (q) is 1-po.

The predicted male proportion (pe) is 0.5. (50 percent )

A total of 160 observations (n) were made.

We want to answer the following questions,

  1. whether the observed (po) and predicted (pe) proportions of males equal?
  2. is the observed male percentage (po) less than the expected male proportion (pe)?
  3. whether the observed male proportion (po) exceeds the expected male proportion (pe)?

Control Chart in Quality Control-Quick Guide – Data Science Tutorials

In statistics, the analogous null hypothesis (H0) is defined as follows.

H0:po=pe
H0:po≤pe
H0:po≥pe

The following are the relevant alternative hypothesis (H1)

H1:po≠pe (different)
H1:po>pe (greater)
H1:po<pe (less)

Note that:

Two-tailed tests are used to test hypotheses 1.

One-tailed tests are used to test hypotheses 2 and 3.

How to make a rounded corner bar plot in R? – Data Science Tutorials

The sample size is n.

If |z| is less than 1.96, the difference is not significant at 5%.
If |z| is greater than or equal to  1.96, the difference is significant at 5%.

The z-table contains the corresponding significance level (p-value) for the z-statistic. We’ll look at how to do it in R.

Compute One sample proportion test in R

binom.test() and prop.test() are R functions ()

To do a one-proportion test, use the R methods binom.test() and prop.test():

Calculate the exact binomial test with binom.test(). When the sample size is small, prop.test() is recommended.

When the sample size is large (N > 30), prop.test() can be utilised. It uses a normal approximation.

The two functions have exactly the same syntax. The following is a simplified format.

Two-Way ANOVA Example in R-Quick Guide – Data Science Tutorials

binom.test(x, n, p = 0.5, alternative = "two.sided")
prop.test(x, n, p = NULL, alternative = "two.sided", correct = TRUE)

x: the number of successes

n: the total number of trials

p: the probability to test against.

correct: a logical indicator of whether Yates’ continuity correction should be used if at all practicable.

Note that prop.test() uses the Yates continuity adjustment by default, which is critical if either the expected successes or failures is less than 5.

If you don’t want the correction, use the prop.test() function’s additional argument correct = FALSE.

TRUE is the default value. (To make the test mathematically comparable to the uncorrected z-test of a proportion, set this option to FALSE.)

We’d like to know if cancer affects more men than women.

Best GGPlot Themes You Should Know – Data Science Tutorials

We’ll utilize the prop.test function ()

prop <- prop.test(x = 100, n = 160, p = 0.5, correct = FALSE)
prop
1-sample proportions test without continuity correction
data:  100 out of 160, null probability 0.5
X-squared = 10, df = 1, p-value = 0.001565
alternative hypothesis: true p is not equal to 0.5
95 percent confidence interval:
 0.5478817 0.6962568
sample estimates:
    p
0.625

The function returns,

  1. the value of Pearson’s chi-squared test statistic.
  2. p-value
  3. 95% confidence intervals
  4. Estimated probability of success (the proportion of males with cancer)

Keep in mind,

If you wish to see if the percentage of men with cancer is less than 0.5 (one-tailed test), enter:

prop.test(x = 100, n = 160, p = 0.5, correct = FALSE, alternative = "less")

Alternatively, type this to see if the fraction of men with cancer is more than 0.5 (one-tailed test):

prop.test(x = 100, n = 160, p = 0.5, correct = FALSE, alternative = "greater")

Conclusion

The test’s p-value is 0.001565, which is less than the alpha = 0.05 significance level. With a p-value of 0.001565, we may conclude that the proportion of males with cancer is substantially different from 0.5.

Check your inbox or spam folder to confirm your subscription.

Tweet
Share
Share
Pin
R Tags:one sample proportion

Post navigation

Previous Post: How to add labels at the end of each line in ggplot2?
Next Post: Calculate the p-Value from Z-Score in R

Related Posts

  • Cumulative Sum calculation in R
    Cumulative Sum calculation in R R
  • What is the best way to filter by row number in R?
    What is the best way to filter by row number in R? R
  • How to create a ggalluvial plot in r
    How to create a ggalluvial plot in R? R
  • How to Avoid Overfitting
    How to Avoid Overfitting? Machine Learning
  • How to Find Optimal Clusters in R, K-means clustering is one of the most widely used clustering techniques in machine learning.
    How to Find Optimal Clusters in R? R
  • Calculate the P-Value from Chi-Square Statistic in R
    Calculate the P-Value from Chi-Square Statistic in R R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Defensive Programming Strategies in R
  • Plot categorical data in R
  • Top Data Modeling Tools for 2023
  • Ogive Graph in R
  • Is R or Python Better for Data Science in Bangalore

Check your inbox or spam folder to confirm your subscription.

  • Data Scientist Career Path Map in Finance
  • Is Python the ideal language for machine learning
  • Convert character string to name class object
  • How to play sound at end of R Script
  • Pattern Searching in R
  • How to perform TBATS Model in R
    How to perform TBATS Model in R R
  • Arrange the rows in a specific sequence in R
    Arrange the rows in a specific sequence in R R
  • Count Observations by Group in R
    Count Observations by Group in R R
  • Best GGPlot Themes
    Best GGPlot Themes You Should Know R
  • Radar plot in R
    How to create Radar Plot in R-ggradar R
  • How to Perform Bootstrapping in R
    How to Perform Bootstrapping in R R
  • Separate a data frame column into multiple columns
    Separate a data frame column into multiple columns-tidyr Part3 R
  • Two-Way ANOVA Example in R
    How to perform One-Sample Wilcoxon Signed Rank Test in R? R

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme