1
+ from collections import namedtuple
1
2
import numpy as np
2
3
import pandas as pd
3
4
7
8
from scipy .stats import friedmanchisquare
8
9
9
10
10
- def compute_friedmanchisquare (table ):
11
- '''
11
+ TestResult = namedtuple ("TestResult" , ["statistic" , "p_value" ])
12
+
13
+
14
+ def compute_friedmanchisquare (table : pd .DataFrame ) -> TestResult :
15
+ """ Compute Friedman test for repeated samples
12
16
Example:
13
17
- n wine judges each rate k different wines. Are any of the k wines
14
18
ranked consistently higher or lower than the others?
@@ -19,21 +23,17 @@ def compute_friedmanchisquare(table):
19
23
This will output a statistic and a p-value
20
24
SciPy does the following:
21
25
- k: is the number of parameters passed to the function
22
- - n: is the lenght of each array passed to the function
26
+ - n: is the length of each array passed to the function
23
27
The two options for the given table are:
24
- - k is the datasets: table['mean'].values) .tolist()
25
- - k is the calibration methods: table['mean'].T.values) .tolist()
26
- '''
28
+ - k is the datasets: table['mean'].values.tolist()
29
+ - k is the calibration methods: table['mean'].T.values.tolist()
30
+ """
27
31
if table .shape [1 ] < 3 :
28
- print ('Friedman test not appropiate for less than 3 methods' )
29
-
30
- class Ftest ():
31
- def __init__ (self , statistic , pvalue ):
32
- self .statistic = statistic
33
- self .pvalue = pvalue
34
- return Ftest (np .nan , np .nan )
32
+ print ('Friedman test not appropriate for less than 3 methods' )
33
+ return TestResult (np .nan , np .nan )
35
34
36
- return friedmanchisquare (* (table .T .values ).tolist ())
35
+ statistic , p = friedmanchisquare (* table .T .values )
36
+ return TestResult (statistic , p )
37
37
38
38
39
39
def paired_test (table , stats_func = ranksums ):
0 commit comments