mann_whitney_u_test_fl()
関数mann_whitney_u_test_fl()
は、Mann-Whitney U テストを実行する UDF (ユーザー定義関数)。
前提条件
- Python プラグインは、クラスター 有効にする必要があります。 これは、関数で使用されるインライン Python に必要です。
- Python プラグインは、データベース 有効にする必要があります。 これは、関数で使用されるインライン Python に必要です。
構文
T | mann_whitney_u_test_fl(
data1,
data2,
test_statistic,
p_value [,
use_continuity ])
構文規則について詳しく知る。
パラメーター
件名 | タイプ | Required | 説明 |
---|---|---|---|
data1 | string |
✔️ | テストに使用する最初のデータ セットを含む列の名前。 |
data2 | string |
✔️ | テストに使用する 2 番目のデータ セットを含む列の名前。 |
test_statistic | string |
✔️ | 結果の検定統計量値を格納する列の名前。 |
p_value | string |
✔️ | 結果の p 値を格納する列の名前。 |
use_continuity | bool |
継続性の修正 (1/2) が適用されるかどうかを判断します。 既定値は true です。 |
関数定義
関数を定義するには、次のようにコードをクエリ定義関数として埋め込むか、データベースに格納された関数として作成します。
次の let ステートメントを使用して関数を定義。 権限は必要ありません。
重要
let ステートメント単独では実行できません。 その後に 表形式の式ステートメントが続く必要があります。 mann_whitney_u_test_fl()
の動作例を実行するには、Exampleを参照してください。
let mann_whitney_u_test_fl = (tbl:(*), data1:string, data2:string, test_statistic:string, p_value:string, use_continuity:bool=true)
{
let kwargs = bag_pack('data1', data1, 'data2', data2, 'test_statistic', test_statistic, 'p_value', p_value, 'use_continuity', use_continuity);
let code = ```if 1:
from scipy import stats
data1 = kargs["data1"]
data2 = kargs["data2"]
test_statistic = kargs["test_statistic"]
p_value = kargs["p_value"]
use_continuity = kargs["use_continuity"]
def func(row):
statistics = stats.mannwhitneyu(row[data1], row[data2], use_continuity=use_continuity)
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 mann_whitney_u_test_fl = (tbl:(*), data1:string, data2:string, test_statistic:string, p_value:string, use_continuity:bool=true)
{
let kwargs = bag_pack('data1', data1, 'data2', data2, 'test_statistic', test_statistic, 'p_value', p_value, 'use_continuity', use_continuity);
let code = ```if 1:
from scipy import stats
data1 = kargs["data1"]
data2 = kargs["data2"]
test_statistic = kargs["test_statistic"]
p_value = kargs["p_value"]
use_continuity = kargs["use_continuity"]
def func(row):
statistics = stats.mannwhitneyu(row[data1], row[data2], use_continuity=use_continuity)
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, 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 mann_whitney_u_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 | 0.095215131912761986 |
テスト #2 | [20.85, 21.89, 23.41] | [35.09, 30.02, 26.52] | 0 | 0.04042779918502612 |
テスト #3 | [20.13, 20.5, 21.7, 22.02] | [32.2, 32.79, 33.9, 34.22] | 0 | 0.015191410988288745 |
この機能はサポートされていません。
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示