library(tidyverse)
gapminder_2007 <- read_tsv("https://bcdanl.github.io/data/gapminder.tsv") |>
filter(year == 2007)Classwork 15
Seeing Relationships with a Log Transformation
Complete the questions and submit your responses on the corresponding Brightspace page.
Complete the code in an R script and keep your brief written interpretations with it. This page contains its own setup and data definitions; no earlier classwork is required.
Setup and data
Load the historical Gapminder data and keep 2007. Each row in the filtered table represents one country.
| Variable | Meaning |
|---|---|
pop |
Country population, in people |
lifeExp |
Life expectancy in years |
These are historical 2007 country-level data, not current population counts or individual people’s outcomes. Reference: Gapminder package data documentation.
Filling-in-the-blank: 1. Compare the raw and transformed horizontal variables
Draw two scatterplots, changing only the horizontal variable. Use log10() in the blank.
ggplot(data = gapminder_2007,
mapping = aes(x = pop,
y = lifeExp)) +
geom_point()
ggplot(data = gapminder_2007,
mapping = aes(x = ____(pop),
y = lifeExp)) +
geom_point()Which version makes countries with smaller populations easier to distinguish on the horizontal axis? Describe what changes in the spacing of points. Do the plots show a clear overall relationship between population and life expectancy?
Interpretation: 2. Read a transformed value
On a log10(pop) horizontal axis, 6 corresponds to 1 million people and 7 corresponds to 10 million people. What original population does 5 correspond to?
Interpretation: 3. Transformation is not deletion
Does taking a logarithm remove any country from these positive-valued data or change the countries’ population ranking? Explain. Does changing the horizontal scale, by itself, establish an association or show that population causes life expectancy?
You do not need to interpret a regression slope or calculate percentage changes from logarithms. A logarithm of zero or a negative value is not defined as a real number, so check values before applying this transformation to another dataset.