# leoegidi/footbayes architecture

> Architecture diagram of the GitHub repository leoegidi/footbayes, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leoegidi/footbayes
- Repository: https://github.com/leoegidi/footbayes

## Overview

footBayes is an R package for fitting football score and team-strength models, then examining model results and predictions. The documented example runs from match data through a Bayesian fit to ability plots, posterior predictive checks, league rankings, and outcome probabilities. The README also describes MLE, model comparison, and Bradley–Terry–Davidson strengths as a covariate. Source excerpts were not provided, so relationships below are limited to documented capabilities and workflow; individual Stan model variants are represented together.

Main entry points: [`R/stan_foot.R`](https://github.com/leoegidi/footbayes/blob/master/R/stan_foot.R) (Bayesian fit), [`R/btd_foot.R`](https://github.com/leoegidi/footbayes/blob/master/R/btd_foot.R) (Bradley–Terry–Davidson), [`data/italy.rda`](https://github.com/leoegidi/footbayes/blob/master/data/italy.rda) (Italy dataset), [`data/england.rda`](https://github.com/leoegidi/footbayes/blob/master/data/england.rda) (England dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_fit["Model fitting"]
  node_stan_fit["Bayesian fit<br/>[stan_foot.R]"]
  node_mle_fit["MLE fit<br/>[mle_foot.R]"]
  node_stan_models["Stan models"]
end

subgraph group_strength["Team strengths"]
  node_btd["Bradley–Terry–Davidson<br/>[btd_foot.R]"]
end

subgraph group_analysis["Results and diagnostics"]
  node_abilities["Team abilities<br/>[foot_abilities.R]"]
  node_posterior_checks["Posterior checks<br/>[pp_foot.R]"]
  node_ability_plot["Ability plots<br/>[plot_logStrength.R]"]
  node_btd_plot["BTD posterior plot"]
end

subgraph group_predict["Prediction"]
  node_league_rank["League ranking<br/>[foot_rank.R]"]
  node_match_probs["Outcome probabilities<br/>[foot_prob.R]"]
  node_comparison["Model comparison<br/>[compare_foot.R]"]
  node_round_robin["Round-robin outcomes<br/>[foot_round_robin.R]"]
end

node_analyst(("Analyst"))
node_match_data["Match data"]
node_italy_data["Italy dataset<br/>[italy.rda]"]
node_england_data["England dataset<br/>[england.rda]"]

node_analyst -->|"fits model"| node_stan_fit
node_match_data -->|"provides matches"| node_stan_fit
node_stan_fit -->|"fits with"| node_stan_models
node_analyst -->|"fits by MLE"| node_mle_fit
node_analyst -->|"estimates strengths"| node_btd
node_btd -->|"supplies covariate"| node_stan_fit
node_stan_fit -->|"examines effects"| node_abilities
node_stan_fit -->|"checks fit"| node_posterior_checks
node_stan_fit -->|"visualizes strengths"| node_ability_plot
node_btd -.->|"visualizes posterior"| node_btd_plot
node_stan_fit -->|"reconstructs league"| node_league_rank
node_stan_fit -->|"predicts outcomes"| node_match_probs
node_analyst -->|"compares models"| node_comparison
node_analyst -.->|"analyzes outcomes"| node_round_robin
node_italy_data -->|"example input"| node_stan_fit
node_england_data -.-> node_stan_fit

click node_stan_fit "https://github.com/leoegidi/footbayes/blob/master/R/stan_foot.R"
click node_mle_fit "https://github.com/leoegidi/footbayes/blob/master/R/mle_foot.R"
click node_stan_models "https://github.com/leoegidi/footbayes/tree/master/src/stan"
click node_btd "https://github.com/leoegidi/footbayes/blob/master/R/btd_foot.R"
click node_abilities "https://github.com/leoegidi/footbayes/blob/master/R/foot_abilities.R"
click node_posterior_checks "https://github.com/leoegidi/footbayes/blob/master/R/pp_foot.R"
click node_ability_plot "https://github.com/leoegidi/footbayes/blob/master/R/plot_logStrength.R"
click node_btd_plot "https://github.com/leoegidi/footbayes/blob/master/R/plot_btdPosterior.R"
click node_league_rank "https://github.com/leoegidi/footbayes/blob/master/R/foot_rank.R"
click node_match_probs "https://github.com/leoegidi/footbayes/blob/master/R/foot_prob.R"
click node_comparison "https://github.com/leoegidi/footbayes/blob/master/R/compare_foot.R"
click node_round_robin "https://github.com/leoegidi/footbayes/blob/master/R/foot_round_robin.R"
click node_italy_data "https://github.com/leoegidi/footbayes/blob/master/data/italy.rda"
click node_england_data "https://github.com/leoegidi/footbayes/blob/master/data/england.rda"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_stan_fit,node_mle_fit,node_stan_models toneBlue
class node_btd toneAmber
class node_abilities,node_posterior_checks,node_ability_plot,node_btd_plot toneMint
class node_league_rank,node_match_probs,node_comparison,node_round_robin toneRose
class node_analyst,node_match_data toneIndigo
class node_italy_data,node_england_data toneTeal
```

## Components

### Model fitting

- [Bayesian fit](https://github.com/leoegidi/footbayes/blob/master/R/stan_foot.R): `R/stan_foot.R`
- [MLE fit](https://github.com/leoegidi/footbayes/blob/master/R/mle_foot.R): `R/mle_foot.R`
- [Stan models](https://github.com/leoegidi/footbayes/tree/master/src/stan): `src/stan`

### Team strengths

- [Bradley–Terry–Davidson](https://github.com/leoegidi/footbayes/blob/master/R/btd_foot.R): `R/btd_foot.R`

### Results and diagnostics

- [Team abilities](https://github.com/leoegidi/footbayes/blob/master/R/foot_abilities.R): `R/foot_abilities.R`
- [Posterior checks](https://github.com/leoegidi/footbayes/blob/master/R/pp_foot.R): `R/pp_foot.R`
- [Ability plots](https://github.com/leoegidi/footbayes/blob/master/R/plot_logStrength.R): `R/plot_logStrength.R`
- [BTD posterior plot](https://github.com/leoegidi/footbayes/blob/master/R/plot_btdPosterior.R): `R/plot_btdPosterior.R`

### Prediction

- [League ranking](https://github.com/leoegidi/footbayes/blob/master/R/foot_rank.R): `R/foot_rank.R`
- [Outcome probabilities](https://github.com/leoegidi/footbayes/blob/master/R/foot_prob.R): `R/foot_prob.R`
- [Model comparison](https://github.com/leoegidi/footbayes/blob/master/R/compare_foot.R): `R/compare_foot.R`
- [Round-robin outcomes](https://github.com/leoegidi/footbayes/blob/master/R/foot_round_robin.R): `R/foot_round_robin.R`

### Other components

- **Analyst**
- **Match data**
- [Italy dataset](https://github.com/leoegidi/footbayes/blob/master/data/italy.rda): `data/italy.rda`
- [England dataset](https://github.com/leoegidi/footbayes/blob/master/data/england.rda): `data/england.rda`

## Connections

- Analyst → Bayesian fit: fits model (evidence: `README.md`)
- Match data → Bayesian fit: provides matches (evidence: `README.md`)
- Bayesian fit → Stan models: fits with (evidence: `README.md`)
- Analyst → MLE fit: fits by MLE (evidence: `README.md`)
- Analyst → Bradley–Terry–Davidson: estimates strengths (evidence: `README.md`)
- Bradley–Terry–Davidson → Bayesian fit: supplies covariate (evidence: `README.md`)
- Bayesian fit → Team abilities: examines effects (evidence: `README.md`)
- Bayesian fit → Posterior checks: checks fit (evidence: `README.md`)
- Bayesian fit → Ability plots: visualizes strengths (evidence: `README.md`)
- Bradley–Terry–Davidson → BTD posterior plot: visualizes posterior
- Bayesian fit → League ranking: reconstructs league (evidence: `README.md`)
- Bayesian fit → Outcome probabilities: predicts outcomes (evidence: `README.md`)
- Analyst → Model comparison: compares models (evidence: `README.md`)
- Analyst → Round-robin outcomes: analyzes outcomes
- Italy dataset → Bayesian fit: example input (evidence: `README.md`)
- England dataset → Bayesian fit
