Midterm Exam Version B: Questions and Answers
Grading summary and example answers
Midterm exam grading summary
The table summarizes fractional credit earned for each grading criterion across all 96 graded exams from both sections and all three versions (A, B, and C). The versions contain the same questions in a different order, with the multiple-choice options rearranged, so every version’s page reports the same statistics; this page lists each criterion under its Version B question number. Assigned points gives each criterion’s maximum; these weights sum to 100 points. A fractional score of 1 represents full credit, 0.5 represents half credit, and 0 represents no credit.
The mean, sample standard deviation (SD), and histogram are computed below. The mean is the average fraction of credit earned, rather than the share of students receiving full credit.
Try each question before expanding its example answer. The original exam allowed 50 minutes for 100 points.
Instructions. Answer all 27 numbered questions. For each MCQ, select one option. A “Both” option is correct only if both referenced choices are correct. Question 21 contains four separate MCQs. Complete the requested blanks. The CSV-import short answer requires one line of R code; the other short answers require interpretation, explanation, or arithmetic. Assume dplyr is loaded. The flights excerpt is adapted from real data as noted on its reference page; other examples are fictional.
50 minutes | 100 points. Concepts and statistical reasoning: 50 points; coding, including interpreting R code and its output: 50 points. Point values appear with each question.
Multiple choice: concepts and R fundamentals
Question 1 (3 points)
Six customers’ recorded waits are 2, 3, 4, 5, 6, and 45 minutes. For a sensitivity check, replace only 45 with 105, keeping the other five waits unchanged. Which comparison of the resulting mean and median is correct?
A. The mean increases by 10 minutes; the median remains 4.5 minutes.
B. Both the mean and median increase by 10 minutes.
C. The mean is unchanged; the median increases by 10 minutes.
D. The mean increases by 12 minutes; the median remains 4.5 minutes.
A. The total increases by 105 - 45 = 60 minutes across the same six customers, so the mean increases by 60/6 = 10 minutes (from 65/6 to 125/6). The two middle waits remain 4 and 5, so the median remains (4 + 5)/2 = 4.5 minutes. This states an exact sensitivity comparison rather than assuming that a measure is universally best.
Question 2 (4 points)
The following excerpt from skimr::skim(orders) summarizes 10 fictional orders. amount is in dollars; items is the number of items ordered. Only selected output fields are shown.
Number of rows 10
Variable type: numeric
skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100
1 amount 2 0.8 40 22.7 10 27.5 35 52.5 80
2 items 1 0.9 2 1 1 1 2 2 4
Which statement is justified by this output?
A. The middle 50% of observed amounts span $22.7, as measured by the IQR.
B. The recorded amounts total $400 because there are 10 orders with a mean of $40.
C. The 8 observed values in the variable amount have a mean of $40 and a median of $35.
D. Exactly 8 orders have both amount and items recorded.
C. There are 10 - 2 = 8 observed amounts. Their mean is $40, and p50 gives their median, $35. complete_rate = 0.8 applies to the amount column, not to complete rows across both columns. The output does not identify whether the missing values occur in the same rows; either 7 or 8 orders could have both values recorded. The recorded amounts total 8 x $40 = $320, not $400. For amount, p25 and p75 give Q1 = $27.5 and Q3 = $52.5. The IQR is $52.5 - $27.5 = $25, the span of the middle 50% of the observed amounts. The sd column reports the sample SD, approximately $22.7; that is a different measure of spread.
Question 3 (1 point)
Assume the readr package is already installed. Which command loads the readr package so that you can use read_csv()?
A. library(readr)
B. install.packages("readr")
C. class(readr)
D. read_csv(readr)
A. library(readr) loads the installed package for use. read_csv() is a function from readr; installing a package and loading an installed package are different operations.
Question 4 (1 point)
In round(6.274, digits = 1), which statement is correct?
A. digits is an argument value and 1 is a parameter name.
B. Omitting x = means no value was supplied for x.
C. The expression returns 6.274 because the default is always used.
D. digits is a parameter name; 1 is its supplied argument value.
D. digits is a parameter name and 1 its supplied argument value. The value 6.274 is supplied positionally for x; the result is 6.3.
Question 5 (3 points)
For x <- c(3, 6, 9, 12), what does x[x >= 6 | x < 12] return?
A. c(6, 9, 12)
B. c(3, 6, 9, 12)
C. c(6, 9)
D. c(TRUE, TRUE, TRUE, TRUE)
B. c(3, 6, 9, 12). Each value meets at least one condition: 3 is below 12, 12 is at least 6, and 6 and 9 meet both. OR therefore retains all four values. Logical indexing returns the selected values, rather than the TRUE/FALSE test itself.
Question 6 (1 point)
Which question is prescriptive?
A. How many lunches will students buy tomorrow?
B. How many meals did the dining hall serve yesterday?
C. Why did lunch demand rise last week?
D. How many serving stations should open tomorrow to meet demand within the staffing budget?
D. It recommends an action subject to a staffing-budget constraint. The other choices summarize the past, investigate a cause, or forecast demand.
Question 7 (1 point)
A manager wants the number of Noise requests per borough from a stored database, followed by a chart in R. Which statement correctly describes the workflow?
A. Reading an exported CSV into R is itself the same operation as querying the stored database with SQL.
B. An SQL query must change the stored request records before it can return a summary.
C. RStudio is the database-query language, while SQL is the environment in which R code is written.
D. An SQL query can return a summary table; R can analyze or visualize it, using RStudio as a working environment.
D. SQL requests data or summaries from database tables; the result can be a smaller table used in R for analysis and visualization. RStudio is a working environment, not a query language. Requesting a summary need not alter the underlying records, and importing a CSV is a different operation from querying its source database.
Question 8 (2 points)
An orders table’s schema requires a nonmissing, unique order_id and a numeric total recorded in dollars. ID 104 already exists; 105 is unused. A new sale was actually $25. Which proposed record satisfies these stated schema rules but misstates the sale amount?
A. order_id = NA, total = 25
B. order_id = 105, total = 2500
C. order_id = 104, total = 25
D. order_id = 105, total = "twenty-five"
B. The record with new ID 105 and numeric total 2500 satisfies the stated structure and uniqueness rules but records the wrong amount for a $25 sale. The other choices repeat an existing ID, use text for a numeric field, or omit a required ID. Schema compliance checks structure; it does not by itself establish factual accuracy.
Data reference: NYC flights (exam copy)
flights15 is the complete data frame used in the transformation questions. It is adapted from the first 15 observations of nycflights13::flights (version 1.0.2), with six selected columns. Each row represents a flight departing the NYC area on January 1, 2013. For this exam, the third observation’s dep_delay is set to NA to represent a missing value. All other values and the original row order are unchanged.
| Row* | origin | dest | carrier | flight | dep_delay | distance |
|---|---|---|---|---|---|---|
| 1 | EWR | IAH | UA | 1545 | 2 | 1400 |
| 2 | LGA | IAH | UA | 1714 | 4 | 1416 |
| 3 | JFK | MIA | AA | 1141 | NA | 1089 |
| 4 | JFK | BQN | B6 | 725 | -1 | 1576 |
| 5 | LGA | ATL | DL | 461 | -6 | 762 |
| 6 | EWR | ORD | UA | 1696 | -4 | 719 |
| 7 | EWR | FLL | B6 | 507 | -5 | 1065 |
| 8 | LGA | IAD | EV | 5708 | -3 | 229 |
| 9 | JFK | MCO | B6 | 79 | -3 | 944 |
| 10 | LGA | ORD | AA | 301 | -2 | 733 |
| 11 | JFK | PBI | B6 | 49 | -2 | 1028 |
| 12 | JFK | TPA | B6 | 71 | -2 | 1005 |
| 13 | JFK | LAX | UA | 194 | -2 | 2475 |
| 14 | EWR | SFO | UA | 1124 | -2 | 2565 |
| 15 | LGA | DFW | AA | 707 | -1 | 1389 |
Row is a printed reference label, not a variable in flights15.
| Variable | Description |
|---|---|
origin |
Departure airport code: EWR (Newark), JFK (John F. Kennedy), LGA (LaGuardia). |
dest |
Destination airport code. |
carrier |
Airline code: UA, AA, B6, DL, or EV; a category label. |
flight |
Airline flight number; an integer identifier, not a quantity or globally unique key. |
dep_delay |
Departure delay in minutes: positive = late; negative = early; 0 = on time; NA = missing. |
distance |
Flight distance in miles. |
origin, dest, and carrier are character variables. The last three columns are numeric (the flight number is an integer identifier). Use only these 15 rows, not the full flights dataset. You need no internet connection or data download to answer.
Adapted from: Official nycflights13 flights documentation; underlying data from the U.S. Bureau of Transportation Statistics.
Multiple choice: transforming flights15
Refer to the printed data reference page.
Question 9 (4 points)
Which record is first in this result? Sort airport codes alphabetically.
flights15 |>
arrange(origin, desc(distance)) |>
select(flight, origin, dest)A. Flight 194: JFK to LAX
B. Flight 1545: EWR to IAH
C. Flight 5708: LGA to IAD
D. Flight 1124: EWR to SFO
D. EWR comes before JFK and LGA. Among EWR flights, the greatest distance is 2565 miles, for flight 1124 to SFO (original row 14).
Question 10 (2 points)
Which statement correctly describes flights15 |> distinct(origin, carrier)?
A. It drops the carrier column while keeping every original flight row.
B. It keeps one row per origin, even when that origin has several different carriers.
C. Both B and E
D. It sorts the original flight rows by origin and carrier without removing repeated pairs.
E. It keeps one row for each distinct origin-carrier pair and returns only those two columns.
E. It keeps the first occurrence of each distinct origin-carrier combination and returns only those two named columns. The same origin can appear more than once when its carrier differs. distinct() is not a sorting operation. The “Both” option is incorrect: one row per origin would lose different carriers at the same origin.
Question 11 (3 points)
Choose the two blanks, in order, so the result contains exactly origin, dest, and miles, where miles contains the original distance values.
flights15 |>
________(origin, dest, distance) |>
rename(________________)A. select; dep_delay = distance
B. select; distance = miles
C. Both D and E
D. rename; miles = distance
E. select; miles = distance
F. filter; miles = distance
E. select keeps the three columns; rename(miles = distance) uses new_name = old_name. The result has 15 rows and the columns origin, dest, and miles. Reversing the expression to distance = miles tries to rename an existing miles column, which is not present at that step. No assignment changes flights15. The “Both” option is incorrect: using rename for the first blank gives an error because its renaming inputs must be named. It does not select a subset of columns.
Question 12 (4 points)
Using only flights15 on the data reference page, which option identifies all listed expressions that keep exactly the UA flights that departed late?
A. flights15 |> filter(carrier == "UA", dep_delay > 0)
B. flights15 |> filter(carrier == "UA", dep_delay < 0)
C. flights15 |> filter(carrier == "UA" | dep_delay > 0)
D. flights15 |> filter(origin == "UA", dep_delay > 0)
E. Both A and F
F. flights15 |> filter(carrier == "UA" & dep_delay > 0)
E. The comma and & expressions are both correct. They require the UA condition and positive departure delay together, returning flights 1545 and 1714. OR also retains early UA flights, so it is not correct. Flight 1141 has a missing departure delay in this exam data frame; its OR condition is FALSE | NA, which is NA, so filter() drops it. The negative-delay expression keeps early UA flights; comparing origin with "UA" tests an airport code against an airline code.
Combining tables and handling missing values
Use these fictional data frames for questions about visits and locations. For flights15, use the printed data reference page. visits has one row per visit; locations is a lookup that accidentally repeats a key. visit_id identifies a visit; location_code is the shared matching code; city is a location’s city name.
visits
visit_id |
location_code |
|---|---|
| 201 | X |
| 202 | Y |
| 203 | Q |
locations
location_code |
city |
|---|---|
| X | Albany |
| Y | Buffalo |
| Y | Syracuse |
| Z | Ithaca |
Question 13 (5 points)
Use the flights15 data frame on the data reference page.
- Complete the two blanks to save only rows with a nonmissing departure delay as
observed_flights. (3 points: 1 for the function, 2 for the condition.)
observed_flights <- flights15 |>
________(________________)The completed
filter()condition would ________ a row whosedep_delayisNA. (keep / drop) (1 point)After this assignment, the original
flights15data frame is ________. (changed / unchanged) (1 point)
a. filter; !is.na(dep_delay). is.na(dep_delay) checks whether the departure delay is missing, and ! negates that check. An equivalent nonmissing-value condition also works.
observed_flights <- flights15 |> filter(!is.na(dep_delay))b. Drop. For a missing delay, is.na(dep_delay) is TRUE, so !is.na(dep_delay) is FALSE. filter() keeps only rows whose condition is TRUE.
c. Unchanged. The result is assigned to a new object, observed_flights. It contains 14 rows: all except the row with a missing departure delay. The original flights15 still has 15 rows, including the missing delay.
Question 14 (2 points)
After visits |> left_join(locations, by = "location_code"), which city value is attached to visit 203?
A. "Ithaca"
B. NA
C. Visit 203 is removed.
D. 0
B. Location Q has no matching lookup record. The left join retains visit 203 with city = NA; this is missing information, not a zero or empty text value.
Question 15 (3 points)
How many rows does visits |> left_join(locations, by = "location_code") return?
A. 5
B. 3
C. 2
D. 4
D. There is one row for visit 201, two for visit 202 (two Y matches), and one unmatched row for visit 203: 1 + 2 + 1 = 4.
Question 16 (3 points)
Which statement correctly interprets visits |> left_join(locations, by = "location_code")?
A. The unused Z lookup row adds a visit to Ithaca.
B. An unmatched visit is dropped, and every lookup row creates a new visit.
C. Both D and E
D. The repeated Y key can multiply a visit; the unused Z key does not create a visit.
E. The first visit always receives the first city because joins match row positions.
D. Y has two right-table matches, so visit 202 is repeated. Z is unused by visits; its Ithaca row does not create a new visit. Matching uses key values, not row positions. The “Both” option is incorrect because its claim that joins match row positions is false.
Question 17 (4 points)
Which option identifies all expressions that keep every visit and add matching city information using location_code?
A. visits |> left_join(locations, by = "city")
B. locations |> left_join(visits, by = "location_code")
C. visits |> left_join(locations, by = "visit_id")
D. visits |> left_join(locations)
E. Both D and F
F. visits |> left_join(locations, by = "location_code")
E. Both the explicit-key and omitted-key expressions give the required left join. The two tables share only one column name, location_code, so left_join() uses that column when by is omitted. visits stays on the left. The reversed join keeps the wrong main table; city and visit_id are not shared keys in these tables.
R expressions: fill in the blanks and multiple choice
Question 18 (2 points)
Assume bonus and result have not been defined. Run these lines in order. What happens?
start <- 8
result <- start + bonusA. An error occurs, and result is created.
B. An error occurs, and result is not created.
C. result is created with the value NA.
D. result is created with the value 8.
E. bonus is created with the value 8.
B. The second line produces an error because bonus has not been defined. R must calculate the right-hand side before assigning a result. Consequently, result is not created; start remains 8.
Question 19 (6 points)
Run these assignments, then give the complete vector returned by each expression.
x <- c(-2, 4)
y <- c(3, -1)x + 2 * yreturns: ______________________________ (2 points)(x + y)^2 - x * yreturns: ______________________________ (4 points)
a. c(4, 2). Multiplication occurs before addition: 2 * y is c(6, -2), then addition pairs those values with x.
b. c(7, 13). x + y gives c(1, 3), so (x + y)^2 gives c(1, 9). The element-by-element product x * y is c(-6, -4). Subtracting corresponding elements gives c(1 - (-6), 9 - (-4)).
Fill in the blanks: tidy data
Question 20 (3 points)
Complete the three rules for a tidy data frame. (1 point per blank)
Each row represents one ________________________.
Each column represents one ________________________.
Each cell contains one ________________________.
a. observation
b. variable
c. value
Each observation occupies a row, each variable occupies a column, and each value occupies a cell.
Multiple choice: measurement scales
Question 21 (6 points)
The fictional data frame race_results has one row per runner’s result in a particular race.
finish_place |
event_year |
avg_speed_kmh |
timing_method |
|---|---|---|---|
| 2 | 2024 | 12.5 | Chip |
| 8 | 2025 | 10.0 | Manual |
| 1 | 2026 | 15.0 | Video |
Variable descriptions
finish_place: Official finishing position within that runner’s race.
event_year: Calendar year (CE) in which the race was held.
avg_speed_kmh: Runner’s average speed over the course, in kilometers per hour.
timing_method: Method used to record the finish: chip sensor, stopwatch, or video.
(a) What is the measurement scale of event_year? Select one answer. (2 points)
A. Interval; B. Ordinal; C. Ratio; D. Nominal
(b) What is the measurement scale of avg_speed_kmh? Select one answer. (2 points)
A. Interval; B. Nominal; C. Ratio; D. Ordinal
(c) What is the measurement scale of timing_method? Select one answer. (1 point)
A. Ratio; B. Nominal; C. Ordinal; D. Interval
(d) What is the measurement scale of finish_place? Select one answer. (1 point)
A. Nominal; B. Ordinal; C. Interval; D. Ratio
(a) A. Interval. Calendar-year differences are meaningful, but the calendar origin is conventional rather than a natural zero for ratios of year labels. An answer of Ordinal earned partial credit: years do have an order, but the ordinal scale misses that consecutive years are separated by equal one-year intervals, which is what makes differences such as 2026 - 2024 = 2 years meaningful.
(b) C. Ratio. Speed has equal measurement units and a meaningful zero; for example, 15 km/h is 1.5 times 10 km/h.
(c) B. Nominal. The recording methods are category names without an inherent ranking.
(d) B. Ordinal. Finishing positions rank runners; a one-place gap does not specify an equal difference in finishing time or performance.
Data tools and interpretation
Question 22 (2 points)
A student reads orders.csv into an R data frame named orders, changes that object, and saves only the R script. No export or database-update command is run. Which statement is correct?
A. Saving the script automatically writes the transformed table values into orders.csv.
B. The R object can change while orders.csv stays unchanged; reading that CSV does not by itself mean a database was queried.
C. The CSV file is a DBMS that automatically synchronizes changes from the R object.
D. Reading the CSV makes subsequent changes to the R object automatically update the original orders.csv file.
B. A CSV stores table values as text; the R data frame is an object used for analysis. Changing it and saving the script does not automatically export its current values or update a database. A script records instructions, and a CSV import is not necessarily a database operation.
Question 23 (4 points)
A Geneseo cafe records whether each order is ready or delivered on time. The diagram groups those orders by order type, delivery distance, and whether they were placed during a busy hour. Each box summarizes the recorded orders in that group.
(a) This type of model is called a ________________________. (1 point)
(b) For a delivery order, a distance of 4 km, and busy hour = Yes, the on-time percentage shown in the matching final box is ________%. (1 point)
(c) Does the percentage in (b) guarantee that the next order in this situation will be on time? Answer yes or no and explain in one sentence, using a fact from that box. (2 points)
a. Decision tree.
b. 66%. Follow Delivery, then distance at most 5 km, then Busy hour = Yes. The final box contains 100 recorded orders, with 66% on time and 34% late.
c. No. For example: “No; 34% of the recorded orders in that group were late, so the next order is not guaranteed to be on time.” Equivalently, 34 of the 100 recorded orders were late. The percentage describes past orders in this group; it does not make the next outcome certain.
Short answer: CSV import
Question 24 (3 points)
Assume that readr is installed but not loaded and R’s working directory is /Users/geneseo/Documents/danl-ex-q.
The provided exam flights data frame is stored at the absolute pathname:
/Users/geneseo/Documents/danl-ex-q/data/flights15.csv.
Write exactly one physical line of R code that reads that CSV and assigns the resulting data frame to flight_copy. Use the relative pathname.
flight_copy <- readr::read_csv("data/flights15.csv")The readr:: prefix calls the package’s function without a separate library(readr) command; a bare read_csv() call fails because readr is not loaded. Base R’s read.csv("data/flights15.csv") also works, as does a single line that loads the package before the assignment, such as library(readr); flight_copy <- read_csv("data/flights15.csv"). The relative pathname data/flights15.csv is read from the working directory /Users/geneseo/Documents/danl-ex-q.
Short answer: interpretation and reasoning
Question 25 (9 points)
Three customers wait 2, 4, and 6 minutes. Calculate the mean, sample variance, and sample standard deviation. State the unit of the SD value, and briefly explain why the units of variance and SD differ. No R code is required.
The mean is 4 minutes: (2+4+6)/3=4.
The sample variance is 4. One calculation is
s^2=\frac{(2-4)^2+(4-4)^2+(6-4)^2}{3-1}=\frac{8}{2}=4.
The sample SD is 2 minutes because s=\sqrt{4}=2.
Units explanation: variance squares deviations, while SD takes the square root and restores the original unit. The units are minutes squared for variance and minutes for SD.
Question 26 (10 points)
An analyst summarizes integer satisfaction ratings from 1 to 5 stars for two cafes in Geneseo: each recorded rating is one of 1, 2, 3, 4, or 5. The analyst computes the SDs; they are not supplied by a review website. Interpret these recorded reviews only. No R code is required.
| Cafe | Reviews | Mean rating | Sample SD (rounded) |
|---|---|---|---|
| A | 20 | 4.5 | 1.00 |
| B | 20 | 4.4 | 0.50 |
(a) Classify an individual star rating as nominal, ordinal, interval, or ratio. State what the ratings establish, and identify an additional assumption needed to interpret the mean and SD as magnitudes of underlying satisfaction. (3 points)
(b) Does checking SD establish that assumption? Do the means and SDs alone establish which cafe is better for every customer? Briefly explain both judgments. (4 points)
(c) An analyst claims: “Cafe A’s customers are about 2.3% more satisfied because 4.5 / 4.4 is approximately 1.023.” Explain whether this claim is justified. (3 points)
a. Ordinal. The ratings establish an order but do not by themselves establish equal gaps in satisfaction. Interpreting means and SDs as satisfaction magnitudes requires an approximately equal-gap assumption.
b. No to both judgments. For the first, SD itself uses the recorded numerical distances and cannot establish equal gaps in underlying satisfaction. For the second, the summaries do not determine a preferred cafe for every customer, for example because customers can value different features or experiences. A preference for either cafe can be reasonable; lower SD is not automatically better.
c. The claim is not justified. The ordered star labels do not establish a ratio scale for satisfaction: equal satisfaction gaps and a meaningful zero are not guaranteed. Thus, 4.5 / 4.4 compares coded averages and does not establish that one group is 2.3% more satisfied. A correct arithmetic ratio alone does not justify the satisfaction interpretation.
Question 27 (9 points)
Interpret the horizontal boxplot of fictional customer waits. Dashed guides are the usual fences. No R code is required.
(a) Read the median, Q1, and Q3 from the figure. (3 points)
(b) Calculate the IQR, in minutes. (1 point)
(c) Give the upper whisker endpoint and calculate the upper fence. Explain what the hollow dot to the right of the boxplot indicates, using its position relative to the upper fence. (5 points)
a. Median = 40, Q1 = 30, Q3 = 50 minutes. The interior line marks the median; the box edges mark Q1 and Q3.
b. IQR = 50 - 30 = 20 minutes.
c. Upper whisker endpoint = 60 minutes; upper fence = Q3 + 1.5(IQR) = 50 + 1.5(20) = 80 minutes. The hollow dot marks a possible outlier because its observed wait lies beyond the upper fence. It is not automatically a recording error.
The whisker ends at the largest observed value within the fences; the dashed fence is a calculated threshold.