Skip to content

Fit Y by X (Ctrl+F)

Fit Y by X report

When to use it

Univariate linear regression of a continuous Y on a single continuous X (simple linear regression). Use when X is the only predictor and you want the fit line, CI/PI bands, ANOVA decomposition, and parameter estimates in one report. Continuous modeling type for both Y and X. Multivariate Y / X are not used; if a By zone is filled, the launch switches to a t-test-by-group path instead of the scatter report.

GUI workflow

  1. Press Fit Y by X (Ctrl+F) — Launch Dialog opens with Fit Y by X active.
  2. Roles: Y, Response * (single, required), X, Factor * (single, required), By (multiple, optional), Weight, Freq (optional).
  3. Assign Y and X via the picker (activated role zone), one column per zone. By groups the data; with a By assignment the launch runs a t-test comparison instead of the scatter report.
  4. Run opens the floating report window.

Floating report window

  • Scatter / Fit (brushable) — points (unselected/background, selected/accent), the fitted line, and 95% CI (green) and 95% PI (purple) bands when CI/PI is enabled. t-critical uses an approx 95% value of 2.0 for moderate n. Drag to brush-select; click to clear; hidden rows omitted.
  • Summary of Fit — n, R², Residual SD, Slope, Intercept.
  • ANOVA — single row for Regression (Source, SS, DF=1, MS, F) and Residual (Source, SS, DF=n-2, MS, —).
  • Parameter Estimates — Term, Estimate, SE, t, p (intercept and slope from the OLS fit).

Header ... menu: Toggle CI/PI (flips the CI/PI bands immediately), Save Residuals, Save Script to Table, Export SVG, Export JSON. Hidden rows are omitted everywhere.

Mathematical formulation

Ordinary least squares, intercept + slope:

\[\hat{\beta}_1 = \frac{\sum_i (x_i - \bar{x})(y_i - \bar{y})}{\sum_i (x_i - \bar{x})^2},\qquad \hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x}\]

Fitted values \(\hat{y}_i = \hat{\beta}_0 + \hat{\beta}_1 x_i\); residuals \(e_i = y_i - \hat{y}_i\).

ANOVA decomposition:

\[TSS = \sum_i (y_i - \bar{y})^2,\quad RSS = \sum_i e_i^2,\quad SSR = TSS - RSS,\qquad F = \frac{MS_{\text{reg}}}{MS_{\text{res}}}\]

with \(MS_{\text{reg}} = SSR/1\) and \(MS_{\text{res}} = RSS/(n-2)\).

Confidence band and prediction band at an x:

\[\hat{y}(x) \pm t_{\alpha/2,\,n-2}\, s_e \sqrt{\tfrac{1}{n} + \tfrac{(x-\bar{x})^2}{\sum_i (x_i-\bar{x})^2}} \quad\text{(CI)}\]
\[\hat{y}(x) \pm t_{\alpha/2,\,n-2}\, s_e \sqrt{1 + \tfrac{1}{n} + \tfrac{(x-\bar{x})^2}{\sum_i (x_i-\bar{x})^2}} \quad\text{(PI)}\]

\(R^2 = SSR/TSS\); Adjusted \(R^2 = 1 - (1 - R^2)(n-1)/(n-p-1)\) with \(p = 1\).

The OLS fit uses QR/SVD-based stability from leap_stats::ols::fit_ols (basis Linear).

CLI parity — exact flags

Fit Y by X (Ctrl+F) — Launch Dialog → Run.

leap fit-ols data.csv --y <col> --x <col1,col2> [--selected <ids>] [--json]

JSON output includes n_total, n_used, exclusion counts, coefficients (estimate / SE / t / p_value), R², adjusted R², residual SD, RSS/TSS, F-stat/p-value, df, rank, diagnostics (fitted / raw / leverage / standardized / studentized residuals + Cook's distance, plus Q-Q points), and profiler slices (per-predictor grid points with x / predicted_y / 95% CI / PI / in_range, or an error).