{
  "category": "Statistical functions",
  "display_name": "STEYX",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.STEYX",
  "implementation_state": {
    "answer_bank": null,
    "detail": "Recorded: 6 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 6 recorded answers",
    "workbook_corpus": {
      "cells": 6,
      "matched": 6
    }
  },
  "implementations": [
    {
      "commit": "9e1884369a678158dd82d3d74188daf986995e87",
      "flavour": "excel-compatibility-candidate",
      "language": "Rust",
      "name": "CalcFunc",
      "own_code": [
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/statistics.rs#L377-L379",
        "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/ported/moment_stats_family.rs#L101-L128"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/statistics.rs#L377-L379",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 6 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.STEYX.json",
  "name": "STEYX",
  "notes": [],
  "schema": "efh.function-reference/v1",
  "section_order": [
    "what-it-does",
    "try-it",
    "quirks",
    "how-to-implement",
    "version-differences",
    "alternatives"
  ],
  "sections": {
    "alternatives": "\n### Relationships\n\n\n`STEYX` is one output of a single least-squares fit, and Excel spreads that one fit across half a\ndozen surfaces. Holding them together is the useful thing this page can do:\n\n| Surface | Which part of the same fit |\n|---|---|\n| `SLOPE` | `b = Sxy / Sxx` |\n| `INTERCEPT` | `a = ȳ − b·x̄` |\n| `RSQ` | `r² = Sxy² / (Sxx·Syy)` |\n| `PEARSON`, `CORREL` | `r = Sxy / sqrt(Sxx·Syy)` |\n| `FORECAST`, `FORECAST.LINEAR` | `a + b·x*` at a new point |\n| `TREND` | the same, vectorized and generalized to several predictors |\n| `LINEST` | all of the above at once — and its statistics block reports the same standard error of the estimate that `STEYX` returns |\n| `STEYX` | `sqrt( Syy(1 − r²) / (n − 2) )` |\n\nThe identity worth remembering, because it is exact and testable:\n`STEYX² · (n − 2) = Syy · (1 − RSQ)`, with `Syy = DEVSQ(known_y's)`. That gives a route to check\nExcel against Excel with no external oracle.\n\n- **`LINEST`** is the closest relative and the one that matters most: it computes this quantity\n  as part of its statistics block, so Excel has at least two code paths to the same number. Are\n  they the same path? Nobody has published an answer.\n- **`STDEV.S`** is the corresponding one-variable object: `STEYX` is to a fitted line what\n  `STDEV.S` is to a fitted constant, right down to the degrees-of-freedom bookkeeping\n  (`n − 1` for one estimated parameter, `n − 2` for two).\n- **Confused with**: the standard error *of the slope* (which `LINEST` also reports, and which is\n  `STEYX / sqrt(Sxx)`), and with the standard error *of a prediction* at a new point (which is\n  larger, and which no Excel surface returns). `STEYX`'s own English description — \"the standard\n  error of the predicted y-value for each x in the regression\" — invites exactly this confusion,\n  because the standard error of a predicted value is not what the documented formula computes.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n**The subtraction is the problem.** `Syy − Sxy²/Sxx` is mathematically `Syy(1 − r²)`, and when\nthe fit is good `r²` is close to 1, so the two terms are nearly equal and their difference loses\ndigits proportionally. For `r² = 1 − δ`, roughly `−log₁₀ δ` decimal digits are gone. Real\nregression data with `r² = 0.9999` — an ordinary result in a calibration lab — has already lost\nfour digits before the square root is taken, and the square root then halves the *relative* error,\nwhich is the one mercy in the arrangement. The failure mode at the end of the road is a negative\nradicand and a domain error on `sqrt` for data that is merely collinear to within rounding.\n\n**The fix is to compute a sum of squares, not a difference.** `Σ(yᵢ − ŷᵢ)²` is non-negative by\nconstruction and has no cancellation between terms — only within each residual, where it is\nbenign because the residual is the quantity of interest. It costs a second pass over the data.\nFor the same reason a QR factorization of the design matrix by Householder reflections yields the\nresidual norm directly as the norm of the transformed tail, with no subtraction anywhere; this is\nthe standard recommendation of the least-squares literature (Lawson & Hanson; Björck; Golub & Van\nLoan; Higham, *Accuracy and Stability of Numerical Algorithms*, chapter 20). The one-variable\nanalogue of the same argument — never compute a variance as `Σx² − (Σx)²/n` — is Higham's §1.9\nand Chan, Golub & Van Loan's classic note, and it is the same lesson one dimension down.\n\n**Centring is already correct here.** Microsoft's documented formula is written in deviations\nfrom the means, so it is a two-pass centred form and avoids the worst of the uncentred disease.\nThat is worth crediting: the documented formula's weakness is the `r² → 1` cancellation, not the\nlarge-offset catastrophe that afflicts uncentred computational formulas.\n\n**Accumulation order matters.** `Sxx`, `Syy` and `Sxy` are sums of products; their accuracy\ndepends on summation order and on whether a compensated (Kahan/Neumaier) or pairwise sum is used.\nFor data spanning many magnitudes the difference is visible in the last digits of the answer.\n\nThe accuracy of Excel's own statistical procedures — and specifically its regression outputs — is\nthe subject of a substantial published literature: Morten Welinder's work on Gnumeric's\nstatistical functions documents the historical failure modes concretely, and the assessments by\nKnüsel and by McCullough & Wilson evaluate Excel's regression against the NIST StRD reference\ndatasets (`Norris`, `Longley`, `Filip`, the `Wampler` series). The Handbook names those sources\nbecause they are the right reading; it does **not** assert from them what any current Excel build\ndoes with `STEYX`, which is a separate question nobody in this record has measured.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number`, a non-negative standard error.\n\n- **Near-collinear data** — real calibration data, for instance — is worse than perfectly\n  collinear data, because the true answer is small and non-zero, so relative accuracy is\n  observable and the cancellation eats it.\n- **`n = 3`** is the smallest admissible case (one residual degree of freedom) and is the point\n  where the estimator has the least information; `n < 3` is a documented `#DIV/0!`.\n- **Constant `x`** makes `Sxx = 0` and the regression undefined. The documented error list does\n  not cover it. What Excel does — `#DIV/0!`, `#NUM!`, or a number — is unchecked.\n- **Constant `y` with varying `x`** is fine: the fitted line is flat and the standard error is 0.\n- **Very large or very small magnitudes.** Because the formula is written in centred deviations\n  it does not have the classic uncentred sum-of-squares overflow problem, but `Sxy²` squares an\n  already-squared quantity and can overflow for data that `Syy` and `Sxx` handle comfortably. A\n  vector of values around `1e160` is enough.\n\n\n\n### Errors\n\n\nAs documented on Microsoft's `STEYX` page:\n\n| Error | Documented condition |\n|---|---|\n| `#N/A` | `known_y's` and `known_x's` have a different number of data points. |\n| `#DIV/0!` | `known_y's` and `known_x's` are empty, or have fewer than three data points. |\n| propagated | \"Arguments that are error values or text that cannot be translated into numbers cause errors.\" |\n\nNot documented: the constant-`x` case (`Sxx = 0`), and what happens if the cancellation in the\ndocumented formula produces a negative radicand. Both would have to resolve to something, and\nneither is named. The Handbook has not verified any of this against Excel.\n\n\n",
    "sources": "\n- Microsoft, \"STEYX function\" —\n  <https://support.microsoft.com/en-us/office/steyx-function-6ce74b2c-449d-4a6e-b9ac-f9cef5ba48ab>\n  (syntax; the standard-error equation; the direct-versus-reference coercion split, including\n  that cells with the value zero are included while text, logicals and empty cells in a reference\n  are ignored; `#N/A` for different numbers of data points; `#DIV/0!` for empty arguments or\n  fewer than three data points; and that error values and untranslatable text cause errors).\n  Retrieved for this page.\n- N. J. Higham, *Accuracy and Stability of Numerical Algorithms* — §1.9 on computing the sample\n  variance without a cancelling difference, and chapter 20 on least-squares problems and the\n  residual norm from a QR factorization.\n- C. L. Lawson and R. J. Hanson, *Solving Least Squares Problems*; Å. Björck, *Numerical Methods\n  for Least Squares Problems*; G. H. Golub and C. F. Van Loan, *Matrix Computations* — the\n  Householder-QR route to a residual sum of squares with no subtraction.\n- T. F. Chan, G. H. Golub and R. J. LeVeque, \"Algorithms for computing the sample variance:\n  analysis and recommendations\" — the one-dimensional form of the same argument.\n- M. Welinder's documentation of Gnumeric's statistical functions, and the assessments of Excel's\n  statistical procedures against the NIST Statistical Reference Datasets by R. Knüsel and by\n  B. D. McCullough and B. Wilson — named as the standing literature on Excel's regression\n  accuracy, not as evidence about any current build.\n- Handbook [Coercion and lifting](../model/02-coercion-and-lifting.md).\n- Handbook projections `data/functions/FUNC.STEYX.json` (arity, classification axes),\n  `data/presence/FUNC.STEYX.json` (the shared `moment_stats_family` module) and\n  `data/battery/FUNC.STEYX.json`.\n\n",
    "version-differences": "No comparison between specific Excel builds is recorded here yet. This does not establish that all builds behave alike.",
    "what-it-does": "\n`STEYX(known_y's, known_x's)` returns the **standard error of the estimate** for a simple linear\nregression of `y` on `x` — the residual standard deviation of the fitted line, and the quantity a\ntextbook writes `s_{y·x}` or `s_e`.\n\nMicrosoft gives the defining formula on the function's page. Written out, with `n` the number of\npaired points and bars denoting means:\n\n    STEYX = sqrt(  ( Σ(y − ȳ)²  −  ( Σ(x − x̄)(y − ȳ) )² / Σ(x − x̄)² )  /  (n − 2)  )\n\nThe bracketed quantity is the **residual sum of squares** of the least-squares line. Introducing\nthe usual centred sums\n\n    Sxx = Σ(x − x̄)²,    Syy = Σ(y − ȳ)²,    Sxy = Σ(x − x̄)(y − ȳ)\n\nthe formula is `sqrt( (Syy − Sxy²/Sxx) / (n − 2) )`, and every equivalent reading is worth having\nin view because each one exposes a different implementation route:\n\n    Syy − Sxy²/Sxx  =  Syy · (1 − r²)  =  Σ(yᵢ − ŷᵢ)²  =  Syy − b · Sxy\n\nwhere `r` is the Pearson correlation (`RSQ` is `r²`), `b = Sxy/Sxx` is the slope (`SLOPE`), and\n`ŷᵢ = a + b·xᵢ` are the fitted values. The last of the four is a sum of squares and therefore\nnon-negative by construction; the first is a difference of two positive numbers and is not. That\ndistinction is the entire numerical content of this function, and it is taken up below.\n\nDomain and range: defined for `n ≥ 3` paired finite points with `Sxx > 0`; the result is a\nnon-negative real in the same units as `y`. It is exactly 0 when the points are collinear, and\nit grows without bound as the scatter about the line grows.\n\nThe divisor `n − 2` is the residual degrees of freedom: two parameters — slope and intercept —\nhave been estimated from the data. This makes `STEYX²` the unbiased estimator of the error\nvariance σ² in the model `y = α + βx + ε`, `ε ~ N(0, σ²)`, which is why it is `n − 2` and not\n`n` or `n − 1`.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Required |\n|---|---|---|\n| `known_y's` | \"An array or range of dependent data points.\" | Yes |\n| `known_x's` | \"An array or range of independent data points.\" | Yes |\n\nThe documented coercion rule is the familiar direct-versus-scan split, stated on the function's\npage in the same words the aggregates use:\n\n- **Typed directly into the argument list**: logical values and text representations of numbers\n  are counted.\n- **Inside an array or reference**: text, logical values and empty cells are ignored — but cells\n  containing zero *are* included.\n\nSee [Coercion and lifting](../model/02-coercion-and-lifting.md) for why those two rules are\ndifferent rules rather than one rule with an exception.\n\nWhat the documentation does not say, and this page will not invent: **when a value is ignored in\none vector, what happens to its partner in the other?** A regression over paired data has to\nanswer this — either the pair is dropped together, or the two vectors are compacted\nindependently and the pairing silently shifts. The two readings give different numbers on the\nsame input, and the second one gives an answer that is not a regression of anything. Microsoft's\npage is silent. It is the first probe below.\n\n\n"
  },
  "signature": {
    "display": "STEYX(known_ys, known_xs)",
    "parameters": [
      {
        "description": null,
        "name": "known_ys",
        "optional": false,
        "repeats": false
      },
      {
        "description": null,
        "name": "known_xs",
        "optional": false,
        "repeats": false
      }
    ],
    "trailing_repeats": false
  },
  "sources": {
    "metadata": {
      "admission": {
        "label": "implemented",
        "reason": null
      },
      "arity": {
        "max": 2,
        "min": 2
      },
      "category": "Statistical functions",
      "classification": {
        "arg_preparation_profile": "ValuesOnlyPreAdapter",
        "coercion_lift_profile": "Custom",
        "determinism_class": "Deterministic",
        "error_collapse_profile": "None",
        "fec_dependency_profile": "None",
        "host_interaction_class": "None",
        "kernel_signature_class": "Custom",
        "rich_value_usage": "RichBlind",
        "surface_fec_dependency_profile": "RefOnly",
        "thread_safety_class": "SafePure",
        "volatility_class": "NonVolatile"
      },
      "descriptions": {
        "long": null,
        "short": "Standard error of the y values predicted by the least-squares line",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the standard error of the predicted y-value for each x in the regression",
        "microsoft_url": "https://support.microsoft.com/en-us/office/steyx-function-6ce74b2c-449d-4a6e-b9ac-f9cef5ba48ab"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "STEYX"
        },
        {
          "locale": "bg-BG",
          "name": "STEYX"
        },
        {
          "locale": "cs-CZ",
          "name": "STEYX"
        },
        {
          "locale": "da-DK",
          "name": "STFYX"
        },
        {
          "locale": "de-DE",
          "name": "STEYX"
        },
        {
          "locale": "el-GR",
          "name": "STEYX"
        },
        {
          "locale": "en-AU",
          "name": "STEYX"
        },
        {
          "locale": "en-GB",
          "name": "STEYX"
        },
        {
          "locale": "en-US",
          "name": "STEYX"
        },
        {
          "locale": "es-ES",
          "name": "ERROR.TIPICO.XY"
        },
        {
          "locale": "et-EE",
          "name": "STEYX"
        },
        {
          "locale": "fi-FI",
          "name": "KESKIVIRHE"
        },
        {
          "locale": "fr-FR",
          "name": "ERREUR.TYPE.XY*"
        },
        {
          "locale": "he-IL",
          "name": "STEYX"
        },
        {
          "locale": "hr-HR",
          "name": "STEYX"
        },
        {
          "locale": "hu-HU",
          "name": "STHIBAYX"
        },
        {
          "locale": "id-ID",
          "name": "STEYX"
        },
        {
          "locale": "it-IT",
          "name": "STEYX"
        },
        {
          "locale": "ja-JP",
          "name": "STEYX"
        },
        {
          "locale": "ko-KR",
          "name": "STEYX"
        },
        {
          "locale": "lt-LT",
          "name": "STEYX"
        },
        {
          "locale": "lv-LV",
          "name": "STEYX"
        },
        {
          "locale": "nb-NO",
          "name": "STEYX"
        },
        {
          "locale": "nl-NL",
          "name": "STAND.FOUT.YX"
        },
        {
          "locale": "pl-PL",
          "name": "REGBŁSTD"
        },
        {
          "locale": "pt-BR",
          "name": "STEYX"
        },
        {
          "locale": "pt-PT",
          "name": "EPADYX"
        },
        {
          "locale": "ro-RO",
          "name": "STEYX"
        },
        {
          "locale": "ru-RU",
          "name": "СТОШYX"
        },
        {
          "locale": "sk-SK",
          "name": "STEYX"
        },
        {
          "locale": "sl-SI",
          "name": "STEYX"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "STEYX"
        },
        {
          "locale": "sv-SE",
          "name": "STDFELYX"
        },
        {
          "locale": "th-TH",
          "name": "STEYX"
        },
        {
          "locale": "tr-TR",
          "name": "STHYX işlevi"
        },
        {
          "locale": "uk-UA",
          "name": "STEYX"
        },
        {
          "locale": "vi-VN",
          "name": "STEYX"
        },
        {
          "locale": "zh-CN",
          "name": "STEYX"
        },
        {
          "locale": "zh-HK",
          "name": "STEYX"
        },
        {
          "locale": "zh-TW",
          "name": "STEYX"
        }
      ],
      "signature": {
        "display": "STEYX(known_ys, known_xs)",
        "parameters": [
          {
            "description": null,
            "name": "known_ys",
            "optional": false,
            "repeats": false
          },
          {
            "description": null,
            "name": "known_xs",
            "optional": false,
            "repeats": false
          }
        ],
        "trailing_repeats": false
      },
      "surface_name": "STEYX",
      "version_marker": null,
      "xlcall": {
        "code": "314",
        "symbol": "xlfSteyx"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/steyx-function-6ce74b2c-449d-4a6e-b9ac-f9cef5ba48ab"
  },
  "try_it": {
    "formula": "=STEYX({2;4;7;8},{1;2;3;4})"
  },
  "url": "https://handbook.dnacalc.com/functions/STEYX.html",
  "variants": [],
  "versions": []
}