Single Sample Test for Proportions

The prop.test function in R is used to perform a test of proportions. It allows you to test whether the proportions in one or more groups are equal to specified values or whether the proportions in two or more groups are equal. This function is often used in hypothesis testing to compare proportions in different samples.

Usage:

prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), 
          correct = TRUE, conf.level = 0.95)

Arguments:

Single Sample Example

* Sample size (n) = 500
* Number of successes (x) = 280
* Expected value under null hypothesis (Usually \(\pi\), but here as p)
prop.test(x=280,n=500,p=0.60)
## 
##  1-sample proportions test with continuity correction
## 
## data:  280 out of 500, null probability 0.6
## X-squared = 3.1688, df = 1, p-value = 0.07506
## alternative hypothesis: true p is not equal to 0.6
## 95 percent confidence interval:
##  0.5151941 0.6038700
## sample estimates:
##    p 
## 0.56

Two Sample Example:

Suppose you have two groups and you want to test if the proportions of successes are equal in these groups.

# Number of successes in each group
successes <- c(50, 30)
# Number of trials in each group
trials <- c(100, 100)

# Perform the test
result <- prop.test(successes, trials)

# Print the result
print(result)
## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  successes out of trials
## X-squared = 7.5208, df = 1, p-value = 0.006099
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  0.05706878 0.34293122
## sample estimates:
## prop 1 prop 2 
##    0.5    0.3

Conclusion

This will give you the test statistic, p-value, and confidence interval for the difference in proportions. The prop.test function is a powerful tool for comparing proportions in different groups and is commonly used in medical research, social sciences, and other fields that involve categorical data analysis.