Winter 2025 Quiz 4

← return to practice.dsc10.com


This quiz was administered in-person. Students were allowed a double-sided sheet of handwritten notes. Students had 20 minutes to work on the quiz.

This quiz covered Lectures 18-21 of the Winter 2025 offering of DSC 10.

⚠️ PDF version available here .


Problem 1

Lecture 18

You want to estimate the proportion of all flower fields in the world that use fertilizer. You will create a 68% confidence interval for this proportion, based on a sample of flower fields. You want your confidence interval to have a width of at most 0.01. Using the fact that the standard deviation of any dataset of 0s and 1s is no more than 0.5, calculate the minimum sample size required. Give your answer as an integer.

Answer: 10,000

By the Central Limit Theorem, the distribution of the sample proportion is roughly normal, with

\text{SD of sample proportion} = \frac{\text{population SD}}{\sqrt{n}}

A 68% confidence interval covers about 1 SD on either side of the sample proportion, so

\text{width} = 2 \cdot \frac{\text{population SD}}{\sqrt{n}}

The population SD of 0s and 1s is at most 0.5, so the worst case is:

2 \cdot \frac{0.5}{\sqrt{n}} \le 0.01 \;\Longrightarrow\; \frac{1}{\sqrt{n}} \le 0.01 \;\Longrightarrow\; \sqrt{n} \ge 100 \;\Longrightarrow\; n \ge 10000


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 53%.


Problem 2

Lecture 22

A researcher collects data on many flowers, some of which have been treated with fertilizer and some of which have not (untreated). The researcher wants to determine whether there is a relationship between fertilizer use and the height of the flowers.


Problem 2.1

Choose the correct formulation of the null and alternative hypotheses.

Answer: B

  • The null hypothesis has to be the “nothing interesting is happening” model, so option 1 is backwards.

  • The researcher wants to know whether there is a relationship between fertilizer and height. No direction is given, so the alternative should be two-sided (“there is a difference”), not “treated flowers grow taller” (option 3).

  • Option 4 talks about causation. This is observational data (the researcher only collects data and does not randomly assign fertilizer), so a hypothesis test can’t show that fertilizer causes taller flowers.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 70%.


Problem 2.2

True or False: We could use a permutation test to test these hypotheses.

Answer: True

The question is whether two samples (treated and untreated) come from the same population distribution. That is exactly what a permutation test checks. We shuffle the treated/untreated labels, recompute a statistic such as the absolute difference in group means each time, and compare the observed statistic to that simulated distribution.


Difficulty: ⭐️⭐️

The average score on this problem was 80%.



Problem 3

Lecture 21

The DataFrame flowers contains information on a sample of flower fields. Each row corresponds to a different flower field. The "Fertilizer" column contains Boolean values corresponding to whether each flower field uses fertilizer.

You wonder if it could be the case that flower fields are fertilized at random, with each flower field having an 80% chance of being fertilized, independently of all others. You decide to do a hypothesis test to determine whether this could or could not be the case, testing at the p=0.05 significance level. You will use as your test statistic the absolute difference between 0.8 and the proportion of fertilized flower fields.


Problem 3.1

Complete the implementation of the function one_stat, which calculates one simulated value of this test statistic, under the assumptions of the null hypothesis. Note that the optional argument p in np.random.choice specifies the probabilities with which each element is chosen (here, there is a 0.8 probability of selecting True).

def one_stat():
    sample_size = __(a)__
    random_choice = (np.random.choice([True, False], 
                     sample_size, p=[0.8, 0.2]))
    return __(b)__

(a): flowers.shape[0]

Each simulated sample has to be the same size as the observed sample, the number of rows in flowers. If we simulated a different sample size, the simulated statistics wouldn’t be comparable to the observed one. len(flowers) or flowers.shape[0] both work.

(b): np.abs(0.8 - random_choice.mean())

What random_choice looks like: say there are 5 fields. Then np.random.choice([True, False], 5, p=[0.8, 0.2]) might give

array([ True,  True, False,  True,  True])

Each entry is one pretend flower field, fertilized (True) with probability 0.8.

To get the proportion of Trues, use the fact that Python treats True as 1 and False as 0:

  • random_choice.sum() → 4 (the count of fertilized fields)

  • random_choice.mean() → 4/5 = 0.8 (the proportion of fertilized fields)

Then we apply the same formula used for the observed statistic: np.abs(0.8 - proportion).


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 59%.



