One-Sample Proportions

Introduction

  • In the last module, we discussed describing data.

  • In this module, we are discussing statistical inference on one sample.

    • Mean / median

    • Proportion

    • Variance / standard deviation

  • In this lecture, we are focusing on one-sample proportions.

R Setup

library(tidyverse)
library(ssstats)
  • Recall our Zootopia data,
zootopia <- read_csv("https://raw.githubusercontent.com/samanthaseals/SDSI/refs/heads/main/files/data/lectures/1-zootopia.csv")
resident_name department district academy_status academy_exam_score sleep_hours hustle_earnings district_temp_f
Sable Jones Desk Rainforest District Fail 65 5.5 14.72 72.2
Kevin Frostwhisker Patrol Downtown Fail 69 7.4 45.66 66.2
Jasper Duskrunner Patrol Sahara Square Pass 79 8.7 30.91 89.8

Confidence Interval for \pi

  • (1–\alpha)100% CI for a population proportion, \pi

\hat{p} \pm z_{\alpha/2} \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}

  • \hat{p} is the sample proportion (the point estimate)

  • z_{\alpha/2} comes from the standard normal distribution (the critical value)

  • \hat{p}(1-\hat{p}) is the variance of the Bernoulli distribution and n is the sample size (\sqrt{\hat{p}(1-\hat{p})/n} is the standard error of the mean)

Hypothesis Test for \pi

  • Hypotheses

Two-Tailed

H_0: \pi = \pi_0

H_1: \pi \ne \pi_0

Left-Tailed

H_0: \pi \ge \pi_0

H_1: \pi < \pi_0

Right-Tailed

H_0: \pi \le \pi_0

H_1: \pi > \pi_0

  • \pi is the population proportion,

  • \pi_0 is the hypothesized value of \pi.

Hypothesis Test for \pi

  • Test Statistic

z_0 = \frac{\hat{p} - \pi_0}{\sqrt{\frac{\pi_0(1-\pi_0)}{n}}}

  • where

    • \hat{p} is the sample proportion

    • \pi_0 is the hypothesized value of \pi

    • n is the sample size

Statistical Inference on One Proportion (R)

  • We will use the one_proportion() function from library(ssstats) to perform statistical inference.
dataset_name |> one_proportion(outcome = variable_name,
                                event = event_name_or_number,
                                p = hypothesized_value,
                                alternative = "two" | "less" | "greater",
                                alpha = alpha_level)
  • where

    • outcome is the variable name of the outcome variable

    • event is the name or number of the event of interest

    • p is the hypothesized value of the population proportion (default = 0.05)

    • alternative is the alternative hypothesis (default = “two”)

    • alpha is the significance level (default = 0.05)

Example 1

  • ZPD’s official staffing policy states that 50% of officers are assigned to Patrol, with the rest working Desk duty. As Zootopia’s data analyst, you believe that Patrol seems to make up a lot more than 50% of the department these days. We will use the zootopia dataset to answer:

    • Has the true proportion of officers in Patrol increased from 50%?
  • First, we need to describe the data.

    • We start with point and interval estimates.
  • Then, we will perform a hypothesis test to answer the question.

Example 1

  • Point and interval estimates:
zootopia |> one_proportion(outcome = department)
Error in `one_proportion()`:
! argument "event" is missing, with no default
  • Oops! We need to make sure we specify the event of interest. Let’s see how it’s coded in the department variable.
zootopia |> n_pct(department)
department n (pct)
Desk 12 (40.0%)
Patrol 18 (60.0%)

Example 1

  • Point and interval estimates:
zootopia |> one_proportion(outcome = department,
                            event = "Patrol")
One-sample proportion

p̂ = 0.6 (18/30)

95% CI for π: (0.4247, 0.7753)

Hypotheses:
H₀: π = 0.5
H₁: π ≠ 0.5
Test statistic: z = 1.1
p-value: 0.273
Conclusion: Fail to reject the null hypothesis (p = 0.273 ≥ α = 0.050)
  • The estimated proportion of officers in Patrol is 60% (95% CI: 42.5%, 77.5%).

