diff --git a/R/setup.R b/R/setup.R index 04047dc..60a8afb 100644 --- a/R/setup.R +++ b/R/setup.R @@ -58,3 +58,29 @@ est_ci <- function(.df, rsample = FALSE) { glue::glue("{.df$estimate} (95% CI {.df$conf.low}, {.df$conf.high})") } } + +# based on https://github.com/hadley/r-pkgs/blob/main/common.R +status <- function(type) { + status <- switch(type, + unstarted = "is unstarted, but don't worry, it's on our roadmap", + polishing = "has its foundations written but is still undergoing changes", + wip = "is actively undergoing work and may be restructured or changed. It may also be incomplete", + complete = "is mostly complete, but we might make small tweaks or copyedits", + stop("Invalid `type`", call. = FALSE) + ) + + class <- switch(type, + complete = , + polishing = "callout-note", + wip = "callout-warning", + unstarted = "callout-warning" + ) + + knitr::asis_output(paste0( + "::: ", class, "\n", + "## Work-in-progress 🚧\n", + "You are reading the work-in-progress first edition of *Causal Inference in R*. ", + "This chapter ", status, ". \n", + ":::\n" + )) +} diff --git a/chapters/01-casual-to-causal.qmd b/chapters/01-casual-to-causal.qmd index 3074e4d..0f6d46f 100644 --- a/chapters/01-casual-to-causal.qmd +++ b/chapters/01-casual-to-causal.qmd @@ -4,6 +4,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("complete") +``` + ## Casual inference The heart of causal analysis is the causal question; it dictates what data we analyze, how we analyze it, and to which populations our inferences apply. diff --git a/chapters/02-whole-game.qmd b/chapters/02-whole-game.qmd index a51110d..38e43c7 100644 --- a/chapters/02-whole-game.qmd +++ b/chapters/02-whole-game.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("complete") +``` + In this chapter, we'll analyze data using techniques we learn in this book. We'll play the [whole game](https://www.gse.harvard.edu/news/uk/09/01/education-bat-seven-principles-educators) of causal analysis using a few key steps: diff --git a/chapters/03-counterfactuals.qmd b/chapters/03-counterfactuals.qmd index d2f947a..0518b6b 100644 --- a/chapters/03-counterfactuals.qmd +++ b/chapters/03-counterfactuals.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + ## Potential Outcomes {#sec-potential} Let's begin by thinking about the philosophical concept of a *potential outcome.* Prior to some "cause" occurring, for example receiving some exposure, the *potential outcomes* are all of the potential things that could occur depending on what you are exposed to. diff --git a/chapters/04-target-trials-std-methods.qmd b/chapters/04-target-trials-std-methods.qmd index a4fb364..f9ea732 100644 --- a/chapters/04-target-trials-std-methods.qmd +++ b/chapters/04-target-trials-std-methods.qmd @@ -2,6 +2,11 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` ## Randomized trials {#sec-rand-trials} diff --git a/chapters/05-dags.qmd b/chapters/05-dags.qmd index a385321..d6836d1 100644 --- a/chapters/05-dags.qmd +++ b/chapters/05-dags.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("complete") +``` + ## Visualizing Causal Assumptions > Draw your assumptions before your conclusions --@hernan2021 diff --git a/chapters/06-not-just-a-stats-problem.qmd b/chapters/06-not-just-a-stats-problem.qmd index 8f2069f..bf76fed 100644 --- a/chapters/06-not-just-a-stats-problem.qmd +++ b/chapters/06-not-just-a-stats-problem.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("complete") +``` + ## The Causal Quartet We now have the tools to look at something we've alluded to thus far in the book: causal inference is not (just) a statistical problem. diff --git a/chapters/07-prep-data.qmd b/chapters/07-prep-data.qmd index 24b34d5..e31c94b 100644 --- a/chapters/07-prep-data.qmd +++ b/chapters/07-prep-data.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + ## Introduction to the data {#sec-data} Throughout this book we will be using data obtained from [Touring Plans](https://touringplans.com). diff --git a/chapters/08-building-ps-models.qmd b/chapters/08-building-ps-models.qmd index 6e3d940..d8f9bd2 100644 --- a/chapters/08-building-ps-models.qmd +++ b/chapters/08-building-ps-models.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + Often we are interested in how some *exposure* (or treatment) impacts an outcome. For example, we could assess how an ad campaign (exposure) impacts sales (outcome), whether a particular medication (exposure) improves patient survival (outcome), or whether opening a theme park early to some visitors (exposure) reduces wait times later in the day (outcome). As defined in the @sec-counterfactuals, an exposure in the context of this book is often a modifiable event or condition that occurs before the outcome. diff --git a/chapters/09-using-ps.qmd b/chapters/09-using-ps.qmd index 3d8754d..d3c3bf1 100644 --- a/chapters/09-using-ps.qmd +++ b/chapters/09-using-ps.qmd @@ -2,6 +2,13 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + + The propensity score is a *balancing* tool -- we use it to help us make our exposure groups *exchangeable*. There are many ways to incorporate the propensity score into an analysis. Commonly used techniques include stratification (estimating the causal effect within propensity score stratum), matching, weighting, and direct covariate adjustment. In this section, we will focus on *matching* and *weighting*; other techniques will be discussed once we introduce the *outcome model*. Recall at this point in the book we are still in the *design* phase. We have not yet incorporated the outcome into our analysis at all. ## Matching diff --git a/chapters/10-evaluating-ps.qmd b/chapters/10-evaluating-ps.qmd index d26001e..561b11b 100644 --- a/chapters/10-evaluating-ps.qmd +++ b/chapters/10-evaluating-ps.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + Propensity scores are inherently *balancing* scores. The goal is to *balance* the exposure groups across confounders. ## Calculating the standardized mean difference diff --git a/chapters/11-estimands.qmd b/chapters/11-estimands.qmd index 8758675..d464be0 100644 --- a/chapters/11-estimands.qmd +++ b/chapters/11-estimands.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + ## Estimands, Estimators, Estimates When analyzing to make causal inferences, we need to keep the causal question that we're interested in close to our chest. diff --git a/chapters/12-outcome-model.qmd b/chapters/12-outcome-model.qmd index 1b2dc8e..07804df 100644 --- a/chapters/12-outcome-model.qmd +++ b/chapters/12-outcome-model.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("polishing") +``` + ## Using matched data sets When fitting an outcome model on matched data sets, we can simply subset the original data to only those who were matched and then fit a model on these data as we would otherwise. For example, re-performing the matching as we did in @sec-using-ps, we can extract the matched observations in a dataset called `matched_data` as follows. diff --git a/chapters/13-continuous-exposures.qmd b/chapters/13-continuous-exposures.qmd index 05a9661..1a88ee2 100644 --- a/chapters/13-continuous-exposures.qmd +++ b/chapters/13-continuous-exposures.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("wip") +``` + ## Calculating propensity scores for continuous exposures Propensity scores generalize to many other types of exposures, including continuous exposures. diff --git a/chapters/14-categorical-exposures.qmd b/chapters/14-categorical-exposures.qmd index 3c0cfcd..a5ba685 100644 --- a/chapters/14-categorical-exposures.qmd +++ b/chapters/14-categorical-exposures.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Calculating propensity scores for categorical exposures ```{r} diff --git a/chapters/15-g-comp.qmd b/chapters/15-g-comp.qmd index 103c365..fc4a389 100644 --- a/chapters/15-g-comp.qmd +++ b/chapters/15-g-comp.qmd @@ -2,6 +2,13 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("wip") +``` + + ## The Parametric G-Formula Let's pause to recap a typical goal of the causal analyses we've seen in this book so far: to estimate what would happen if *everyone* in the study were exposed versus what would happen if *no one* was exposed. diff --git a/chapters/16-interaction.qmd b/chapters/16-interaction.qmd index 540b1fa..18300c7 100644 --- a/chapters/16-interaction.qmd +++ b/chapters/16-interaction.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Functional form, hetereogenous effects, and joint causes ## Fitting interaction terms in causal models diff --git a/chapters/17-missingness-and-measurement.qmd b/chapters/17-missingness-and-measurement.qmd index a3c0ac0..1be0b60 100644 --- a/chapters/17-missingness-and-measurement.qmd +++ b/chapters/17-missingness-and-measurement.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("wip") +``` + Missing and mismeasured data are problems for most real datasets that impact all three types of analysis: description, prediction, and causal inference. As with analysis, the impact of missingness and mismeasurement is also different across all three, even when we use the same tools (like multiple imputation) to address it. At their best, missingness and mismeasurement can worsen the precision and bias of the sample; at their worst, they can create unresolvable selection bias, giving you a completely wrong answer. diff --git a/chapters/18-longitudinal.qmd b/chapters/18-longitudinal.qmd index 124190b..0269669 100644 --- a/chapters/18-longitudinal.qmd +++ b/chapters/18-longitudinal.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Loss to follow-up ```{r} diff --git a/chapters/19-survival.qmd b/chapters/19-survival.qmd index 0ce9ebe..fe75956 100644 --- a/chapters/19-survival.qmd +++ b/chapters/19-survival.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Preparing data for survival analysis ```{r} diff --git a/chapters/20-mediation.qmd b/chapters/20-mediation.qmd index e8e9533..62b51bd 100644 --- a/chapters/20-mediation.qmd +++ b/chapters/20-mediation.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Estimating direct effects ```{r} diff --git a/chapters/21-sensitivity.qmd b/chapters/21-sensitivity.qmd index bdc302b..af09bfc 100644 --- a/chapters/21-sensitivity.qmd +++ b/chapters/21-sensitivity.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("wip") +``` + ```{r} #| include: false library(ggdag) diff --git a/chapters/22-machine-learning.qmd b/chapters/22-machine-learning.qmd index d3aef42..be1d37d 100644 --- a/chapters/22-machine-learning.qmd +++ b/chapters/22-machine-learning.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Prediction and causal inference, again ## Augmented propensity scores diff --git a/chapters/23-iv-and-friends.qmd b/chapters/23-iv-and-friends.qmd index 13e82b2..d028086 100644 --- a/chapters/23-iv-and-friends.qmd +++ b/chapters/23-iv-and-friends.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + ## Instrumental variable analysis ```{r} diff --git a/chapters/24-evidence.qmd b/chapters/24-evidence.qmd index ec39bac..9d3bca1 100644 --- a/chapters/24-evidence.qmd +++ b/chapters/24-evidence.qmd @@ -2,6 +2,12 @@ {{< include 00-setup.qmd >}} +```{r} +#| echo: false +# TODO: remove when first edition complete +status("unstarted") +``` + > "Circumstantial evidence is a very tricky thing. It may seem to point very straight to one thing, but if you shift your own point of view a little, you may find it pointing in an equally uncompromising manner to something entirely different” > --- Sherlock Holmes