Homework 4

Relationships, Log Transformations, Time Trends, and Career Preparation

Homework 4 based on Lectures 8 and 9, with R coding using Gapminder data read from a CSV file.
Author

Byeong-Hak Choe

Published

November 11, 2026

Instructions

This homework focuses on Lecture 8 and includes two Lecture 9 career questions. Answer all 32 questions, worth 100 points.

  • Concepts: 50 points. Questions 1–13 are multiple-choice questions; Questions 14–16 are conceptual fill-in-the-blank questions.
  • R programming: 50 points. Questions 17–32 each contain one R-code blank and use the gapminder data frame read from the CSV file below, or a setup subset derived from it.
  • Questions 12 and 13 connect the Andy and Oliver and Marcie career sessions, respectively, with Prof. Choe’s thoughts in Lecture 9.

For each multiple-choice question, select the one best answer. For a conceptual blank, enter only the requested term or number. For a coding question, enter only the R code that replaces [?], not the entire code block. Include quotation marks when the missing code is a character string.

A coding blank may require a complete condition, aesthetic mapping, or plot layer. Read the requested result carefully and compare your completed code with the target visualization. The completed code used to generate each target is hidden.

Run the setup below once, then write and test your answers in an R script. Each coding question starts from the original setup objects and can be completed independently. Plot labels, axis formatting, legend settings, and palette choices already supplied in a code block are part of the template; keep them as provided. They are not additional blanks.

Use the course materials and R methods covered through Lecture 8, together with the specified Lecture 9 career material. Colored group comparisons use a ggthemes colorblind-friendly palette. Labels, shapes, line types, and panels provide additional group cues where appropriate.

Submission: Submit your answers through the Brightspace quiz. Check Brightspace for the due date and attempt limit.

ImportantGenerative AI is not permitted

Complete this homework independently. Do not use generative AI tools to generate, revise, explain, debug, or check your answers or R code. Use the lectures, classwork, and your own course notes. Please ask Prof. Choe if you need help.

Setup and Data

All coding questions use the gapminder data frame. Read the CSV file directly from the web and create the subsets below.

library(tidyverse)
library(ggthemes)

gapminder <- read_csv(
  "https://bcdanl.github.io/data/gapminder.csv"
)

countries_2007 <- gapminder |>
  filter(year == 2007)

three_continents <- countries_2007 |>
  filter(continent == "Americas" |
         continent == "Asia" |
         continent == "Europe")

If ggthemes is missing, run install.packages("ggthemes") once before loading it.

The gapminder Data Frame

gapminder has 1,704 country-year records for 142 countries, with observations every five years from 1952 through 2007 (12 recorded years per country). Each row represents one country in one recorded year, not one person. Countries receive equal weight in the plots; population is not used as a plot weight.

Variable descriptions

Variable Description
country Country name.
continent Continent category in the dataset.
year Year of the country record, recorded every five years: 1952, 1957, and so on through 2007.
lifeExp Life expectancy at birth, in years. This is a country-level measure, not an individual person’s age.
pop Country population, in people.
gdpPercap GDP per person, in the dataset’s dollar units.

Setup subsets

  • countries_2007: the 142 country records for 2007.
  • three_continents: the 88 records for the Americas, Asia, and Europe in 2007, including the United States. These groups are used for grouped fitted curves; Oceania has only two records in the 2007 subset.

All GDP and population values used in the logarithmic plots are positive. Connecting two recorded years with a line does not add observations for the intervening years.

Part I: Multiple Choice — Concepts

Question 1

3 points · Lecture 8

This scatterplot uses GDP per person on the horizontal axis and life expectancy on the vertical axis. What does one point represent?

Each point places one country’s 2007 GDP per person and life expectancy. Color and shape identify continent.

  1. One country’s GDP-per-person and life-expectancy values in 2007.
  2. One person’s income and eventual age at death.
  3. The total population of one continent across all years.
  4. The change in a country’s GDP between two years.

Question 2

3 points · Lecture 8

The curve summarizes the relationship between GDP per person and life expectancy in 2007. Which description best matches its direction and shape?

