svgfstat-sequence
F statistics over candidate breaks
At which date would a break in the regression be most pronounced, and is the largest F beyond chance?
How to read it
- Read the curve as the F statistic for a break after each candidate date.
- The highest point (sup-F) is the most pronounced break.
- Compare it with the critical value of the maximum, not the usual F table.
- Callout 1: sup-F: the largest F, at the most pronounced break.
- Callout 2: Low values: no sign of a break around these dates.
Watch out
- Searching all dates inflates F, so a usual F table overstates the evidence.
Defaults
- 5% critical value (0 = none)
- 0
- The critical value of sup-F (the analysis sends a simulated one).
- Range 0 to 100, step 0.1
Pinned in the code
- F_i = (RSS − RSS₁ − RSS₂) / ((RSS₁ + RSS₂)/(n − 2k)) for a break after observation i, i = ⌊πn⌋…⌊(1−π)n⌋, as strucchange::Fstats.
- The critical line is for the maximum over all candidates — not for any single F — so it sits well above the usual F critical value.
# F statistics over candidate breaks — Codesplash Chart Lab (recipe "fstat-sequence")
# controls: crit=0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
df = pd.read_csv("fstat-sequence-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"]) # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"]) # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def ordered(d, x, cols):
"""Rows with the needed values, sorted by the time column (stable); row order when there is none."""
d = d.dropna(subset=[c for c in cols if c] + ([x] if x else []))
return d.sort_values(x, kind="stable") if x else d
def time_of(d, x):
return d[x] if x else pd.Series(np.arange(1, len(d) + 1), index=d.index)
X = "break after"
Y = "F"
CRIT = 0 # 5% critical value of sup-F (0 = none)
d = ordered(df, X, [Y])
t, F = time_of(d, X), d[Y].to_numpy(dtype=float)
i = int(np.argmax(F))
fig, ax = plt.subplots(figsize=(8, 4))
if CRIT > 0:
ax.axhline(CRIT, color="#ce5342", linestyle="--", label="5% critical value of sup-F")
ax.plot(t, F, color=PALETTE[0], linewidth=1.6)
ax.scatter([t.iloc[i]], [F[i]], color="#ce5342" if CRIT and F[i] > CRIT else PALETTE[3 % len(PALETTE)], zorder=3)
ax.set_title(f"sup-F = {F[i]:.2f} after {t.iloc[i]}", fontsize=10, loc="left")
ax.set_ylim(bottom=0)
ax.set_xlabel("break after")
ax.set_ylabel("F")
plt.show()Needs pandas, numpy, matplotlib · reads fstat-sequence-demo.csv · app theme from the optional codesplash helper
# F statistics over candidate breaks — Codesplash Chart Lab (recipe "fstat-sequence")
# controls: crit=0
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
try:
import codesplash as cs # optional: the app's chart theme
except ImportError:
cs = None
if cs:
cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else px.colors.qualitative.Plotly
df = pd.read_csv("fstat-sequence-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"]) # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"]) # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def ordered(d, x, cols):
"""Rows with the needed values, sorted by the time column (stable); row order when there is none."""
d = d.dropna(subset=[c for c in cols if c] + ([x] if x else []))
return d.sort_values(x, kind="stable") if x else d
def time_of(d, x):
return d[x] if x else pd.Series(np.arange(1, len(d) + 1), index=d.index)
X = "break after"
Y = "F"
CRIT = 0
d = ordered(df, X, [Y])
t, F = time_of(d, X), d[Y].to_numpy(dtype=float)
i = int(np.argmax(F))
fig = go.Figure(go.Scatter(x=t, y=F, mode="lines", line=dict(color=PALETTE[0])))
if CRIT > 0:
fig.add_hline(y=CRIT, line=dict(color="#ce5342", dash="dash"), annotation_text="5% critical value")
fig.add_scatter(x=[t.iloc[i]], y=[F[i]], mode="markers", marker=dict(size=9, color="#ce5342"))
fig.update_layout(title=f"sup-F = {F[i]:.2f}", xaxis_title="break after", yaxis_title="F", showlegend=False)
fig.show()Needs pandas, numpy, plotly · reads fstat-sequence-demo.csv · app theme from the optional codesplash helper
# F statistics over candidate breaks — Codesplash Chart Lab (recipe "fstat-sequence")
# controls: crit=0
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("fstat-sequence-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
ordered <- function(d, x, cols) {
keep <- stats::complete.cases(d[, c(cols, x), drop = FALSE])
d <- d[keep, , drop = FALSE]
if (!is.null(x)) d[order(d[[x]]), , drop = FALSE] else d
}
time_of <- function(d, x) if (is.null(x)) seq_len(nrow(d)) else d[[x]]
x_col <- "break after"
y_col <- "F"
CRIT <- 0
d <- ordered(df, x_col, y_col)
fs <- data.frame(t = time_of(d, x_col), F = d[[y_col]])
i <- which.max(fs$F)
p <- ggplot(fs, aes(t, F)) + { if (CRIT > 0) geom_hline(yintercept = CRIT, colour = "#ce5342", linetype = "dashed") } +
geom_line(colour = cs_cat[1]) + geom_point(data = fs[i, ], colour = "#ce5342", size = 2.5) + expand_limits(y = 0) +
labs(x = "break after", y = "F", title = sprintf("sup-F = %.2f", fs$F[i])) + theme_cs
print(p)Needs ggplot2 · reads fstat-sequence-demo.csv · app theme from the optional codesplashr helper