Share via


bartlett_test_fl()

La bartlett_test_fl() funzione è una funzione tabulare definita dall'utente che esegue il test Bartlett.

Prerequisiti

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

Sintassi

T | invoke bartlett_test_fl()(data1,data2,, test_statisticp_value)

Altre informazioni sulle convenzioni di sintassi.

Parametri

Nome Tipo Obbligatoria Descrizione
data1 string ✔️ Nome della colonna contenente il primo set di dati da usare per il test.
data2 string ✔️ Nome della colonna contenente il secondo set di dati da usare per il test.
test_statistic string ✔️ Nome della colonna per archiviare il valore della statistica di test per i risultati.
p_value string ✔️ Nome della colonna da archiviare p-value 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 segue:

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

Importante

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

let bartlett_test_fl = (tbl:(*), data1:string, data2:string, test_statistic:string, p_value:string)
{
    let kwargs = bag_pack('data1', data1, 'data2', data2, 'test_statistic', test_statistic, 'p_value', p_value);
    let code = ```if 1:
        from scipy import stats
        data1 = kargs["data1"]
        data2 = kargs["data2"]
        test_statistic = kargs["test_statistic"]
        p_value = kargs["p_value"]
        def func(row):
            statistics = stats.bartlett(row[data1], row[data2])
            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 usato l'operatore invoke per eseguire la funzione.

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

let bartlett_test_fl = (tbl:(*), data1:string, data2:string, test_statistic:string, p_value:string)
{
    let kwargs = bag_pack('data1', data1, 'data2', data2, 'test_statistic', test_statistic, 'p_value', p_value);
    let code = ```if 1:
        from scipy import stats
        data1 = kargs["data1"]
        data2 = kargs["data2"]
        test_statistic = kargs["test_statistic"]
        p_value = kargs["p_value"]
        def func(row):
            statistics = stats.bartlett(row[data1], row[data2])
            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)
};
// Example query that uses the function
datatable(id:string, sample1:dynamic, sample2:dynamic) [
'Test #1', dynamic([23.64, 20.57, 20.42]), dynamic([27.1, 22.12, 33.56]),
'Test #2', dynamic([20.85, 21.89, 23.41]), dynamic([35.09, 30.02, 26.52]),
'Test #3', dynamic([20.13, 20.5, 21.7, 22.02]), dynamic([32.2, 32.79, 33.9, 34.22])
]
| extend test_stat= 0.0, p_val = 0.0
| invoke bartlett_test_fl('sample1', 'sample2', 'test_stat', 'p_val')

Output

id sample1 sample2 test_stat p_val
Test #1 [23.64, 20.57, 20.42] [27.1, 22.12, 33.56] 1.7660796224425723 0.183868001738637
Test #2 [20.85, 21.89, 23.41] [35.09, 30.02, 26.52] 1.9211710616896014 0.16572762069132516
Test #3 [20.13, 20.5, 21.7, 22.02] [32.2, 32.79, 33.9, 34.22] 0.0026985713829234454 0.958570306268548

Questa funzionalità non è supportata.