Country life expectancy in 2007 plotted against GDP per person on an ordinary dollar axis. A black smooth curve rises quickly at lower GDP values and becomes flatter at higher GDP values, with points scattered around it.

  1. Life expectancy generally decreases as GDP per person increases, and the decrease becomes faster at higher GDP values.
  2. There is no overall direction because the curve becomes flatter at higher GDP values.
  3. Life expectancy generally increases as GDP per person increases, but the upward curve becomes flatter at higher GDP values.
  4. Life expectancy first decreases and then increases as GDP per person increases.

Question 3

4 points · Lecture 8

The straight fitted line summarizes life expectancy against base-10 log GDP per person. Choose a GDP-per-person value on the horizontal axis. What does the fitted line tell us about life expectancy at that value?

Country-level scatterplot of life expectancy against log10 GDP per person, with one upward fitted straight line.

  1. The life expectancy that every country at that GDP value must have.
  2. The median GDP per person of the countries above the line.
  3. A guaranteed life expectancy after a country adopts a particular policy.
  4. An estimated average life expectancy at that GDP-per-person value, based on the plotted data and fitted model.

Question 4

4 points · Lecture 8

The grey ribbon around the fitted line is the default 95% confidence ribbon. Some country points fall outside it. Which interpretation is appropriate?

A fitted straight line and grey confidence ribbon summarize the average relationship. Country observations are scattered on both sides, including outside the ribbon.

  1. The ribbon shows uncertainty around the estimated average relationship; it is not a band required to contain 95% of individual country observations.
  2. The graph is incorrect unless exactly 95% of all country points lie inside the ribbon.
  3. A point outside the ribbon must be a data-entry error.
  4. The ribbon gives the full minimum-to-maximum range of country life expectancy at every GDP value.

Question 5

3 points · Lecture 8

This plot includes the 2007 countries with GDP per person between $2,000 and $6,000. What does the vertical spread of the points around the fitted line show?

Thirty countries with GDP per person between 2,000 and 6,000 dollars have life expectancies ranging from about 40 to 76 years. A straight fitted line summarizes the pattern, with substantial vertical spread among the points.

  1. Countries at similar GDP-per-person values have similar life expectancies, so the line captures almost all country differences.
  2. The spread measures how much each country’s GDP per person changed between 1952 and 2007.
  3. Countries with similar GDP per person can have quite different life expectancies, even though the line summarizes an overall pattern.
  4. The distance from a point to the line measures the uncertainty in that country’s recorded GDP per person.

Question 6

4 points · Lecture 8

The United States and South Africa are labeled in this 2007 country comparison. Which statement best compares their life expectancies with the fitted pattern?

Life expectancy against log10 GDP per person for countries in 2007, with a fitted straight line. The United States and South Africa are labeled and marked with blue triangles. Both are below the fitted line; South Africa is much farther below it.

  1. Both countries lie above the fitted line, with South Africa farther from the fitted pattern at its GDP-per-person value.
  2. Both countries lie below the fitted line, with South Africa farther from the fitted pattern at its GDP-per-person value.
  3. Both countries lie below the fitted line, with the United States farther from the fitted pattern at its GDP-per-person value.
  4. South Africa lies above the fitted line, while the United States lies below the fitted pattern at its GDP-per-person value.

Question 7

3 points · Lecture 8

This chart includes the United States and other countries. Each continent is identified by both a point’s color and shape. How do the point shapes help when the chart is printed in black and white?

The Americas, Asia, and Europe are identified by distinct point shapes as well as color, with a labeled legend. The Americas include the United States.

  1. Changing the symbols changes the numerical values of life expectancy.
  2. Every symbol becomes a separate country-year dataset.
  3. The shapes remove the need to name the groups in the legend.
  4. The point symbols provide another way to distinguish the continent groups when colors are difficult to distinguish.

Question 8

4 points · Lecture 8

The three panels use the same horizontal and vertical scales. Which comparison of their fitted straight lines is correct?

