Analyzing proportions (Part 2)

M. Drew LaMar
February 22, 2017

Class Announcements

  • Homework #6 has been posted (due Monday)
  • Reading Assignment for Friday: Chapter 8, Fitting probability models to frequency data (QUIZ)

Project: Part I (5% of grade)


www.sleepcycle.com

  • For this week: Download and use app nightly.
  • Think about what factors might influence your sleep.

What is the sampling distribution for the estimate?

The sampling distribution for the sample estimate of the proportion is a “scaled” binomial distribution.

\[ \hat{p} = \frac{\mathrm{Number \ of \ successes \ in \ sample}}{\mathrm{Total \ sample \ size}} = \frac{\hat{X}}{n} \]

What is the sampling distribution for the estimate?

Definition: The binomial distribution provides the probability distribution for the number of “successes” in a fixed number of independent trials, when the probability of success is the same in each trial.

Properties:

  • Number of trials is fixed (\( n \))
  • Probability of success in each trial (\( p \)) is the same in every trial
  • Separate trials are independent

What is the sampling distribution for the estimate?

Definition: The binomial distribution provides the probability distribution for the number of “successes” in a fixed number of independent trials, when the probability of success is the same in each trial.

Properties:

  • Number of trials is fixed (\( n \)) [sample size]
  • Probability of success in each trial (\( p \)) is the same in every trial [proportion of successes in population]
  • Separate trials are independent [random sample]

Binomial distributions

If we have \( n \) trials, and the probability of success in each trial is \( p \), we have \[ \mathrm{Pr[}X \mathrm{ \ successes]} = \left(\begin{array}{c}{n \\ X}\end{array}\right)p^{X}(1-p)^{n-X}, \] where \[ \left(\begin{array}{c}{n \\ X}\end{array}\right) = \frac{n!}{X!(n-X)!}, \] and \[ n! = n\times(n-1)\times(n-2)\cdots 2\times 1. \]

Why?

Binomial distributions - Math moment

To figure out Pr[\( X \) successes], first ask

Question: “What are all different outcomes of \( X \) successes in \( n \) trials?”

Example: Suppose \( n=3 \) and \( X=2 \).

\[ 2 \ \mathrm{successes} = \{SSF, SFS, FSS\} \]

\[ \mathrm{Pr}[SSF] = \mathrm{Pr}[S]\times \mathrm{Pr}[S]\times \mathrm{Pr}[F] = p^2(1-p) \]

\[ \mathrm{Pr}[SFS] = \mathrm{Pr}[S]\times \mathrm{Pr}[F]\times \mathrm{Pr}[S] = p^2(1-p) \]

\[ \mathrm{Pr}[FSS] = \mathrm{Pr}[F]\times \mathrm{Pr}[S]\times \mathrm{Pr}[S] = p^2(1-p) \]

Binomial distributions - Math moment

To figure out Pr[\( X \) successes], first ask

Question: “What are all different outcomes of \( X \) successes in \( n \) trials?”

Example: Suppose \( n=3 \) and \( X=2 \).

\[ 2 \ \mathrm{successes} = \{SSF, SFS, FSS\} \]

\[ \mathrm{Pr}[SSF] = \mathrm{Pr}[SFS] = \mathrm{Pr}[FSS] = p^2(1-p) = p^X(1-p)^{n-X} \]

How many ways are there to have 2 successes in 3 trials? 3 choose 2!!

\[ \mathrm{Pr[2 \ successes]} = \left(\begin{array}{c}{3 \\ 2}\end{array}\right)p^2(1-p) \]

Binomial distributions - in R

To get values of probability distribution, use the dbinom function. Supposing \( n=10 \) and \( p=0.5 \), we have:

(pdist <- dbinom(x=0:10, size=10, prob=0.5))
 [1] 0.0009765625 0.0097656250 0.0439453125 0.1171875000 0.2050781250
 [6] 0.2460937500 0.2050781250 0.1171875000 0.0439453125 0.0097656250
[11] 0.0009765625
sum(pdist)
[1] 1

The d in dbinom stands for distribution.

Binomial distributions - in R

Question: Given \( p=0.3 \) and \( n=20 \), what is Pr[6 successes]? (Write out using notation)

Answer: \[ \mathrm{Pr[}6 \mathrm{ \ successes]} = \left(\begin{array}{c}{20 \\ 6}\end{array}\right)0.3^{6}\times 0.7^{14}. \]

Using R and dbinom,

(ans <- dbinom(x=6, size=20, prob=0.3))
[1] 0.191639

Thus, Pr[6 successes] = 0.191639.

Binomial distributions - in R

Let's plot the distribution:

barplot(pdist, 
        names.arg=0:10, 
        col="firebrick", 
        xlab="X (Number of successes)", 
        ylab="Probability")

Binomial distributions - in R

Let's plot the distribution:

plot of chunk unnamed-chunk-4

Binomial distributions - in R