Problem 3.2

Complete the implementation of the function one_stat_differently, which also calculates one simulated value of this test statistic under the null.

def one_stat_differently():
    multi = np.random.multinomial(__(c)__)
    return __(d)__

(c): flowers.shape[0], [0.8, 0.2]

np.random.multinomial(n, pvals) takes two arguments:

  • n: how many items to draw (our sample size, flowers.shape[0])

  • pvals: the probability of each category ([0.8, 0.2] for fertilized and not fertilized)

(d): np.abs(0.8 - multi[0] / flowers.shape[0])

Unlike np.random.choice, np.random.multinomial doesn’t return the individual draws. It returns the count in each category. With 5 fields, multi might be

array([4, 1])

which means “4 fields fertilized, 1 not.” So:

  • multi[0] is the count of fertilized fields (4).

  • multi[0] / flowers.shape[0] is the proportion of fertilized fields (0.8).

Then we calculate the same test statistic as before.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 65%.


Problem 3.3

Fill in the blanks to calculate 10,000 simulated values of the test statistic and collect them in an array called many_stats. You can use the functions you’ve already written to help you.

        many_stats = __(e)__
        for i in np.arange(10000):
            many_stats = __(f)__

(e): np.array([])

np.array([]) is an empty array to collect the results in. This is the standard simulation pattern: start empty, then add one result each time through the loop.

(f): np.append(many_stats, one_stat())

  • Each time through the loop, one_stat() runs a brand new random simulation and returns one value of the test statistic.
  • np.append returns a new array with that value added to the end. It doesn’t change many_stats in place, so the result has to be stored back in many_stats. That’s why the line starts with many_stats = ....

After the loop, many_stats holds 10,000 values. Together they show what the test statistic tends to look like when the null is true.

one_stat_differently() would work just as well.


Difficulty: ⭐️⭐️

The average score on this problem was 75%.


Problem 3.4

Suppose that the observed value of the test statistic is 0.04. What do we conclude?

Answer: Not enough information.

To decide, we would calculate the p-value:

p_value = np.count_nonzero(many_stats >= 0.04) / 10000

That’s the proportion of simulated statistics at least as extreme as the observed one (≥, because large values favor the alternative). Then:

  • If p_value < 0.05, reject the null.

  • If p_value >= 0.05, fail to reject the null.

The problem: we don’t know the simulated distribution. Whether 0.04 is unusual depends heavily on the sample size, which the quiz never gives.

  • Small sample (say 25 fields): sample proportions often land 0.04 or more away from 0.8 just by chance. Even a single field changes the proportion by 0.04. So 0.04 would be completely ordinary, the p-value would be large, and we would fail to reject.
  • Large sample (say 10,000 fields): the sample proportion almost always lands very close to 0.8 (the SD of the sample proportion is about \sqrt{\frac{0.8 \cdot 0.2}{10000}} = 0.004). A difference of 0.04 would be about 10 SDs away, extremely unlikely. The p-value would be about 0, and we would reject.

The same observed value supports opposite conclusions depending on information we don’t have, so the answer is Not enough information.

Why not the other options?

  • Accept the null hypothesis: never correct. A hypothesis test can’t prove the null is true. At most, the data is consistent with it.

  • Reject / Fail to reject: either one could be right, but we can’t tell which without the p-value.


Difficulty: ⭐️⭐️⭐️⭐️⭐️

The average score on this problem was 15%.



Problem 3.5

True or False: We could construct a confidence interval to test these hypotheses.

Answer: True

A confidence interval can test a hypothesis when the null hypothesis says a population parameter equals a specific value. Here, the null says the population proportion of fertilized fields is 0.8, which fits.

How to do it:

  1. Bootstrap the flowers sample: resample its rows with replacement many times, and calculate the proportion of fertilized fields in each resample.

  2. Take the middle 95% of those bootstrapped proportions (the 2.5th to 97.5th percentiles) as a 95% confidence interval. Use 95% because the significance level is 0.05 = 1 − 0.95.

  3. Check whether 0.8 is inside:

    • 0.8 is outside the interval: 0.8 isn’t a plausible value for the true proportion, so reject the null.

    • 0.8 is inside the interval: 0.8 is a plausible value, so fail to reject the null.

This works because the null hypothesis is a claim about the value of a population parameter.


Difficulty: ⭐️⭐️

The average score on this problem was 83%.



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