â 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 .
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
The average score on this problem was 53%.
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.
Choose the correct formulation of the null and alternative hypotheses.
Null: There is a difference in the average height of treated and untreated flowers. Alt: There is no difference in the average height of treated and untreated flowers.
Null: There is no difference in the average height
of treated and untreated flowers. Alt: There is a
difference in the average height of treated and untreated flowers.
Null: There is no difference in the average height of treated and untreated flowers. Alt: Treated flowers grow taller,on average, than untreated flowers.
Null: Fertilizer use has no impact on flower height. Alt: Fertilizer use causes taller flowers.
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.
The average score on this problem was 70%.
True or False: We could use a permutation test to test these hypotheses.
True
False
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.
The average score on this problem was 80%.
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.
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).
The average score on this problem was 59%.
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.
The average score on this problem was 65%.
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())
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.
The average score on this problem was 75%.
Suppose that the observed value of the test statistic is 0.04. What do we conclude?
Reject the null hypothesis.
Accept the null hypothesis.
Fail to reject the null hypothesis.
Not enough information.
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.
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.
The average score on this problem was 15%.
True or False: We could construct a confidence interval to test these hypotheses.
True
False
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:
Bootstrap the flowers sample:
resample its rows with replacement many times, and calculate the
proportion of fertilized fields in each resample.
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.
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.
The average score on this problem was 83%.