The Americas, Asia, and Europe appear in separate panels with identical GDP-per-person and life-expectancy scales. GDP per person is measured in ten-thousand-dollar units. Each has an upward fitted straight line. Asia’s line rises more steeply than the Americas and Europe lines.

  1. The Americas’ fitted line has the steepest upward slope.
  2. Asia’s fitted line has the steepest upward slope.
  3. Europe’s fitted line has the steepest upward slope.
  4. The fitted lines have the same slope because they all rise.

Question 9

3 points · Lecture 8

On an ordinary dollar axis, the increase from $4,000 to $8,000 is smaller than the increase from $12,000 to $24,000. How do these two changes compare on a logarithmic axis?

  1. The second must remain three times as wide because it adds three times as many dollars.
  2. The first becomes wider because it begins at a smaller amount.
  3. They have equal horizontal distances because both multiply the starting value by two.
  4. They collapse to zero distance because logarithms remove all differences.

Question 10

3 points · Lecture 8

A scatterplot’s horizontal axis is labeled log10 GDP per person. The axis position 3 corresponds to $1,000, and position 4 corresponds to $10,000. What does moving from horizontal position 3 to position 4 mean?

  1. GDP per person increases by exactly one dollar.
  2. GDP per person becomes ten times as large; the vertical life-expectancy axis is still measured in years.
  3. Life expectancy must become ten times as large.
  4. Both axes have necessarily been transformed into logarithms.

Question 11

3 points · Lecture 8

The gapminder data frame records each country at five-year intervals. A line connects a country’s life-expectancy point for 1952 to its point for 1957. What can a reader conclude about 1953–1956 from that connecting segment alone?

Canada and the United States each have life-expectancy records every five years from 1952 to 2007. Separate lines connect each country’s recorded points; colors, point shapes, and line types distinguish the countries.

  1. The data frame contains an annual life-expectancy record at every point on the segment.
  2. Life expectancy must have stayed exactly equal to the 1952 value until 1957.
  3. The line forecasts life expectancy for years after 2007.
  4. The segment connects the recorded endpoints; it does not supply recorded annual values for 1953–1956.

Question 12

2 points · Lecture 9

Andy and Oliver, together with Prof. Choe’s thoughts: Leah has finished a course project and wants to apply for internships this month. She has little interview experience. Which plan best follows the career preparation advice in Lecture 9?

  1. Practice explaining her project decisions, seek Career Center feedback, and apply to suitable openings while reaching out to campus contacts.
  2. Build a second project using an employer’s tools, then begin applications and interview preparation once the new project is complete.
  3. Concentrate on sending applications with a shared résumé, and prepare project explanations after employers invite her to interview.
  4. Seek alumni referrals for a small set of roles, and use feedback from her first interviews to decide what preparation to do.

Question 13

3 points · Lecture 9

Marcie, together with Prof. Choe’s thoughts: Mateo has taken an introductory data course and is interested in product marketing and customer education. Which next learning goal best reflects the value of data skills in those roles, as discussed in Lecture 9?

  1. Learn a company’s reporting software so he can reproduce its existing dashboards and prepare reports in the formats its teams use.
  2. Use data to answer a customer question, check the evidence, and explain the findings and their limits to a nontechnical audience.
  3. Develop presentation and marketing skills first, then return to data analysis when the requirements of a particular position become clearer.
  4. Build a portfolio of advanced statistical models to demonstrate technical depth and distinguish his quantitative skills from those of other marketing applicants.

Part II: Fill in the Blank — Concepts

Question 14

2 points · Lecture 8

In a relationship plot, the variable whose values we want to understand or predict is called the [?] variable. In the country example, life expectancy plays this role. Enter the term used in Lecture 8.

Question 15

3 points · Lecture 8

A logarithmic axis gives the same horizontal distance to the change from $2,000 to $6,000 as to the change from $6,000 to $18,000. Each change multiplies the starting value by [?]. Enter one number.

Question 16

3 points · Lecture 8

An illustrative country’s GDP per person rises from $8,000 to $10,000. The percentage increase is [?]%. Enter only the number, without a percent sign.

Part III: Fill in the Blank — R Programming

Question 17

3 points · Lecture 8

Reproduce the 2007 comparison for countries in the Americas, including the United States.

