Skip to content

Commit

Permalink
Merge pull request #258 from r-causal/status_banners
Browse files Browse the repository at this point in the history
add status banners to chapters
  • Loading branch information
malcolmbarrett authored Aug 28, 2024
2 parents c5db868 + 765d7d0 commit f005559
Show file tree
Hide file tree
Showing 25 changed files with 171 additions and 0 deletions.
26 changes: 26 additions & 0 deletions R/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
}
6 changes: 6 additions & 0 deletions chapters/01-casual-to-causal.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/02-whole-game.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 6 additions & 0 deletions chapters/03-counterfactuals.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions chapters/04-target-trials-std-methods.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{{< include 00-setup.qmd >}}

```{r}
#| echo: false
# TODO: remove when first edition complete
status("polishing")
```

## Randomized trials {#sec-rand-trials}

Expand Down
6 changes: 6 additions & 0 deletions chapters/05-dags.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions chapters/06-not-just-a-stats-problem.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/07-prep-data.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
6 changes: 6 additions & 0 deletions chapters/08-building-ps-models.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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, <!--TODO make sure that this is correct --> an exposure in the context of this book is often a modifiable event or condition that occurs before the outcome.
Expand Down
7 changes: 7 additions & 0 deletions chapters/09-using-ps.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions chapters/10-evaluating-ps.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions chapters/11-estimands.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/12-outcome-model.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/13-continuous-exposures.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/14-categorical-exposures.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
7 changes: 7 additions & 0 deletions chapters/15-g-comp.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/16-interaction.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions chapters/17-missingness-and-measurement.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions chapters/18-longitudinal.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

{{< include 00-setup.qmd >}}

```{r}
#| echo: false
# TODO: remove when first edition complete
status("unstarted")
```

## Loss to follow-up

```{r}
Expand Down
6 changes: 6 additions & 0 deletions chapters/19-survival.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions chapters/20-mediation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

{{< include 00-setup.qmd >}}

```{r}
#| echo: false
# TODO: remove when first edition complete
status("unstarted")
```

## Estimating direct effects

```{r}
Expand Down
6 changes: 6 additions & 0 deletions chapters/21-sensitivity.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

{{< include 00-setup.qmd >}}

```{r}
#| echo: false
# TODO: remove when first edition complete
status("wip")
```

```{r}
#| include: false
library(ggdag)
Expand Down
6 changes: 6 additions & 0 deletions chapters/22-machine-learning.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions chapters/23-iv-and-friends.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

{{< include 00-setup.qmd >}}

```{r}
#| echo: false
# TODO: remove when first edition complete
status("unstarted")
```

## Instrumental variable analysis

```{r}
Expand Down
6 changes: 6 additions & 0 deletions chapters/24-evidence.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f005559

Please sign in to comment.