# Chapter 25 Inference on a Single Proportion

To conduct a statistical inference on proportions in R, whether it be a single proportion or two proportions, we use the function:
prop.test(count of success, total count, p = probability of success, …)

The following arguments may be added as needed:

• alternative = “less” or “greater” - for one-sided test. If nothing is specified, then two-sided alternative is the default.
• conf.level = confidence level desired. If no confidence level is specified, the argument defaults to 95% confidence level.

Suppose we ask 100 people if they are left-handed or not. We observe that 15 out of the 100 participants say they are left-handed (success). For a single proportion, we can easily enter the data ourselves, ie, enter the number of trials, the number of successes, etc. into the function.

## 25.1 Two-Sided Alternative Hypothesis Test

Suppose we are interested in determining whether the population proportion of left-handed people (success) is different from 10%. In other words, the alternative hypothesis is p ≠ 0.1.

prop.test(15, 100, p = 0.1)   # Success = 15, Trials = 100
##
##  1-sample proportions test with continuity correction
##
## data:  15 out of 100, null probability 0.1
## X-squared = 2.25, df = 1, p-value = 0.1336
## alternative hypothesis: true p is not equal to 0.1
## 95 percent confidence interval:
##  0.0891491 0.2385308
## sample estimates:
##    p
## 0.15

The output shows that the P-value is 0.1336, the 95% confidence interval is (0.089, 0.239) and the sample proportion is 0.15.

If a confidence level different from 95% is desired, specify it in the argument. Suppose we want an 85% confidence level.

prop.test(15, 100, p = 0.1, conf.level = 0.85)
##
##  1-sample proportions test with continuity correction
##
## data:  15 out of 100, null probability 0.1
## X-squared = 2.25, df = 1, p-value = 0.1336
## alternative hypothesis: true p is not equal to 0.1
## 85 percent confidence interval:
##  0.1015232 0.2140434
## sample estimates:
##    p
## 0.15

Notice that all the outputs stayed the same as with the above test except the confidence interval, which became narrower.

There are lots of information given from the output. The R Help page has a detailed list of what the object returned by the function contains.

To list the attributes, use the function, ls( ). However, before we can use the function ls( ), we need to assign prop.test( ) to a vector. Let us call this vector lefty.

lefty <- prop.test(15, 100, p = 0.1, conf.level = 0.85)
lefty
##
##  1-sample proportions test with continuity correction
##
## data:  15 out of 100, null probability 0.1
## X-squared = 2.25, df = 1, p-value = 0.1336
## alternative hypothesis: true p is not equal to 0.1
## 85 percent confidence interval:
##  0.1015232 0.2140434
## sample estimates:
##    p
## 0.15

Let us list the attributes.

ls(lefty)
## [1] "alternative" "conf.int"    "data.name"   "estimate"    "method"
## [6] "null.value"  "p.value"     "parameter"   "statistic"

With this new vector, we can now target a specific attribute.

# Show alternative hypothesis
lefty$alternative ## [1] "two.sided" # Calculate confidence interval at 95% confidence level lefty$conf.int
## [1] 0.1015232 0.2140434
## attr(,"conf.level")
## [1] 0.85
# Calculate P-value
lefty$p.value ## [1] 0.1336144 # Calculate sample proportion lefty$estimate
##    p
## 0.15

## 25.2 Calculating Confidence Interval

To calculate the confidence interval only, append $conf.int after the prop.test( ) function. If no confidence level is specified, R defaults to 95%. # Calculates confidence interval at default of 95% confidence level prop.test(15, 100)$conf.int
## [1] 0.0891491 0.2385308
## attr(,"conf.level")
## [1] 0.95
# Calculates confidence interval at 85% confidence level
prop.test(15, 100, conf.level = 0.80)\$conf.int
## [1] 0.1056126 0.2069149
## attr(,"conf.level")
## [1] 0.8

Notice that as the confidence level goes down, the confidence interval narrows.

## 25.3 One-Sided Alternative Hypothesis Test

Suppose we are interested in determining whether the population proportion of left-handed people (success) is greater than 10%. In other words, the alternative hypothesis is p > 0.1.

We need to do a right-tailed hypothesis test.

prop.test(15, 100, p = 0.1, alternative = "greater")
##
##  1-sample proportions test with continuity correction
##
## data:  15 out of 100, null probability 0.1
## X-squared = 2.25, df = 1, p-value = 0.06681
## alternative hypothesis: true p is greater than 0.1
## 95 percent confidence interval:
##  0.09644405 1.00000000
## sample estimates:
##    p
## 0.15

Notice that the P-value of the one-sided hypothesis test is half the P-value of the two-sided hypothesis test.