americas_2007 <- gapminder |>
  filter(year == 2007,
         continent == "Americas")

ggplot(data = americas_2007,
       mapping = [?]) +
  geom_point(color = "steelblue",
             alpha = 0.65,
             size = 2) +
  labs(x = "GDP per person (US$)",
       y = "Life expectancy (years)")

Target visualization:

GDP per person and life expectancy for 25 countries in the Americas in 2007, including the United States, shown as blue points on ordinary numeric axes.

Question 18

2 points · Lecture 8

Reproduce this country-year scatterplot with points at 70% opacity.

ggplot(data = gapminder,
       mapping = aes(x = log10(gdpPercap),
                     y = lifeExp,
                     color = continent,
                     shape = continent)) +
  geom_point([?],
             size = 1.1) +
  scale_color_colorblind() +
  labs(x = "log10(GDP per person)",
       y = "Life expectancy (years)",
       color = "Continent",
       shape = "Continent")

Target visualization:

All 1,704 country-year observations form a dense scatterplot of life expectancy against log10 GDP per person. Partly transparent points use continent colors and shapes.

Question 19

2 points · Lecture 8

Complete the fitted trend for the United States.

us_history <- gapminder |>
  filter(country == "United States")

ggplot(data = us_history,
       mapping = aes(x = gdpPercap,
                     y = lifeExp)) +
  geom_point(alpha = 0.7,
             color = "steelblue") +
  geom_smooth(method = [?],
              se = FALSE,
              color = "grey30") +
  labs(x = "United States GDP per person (US$)",
       y = "United States life expectancy (years)")

Target visualization:

The United States’ 12 observations from 1952 to 2007 appear as blue points on GDP-per-person and life-expectancy axes, with one upward straight fitted line and no ribbon.

Question 20

2 points · Lecture 8

Match the target’s treatment of uncertainty.

us_canada_history <- gapminder |>
  filter(country == "United States" |
         country == "Canada")

ggplot(data = us_canada_history,
       mapping = aes(x = year,
                     y = log10(gdpPercap),
                     color = country,
                     linetype = country)) +
  geom_point(mapping = aes(shape = country),
             size = 2) +
  geom_smooth(se = [?]) +
  scale_color_colorblind() +
  labs(x = "Year of record",
       y = "log10(GDP per person)",
       color = "Country",
       linetype = "Country",
       shape = "Country")

Target visualization:

The United States and Canada have separate smooth fitted log-GDP trends over 1952–2007, with their observed points and no shaded uncertainty ribbons. Colors, shapes, and line types identify the two countries.

Question 21

3 points · Lecture 8

Reproduce the horizontal scale shown in the target.

ggplot(data = countries_2007,
       mapping = aes(x = [?],
                     y = lifeExp,
                     color = continent,
                     shape = continent)) +
  geom_point(alpha = 0.85,
             size = 2) +
  scale_color_colorblind() +
  labs(x = "log10(GDP per person in US$)",
       y = "Life expectancy (years)",
       color = "Continent",
       shape = "Continent")

Target visualization:

Life expectancy plotted against log10 GDP per person for 142 countries. Colors and point shapes identify continents, and lower-GDP countries are more spread out horizontally than on an ordinary dollar axis.

Question 22

2 points · Lecture 8

Reproduce these three countries’ trends and their uncertainty bands.

north_america_history <- gapminder |>
  filter(country == "United States" |
         country == "Canada" |
         country == "Mexico")

ggplot(data = north_america_history,
       mapping = aes(x = year,
                     y = lifeExp,
                     color = country,
                     fill = [?],
                     linetype = country)) +
  geom_smooth(alpha = 0.15,
              linewidth = 1) +
  scale_color_tableau() +
  scale_fill_tableau() +
  labs(x = "Year of record",
       y = "Life expectancy (years)",
       color = "Country",
       fill = "Country",
       linetype = "Country")

Target visualization:

Three life-expectancy curves extend from 1952 to 2007 for Canada, Mexico, and the United States. Distinct colors and line types identify countries, with lightly shaded confidence bands matching each curve. Mexico starts much lower and rises more rapidly, while Canada and the United States begin higher.

