{
  "slug": "ordinary-least-squares",
  "title": "Univariate least-squares fit",
  "topic": "estimation",
  "summary": "Inspect an in-sample slope, intercept and fit summary for aligned numerical pairs.",
  "version": "1.0.0",
  "published": "2026-10-16",
  "status": "Educational reference",
  "formula": "slope = sample_cov(x,y)/sample_var(x); intercept = mean(y) - slope*mean(x)",
  "inputs": [
    [
      "x",
      "3-250 finite numbers; each -1000000 to 1000000",
      "Explanatory values, nonconstant"
    ],
    [
      "y",
      "Same length as x; each -1000000 to 1000000",
      "Aligned response values"
    ]
  ],
  "method": [
    "The fixture pairs 1,2,3,4 with 2,4,5,7. The fitted slope is 1.6 and the intercept is 0.5, with residual sum of squares 0.2. These numbers describe the supplied pairs; they do not identify a causal mechanism or establish a forecasting relationship.",
    "The implementation uses the pinned Simple Statistics least-squares function and separately calculates residual fit. Independent Python checks use centered sums, providing a second arithmetic path. Constant x is rejected because no slope is identified; constant y retains a valid fit but withholds R-squared."
  ],
  "limits": [
    "No p-values, robust standard errors, confidence intervals, multiple regressors or out-of-sample predictions are implied. Large offsets with very small variation can be numerically ill-conditioned; rescale before interpreting. This bounded teaching implementation is not a statistical certification."
  ],
  "checks": [
    "Known line, residual sums, constant-response and constant-explanatory cases.",
    "Input alignment and missing-value rejection tested."
  ],
  "related": [
    "regression-fit-versus-forecast",
    "arithmetic-tests-versus-validation"
  ],
  "sources": [
    {
      "title": "SciPy: least-squares regression",
      "url": "https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html"
    },
    {
      "title": "Simple Statistics: reference implementation and API",
      "url": "https://simple-statistics.github.io/"
    }
  ],
  "example": {
    "x": [
      1,
      2,
      3,
      4
    ],
    "y": [
      2,
      4,
      5,
      7
    ]
  },
  "frozen_result": {
    "schema_version": 1,
    "model_id": "ordinary-least-squares",
    "model_version": "1.0.0",
    "engine_version": "1.0.0",
    "published_at": "2026-10-16",
    "scope": "Synthetic educational reference calculation. Not a fitted investment strategy, forecast, provider model or client return.",
    "inputs": {
      "x": [
        1,
        2,
        3,
        4
      ],
      "y": [
        2,
        4,
        5,
        7
      ]
    },
    "outputs": {
      "slope": 1.6,
      "intercept": 0.5,
      "r_squared": 0.9846153846153847,
      "residual_sum_squares": 0.1999999999999999,
      "observations": 4
    },
    "notes": [
      "Univariate in-sample least squares with an intercept. R-squared is withheld for constant response; no inference or out-of-sample accuracy is supplied."
    ]
  }
}
