# HSCI 410 Lesson 6, Activity 6.1: Anscombe's quartet in R # Run-along script for the narrated walkthrough. It uses the anscombe data # frame that comes with R, so there is nothing to set up: open it # in RStudio and run each part with Ctrl+Enter when the narration asks. # 1. Look at the data and summarise each column anscombe # four small datasets that come with R round(colMeans(anscombe), 2) # the mean of each column round(sapply(anscombe, sd), 2) # the standard deviation of each column # 2. The correlation and the fitted line in each set round(cor(anscombe$x1, anscombe$y1), 3) # correlation in set 1 round(cor(anscombe$x2, anscombe$y2), 3) # set 2 round(cor(anscombe$x3, anscombe$y3), 3) # set 3 round(cor(anscombe$x4, anscombe$y4), 3) # set 4 coef(lm(y1 ~ x1, data = anscombe)) # intercept and slope, set 1 coef(lm(y3 ~ x3, data = anscombe)) # set 3 coef(lm(y4 ~ x4, data = anscombe)) # set 4 # 3. Plot the four sets, each with the same straight line par(mfrow = c(2, 2)) # four plots in one window: two rows, two columns plot(anscombe$x1, anscombe$y1, main = "Set 1", xlab = "x", ylab = "y") abline(3, 0.5, col = "red") # add the line y = 3 + 0.5x plot(anscombe$x2, anscombe$y2, main = "Set 2", xlab = "x", ylab = "y") abline(3, 0.5, col = "red") plot(anscombe$x3, anscombe$y3, main = "Set 3", xlab = "x", ylab = "y") abline(3, 0.5, col = "red") plot(anscombe$x4, anscombe$y4, main = "Set 4", xlab = "x", ylab = "y") abline(3, 0.5, col = "red") par(mfrow = c(1, 1)) # back to one plot per window