Here are my answers to the Week 4 Quiz Activity of the couse Inferential Statistics with R presented by Coursera and conducted by Mine Çetinkaya-Rundel.

R Markdown

This is a R Markdown file. To a better viewing, it could be forked and knitted on RStudio to a html file or it could be viewed directly as a RPubs publication.

Packages

We will use the devtools package to install the statsr package associated with this course. We need to install and load this package.

install.packages("devtools")
library(devtools)

Now we can install the rest of the packages we will use during the course. Type the following commands in the Console as well:

install.packages("dplyr")
install.packages("ggplot2")
install.packages("shiny")
install_github("StatsWithR/statsr")
  1. Which of the following is not required for the distribution of the sample proportion to be nearly normal?
    1. Observations should be independent.
    2. There should be at least 10 successes.
    3. Sample size should be at least 30 and the population distribution should not be extremely skewed.
    4. There should be at least 10 failures.
    5. It is not required that sample size is at least 30 and the population distribution not extremely skewed.

Recognize that the Central Limit Theorem (CLT) is about the distribution of point estimates, and that given certain conditions, this distribution will be nearly normal.

In the case of the proportion the CLT tells us that if

then the distribution of the sample proportion will be nearly normal, centered at the true population proportion and with a standard error of \(\sqrt{p(1−p)/n}\).

\[ \hat{p} \sim N \left( \text{mean} = p, SE = \sqrt{\frac{p(1−p)}{n}} \right) \]

When considering the distribution of the sample proportion, we don’t have a requirement of \(n \ge 30\). To determine if the sample size of categorical data is high enough, we instead check the success-failure condition.

  1. When checking conditions for calculating a confidence interval for a proportion, you should use which number of successes and failures?
    1. Depends on the context
    2. Not applicable. The number of successes and failures (observed or otherwise) is not part of the conditions required for calculating a confidence interval for a proportion.
    3. Observed
    4. Expected (based on the null value)
    5. We should use the observed number of successes and failures.

For confidence intervals use \(\hat{p}\) (observed sample proportion) when calculating the standard error and checking the success/failure condition. For hypothesis tests use p0 (null value) when calculating the standard error and checking the success/failure condition.

Use the observed number of successes and failures when calculating a confidence interval for a proportion, but not when doing a hypothesis test. In a hypothesis test for a proportion, you should use \(np_{0}\) and \(n(1 − p_{0})\) successes and failures; that is, the expected number based on the null proportion.

  1. In May 2011, Gallup asked 1,721 students in grades five through twelve if their school teaches them about money and banking. Researchers are interested in finding out if a majority of students receive such education. Which of the following is the correct set of hypotheses?
    1. \(H_0: p = 0.5\); \(H_A: p > 0.5\)
    2. \(H_0: \hat{p}= 0.5\); \(H_A: \hat{p} \neq 0.5\)
    3. \(H_0: \mu = 0.5\); \(H_A: \mu > 0.5\)
    4. \(H_0: p < 0.5\); \(H_A: p > 0.5\)
    5. The hypotheses test is given by \(H_0: p = 0.5\); \(H_A: p > 0.5\).
  2. You and a friend are about to visit the aviary at the local zoo for the first time. A trustworthy zookeeper says the aviary holds about 3,000 birds. Your friend read somewhere that 10% of those birds are cardinals, but he thinks there are really more cardinals than that. You’re both great at identifying cardinals so you decide to test this claim with a hypothesis test on the true proportion p of cardinals in the aviary. You walk around the aviary together and get a simple random sample by spotting 250 birds. Of these, 35 were cardinals and 215 were not cardinals. The p-value is 0.0175. Which of the following is false?
    1. The success-failure condition is met.
    2. \(\hat{p}= 0.14\)
    3. \(H_0: \hat{p} = 0.10\)
    4. If in fact 10% of the birds in the aviary are cardinals, the probability of obtaining a random sample of 250 birds where exactly 14% are cardinals is 0.0175.
    5. The success-failure condition is met, \(\hat{p}= 0.14\) and \(H_0: \hat{p} = 0.10\) are both correct.

\[ \text{p-value} = P \left( \text{observed or more extreme test statistic} | H_{0} \text{true} \right) \]

  1. Gallup conducts an annual poll of U.S. residents. Approximately 1,000 residents across all 50 states and Washington D.C. are asked “Do you believe the use of marijuana should be made legal?” The distribution of responses by date of survey is shown in the table below. Imagine a hypothesis test evaluating whether there is a difference from 2012 to 2013 between proportions of “yes” responses. Using the information in the table below, calculate the standard error for this hypothesis test. Choose the closest answer.
    1. 0.5274
    2. 0.5798
    3. 0.4754
    4. 0.022
    5. 0.00048
