Keyword: フリードマン, Friedman Test, 検定, 二元配置分散分析
概要
本サンプルはフリードマンの二元配置分散分析(フリードマン検定/Friedman Test) を行うC言語によるサンプルプログラムです。 本サンプルは以下に示される3つの標本を分析対象とし、検定統計量と自由度、有意確率を出力します。
※本サンプルはnAG Cライブラリに含まれる関数 nag_friedman_test() のExampleコードです。本サンプル及び関数の詳細情報は nag_friedman_test のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本関数の詳細はnag_friedman_test のマニュアルページを参照)| このデータをダウンロード |
nag_friedman_test (g08aec) Example Program Data 1 2 1 1 3 2 3 1 3 3 2 2 3 2 2.5 3 3 2 3 3 3 2 1 3 2 3 1 1 3 3 2 3 2.5 2 2 3 2 1 2 3 2 1 1 2 2 2 1 1 1 1 1 1 1 1
- 1行目はタイトル行で読み飛ばされます。
- 2行目に1つ目の標本(x(1,1..18))を指定しています。
- 3行目に2つ目の標本(x(2,1..18))を指定しています。
- 4行目に3つ目の標本(x(3,1..18))を指定しています。
出力結果
(本関数の詳細はnag_friedman_test のマニュアルページを参照)| この出力例をダウンロード |
nag_friedman_test (g08aec) Example Program Results
Friedman test
Data values
Group Group Group
1 2 3
1.0 3.0 2.0
2.0 3.0 1.0
1.0 3.0 2.0
1.0 2.0 3.0
3.0 1.0 2.0
2.0 3.0 1.0
3.0 2.0 1.0
1.0 3.0 2.0
3.0 1.0 2.0
3.0 1.0 2.0
2.0 3.0 1.0
2.0 3.0 1.0
3.0 2.0 1.0
2.0 3.0 1.0
2.5 2.5 1.0
3.0 2.0 1.0
3.0 2.0 1.0
2.0 3.0 1.0
Test statistic 8.583
Degrees of freedom 2
Significance 0.014
- 9行目〜26行目に読み込まれた標本のデータが縦3列に出力されています。
左から1つ目の標本データ、2つ目の標本データ、3つ目の標本データの順に出力されています。 - 28行目には検定統計量が出力されています。
- 29行目には自由度が出力されています。
- 30行目には有意確率が出力されています。
ソースコード
(本関数の詳細はnag_friedman_test のマニュアルページを参照)
※本サンプルソースコードはnAG数値計算ライブラリ(Windows, Linux, MAC等に対応)の関数を呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
/* nag_friedman_test (g08aec) Example Program.
*
* CLL6I261D/CLL6I261DL Version.
*
* Copyright 2017 Numerical Algorithms Group.
*
* Mark 26.1, 2017.
*/
#include <stdio.h>
#include <nag.h>
#include <nag_stdlib.h>
#include <nagg08.h>
int main(void)
{
Integer exit_status = 0, i, ix, j, k, n;
NagError fail;
double fr, sig, *x = 0;
#define X(I, J) x[((I) -1)*n +(J) -1]
INIT_FAIL(fail);
printf("nag_friedman_test (g08aec) Example Program Results\n");
/* Skip heading in data file */
scanf("%*[^\n]");
n = 18;
k = 3;
ix = k;
if (!(x = nAG_ALLOC(ix * n, double)))
{
printf("Allocation failure\n");
exit_status = -1;
goto END;
}
for (i = 1; i <= ix; ++i)
for (j = 1; j <= n; ++j)
scanf("%lf", &X(i, j));
printf("\nFriedman test\n");
printf("\nData values\n");
printf("\n Group Group Group\n");
printf(" 1 2 3\n");
for (j = 1; j <= 18; ++j) {
for (i = 1; i <= 3; ++i)
printf("%7.1f", X(i, j));
printf("\n");
}
/* nag_friedman_test (g08aec).
* Friedman two-way analysis of variance on k matched
* samples
*/
nag_friedman_test(k, n, x, n, &fr, &sig, &fail);
if (fail.code != NE_NOERROR) {
printf("Error from nag_friedman_test (g08aec).\n%s\n", fail.message);
exit_status = 1;
goto END;
}
printf("\n");
printf("%s%6.3f\n", "Test statistic ", fr);
printf("%s%6ld\n", "Degrees of freedom ", k - 1);
printf("%s%6.3f\n", "Significance ", sig);
END:
nAG_FREE(x);
return exit_status;
}
