Concept Map: Definitions and Results

Configuring R

Functions from these packages will be used throughout this document:

[R code]
library(conflicted) # check for conflicting function definitions
# library(printr) # inserts help-file output into markdown output
library(rmarkdown) # Convert R Markdown documents into a variety of formats.
library(pander) # format tables for markdown
library(ggplot2) # graphics
library(ggfortify) # help with graphics
library(dplyr) # manipulate data
library(tibble) # `tibble`s extend `data.frame`s
library(magrittr) # `%>%` and other additional piping tools
library(haven) # import Stata files
library(knitr) # format R output for markdown
library(tidyr) # Tools to help to create tidy data
library(plotly) # interactive graphics
library(dobson) # datasets from Dobson and Barnett 2018
library(parameters) # format model output tables for markdown
library(haven) # import Stata files
library(latex2exp) # use LaTeX in R code (for figures and tables)
library(fs) # filesystem path manipulations
library(survival) # survival analysis
library(survminer) # survival analysis graphics
library(KMsurv) # datasets from Klein and Moeschberger
library(parameters) # format model output tables for
library(webshot2) # convert interactive content to static for pdf
library(forcats) # functions for categorical variables ("factors")
library(stringr) # functions for dealing with strings
library(lubridate) # functions for dealing with dates and times
library(broom) # Summarizes key information about statistical objects in tidy tibbles
library(broom.helpers) # Provides suite of functions to work with regression model 'broom::tidy()' tibbles

Here are some R settings I use in this document:

[R code]
rm(list = ls()) # delete any data that's already loaded into R

conflicts_prefer(dplyr::filter)
ggplot2::theme_set(
  ggplot2::theme_bw() + 
        # ggplot2::labs(col = "") +
    ggplot2::theme(
      legend.position = "bottom",
      text = ggplot2::element_text(size = 12, family = "serif")))

knitr::opts_chunk$set(message = FALSE)
options('digits' = 6)

panderOptions("big.mark", ",")
pander::panderOptions("table.emphasize.rownames", FALSE)
pander::panderOptions("table.split.table", Inf)
conflicts_prefer(dplyr::filter) # use the `filter()` function from dplyr() by default
legend_text_size = 9
run_graphs = TRUE

This appendix shows how the definitions and results (def, thm, lem, cor, prp callouts) in the notes depend on one another.

We say result \(B\) is a descendant of result \(A\) if \(A\) is referenced inside the statement or proof of \(B\) (directly, or transitively through a chain of intermediate results). The more descendants a result has, the more of the rest of the notes rests on it — so descendant count is a rough measure of how foundational a result is.

The dependency graph is built by data-raw/callout-graph.R, which scans the source .qmd files and saves the result to inst/extdata/callout-graph.rds. This appendix reads that saved file rather than re-scanning the notes on every render, so re-run that script whenever divs are added, removed, or re-titled to refresh the diagram and table below.

[R code]
library(igraph)
library(ggraph)
library(ggrepel)

cg <- readRDS(here::here("inst/extdata/callout-graph.rds"))

type_levels <- c("def", "thm", "lem", "cor", "prp")
type_labels <- c(
  def = "Definition", thm = "Theorem", lem = "Lemma",
  cor = "Corollary", prp = "Proposition"
)
type_palette <- c(
  def = "#1b9e77", thm = "#d95f02", lem = "#7570b3",
  cor = "#e7298a", prp = "#66a61e"
)

There are 472 labeled definitions and results in the notes, connected by 143 direct dependency links.

1 Dependency diagram

Figure 1 shows the results that participate in at least one dependency link, laid out so that connected results sit near each other. Color encodes the type of result. Results with no detected dependency links are omitted from the diagram. Node labels are larger for results with more total descendants, so the most foundational results are visually prominent. The most foundational results (most descendants) appear near the center; peripheral results have no or few descendants. Long names are abbreviated in the diagram; the table below gives each result’s full name. Labels are shifted to avoid overlap; a grey line connects a shifted label to its node position. Zoom in with Ctrl+scroll (or pinch on mobile) to read individual labels.

