{
  "category": "Statistical functions",
  "display_name": "SLOPE",
  "entry_kind": "built_in_function",
  "eval_api": {
    "method": "POST",
    "url": "https://handbook.dnacalc.com/api/eval"
  },
  "function_id": "FUNC.SLOPE",
  "implementation_state": {
    "answer_bank": {
      "excel_builds": [
        "20131"
      ],
      "larger_numeric": 0,
      "last_bit": 0,
      "matched": 4,
      "other_mismatch": 0,
      "refused": 0,
      "rows": 4,
      "unread": 0,
      "worst_ulp": 0
    },
    "detail": "Recorded: 4 in the answer bank and 7 workbook cells.",
    "dnacalc_commit": "9e1884369a678158dd82d3d74188daf986995e87",
    "in_catalogue": true,
    "state": "matches",
    "state_label": "Matches every recorded Excel answer",
    "summary": "Matches all 11 recorded answers",
    "workbook_corpus": {
      "cells": 7,
      "matched": 7
    }
  },
  "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#L371-L373"
      ],
      "repository": "https://github.com/DnaCalc/DnaCalc",
      "shared_code": [
        "ported/paired_stats_common::means",
        "ported/paired_stats_common::slope_from_pairs"
      ],
      "source": "https://github.com/DnaCalc/DnaCalc/blob/9e1884369a678158dd82d3d74188daf986995e87/crates/calc-func/src/catalogue/statistics.rs#L371-L373",
      "state": "matches",
      "suite": null,
      "summary": "Matches all 11 recorded answers"
    }
  ],
  "json_url": "https://handbook.dnacalc.com/api/functions/FUNC.SLOPE.json",
  "name": "SLOPE",
  "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- **[RSQ](FUNC.RSQ.md)** is the goodness of fit of the same line, and satisfies\n  `RSQ(y,x) = SLOPE(y,x) * SLOPE(x,y)`. A large slope with a small `RSQ` is a strong-looking\n  relationship that explains nothing; the two functions are meant to be read together.\n- **[CORREL](FUNC.CORREL.md) and [PEARSON](FUNC.PEARSON.md)** give `r`, from which\n  `b = r * s_y / s_x`.\n- **[STEYX](FUNC.STEYX.md)** is the standard error of the same regression — the scale of the\n  residuals `SLOPE` leaves behind.\n- **[LINEST](FUNC.LINEST.md)** returns the same slope as part of a full regression, with standard\n  errors and diagnostics, and generalises to multiple predictors. `SLOPE` is the one-predictor\n  special case with everything else discarded. **[TREND](FUNC.TREND.md)** and\n  **[FORECAST.LINEAR](FUNC.FORECAST.LINEAR.md)** evaluate the same line at new `x` values.\n- **[FORECAST](FUNC.FORECAST.md)** is the legacy name of `FORECAST.LINEAR` and uses the same\n  fit.\n- Readers confuse `SLOPE` with the chart trendline coefficient. They are the same quantity\n  mathematically; whether Excel computes them by the same code path is not something this page\n  claims.\n\n\n",
    "how-to-implement": "\n### Numerical notes\n\n\n`SLOPE` is the function where Excel's statistical accuracy was fought over in public, and the\nargument is entirely about **which algebraically-equal formula you evaluate**.\n\n**Two forms, one answer, very different error.** The textbook one-pass form is\n\n    b  =  ( n*sum(x*y) - sum(x)*sum(y) )  /  ( n*sum(x^2) - sum(x)^2 )\n\nIt needs one pass and no stored data, which is why every statistics textbook of the punched-card\nera printed it. It is also catastrophically unstable: when the `x` values are large relative to\ntheir spread, `n*sum(x^2)` and `sum(x)^2` are two nearly-equal large numbers whose difference is\nthe small quantity `Sxx`. Subtracting them destroys leading digits in proportion to\n`(xbar/s_x)^2`. For `x` values around a million with a spread of one, the denominator can lose\nevery significant digit it had, and the computed `Sxx` can even come out **negative** — which is\nimpossible for a sum of squares and is the signature by which this bug is recognised.\n\n    xbar  =  sum(x)/n ;   Sxx = sum (x - xbar)^2 ;   Sxy = sum (x - xbar)(y - ybar)\n\ncomputes each deviation before squaring, so no large cancellation ever occurs. Its error grows\nwith the condition number of the problem rather than with its square. Chan, Golub and LeVeque\n(1983) give the error analysis for exactly this comparison, and their recommendation — use the\ntwo-pass form, or Welford-style updating if one pass is required — is the settled answer.\n\n**The published record on Excel.** McCullough and Wilson's assessments of Excel's statistical\nprocedures, running from 1999 through the 2000s in *Computational Statistics & Data Analysis*,\nand Knüsel's work on the same subject, documented failures of exactly this kind in Excel's\nregression and variance functions, and recorded that the algorithms were changed at Excel 2003.\nWelinder's work on Gnumeric's statistical functions is the other standing reference on Excel's\nstatistical numerics and is legitimate to consult. **What none of that licenses is a statement on\nthis page about what Excel's `SLOPE` does internally today.** The Handbook does not assert\nExcel's algorithm. What it asserts is that the two forms are distinguishable by measurement, and\nthat the measurement has not been made here.\n\n**Residual hazards in the good form.** The two-pass form is not immune, only far better:\n\n- The mean is accumulated by naive left-to-right summation, so `xbar` itself carries an error\n  growing with `n`. Compensated or pairwise summation would bound it by a constant.\n- `Sxx` and `Sxy` are accumulated naively too. `Sxx` has non-negative terms and is therefore\n  well-conditioned; `Sxy` has mixed signs and can cancel badly when the relationship is weak —\n  which is exactly when the slope is near zero and its relative error is worst. A near-zero slope\n  from a large noisy sample is the least trustworthy answer this function gives.\n- The final division is a single correctly-rounded operation and contributes at most half an ulp.\n- The `Sxx == 0` test is an exact comparison against zero, not a tolerance. Data whose `x` spread\n  is real but tiny passes the test and yields an enormous slope rather than an error. There is no\n  right answer here; there is a choice, and the choice is exactness.\n\n**Reproducibility.** Summation order is part of the answer. Two implementations that both use the\ncentred form, and both are correct, will disagree in the last bits if they traverse the data in\ndifferent orders or vectorise differently. Nothing about the mathematics fixes those bits.\n\n\n",
    "quirks": "\n### Result and edge cases\n\n\nReturns `Number`.\n\n- **All `x` equal.** `Sxx = 0` and the answer is `#DIV/0!`. Note this is checked on the computed\n  `Sxx`, not on a distinctness test of the `x` values, so it also triggers when the `x` values\n  differ but their centred squares underflow to zero.\n- **All `y` equal.** `Sxy = 0` and the slope is exactly `0` — a valid answer, not an error.\n- **Unequal element counts.** `#N/A`, documented and implemented.\n- **Errors in either argument** propagate as themselves.\n- **Two-dimensional arguments** are flattened row-major before pairing.\n\n\n",
    "sources": "- Microsoft, *SLOPE function* —\n  <https://support.microsoft.com/en-us/office/slope-function-11fb8f97-3117-4813-98aa-61d7e01276b9>\n  (signature and argument order, the stated equation, the ignore-text-and-logicals rule for\n  arrays, and the documented `#N/A` and `#DIV/0!` conditions). Retrieval was blocked by the\n  upstream host for this page; the documented behaviour above is stated as documented behaviour\n  and should be re-checked against the page.\n- T. F. Chan, G. H. Golub and R. J. LeVeque, \"Algorithms for Computing the Sample Variance:\n  Analysis and Recommendations\", *The American Statistician* 37(3), 1983, pp. 242–247 — the\n  error analysis behind the two-pass recommendation.\n- B. D. McCullough and B. Wilson, \"On the accuracy of statistical procedures in Microsoft Excel\",\n  *Computational Statistics & Data Analysis*, 1999, and the follow-up assessments through 2005;\n  L. Knüsel's parallel work — the published record of Excel's statistical accuracy and of the\n  algorithm change at Excel 2003. M. Welinder's work on Gnumeric's statistical functions is the\n  other standing reference on this subject.\n- N. J. Higham, *Accuracy and Stability of Numerical Algorithms*, 2nd ed. — summation error\n  bounds and the conditioning discussion underlying the residual-hazards list.\n- Handbook evidence record `EV-MISC-0008` (rendered beside this page).\n- Handbook `data/functions/FUNC.SLOPE.json`, `data/presence/FUNC.SLOPE.json`.\n\n",
    "version-differences": "The recorded environments below distinguish a reading from a same-input comparison. Counts describe captured inputs in each environment; overlapping captures and comparisons are not totals of unique worksheet calls.\n\n| Excel 16.0 build | Platform and CPU | Captured inputs |\n|---|---|---:|\n| 20131 | Windows, bitness not recorded, AMD Ryzen 7 4800H with Radeon Graphics | 4 |\n\nThe record contains no same-input comparison between these environments. Reading different inputs on different builds does not establish either a version change or cross-build agreement.\n\n[Recorded environments and comparison details](https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.SLOPE.json).",
    "what-it-does": "\n`SLOPE(known_y's, known_x's)` returns the slope `b` of the **ordinary least squares** line fitted\nthrough the paired data — the unique `b` minimising the sum of squared vertical residuals.\n\nFor pairs `(x_1, y_1), …, (x_n, y_n)`, write the means `xbar` and `ybar` and the centred sums\n\n    Sxx  =  sum (x_i - xbar)^2\n    Sxy  =  sum (x_i - xbar)(y_i - ybar)\n\nThen\n\n    SLOPE  =  b  =  Sxy / Sxx\n\nThis is the stationary point of `sum (y_i - a - b*x_i)^2` in `b`, and it is the entire content of\nthe function. Three equivalent readings are worth carrying, because each explains a different\nedge case:\n\n1. **`b = Sxy / Sxx`** — a ratio of second moments. Undefined precisely when `Sxx = 0`, that is,\n   when every `x_i` is the same. A vertical scatter has no least-squares slope, which is why the\n   documented failure there is `#DIV/0!` rather than a large number.\n2. **`b = r * (s_y / s_x)`** — the correlation scaled by the ratio of standard deviations. This\n   is the reading that shows `SLOPE` carries **units**: `b` is in units of `y` per unit of `x`,\n   unlike `r` and [RSQ](FUNC.RSQ.md), which are dimensionless.\n3. **`b = COVARIANCE.P(y, x) / VAR.P(x)`** — and equally with the sample forms, since the `n`\n   and `n-1` factors cancel between numerator and denominator. `SLOPE` is a ratio in which the\n   population/sample distinction is invisible.\n\n`SLOPE` is **not symmetric in its arguments**. The least-squares line of `y` on `x` minimises\nvertical distances; the line of `x` on `y` minimises horizontal ones, and they are different\nlines unless the fit is perfect. The relation between them is\n`SLOPE(y,x) * SLOPE(x,y) = r^2`, which is [RSQ](FUNC.RSQ.md) — so swapping the arguments does not\ngive the reciprocal, it gives the reciprocal *shrunk by* `r^2`. This is regression to the mean,\nstated as an identity.\n\nTogether with [INTERCEPT](FUNC.INTERCEPT.md), which returns `a = ybar - b*xbar`, the pair\ndetermines the fitted line. The line always passes through `(xbar, ybar)`.\n\n\n\n### Arguments\n\n\n| Argument | Meaning | Required |\n|---|---|---|\n| `known_y's` | The dependent values — the ones being explained. First. | yes |\n| `known_x's` | The independent values. Second. | yes |\n\n**The `y` argument comes first.** This is the single most common error at the call site, because\nit reads backwards against `(x, y)` habit and against the way charts are labelled. Getting it\nwrong does not produce an error — it produces `1/b` shrunk by `r^2`, a plausible number in the\nwrong units.\n\nBoth arguments are consumed by scanning. Pairing is **positional**, in row-major order over each\nargument; the two need not have the same shape, only the same number of elements.\n\n"
  },
  "signature": {
    "display": "SLOPE(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": "Slope of the least-squares line through the known points",
        "short_source": "dna-calc-own"
      },
      "docs": {
        "english_description": "Returns the slope of the linear regression line",
        "microsoft_url": "https://support.microsoft.com/en-us/office/slope-function-11fb8f97-3117-4813-98aa-61d7e01276b9"
      },
      "entry_kind": "built_in_function",
      "localized_family_names": null,
      "localized_names": [
        {
          "locale": "ar-SA",
          "name": "SLOPE"
        },
        {
          "locale": "bg-BG",
          "name": "SLOPE"
        },
        {
          "locale": "cs-CZ",
          "name": "SLOPE"
        },
        {
          "locale": "da-DK",
          "name": "STIGNING"
        },
        {
          "locale": "de-DE",
          "name": "SLOPE"
        },
        {
          "locale": "el-GR",
          "name": "SLOPE"
        },
        {
          "locale": "en-AU",
          "name": "SLOPE"
        },
        {
          "locale": "en-GB",
          "name": "SLOPE"
        },
        {
          "locale": "en-US",
          "name": "SLOPE"
        },
        {
          "locale": "es-ES",
          "name": "PENDIENTE"
        },
        {
          "locale": "et-EE",
          "name": "SLOPE"
        },
        {
          "locale": "fi-FI",
          "name": "KULMAKERROIN"
        },
        {
          "locale": "fr-FR",
          "name": "PENTE*"
        },
        {
          "locale": "he-IL",
          "name": "SLOPE"
        },
        {
          "locale": "hr-HR",
          "name": "SLOPE"
        },
        {
          "locale": "hu-HU",
          "name": "MEREDEKSÉG"
        },
        {
          "locale": "id-ID",
          "name": "SLOPE"
        },
        {
          "locale": "it-IT",
          "name": "SLOPE"
        },
        {
          "locale": "ja-JP",
          "name": "SLOPE"
        },
        {
          "locale": "ko-KR",
          "name": "SLOPE"
        },
        {
          "locale": "lt-LT",
          "name": "SLOPE"
        },
        {
          "locale": "lv-LV",
          "name": "SLOPE"
        },
        {
          "locale": "nb-NO",
          "name": "BAKKE"
        },
        {
          "locale": "nl-NL",
          "name": "RICHTING"
        },
        {
          "locale": "pl-PL",
          "name": "NACHYLENIE"
        },
        {
          "locale": "pt-BR",
          "name": "SLOPE"
        },
        {
          "locale": "pt-PT",
          "name": "DECLIVE"
        },
        {
          "locale": "ro-RO",
          "name": "SLOPE"
        },
        {
          "locale": "ru-RU",
          "name": "НАКЛОН"
        },
        {
          "locale": "sk-SK",
          "name": "SLOPE"
        },
        {
          "locale": "sl-SI",
          "name": "SLOPE"
        },
        {
          "locale": "sr-Latn-RS",
          "name": "SLOPE"
        },
        {
          "locale": "sv-SE",
          "name": "LUTNING"
        },
        {
          "locale": "th-TH",
          "name": "SLOPE"
        },
        {
          "locale": "tr-TR",
          "name": "EĞİM işlevi"
        },
        {
          "locale": "uk-UA",
          "name": "SLOPE"
        },
        {
          "locale": "vi-VN",
          "name": "SLOPE"
        },
        {
          "locale": "zh-CN",
          "name": "SLOPE"
        },
        {
          "locale": "zh-HK",
          "name": "SLOPE"
        },
        {
          "locale": "zh-TW",
          "name": "SLOPE"
        }
      ],
      "signature": {
        "display": "SLOPE(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": "SLOPE",
      "version_marker": null,
      "xlcall": {
        "code": "315",
        "symbol": "xlfSlope"
      }
    },
    "microsoft": "https://support.microsoft.com/en-us/office/slope-function-11fb8f97-3117-4813-98aa-61d7e01276b9"
  },
  "try_it": {
    "formula": "=SLOPE({2;4;7},{1;2;3})"
  },
  "url": "https://handbook.dnacalc.com/functions/SLOPE.html",
  "variants": [],
  "versions": [
    {
      "behaviour": "4 captured inputs are indexed for this environment. Capture dates: 2026-07-12 to 2026-07-12. This is a reading count, not a comparison with another build.",
      "excel_build": "16.0 build 20131",
      "platform": "Windows, bitness not recorded, AMD Ryzen 7 4800H with Radeon Graphics",
      "sources": [
        "https://github.com/DnaCalc/ExcelFunctionsHandbook/blob/5dc75391aa5125ccc5abdb095da85950980d6fd8/content/evidence/environments/FUNC.SLOPE.json"
      ]
    }
  ]
}