Skip to content
svgcensored-fit

Censored regression (Tobit) fit

How does a Tobit model's latent mean relate to outcomes that pile up at a limit?

Demo data · seed 20261101 · 120 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each point as an outcome against its fitted latent mean.
  2. Squares mark rows censored at the limit.
  3. The latent mean extends below the limit, which is why simple regression would be biased.
  1. Callout 1: Censored rows, piled up at the limit.
  2. Callout 2: Uncensored rows follow the line.
  3. Callout 3: The line y = x.

Watch out

  • If far more than half the rows are censored, the estimates lean heavily on normality.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing inferential.
  • Status values containing “left/lower” or “right/upper” mark censored rows; everything else is uncensored.
  • Censored points sit on the limit line by construction — their true latent value is beyond it, which is what the Tobit likelihood accounts for.
# Censored regression (Tobit) fit — Codesplash Chart Lab (recipe "censored-fit")
# controls: defaults
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("censored-fit-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["status"] = pd.Categorical(df["status"].astype("string"), categories=["observed", "left-censored"])

_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")
F = "x′β"
O = "hours"
ST = "status"
d = df.dropna(subset=[F, O])
status = d[ST].astype(str).str.lower() if ST else pd.Series("", index=d.index)
cens = status.str.contains("left|lower|below|right|upper|above")
lim = [min(d[F].min(), d[O].min()), max(d[F].max(), d[O].max())]
fig, ax = plt.subplots(figsize=(7, 5))
ax.plot(lim, lim, color=REF, linestyle="--", label="y = x")
ax.scatter(d.loc[~cens, F], d.loc[~cens, O], s=14, color=PALETTE[0], alpha=0.6, label="uncensored")
ax.scatter(d.loc[cens, F], d.loc[cens, O], s=26, marker="s", facecolors="none", edgecolors="#c27c0e", label="censored (at the limit)")
ax.set_xlabel("fitted latent mean (x'b)")
ax.set_ylabel(O)
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads censored-fit-demo.csv · app theme from the optional codesplash helper