Causal inference in ecology with R

Causal inference in ecology with R: confounding, colliders, BACI, instrumental variables, propensity scores, panel designs, and the assumption no diagnostic can test.

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

Designs that identify

Adjusting for what you measured

Panels: units and time

The assumption you cannot test

Where this connects

Newsletter

Get new tutorials by email

New R and QGIS tutorials for ecologists, straight to your inbox. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.