Skip to content

Data Science Tutorials

For Data Science Learners

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Contact
  • About Us
  • Toggle search form
  • best books about data analytics
    Best Books to learn Tensorflow Course
  • ChatGPT Coursera Review
    ChatGPT Coursera Review Course
  • stacked barplot in R
    Stacked Barplot in R R
  • Determine the significance of a mediation effect in R
    Determine the significance of a mediation effect in R R
  • Autocorrelation and Partial Autocorrelation in Time Series
    Autocorrelation and Partial Autocorrelation in Time Series Statistics
  • Pattern Mining Analysis in R-With Examples R
  • Gamma distribution in R
    Gamma distribution in R R
  • pheatmap function in R
    The pheatmap function in R R
one-sample-proportion-test-in-r

One sample proportion test in R-Complete Guide

Posted on May 25May 25 By Admin No Comments on One sample proportion test in R-Complete Guide

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.

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

  • Convert Multiple Columns to Numeric in R
    Convert Multiple Columns to Numeric in R R
  • How to Standardize Data in R
    How to Standardize Data in R? R
  • R Percentage by Group Calculation
    R Percentage by Group Calculation R
  • Credit Card Fraud detection in R
    Credit Card Fraud Detection in R R
  • Checking Missing Values in R
    Checking Missing Values in R R
  • Logistic Function in R R

Leave a Reply Cancel reply

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

  • Multiple regression model in R
  • Descriptive statistics in R
  • How to Find the Size of a Data Frame in R
  • Filter a Vector in R
  • Split a Vector into Chunks in R
  • About Us
  • Contact
  • Disclaimer
  • Privacy Policy

https://www.r-bloggers.com

  • YouTube
  • Twitter
  • Facebook
  • Course
  • Excel
  • Machine Learning
  • Opensesame
  • R
  • Statistics

Check your inbox or spam folder to confirm your subscription.

  • Augmented Dickey-Fuller Test in R
    Augmented Dickey-Fuller Test in R R
  • pheatmap function in R
    The pheatmap function in R R
  • How to Get a Job as a Data Engineer
    How to Get a Job as a Data Engineer? R
  • Artificial Intelligence Examples
    Artificial Intelligence Examples-Quick View Course
  • Get the first value in each group in R
    Get the first value in each group in R? R
  • best books about data analytics
    Best Books About Data Analytics Course
  • 5 Free Books to Learn Statistics For Data Science
    5 Free Books to Learn Statistics For Data Science Course
  • Wrap a character string in R R

Privacy Policy

Copyright © 2024 Data Science Tutorials.

Powered by PressBook News WordPress theme