Question 23

3 points · Lecture 8

Arrange the comparisons for the three years as shown.

comparison_years <- gapminder |>
  filter(year == 1952 |
         year == 1977 |
         year == 2007)

ggplot(data = comparison_years,
       mapping = aes(x = log10(gdpPercap),
                     y = lifeExp)) +
  geom_point(mapping = aes(color = continent,
                           shape = continent),
             alpha = 0.45,
             size = 1.7) +
  geom_smooth(method = "lm",
              se = FALSE,
              color = "grey25") +
  [?] +
  scale_color_colorblind() +
  labs(x = "log10(GDP per person)",
       y = "Life expectancy (years)",
       color = "Continent",
       shape = "Continent")

Target visualization:

Three panels labeled 1952, 1977, and 2007 compare life expectancy against base-10 log GDP per person. Continent-colored and shaped country points surround one dark straight fitted line in each panel; the panels share axis scales.

Question 24

3 points · Lecture 8

Complete the historical GDP series for the United States.

us_economy <- gapminder |>
  filter(country == "United States")

ggplot(data = us_economy,
       mapping = [?]) +
  geom_line(color = "steelblue",
            linewidth = 0.8) +
  geom_point(color = "steelblue",
             size = 2) +
  labs(x = "Year of record",
       y = "United States GDP per person (US$)")

Target visualization:

The United States’ GDP per person from 1952 through 2007, shown as blue points joined in year order on an ordinary dollar axis. GDP per person increases across the recorded observation dates.

Question 25

4 points · Lecture 8

Plot the 2007 country records from the Americas or Europe with life expectancy at least 70 years, including the United States.

selected_countries <- three_continents |>
  filter([?])

ggplot(data = selected_countries,
       mapping = aes(x = log10(gdpPercap),
                     y = lifeExp,
                     color = continent,
                     shape = continent)) +
  geom_point(alpha = 0.65,
             size = 2) +
  geom_smooth(method = "lm",
              se = FALSE) +
  scale_color_colorblind() +
  labs(x = "log10(GDP per person in US$)",
       y = "Life expectancy (years)",
       color = "Continent",
       shape = "Continent")

Target visualization:

Log10 GDP and life expectancy for countries in the Americas and Europe with life expectancy at least 70 years in 2007, including the United States. Colors and shapes distinguish the two continents, and each has a separate straight fitted line.

Question 26

4 points · Lecture 8

Complete the country histories and continental trends shown.

ggplot(data = gapminder,
       mapping = [?]) +
  geom_line(mapping = aes(group = country),
            color = "grey70",
            linewidth = 0.3,
            alpha = 0.45,
            show.legend = FALSE) +
  geom_smooth(se = FALSE,
              linewidth = 1.1,
              show.legend = FALSE) +
  facet_wrap(~ continent) +
  scale_color_colorblind() +
  labs(x = "Year of record",
       y = "log10(GDP per person)",
       color = "Continent")

Target visualization:

Five labeled continent panels show thin grey country GDP histories from 1952 to 2007 on a base-10 logarithmic vertical axis. Each panel also has one thicker colored smooth curve without an uncertainty ribbon, and the panels share axis scales.

Question 27

4 points · Lecture 8

Add the overall fitted trend for the Americas, Asia, and Europe, including the United States.

ggplot(data = three_continents,
       mapping = aes(x = log10(gdpPercap),
                     y = lifeExp)) +
  geom_point(mapping = aes(color = continent,
                           shape = continent),
             alpha = 0.55,
             size = 2) +
  [?] +
  scale_color_colorblind() +
  labs(x = "log10(GDP per person)",
       y = "Life expectancy (years)",
       color = "Continent",
       shape = "Continent")

Target visualization:

the Americas, Asia, and Europe appear as differently colored and shaped country points, with one overall straight fitted line across all 88 observations and no ribbon.

Question 28

4 points · Lecture 8

Reproduce the population–GDP relationship for the three continents, including the United States.

