Analyzing proportions

M. Drew LaMar
February 20, 2017


https://xkcd.com/539/

Class Announcements

  • Alert: I consider it an honor code violation to use any previous exams from this course. Exam #1 is exempt from this rule.
  • Lab #5: Data Manipulation in R with dplyr
  • Reminder: Homework #5 due Wednesday at 5:00
  • Reading Assignment for Wednesday: Chapter 7, Analyzing Proportions (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.

Using statistics ethically to combat 'a scientific credibility crisis'

Quote: “Although it can often seem that data analysis is secondary to the ‘main’ science or study purpose, the analytic method and its interpretation are essential attributes of both rigor and reproducibility, and this is true for their own work and for their peer review of others' work.”
- Tractenberg

Read more at: https://phys.org/news/2017-02-statistics-ethically-combat-scientific-credibility.html#jCp

From means to proportions

So far, the population parameter of interest was a mean/average.

For means and averages, the random variable of interest was numerical.

In this chapter, the population parameter of interest is a proportion.

For proportions, the random variable of interest is categorical.

More specifically, we are interested in the proportion of times in the population that a particular level of a categorical variable occurs.

Example

Practice Problem #5 (estimation)

Population: All $1 US bills

Variable: Measurable cocaine? (Levels: Yes/No)

Parameter: Proportion of bills with measurable cocaine.

Sample: 50 $1 bills [BTW, in actual study, 46 had measurable cocaine]

Example

Practice Problem #4 (hypothesis testing)

Population: All humans who could have been downwind of site of 11 previous aboveground nuclear bomb tests in 1955.

Variable: Developed cancer by 1980s? (Levels: Yes/No)

Parameter: Probability of developing cancer by 1980s.

Sample: 220 actors in film The Conqueror (including John Wayne) who were downwind of … [91 developed cancer by 1980s]

Note: 14% of age group within this time frame should have been stricken with cancer.

Preliminaries - What variable?

Suppose I have a population of size \( N \) and a categorical variable \( Y \) (e.g. \( Y \) could be genotype with levels {aa, Aa, AA}).

For proportions, we really need a categorical variable with only two levels, which would be

  • “Success = has level of interest”
  • “Failure = does not have level of interest”.

For example, with the genotype case, we could be interested in the proportion of heterozygotes in a population, so we would have

  • “Success = Aa”
  • “Failure = not Aa = {aa, AA}”

Preliminaries - What parameter?

Given the categorical variable with levels “Success” and “Failure”, the proportion of successes in the population would be denoted by

\[ p = \frac{\mathrm{Number \ of \ successes \ in \ population}}{\mathrm{Total \ population \ size}} = \frac{X}{N} \]

If we have a sample of size \( n \), then we would have a sample estimate of this proportion \( p \) given by

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

Estimation

What is the standard error for a proportion (i.e. what is the measure of precision for the sample proportion)?

Definition: The standard error of a proportion is the standard deviation of the sampling distribution for a proportion and is given by \[ \sigma_{\hat{p}} = \sqrt{\frac{p(1-p)}{n}} \]

Definition: An estimate of the standard error for the proportion is given by \[ \mathrm{SE}_{\hat{p}} = \sqrt{\frac{\hat{p}(1-\hat{p})}{n}} \]

Estimation - Practice Problem #3

In a study in Scotland (as reported by Devlin 2009), researchers left a total of 240 wallets around Edinburgh, as though the wallets were lost. Each contained contact information including an address. Of the wallets, 101 were returned by the people who found them.

Discuss: What might the population of interest be in this study?

Answer: Possibly the Edinburgh population only (otherwise, possible bias). Could also be all previously (or futurely) dropped wallets.

Estimation - Practice Problem #3

In a study in Scotland (as reported by Devlin 2009), researchers left a total of 240 wallets around Edinburgh, as though the wallets were lost. Each contained contact information including an address. Of the wallets, 101 were returned by the people who found them.

Discuss: What might be a possible weakness with this study, if they were interested in inferring about “honesty” of the population?

Answer: Possible that one person could have found multiple wallets, which is an independence issue.

Estimation - Practice Problem #3

In a study in Scotland (as reported by Devlin 2009), researchers left a total of 240 wallets around Edinburgh, as though the wallets were lost. Each contained contact information including an address. Of the wallets, 101 were returned by the people who found them.

Discuss: What is the categorical variable of interest (include levels)?

Answer: Wallet fate (Levels: returned/not returned)

Estimation - Practice Problem #3

In a study in Scotland (as reported by Devlin 2009), researchers left a total of 240 wallets around Edinburgh, as though the wallets were lost. Each contained contact information including an address. Of the wallets, 101 were returned by the people who found them.

Calculate: Estimate the proportion of returned wallets.

Answer: \( \ \hat{p} = 101/240 \approx 0.42 \)

Calculate: Compute \( \mathrm{SE}_{\hat{p}} \).

Answer: \( \ \mathrm{SE}_{\hat{p}} = \sqrt{\frac{0.42\times(1-0.42)}{240}} \approx 0.032 \)

Is that good?

95% confidence interval for proportion

Two main methods.

Method #1: In the Wald method, the 95% confidence interval is given by

\[ \hat{p} - 1.96\ \mathrm{SE}_{\hat{p}} < p < \hat{p} + 1.96\ \mathrm{SE}_{\hat{p}} \]

Caution: The Wald method is only accurate when (1) \( n \) is large and (2) population parameter \( p \) is not close to 0 or 1. If these conditions are not met, then the Wald confidence interval will bracket the true population parameter less than 95% of the time.

95% confidence interval for proportion

Due to this, you should use the Agresti-Coull method.

Method #2: In the Agresti-Coull method, the 95% confidence interval is given by

\[ \scriptsize p^{\prime} - 1.96\sqrt{\frac{p^{\prime}(1-p^{\prime})}{n+4}} < p < p^{\prime} + 1.96\sqrt{\frac{p^{\prime}(1-p^{\prime})}{n+4}} \] where \[ \scriptsize p^{\prime} = \frac{X+2}{n+4}. \]

Estimation - Practice Problem #3

Let's use R. Load in the lost wallet data.

walletData <- read.csv("http://whitlockschluter.zoology.ubc.ca/wp-content/data/chapter07/chap07q03LostWallets.csv")
str(walletData)
'data.frame':   240 obs. of  1 variable:
 $ return: Factor w/ 2 levels "not returned",..: 2 2 2 2 2 2 2 2 2 2 ...

Estimation - Practice Problem #3

Only one variable, so let's remove the data frame from the picture:

walletData <- walletData$return
(walletTable <- summary(walletData))
not returned     returned 
         139          101 

Okay, well, I guess we already knew this. ¯\(ツ)

Estimation - Practice Problem #3

Let's compute the standard error for the proportion.

(n <- sum(walletTable)) # Number of trials
[1] 240
(phat <- walletTable["returned"]/n) # Estimate
 returned 
0.4208333 
(phat <- unname(phat)) # Remove confusing name
[1] 0.4208333

Estimation - Practice Problem #3

Let's compute the standard error for the proportion.

(SE_phat <- sqrt(phat*(1-phat)/n))
[1] 0.03186774

Now 95% confidence interval using Wald method.

lower <- phat - 1.96 * SE_phat
upper <- phat + 1.96 * SE_phat
(wald_CI <- c(lower = lower, upper = upper))
    lower     upper 
0.3583726 0.4832941 

Estimation - Practice Problem #3

Finally, 95% confidence interval using Agresti-Coull (and Wald to compare).

library(binom) # Need binom package
binom.confint(walletTable["returned"], n, method = "ac")
         method   x   n      mean     lower     upper
1 agresti-coull 101 240 0.4208333 0.3600899 0.4840711
wald_CI
    lower     upper 
0.3583726 0.4832941 

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} \]