Anscombe’s Quartet

Hywel Owen
(c) University of Manchester, 2015

20 April 2015

Anscombe’s Quartet

In this notebook we numerically demonstrate Anscombe’s Quartet, which illustrates the importance of graphing data as well as carrying out numerical measures of the statistical properties of that data. We use the data given in the Wikipedia article here:
http://en.wikipedia.org/wiki/Anscombe’s_quartet

First we define the four data sets: (x1,y1), (x2,y2), (x3,y3), (x4,y4).

x1={10,8,13,9,11,14,6,4,12,7,5};
y1={8.04,6.95,7.58,8.81,8.33,9.96,7.24,4.26,10.84,4.82,5.68};

x2={10,8,13,9,11,14,6,4,12,7,5};
y2={9.14,8.14,8.74,8.77,9.26,8.1,6.13,3.1,9.13,7.26,4.74};

x3={10,8,13,9,11,14,6,4,12,7,5};
y3={7.46,6.77,12.74,7.11,7.81,8.84,6.08,5.39,8.15,6.42,5.73};

x4={8,8,8,8,8,8,8,19,8,8,8};
y4={6.58,5.76,7.71,8.84,8.47,7.04,5.25,12.5,5.56,7.91,6.89};

Numerical Calculations

We can tabulate the data to make it look nicer:

TableForm[{x1,y1,x2,y2,x3,y3,x4,y4},TableHeadings->{{"x1","y1","x2","y2","x3","y3","x4","y4"},None},TableAlignments->Center]

We calculate the mean of the four x arrays:

Mean[#]&/@{x1,x2,x3,x4}

and then their variances:

Variance[#]&/@{x1,x2,x3,x4}

We calculate the mean of the four y arrays:

Mean[#]&/@{y1,y2,y3,y4}

and then their variances too:

Variance[#]&/@{y1,y2,y3,y4}

We may also calculate the correlation between each pair of datasets, e.g. {x1,y1}:

Correlation@@#&/@(Transpose[#]&/@data)

And finally, we can show the linear model fits to each of the data sets:

#["BestFit"]&/@(LinearModelFit[#,x,x]&/@data)

Visualising the Data

We define a single list that has all the data in it:

data={{x1,y1}//Transpose,{x2,y2}//Transpose,{x3,y3}//Transpose,{x4,y4}//Transpose};

We make linear regression lines for each of the data sets using LinearModelFit, and make plots of those lines which we keep for later.

fittedlines=Plot[#["BestFit"],{x,2,20},PlotStyle->Blue]&/@(LinearModelFit[#,x,x]&/@data);

We also make plots of the data itself using ListPlot:

plotteddata=ListPlot[#,LabelStyle->{FontFamily->"Arial",FontSize->18}, Frame->True,GridLines->None,FrameLabel->{"x","y"},PlotStyle->{Orange,AbsolutePointSize[10]}, ImageSize->400,PlotRange->{{2,20},{2,14}}]&/@data;

We then plot each data set with its own fitted line, and group the plots into a 2x2 grid:

anscombeplot=GraphicsGrid[Partition[Show[#]&/@Transpose[{plotteddata,fittedlines}],2]]

Export["anscombe.png",anscombeplot]