Package 'causalpie'

Title: Causal Pies for Sufficient Causes
Description: Causal pies are a way of visualizing the sufficient causes framework. Sufficient causes are what must occur before some event happens. The components of what causes the event may be in any or all sufficient causes, and those that are in all are called necessary causes. The sufficient cause framework was developed by Kenneth 'Rothman' as a way of thinking about causes of disease in epidemiology ('Rothman' (1976) <doi:10.1093/oxfordjournals.aje.a112335>).
Authors: Malcolm Barrett [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-0299-5825>)
Maintainer: Malcolm Barrett <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-10-04 18:08:38 UTC
Source: https://github.com/r-causal/causalpie

Help Index


Create sufficient causes

Description

Create sufficient causes

Usage

sc(...)

causify(..., add_u = TRUE)

Arguments

...

components of the cause

add_u

logical. Should component "U" be added to the sufficient cause? Default is TRUE.

Value

sc(): a named vector; causify(): a tibble with sufficient causes.

Examples

causify(sc(A = 1, B = 0), sc(A = 1, E = 1, C = 0))

causify(sc(F = 1, Q = 0), sc(A = 1), add_u = FALSE)

Identify components of a set of sufficient causes

Description

components() identifies the unique components across all sufficient causes. necessary_causes() identifies the components that appear in all sufficient causes. sufficient_causes() identifies all the components of a sufficient cause.

Usage

components(causes)

necessary_causes(causes)

sufficient_causes(causes)

Arguments

causes

a data frame, the result of causify()

Value

a character vector

Examples

causes <- causify(sc(A = 1, B = 0), sc(A = 1, E = 1, C = 0))

components(causes)
necessary_causes(causes)
sufficient_causes(causes)

Causal Pies

Description

Causal pies are visual representations of sufficient causes. causal_pie() plots all sufficient causes and highlights the unique components. causal_pie_necessary() does the same but highlights necessary causes (those components that appear in every sufficient cause).

Usage

causal_pie(causes, text_col = "black")

causal_pie_necessary(causes, text_col = "black")

Arguments

causes

a data frame, the result of causify()

text_col

color of the text. Default is "black".

Value

a ggplot

Examples

causes <- causify(sc(A = 1, B = 0), sc(A = 1, E = 1, C = 0))

causes |>
  causal_pie() +
  theme_causal_pie()

causes |>
  causal_pie_necessary() +
  theme_causal_pie_grid()

Minimalist themes for causal pies

Description

Minimalist themes for causal pies

Usage

theme_causal_pie(base_size = 12, base_family = "", ...)

theme_causal_pie_grid(base_size = 12, base_family = "", ...)

Arguments

base_size

base font size, given in pts.

base_family

base font family

...

additional arguments passed to theme()

Value

A ggplot2::theme object

Examples

causify(sc(A = 1, B = 0), sc(A = 1, E = 1, C = 0)) |>
  causal_pie_necessary() +
  theme_causal_pie()