Logo

SQL Server CHISQ_INV_RT Function

Updated 2023-11-02 21:15:14.397000

Description

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

Syntax

SELECT [westclintech].[wct].[CHISQ_INV_RT](
  <@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 = 1 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_RT(   0.95, --@Probability
                           10    --@Degrees_freedom
                       ) as [X];

This produces the following result.

X
3.94029913611906

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

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

This produces the following result.

XX
3.940299136119063.94029913611906

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_RT(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
10.0001570878579097020.003932140000019530.01579077409343120.1015310442676210.4549364231195721.323303696931462.70554345409543.841458820694126.63489660102121
20.02010067170700290.1025865887751010.2107210313156530.5753641449035621.386294361119892.772588722239784.605170185988095.991464547107989.21034037197618
30.1148318018991170.3518463177492720.5843743741551831.212532903045672.365973884375344.108344935632326.251388631170337.8147279032511811.3448667301444
40.2971094805065320.7107230213973241.063623216779221.922557526229553.356693980033325.385269057779397.779440339734869.4877290367811513.2767041359876
50.5542980767282771.145476226061771.610307986962322.674602809432164.351460191095536.625679763829259.2363568997811211.070497693516415.086272469389
60.8720903301565871.635382894327912.204130656498643.454598835721045.348120627447127.8408041205851210.644640675668412.59158724374416.8118938297709
71.239042305567932.167349909298062.833106917815344.254852183546526.345811195521529.0371475479081412.017036623780514.067140449340218.4753069065824
81.646497372690772.732636793499663.489539125649825.070640423800187.3441214977017810.218854970246813.361566136511715.507313055865520.0902350296632
92.087900735870733.325112843066814.16815900814615.898825882969978.3428326922529511.388751440470414.683656573259816.918977604620521.6659943334619
102.558212160187213.940299136119064.865182051925336.737200771954649.3418177655919612.548861396889415.987179172105318.307038053275123.2092511589543
113.053484106640684.574813079322225.577784789799857.5841427854412810.340998074391813.700692746011517.275008517500119.675137572682524.7249703113183
123.570568970604395.226029488392646.303796059584328.4384187661357911.340322377424114.845403671040218.549347786703321.026069817483126.2169673055359
134.10691547150445.891864337709857.041504580095459.2990655298521312.339755882563915.983906216312119.811929307127622.362032494826927.6882496104571
144.660425062657776.570631383789357.7895336097523710.165313805377113.339274149099517.116933596000121.064144212997123.684791304840629.1412377406728
155.229348884098967.260943927670038.5467562417045411.03653765909114.338859510956718.245085602415122.307129581578724.995790139728630.5779141668925
165.812212470134977.961645572378559.31223635379611.91221969741615.338498885001619.368860220584523.541828923096126.296227604864231.9999269088152
176.407759777738948.6717602046700810.085186334619312.79192642383216.338182377392520.488676238391524.769035343901427.587111638275333.4086636050046
187.014910901172589.3904550806889910.864936116508913.675290350398317.337902368740821.604889795728225.989423082637228.869299430392634.8053057347051
197.6327296475714710.11701306385911.650910032126914.561996731420218.337652896756522.717806744199827.203571029356830.143527205646236.1908691292701
208.260398332546410.850811394182612.442609210450115.451773539047719.337429229428323.827692043030928.411980584305631.410432844230937.5662347866251
229.5424923387850812.338014578790714.04149318942217.239619404759121.337044807672726.03926502816530.81328234395333.924438471443840.2893604375938
2410.856361475532313.848425027170215.658684052512819.037252529523623.336726306089628.241150025528733.196244288628236.415028501807342.9798201393516
2612.198146923505615.379156583261817.291884989738820.843431103075425.336458117477330.434565428615835.563171271923538.8851386598345.6416826662831
2813.564709754618816.927875044422518.939242371917522.65715567064627.336229198689832.620494099025537.91592254469741.337138151427448.2782357703155
3014.953456528455518.492660981953520.599234614585424.477607664886329.336031516661734.799742519140940.256023738711843.772971825742250.8921813115171
4022.164261252975226.509303196693229.050522930545633.660294922984539.335344846611545.616013618942151.805057213317555.75847927888763.6907397515644
5029.706682698841334.764251683501837.688648393978642.94208381090649.334936733977256.333604922132363.167121005726367.504806549541176.1538912490126
6037.484851529803843.187958453989746.458888300203452.293816583775259.334666276442666.98146110761974.397005719368579.081944487848788.3794189014493

See Also

CHISQ_DIST - Lower chi-squared distribution

CHISQ_INV - Inverse of the chi-squared distribution

CHISQ_DIST_RT - Upper chi-squared distribution

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