← 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 21-24 of the Winter 2024 offering
of DSC 10.
⚠️ PDF version available here .
It can be hard to find a parking spot on UCSD’s campus! The
parking DataFrame contains UCSD parking occupancy data for
two on-campus parking structures. The "Structure" column
contains either "Gilman" or "Hopkins". Each
row of parking represents one day. The
"Occupancy" column contains a float representing the
proportion of occupied spaces at noon on that day. We’ll use this data
to test the following hypotheses:
Null Hypothesis: At noon, Gilman and Hopkins are equally occupied. The observed differences in our samples are simply due to random chance.
Alternative Hypothesis: At noon, Hopkins is less occupied than Gilman. The observed differences in our samples cannot be explained by random chance alone.
As our test statistic, we will use the mean noontime
"Occupancy" of Hopkins minus the mean noontime
"Occupancy" of Gilman.
Suppose the Series s is defined as below. Write an
expression involving s that evaluates to the observed value
of the test statistic, and store the result in
observed.
s = parking.groupby("Structure").mean().get("Occupancy")
observed = ______
What goes in the blank?
Answer:
s.loc["Hopkins"] - s.loc["Gilman"]
parking.groupby("Structure").mean() makes a DataFrame
with one row per structure, where each value is that structure’s mean.
.get("Occupancy") takes the "Occupancy" column
as a Series whose index is the structure names, "Gilman"
and "Hopkins". .loc looks up a value by its
index label, so s.loc["Hopkins"] is Hopkins’ mean occupancy
and s.loc["Gilman"] is Gilman’s.
The average score on this problem was 61%.
In running the permutation test, we need to do a simulation that runs
many times, using a for-loop. What should be the first
thing we do inside the for-loop?
Initialize an empty array to store our results.
Define a variable for the number of repetitions.
Permute one of the columns of parking.
Calculate the difference in group means.
Answer: Permute one of the columns of
parking.
Each repetition of the simulation needs a new random shuffle. So the
first step inside the loop is to shuffle one column, usually
"Structure", using np.random.permutation.
Shuffling breaks any connection between structure and occupancy, which
is what the null hypothesis says.
Option 1: Initialize an empty array to store our results. Incorrect. This happens before the loop. If it were inside, the array would be reset every repetition and only the last result would be kept.
Option 2: Define a variable for the number of repetitions. Incorrect. This is also set up before the loop, since the loop uses it to know how many times to run.
Option 4: Calculate the difference in group means. Incorrect. This does happen inside the loop, but only after shuffling. Calculating first would just give the observed statistic again.
The average score on this problem was 79%.
Suppose we store 5000 simulated test statistics in the array
differences. Choose the appropriate symbol to fill in the
calculation of the p-value below.
p_value = np.count_nonzero(differences ______ observed) / 5000
<
<=
==
!=
>
>=
Answer: <=
The p-value is the proportion of simulated statistics that are as extreme or more extreme than the observed statistic, in the direction of the alternative hypothesis.
The alternative says Hopkins is less occupied than Gilman.
Since the statistic is Hopkins minus Gilman, that means small (negative)
values of the statistic favor the alternative. So “as or more extreme”
means less than or equal to observed, which is
differences <= observed.
Common mistakes:
>=. That would be correct if
the alternative said Hopkins is more occupied, or if the
statistic were Gilman minus Hopkins.< instead of
<=. The p-value includes simulated values that
are exactly as extreme as the observed one, so the equal case
counts.
The average score on this problem was 65%.
Suppose the p-value of our test is 0.01 and we are testing the hypotheses at the 0.05 significance level. Which hypothesis is better supported by the data?
Null
Alternative
Answer: Alternative
A p-value of 0.01 is less than the significance level of 0.05, so we reject the null hypothesis. The data are more consistent with the alternative: Hopkins is less occupied than Gilman at noon.
Note that rejecting the null doesn’t prove the alternative is true. It only means the observed difference would be unlikely if the null were true.
The average score on this problem was 93%.
UCSD’s parking lots include A spaces for faculty, B spaces for staff, and S spaces for students.
The scatter plot on the left shows the relationship between the number of A spaces and the total number of parking spaces in each region of campus. Similarly, the scatter plot on the right shows the relationship between the number of B spaces and the total number of parking spaces in each region of campus. Note that these numbers represent a count of parking spaces existing on campus, and have nothing to do with occupancy.
Based on these scatter plots, which pair of variables has a larger correlation coefficient?
A Spaces and Total Spaces
B Spaces and Total Spaces
Answer: B Spaces and Total Spaces
The correlation coefficient measures how closely the points follow a straight line. Both plots show a positive association, but the points in the B plot sit much closer to the regression line.
In plot A, many points are far from the line. That scatter around the line means a weaker linear relationship, so a smaller correlation coefficient.
A common mistake is to compare the slopes of the two lines. The correlation coefficient doesn’t depend on how steep the line is. It only measures how tightly the points cluster around it.
The average score on this problem was 86%.
Which of the following variables would most likely be negatively associated with the total number of spaces in a campus region?
Total area of the campus region
Number of athletic fields in the campus region
Number of residents in the campus region
Number of electric vehicle charging stations in the campus region
Answer: Number of athletic fields in the campus region
Two variables are negatively associated if as one variable increases, the other tends to decrease. Athletic fields take up land that could otherwise be used for parking, so regions with more athletic fields would likely have fewer parking spaces.
Total area of the campus region. Positive association. A bigger region has more room for parking.
Number of residents in the campus region. Positive association. More residents means more people who need somewhere to park.
Number of electric vehicle charging stations in the campus region. Positive association. Charging stations are built into parking spaces, so regions with more parking tend to have more of them.
The average score on this problem was 73%.
The number of S spaces and the total number of parking spaces in each campus region are linearly related with a correlation coefficient of 0.6. The number of S spaces in the Warren College region of campus is 5 standard deviations below average. What does the regression line predict for the number of total spaces in Warren College, measured in standard units?
Answer: -3
When both variables are measured in standard units, the regression line is
\text{predicted } y_{\text{(su)}} = r \cdot x_{\text{(su)}}
Warren College’s number of S spaces is 5 standard deviations below average, so x_{\text{(su)}} = -5. With r = 0.6:
\text{predicted } y_{\text{(su)}} = 0.6 \cdot (-5) = -3
So the regression line predicts that Warren College’s total number of spaces is 3 standard deviations below average.
Common mistakes:
The average score on this problem was 64%.
True or False: Since number of parking spaces is always a positive integer, the regression line that predicts the total number of spaces from the number of S spaces must have a positive y-intercept.
True
False
Answer: False
The y-intercept is the line’s prediction when the number of S spaces is 0. The regression line is chosen to fit the data as well as possible, not to give realistic numbers of parking spaces, so its predictions can be negative. Its predictions are most accurate within the range of the data. So if no region has close to 0 S spaces, the y-intercept may not be a realistic value at all.
A common mistake is to treat the regression line as if it had to follow the rules of the data. Its predictions don’t have to be positive or whole numbers.
The average score on this problem was 64%.