DATA4207 · Data Analysis in the Social Sciences
Visualising Data, Confounding, and Linear Regression
Week 2 builds visualisation skill with the ggplot2 grammar of graphics and the judgement of when a graph beats a table, then introduces randomisation, confounding, and simple linear regression. You connect a clean plot to a first fitted model and interpret its slope, intercept and fit. This is where the regression interpretation the group projects and the individual report lean on all semester starts.
What this chapter covers
- 01The ggplot2 grammar of graphics: data + aesthetics + geoms layered coherently (geom_point, geom_smooth(method = lm))
- 02Choosing a visualisation by data, audience and purpose; Tufte's data-ink ratio and EDA
- 03Randomisation, and why controlling for confounders (education, income, gender, birthplace) matters
- 04Confounding variable: a factor affecting both X and Y, identified before analysis from theory/literature
- 05Simple and multiple linear regression: y = α + βx + ε; slope = expected change in y per unit x, holding controls constant
- 06Reading regression output: coefficient estimates and standard errors, baseline (reference) categories, R²
- 07The five OLS assumptions: linearity, independence, normality of residuals, homoscedasticity, no multicollinearity
- 08Interaction terms and how controlling for a confounder changes the slope of interest
Interpreting a simple linear regression
- +1Fitted model: rent = α + β·size + ε = 250 + 22·size. The intercept α = 250 and slope β = 22 come straight off the lm() output.
- +1Slope: each additional 1 m² of floor area is associated with about A$22 more rent per month, holding any other predictors constant. The slope is rise/run — the expected change in y per one-unit change in x.
- +1Intercept: the predicted rent at size = 0 m², A$250 — substantively meaningless (there is no zero-size flat), which is why centring the predictor makes the intercept interpretable.
- +1Prediction at 40 m²: 250 + 22·40 = 250 + 880 = A$1,130/month. R² ≈ 0.35 means the model explains about 35% of the variance in rent — a typical, modest fit for a single social predictor.
Key terms
- Grammar of graphics (ggplot2)
- A layered system for building plots from data, aesthetic mappings (aes) and geoms. A typical call is ggplot(data, aes(x, y)) + geom_point() + geom_smooth(method = lm) — one coherent grammar rather than one function per chart type.
- Confounding variable
- A factor that influences both the predictor and the outcome, biasing the observed relationship if uncontrolled (e.g. gender confounds a height→earnings link). Identified before analysis from theory and the literature and added as a control.
- Simple linear regression
- The model y = α + βx + ε fit by lm(): α is the intercept, β the slope (expected change in y per unit x), ε the error term. With controls it becomes multiple regression and each β is read 'holding the others constant'.
- R-squared
- The proportion of variance in the outcome explained by the model, from 0 to 1. Social-science models with one predictor often have a low R² (around 0.1), which is normal, not a mistake.
- Baseline (reference) category
- The omitted level of a categorical predictor against which the other levels' coefficients are read. Set it deliberately with relevel() so the contrasts are interpretable.
- Homoscedasticity
- One of the five OLS assumptions: the variance of the residuals is constant across the range of the predictors. A funnel shape in a residuals-vs-fitted plot signals it is violated.
Visualising Data, Confounding, and Linear Regression FAQ
When should I use a graph instead of a table?
Use a graph when the pattern — a trend, a comparison, a distribution — is what the reader needs, and a table when exact values matter. The unit follows Tufte: show the data, maximise the data-ink ratio, and design a figure a reader can grasp in a couple of seconds. Exploratory plots also help you check assumptions and spot outliers before modelling.
What exactly is a confounder and why control for it?
A confounder influences both your predictor and your outcome, so leaving it out makes the observed relationship misleading — the classic example is gender confounding the link between height and earnings. You identify likely confounders from theory and the literature before analysis and include them as controls, which isolates the effect of interest and often turns out to be substantively interesting in its own right.
How do I interpret a regression slope in a report?
State it as an expected change: 'a one-unit increase in X is associated with a β change in Y, holding the other predictors constant.' Add whether it is statistically meaningful and be careful with the word 'cause' — most social-science designs support association, not causation.
Can AI help me with linear regression in DATA4207?
Yes, as a study aid. Sia can explain the grammar of graphics, the meaning of a slope, intercept and R², and how a confounder biases a coefficient, and it can check your interpretation of lm() output step by step. It teaches the method and checks your reasoning; it does not do graded work, and University of Sydney academic-integrity rules apply — confirm on Canvas whether AI is permitted for a given task.
Assessment move
Pair every plot with a model this week. In R, take a real dataset, draw a scatter with geom_point() and a fitted line with geom_smooth(method = lm), then fit the same relationship with lm() and read off the slope, intercept and R². Practise writing the one-sentence interpretation of a slope 'holding controls constant', and deliberately add a confounder to a model to watch the coefficient of interest move — that is the intuition the group projects and the individual report reward. Memorise the five OLS assumptions now; Week 3 makes you check them. These skills feed the descriptive-then-model workflow used in every DATA4207 assessment, so rehearse them on your own project idea, and confirm lab tasks on Canvas.
Working through Visualising Data, Confounding, and Linear Regression in DATA4207? Sia is AskSia’s AI Statistics tutor — ask any DATA4207 Visualising Data, Confounding, and Linear Regression question and get a clear, step-by-step explanation grounded in how DATA4207 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.