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.
| X | X |
|---|---|
| 3.94029913611906 | 3.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.
| df | 0.99 | 0.95 | 0.90 | 0.75 | 0.50 | 0.25 | 0.10 | 0.05 | 0.01 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.000157087857909702 | 0.00393214000001953 | 0.0157907740934312 | 0.101531044267621 | 0.454936423119572 | 1.32330369693146 | 2.7055434540954 | 3.84145882069412 | 6.63489660102121 |
| 2 | 0.0201006717070029 | 0.102586588775101 | 0.210721031315653 | 0.575364144903562 | 1.38629436111989 | 2.77258872223978 | 4.60517018598809 | 5.99146454710798 | 9.21034037197618 |
| 3 | 0.114831801899117 | 0.351846317749272 | 0.584374374155183 | 1.21253290304567 | 2.36597388437534 | 4.10834493563232 | 6.25138863117033 | 7.81472790325118 | 11.3448667301444 |
| 4 | 0.297109480506532 | 0.710723021397324 | 1.06362321677922 | 1.92255752622955 | 3.35669398003332 | 5.38526905777939 | 7.77944033973486 | 9.48772903678115 | 13.2767041359876 |
| 5 | 0.554298076728277 | 1.14547622606177 | 1.61030798696232 | 2.67460280943216 | 4.35146019109553 | 6.62567976382925 | 9.23635689978112 | 11.0704976935164 | 15.086272469389 |
| 6 | 0.872090330156587 | 1.63538289432791 | 2.20413065649864 | 3.45459883572104 | 5.34812062744712 | 7.84080412058512 | 10.6446406756684 | 12.591587243744 | 16.8118938297709 |
| 7 | 1.23904230556793 | 2.16734990929806 | 2.83310691781534 | 4.25485218354652 | 6.34581119552152 | 9.03714754790814 | 12.0170366237805 | 14.0671404493402 | 18.4753069065824 |
| 8 | 1.64649737269077 | 2.73263679349966 | 3.48953912564982 | 5.07064042380018 | 7.34412149770178 | 10.2188549702468 | 13.3615661365117 | 15.5073130558655 | 20.0902350296632 |
| 9 | 2.08790073587073 | 3.32511284306681 | 4.1681590081461 | 5.89882588296997 | 8.34283269225295 | 11.3887514404704 | 14.6836565732598 | 16.9189776046205 | 21.6659943334619 |
| 10 | 2.55821216018721 | 3.94029913611906 | 4.86518205192533 | 6.73720077195464 | 9.34181776559196 | 12.5488613968894 | 15.9871791721053 | 18.3070380532751 | 23.2092511589543 |
| 11 | 3.05348410664068 | 4.57481307932222 | 5.57778478979985 | 7.58414278544128 | 10.3409980743918 | 13.7006927460115 | 17.2750085175001 | 19.6751375726825 | 24.7249703113183 |
| 12 | 3.57056897060439 | 5.22602948839264 | 6.30379605958432 | 8.43841876613579 | 11.3403223774241 | 14.8454036710402 | 18.5493477867033 | 21.0260698174831 | 26.2169673055359 |
| 13 | 4.1069154715044 | 5.89186433770985 | 7.04150458009545 | 9.29906552985213 | 12.3397558825639 | 15.9839062163121 | 19.8119293071276 | 22.3620324948269 | 27.6882496104571 |
| 14 | 4.66042506265777 | 6.57063138378935 | 7.78953360975237 | 10.1653138053771 | 13.3392741490995 | 17.1169335960001 | 21.0641442129971 | 23.6847913048406 | 29.1412377406728 |
| 15 | 5.22934888409896 | 7.26094392767003 | 8.54675624170454 | 11.036537659091 | 14.3388595109567 | 18.2450856024151 | 22.3071295815787 | 24.9957901397286 | 30.5779141668925 |
| 16 | 5.81221247013497 | 7.96164557237855 | 9.312236353796 | 11.912219697416 | 15.3384988850016 | 19.3688602205845 | 23.5418289230961 | 26.2962276048642 | 31.9999269088152 |
| 17 | 6.40775977773894 | 8.67176020467008 | 10.0851863346193 | 12.791926423832 | 16.3381823773925 | 20.4886762383915 | 24.7690353439014 | 27.5871116382753 | 33.4086636050046 |
| 18 | 7.01491090117258 | 9.39045508068899 | 10.8649361165089 | 13.6752903503983 | 17.3379023687408 | 21.6048897957282 | 25.9894230826372 | 28.8692994303926 | 34.8053057347051 |
| 19 | 7.63272964757147 | 10.117013063859 | 11.6509100321269 | 14.5619967314202 | 18.3376528967565 | 22.7178067441998 | 27.2035710293568 | 30.1435272056462 | 36.1908691292701 |
| 20 | 8.2603983325464 | 10.8508113941826 | 12.4426092104501 | 15.4517735390477 | 19.3374292294283 | 23.8276920430309 | 28.4119805843056 | 31.4104328442309 | 37.5662347866251 |
| 22 | 9.54249233878508 | 12.3380145787907 | 14.041493189422 | 17.2396194047591 | 21.3370448076727 | 26.039265028165 | 30.813282343953 | 33.9244384714438 | 40.2893604375938 |
| 24 | 10.8563614755323 | 13.8484250271702 | 15.6586840525128 | 19.0372525295236 | 23.3367263060896 | 28.2411500255287 | 33.1962442886282 | 36.4150285018073 | 42.9798201393516 |
| 26 | 12.1981469235056 | 15.3791565832618 | 17.2918849897388 | 20.8434311030754 | 25.3364581174773 | 30.4345654286158 | 35.5631712719235 | 38.88513865983 | 45.6416826662831 |
| 28 | 13.5647097546188 | 16.9278750444225 | 18.9392423719175 | 22.657155670646 | 27.3362291986898 | 32.6204940990255 | 37.915922544697 | 41.3371381514274 | 48.2782357703155 |
| 30 | 14.9534565284555 | 18.4926609819535 | 20.5992346145854 | 24.4776076648863 | 29.3360315166617 | 34.7997425191409 | 40.2560237387118 | 43.7729718257422 | 50.8921813115171 |
| 40 | 22.1642612529752 | 26.5093031966932 | 29.0505229305456 | 33.6602949229845 | 39.3353448466115 | 45.6160136189421 | 51.8050572133175 | 55.758479278887 | 63.6907397515644 |
| 50 | 29.7066826988413 | 34.7642516835018 | 37.6886483939786 | 42.942083810906 | 49.3349367339772 | 56.3336049221323 | 63.1671210057263 | 67.5048065495411 | 76.1538912490126 |
| 60 | 37.4848515298038 | 43.1879584539897 | 46.4588883002034 | 52.2938165837752 | 59.3346662764426 | 66.981461107619 | 74.3970057193685 | 79.0819444878487 | 88.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).