n1 = 1037
p1 = 493/n1
n2 = 1028
p2 = 596/n2
SE <- sqrt( p1*(1-p1)/n1  + p2*(1-p2)/n2 )
SE
## [1] 0.02185173
  1. “In statistical inference for proportions, standard error (SE) is calculated differently for hypothesis tests and confidence intervals.” Which of the following is the best justification for this statement?
    1. Because in hypothesis testing we’re interested in the variability of the true population distribution, and in confidence intervals we’re interested in the variability of the sampling distribution.
    2. Because statistics is full of arbitrary formulas.
    3. Because in hypothesis testing, we assume the null hypothesis is true, hence we calculate SE using the null value of the parameter. In confidence intervals, there is no null value, hence we use the sample proportion(s).
    4. Because if we used the same method for hypothesis tests as we did for confidence intervals, the calculation would be impossible.
    5. The third option is the best justification.

Note that the reason for the difference in calculations of standard error is the same as in the case of the single proportion: when the null hypothesis claims that the two population proportions are equal, we need to take that into consideration when calculating the standard error for the hypothesis test, and use a common proportion for both samples.

  1. An introductory stats professor hypothesizes that 50% of students learn best by watching the videos, 10% by reading the book, 20% by solving questions, and the rest from the discussion forums. She surveys a random sample of a large sample of students asking them how they learn best, and wants to use these data to evaluate her hypothesis. Which method should she use?
    1. ANOVA
    2. hypothesis test for a single mean
    3. F-test
    4. \(\chi^2\) test of independence
    5. t-test
    6. Z-test
    7. \(\chi^2\) test of goodness of fit
    8. She should use a \(\chi^2\) test of goodness of fit.
  1. A variety of studies suggest that 10% of the world population is left-handed. It is also claimed that artists are more likely to be left-handed. In order to test this claim we take a random sample of 40 art students at a college and find that 6 of them (15%) are left handed. Which of the following is the correct set-up for calculating the p-value for this test?
    1. Roll a 10-sided die 40 times and record the proportion of times you get a 1. Repeat this many times, and calculate the proportion of simulations where the sample proportion is 15% or more.
    2. In a bag place 40 chips, 6 red and 34 blue. Randomly sample 40 chips, with replacement, and record the proportion of red chips in the sample. Repeat this many times, and calculate the proportion of samples where at least 10% of the chips are red.
    3. Roll a 10-sided die 40 times and record the proportion of times you get a 1. Repeat this many times, and calculate the proportion of simulations where the sample proportion is 10% or more.
    4. Randomly sample 40 non-art students, and record the number of left-handed students in the sample. Repeat this many times and calculate the proportion of samples where at least 15% of the students are left-handed.
    5. The correct set-up is the following: “Roll a 10-sided die 40 times and record the proportion of times you get a 1. Repeat this many times, and calculate the proportion of simulations where the sample proportion is 15% or more.”

In hypothesis testing for one categorical variable, generate simulated samples based on the null hypothesis, and then calculate the number of samples that are at least as extreme as the observed data.

P-value is not the proportion of samples that are at least as extreme as the null, rather it is the proportion of sample that is “at least as extreme as the observed data”.

  1. True or false: The \(\chi^2\) statistic is always non-negative.
    1. True.
    2. False.
    3. True.
  2. Suppose in a population 20% of people wear contact lenses. What is the expected shape of the sampling distribution of proportion of contact lens wearers in random samples of 30 people from this population?
    1. right-skewed
    2. left-skewed
    3. uniform
    4. nearly normal
    5. The expected shape of the sampling distribution is right-skewed.

Note that if the CLT doesn’t apply and the sample proportion is low (close to 0) the sampling distribution will likely be right skewed, if the sample proportion is high (close to 1) the sampling distribution will likely be left skewed.

Success-failure condition not met, and the true population is closer to 0 than 1, so the sampling distribution will be right skewed.

  1. At a stop sign, some drivers come to a full stop, some come to a ‘rolling stop’ (not a full stop, but slow down), and some do not stop at all. We would like to test if there is an association between gender and type of stop (full, rolling, or no stop). We collect data by standing a few feet from a stop sign and taking note of type of stop and the gender of the driver. Below is a contingency table summarizing the data we collected. If gender is not associated with type of stop, how many males would we expect to not stop at all? Choose the closest answer.
    1. 6.24
    2. 3.64
    3. 3.36
    4. 5.76
n_m = 24
n_f = 26
no_stop_m = 3
no_stop_f = 4
p_pooled <- (no_stop_m + no_stop_f)/(n_m + n_f)
n_m_exp <- n_m * p_pooled
n_m_exp
## [1] 3.36
  1. We would like to test the following hypotheses \(H_0: p = 0.05\); \(H_A: p < 0.05\). The sample size is 150 and the sample proportion is 8%, i.e. \(\hat{p} = 0.08\). Which of the below is the correct test for this situation?
    1. z-test for comparing two proportions
    2. t-test for a mean
    3. z-test for a proportion
    4. randomization test for a proportion
    5. chi-square test of independence
    6. Since there is only one proportion and the success-failure conditions are not met, \(150 \times 0.05 < 10\), we should use a randomization test for a proportion.

Use simulation methods when sample size conditions aren’t met for inference for categorical variables.

In hypothesis testing

Success-failure conditions are not met.