Diagnostic analytics and causality - explained simply
Introduction and exam tips
Module 1 in plain language
Module 1 is about two things. First: how do you describe data, and how sure can you be of an average? Second: how do you find out why one customer, store or employee performs better than another? The second part is called diagnostic analytics.
You have a column of numbers, for example revenue per store. Two questions:
- Where is the middle? The mean adds everything up and divides. The median is the middle value. A few huge outliers pull the mean up, while the median stays put. If the mean is larger than the median, the distribution is right-skewed.
- How spread out are the values? The standard deviation is roughly the average distance to the mean. The range is maximum minus minimum. The interquartile range (IQR) is the distance between the 25th and the 75th percentile.
Many things follow a bell shape: height, IQ, stock returns. You only need two numbers: the mean and the standard deviation. Then the rule of thumb 68 - 95 - 99.7 applies: 68% of values lie within 1 standard deviation of the mean, 95% within 2, 99.7% within 3.
Example: the waiting time for an MRI scan is 7.1 weeks on average with a standard deviation of 2.3. A wait of 11.7 weeks is (11.7 - 7.1) / 2.3 = 2 standard deviations above the mean. Such a tells you how many standard deviations you are away from the centre. About 2.5% of patients wait longer than that.
You cannot ask everyone, so you draw a sample. A sample mean is never exactly the true population mean. Draw a new sample tomorrow and you get something slightly different. That is chance (noise).
The says: sample means are approximately normally distributed around the true mean. The spread of that distribution is called the : SE = s / sqrt(n). More people in your sample (larger n) means a smaller standard error. More spread in the data (larger s) means a larger standard error.
A puts a margin around the mean: mean plus or minus 1.96 times the standard error for 95%.
Example: mean 36.9, s = 14.3, n = 100. SE = 14.3 / 10 = 1.43. Interval: 36.9 plus or minus 1.96 x 1.43, roughly 34.1 to 39.7.
Mind what 95% means. If you repeated this many times, about 95% of the intervals would contain the true mean. It is not: “95% chance that the true mean lies in this one interval”, and not: “95% of the data lie in the interval”.
Suppose a retail chain spends a lot on advertising and wants to know how it works. You then follow a fixed route, the empirical cycle: research question, ideas from theory, hypotheses, model, data, analysis, conclusion.
Without hypotheses in advance you go “fishing” in your data. Test enough relationships and a few will always show up by chance (). Hypotheses in advance bring focus and decide which data you need to collect.
A drawing with boxes and arrows: what causes what?
Tap a part for the explanation from the summary.
The variable you assume affects Y.
The variable you want to explain or predict.
Lies between X and Y: X works on Y through M. Explains *how* the effect arises.
Changes the strength or direction of the effect of X on Y. Explains *when* the effect holds.
Affects both X and Y and can create a spurious relationship. Control for it.
A relationship between X and Y is not yet a cause: always ask which other variable may be behind it.
- Direct effect: advertising leads to more revenue.
- Indirect effect via a : advertising leads to more store visits, and store visits lead to more revenue. The mediator sits “on the way” between cause and effect.
- (interaction effect): the season determines how strong advertising works. Around Christmas, advertising works harder. The moderator points at another arrow.
- : more revenue gives a larger advertising budget. The arrow can also point the other way.
- : a third variable that influences both cause and effect, such as warm weather for ice cream sales and drownings.
Next to the arrows you put a plus (expected positive), a minus (expected negative), an asterisk (categorical variable) or a question mark (competing hypotheses: you can argue both ways).
Each arrow in your scheme is usually one hypothesis. A good hypothesis is testable, has a direction and names the variables clearly. For example: “Advertising spend has a positive influence on revenue.” The matching H0 (null hypothesis) says: there is no positive influence.
Only say “causes” if your data can show that, for example through an experiment. If you only have a survey, formulate an association: “students who spend more time on social media are less satisfied”.
- Nominal: names or categories without an order (country, gender).
- Ordinal: categories with an order, distances mean nothing (job level, preference).
- Continuous and discrete: real numbers (salary, class size). Together they are called quantitative.
The dependent variable is the outcome you want to explain, the independent variable is what you see as the cause.
: can you trust the answer for your own sample (good statistics, good sampling, no biases, no confounders)? : may you generalise it to other groups or other times?
Diagnostic analytics and causality - exam level
Introduction and exam tips
Module 1: exam level
Block 1 of the exam (4 MC, 10 points) and question 7.3 (7 points, max 150 words) come from this module. The rules for the CI and correlation are on the formula sheet (say so in your answer); the percentages of the normal distribution (68-95-99.7) are not on it, you have to know them.
- Mean = sum / n. Median = middle value after sorting. Mode = most frequent value.
- Skewness: symmetric gives mean = median; right-skewed gives mean > median; left-skewed gives mean < median. The mean is sensitive to outliers, the median is not.
- Dispersion: minimum, maximum, range (max - min), MAD (mean absolute deviation), variance, standard deviation (square root of the variance), coefficient of variation = sd / mean, percentiles and IQR (75th minus 25th percentile).
- R: mean(x), median(x), sd(x), var(x), range(x), quantile(x, 0.25), IQR(x), summary(x). In the output of summary() you read min, 1st Qu., Median, Mean, 3rd Qu., Max. Pitfall: var() and sd() divide by n - 1 (sample), the slide formula of the variance divides by n.
- A probability mass function belongs to discrete variables (all probabilities add up to 1); a probability density function to continuous ones (the area under the curve is 1). The probability of one exact value of a continuous variable is 0, a probability is an area between two values.
- Normal distribution: symmetric, mean = median = mode, determined by mu and sigma. 68% within 1 sigma, 95% within 2 sigma, 99.7% within 3 sigma.
- : Z = (x - mu) / sigma. Example: waiting time mu = 7.1 and sigma = 2.3 weeks: P(> 11.7) has Z = 2, so about 2.5%. P(4.8 < waiting time < 9.4) has Z between -1 and 1, so about 68%.
- R: pnorm(x, mu, sigma) gives the probability to the left of x (left tail is the default), so 1 - pnorm(11.7, 7.1, 2.3) for the right tail. qnorm(p) gives the critical value, for example qnorm(0.975) = 1.96.
- Pitfall: calculating the Z-score and then reading the probability from the wrong side (right versus left tail).
- A random variable is a quantity whose value depends on chance. The key question of statistics: is this signal or noise?
- Notation: mu (population mean), sigma (population sd), x-bar (sample mean), s (sample sd), n (sample size).
- Central limit theorem: the mean of a simple random sample of size n is approximately normally distributed with expectation mu and standard deviation sigma / sqrt(n), even if the population itself is not normal. In practice this works from n of about 20 to 30.
- = s / sqrt(n) (with sigma if known). The SE falls with a larger n and rises with a larger s. To halve the SE you need four times as many observations.
- Formula (on the formula sheet): CI = x-bar +/- t* x s / sqrt(n), or z* x sigma / sqrt(n) for known sigma or large n.
- Critical values: 90% gives 1.64, 95% gives 1.96 (rule of thumb 2), 99% gives 2.58. In R: qnorm(1 - alpha/2), for unknown sigma qt(0.975, df = n - 1).
- Example (Donations, simulated donations): x-bar = 36.9, s = 14.3, n = 100, so SE = 1.43 and CI = [34.1; 39.7].
- Correct interpretation: if you draw samples repeatedly, about 95% of the intervals contain the true mean (“we are 95% confident”). Incorrect: the probability that mu is in this one interval is 95%; 95% of the data lie in the interval; 95% chance that the sample mean of a repeat falls inside.
- A larger n or a smaller s gives a narrower interval; a higher confidence level gives a wider interval.
- Cycle: research question, ideas (theory, logic, earlier results), hypotheses, model, data, analysis, conclusion. Three ingredients between question and data: , hypotheses, model.
- Why hypotheses in advance? (1) Focus and discipline; (2) they steer data collection, so you do not collect the wrong data or answer a different question; (3) they prevent : whoever keeps searching finds relationships by chance; (4) they limit confirmation bias afterwards.
- Deductive (confirmatory) research starts with hypotheses, inductive (exploratory) research looks for patterns.
| Role | Meaning | Example |
|---|---|---|
| Direct effect | X acts directly on Y | advertising, revenue |
| sits between X and Y and explains the indirect effect | advertising, store visits, revenue | |
| determines the strength (or sign) of the effect of X on Y: interaction effect | season (Christmas or not) | |
| influences both X and Y and can create a spurious relationship | temperature for ice cream and drownings | |
| Y also influences X (simultaneous effects) | revenue, budget |
Tap a part for the explanation from the summary.
The variable you assume affects Y.
The variable you want to explain or predict.
Lies between X and Y: X works on Y through M. Explains *how* the effect arises.
Changes the strength or direction of the effect of X on Y. Explains *when* the effect holds.
Affects both X and Y and can create a spurious relationship. Control for it.
A relationship between X and Y is not yet a cause: always ask which other variable may be behind it.
- Arrow symbols: + expected positive, - expected negative, * categorical variable (moderator as a nominal variable), ? competing hypotheses.
- Recognising them: “explains how or through which channel” is a mediator. “Stronger for group A than for group B” is a moderator. “Influences both” is a confounder.
- A mediator sits in the causal path, a confounder stands outside it and causes X and Y. A moderator changes the strength of an arrow, a mediator adds an extra link.
- Only the relationships you ask about go into the scheme. You usually leave control variables out.
- Associative: “Students who spend more hours on social media are less satisfied with their studies.” Causal: “Limiting social media to 30 minutes a day increases satisfaction.”
- Choose causal only if your design allows causal inference (experiment: you intervene and see what changes). With a survey, only an associative hypothesis.
- A good hypothesis: testable, with a direction, variables named clearly. The H0 is the counterpart: no effect (for a directional H1: no positive influence).
- One hypothesis per arrow: H1 direct effect, H2 indirect effect via (“positive indirect influence via store visits”), H3 (“larger in the Christmas period than in other seasons”).
- A model is a formal, abstract and subjective representation of reality: no vagueness, only the essential features, assumed relationships. It is the framework within which you test hypotheses. An abstract concept (construct) does not have to be directly observable; you make it measurable through operationalisation.
- Measurement levels: nominal (no order), ordinal (order, distances meaningless), continuous and discrete (both quantitative). In R: character or factor, ordered factor, double, integer.
- Dependent variable (Y, outcome) and independent variable (X, explanatory variable).
- : how trustworthy is the answer for the source population itself? Depends on statistics, sampling method, biases and confounders.
- : how well can you generalise to the target population, other groups or other times? Pitfall: a source population that is too specific.
- Experiment versus observational data (survey): an experiment (preferably with random assignment) gives strong evidence for causality; observational data gives associations. That is why causal conclusions from a survey are wrong.
- Ceteris paribus: causality means that a change in X leads to a change in Y while all other influences stay constant.
cor(School$Sat, School$Debts) gives 0.166 and cor(School$CostTot, School$Debts) gives 0.424. That is association, not proof that higher costs cause debts: the differences between groups (tapply, aggregate) only show that averages differ.
- Reading the 95% CI as “95% chance that mu is inside”.
- Confusing SE with sd (SE is about the mean, sd about the data).
- Mixing up and .
- A causal conclusion from a survey.
- A hypothesis that is not testable (“social media is important”) or has no direction.
- Formulating hypotheses only after looking at the data.
Module 1 as Harwin says it
Introduction and exam tips
Module 1 as Harwin says it
Harwin de Vries explains module 1 in the lecture in Dutch, with English technical terms. The quotes below are verbatim from the lecture (Whisper transcript) or from the slides and stay in the original language. Each quote comes with an explanation in my own words. The lecture rests on four ideas: signal versus noise, the central limit theorem, the causal relationship scheme and the role of hypotheses in advance.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 1:07:57:
De uitkomst van een random variabele, is dat nou toeval dat we deze uitkomst hebben? of moeten we hier echt een signaal in zien?
The core question of statistics: is a difference real or pure chance? Every number from a sample is an outcome of a random variable. Without a measure of uncertainty you do not know whether a rise in revenue or conversion is a signal.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 1:34:23:
Het gemiddelde van een sample is normaal verdeeld.
Harwin himself calls it “loosely formulated”: it is an approximately normal distribution, and the nuance follows right after. What matters is that this holds regardless of the shape of the population.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 1:40:00:
en de standaard afwijking van die normale verdeling die bereken je als sigma gedeeld door de wortel n en die noemen wij de standard error
SE = sigma / sqrt(n). Here you see why a larger sample (n) and less spread (sigma) make you more certain about the mean. The standard error is the spread of the sample mean, not of the data.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 1:43:39:
Dus ik heb net die 36,9. Bereken ik een betrouwbaarheidsinterval eromheen.
The example uses the Donations data: mean 36.9, s = 14.3, n = 100, SE = 1.43. The interval is the mean plus or minus 1.96 times SE.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 1:48:23:
Dus waar onze kansuitspraak over gaat, het gaat over onze methode.
The 95% belongs to the method, not to the one interval you have calculated. That one interval either contains mu or it does not, like the ball under one of two cups. Repeat the method often and about 95% of the intervals contain the true mean.
Dia 52 uit BM21MIM-P - Session 2:
Without hypotheses: may find relationships “by chance” ()
Hypotheses bring discipline and focus. Without hypotheses you find relationships that are pure chance (data dredging). Harwin adds that hypotheses also decide which data you collect.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 2:09:58:
dat je gaat zitten vissen in de de data en dan per toeval iets vindt wat meer toevalgedreven is dan echt een signaal is
Whoever jumps from the question straight to the data runs three risks: collecting the wrong data, answering a different question, or finding something by chance.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 2:16:04:
Tap a part for the explanation from the summary.
The variable you assume affects Y.
The variable you want to explain or predict.
Lies between X and Y: X works on Y through M. Explains *how* the effect arises.
Changes the strength or direction of the effect of X on Y. Explains *when* the effect holds.
Affects both X and Y and can create a spurious relationship. Control for it.
A relationship between X and Y is not yet a cause: always ask which other variable may be behind it.
En die store visits in zo’n indirect effect, dat wordt een medierende variabele genoemd.
Advertising leads to more store visits and those lead to more revenue. The store visits lie in the causal path and explain the indirect effect. Harwin calls this “an important term to remember”.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 2:16:04:
dat die afhangt van een andere variabele, van een derde variabele, namelijk het seizoen.
The strength of the effect of advertising on revenue depends on the season: around Christmas advertising works harder. In the scheme the arrow of the moderator points at the arrow itself. In data the line is steeper in the Christmas period.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 2:21:16:
Het betekent, ik kan beide kanten opredeneren.
A question mark (or plus/minus) at an arrow does not mean “no idea”. It means you can argue for both a positive and a negative effect. The data then decide which explanation gets support.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 2:25:15:
Maar het is dus een fout als je zegt, ik formuleer hem causaal, maar mijn data stellen me eigenlijk niet in staat om dat te testen.
Your hypothesis must fit what your data can do. A survey gives an association. An experiment, where you change something and measure the outcome, may be worded causally. This is a common mistake in exam answers.
Gezegd door Harwin de Vries in Module 1 - Opname college (video), minuut 2:30:13:
Alles moeten we vanaf nu gaan specificeren. Dus het wordt heel erg formiel. Geen vaagheid. Alle termen zijn precies gedefinieerd.
A model is an abstract representation of reality, like the London Underground map. It is formal (no vagueness) and abstract (not everything is included). It provides the framework in which you test the hypotheses and forces you to decide how you measure variables.
A university looks at student debts (Debts) in the file School.csv (80 universities, one mean per university). Real output from m1-school-correlatie and m1-school-groepsgemiddelden.
- Association: cor(Sat, Debts) = 0.166, cor(CostTot, Debts) = 0.424. Higher total costs go together with higher debts, but that is an association.
- Group difference: the mean debt is 11.35 for Toefl = 0 and 13.56 for Toefl = 1. A difference between groups is not yet a cause.
- Wording: “higher costs are associated with higher debts” is associative. “Higher costs cause higher debts” is causal and needs a mechanism, a time order and the exclusion of a third variable, for example the type of school the university belongs to.
- So you formulate your hypothesis in advance, with a direction and an H0, and you examine a possible or explicitly instead of fishing in the data afterwards.
Own case in the style of question 7.3 (7 points, maximum 150 words); the answer model of the practice exam itself is in Practice exam 0.
Case: a supermarket chain investigates whether a loyalty app (X) raises spending per customer (Y). The effect runs through the number of visits per month, and according to the marketer it is stronger for customers in big cities.
- Roles (2 p): the number of visits is a (app, then more visits, then higher spending). The place of residence (big city or not) is a : it determines how strong the effect of the app is.
- Hypothesis (3 p): H1: use of the loyalty app has a positive effect on spending per customer. H0: use of the loyalty app has no positive effect on spending.
- Why in advance (2 p): formulate your hypothesis before you see the data. It then steers which data you collect, and you avoid taking a chance pattern as confirmation afterwards (confirmation bias).