ggplot(data = three_continents,
       mapping = [?]) +
  geom_point(mapping = aes(color = continent,
                           shape = continent),
             alpha = 0.65,
             size = 2) +
  geom_smooth() +
  scale_color_colorblind() +
  labs(x = "log10(GDP per person)",
       y = "log10(Population in people)",
       color = "Continent",
       shape = "Continent")

Target visualization:

Population versus GDP per person for the Americas, Asia, and Europe in 2007, with base-10 logarithms on both axes. Color and point shape identify continents; each point represents a country. One fitted smooth curve and its confidence ribbon summarize the overall relationship.

Question 29

4 points · Lecture 8

Keep the United States and India from 1982 through 2007, inclusive, then reproduce the population trends.

selected_population <- gapminder |>
  filter([?])

ggplot(data = selected_population,
       mapping = aes(x = year,
                     y = pop / 1000000,
                     color = country,
                     linetype = country)) +
  geom_line(linewidth = 1) +
  geom_point(mapping = aes(shape = country),
             size = 2) +
  scale_color_colorblind() +
  labs(x = "Year of record",
       y = "Population (millions of people)",
       color = "Country",
       linetype = "Country",
       shape = "Country")

Target visualization:

The United States and India population histories from 1982 through 2007, with six points per country, connected by separate colored and patterned lines. Population is measured in millions of people. India has the larger population throughout this interval.

Question 30

4 points · Lecture 8

Reproduce these GDP histories.

gdp_histories <- gapminder |>
  filter(country == "Kuwait" |
         country == "United States" |
         country == "Japan")

ggplot(data = gdp_histories,
       mapping = [?]) +
  geom_line(linewidth = 1) +
  geom_point(mapping = aes(shape = country),
             size = 2) +
  scale_color_colorblind() +
  labs(x = "Year of record",
       y = "log10(GDP per person)",
       color = "Country",
       linetype = "Country",
       shape = "Country")

Target visualization:

The United States, Japan, and Kuwait have separate colored and patterned GDP histories from 1952 to 2007, with symbols at the 12 recorded years. The vertical axis is base-10 log GDP per person. Kuwait starts high and fluctuates markedly; United States GDP per person rises throughout the recorded years, and Japan rises rapidly before its growth slows.

Question 31

3 points · Lecture 8

Reproduce the population histories in the three panels.

population_histories <- gapminder |>
  filter(country == "United States" |
         country == "Germany" |
         country == "Japan")

ggplot(data = population_histories,
       mapping = [?]) +
  geom_line(mapping = aes(color = country),
            linewidth = 0.8,
            show.legend = FALSE) +
  geom_point(mapping = aes(color = country),
             size = 1.6,
             show.legend = FALSE) +
  facet_wrap(~ country) +
  scale_color_colorblind() +
  labs(x = "Year of record",
       y = "log10(Population in people)")

Target visualization:

Three panels labeled Germany, Japan, and United States show population histories from 1952 to 2007. Colored lines connect each country’s 12 observations, the vertical axis is base-10 log population in people, and all panels share axis scales. The United States has the largest population throughout the period, while Germany’s changes are comparatively small.

Question 32

3 points · Lecture 8

Add the fitted trends shown for the United States and South Africa.

life_histories <- gapminder |>
  filter(country == "United States" |
         country == "South Africa")

ggplot(data = life_histories,
       mapping = aes(x = year,
                     y = lifeExp,
                     color = country,
                     fill = country,
                     linetype = country)) +
  geom_line(linewidth = 0.7,
            alpha = 0.45) +
  geom_point(mapping = aes(shape = country),
             size = 2) +
  [?] +
  scale_color_tableau() +
  scale_fill_tableau() +
  labs(x = "Year of record",
       y = "Life expectancy (years)",
       color = "Country",
       fill = "Country",
       linetype = "Country",
       shape = "Country")

Target visualization:

United States and South Africa life-expectancy observations from 1952 to 2007 appear as country-specific points joined by faint lines. Separate fitted smooth curves have matching shaded confidence ribbons. The United States rises gradually from about 68 to 78 years; South Africa rises from about 45 to the low 60s before declining to about 49 years.

Back to top