Class: Num4TstStatistic2Lib::ParametrixTestLib

Inherits:
Object
  • Object
show all
Defined in:
lib/num4tststatistic2.rb

Overview

パラメトリック検定

Instance Method Summary collapse

Constructor Details

#initialize(hypothTest3) ⇒ ParametrixTestLib

Returns a new instance of ParametrixTestLib.



8
9
10
11
# File 'lib/num4tststatistic2.rb', line 8

def initialize(hypothTest3)
    @hypothTest3 = hypothTest3
    @paraTest = Num4TstStatisticLib::ParametrixTestLib.new
end

Instance Method Details

#diffPopulationMean(xi1, xi2, a) ⇒ boolean

対応のある2つの母平均の差の検定量

Examples:

xi1 = [37.1, 36.2, 36.6, 37.4, 36.8, 36.7, 36.9, 37.4, 36.6, 36.7]
xi2 = [36.8, 36.6, 36.5, 37.0, 36.0, 36.5, 36.6, 37.1, 36.4, 36.7]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.diffPopulationMean(xi1, xi2, 0.05)
=> true

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi1 (Array)

    x1のデータ(double[])

  • xi2 (Array)

    x2のデータ(double[])

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


153
154
155
156
157
158
159
160
# File 'lib/num4tststatistic2.rb', line 153

