normality_test_fl()

関数normality_test_fl()は、正規性テストを実行する UDF (ユーザー定義関数) です。

前提条件

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

構文

T | invoke normality_test_fl(data,test_statistic,p_value)

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

パラメーター

名前 必須 説明
data string ✔️ テストに使用するデータを含む列の名前。
test_statistic string ✔️ 結果のテスト統計値を格納する列の名前。
p_value string ✔️ 結果の p 値を格納する列の名前。

関数の定義

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

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

重要

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

let normality_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.normaltest(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.

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

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

let normality_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.normaltest(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, 27.1, 22.12, 33.56, 23.64, 20.57]),
'Test #2', dynamic([20.85, 21.89, 23.41, 35.09, 30.02, 26.52, 20.85, 21.89]),
'Test #3', dynamic([20.13, 20.5, 21.7, 22.02, 32.2, 32.79, 33.9, 34.22, 20.13, 20.5])
]
| extend test_stat= 0.0, p_val = 0.0
| invoke normality_test_fl('sample1', 'test_stat', 'p_val')

出力

id sample1 test_stat p_val
テスト #1 [23.64, 20.57, 20.42, 27.1, 22.12, 33.56, 23.64, 20.57] 7.4881873153941036 0.023657060728893706
テスト #2 [20.85, 21.89, 23.41, 35.09, 30.02, 26.52, 20.85, 21.89] 3.29982750330276 0.19206647332255408
テスト #3 [20.13, 20.5, 21.7, 22.02, 32.2, 32.79, 33.9, 34.22, 20.13, 20.5] 6.9868433851364324 0.030396685911910585

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