# Unequal groups and the variance of a pooled endpoint mean

This is a synthetic, deterministic covariance calculation. It is not a measured
storage failure rate, a fitted correlation, a new statistical method or a
replication of a field study.

Run with Python 3.10+ standard library:
```sh
python3 -B model.py --check
python3 -B -m unittest -v test_model.py
```

## Target and assumptions
Every device contributes one complete failed/not-failed outcome at the same fixed
horizon, with common marginal probability p strictly between zero and one.
The estimator is the equally weighted mean of N devices, not an equally weighted
mean of groups and not failures per drive-year. Fixed groups are independent.
Within each group every distinct pair has the same specified correlation rho.
The examples use rho=0 or 0.01, not an estimate from hardware data.

A binary construction exists for 0<=rho<=1: independently for each group, with
probability rho give all members one common Bernoulli(p) draw, and otherwise give
members independent Bernoulli(p) draws. This establishes feasibility, not a
physical failure mechanism or a distribution used to calculate confidence limits.

## Derivation
With marginal variance v=p(1-p), each diagonal covariance is v. Each ordered
distinct within-group pair contributes rho*v. There are sum_g m_g(m_g-1)
such pairs; cross-group covariance is zero. Therefore

Var(mean) = v * [N + rho * sum_g m_g(m_g-1)] / N^2.

Dividing by the independent-reference variance v/N gives
D = 1 + rho * [sum_g m_g^2/N - 1].
The standard-error ratio is sqrt(D); the variance-equivalent count is N/D.
All rational quantities are exact in results.json; square roots and displayed
decimal quantities are rounded representations.

Holding N and group count fixed, the unequal-size penalty is
rho * population_variance(group_size) / mean(group_size).
Changing the estimator weights changes this expression. N/D is not an integer
trial count, a cluster count or a degree of freedom. Equal variance alone does not
specify tail probabilities, so substituting N/D into a binomial confidence limit
is not justified. No interval or coverage claim is calculated.

## Evidence
- Cameron and Miller (2015), A Practitioner's Guide to Cluster-Robust Inference,
  DOI 10.3368/jhr.50.2.317; sections II.A-B (covariances and equation 6), IV
  (clustering level), VI (few-cluster inference).
  https://www.econ.ucdavis.edu/faculty/cameron/research/Cameron_Miller_JHR_2015_February.pdf
- Survey Methodology (2020), Considering interviewer and design effects when
  planning sample sizes, section 1: estimator/reference-specific definition.
  https://www150.statcan.gc.ca/n1/pub/12-001-x/2020001/article/00005/01-eng.htm
- Schroeder and Gibson, FAST 2007, Disk failures in the real world: What does an
  MTTF of 1,000,000 hours mean to you?, sections 2.1 and 5.2. Historical replacement
  count autocorrelation motivates checking dependence; it is not a within-rack
  endpoint correlation and does not supply rho=0.01.
  https://static.usenix.org/events/fast07/tech/schroeder/schroeder_html/index.html

Sources accessed 2026-11-19. Only original calculations and implementation are
distributed here, not copies of third-party papers. Tests independently sum all
pair covariances for 336 small configurations, check the published rows,
limits, permutation invariance and invalid inputs. No network or device access.
