Winter 2024 Quiz 5

← 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 18-21 of the Winter 2024 offering of DSC 10.

⚠️ PDF version available here .


That's the end of the quiz.

Problem 1

Lecture 18


Problem 1.1

Suppose you want to estimate the proportion of UCSD students that prefer sunny days over rainy days. You plan to survey 900 students, then construct a 95% confidence interval for this proportion. What is the widest possible width for the resulting confidence interval? Give your answer as a fully simplified fraction.

Answer: \frac{1}{15}

We can think of each student’s response as a 1 (prefers sunny days) or a 0 (prefers rainy days). The proportion of students who prefer sunny days is then the mean of these 0s and 1s, so we can use the CLT to build a confidence interval for it.

A 95% confidence interval goes 2 SDs of the sample mean in each direction from the sample mean, so its width is 4 \cdot \frac{\text{sample SD}}{\sqrt{\text{sample size}}}. To make the width as large as possible, we need the sample SD to be as large as possible.

For a collection of 0s and 1s, the SD is largest when there are equally many 0s and 1s, and in that case the SD is 0.5. So the widest possible width is 4 \cdot \frac{0.5}{\sqrt{900}} = \frac{2}{30} = \frac{1}{15}.


Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 38%.


Problem 1.2

If you decide to survey 450 students instead of 900 students for your sample, the maximum possible width of your 95% confidence interval would:

Answer: increase by less than double

The sample size is under a square root in the formula for the width, 4 \cdot \frac{0.5}{\sqrt{\text{sample size}}}. Cutting the sample size in half doesn’t double the width. It multiplies the width by \sqrt{2}.

With 450 students, the widest possible width is 4 \cdot \frac{0.5}{\sqrt{450}} = \frac{2}{\sqrt{450}}. Compared to the width with 900 students, this is \frac{\sqrt{900}}{\sqrt{450}} = \sqrt{2} \approx 1.41 times as large. Since 1.41 is less than 2, the width increases by less than double.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 60%.



Problem 2

Lecture 20

Bill claims that San Diego is sunny 60% of the year, but you think the percentage is higher. You decide to test the validity of Bill’s claim by running a hypothesis test.


Problem 2.1

Both your null and alternative hypotheses will take this form:

The percentage of sunny days in San Diego is ______ 60%.

(i) For the null hypothesis, how should we fill in the blank?

(ii) For the alternative hypothesis, how should we fill in the blank?

Answer (i): equal to

The null hypothesis is Bill’s claim, and it has to give an exact value we can simulate under. “The percentage of sunny days in San Diego is equal to 60%” tells us exactly what probability to use in a simulation.


Difficulty: ⭐️⭐️

The average score on this problem was 89%.

Answer (ii): greater than

The alternative hypothesis is what you believe instead of Bill’s claim. You think the percentage is higher than 60%, so the alternative hypothesis is that the percentage of sunny days is greater than 60%.


Difficulty: ⭐️⭐️

The average score on this problem was 75%.


Problem 2.2

Say that in 2023, San Diego had 235 sunny days. Using the number of sunny days per year as the test statistic, fill in the following code to run the hypothesis test and store the p-value of your test in p_val. We’ll assume that all years have 365 days.

    observed_stat = ___(w)___
    results = np.array([])

    for i in np.arange(10000):
        result = np.___(x)___(365, ___(y)___)[0] 
        results = np.append(results, result)

    p_val = np.count_nonzero(results __(z)__ observed_stat) / 10000

Answer (w): 235

The test statistic is the number of sunny days in a year, so the observed statistic is the number of sunny days we actually saw in 2023, which is 235.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 58%.

Answer (x): random.multinomial

np.random.multinomial(365, ...) simulates 365 days, where each day is randomly assigned to a category based on the given probabilities. It returns an array with the number of days that landed in each category.


Difficulty: ⭐️

The average score on this problem was 93%.

Answer (y): [0.6, 0.4]

