Logo

SQL Server CHISQ_INV Function

Updated 2023-11-02 21:11:42.813000

Description

Use the scalar function CHISQ_INV to calculate the inverse of the left-tailed probability of a chi-squared distribution.

Syntax

SELECT [westclintech].[wct].[CHISQ_INV](
  <@Probability, float,>
 ,<@Degrees_freedom, float,>)

Arguments

@Probability

The value of interest to be evaluated. @Probability must be of a type float or of type that intrinsically converts to float.

@Degrees_freedom

The number of degrees freedom. @Degrees_freedom must be of a type float or of a type that intrinsically converts to float.

Return Type

float

Remarks

0 ≤ @Probability ≤ 1.

0 < @Degrees_freedom.

If @Probability = 0 then 0 is returned.

Examples

In this example we calculate inverse of the chi-squared distribution with probability 0.975 and 10 degrees of freedom.

SELECT wct.CHISQ_INV(   0.95, --@Probability
                        10    --@Degrees_freedom
                    ) as [X];

This produces the following result.

X
18.3070380532751

The chi-squared distribution is a special case of the gamma distribution.

SELECT wct.CHISQ_INV(p, df) as [X],
       wct.INVGAMMAP(p, 0.5 * df) * 2 as [X]
FROM
(
    VALUES
        (0.95, 10)
) n (p, df);

This produces the following result.

XX
18.307038053275118.3070380532751

This example returns a table of critical values for the distribution.

SELECT df,
       [0.99],
       [0.95],
       [0.90],
       [0.75],
       [0.50],
       [0.25],
       [0.10],
       [0.05],
       [0.01]
FROM
(
    SELECT df,
           p,
           wct.CHISQ_INV(p, df) as x
    FROM
    (
        VALUES
            (0.99),
            (0.95),
            (0.90),
            (0.75),
            (0.50),
            (0.25),
            (0.10),
            (0.05),
            (0.01)
    ) n (p)
        CROSS APPLY
    (
        VALUES
            (1),
            (2),
            (3),
            (4),
            (5),
            (6),
            (7),
            (8),
            (9),
            (10),
            (11),
            (12),
            (13),
            (14),
            (15),
            (16),
            (17),
            (18),
            (19),
            (20),
            (22),
            (24),
            (26),
            (28),
            (30),
            (40),
            (50),
            (60)
    ) m (df)
) p
PIVOT
(
    max(x)
    FOR p IN ([0.99], [0.95], [0.90], [0.75], [0.50], [0.25], [0.10], [0.05], [0.01])
) d;

This produces the following result.

df0.990.950.900.750.500.250.100.050.01
16.634896601021213.841458820694122.70554345409541.323303696931460.4549364231195720.1015310442676210.01579077409343120.003932140000019520.000157087857909702
29.210340371976185.991464547107984.605170185988092.772588722239781.386294361119890.5753641449035620.2107210313156530.1025865887751010.0201006717070029
311.34486673014447.814727903251186.251388631170334.108344935632322.365973884375341.212532903045670.5843743741551830.3518463177492720.114831801899117
413.27670413598769.487729036781157.779440339734865.385269057779393.356693980033321.922557526229551.063623216779220.7107230213973240.297109480506532
515.08627246938911.07049769351649.236356899781126.625679763829254.351460191095532.674602809432161.610307986962321.145476226061770.554298076728277
616.811893829770912.59158724374410.64464067566847.840804120585125.348120627447123.454598835721042.204130656498641.635382894327910.872090330156586
718.475306906582414.067140449340212.01703662378059.037147547908146.345811195521524.254852183546522.833106917815342.167349909298061.23904230556793
820.090235029663215.507313055865513.361566136511710.21885497024687.344121497701785.070640423800183.489539125649822.732636793499661.64649737269077
921.665994333461916.918977604620514.683656573259811.38875144047048.342832692252955.898825882969974.168159008146113.325112843066812.08790073587073
1023.209251158954318.307038053275115.987179172105312.54886139688949.341817765591966.737200771954644.865182051925333.940299136119062.55821216018721
1124.724970311318319.675137572682517.275008517500113.700692746011510.34099807439187.584142785441285.577784789799854.574813079322223.05348410664068
1226.216967305535921.026069817483118.549347786703314.845403671040211.34032237742418.438418766135796.303796059584325.226029488392643.57056897060439
1327.688249610457122.362032494826919.811929307127615.983906216312112.33975588256399.299065529852137.041504580095465.891864337709844.1069154715044
1429.141237740672823.684791304840621.064144212997117.116933596000113.339274149099510.16531380537717.789533609752376.570631383789354.66042506265777
1530.577914166892524.995790139728622.307129581578718.245085602415114.338859510956711.0365376590918.546756241704557.260943927670035.22934888409896
1631.999926908815226.296227604864223.541828923096119.368860220584515.338498885001611.9122196974169.3122363537967.961645572378555.81221247013496
1733.408663605004627.587111638275324.769035343901420.488676238391516.338182377392512.79192642383210.08518633461938.671760204670086.40775977773894
1834.805305734705128.869299430392625.989423082637221.604889795728217.337902368740813.675290350398310.86493611650899.390455080688987.01491090117258
1936.190869129270130.143527205646227.203571029356822.717806744199818.337652896756514.561996731420211.650910032126910.1170130638597.63272964757147
2037.566234786625131.410432844230928.411980584305623.827692043030919.337429229428315.451773539047712.442609210450110.85081139418268.2603983325464
2240.289360437593833.924438471443830.81328234395326.03926502816521.337044807672717.239619404759114.04149318942212.33801457879079.54249233878508
2442.979820139351636.415028501807333.196244288628228.241150025528723.336726306089619.037252529523615.658684052512813.848425027170210.8563614755323
2645.641682666283138.8851386598335.563171271923530.434565428615825.336458117477320.843431103075417.291884989738815.379156583261712.1981469235056
2848.278235770315541.337138151427437.91592254469732.620494099025527.336229198689822.65715567064618.939242371917516.927875044422513.5647097546188
3050.892181311517143.772971825742240.256023738711834.799742519140929.336031516661724.477607664886320.599234614585418.492660981953514.9534565284554
4063.690739751564455.75847927888751.805057213317545.616013618942139.335344846611533.660294922984529.050522930545526.509303196693122.1642612529752
5076.153891249012667.504806549541163.167121005726356.333604922132349.334936733977242.94208381090637.688648393978634.764251683501829.7066826988413
6088.379418901449379.081944487848774.397005719368566.98146110761959.334666276442652.293816583775246.458888300203443.187958453989837.4848515298038

See Also

CHISQ_DIST - Lower chi-squared distribution

CHISQ_INV_RT - Calculate the inverse of the right-tailed probability of a chi-squared distribution.

CHISQ_DIST_RT - Upper chi-squared distribution

INVGAMMAP - Calculate the inverse of the incomplete gamma functionP(a,x).