Anscombe’s quartet in R

Anscombe’s quartet comprises four data sets that have nearly identical simple descriptive statistics, yet have very different distributions and appear very different when graphed. Each dataset consists of eleven (x,y) points. They were constructed in 1973 by the statistician Francis Anscombe to demonstrate both the importance of graphing data before analyzing it and the effect of outliers and other influential observations on statistical properties. He described the article as being intended to counter the impression among statisticians that “numerical calculations are exact, but graphs are rough.

The objectives of this problem set is to orient you to a number of activities in R. And to conduct a thoughtful exercise in appreciating the importance of data visualization. For each question create a code chunk or text response that completes/answers the activity or question requested.

Photo by Mick Haupt on Unsplash

Anscombes quartet is a set of 4 x,y data sets that were published by Francis Anscombe in a 1973 paper Graphs in statistical analysis. For this first question load the anscombe data that is part of the library(datasets) in R. And assign that data to a new object called data.

library(xtable)

xtable(head(anscombe, 10))

Summarise the data by calculating the mean, variance, for each column and the correlation between each pair (eg. x1 and y1, x2 and y2, etc) (Hint: use the fBasics() package!)

  1. 9
  2. 9
  3. 9
  4. 9
  5. 7.50090909090909
  6. 7.50090909090909
  7. 7.5
  8. 7.50090909090909
  1. 11
  2. 11
  3. 11
  4. 11
  5. 4.12726909090909
  6. 4.12762909090909
  7. 4.12262
  8. 4.12324909090909
  1. 0.81642051634484
  2. 0.816236506000243
  3. 0.816286739489598
  4. 0.816521436888503

Create scatter plots for each x,y pair of data.

png
png
png
png

Now change the symbols on the scatter plots to solid circles and plot them together as a 4 panel graphic

png

Now fit a linear model to each data set using the lm() function.

Now combine the last two tasks. Create a four panel scatter plot matrix that has both the data points and the regression lines. (hint: the model objects will carry over chunks!)

png

Based on the figure from Dataset 1, the linear regression model seems to fit the data quite closely. However, for the figure from Dataset 2, the data seems to be of a curvilinear nature, possibly quadratic and the linear model fitting is inappropriate. Similarly, the linear model on the figure based on Dataset 3 is also erroneous; only 1 data point passes through the fitted line and one point is far away from the regression fitted line. For the figure from Dataset 4, one point is a clear outlier, while all the other points are clustered at the same x value. Hence, one should check the validity of the data. Additionally, if the data is accurate, then the linear model fit should be reported as-is. However, one should mention that one of the data points have played a crtical role in the linear regression model fitting of the data.

In text, summarize the lesson of Anscombe’s Quartet and what it says about the value of data visualization. Anscombe’s quartet provides a quick way to the idea that sometimes the visual dimension can reveal a story that simple numerical analysis appears to deny.

I hope you like it.

No matter what books or blogs or courses or videos one learns from, when it comes to implementation everything can look like “Outside the Curriculum”.

The best way to learn is by doing! The best way to learn is by teaching what you have learned!ç

See you on Linkedin!

Ref: https://rpubs.com/debosruti007/anscombeQuartet

Master in Data Science. Passionate about learning new skills. Former branch risk analyst. https://www.linkedin.com/in/oscar-rojo-martin/. www.oscarrojo.es

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store