Example 1

  • Then, we will perform a hypothesis test to answer the question.

    • Has the true proportion of officers in Patrol increased from 50%?
  • How do we translate this into hypotheses?

    • H_0: \pi \le 0.5
    • H_1: \pi > 0.5
  • For the one_proportion() function, we will set

    • p = 0.5
    • alternative = "greater".

Example 1

  • Has the true proportion of officers in Patrol increased from 50%?
zootopia |> one_proportion(outcome = department,
                            event = "Patrol",
                            p = 0.5,
                            alternative = "greater",
                            alpha = 0.05)
One-sample proportion

p̂ = 0.6 (18/30)

95% CI for π: (0.4247, 0.7753)

Hypotheses:
H₀: π ≤ 0.5
H₁: π > 0.5
Test statistic: z = 1.1
p-value: 0.137
Conclusion: Fail to reject the null hypothesis (p = 0.137 ≥ α = 0.050)

Example 1

  • Hypotheses

    • H_0: \pi \le 0.5
    • H_1: \pi > 0.5
  • Test Statistic and p-Value

    • z_0 = 1.1
    • p = 0.137
  • Rejection Region

    • Reject H_0 if p < \alpha; \alpha = 0.05
  • Conclusion and Interpretation

    • Fail to reject H_0. There is not sufficient evidence to suggest that the current proportion of officers in Patrol has increased from 50%.

Example 2

  • Zootopia’s Housing Authority claims that 40% of officers live in Downtown. As data analyst, you believe Downtown might actually make up a smaller proportion of the roster than the Authority’s number suggests. We will use the zootopia dataset to answer:

    • Is the true proportion of officers living in Downtown actually less than 40%?
  • First, we need to describe the data.

    • We start with point and interval estimates.
  • Then, we will perform a hypothesis test to answer the question.

Example 2

  • Looking at what is in district,
zootopia |> n_pct(district)
district n (pct)
Downtown 8 (26.7%)
Rainforest District 7 (23.3%)
Sahara Square 9 (30.0%)
Tundratown 6 (20.0%)
  • We know that the event of interest is coded as Downtown.

Example 2

  • Point and interval estimates:
zootopia |> one_proportion(outcome = district,
                            event = "Downtown")
One-sample proportion

p̂ = 0.2667 (8/30)

95% CI for π: (0.1084, 0.4249)

Hypotheses:
H₀: π = 0.5
H₁: π ≠ 0.5
Test statistic: z = -2.56
p-value: 0.011
Conclusion: Reject the null hypothesis (p = 0.011 < α = 0.050)
  • The estimated proportion of officers living in Downtown is 26.7% (95% CI: 10.8%, 42.5%).

Example 2

  • Then, we will perform a hypothesis test to answer the question.

    • Is the true proportion of officers living in Downtown actually less than 40%?
  • How do we translate this into hypotheses?

    • H_0: \pi \ge 0.4
    • H_1: \pi < 0.4
  • For the one_proportion() function, we will set

    • p = 0.4
    • alternative = "less".

Example 2

  • Is the true proportion of officers living in Downtown actually less than 40%?
zootopia |> one_proportion(outcome = district,
                            event = "Downtown",
                            p = 0.4,
                            alternative = "less",
                            alpha = 0.05)
One-sample proportion

p̂ = 0.2667 (8/30)

95% CI for π: (0.1084, 0.4249)

Hypotheses:
H₀: π ≥ 0.4
H₁: π < 0.4
Test statistic: z = -1.49
p-value: 0.068
Conclusion: Fail to reject the null hypothesis (p = 0.068 ≥ α = 0.050)

Example 2

  • Hypotheses

    • H_0: \pi \ge 0.4
    • H_1: \pi < 0.4
  • Test Statistic and p-Value

    • z_0 = - 1.49
    • p = 0.068
  • Rejection Region

    • Reject H_0 if p < \alpha; \alpha = 0.05
  • Conclusion and Interpretation

    • Fail to reject H_0. There is not sufficient evidence to suggest that the current proportion of officers living in Downtown is less than 40%.

Wrap Up

  • In this lecture, we discussed statistical inference on one proportion.

  • Fun fact: proportions are just a mean!

  • In the next lecture, we will examine statistical inference on one variance or standard deviation.