Logo

INTERCEPT_q

Updated 2023-11-01 12:41:36.987000

Syntax

SELECT [westclintech].[wct].[INTERCEPT_q] (
   <@Known_y_Known_x_RangeQuery, nvarchar(4000),>)

Description

Use the scalar function INTERCEPT_q to calculate the point at which a line will intersect the y-axis by using existing x-values and y-values. The y-intercept is the value of the point at which intersects the line at x = 0. In linear equations that are in the slope intercept from of y = mx + b, the value of b is the y-intercept. The equation for intercept is:

\\ \bar{a}=\bar{y}-b\bar{x} \\ \text{where the slope,}\; b\text{, is calculated} \\ b=\frac{\sum(x-\bar{x})(y-\bar{y})}{\sum(x-\bar{x})^2}

Arguments

@Known_y_Known_x_RangeQuery

the select statement, as text, used to determine the known y- and x-values to be used in the INTERCEPT_q function.

Return Type

float

Remarks

If the number of y-data points is not equal to the number of x-data points, INTERCEPT will return an error.

No GROUP BY is required for this function even though it produces aggregated results.

Examples

CREATE TABLE #i1

(

    [y] [float] NOT NULL,

    [x] [float] NOT NULL

);

INSERT INTO #i1

VALUES

(-4.5, -1);

INSERT INTO #i1

VALUES

(0, 2);

INSERT INTO #i1

VALUES

(-9, -4);

INSERT INTO #i1

VALUES

(4.5, 5);

INSERT INTO #i1

VALUES

(-13.5, -7);

SELECT wct.INTERCEPT_q('SELECT y, x from #i1');

This produces the following result

{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"-3"}]}

See Also

SLOPE - slope of the linear regression through the data points in the known x-values and y-values

COVAR - the average of the products of the deviations in known x- and y-values

TREND - for simpler queries

FORECAST - The predicted y-value for a given x-value

GROWTH - calculate predicted exponential growth using existing values

STEYX - the standard error of the predicted y-value for each x in the regression

RSQ - the Pearson product moment correlation coefficient through data points in known-y’s and known-x’s

CORREL - Aggregate function to calculate the correlation coefficient

PEARSON - Aggregate function to calculate the correlation coefficient

INTERCEPT - the point at which a line will intersect the y-axis by using existing x-values and y-values