Fall 2025 Midterm 1
2026-10-13
Explain how and when to install a package.
Explain how and when to load a package.
How do you access R’s built-in help for a function or dataset?
What is a vector?
What is a data frame?
Explain the difference between a categorical and a numerical variable.
For two categorical variables, describe an appropriate plot.
The exam gives heat map as its worked example.
For one categorical variable, describe an appropriate plot to visualize its distribution.
For one numerical variable, describe an appropriate plot to visualize its distribution.
For two numerical variables, describe an appropriate plot to visualize their joint distribution.
For one numerical variable and one categorical variable, describe an appropriate plot.
For each variable in animals, identify whether it is categorical or numerical.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
How many rows and columns are in animals?
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
Write a command that keeps only the rows corresponding to cats.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
What does this command return? Predict before running it.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
What does this command return? Predict before running it.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
What does this pipeline return?
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
Draw the table returned by this pipeline.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
Draw the table returned by this pipeline.
A survey measured annual per-capita nacho cheese consumption in five countries.
What is this type of plot called?
True or false: a quarter of the people surveyed in the USA consume less than 5 liters of nacho cheese per year.
Explain everything the plot tells us about consumption in the Canadian portion of the sample.
Can you conclude that the population of the USA consumes more nacho cheese on average than the population of France? Explain.
Can you conclude that average consumption in the USA portion of the sample is at most 5 liters per year? Explain.
Can you conclude that average consumption in the USA portion of the sample is at least 2 liters per year? Explain.
The heights table contains self-reported student height in inches and sex.
What is the response variable in this model?
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
What is the predictor variable in this model?
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
Write the equation of the fitted regression line.
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
How many observations were used to fit this model?
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
A student is male and 170 cm tall. What height does the model predict for this student? Round to the nearest inch.
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
State a test of whether average male and female heights are equal. Explain how to use this output and state your conclusion.
Call:
lm(formula = height ~ sex, data = heights)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 64.9394 0.2363 274.82 <2e-16
sexMale 4.3753 0.2687 16.28 <2e-16
Residual standard error: 3.645 on 1048 df
Multiple R-squared: 0.2019
What is the correlation between height and an indicator that equals 1 when the student is female?
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
This code is intended to compute average dog weight. Explain the bug and fix it.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
This code is intended to count each species. Explain the bug and fix it.
# A tibble: 6 x 3
species has_feathers weight
<chr> <lgl> <dbl>
1 dog FALSE 20.5
2 cat FALSE 11.6
3 cat FALSE 8
4 cat FALSE 7
5 chicken TRUE NA
6 chicken TRUE 2.5
Sort alphabetically by species, breaking ties by putting the heaviest animals first. Explain the bug and fix it.
The heights table has columns sex and height.
Height is measured in inches.
This code is intended to compute average student height. Explain the bug and fix it.
The weather table has one row per date.
date is the observation date.tmax is daily maximum temperature in °C.Compute average daily maximum temperature for each month. Explain the bugs and fix them.
Daily Ann Arbor weather measurements, as used in last year’s exam.
# A tibble: 48,636 x 12
date station tmin tmax prcp snow snwd
<date> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1891-10-01 USC00200230 7.8 20.6 NA NA NA
2 1891-10-02 USC00200230 13.9 26.7 NA NA NA
3 1891-10-03 USC00200230 16.1 26.1 NA NA NA
4 1891-10-04 USC00200230 11.1 22.8 7.6 NA NA
5 1891-10-05 USC00200230 6.7 13.9 NA NA NA
6 1891-10-06 USC00200230 5 14.4 NA NA NA
# 5 more variables: tmax_flag, tmin_flag, prcp_flag,
# snow_flag, snwd_flag
Average daily maximum temperature by year and month, 2010–2020, in °C.
year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2010 -0.9 0.5 11.5 19.4 22.3 26.9 29.9 29.0 23.4 19.0 10.5 -0.8
2011 -2.5 0.7 6.3 14.0 21.6 27.3 32.3 27.8 22.1 16.9 11.6 4.6
2012 2.9 4.1 16.3 16.0 25.2 28.8 32.9 28.7 24.1 16.2 9.0 4.9
2013 2.4 0.3 4.9 13.6 24.0 25.6 27.7 26.8 24.0 16.9 7.2 0.3
2014 -4.1 -2.7 3.7 15.9 22.0 26.5 26.1 27.1 23.3 16.2 5.6 3.9
2015 -2.1 -4.5 7.1 15.7 24.1 25.3 27.6 26.8 26.4 17.5 12.6 7.6
2016 0.9 4.0 11.7 14.5 21.8 28.2 30.3 29.7 25.4 19.0 13.1 1.0
2017 2.3 8.4 7.4 18.1 20.7 27.9 28.9 26.8 25.4 19.2 8.6 0.1
2018 0.1 3.7 5.9 11.4 25.4 26.7 29.6 28.6 24.9 15.7 4.3 3.6
2019 -0.4 1.8 6.2 15.6 21.1 25.3 30.1 27.4 24.8 16.9 5.4 4.8
2020 2.7 2.4 9.7 13.7 20.1 28.1 30.5 28.4 23.4 15.5 12.7 3.6
We need:
Describe the steps to make the table on the previous slide.
Write code or a plan precise enough for an experienced R user to implement.
What would you like to go over again?
ARCHIVED CLASS RECORD
Closed October 16, 2026 at 12:22 PM
0 class questions · 0 anonymous responses · 0 student questions
The following slides preserve what students submitted during class. No names or login information are included.