[R code]
connected <- cg$nodes$id[cg$nodes$id %in% c(cg$edges$from, cg$edges$to)]
core <- graph_from_data_frame(
  cg$edges,
  vertices = cg$nodes[cg$nodes$id %in% connected, ],
  directed = TRUE
)
V(core)$type <- factor(V(core)$type, levels = type_levels)

set.seed(204)
# Use Fruchterman-Reingold for angular arrangement (connected nodes cluster
# together), then override each node's radius so the most foundational nodes
# land near the center.
fr_layout <- create_layout(core, layout = "fr", niter = 2000)
n_desc_vals <- V(core)$n_desc
fr_angle <- atan2(fr_layout$y, fr_layout$x)
# log1p radius: nodes with more descendants land closer to center (r = 0);
# nodes with 0 descendants land at the periphery (r = 1). The log scale
# compresses the high end so the few top hubs don't crowd the center, and
# pulls nodes with even a handful of descendants well off the outer rim.
max_desc <- max(n_desc_vals)
target_r <- 1 - log1p(n_desc_vals) / log1p(max_desc)
layout <- fr_layout
layout$x <- target_r * cos(fr_angle)
layout$y <- target_r * sin(fr_angle)

# Abbreviate long node labels for the diagram only (the descendants table below
# keeps the full titles). First drop synonym lists -- the text after the first
# comma -- so e.g. "Expectation, expected value, population mean" becomes
# "Expectation". Then apply curated short forms for the few names that are
# still long; extend this map as needed.
layout$label <- sub(",.*$", "", layout$title)
short_forms <- c("def-hazard" = "Hazard")
hit <- match(layout$name, names(short_forms))
layout$label <- ifelse(is.na(hit), layout$label, short_forms[hit])
layout$label <- stringr::str_wrap(layout$label, width = 15)

ggraph(layout) +
  geom_edge_link(
    arrow = arrow(length = unit(1.8, "mm"), type = "closed"),
    end_cap = circle(2, "mm"),
    edge_alpha = 0.25, edge_width = 0.3
  ) +
  geom_label_repel(
    data = as.data.frame(layout),
    aes(x = x, y = y, label = label, fill = type, size = n_desc),
    inherit.aes = FALSE,
    # point.size = NA: suppress the dot so the label itself is the node;
    # ggrepel still repels labels away from each other to avoid overlap.
    point.size = NA,
    color = "white",
    fontface = "bold",
    max.overlaps = Inf,
    force = 3,
    force_pull = 1,
    box.padding = unit(0.15, "lines"),
    label.padding = unit(0.1, "lines"),
    label.r = unit(0.05, "lines"),
    label.size = 0.1,
    alpha = 0.88,
    segment.color = "grey60",
    segment.alpha = 0.5,
    segment.size = 0.3,
    min.segment.length = unit(0.5, "lines"),
    seed = 204
  ) +
  scale_fill_manual(
    values = type_palette, labels = type_labels, name = "Type", drop = FALSE
  ) +
  scale_size_continuous(range = c(8.0, 16.0), guide = "none") +
  theme_void() +
  theme(legend.position = "bottom")
Figure 1: Dependency structure of the definitions and results in the notes. An arrow points from a result to each result that uses it. Color indicates result type (see legend). Label font size is proportional to the number of total descendants; results with more descendants appear closer to the center.

2 Descendants of each result

Table 1 lists every result that has at least one descendant, sorted by the number of total descendants (direct or transitive).

[R code]
ranked <- cg$nodes[cg$nodes$n_desc >= 1, ]
ranked <- ranked[order(-ranked$n_desc, ranked$id), ]

descendant_table <- data.frame(
  Result               = ranked$title,
  Type                 = type_labels[ranked$type],
  `Direct descendants`  = ranked$n_direct,
  `Total descendants`   = ranked$n_desc,
  check.names = FALSE, row.names = NULL, stringsAsFactors = FALSE
)

