Descriptive statistics, sampling and correlation - explained simply
Introduction and exam tips
Module 2 in plain language
Module 2 is about three questions. How do you describe data honestly? How do you get a sample that is useful? And how do you measure whether two variables go together, without immediately claiming that one causes the other?
A newspaper headline says that sales fell in April. That can be true and still mislead: one month was looked at instead of the trend, the comparison is with the month before instead of a year earlier, and the axis does not start at zero. Those are choices, and choices change the story. Descriptive statistics are therefore never neutral.
For numbers you use the mean, median, standard deviation and interquartile range. For categories you count: a frequency table, a bar chart or a pie chart. A mean of the codes 1, 2 and 3 for “city, suburb, rural” means nothing. For visuals you choose the histogram for one variable, the scatter plot for two numbers and the box plot for a number per category.
You can rarely ask everyone. So you first choose your population (who do you want to say something about?) and then a sample. Two kinds of validity matter:
- Internal validity: can you trust the answer for the group you drew from (the )? That depends on good statistics, good sampling and the absence of biases.
- External validity: can you generalise the answer to the , other groups or other times?
A source population that is too specific (only the students of one programme) costs you external validity.
A sample is representative if it looks like the population. The simplest route is : everyone has the same chance. In practice that often fails. The Literary Digest poll of 1936 asked 10 million people and received 2.3 million answers, but it picked car owners, phone users and subscribers. They were wealthier, and the prediction was wrong. A big sample does not rescue a bad selection.
- : first split the population into groups (strata), then draw from each group. This way your sample is balanced.
- : every tenth person, with a fixed step size.
- : first randomly choose clusters (schools, cities, companies) and collect data inside them.
A sample mean always differs a little from the true mean. A random deviation is non-systematic. A deviation with a direction is a bias:
- : your design over- or under-represents some groups.
- : some groups disproportionately often do not take part.
- : people answer differently from how they behave, for example because of the order of the questions.
A gives one number (the sample mean). An gives an interval that contains the true mean with a certain probability. The central limit theorem says that the mean of a sample is approximately normally distributed around the true mean, with spread sigma divided by the square root of n: the standard error. From n = 20 to 30 this works in practice.
The 95% confidence interval is the mean plus or minus 1.96 times the standard error (90%: 1.64; 99%: 2.58). If you do not know sigma, use s and the t-distribution. The 95% belongs to the method: if you draw samples often, about 95% of the intervals contain the true mean.
Draw a line through the mean of x and of y. Each point forms a rectangle with the centre of gravity. Points top right and bottom left give a positive rectangle, the other two quadrants a negative one. The average size is the covariance. It has a drawback: the number can be anything and depends on the unit. Therefore we divide by the spreads and get the correlation r, between -1 and +1.
Watch out for three things:
- An outlier can pull r far up or down. Always look at the scatter plot.
- Pearson only measures linear association. An r of 0 does not mean there is no relationship.
- Spearman uses ranks and fits a rising relationship that is not straight.
If A and B go together, A can be the cause, B can be the cause, it can be chance, they can influence each other, or a third variable (confounder) can cause both. Ice cream sales and drownings go together because warm weather raises both. Such a fake relationship is called . The controls for that third variable and shows what is left.
Finally: statistical dependence is something different from causality. Two variables are independent if knowing what one does does not change the probability of the other.
Descriptive statistics, sampling and correlation - exam summary
Introduction and exam tips
Module 2: exam material
Descriptive statistics are summary measures for quantitative data: mean, median, standard deviation, interquartile range. A mean larger than the median points to a tail to the right. A Z-score is (x - mean) / sd and counts the number of standard deviations from the mean; a value with |Z| larger than 2 stands out. The outlier fences of the box plot are Q3 + 1.5 x IQR and Q1 - 1.5 x IQR.
Tap a part for the explanation from the summary.
The average: the sum of all values divided by their number. Sensitive to outliers.
The middle value of the ordered data. Not sensitive to outliers.
The most frequent value. Also usable for categorical variables.
How far values lie from the mean on average: the square root of the variance.
Choose the measure to fit the distribution: with a skewed distribution and outliers the median is more robust than the mean.
A summary is never neutral. The retail newspaper example made three choices: one observation instead of the trend, the previous month as reference instead of a year earlier, and an axis that does not start at zero. For every chart ask which choice is behind it.
Qualitative data are described with a frequency table, bar chart or pie chart. A mean of category codes has no interpretation.
- Histogram: the distribution of one quantitative variable (bins).
- Scatter plot: relationship between two quantitative variables, possibly a third as colour.
- Box plot: a quantitative variable per category (median, quartiles, outliers).
You draw a sample from a population to say something about it. The three levels are (what you want to say something about), (what you really draw from) and study sample.
- Internal validity: how trustworthy is the answer for the source population? Depends on statistics, sampling design and biases and confounders.
- External validity: to what extent do you generalise to other populations or times?
Pitfall in a thesis: a source population that is too specific costs external validity. means that mean, spread and shape of the sample resemble those of the population.
- : every element has the same probability. Easy in theory, hard in practice (the Literary Digest example of 1936: large sample, wrong selection).
- : divide into strata (age, gender, department) and draw from each stratum. This way the sample is balanced on those characteristics.
- : ordered list, fixed step size. With N = 2000 and n = 50 you take every 40th.
- : randomly choose clusters (schools, cities, companies) and collect data inside them.
The advantage of the alternatives: less effort in data collection, often a better estimate.
is the difference between a sample statistic and the population value (x-bar versus mu). Non-systematic errors come from chance and have no direction. Systematic errors are biases:
- : the sampling design over- or under-represents groups.
- : some groups disproportionately often do not take part.
- : answers are systematically not in line with reality. Example: the same two product pictures in reversed order gave 56% for the first picture in sample 1 and 58% for the first (other) picture in sample 2.
A larger n reduces the chance error, but does not remove bias.
Inference is a conclusion about the population based on a sample. Two sources of uncertainty: sampling variation and unknown population characteristics. A gives one number; an gives an interval that contains the parameter with a certain probability.
For a random variable with expected value mu and finite variance sigma squared, the mean of a simple random sample of size n is approximately normally distributed with mean mu and standard deviation sigma / sqrt(n): the standard error (SE). In practice this works from n = 20 to 30.
- 95% confidence interval: x-bar plus or minus 1.96 x SE; 90%: 1.64; 99%: 2.58.
- Unknown sigma: use s and t* from the t-distribution: CI = x-bar plus or minus t* x s / sqrt(n).
- A higher confidence level means a wider interval; four times as many observations halves the SE.
- Interpretation: the 95% belongs to the method, not to one interval.
In R: qnorm(0.975) = 1.96; pnorm gives the left tail, the right tail is 1 - pnorm(); qt(0.975, df) gives t*.
Cov(X, Y) = sum of (x_i - x-bar)(y_i - y-bar), divided by n - 1. It is the average rectangle area around the centre of gravity. Positive means x and y rise together, negative that one rises when the other falls. Drawback: the value depends on the units and can be anything, so it is hard to interpret.
Pearson: r = Cov(X, Y) / (sd(X) x sd(Y)). Always between -1 and +1, unit-free. Example: Cov = 54, sd’s 12 and 9 gives r = 54 / 108 = 0.5. What is strong or weak depends on the context.
Three pitfalls:
- An outlier can pull r strongly up or down. A conclusion based on r alone is wrong; always look at the scatter plot.
- An r around 0 does not mean there is no relationship; Pearson only measures linear association (y = x squared gives r = 0).
- For a non-linear but rising relationship Pearson gives a value below 1.
Spearman is the correlation of the ranks and fits monotone non-linear relationships and outliers.
A correlation between A and B can arise from: A causes B, B causes A (reverse causality), chance (mozzarella and doctorates), feed-forward (police and crime; cycling and BMI), or a third variable C (confounder: ice cream sales and drownings via temperature).
A is a statistical relationship without a causal one, due to chance or a confounder. The measures the relationship between X and Y after controlling for Z:
r_XY.Z = (r_XY - r_XZ x r_YZ) / sqrt((1 - r_XZ squared)(1 - r_YZ squared)).
A partial correlation much smaller than r_XY points to a confounder or to a mediator; the design (the causal order in the scheme) decides which of the two it is.
Causal relationship: a change in X leads to a change in Y while all other influences stay constant (ceteris paribus). Statistical relationship: the joint distribution shows a systematic pattern. Causality is not the same as statistical dependence; dependence can be determined objectively from data, causality is harder.
Two variables are statistically independent if the marginal distribution equals the conditional distribution: P(buy) = P(buy | blue website). Information about X then has no predictive value for Y.
The exam does not ask for R code, but it does ask you to interpret output. In summary() you compare mean and median; in cor.test() you read r, t, df, the p-value and the 95% confidence interval. If the interval contains 0, the correlation is not significant at 5%. You read a correlation matrix per pair; a single outlier can make a significance disappear or appear.
Suppose n = 100, mean 50 and s = 20 (simulated data). Then SE = 20 / sqrt(100) = 2. The 95% confidence interval is 50 +/- 1.96 x 2, so [46.08; 53.92]. To halve the SE to 1 you need n = 400: four times as many, because the SE falls with the square root of n. A higher confidence level (99%: 2.58) makes the interval wider, a larger n makes it narrower.
- Saying that a strong correlation proves causality.
- Thinking that the 95% is a probability for this one interval.
- Seeing a larger sample as a cure for .
- Reading r = 0 as “no relationship”.
- Interpreting a correlation without the scatter plot.
Module 2 as Harwin says it
Introduction and exam tips
Module 2 as Harwin says it
Harwin de Vries explains module 2 in lectures 2.1 and 2.2 in Dutch, with English technical terms. The quotes below are verbatim from the video (Whisper transcript) or from the slides and stay in the original language. Each quote comes with an explanation in my own words. The focus is on three ideas: a sample is only useful if it is representative and valid, an interval belongs to a method, and a correlation is a summary that you may never read without the data.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 13:26:
Dus externe validiteit zegt iets over de mate waarin jouw resultaten kunnen worden gegeneraliseerd.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 14:26:
Dus interne validiteit die kijkt juist naar jouw studiesample zelf.
External validity is about generalising to other populations or times. Internal validity is about how trustworthy the answer is for the itself. The distinction between , source population and study sample returns often in the exam, especially in open questions about the credibility of conclusions.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 10:04:
Dus de sample was totaal niet representatief.
In the 1936 poll 2.3 million people took part, but they were car owners, phone users and magazine members. The error was in the selection, not in the number. beats size.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 19:56:
Dat zorgt ervoor dat je sample in elk geval gebalanceerd is langs die specifieke karakteristieken.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 20:23:
Dus nummertje 1, nummertje 11, nummertje 21 of iedere tiende bezoeker van mijn supermarkt ga ik benaderen.
With you first divide into strata and draw a predetermined number from each, so that the sample is right on those characteristics. With systematic sampling you choose a fixed step, for example every tenth visitor.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 20:55:
ga je eerst een subset van de clusters random selecteren.
With cluster sampling you first randomly choose clusters, such as schools, cities or companies. Then you collect data inside those clusters. It saves a lot of effort in data collection.
Dia 20 uit BM21MIM-P - Module 2:
Selection bias: Sampling design leads to systematic over- or under-representation of groups in the population
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 24:31:
We krijgen een bias doordat bepaalde groepen in de populatie een grotere, een disproportioneel grote neiging hebben om wel of niet mee te doen in de studie.
Selection bias sits in the design: some groups appear too often or too rarely. Non-response bias arises when the invitation was broad, but some groups drop out more often. In both cases the mean shifts in one direction.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 25:06:
Dat is waarbij mensen antwoord geven, maar waarbij het antwoord niet in lijn is met wat ze werkelijk zouden doen.
The perfume example shows that the same pictures in a different order give a different preference. The reported preference is then not equal to real behaviour.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 29:41:
Tap a part for the explanation from the summary.
The average: the sum of all values divided by their number. Sensitive to outliers.
The middle value of the ordered data. Not sensitive to outliers.
The most frequent value. Also usable for categorical variables.
How far values lie from the mean on average: the square root of the variance.
Choose the measure to fit the distribution: with a skewed distribution and outliers the median is more robust than the mean.
Een puntschatter is een methode die een specifiek getalletje produceert.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 34:02:
Dus in de praktijk zeggen we, als je een samplegrootte hebt van twintig of dertig, dan is het eigenlijk best wel prima om die normale verdeling al te gebruiken.
A point estimator gives one number, an an interval. The central limit theorem makes the interval possible: the sample mean is approximately normally distributed, and in practice an n of 20 to 30 is enough.
Gezegd door Harwin de Vries in Module 2.1 - High Mastery (video), minuut 34:02:
dat met 95% kans die x-bar die wij krijgen, maximaal 1,96 standard errors weg ligt van het echte gemiddelde
The probability statement is about the method: x-bar lies with 95% probability at most 1.96 standard errors from mu. Therefore x-bar plus or minus 1.96 x SE is the 95% confidence interval. For 90% you use 1.64 and for 99% 2.58.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 06:44:
Het kan in principe iedere mogelijke waarde tussen minus oneindig en plus oneindig aannemen.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 06:44:
De correlatie is eigenlijk gelijk aan de covariantie, maar dan genormaliseerd.
The covariance is the average area of the rectangles around the centre of gravity, but the value is hard to read. By dividing by the spreads you get the correlation between -1 and +1.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 09:46:
Dus jouw correlatiecoëfficiënt kan enorm worden beïnvloed door outliers.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 11:19:
Het is verkeerd om te zeggen, als we geen correlatie hebben, dan is er geen relatie.
One outlier can inflate a correlation, and a correlation of almost zero does not rule out a non-linear relationship. Therefore always look at the scatter plot.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 12:55:
In plaats van naar de absolute x-waardes of de y-waardes, kijkt die naar de rang van de x-waardes en de y-waardes.
Spearman ranks x and y and correlates the ranks. For a rising but not straight relationship Spearman comes closer to 1 than Pearson. You do not need to know the formula.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 20:52:
Dat is eigenlijk een soort van een nep correlatie, een fake correlatie.
Dia 43 uit BM21MIM-P - Module 2:
The measure of the relationship between two variables while controlling for the effect of a third variable.
A is a statistical relationship without a causal one: due to chance or a confounder such as temperature. The partial correlation filters out the effect of that third variable.
Gezegd door Harwin de Vries in Module 2.2 - High Mastery (video), minuut 28:31:
De occurrence van één event bepaalt niet of heeft geen impact op de kans dat dat andere event gebeurt.
With independence, knowing one event does not change the probability of the other. The red or blue website then does not change the probability of a purchase. That is something different from causality.
An energy company studies 211 homes (Energy02.csv). Real output from m2-energy-cortest and m2-energy-cor.
- Pearson r between pEnergy and pCool is 0.086 (t = 1.242, df = 209, p = 0.2156). The 95% interval runs from -0.050 to 0.218 and contains 0.
- Spearman gives 0.138: the rank association is slightly stronger, but also weak.
- Conclusion: at alpha = 0.05 H0 (rho = 0) is not rejected. That is not proof of independence, only too little evidence for a relationship.
Case: assignment 3 (energy and cooling costs), part a, 3 points, maximum 100 words.
- Strength (1 p): r = 0.086 is very weak.
- Significance (1 p): p = 0.2156 is larger than 0.05, so H0 is not rejected. The interval -0.050 to 0.218 contains 0, which fits.
- Caution (1 p): this does not prove independence; the data give too little evidence for a relationship.