def diffPopulationMean(xi1, xi2, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    n = xi1.size
    df = n - 1
    statistic = @paraTest.diffPopulationMean(xi1, xi2)
    return @hypothTest3.tDistTest(statistic, df, a)
end

#diffPopulationMean2EquVar(xi1, xi2, a) ⇒ boolean

2つの母平均の差の検定(等分散性を仮定)

Examples:

xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.diffPopulationMean2EquVar(xi1, xi2, 0.05)
=> false

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi1 (Array)

    x1のデータ(double[])

  • xi2 (Array)

    x2のデータ(double[])

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


109
110
111
112
113
114
115
116
117
# File 'lib/num4tststatistic2.rb', line 109

def diffPopulationMean2EquVar(xi1, xi2, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    n1 = xi1.size
    n2 = xi2.size
    df = n1 + n2 - 2
    statistic = @paraTest.diffPopulationMean2EquVar(xi1, xi2)
    return @hypothTest3.tDistTest(statistic, df, a)
end

#diffPopulationMean2UnEquVar(xi1, xi2, a) ⇒ boolean

2つの母平均の差の検定(不等分散性を仮定)

Examples:

xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.diffPopulationMean2UnEquVar(xi1, xi2, 0.05)
=> false

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi1 (Array)

    x1のデータ(double[])

  • xi2 (Array)

    x2のデータ(double[])

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


132
133
134
135
136
137
138
# File 'lib/num4tststatistic2.rb', line 132

def diffPopulationMean2UnEquVar(xi1, xi2, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    df = @paraTest.df4welch(xi1, xi2)
    statistic = @paraTest.diffPopulationMean2UnEquVar(xi1, xi2)
    return @hypothTest3.tDistTest(statistic, df, a)
end

#diffPopulationRatio(m1, n1, m2, n2, a) ⇒ boolean

2つの母比率の差の検定

Examples:

hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.diffPopulationRatio(469, 1200, 308, 900, 0.05)
=> true

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • m1 (int)

    m1値

  • n1 (int)

    N1値

  • m2 (int)

    m2値

  • n2 (int)

    N2値

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


197
198
199
200
201
202
# File 'lib/num4tststatistic2.rb', line 197

def diffPopulationRatio(m1, n1, m2, n2, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    statistic = @paraTest.diffPopulationRatio(m1, n1, m2, n2)
    return @hypothTest3.normDistTest(statistic, a)
end

#diffPopulationVar(xi1, xi2, a) ⇒ boolean

2つの母分散の差の検定

Examples:

xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.diffPopulationVar(xi1, xi2, 0.05)
=> false

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi1 (Array)

    x1のデータ(double[])

  • xi2 (Array)

    x2のデータ(double[])

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


175
176
177
178
179
180
181
182
# File 'lib/num4tststatistic2.rb', line 175

def diffPopulationVar(xi1, xi2, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    nf = xi1.size - 1
    df = xi2.size - 1
    statistic = @paraTest.diffPopulationVar(xi1, xi2)
    return @hypothTest3.fDistTest(statistic, nf, df, a)
end

#diffPopulationVarMean(xi1, xi2, a) ⇒ boolean

2つの母平均の差の検定

Examples:

xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.diffPopulationVarMean(xi1, xi2, 0.05)
=> false

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi1 (Array)

    x1のデータ(double[])

  • xi2 (Array)

    x2のデータ(double[])

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)



86
87
88
89
90
91
92
93
94
# File 'lib/num4tststatistic2.rb', line 86

def diffPopulationVarMean(xi1, xi2, a)
    bRet = diffPopulationVar(xi1, xi2, a)

    if bRet == true # 等分散ではない
        return diffPopulationMean2UnEquVar(xi1, xi2, a)
    else            # 等分散性
        return diffPopulationMean2EquVar(xi1, xi2, a)
    end
end

#fidelity(fi, pi, a) ⇒ boolean

適合度の検定

Examples:

fi = [57, 33, 46, 14]
pi = [0.4, 0.2, 0.3, 0.1]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.fidelity(fi, pi, 0.05)
=> false

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • fi (Array)

    実測度数(double[])

  • pi (Array)

    比率(double[])

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


217
218
219
220
221
222
223
# File 'lib/num4tststatistic2.rb', line 217

def fidelity(fi, pi, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    df = fi.size - 1
    statistic = @paraTest.fidelity(fi, pi)
    return @hypothTest3.chi2DistTest(statistic, df, a)
end

#independency(fij, a) ⇒ boolean

独立性の検定

Examples:

fij = [
  [57, 33, 46, 14],
  [89, 24, 75, 12],
]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.independency(fij, 0.05)
=> true

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


239
240
241
242
243
244
245
246
247
# File 'lib/num4tststatistic2.rb', line 239

def independency(fij, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    m = fij.size
    n = fij[0].size
    df = (m - 1) * (n - 1)
    statistic = @paraTest.independency(fij)
    return @hypothTest3.chi2DistTest(statistic, df, a)
end

#populationMean(xi, m0, a) ⇒ boolean

正規母集団の母平均の検定

Examples:

xi = [15.5, 15.7, 15.4, 15.4, 15.6, 15.4, 15.6, 15.5, 15.4]
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.populationMean(xi, 15.4, 0.05)
=> true

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi (Array)

    データ(double[])

  • m0 (double)

    母平均

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


25
26
27
28
29
30
31
# File 'lib/num4tststatistic2.rb', line 25

def populationMean(xi, m0, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    df = xi.size - 1
    statistic = @paraTest.populationMean(xi, m0)
    return @hypothTest3.tDistTest(statistic, df, a)
end

#populationRatio(m, n, p0, a) ⇒ boolean

母比率の検定

Examples:

hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.populationRatio(29, 346, 0.12, 0.05)
=> true

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • m (int)

    m値

  • n (int)

    N値

  • p0 (double)

    母比率

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


66
67
68
69
70
71
# File 'lib/num4tststatistic2.rb', line 66

def populationRatio(m, n, p0, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    statistic = @paraTest.populationRatio(m, n, p0)
    return @hypothTest3.normDistTest(statistic, a)
end

#populationVar(xi, sig0, a) ⇒ boolean

正規母集団の母分散の検定

Examples:

xi = [35.2, 34.5, 34.9, 35.2, 34.8, 35.1, 34.9, 35.2, 34.9, 34.8]
sd = 0.4
hypothTest = Num4HypothTestLib::TwoSideTestLib.new
paraTest = Num4TstStatistic2Lib::ParametrixTestLib.new(hypothTest)
paraTest.populationVar(xi, sd*sd, 0.05)
=> true

Returns 検定結果(true:棄却域内 false:棄却域外).

Parameters:

  • xi (Array)

    データ(double[])

  • sig0 (double)

    母分散

  • a (double)

    有意水準

Returns:

  • (boolean)

    検定結果(true:棄却域内 false:棄却域外)

Raises:

  • (TypeError)


46
47
48
49
50
51
52
# File 'lib/num4tststatistic2.rb', line 46

def populationVar(xi, sig0, a)
    raise TypeError unless @hypothTest3.kind_of?(HypothTest3IF)

    df = xi.size - 1
    statistic = @paraTest.populationVar(xi, sig0)
    return @hypothTest3.chi2DistTest(statistic, df, a)
end