[ 簡単な説明 ] 検定とは、統計学の理論を使って、母集団の特徴の仮説を立て、標本で得られたデータからその仮説が成り立つかどうかを判断するものです。 例えば、下表の mtst1( ) は、母集団が正規分布の集団でその分散が既知である時、標本のデータから得られた平均値を母集団の平均値とみなせるかどうかの検定を行います。 |
関数名 | 関数の機能 | 機能説明 | 呼び出し例 |
mtst1( ) | 母平均検定 (母分散既知) |
|
mtst1( n, xbar, pm, pv, al, &sw, &u0, &u); |
mtst2( ) | 母平均検定 (母分散未知) |
|
mtst2( n, xbar, pm, uv, al, &sw, &t0, &t); |
mdtst1( ) | 2つの母平均の 差の検定 (母分散既知) |
|
mdtst1( n1, n2, xbar1, xbar2, pv1, pv2, al, &sw, &u0, &u); |
mdtst2( ) | 2つの母平均の 差の検定 (母分散未知 (等しい)) |
|
mdtst2( n1, n2, xbar1, xbar2, s1, s2, al, &sw, &t0, &t); |
mdtst3( ) | 2つの母平均の 差の検定 (母分散未知 (異なる)) |
|
mdtst3( n1, n2, xbar1, xbar2, uv1, uv2, al, &sw, &t0, &t); |
nbptst( ) | 母百分率 (不良率)の 検定 (正規分布検定) |
|
nbptst( n, ps, pp, al, &sw, &u0, &u); |
fbptst( ) | 母百分率 (不良率)の 検定 (F分布検定) |
|
fbptst( n, ps, pp, al, &sw, &f0, &f); |
bpdtst( ) | 2つの母百分率 (不良率)の 差の検定 |
|
bpdtst( n1, n2, ps1, ps2, al, &sw, &u0, &u); |
vtst( ) | 母分散の検定 |
|
vtst( sw1, n, s, v, al, &sw2, &x20, &x21, &x22); |
vdtst( ) | 等分散の検定 |
|
vdtst( n1, n2, uv1, uv2, al, &sw, &f0, &f); |
cont22( ) | 2元分割表 による 独立性検定 |
|
cont22( &sw, a, b, c, d, al, &x20, &x2); |
contlm( ) | L×M分割表 による 独立性検定 |
|
contlm( l, m, a, al, ac, ar, &at, ef, &x20, &x2, &sw); |
thomp( ) | 棄却検定 (Thompsonの 方法) |
|
thomp( n, xk, xbar, v, al, &sw, &t0, &t); |
rttst( ) | 無相関の t 検定 |
|
rttst( n, r0, al, &sw, &t0, &t); |
rptst( ) | 母相関係数の 検定 |
|
rptst( n, r0, rp, al, &sw, &u0, &u); |
rptst2( ) | 2つの母集団の 母相関係数の 等値検定 |
|
rptst2( n1, n2, r01, r02, al, &sw, &u0, &u); |
/* test.c */ #include <stdio.h> #include "sslib.h" int mtst1(int n, double xbar, double pm, double pv, double al, int *sw, double *u0, double *u) { double qn; if(n < 1 || al <= 0.0 || al >= 1.0) return 999; *u0 = (xbar - pm) * sqrt(n / pv); if(*sw < 0) qn = 1.0 - al; else qn = 1.0 - 0.5 * al; *u = pnorm(qn); if(fabs(*u0) >= *u) *sw = 1; else *sw = 0; return 0; } int mtst2(int n, double xbar, double pm, double uv, double al, int *sw, double *t0, double *t) { double qt; if(n < 1 || al <= 0.0 || al >= 0.5) return 999; *t0 = (xbar - pm) * sqrt(n / uv); if(*sw < 0) qt = 2.0 * al; else qt = al; n--; *t = pt(qt, n); if(fabs(*t0) >= *t) *sw = 1; else *sw = 0; return 0; } int mdtst1(int n1, int n2, double xbar1, double xbar2, double pv1, double pv2, double al, int *sw, double *u0, double *u) { double w1, w2, qn; if(n1 < 1 || n2 < 1 || al <= 0.0 || al >= 1.0) return 999; w1 = xbar1 - xbar2; w2 = sqrt(pv1 / n1 + pv2 / n2); *u0 = w1 / w2; if(*sw < 0) qn = 1.0 - al; else qn = 1.0 - 0.5 * al; *u = pnorm(qn); if(fabs(*u0) >= *u) *sw = 1; else *sw = 0; return 0; } int mdtst2(int n1, int n2, double xbar1, double xbar2, double s1, double s2, double al, int *sw, double *t0, double *t) { int nu; double w1, w2, w3, qt; if(n1 < 2 || n2 < 2 || al <= 0.0 || al >= 0.5) return 999; nu = n1 + n2 - 2; w1 = xbar1 - xbar2; w2 = sqrt((s1 + s2) / nu); w3 = sqrt(1.0 / n1 + 1.0 / n2); *t0 = w1 / w2 / w3; if(*sw < 0) qt = 2.0 * al; else qt = al; *t = pt(qt, nu); if(fabs(*t0) >= *t) *sw = 1; else *sw = 0; return 0; } int mdtst3(int n1, int n2, double xbar1, double xbar2, double uv1, double uv2, double al, int *sw, double *t0, double *t) { int nu; double w, w1, w2, w3, qt; if(n1 < 2 || n2 < 2 || al <= 0.0 || al >= 0.5) return 999; w1 = xbar1 - xbar2; w2 = uv1 / n1; w3 = uv2 / n2; w = w2 + w3; *t0 = w1 / sqrt(w); w1 = w2 / w; w2 = w1 * w2 / (double)(n1 - 1); w = 1.0 - w1; w3 = w * w /(double)(n2 - 1); nu = 1.0 / (w2 + w3); if(*sw < 0) qt = 2.0 * al; else qt = al; *t = pt(qt, nu); if(fabs(*t0) >= *t) *sw = 1; else *sw = 0; return 0; } int nbptst(int n, double ps, double pp, double al, int *sw, double *u0, double *u) { double qn; if(n < 1 || ps <= 0.0, ps >= 1.0 || pp <= 0. || pp >= 1.0 || al <= 0.0 || al >= 1.0) return 999; *u0 = (ps - pp) / sqrt(pp * (1.0 - pp) / n); if(*sw < 0) qn = 1.0 - al; else qn = 1.0 - 0.5 * al; *u = pnorm(qn); if(abs(*u0) >= *u) *sw = 1; else *sw = 0; return 0; } int fbptst(int n, double ps, double pp, double al, int *sw, double *f0, double *f) { int nu1, nu2; double w; if(n < 1 || ps <= 0.0 || ps >= 1.0 || pp <= 0.0 || pp >= 1.0 || al <= 0.0 || al >= 1.0 || ps == pp) return 999; w = ps * n; if(ps < pp) { nu1 = 2.0 * (w + 1.0); nu2 = 2.0 * ((double)n - w); *f0 = nu2 * pp / nu1 / (1.0 - pp); } else { nu1 = 2.0 * ((double)n - w + 1.0); nu2 = 2.0 * w; *f0 = nu2 * (1.0 - pp) / nu1 / pp; } *f = pf(al, nu1, nu2); if(fabs(*f0) >= *f) *sw = 1; else *sw = 0; return 0; } int bpdtst(int n1, int n2, double ps1, double ps2, double al, int *sw, double *u0, double *u) { double w, w1, w2, qn; if(n1 < 1 || n2 < 1 || ps1 <= 0.0 || ps1 >= 1.0 || ps2 <= 0.0 || ps2 >= 1.0 || al <= 0.0 || al >= 1.0) return 999; w = (ps1 * (double)n1 + ps2 * (double)n2) / (double)(n1 + n2); w1 = ps1 - ps2; w2 = w * (1.0 - w) * (1.0 / (double)n1 + 1.0 / (double)n2); *u0 = w1 / sqrt(w2); if(*sw < 0) qn = 1.0 - al; else qn = 1.0 - 0.5 * al; *u = pnorm(qn); if(fabs(*u0) >= *u) *sw = 1; else *sw = 0; return 0; } int vtst(int sw1, int n, double s, double v, double al, int *sw2, double *x20, double *x21, double *x22) { double qc1; if(n < 2 || al <= 0.0 || al >= 1.0) return 999; if(sw1 < 0) n--; *x20 = s / v; if(*sw2 < 0) qc1 = al; else qc1 = 0.5 * al; *x21 = pchi(qc1, n); *x22 = pchi(1.0 - qc1, n); if(*x20 < *x21 && *x20 > *x22) *sw2 = 0; else *sw2 = 1; return 0; } int vdtst(int n1, int n2, double uv1, double uv2, double al, int *sw, double *f0, double *f) { if(n1 < 2 || n2 < 2 || al <= 0.0 || al >= 1.0) return 999; n1--; n2--; al *= 0.5; if(uv1 >= uv2) { *f0 = uv1 / uv2; *f = pf(al, n1, n2); } else { *f0 = uv2 / uv1; *f = pf(al, n2, n1); } if(*f0 >= *f) *sw = 1; else *sw = 0; return 0; } int cont22(int *sw, double a, double b, double c, double d, double al, double *x20, double *x2) { double w1, w2, w3, w21, w22, w23, w24; if(al <= 0.0 || al >= 1.0) return 999; w1 = a + b + c + d; w3 = (a + b) * (c + d) * (a + c) * (b + d); w21 = a * d - b * c; if(*sw >= 0) w2 = w21 * w21; else { w22 = w1 * 0.5; w23 = w21 + w22; w24 = w21 - w22; if(fabs(w23) > fabs(w24)) w2 = w24 * w24; else w2 = w23 * w23; } *x20 = w1 * w2 / w3; *x2 = pchi(al, 1); if(*x20 >= *x2) *sw = 1; else *sw = 0; return 0; } int contlm(int l, int m, double a[], double al, double ac[], double ar[], double *at, double ef[], double *x20, double *x2, int *sw) { int i, j, k, n, nu; double w; if(l < 2 || m < 2 || al <= 0.0 || al >= 1.0) return 999; for(i = 0; i < m; i++) { w = 0.0; for(j = 0; j < l; j++) { k = j * m + i; w += a[k]; } ac[i] = w; } for(i = 0; i < l; i++) { n = i * m; w = 0.0; for(j = 0; j < m; j++) { k = n + j; w += a[k]; } ar[i] = w; } *at = 0.0; for(i = 0; i < l; i++) *at += ar[i]; for(i = 0; i < l; i++) { n = i * m; for(j = 0; j < m; j++) { k = n + j; ef[k] = ar[i] * ac[j] / *at; } } *x20 = 0.0; for(i = 0; i < l; i++) { n = i * m; for(j = 0; j < m; j++) { k = n + j; w = a[k] - ef[k]; *x20 += (w * w / ef[k]); } } nu = (l - 1) * (m - 1); *x2 = pchi(al, nu); if(*x20 >= *x2) *sw = 1; else *sw = 0; return 0; } int thomp(int n, double xk, double xbar, double v, double al, int *sw, double *t0, double *t) { double w; if(n < 3 || al <= 0.0 || al >= 1.0) return 999; w = (xk - xbar) / sqrt(v); n -= 2; *t0 = sqrt((double)n) * w / sqrt((double)n + 1.0 - w * w); *t = pt(al, n); if(fabs(*t0) >= *t) *sw = 1; else *sw = 0; return 0; } int rttst(int n, double r0, double al, int *sw, double *t0, double *t) { if(n < 2 || al <= 0.0 || al >= 1.0 || fabs(r0) >= 1.0) return 999; n -= 2; *t0 = r0 * sqrt((double)n) / sqrt(1.0 - r0 * r0); *t = pt(al, n); if(fabs(*t0) >= *t) *sw = 1; else *sw = 0; return 0; } int rptst(int n, double r0, double rp, double al, int *sw, double *u0, double *u) { double w1, w2; if(n < 3 || al <= 0.0 || al >= 1.0 || fabs(r0) >= 1.0 || fabs(rp) >= 1.0) return 999; w1 = 0.5 * log((1.0 + r0) / (1.0 - r0)); w2 = 0.5 * log((1.0 + rp) / (1.0 - rp)); *u0 = (w1 - w2) * sqrt((double)(n - 3)); *u = pnorm(1.0 - 0.5 * al); if(fabs(*u0) >= *u) *sw = 1; else *sw = 0; return 0; } int rptst2(int n1, int n2, double r01, double r02, double al, int *sw, double *u0, double *u) { double w1, w2; if(n1 < 4 || n2 < 4 || al <= 0.0 || al >= 1.0 || fabs(r01) >= 1.0 || fabs(r02) >= 1.0) return 999; w1 = 0.5 * log((1.0 + r01) / (1.0 - r01)); w2 = 0.5 * log((1.0 + r02) / (1.0 - r02)); *u0 = (w1 - w2) / sqrt(1.0 / (double)(n1 - 3) + 1.0 / (double)(n2 - 3)); *u = pnorm(1.0 - 0.5 * al); if(fabs(*u0) >= *u) *sw = 1; else *sw = 0; return 0; } |