Is the failure rate constant?
An exponential lifetime has no memory. See what that means for maintenance, then test it with the Gini statistic and the TTT plot.
What runs in CodeSplash
- STAT145Gini exponentiality test Runs in CodeSplash
- Exponentiality tests (battery) Verified in Python and R
You will be able to
- Explain the memoryless property and when it matters
- Read a scaled TTT plot as rising, constant or falling hazard
- Read the Gini statistic against its exponential value of one half
Read first
A part with no memory
PredictPredict first
A part's lifetime follows an exponential distributionExponential distributionThe wait until an event when the risk per unit of time is constant; it has no memory., with a mean of 1,000 hours. One part has already run for 1,000 hours without failing.
Compared with a brand-new part, how likely is it to last another 1,000 hours?
Reveal
Exactly as likely: . An exponential part doesn't age. Its hazard rateHazard rateThe failure rate among units still working at a given age. Rising means wear-out, falling means early failures, flat means random failures. stays the same at every age.
Why this question matters
ReadIf the rate is constant, replacing a part early buys nothing: the new one is no better than the one you removed. If the rate rises, planned replacement may pay.
The exponential is also the simplest model: one number, the mean life, sets every reliability figure. So people use it a lot, and they should check it.
A test of exponentialityExponentialityLifetimes are exponential when the failure rate is constant, so a working unit is as good as new at any age. asks whether lifetimes are compatible with this model. Lifetimes must be complete here, with no units still running.
Shape the hazard
ExploreChange the shape below and watch the hazard and the survival curve together.
FExplorable · From hazard to survival
How does the moment-to-moment risk build up into a survival curve?
What share of group A is still event-free at this time?
Below 1 risk falls with time; above 1 it rises.
Hazard: risk at each moment
Survival: still event-free
Commit your prediction above to see the result
Make your prediction to see the result.
A rising hazard means wear-out. A falling hazard means early failures, or a mix of strong and weak units.
The TTT plot
ReadSort the lifetimes. For each failure, add up the total time every unit spent on test so far, and divide by the grand total. Plot that against the share of units failed.
That is the scaled TTT plotTotal-time-on-test plotScaled accumulated running time against the share failed. On the diagonal the hazard is constant; bowed up it rises, bowed down it falls.:
- On the diagonal: constant rate.
- Above it: rising rate, wear-out.
- Below it: falling rate.
The Gini statistic summarizes the same curve: it's one minus the curve's average height, and it equals one half on the diagonal.
Read G
PredictPredict first
A sample of 40 lifetimes comes from a part that wears out, so failures bunch around a typical life. Where does land?
Reveal
Below: = 0.239. Lifetimes that bunch together are more equal, so is small. That sample's verdict: the departure looks like a rising failure rate (wear-out).
Three real samples
Read- Ball bearings: = 0.29, far below one half. Their fatigue life shows wear-out.
- Air-conditioner failures: = 0.56, slightly above. Its verdict: the lifetimes are compatible with a constant failure rate.
- Simulated exponential lifetimes: = 0.54, p = .457.
Gini = 0.54, p = .457
- Mean life
- 0.8592
- Failure rate
- 1.164
- Tests rejecting
- 0
- p, adjusted for the battery
- .457
- Tests run
- 1
Plots
View data
| x |
|---|
| 0.1987 |
| 0.0565 |
| 0.7537 |
| 0.4180 |
| 0.0554 |
| 2.037 |
| 0.4341 |
| 0.0808 |
| 2.685 |
| 0.1919 |
| 0.7465 |
| 0.5602 |
| 0.0452 |
| 3.232 |
| 0.4822 |
| 1.786 |
| 0.5297 |
| 0.5335 |
| 0.7144 |
| 0.9352 |
| 0.6679 |
| 0.7535 |
| 2.622 |
| 0.1017 |
View data
| Series | Fitted F(t) | x |
|---|---|---|
| data | — | 0.1987 |
| data | — | 0.0565 |
| data | — | 0.7537 |
| data | — | 0.4180 |
| data | — | 0.0554 |
| data | — | 2.037 |
| data | — | 0.4341 |
| data | — | 0.0808 |
| data | — | 2.685 |
| data | — | 0.1919 |
| data | — | 0.7465 |
| data | — | 0.5602 |
| data | — | 0.0452 |
| data | — | 3.232 |
| data | — | 0.4822 |
| data | — | 1.786 |
| data | — | 0.5297 |
| data | — | 0.5335 |
| data | — | 0.7144 |
| data | — | 0.9352 |
| data | — | 0.6679 |
| data | — | 0.7535 |
| data | — | 2.622 |
| data | — | 0.1017 |
| exponential | 0.0513 | 0.0452 |
| exponential | 0.1091 | 0.0992 |
| exponential | 0.1633 | 0.1532 |
| exponential | 0.2143 | 0.2073 |
| exponential | 0.2622 | 0.2613 |
| exponential | 0.3072 | 0.3153 |
| exponential | 0.3494 | 0.3693 |
| exponential | 0.3890 | 0.4233 |
| exponential | 0.4263 | 0.4774 |
| exponential | 0.4612 | 0.5314 |
| exponential | 0.4940 | 0.5854 |
| exponential | 0.5249 | 0.6394 |
| exponential | 0.5538 | 0.6934 |
| exponential | 0.5810 | 0.7475 |
| exponential | 0.6065 | 0.8015 |
| exponential | 0.6305 | 0.8555 |
| exponential | 0.6530 | 0.9095 |
| exponential | 0.6742 | 0.9635 |
| exponential | 0.6940 | 1.018 |
| exponential | 0.7127 | 1.072 |
| exponential | 0.7302 | 1.126 |
| exponential | 0.7466 | 1.180 |
| exponential | 0.7621 | 1.234 |
| exponential | 0.7766 | 1.288 |
| exponential | 0.7902 | 1.342 |
| exponential | 0.8030 | 1.396 |
| exponential | 0.8150 | 1.450 |
| exponential | 0.8262 | 1.504 |
| exponential | 0.8368 | 1.558 |
| exponential | 0.8468 | 1.612 |
| exponential | 0.8561 | 1.666 |
| exponential | 0.8649 | 1.720 |
| exponential | 0.8731 | 1.774 |
| exponential | 0.8808 | 1.828 |
| exponential | 0.8881 | 1.882 |
| exponential | 0.8949 | 1.936 |
First 60 of 84 rows.
View data
| x |
|---|
| 0.1987 |
| 0.0565 |
| 0.7537 |
| 0.4180 |
| 0.0554 |
| 2.037 |
| 0.4341 |
| 0.0808 |
| 2.685 |
| 0.1919 |
| 0.7465 |
| 0.5602 |
| 0.0452 |
| 3.232 |
| 0.4822 |
| 1.786 |
| 0.5297 |
| 0.5335 |
| 0.7144 |
| 0.9352 |
| 0.6679 |
| 0.7535 |
| 2.622 |
| 0.1017 |
Assumptions
- Independent lifetimes — Not testable from these numbers alone; check how the units were sampled.
- Complete lifetimes — All 24 values are treated as failures. For censored units use Distribution ID.
- No tied lifetimes — All lifetimes are distinct.
Exponentiality tests
| Test | Statistic | z | p (reference) | p (simulated) | p used | p adjusted | Rejects at .05 |
|---|---|---|---|---|---|---|---|
| Gini | 0.5447 | 0.7434 | .457 | — | .457 | — | no |
Mean life under the exponential model
| Mean life | 95% CI low | 95% CI high | Failure rate |
|---|---|---|---|
| 0.8592 | 0.5975 | 1.341 | 1.164 |
- Simulated p-values compare each statistic with 999 exponential samples of the same size (seed 42), renormalized as in the data; every test sees the same samples.
- The count of rejections is not a combined test: the tests overlap, so about 3 in 10 exponential samples get at least one. Some tests here use a reference distribution, so the adjusted p is Bonferroni, which is cautious for overlapping tests.
- The total-time-on-test area equals one minus the Gini statistic.
- A Gini statistic below one half and a TTT plot above the diagonal point to a rising failure rate; the reverse points to a falling one.
The exact R script · R R version 4.5.1 (2025-06-13)
# Exponentiality tests (battery)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method life.exponentiality 1.0.2 · spec 0ae686865f94ebe7
# Dataset: life_exp_sim (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # the tests, written from the papers; shared random stream
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/life_exp_sim.parquet", col_select = c("x")))
n_input <- nrow(df)
df <- df[stats::complete.cases(df[c("x")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("x")) # infinite values stop the run (registry/errors.yaml)
# %% Tests
y <- "x"
x <- as.numeric(df[[y]])
x <- x[!is.na(x)]
if (any(x <= 0)) cs_error("CS_E_INVALID_VALUES", column = y, requirement = "positive (lifetimes above zero)", count = sum(x <= 0))
n <- length(x)
cs_check_rows(n, 5, "The exponentiality tests") # the battery needs at least 5 lifetimes
test <- "gini"
alpha <- 0.05
seed <- 42 # exponential samples from the shared Wichmann-Hill stream
reps <- as.integer(999)
a <- 1
b <- 0.44
power <- 0.99
if (b == 1) stop("Deshpande's b must differ from 1")
if (power %in% c(0, 1)) stop("Atkinson's power cannot be 0 or 1")
rows <- cs_exp_battery(x, tests = if (test == "battery") NULL else test, calibration = "reference", reps = reps, seed = seed, a = a, b = b, power = power,
r_gnedenko = NULL,
r_harris = NULL)
tested <- Filter(function(r) is.finite(r$p), rows)
rejecting <- Filter(function(r) r$p < alpha, tested)
# About 1.5 of 30 tests reject by chance, and because they overlap, some rejection turns up in about 3 of every 10
# truly exponential samples. So the verdict rests on the p adjusted for running them all, not on the count.
adjust_method <- rows[[1]]$adjust
battery_p <- if (length(tested)) min(vapply(tested, function(r) r$p_adj, numeric(1))) else NaN
if (n < 300 && any(vapply(rows, function(r) r$calibration == "reference" && r$key %in% c("kochar", "ahsanullah", "rossberg", "deshpande"), logical(1)))) {
warnings <- c(warnings, "Reference distributions reject too often below about 300 lifetimes: Kochar 12%, Ahsanullah 11% and Rossberg 10% at the 5% level with 30 lifetimes. Simulate instead.")
}
# %% Mean life under the exponential model (exact chi-square interval)
conf <- 0.95
mean_x <- mean(x)
mean_low <- 2 * n * mean_x / stats::qchisq(1 - (1 - conf) / 2, 2 * n)
mean_high <- 2 * n * mean_x / stats::qchisq((1 - conf) / 2, 2 * n)
gini <- 2 * sum((2 * seq_len(n) - n - 1) * sort(x)) / (2 * n * (n - 1) * mean_x)
# %% Verdict and values
keys <- vapply(rows, function(r) r$key, character(1))
lead <- if ("cox_oakes" %in% keys) rows[[which(keys == "cox_oakes")]] else rows[[1]]
verdict <- if (length(rows) == 1) {
if (is.finite(lead$p) && lead$p < alpha) "exponentiality rejected at α = .05" else "compatible with an exponential distribution"
} else if (!length(rejecting)) {
"the lifetimes are compatible with a constant failure rate"
} else if (!isTRUE(battery_p < alpha)) {
"that is what chance gives across this many overlapping tests, so the lifetimes are compatible with a constant failure rate"
} else if (!isTRUE(rows[[which(keys == "gini")]]$p < alpha)) {
"the lifetimes depart from an exponential, with no clear rising or falling failure rate"
} else if (gini < 0.5) {
"the departure looks like a rising failure rate (wear-out)"
} else {
"the departure looks like a falling failure rate (early failures)"
}
values <- list(n = n, mean = mean_x, mean_low = mean_low, mean_high = mean_high, rate = 1 / mean_x, min = min(x), max = max(x),
n_tests = length(tested), n_reject = length(rejecting), n_not_computed = length(rows) - length(tested),
battery_p = battery_p, n_reject_adj = sum(vapply(tested, function(r) r$p_adj < alpha, logical(1))), adjust_method = adjust_method,
test_label = if (length(rows) == 1) lead$test else "Battery", verdict = verdict, lead_label = lead$test, lead_stat = lead$statistic, lead_p = lead$p,
gini = gini, reps = reps)
cell <- function(v) if (is.finite(v)) v else NA_real_ # a number the test does not have shows a dash, not NaN
table <- list()
for (r in rows) {
k <- r$key
values[[sprintf("stat[%s]", k)]] <- r$statistic
values[[sprintf("z[%s]", k)]] <- r$z
values[[sprintf("p[%s]", k)]] <- r$p
values[[sprintf("p_ref[%s]", k)]] <- r$p_ref
values[[sprintf("p_adj[%s]", k)]] <- r$p_adj
values[[sprintf("p_mc[%s]", k)]] <- r$p_mc
values[[sprintf("calibration[%s]", k)]] <- r$calibration
table[[length(table) + 1]] <- list(test = r$test, statistic = cell(r$statistic), z = cell(r$z), p_ref = cell(r$p_ref), p_mc = cell(r$p_mc), p = cell(r$p),
reject = if (is.finite(r$p)) (if (r$p < alpha) "yes" else "no") else "not computed")
}
# %% Assumptions
tied <- n - length(unique(x))
assumptions <- list(
list(key = "independence", label = "Independent lifetimes", status = "info", detail = "Not testable from these numbers alone; check how the units were sampled."),
list(key = "complete_data", label = "Complete lifetimes", status = "info", detail = sprintf("All %d values are treated as failures. For censored units use Distribution ID.", n)),
list(key = "ties", label = "No tied lifetimes", status = if (tied) "warn" else "pass",
detail = if (tied) sprintf("%d tied value(s): zero spacings stop the Epstein test and weaken the other spacing tests.", tied) else "All lifetimes are distinct.")
)
# %% Charts
pct <- sprintf("%.0f%%", conf * 100)
fit_t <- seq(min(x), max(x), length.out = 60)
charts <- list(
cs_chart("ttt", "ttt-plot", sprintf("Scaled total-time-on-test plot: %s", y), list(value = cs_col(y, x, "numeric"))),
cs_chart("paper", "probability-plot", sprintf("Exponential probability plot: %s", y), list(
time = cs_col(y, c(x, fit_t), "numeric"),
fit = cs_col("Fitted F(t)", c(rep(NaN, n), -expm1(-fit_t / mean_x)), "numeric"),
family = cs_col("Series", c(rep("data", n), rep("exponential", length(fit_t))), "categorical", levels = c("data", "exponential"))
), controls = list(paper = "exponential")),
cs_chart("lorenz", "lorenz-gini", sprintf("Lorenz curve: %s", y), list(value = cs_col(y, x, "numeric")))
)
# %% Result
cs_publish(list(
method = "life.exponentiality",
methodVersion = "1.0.2",
title = if (length(rows) > 1) "Exponentiality tests" else paste0("Exponentiality: ", lead$test),
engine = cs_engine_info("stats", "codesplashr"),
n = n,
summary = if (length(rows) > 1) sprintf("%d of %d tests reject exponentiality at α = .05; adjusted for running all %d, %s: %s.", length(rejecting), length(tested), length(tested), cs_fmt_p(battery_p), verdict)
else sprintf("%s: %s; %s.", lead$test, cs_fmt_p(lead$p), verdict),
apa = sprintf("%s = %s, %s", lead$test, cs_fmt_num(lead$statistic), cs_fmt_p(lead$p)),
statistics = list(list(key = "mean", label = "Mean life", value = mean_x), list(key = "rate", label = "Failure rate", value = 1 / mean_x),
list(key = "n_reject", label = "Tests rejecting", value = length(rejecting), format = "integer"),
list(key = "battery_p", label = "p, adjusted for the battery", value = battery_p, format = "p"),
list(key = "n_tests", label = "Tests run", value = length(tested), format = "integer")),
tables = list(
list(key = "tests", title = "Exponentiality tests", columns = list(
list(key = "test", label = "Test", type = "string"), list(key = "statistic", label = "Statistic", type = "number"),
list(key = "z", label = "z", type = "number"), list(key = "p_ref", label = "p (reference)", type = "pvalue"),
list(key = "p_mc", label = "p (simulated)", type = "pvalue"), list(key = "p", label = "p used", type = "pvalue"),
list(key = "p_adj", label = "p adjusted", type = "pvalue"),
list(key = "reject", label = "Rejects at .05", type = "string")), rows = table),
list(key = "mean_life", title = "Mean life under the exponential model", columns = list(
list(key = "mean", label = "Mean life", type = "number"), list(key = "low", label = paste(pct, "CI low"), type = "number"),
list(key = "high", label = paste(pct, "CI high"), type = "number"), list(key = "rate", label = "Failure rate", type = "number")),
rows = list(list(mean = mean_x, low = mean_low, high = mean_high, rate = 1 / mean_x)))
),
effectSizes = list(),
assumptions = assumptions,
warnings = warnings,
notes = list(
sprintf("Simulated p-values compare each statistic with %d exponential samples of the same size (seed %d), renormalized as in the data; every test sees the same samples.", reps, as.integer(seed)),
if (adjust_method == "min_p") "The count of rejections is not a combined test: the tests overlap, so about 3 in 10 exponential samples get at least one. The adjusted p asks how often exponential samples of this size give a smallest p-value this small across all the tests (single-step min-p, Westfall & Young 1993)."
else "The count of rejections is not a combined test: the tests overlap, so about 3 in 10 exponential samples get at least one. Some tests here use a reference distribution, so the adjusted p is Bonferroni, which is cautious for overlapping tests.",
"The total-time-on-test area equals one minus the Gini statistic.",
"A Gini statistic below one half and a TTT plot above the diagonal point to a rising failure rate; the reverse points to a falling one."
),
charts = charts,
values = values
))
Gini = 0.54, p = .457
- Mean life
- 0.8592
- Failure rate
- 1.164
- Tests rejecting
- 0
- p, adjusted for the battery
- .457
- Tests run
- 1
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Independent lifetimes — Not testable from these numbers alone; check how the units were sampled.
- Complete lifetimes — All 24 values are treated as failures. For censored units use Distribution ID.
- No tied lifetimes — All lifetimes are distinct.
Exponentiality tests
| Test | Statistic | z | p (reference) | p (simulated) | p used | p adjusted | Rejects at .05 |
|---|---|---|---|---|---|---|---|
| Gini | 0.5447 | 0.7434 | .457 | — | .457 | .457 | no |
Mean life under the exponential model
| Mean life | 95% CI low | 95% CI high | Failure rate |
|---|---|---|---|
| 0.8592 | 0.5975 | 1.341 | 1.164 |
- Simulated p-values compare each statistic with 999 exponential samples of the same size (seed 42), renormalized as in the data; every test sees the same samples.
- The count of rejections is not a combined test: the tests overlap, so about 3 in 10 exponential samples get at least one. Some tests here use a reference distribution, so the adjusted p is Bonferroni, which is cautious for overlapping tests.
- The total-time-on-test area equals one minus the Gini statistic.
- A Gini statistic below one half and a TTT plot above the diagonal point to a rising failure rate; the reverse points to a falling one.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Exponentiality tests (battery)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method life.exponentiality 1.0.2 · spec 0ae686865f94ebe7
# Dataset: life_exp_sim (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
from scipy import stats
import codesplash as cs
from codesplash.stats import exponentiality as ex # the tests, written from the papers; shared random stream
# %% Data
df = pd.read_parquet("tests/parity/fixtures/life_exp_sim.parquet", columns=["x"])
n_input = len(df)
df = df.dropna(subset=["x"]) # listwise deletion over the analysis columns
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["x"]) # infinite values stop the run (registry/errors.yaml)
# %% Tests
y = "x"
x = df[y].to_numpy(dtype=float)
x = x[~np.isnan(x)]
if (x <= 0).any():
cs.cs_error("CS_E_INVALID_VALUES", column=y, requirement="positive (lifetimes above zero)", count=int((x <= 0).sum()))
n = x.size
cs.check_rows(n, 5, "The exponentiality tests") # the battery needs at least 5 lifetimes
test = "gini"
alpha = 0.05
seed, reps = 42, int(999) # exponential samples from the shared Wichmann–Hill stream
a, b, power = 1, 0.44, 0.99
if b == 1:
raise ValueError("Deshpande's b must differ from 1")
if power in (0, 1):
raise ValueError("Atkinson's power cannot be 0 or 1")
rows = ex.exp_battery(
x, tests=None if test == "battery" else [test], calibration="reference", reps=reps, seed=seed, a=a, b=b, power=power,
r_gnedenko=None,
r_harris=None,
)
tested = [r for r in rows if np.isfinite(r["p"])]
rejecting = [r for r in tested if r["p"] < alpha]
# About 1.5 of 30 tests reject by chance, and because they overlap, some rejection turns up in about 3 of every 10
# truly exponential samples. So the verdict rests on the p adjusted for running them all, not on the count.
adjust_method = rows[0]["adjust"]
battery_p = min((r["p_adj"] for r in tested), default=float("nan"))
if n < 300 and any(r["calibration"] == "reference" and r["key"] in ("kochar", "ahsanullah", "rossberg", "deshpande") for r in rows):
warnings.append("Reference distributions reject too often below about 300 lifetimes: Kochar 12%, Ahsanullah 11% and Rossberg 10% at the 5% level with 30 lifetimes. Simulate instead.")
# %% Mean life under the exponential model (exact chi-square interval)
conf = 0.95
mean = float(x.mean())
mean_low = 2 * n * mean / float(stats.chi2.ppf(1 - (1 - conf) / 2, 2 * n))
mean_high = 2 * n * mean / float(stats.chi2.ppf((1 - conf) / 2, 2 * n))
order = np.sort(x)
gini = float(2 * np.sum((2 * np.arange(1, n + 1) - n - 1) * order) / (2 * n * (n - 1) * mean))
# %% Verdict and values
lead = next((r for r in rows if r["key"] == "cox_oakes"), rows[0])
if len(rows) == 1:
verdict = "exponentiality rejected at α = .05" if lead["p"] < alpha else "compatible with an exponential distribution"
elif not rejecting:
verdict = "the lifetimes are compatible with a constant failure rate"
elif not battery_p < alpha:
verdict = "that is what chance gives across this many overlapping tests, so the lifetimes are compatible with a constant failure rate"
elif not next(r for r in rows if r["key"] == "gini")["p"] < alpha:
verdict = "the lifetimes depart from an exponential, with no clear rising or falling failure rate"
elif gini < 0.5:
verdict = "the departure looks like a rising failure rate (wear-out)"
else:
verdict = "the departure looks like a falling failure rate (early failures)"
values = {"n": n, "mean": mean, "mean_low": mean_low, "mean_high": mean_high, "rate": 1 / mean, "min": float(x.min()), "max": float(x.max()),
"n_tests": len(tested), "n_reject": len(rejecting), "n_not_computed": len(rows) - len(tested),
"battery_p": battery_p, "n_reject_adj": sum(1 for r in tested if r["p_adj"] < alpha), "adjust_method": adjust_method,
"test_label": lead["test"] if len(rows) == 1 else "Battery", "verdict": verdict, "lead_label": lead["test"], "lead_stat": lead["statistic"], "lead_p": lead["p"],
"gini": gini, "reps": reps}
def cell(v):
"""A table cell: a number the test does not have shows a dash, not NaN."""
return float(v) if np.isfinite(v) else None
table = []
for r in rows:
k = r["key"]
values[f"stat[{k}]"], values[f"z[{k}]"], values[f"p[{k}]"] = r["statistic"], r["z"], r["p"]
values[f"p_ref[{k}]"], values[f"p_mc[{k}]"], values[f"calibration[{k}]"] = r["p_ref"], r["p_mc"], r["calibration"]
values[f"p_adj[{k}]"] = r["p_adj"]
computed = bool(np.isfinite(r["p"]))
table.append({"test": r["test"], "statistic": cell(r["statistic"]), "z": cell(r["z"]), "p_ref": cell(r["p_ref"]), "p_mc": cell(r["p_mc"]), "p": cell(r["p"]), "p_adj": cell(r["p_adj"]),
"reject": ("yes" if r["p"] < alpha else "no") if computed else "not computed"})
# %% Assumptions
tied = n - np.unique(x).size
assumptions = [
{"key": "independence", "label": "Independent lifetimes", "status": "info", "detail": "Not testable from these numbers alone; check how the units were sampled."},
{"key": "complete_data", "label": "Complete lifetimes", "status": "info", "detail": f"All {n} values are treated as failures. For censored units use Distribution ID."},
{"key": "ties", "label": "No tied lifetimes", "status": "warn" if tied else "pass",
"detail": f"{tied} tied value(s): zero spacings stop the Epstein test and weaken the other spacing tests." if tied else "All lifetimes are distinct."},
]
# %% Charts
pct = f"{conf:.0%}"
fit_t = np.linspace(float(x.min()), float(x.max()), 60)
charts = [
cs.chart("ttt", "ttt-plot", f"Scaled total-time-on-test plot: {y}", {"value": cs.col(y, x, "numeric")}),
cs.chart("paper", "probability-plot", f"Exponential probability plot: {y}", {
"time": cs.col(y, np.concatenate((x, fit_t)), "numeric"),
"fit": cs.col("Fitted F(t)", np.concatenate((np.full(n, np.nan), -np.expm1(-fit_t / mean))), "numeric"),
"family": cs.col("Series", ["data"] * n + ["exponential"] * fit_t.size, "categorical", levels=["data", "exponential"]),
}, controls={"paper": "exponential"}),
cs.chart("lorenz", "lorenz-gini", f"Lorenz curve: {y}", {"value": cs.col(y, x, "numeric")}),
]
# %% Result
cs.publish({
"method": "life.exponentiality",
"methodVersion": "1.0.2",
"title": "Exponentiality tests" if len(rows) > 1 else f"Exponentiality: {lead['test']}",
"engine": cs.engine_info("numpy", "scipy", "codesplash"),
"n": int(n),
"summary": (f"{len(rejecting)} of {len(tested)} tests reject exponentiality at α = .05; adjusted for running all {len(tested)}, {cs.fmt_p(battery_p)}: {verdict}." if len(rows) > 1
else f"{lead['test']}: {cs.fmt_p(lead['p'])}; {verdict}."),
"apa": f"{lead['test']} = {cs.fmt_num(lead['statistic'])}, {cs.fmt_p(lead['p'])}",
"statistics": [{"key": "mean", "label": "Mean life", "value": mean}, {"key": "rate", "label": "Failure rate", "value": 1 / mean},
{"key": "n_reject", "label": "Tests rejecting", "value": len(rejecting), "format": "integer"},
{"key": "battery_p", "label": "p, adjusted for the battery", "value": battery_p, "format": "p"},
{"key": "n_tests", "label": "Tests run", "value": len(tested), "format": "integer"}],
"tables": [
{"key": "tests", "title": "Exponentiality tests", "columns": [
{"key": "test", "label": "Test", "type": "string"}, {"key": "statistic", "label": "Statistic", "type": "number"},
{"key": "z", "label": "z", "type": "number"}, {"key": "p_ref", "label": "p (reference)", "type": "pvalue"},
{"key": "p_mc", "label": "p (simulated)", "type": "pvalue"}, {"key": "p", "label": "p used", "type": "pvalue"},
{"key": "p_adj", "label": "p adjusted", "type": "pvalue"},
{"key": "reject", "label": "Rejects at .05", "type": "string"}], "rows": table},
{"key": "mean_life", "title": "Mean life under the exponential model", "columns": [
{"key": "mean", "label": "Mean life", "type": "number"}, {"key": "low", "label": f"{pct} CI low", "type": "number"},
{"key": "high", "label": f"{pct} CI high", "type": "number"}, {"key": "rate", "label": "Failure rate", "type": "number"}],
"rows": [{"mean": mean, "low": mean_low, "high": mean_high, "rate": 1 / mean}]},
],
"effectSizes": [],
"assumptions": assumptions,
"warnings": warnings,
"notes": [
f"Simulated p-values compare each statistic with {reps} exponential samples of the same size (seed {seed}), renormalized as in the data; every test sees the same samples.",
("The count of rejections is not a combined test: the tests overlap, so about 3 in 10 exponential samples get at least one. The adjusted p asks how often exponential samples of this size give a smallest p-value this small across all the tests (single-step min-p, Westfall & Young 1993)." if adjust_method == "min_p"
else "The count of rejections is not a combined test: the tests overlap, so about 3 in 10 exponential samples get at least one. Some tests here use a reference distribution, so the adjusted p is Bonferroni, which is cautious for overlapping tests."),
"The total-time-on-test area equals one minus the Gini statistic.",
"A Gini statistic below one half and a TTT plot above the diagonal point to a rising failure rate; the reverse points to a falling one.",
],
"charts": charts,
"values": values,
})
A sample can match this one summary without being exponential. Look at the plot too.
Your own lifetimes
ReflectThink of something that fails in your work: a device, a subscription, a server, a customer relationship.
Would you expect its hazard to rise, fall or stay flat with age? What would you do differently in each case?
Check your understanding
CheckpointCheck yourself
A scaled TTT plot bows above the diagonal and is well below one half. What does that suggest?
Show the answer
Answer: a
Above the diagonal means rising hazard, and lifetimes bunch together, which makes small.
Check yourself
An exponential part has mean life 500 hours. It has already run 800 hours. What is the probability it lasts 500 more? Give three decimals.
Show the answer
Answer: 0.368
The past doesn't matter: .
Check yourself
Run the code below on life_wear_sim.csv. What is the Gini statistic? Give two decimals.
Show the answer
Answer: 0.238619751948953
is about a quarter here, well under one half. A Weibull with shape 2.5 has an exact of , close to the sample's value.
Do it in CodeSplash
In the appIn Studios, open Quality & DoE and start from Is the failure rate constant? to go directly to the exponentiality step with its TTT plot. For a quick single test, use Analyze.
This script computes and the height of the TTT curve, and shows they agree.
import numpy as np
import pandas as pd
x = np.sort(pd.read_csv("life_wear_sim.csv")["x"].to_numpy())
n = len(x)
g = np.abs(x[:, None] - x[None, :]).sum() / (2 * n * (n - 1) * x.mean())
spacing = (n - np.arange(n)) * np.diff(np.r_[0, x])
ttt = np.cumsum(spacing) / spacing.sum()
print(g, 1 - ttt[:-1].mean())x <- sort(read.csv("life_wear_sim.csv")$x)
n <- length(x)
g <- sum(abs(outer(x, x, "-"))) / (2 * n * (n - 1) * mean(x))
spacing <- (n - 0:(n - 1)) * diff(c(0, x))
ttt <- cumsum(spacing) / sum(spacing)
c(g, 1 - mean(ttt[-n]))Recap
Recap- An exponential lifetime has no memory: the hazard is the same at every age.
- A scaled TTT plot on the diagonal is compatible with a constant rate; above it means wear-out, and below it a falling rate.
- The Gini statistic is one half under the exponential, and lower for wear-out.
Concepts in this lesson