One-Proportion Z-Test

The One proportion Z-test is used to compare an observed proportion to a theoretical one, when there are only two categories.

Compute one proportion z-test in R

R functions: binom.test() & prop.test()

The R functions binom.test() and prop.test() can be used to perform one-proportion test:

1- binom.test(): Compute exact binomial test. Recommended when sample size is small

2- prop.test() : Can be used when sample size is large ( N > 30). It uses a normal approximation to binomial.

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 of successes

  • n: The total number of trials

  • p: The probability to test against.

  • correct: A logical indicating whether Yates continuity correction should be applied where possible.

example

We have a variable Airline in the dataframe airline.df in which there are diffrent categories of Airlines {Air India, IndiGo, Jet, Spice Jet}. And we have a variable Departure tells that a flight departed in the morning (Departure = AM) or departed at a time later than noon(Departure = PM). Here we want to test whether the proportions of morning and evening flights differ significantly or not.

##            Departure
## Airline      AM  PM Sum
##   Air India  19  22  41
##   IndiGo     35  45  80
##   Jet        75  69 144
##   Spice Jet  40   0  40
##   Sum       169 136 305
##            Departure
## Airline         AM     PM
##   Air India  46.34  53.66
##   IndiGo     43.75  56.25
##   Jet        52.08  47.92
##   Spice Jet 100.00   0.00

So in one-propotion Z-test we will take only a single category of the variable Airline,i.e “Airindia”.

Here from the above table it can be seen that there are 41 flights of Air India. In which 19 flights are from morning(AM) and rest of the flights from evening(PM)

The total number of Air India flights is 41

The number of Air India flights departing in AM hours is 19

Therefore, the proportion of Air India flights departing in the AM hours is 46.34%

TASK 1: Test whether the proportion of Air India flights departing in the AM hours is equal to 45%

  • H0a: The proportion of Air India flights departing in AM hours is equal to 45%

  • H1a: The proportion of Air India flights departing in AM hours is not equal to 45%

## 
##  1-sample proportions test without continuity correction
## 
## data:  19 out of 41, null probability 0.45
## X-squared = 0.02981, df = 1, p-value = 0.8629
## alternative hypothesis: true p is not equal to 0.45
## 95 percent confidence interval:
##  0.3205623 0.6125353
## sample estimates:
##         p 
## 0.4634146

The p-value of the test is 0.8629, which is greater than the significance level alpha = 0.05. We can conclude that the proportion of morning(AM) departure flights does not differ significantly to 45%.

TASK 2: Test whether the proportion of Air India flights departing in the AM hours is equal to 20%

  • H0b: The proportion of Air India flights departing in AM hours is equal to 20%

  • H1b: The proportion of Air India flights departing in AM hours is not equal to 20%

## 
##  1-sample proportions test without continuity correction
## 
## data:  19 out of 41, null probability 0.2
## X-squared = 17.78, df = 1, p-value = 2.479e-05
## alternative hypothesis: true p is not equal to 0.2
## 95 percent confidence interval:
##  0.3205623 0.6125353
## sample estimates:
##         p 
## 0.4634146

The p-value of the test is 2.479e-05, which is less than the significance level alpha = 0.05. We can conclude that the proportion of morning(AM) departure flights differ significantly to 20%.

Two-Proportions Z-Test

The two-proportions z-test is used to compare two observed proportions.

example

we have two groups of Airlines:

Group A , flights of Air india: n = 41

Group B , flights of Indigo : n = 80

Group A with AM departure: n = 41, 19

Group B with AM departure: n = 80, 35

TASK 3: Compare the proportions of Air India and Indigo flights departed at morning(AM)

H0: The proportion of morning departure (AM) flights on airline Air India are the same as the proportion of morning departure (AM) flights on airline IndiGo.

  • If p-value > 0.05, we FAIL TO REJECT the Null Hypothesis H0

  • If p-value < 0.05, we REJECT the Null Hypothesis H0

## 
##  2-sample test for equality of proportions with continuity correction
## 
## data:  c(19, 35) out of c(41, 80)
## X-squared = 0.0061203, df = 1, p-value = 0.9376
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.1799207  0.2317500
## sample estimates:
##    prop 1    prop 2 
## 0.4634146 0.4375000

The p-value of the test is 0.9376 , which is greater than the significance level alpha = 0.05. We can conclude that the proportions of Air India and Indigo flights departed at morning(AM) are not significantly different with a p-value = 0.9376