← return to practice.dsc10.com
This quiz was administered in-person. It was closed-book and
closed-note; students were not allowed to use the DSC
10 Reference Sheet. Students had 20 minutes to work on
the quiz.
This quiz covered Lectures 19-23 of the Fall 2024 offering of
DSC 10.
⚠️ PDF version available here .
We plan to collect a sample of movies and use this sample to estimate
the proportion of all movies with the genre "Musical", a
population parameter.
If we want to create a 95\% confidence interval that is at most 0.08 wide, which of the expressions below represents the smallest sample size we should collect?
\left(\dfrac{1}{0.02}\right)^2
\left(\dfrac{1}{0.04}\right)^2
\left(\dfrac{1}{0.08}\right)^2
\left(\dfrac{1}{0.16}\right)^2
Answer: \left(\dfrac{1}{0.04}\right)^2
The width of a 95% confidence interval for a population proportion is approximately
4 \cdot \frac{\text{sample SD}}{\sqrt{n}}
We don’t know the sample SD before we collect the sample. But for a collection of 0s and 1s, the SD is \sqrt{p(1-p)}, which is never more than 0.5. Using 0.5 gives us the widest possible interval, so the width is at most
4 \cdot \frac{0.5}{\sqrt{n}} = \frac{2}{\sqrt{n}}
We want that to be at most 0.08:
\frac{2}{\sqrt{n}} \leq 0.08 \implies \sqrt{n} \geq \frac{2}{0.08} = \frac{1}{0.04} \implies n \geq \left(\frac{1}{0.04}\right)^2 = 625
The average score on this problem was 41%.
Let W represent the maximum width of a 95\% confidence interval obtained from a sample that is twice as big as the sample size you found in part (a). Which of the following is true?
0 < W < 0.04
W = 0.04
0.04 < W < 0.08
W \geq 0.08
Answer: 0.04 < W < 0.08
The maximum width is \frac{2}{\sqrt{n}}. That means doubling n divides the width by \sqrt{2}, not by 2:
W = \frac{2}{\sqrt{2 \cdot 625}} = \frac{0.08}{\sqrt{2}} \approx 0.057
A bigger sample gives a narrower interval, so W < 0.08. Because the width shrinks with \sqrt{n}, though, doubling the sample size doesn’t cut the width in half, so W > 0.04. To get a width of 0.04 you’d need four times the sample size.
The average score on this problem was 56%.
Consider the following pair of hypotheses:
Null: The proportion of "Comedy"
movies with an average rating above 9 equals the
proportion of "Action" movies with a rating above
9.
Alternative: The proportion of
"Comedy" movies with an average rating above 9 is
greater than the proportion of "Action"
movies with a rating above 9.
Let C_9 be the proportion of
"Comedy" movies with a rating above 9 and let A_9 be the proportion of
"Action" movies with a rating above 9. Which of the
following are valid test statistics to test these hypotheses?
Select all that apply.
C_9 - 0.5
A_9 - 0.5
A_9 \cdot C_9
A_9 + C_9
C_9 - A_9
A_9 - C_9
|A_9 - C_9|
|C_9 - A_9|
Answer: C_9 - A_9 and A_9 - C_9
The hypotheses compare two proportions, and the alternative has a direction (“Comedy is greater”). So a valid test statistic needs to do two things:
C_9 - A_9 and A_9 - C_9 satisfy both. With C_9 - A_9, large positive values point toward the alternative. With A_9 - C_9, large negative values do. Either one works, as long as we calculate the p-value in the matching direction.
The average score on this problem was 82%.
The table below shows how many movies in each of four genres Jack and Eric have seen. What is the total variation distance (TVD) between Jack and Eric’s distribution of movies by genre?
"Musical" |
"Comedy" |
"Action" |
"Horror" |
Total | |
|---|---|---|---|---|---|
| Jack | 2 | 14 | 2 | 2 | 20 |
| Eric | 55 | 15 | 15 | 15 | 100 |
Answer: 0.55
TVD compares two distributions, so first turn each person’s counts into proportions. Jack watched 20 movies and Eric watched 100.
"Musical" |
"Comedy" |
"Action" |
"Horror" |
|
|---|---|---|---|---|
| Jack | 2/20 = 0.10 | 14/20 = 0.70 | 2/20 = 0.10 | 2/20 = 0.10 |
| Eric | 55/100 = 0.55 | 15/100 = 0.15 | 15/100 = 0.15 | 15/100 = 0.15 |
| Absolute difference | 0.45 | 0.55 | 0.05 | 0.05 |
The TVD is half the sum of the absolute differences:
\text{TVD} = \frac{0.45 + 0.55 + 0.05 + 0.05}{2} = \frac{1.10}{2} = 0.55
The average score on this problem was 25%.
Suppose that in movies, the average rating of
"Action" movies is 7.4 and the average rating of
"Horror" movies is 7.2. Based on this data, we decide to
test the following hypotheses:
Null: The ratings of "Action" and
"Horror" movies come from the same distribution.
Alternative: On average, "Action"
movies have a higher rating "Horror" movies.
We’ll use as our test statistic the mean rating of
"Action" movies minus the mean rating of
"Horror" movies.
Fill in the blanks so the code below generates 5000 simulated values of this test statistic and calculates the p-value of our test.
def one_stat(df):
group_means = df.get(["New", "Rating"]).groupby("New").mean().get("Rating")
return group_means.loc[__(a)__] - group_means.loc[__(b)__]
action_horror = movies[(movies.get("Genre") == "Action") |
(movies.get("Genre") == "Horror")]
diffs = np.array([])
for i in np.arange(5000):
new_df = action_horror.assign(New = __(c)__)
diffs = np.append(diffs, __(d)__)
p_value = np.count_nonzero( __(e)__ ) / 5000
(a): "Action"
(b): "Horror"
(c):
np.random.permutation(action_horror.get("Genre"))
(d): one_stat(new_df)
(e): diffs >= 0.2
(a), (b): The test statistic is the mean rating
of "Action" movies minus the mean rating of
"Horror" movies. After groupby("New"), the
genre labels become the index, so we pull out each group’s mean with
.loc["Action"] and .loc["Horror"]. The order
matters: "Action" comes first.
(c): Under the null hypothesis, genre has
nothing to do with rating. So we shuffle the "Genre"
column, which randomly reassigns the genre labels to the ratings. We
only shuffle movies from action_horror, since those are the
only two genres in the test.
(d): We calculate the test statistic on the
shuffled DataFrame. one_stat groups by "New",
the shuffled column, not the original "Genre", which is
exactly why we pass it new_df.
(e): The observed statistic is 7.4 - 7.2 = 0.2. The alternative says
"Action" movies have higher ratings, so large positive
values point toward it. The p-value is the proportion of simulated
statistics that are at least as extreme as the observed
one, meaning greater than or equal to 0.2.
The average score on this problem was 74%.
Suppose that p_value evaluates to 0.14. Using the standard p-value cutoff of
0.05, which of the two hypotheses is
better supported by the data?
Null
Alternative
Answer: Null
The p-value of 0.14 is larger than the 0.05 cutoff, so we fail to reject the null hypothesis. If the null were true, a difference of 0.2 or more would come up about 14% of the time just from random chance. That’s not unusual enough to count as evidence against the null. Note that this doesn’t prove the null is true. It only means the data are consistent with it.
The average score on this problem was 84%.
What kind of hypothesis test did we perform in this question?
Standard hypothesis test
Permutation test
Answer: Permutation test
We were checking whether two samples ("Action" ratings
and "Horror" ratings) come from the same population
distribution. We simulated by shuffling group labels,
which is the defining step of a permutation test. In a standard
hypothesis test, we’d simulate new samples from a known population
distribution that the null hypothesis spells out (for example, flipping
a fair coin with np.random.multinomial). Here, the null
doesn’t give us that distribution, so we shuffle instead.
The average score on this problem was 84%.