Causal inference in ecology with R
Ecologists almost never get to randomise. The protected area was placed where the land was cheap, the fire burned where the fuel was, the restoration went to the sites someone cared about. Every one of those is a treatment assigned by a process that also affects the outcome, which is the definition of the problem, and no amount of model fit repairs it. A regression on observational data returns an association. Turning that into a causal claim takes an argument, and the argument has to be made before the model runs.
This page collects every causal inference tutorial on this site. All of them are built by hand in base R on simulated data where the true effect is known, which is the only way to show that a method recovers it.
Adjusting for everything is the wrong instinct
The reflex is to put every measured variable on the right-hand side. It is wrong, and it is wrong in a way that no diagnostic reports. Adjusting for a confounder removes bias. Adjusting for a mediator removes part of the effect you are trying to measure. Adjusting for a collider, a variable that both the treatment and the outcome cause, MANUFACTURES an association out of nothing: the model fits well, the coefficient is significant, and the correlation it reports does not exist in the world. Selection works the same way. If your sites got into the data set because of something both variables influence, you have conditioned on a collider without writing a single line of adjustment.
So the covariate set is a decision, and it is a decision about causal structure, which no dataset contains. That is why this family starts with a diagram rather than a data frame.
Two ways out, and they are different in kind
Designs that identify. Some situations carry their own argument. A threshold rule that decides who gets treated makes the units either side of it comparable by construction. A variable that shifts treatment without touching the outcome any other way is an instrument. A before-after contrast at both an impacted and a control site differences out the trend and the site difference at once. These do not need you to have measured the confounders. They need a structural claim to be true, and that claim is usually the thing worth arguing about in the paper.
Adjustment for what you measured. Propensity scores, weighting, standardisation and matching all assume the confounders are in your data, and then differ in how they use them. Doubly robust estimation is the neat one: combine an outcome model and a treatment model, and consistency survives either being wrong. It does not survive both being wrong, and it does not survive a confounder you never measured.
The assumption you cannot test
No unmeasured confounding is not testable. Not with a residual plot, not with cross-validation, not with a bigger model. What you can do is ask how strong a hidden confounder would have to be to overturn the result, and answer in units someone can argue with: stronger than elevation? Stronger than anything you did measure? That reframing is the honest end of this literature, and it is where an ecological causal claim should finish.
The tutorials
The two mistakes that decide everything
- Confounding and backdoor adjustment - which covariates to adjust for, and why a mediator is not one of them.
- Collider bias and selection - how conditioning on a common effect invents a correlation, and how sampling does it silently.
Designs that identify
- Before-after-control-impact - the interaction that differences out both a trend and a site difference.
- Instrumental variables and 2SLS - recovering an effect when the confounder was never measured.
- Regression discontinuity - a threshold rule as a local experiment.
Adjusting for what you measured
- Propensity scores and IPW - weighting by the probability of treatment, with balance and overlap checked.
- G-computation and standardisation - the same adjustment written as an outcome model and averaged.
- Doubly robust estimation with AIPW - two chances to be right, and what still kills it.
- Propensity score matching - pairing rather than weighting, and what that trades away.
Panels: units and time
- Event-study difference-in-differences - one number becomes a path, and the pre-treatment periods become a check.
- Staggered adoption and two-way fixed effects - why the standard regression is biased when timing varies.
- The synthetic control method - a weighted comparison unit when only one unit was treated.
- Placebo tests for panel designs - inference from permutation when the usual standard errors cannot be trusted.
The assumption you cannot test
- Sensitivity to unmeasured confounding - how far a hidden confounder would have to reach, in units you can argue about.
- Checking causal assumptions - negative controls, and honest bounds on an untestable premise.
Where this connects
- Path analysis, piecewise SEM and d-separation and checking a structural equation model fit a whole diagram rather than one effect, and hit the limit that Markov-equivalent graphs cannot be told apart.
- Pseudoreplication is what happens to the standard error when the experimental unit is not what you think it is.
- Collinearity and VIF explains why throwing correlated covariates at the problem does not help either.
- Ecological time series in R covers convergent cross mapping, which asks the causal question from dynamics rather than from a design.