bartlett_test_fl()

関数はbartlett_test_fl()Bartlett テストを実行するユーザー定義の表形式関数です。

前提条件

  • データベースで Python プラグイン を有効にする必要があります。 これは、 関数で使用されるインライン Python に必要です。

構文

T | invoke bartlett_test_fl()(data1,data2,test_statistic,p_value)

構文規則について詳しく知る。

パラメーター

名前 必須 説明
data1 string ✔️ テストに使用する最初のデータ セットを含む列の名前。
data2 string ✔️ テストに使用する 2 番目のデータ セットを含む列の名前。
test_statistic string ✔️ 結果のテスト統計値を格納する列の名前。
p_value string ✔️ 結果の p 値を格納する列の名前。

関数の定義

関数を定義するには、次のようにコードをクエリ定義関数として埋め込むか、データベースに格納された関数として作成します。

次の let ステートメントを使用して関数を定義します。 権限は必要ありません。

重要

let ステートメントを単独で実行することはできません。 その後に 表形式の式ステートメントを指定する必要があります。 の動作例 bartlett_test_fl()を実行するには、「 」を参照してください。

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.

次の例では、 invoke 演算子 を使用して関数を実行します。

クエリ定義関数を使用するには、埋め込み関数定義の後で呼び出します。

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')

出力

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

この機能はサポートされていません。