We simulate under the null hypothesis, so each day has a 60% chance of being sunny and a 40% chance of not being sunny. The first category must be sunny days, because we take [0] from the result to get the number of sunny days in the simulated year.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 65%.

Answer (z): >=

The p-value is the proportion of simulated statistics that are equal to, or at least as extreme as, the observed statistic, in the direction of the alternative hypothesis. Our alternative hypothesis is that the percentage is greater than 60%, so more sunny days counts as more extreme. We count the simulated years with at least 235 sunny days.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 67%.



Problem 2.3

Suppose the p-value of this hypothesis test is 0.1. Which of the following statements is a correct interpretation of this p-value?

Answer: If the null hypothesis is true, there is a 10% chance of obtaining a test statistic equal to, or at least as extreme as, the observed statistic.

The p-value is calculated by simulating under the null hypothesis, so it tells us how likely our results are if the null hypothesis is true. That rules out the last option, which assumes the alternative hypothesis is true.

The p-value counts outcomes that are equal to or more extreme than the observed statistic, not just outcomes exactly equal to it. That rules out the first two options.

A p-value of 0.1 means that, if the null hypothesis is true, there is a 10% chance of getting a test statistic equal to, or at least as extreme as, the observed statistic.


Difficulty: ⭐️⭐️

The average score on this problem was 76%.



Problem 3

Lecture 21

Charlie spends 100 days in each of three California cities (San Diego, San Francisco, and Los Angeles). He records the primary weather for each day in each location. The table below shows these values as proportions. For example, 43 of the 100 days that Charlie spent in San Diego had primarily sunny weather.

Weather San Diego San Francisco Los Angeles
sunny 0.43 0.51 0.34
partly cloudy 0.24 0.18 0.22
cloudy 0.22 0.15 0.26
rainy 0.11 0.16 0.18


Problem 3.1

What is the total variation distance between the San Diego and San Francisco weather distributions? Give your answer as an exact decimal.

Answer: 0.13

To find the total variation distance (TVD), we take the absolute difference between the two distributions in each category, add them up, and divide by 2.

The absolute differences between San Diego and San Francisco are |0.43 - 0.51| = 0.08 for sunny, |0.24 - 0.18| = 0.06 for partly cloudy, |0.22 - 0.15| = 0.07 for cloudy, and |0.11 - 0.16| = 0.05 for rainy.

Adding these gives 0.08 + 0.06 + 0.07 + 0.05 = 0.26, and dividing by 2 gives a TVD of \frac{0.26}{2} = 0.13.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 74%.


Problem 3.2

Charlie reconsiders his weather categories and decides to count any “partly cloudy” days as “cloudy” days, thereby combining these two categories into one. If he recalculates the TVD between any pair of cities, what will he find?

Answer: The new TVD is less than or equal to the old TVD.

When we combine “partly cloudy” and “cloudy” into one category, the two differences in those categories get added together before we take the absolute value. If the two differences have the same sign, combining them doesn’t change anything, and the TVD stays the same. If they have opposite signs, they partially cancel out, and the TVD gets smaller. Combining categories can never make the TVD larger.

For example, between San Diego and San Francisco, San Diego has more partly cloudy days (0.24 vs. 0.18) and more cloudy days (0.22 vs. 0.15). Both differences go in the same direction, so the combined category has an absolute difference of |0.46 - 0.33| = 0.13, which is the same as the old 0.06 + 0.07 = 0.13. The TVD stays the same.

Between San Diego and Los Angeles, San Diego has more partly cloudy days (0.24 vs. 0.22) but fewer cloudy days (0.22 vs. 0.26). The differences go in opposite directions, so the combined category has an absolute difference of |0.46 - 0.48| = 0.02, which is smaller than the old 0.02 + 0.04 = 0.06. The TVD goes down.

Since the TVD can stay the same for some pairs and go down for others, the new TVD is less than or equal to the old TVD.


Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 39%.



👋 Feedback: Find an error? Still confused? Have a suggestion? Let us know here.