Let's just look at a lower probability of success, say \( p=0.1 \):

pdist <- dbinom(0:10, 10, 0.1)

barplot(pdist, 
        names.arg=0:10, 
        col="firebrick", 
        xlab="X (Number of successes)", 
        ylab="Probability")

Binomial distributions - in R

Let's just look at a lower probability of success, say \( p=0.1 \):

plot of chunk unnamed-chunk-5

Back to sampling distribution

What is the mean, variance and standard deviation of a binomial random variable \( X \)?

alt text

Definition: Distribution of sample estimates is the sampling distribution.

\[ \hat{p} = \frac{\mathrm{Number \ of \ successes \ in \ sample}}{\mathrm{Total \ sample \ size}} = \frac{\hat{X}}{n} \]

Back to sampling distribution

\[ \hat{p} = \frac{\mathrm{Number \ of \ successes \ in \ sample}}{\mathrm{Total \ sample \ size}} = \frac{1}{n}\hat{X} \]

  • \( \hat{X} \) is a binomial random variable
  • \( \hat{p} \) is thus a scaled binomial random variable
  • Standard deviation of \( \hat{X} \) is \( \sigma_{\hat{X}} = \sqrt{np(1-p)} \)
  • From rules for scaled random variables, the standard deviation of \( \hat{p} \) is thus

    \[ \sigma_{\hat{p}} = \frac{1}{n}\sqrt{np(1-p)} = \sqrt{\frac{p(1-p)}{n}} \]

This is the standard error for \( \hat{p} \)!!!

Sampling distribution for a proportion

plot of chunk unnamed-chunk-6

Binomial test - Definitions

Definition: The binomial test uses data to test whether a population proportion (\( p \)) matches a null expectation (\( p_{0} \)) for the proportion.

Definition: The null hypothesis \( H_{0} \) and alternative hypothesis \( H_{A} \) for a binomial test are given by:

    \( H_{0} \): Relative frequency of successes in population is \( p_{0} \).
    \( H_{A} \): Relative frequency of successes in population is not \( p_{0} \).

Example - Practice Problem #2

Do people typically use a particular ear preferentially when listening to strangers? Marzoli and Tomassi (2009) had a researcher approach and speak to strangers in a noisy nightclub. An observer scored whether the person approached turned either the left or right ear toward the questioner. Of 25 participants, 19 turned the right ear toward the questioner and 6 offered the left ear. Is this evidence of population difference from 50% for each ear?

Discuss: What is the null and alternative hypotheses?

Answer:
\[ \begin{array}{ll} H_{0}\,: & p = 0.5 \\ H_{A}\,: & p \neq 0.5 \end{array} \]

Example - Practice Problem #2

Do people typically use a particular ear preferentially when listening to strangers? Marzoli and Tomassi (2009) had a researcher approach and speak to strangers in a noisy nightclub. An observer scored whether the person approached turned either the left or right ear toward the questioner. Of 25 participants, 19 turned the right ear toward the questioner and 6 offered the left ear. Is this evidence of population difference from 50% for each ear?

Discuss: What is the observed value of the test statistic?

Answer: Number of right ears is 19 (\( \hat{X}=19 \)).

Example - Practice Problem #2

Discuss: Under the null hypothesis, calculate the probability of getting exactly 19 right ears and six left ears.

(prob <- dbinom(x = 19, size = 25, prob = 0.5))
[1] 0.005277991

\[ \mathrm{Pr[19]} = \left(\begin{array}{c}{25 \\ 19}\end{array}\right)0.5^{19}0.5^{6} = 0.005278 \]

Example - Practice Problem #2

Discuss: List all possible outcomes in which the number of right ears is greater than the 19 observed.

Answer: 20, 21, 22, 23, 24, 25

Discuss: Calculate the probability under the null hypothesis of each of the extreme outcomes listed above

(probs <- dbinom(x = 20:25, size = 25, prob = 0.5))
[1] 1.583397e-03 3.769994e-04 6.854534e-05 8.940697e-06 7.450581e-07
[6] 2.980232e-08

Example - Practice Problem #2

Discuss: Use the addition rule to calculate the probability of 19 or more right-eared turns under the null hypothesis.

(extreme_probs <- dbinom(x = 19:25, size = 25, prob = 0.5))
[1] 5.277991e-03 1.583397e-03 3.769994e-04 6.854534e-05 8.940697e-06
[6] 7.450581e-07 2.980232e-08
sum(extreme_probs)
[1] 0.007316649

Example - Practice Problem #2

Discuss: Give the two-tailed \( P \)-value based on your previous answer.

(pval <- 2*sum(extreme_probs))
[1] 0.0146333

Discuss: State your conclusion.

Answer: Using a significance level of \( \alpha = 0.05 \), we reject \( H_{0} \) since \( P < 0.05 \). There is evidence that more people use the right ear than the left ear when listening to a stranger in the noisy nightclub.