knitr::kable(descendant_table, format = "pipe", align = "llrr")
Table 1: All results with at least one descendant, sorted by number of total descendants (most-foundational first).
Result Type Direct descendants Total descendants
Probability measure Definition 7 39
Odds Definition 4 20
Odds as a function of probability Theorem 5 19
log-odds Definition 4 17
Expectation, expected value, population mean Definition 5 8
Odds from log-odds Lemma 2 7
Probability as a function of odds Theorem 4 7
Conditional probability Definition 4 6
Derivative of odds function Theorem 3 6
Risk-set score total Definition 2 5
Derivative of log-odds by odds Lemma 1 5
One plus odds in terms of non-event probability Corollary 1 4
Hazard function, hazard rate, hazard rate function Definition 3 4
Interval failure probability Definition 3 4
logit function Definition 2 4
Variance Definition 3 4
Derivative of odds w.r.t. log-odds Lemma 2 4
Derivative of log-odds by odds Theorem 1 4
Proportional-hazards decomposition of the hazard Theorem 1 4
Derivative of odds function in terms of odds Corollary 1 3
Cumulative distribution function (CDF) Definition 2 3
Statistical independence Definition 3 3
Proportional-hazards first-order interval failure probability Definition 1 3
Cox proportional hazards model Definition 1 3
Vector derivative Definition 1 3
Point-mass optimality of the profile baseline hazard Lemma 1 3
Derivative of log-odds by probability Theorem 2 3
Law of conditional probability Theorem 2 3
An event and its complement sum to 1 Theorem 1 3
Complement rule Corollary 2 2
Covariance Definition 2 2
Cox-Snell generalized residuals Definition 2 2
Dot product/linear combination/inner product Definition 2 2
Riemann integrable Definition 2 2
Cox PH partial likelihood Definition 2 2
Risk Score Definition 1 2
Derivative of log-odds with respect to coefficients Lemma 2 2
Simplified expression for inverse odds function Lemma 1 2
One minus inverse-odds Lemma 2 2
Profile likelihood in terms of point masses Lemma 2 2
Single-subject failure probability in a risk set Lemma 2 2
Derivative of odds in terms of probability Theorem 1 2
Derivative of inverse odds function Theorem 1 2
Derivative of a linear map Theorem 1 2
Expanded expression for logit Theorem 1 2
Log-odds as a function of probability Theorem 1 2
Log-odds via the logit function Corollary 1 1
Odds via the odds function Corollary 1 1
Akaike Information Criterion (AIC) Definition 1 1
Antiderivative Definition 1 1
Conditional expectation Definition 1 1
conditional hazard Definition 1 1
Continuous function Definition 1 1
Variance/covariance of a \(p \times 1\) random vector Definition 1 1
Deviation from a population or subpopulation mean Definition 1 1
Deviation of an observation from its subpopulation mean Definition 1 1
Difference in covariate patterns Definition 1 1
Difference in log-odds Definition 1 1
Estimated Risk Score Definition 1 1
Expectation of a random matrix Definition 1 1
First-order interval failure probability Definition 1 1
Hat matrix Definition 1 1
Per-interval likelihood factor Definition 1 1
inverse odds function Definition 1 1
Martingale Residual Definition 1 1
Predicted value Definition 1 1
Quadratic form Definition 1 1
Risk Set Definition 1 1
Survival function Definition 1 1
Censored-data likelihood Lemma 1 1
The covariance of a variable with itself is its variance Lemma 1 1
Difference in log-odds Lemma 1 1
Difference of log-hazards between two covariate patterns Lemma 1 1
General formula for odds ratios in logistic regression Lemma 1 1
Profile maximum likelihood estimate of each point mass Lemma 1 1
The whether-a-failure-occurs factor Lemma 1 1
Exact discretization of the survival factor Lemma 1 1
Chain rule Theorem 1 1
Derivative of probability w.r.t. log-odds Theorem 1 1
Derivative of a dot product Theorem 1 1
Derivative of natural logarithm Theorem 1 1
Vector-derivative of a matrix-vector product Theorem 1 1
Expressions for expit function Theorem 1 1
Fubini’s theorem (Riemann version) Theorem 1 1
Mean Squared Error equals Bias Squared plus Variance Theorem 1 1
Odds ratios are reversible Theorem 1 1
Probability as a function of log-odds Theorem 1 1
Mean and variance of residuals Theorem 1 1
Law of total probability Theorem 1 1
Variance of a linear combination Theorem 1 1