Share via


wilcoxon_test_fl()

La funzione è una funzione wilcoxon_test_fl()definita dall'utente che esegue il test Wilcoxon.

Prerequisiti

  • Il plug-in Python deve essere abilitato nel cluster. Questa operazione è necessaria per Python inline usato nella funzione .
  • Il plug-in Python deve essere abilitato nel database. Questa operazione è necessaria per Python inline usato nella funzione .

Sintassi

T | invoke wilcoxon_test_fl()(Dati,, test_statisticp_value)

Altre informazioni sulle convenzioni di sintassi.

Parametri

Nome Tipo Obbligatoria Descrizione
data string ✔️ Nome della colonna contenente i dati da utilizzare per il test.
test_statistic string ✔️ Nome della colonna in cui archiviare il valore della statistica di test per i risultati.
p_value string ✔️ Nome della colonna in cui archiviare il valore p per i risultati.

Definizione di funzione

È possibile definire la funzione incorporando il codice come funzione definita da query o creandola come funzione archiviata nel database, come indicato di seguito:

Definire la funzione usando l'istruzione let seguente. Non sono necessarie autorizzazioni.

Importante

Un'istruzione let non può essere eseguita autonomamente. Deve essere seguita da un'istruzione di espressione tabulare. Per eseguire un esempio funzionante di wilcoxon_test_fl(), vedere Esempio.

let wilcoxon_test_fl = (tbl:(*), data:string, test_statistic:string, p_value:string)
{
    let kwargs = bag_pack('data', data, 'test_statistic', test_statistic, 'p_value', p_value);
    let code = ```if 1:
        from scipy import stats
        data = kargs["data"]
        test_statistic = kargs["test_statistic"]
        p_value = kargs["p_value"]
        def func(row):
            statistics = stats.wilcoxon(row[data])
            return statistics[0], statistics[1]
        result = df
        result[[test_statistic, p_value]]  = df.apply(func, axis=1, result_type = "expand")
    ```;
    tbl
    | evaluate python(typeof(*), code, kwargs)
};
// Write your query to use the function here.

Esempio

Nell'esempio seguente viene utilizzato l'operatore invoke per eseguire la funzione .

Per usare una funzione definita da query, richiamarla dopo la definizione della funzione incorporata.

let wilcoxon_test_fl = (tbl:(*), data:string, test_statistic:string, p_value:string)
{
    let kwargs = bag_pack('data', data, 'test_statistic', test_statistic, 'p_value', p_value);
    let code = ```if 1:
        from scipy import stats
        data = kargs["data"]
        test_statistic = kargs["test_statistic"]
        p_value = kargs["p_value"]
        def func(row):
            statistics = stats.wilcoxon(row[data])
            return statistics[0], statistics[1]
        result = df
        result[[test_statistic, p_value]]  = df.apply(func, axis=1, result_type = "expand")
    ```;
    tbl
    | evaluate python(typeof(*), code, kwargs)
};
datatable(id:string, sample1:dynamic) [
'Test #1', dynamic([23.64, 20.57, 20.42]),
'Test #2', dynamic([20.85, 21.89, 23.41]),
'Test #3', dynamic([20.13, 20.5, 21.7, 22.02])
]
| extend test_stat= 0.0, p_val = 0.0
| invoke wilcoxon_test_fl('sample1', 'test_stat', 'p_val') -->

Output

ID sample1 test_stat p_val
Test n. 1 [23.64, 20.57, 20.42] 0, 0.10880943004054568
Test n. 2 [20.85, 21.89, 23.41] 0, 0.10880943004054568
Test n. 3 [20.13, 20.5, 21.7, 22.02] 0, 0.06788915486182899

Questa funzionalità non è supportata.