Data Transformations Practice: River Lengths

A note on AI tools: You may use AI assistants (ChatGPT, Claude, etc.) to help debug your R code — that’s a realistic professional skill. You may not use AI to generate your interpretations. Every write-up sentence must reflect your own reading of the output. If you use AI for any part of this assignment, note where at the end.

The dataset

rivers is a built-in R dataset: the lengths (in miles) of 141 major rivers in North America. No loading required.

length(rivers)
summary(rivers)

Part 1: Diagnose the Skew

Predict first. River lengths can’t be negative and there’s no upper limit on how long a river can be. Do you expect this variable to be symmetric, right-skewed, or left-skewed? Why?

hist(rivers, breaks = 20, main = "Raw river lengths")
library(e1071)
skewness(rivers)
shapiro.test(rivers)
  1. Report the skewness value and the Shapiro-Wilk result. Was your prediction correct?

Part 2: Try a Transformation — Log

log_rivers <- log(rivers)
hist(log_rivers, breaks = 20, main = "Log-transformed river lengths")
skewness(log_rivers)
shapiro.test(log_rivers)
  1. Report the new skewness and Shapiro-Wilk result. Did the log transformation help?
  2. Shapiro-Wilk may still be significant here even though the histogram looks much more symmetric. With n = 141, is that a red flag, or is this the large-sample oversensitivity the normality chapters warned about? Justify your answer using both the visual and the numbers.

Part 3: Try a Transformation — Square Root

sqrt_rivers <- sqrt(rivers)
skewness(sqrt_rivers)
shapiro.test(sqrt_rivers)
  1. Report the skewness for the square-root version. Compare the three skewness values you now have (raw, log, square root) — which transformation worked best for this data, and does that match the chapter’s own guidance about which transformation to try first for severe right skew?

Part 4: The Z-score Trap

z_rivers <- scale(rivers)
skewness(as.vector(z_rivers))
shapiro.test(as.vector(z_rivers))
  1. Compare the skewness and Shapiro-Wilk result for the z-scored version to the raw (untransformed) values from Part 1. What do you notice? Explain, in your own words, why z-scoring cannot fix skew — even though it does successfully rescale the data to mean 0, SD 1.

Part 5: Interpreting the Transformed Scale

Suppose you had two groups of rivers (say, rivers in two different regions) and, after log-transforming, found the mean difference in log(length) was 0.40.

  1. A 0.40 log-unit difference corresponds to a multiplicative difference on the original scale of \(e^{0.40}\). Compute this value. If Group A’s mean log-length is 0.40 higher than Group B’s, approximately what percentage longer are Group A’s rivers than Group B’s, on average?
  2. Why would it be wrong to report “Group A’s rivers are 0.40 miles longer than Group B’s” after running the test on log-transformed data?

Part 6: Common Errors

  1. rivers has a minimum value of 135 — no zeros or negative values. If a dataset did contain zeros, what would happen if you ran log(y) directly on it, and what’s the standard pragmatic fix?
  2. Write one sentence, in the style of the chapter’s own worked example, reporting that river lengths were right-skewed and were log-transformed prior to further analysis. Include the raw and log-transformed Shapiro-Wilk results.