Winter 2024 Quiz 6

← 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 .


That's the end of the quiz.

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:

As our test statistic, we will use the mean noontime "Occupancy" of Hopkins minus the mean noontime "Occupancy" of Gilman.


Problem 1

Lecture 22


Problem 1.1

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.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 61%.


Problem 1.2

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?

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.


Difficulty: ⭐️⭐️

The average score on this problem was 79%.


Problem 1.3

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:

  • Using >=. That would be correct if the alternative said Hopkins is more occupied, or if the statistic were Gilman minus Hopkins.
  • Using < instead of <=. The p-value includes simulated values that are exactly as extreme as the observed one, so the equal case counts.

Difficulty: ⭐️⭐️⭐️

The average score on this problem was 65%.


Problem 1.4

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?

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.


Difficulty: ⭐️

The average score on this problem was 93%.



Problem 2

Lecture 24

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.


Problem 2.1

Based on these scatter plots, which pair of variables has a larger correlation coefficient?

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.


Difficulty: ⭐️⭐️

The average score on this problem was 86%.


Problem 2.2

Which of the following variables would most likely be negatively associated with the total number of spaces in a 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.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 73%.


Problem 2.3

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:

  • Answering -5. That assumes a perfect correlation (r = 1). Because r = 0.6, the prediction is pulled closer to the average. This is called regression to the mean.
  • Answering 5 or 3. “Below average” means a negative value in standard units.

Difficulty: ⭐️⭐️⭐️

The average score on this problem was 64%.


Problem 2.4

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.

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.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 64%.



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