WMPSR
Updated 2023-11-06 16:54:56.330000
Syntax
SELECT [westclintech].[wct].[WMPSR](
<@InputData_RangeQuery, nvarchar(max),>
,<@RV, nvarchar(4000),>)
Description
Use the table-valued function WMPSR to calculate the Wilcoxon matched-pair signed-rank test.
Arguments
@RV
the value to be returned by the function. Use the following values:
{
"columns": [
{
"field": "RV"
},
{
"field": "Description"
}
],
"rows": [
{
"RV": "'W'",
"Description": "the test statistic"
},
{
"RV": "'Z'",
"Description": "the z test statistic (used in the normal approximation of the p-value)"
},
{
"RV": "'PL'",
"Description": "the ‘less than’ p-value"
},
{
"RV": "'PG'",
"Description": "the ‘greater than’ p-value"
},
{
"RV": "'P2'",
"Description": "the 2-sided p-value"
}
]
}
@InputData_RangeQuery
a T-SQL statement, as a string, that specifies the matched pairs passed into the function.
Return Type
float
Remarks
The function is insensitive to order; it does not matter what order the pairs are passed in.
Ranks are calculated based on the absolute value in the difference of a pair. If we call the first value in the pair x and the second y, then the rank is calculated based on ABS(x-y)
Pairs where x = y are not included in the rank calculation.
Ranks ties are calculated as the average of the rank in the interval occupied by the tie.
Once the ranks are calculated, the rank is multiplied by SIGN(x-y). The W-statistic is the sum of absolute values where SIGN(x-y) = 1.
If the number of ranked pairs is less than 50, then the exact p-value is calculated using the PSIGNRANK function, otherwise the NORMSDIST function is used.
Examples
SELECT x,
y
INTO #w
FROM
(
SELECT 5260,
3910
UNION ALL
SELECT 5470,
4220
UNION ALL
SELECT 5640,
3885
UNION ALL
SELECT 6180,
5160
UNION ALL
SELECT 6390,
5645
UNION ALL
SELECT 6515,
4680
UNION ALL
SELECT 6805,
5265
UNION ALL
SELECT 7515,
5975
UNION ALL
SELECT 7515,
6790
UNION ALL
SELECT 8230,
6900
UNION ALL
SELECT 8770,
7335
) w(x, y);
SELECT p.stat,
wct.WMPSR('SELECT x,y FROM #w', p.stat) as stat_value
FROM
(
SELECT 'W'
UNION ALL
SELECT 'Z'
UNION ALL
SELECT 'PL'
UNION ALL
SELECT 'PG'
UNION ALL
SELECT 'P2'
) p(stat);
This produces the following result.
{"columns":[{"field":"stat"},{"field":"stat_value","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"stat":"W","stat_value":"66"},{"stat":"Z","stat_value":"2.93550859009007"},{"stat":"PL","stat_value":"0.00166500695587299"},{"stat":"PG","stat_value":"0.998334993044127"},{"stat":"P2","stat_value":"0.00333001391174598"}]}