num4tststatistic 0.0.4-java → 0.1.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +14 -0
 - data/ext/num4tststatistic/NonParametrixTest.java +55 -0
 - data/ext/num4tststatistic/ParametrixTest.java +193 -0
 - data/ext/num4tststatistic/TstStatistic.java +0 -175
 - data/lib/num4tststatistic.rb +144 -68
 - metadata +4 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 8035ed8852a010c953dc1f89787acb056eb516252687ed2a52ff558fb588ebf6
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 61ed13288b017bf0845b3cc3bf6807694eb655666a71126a4b31c9b67fe61aa4
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6031d267ff6f19ad8c12bc397cde2a6ae8aa95b0280564039c7f5a0c5cc8485455663bb7fd168d9358d8a180c17776440e620190c80af322ff8c21e863f622bc
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f2214a6320e064958b12e7afd72162edad09a8f355690215028126bd9f230ed52dff4e048ca064393b115375c9499cbb7af59ed788dce0b33fbd41c82070eca5
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -2,6 +2,20 @@ 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            ## Unreleased
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
      
 5 
     | 
    
         
            +
            ## [0.1.1] - 2023-12-27
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            ### add
         
     | 
| 
      
 8 
     | 
    
         
            +
            - add function of utest.
         
     | 
| 
      
 9 
     | 
    
         
            +
            - add function of spearmanscorr.
         
     | 
| 
      
 10 
     | 
    
         
            +
            - add function of kendallscorr.
         
     | 
| 
      
 11 
     | 
    
         
            +
            - add function of ks2test.
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            ### change
         
     | 
| 
      
 14 
     | 
    
         
            +
            - chg function name from unCorrelation to pearsoCorrelation.
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            ### delete
         
     | 
| 
      
 17 
     | 
    
         
            +
            - del function of populationCorre.
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
       5 
19 
     | 
    
         
             
            ## [0.0.4] - 2023-12-18
         
     | 
| 
       6 
20 
     | 
    
         | 
| 
       7 
21 
     | 
    
         
             
            ### add
         
     | 
| 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import java.util.Arrays;
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            import org.apache.commons.math3.stat.inference.WilcoxonSignedRankTest;
         
     | 
| 
      
 4 
     | 
    
         
            +
            import org.apache.commons.math3.stat.inference.MannWhitneyUTest;
         
     | 
| 
      
 5 
     | 
    
         
            +
            import org.apache.commons.math3.stat.correlation.SpearmansCorrelation;
         
     | 
| 
      
 6 
     | 
    
         
            +
            import org.apache.commons.math3.stat.correlation.KendallsCorrelation;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            import org.apache.commons.math3.stat.inference.TestUtils;
         
     | 
| 
      
 9 
     | 
    
         
            +
            public class NonParametrixTest {
         
     | 
| 
      
 10 
     | 
    
         
            +
                private static NonParametrixTest nonParamTest = new NonParametrixTest();
         
     | 
| 
      
 11 
     | 
    
         
            +
                public static NonParametrixTest getInstance() {
         
     | 
| 
      
 12 
     | 
    
         
            +
                    return nonParamTest;
         
     | 
| 
      
 13 
     | 
    
         
            +
                }
         
     | 
| 
      
 14 
     | 
    
         
            +
                
         
     | 
| 
      
 15 
     | 
    
         
            +
                // ウィルコクス符号付き順位検定
         
     | 
| 
      
 16 
     | 
    
         
            +
                public double wilcoxon(double[] x, double[] y) {
         
     | 
| 
      
 17 
     | 
    
         
            +
                    int n = x.length;
         
     | 
| 
      
 18 
     | 
    
         
            +
                    WilcoxonSignedRankTest wilcox = new WilcoxonSignedRankTest();
         
     | 
| 
      
 19 
     | 
    
         
            +
                    double w = wilcox.wilcoxonSignedRank(x, y); 
         
     | 
| 
      
 20 
     | 
    
         
            +
                    double e_w = n * (n  + 1.0) / 4.0;
         
     | 
| 
      
 21 
     | 
    
         
            +
                    double var_w = n * (n + 1.0) * (2.0 * n + 1.0) / 24.0;
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    return (w - e_w) / Math.sqrt(var_w); 
         
     | 
| 
      
 24 
     | 
    
         
            +
                }
         
     | 
| 
      
 25 
     | 
    
         
            +
                // マン・ホイットニーのU検定
         
     | 
| 
      
 26 
     | 
    
         
            +
                public double utest(double[] x, double[] y) {
         
     | 
| 
      
 27 
     | 
    
         
            +
                    int n1 = x.length;
         
     | 
| 
      
 28 
     | 
    
         
            +
                    int n2 = y.length;
         
     | 
| 
      
 29 
     | 
    
         
            +
                    MannWhitneyUTest utest = new MannWhitneyUTest();
         
     | 
| 
      
 30 
     | 
    
         
            +
                    double u = utest.mannWhitneyU(x, y);
         
     | 
| 
      
 31 
     | 
    
         
            +
                    double e_u = n1 * n2 / 2.0;
         
     | 
| 
      
 32 
     | 
    
         
            +
                    double var_u = (n1 * n2 * (n1 + n2 + 1.0)) / 12.0;
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                    return (u - e_u) / Math.sqrt(var_u);
         
     | 
| 
      
 35 
     | 
    
         
            +
                }
         
     | 
| 
      
 36 
     | 
    
         
            +
                // スピアマンの順位相関係数
         
     | 
| 
      
 37 
     | 
    
         
            +
                public double spearmanscorr(double[] x, double[] y) {
         
     | 
| 
      
 38 
     | 
    
         
            +
                    SpearmansCorrelation speamans = new SpearmansCorrelation();
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                    return speamans.correlation(x, y);
         
     | 
| 
      
 41 
     | 
    
         
            +
                }
         
     | 
| 
      
 42 
     | 
    
         
            +
                // ケンドールの順位相関係数
         
     | 
| 
      
 43 
     | 
    
         
            +
                public double kendallscorr(double[] x, double[] y) {
         
     | 
| 
      
 44 
     | 
    
         
            +
                    KendallsCorrelation kendalls = new KendallsCorrelation();
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                    return kendalls.correlation(x, y);
         
     | 
| 
      
 47 
     | 
    
         
            +
                }
         
     | 
| 
      
 48 
     | 
    
         
            +
                // コルモゴルフ・スミルノフ検定(2標本)
         
     | 
| 
      
 49 
     | 
    
         
            +
                public boolean ks2test(double[] xi1, double[] xi2, double a) {
         
     | 
| 
      
 50 
     | 
    
         
            +
                    double p = TestUtils.kolmogorovSmirnovTest(xi1, xi2);
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                    return (p < a) ? true : false;
         
     | 
| 
      
 53 
     | 
    
         
            +
                }
         
     | 
| 
      
 54 
     | 
    
         
            +
            }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,193 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import java.util.Arrays;
         
     | 
| 
      
 2 
     | 
    
         
            +
            import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
         
     | 
| 
      
 3 
     | 
    
         
            +
            import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;
         
     | 
| 
      
 4 
     | 
    
         
            +
            public class ParametrixTest {
         
     | 
| 
      
 5 
     | 
    
         
            +
                private static ParametrixTest paramTest = new ParametrixTest();
         
     | 
| 
      
 6 
     | 
    
         
            +
                    
         
     | 
| 
      
 7 
     | 
    
         
            +
                public static ParametrixTest getInstance() {
         
     | 
| 
      
 8 
     | 
    
         
            +
                    return paramTest;
         
     | 
| 
      
 9 
     | 
    
         
            +
                }
         
     | 
| 
      
 10 
     | 
    
         
            +
                // 正規母集団の母平均の検定量
         
     | 
| 
      
 11 
     | 
    
         
            +
                public double populationMean(double[] xi, double m0) {
         
     | 
| 
      
 12 
     | 
    
         
            +
                    int n = xi.length;
         
     | 
| 
      
 13 
     | 
    
         
            +
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    Arrays.stream(xi).forEach(stat::addValue);
         
     | 
| 
      
 16 
     | 
    
         
            +
                    double m = stat.getMean();     // 平均
         
     | 
| 
      
 17 
     | 
    
         
            +
                    double s2 = stat.getVariance();// 分散
         
     | 
| 
      
 18 
     | 
    
         
            +
                    return (m - m0) / Math.sqrt(s2 / n);
         
     | 
| 
      
 19 
     | 
    
         
            +
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
                // 正規母集団の母分散の検定量
         
     | 
| 
      
 21 
     | 
    
         
            +
                public double populationVar(double[] xi, double sig0) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                    int n = xi.length;
         
     | 
| 
      
 23 
     | 
    
         
            +
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
      
 24 
     | 
    
         
            +
                    Arrays.stream(xi).forEach(stat::addValue);
         
     | 
| 
      
 25 
     | 
    
         
            +
                    double s2 = stat.getVariance();// 分散
         
     | 
| 
      
 26 
     | 
    
         
            +
                  
         
     | 
| 
      
 27 
     | 
    
         
            +
                    return (n - 1) * s2 / sig0;
         
     | 
| 
      
 28 
     | 
    
         
            +
                }
         
     | 
| 
      
 29 
     | 
    
         
            +
                // 母比率の検定量
         
     | 
| 
      
 30 
     | 
    
         
            +
                public double populationRatio(int m, int n, double p0) {
         
     | 
| 
      
 31 
     | 
    
         
            +
                    double p = (double)m / (double)n;
         
     | 
| 
      
 32 
     | 
    
         
            +
                    return (p - p0) / Math.sqrt(p0 * (1-p0) / n);
         
     | 
| 
      
 33 
     | 
    
         
            +
                }
         
     | 
| 
      
 34 
     | 
    
         
            +
                // 2つの母平均の差の検定量
         
     | 
| 
      
 35 
     | 
    
         
            +
                // (等分散性を仮定)
         
     | 
| 
      
 36 
     | 
    
         
            +
                public double diffPopulationMean2EquVar(double[] xi1, double[] xi2) {
         
     | 
| 
      
 37 
     | 
    
         
            +
                    int n1 = xi1.length;
         
     | 
| 
      
 38 
     | 
    
         
            +
                    int n2 = xi2.length;
         
     | 
| 
      
 39 
     | 
    
         
            +
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
      
 40 
     | 
    
         
            +
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
      
 41 
     | 
    
         
            +
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
      
 42 
     | 
    
         
            +
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                    double m1 = stat1.getMean();
         
     | 
| 
      
 45 
     | 
    
         
            +
                    double m2 = stat2.getMean();
         
     | 
| 
      
 46 
     | 
    
         
            +
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
      
 47 
     | 
    
         
            +
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
      
 48 
     | 
    
         
            +
                    double s2 = ((n1 - 1) * s12 + (n2 - 1) * s22) / (n1 + n2 - 2);
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    return (m1 - m2) / Math.sqrt((1.0 / n1 + 1.0 / n2) * s2);
         
     | 
| 
      
 51 
     | 
    
         
            +
                }
         
     | 
| 
      
 52 
     | 
    
         
            +
                // 2つの母平均の差の検定量
         
     | 
| 
      
 53 
     | 
    
         
            +
                // (不等分散性を仮定)
         
     | 
| 
      
 54 
     | 
    
         
            +
                public double diffPopulationMean2UnEquVar(double[] xi1, double[] xi2) {
         
     | 
| 
      
 55 
     | 
    
         
            +
                    int n1 = xi1.length;
         
     | 
| 
      
 56 
     | 
    
         
            +
                    int n2 = xi2.length;
         
     | 
| 
      
 57 
     | 
    
         
            +
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
      
 58 
     | 
    
         
            +
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
      
 59 
     | 
    
         
            +
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
      
 60 
     | 
    
         
            +
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                    double m1 = stat1.getMean();
         
     | 
| 
      
 63 
     | 
    
         
            +
                    double m2 = stat2.getMean();
         
     | 
| 
      
 64 
     | 
    
         
            +
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
      
 65 
     | 
    
         
            +
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                    return (m1 - m2) / Math.sqrt(s12 / n1 + s22 / n2);
         
     | 
| 
      
 68 
     | 
    
         
            +
                }
         
     | 
| 
      
 69 
     | 
    
         
            +
                // ウェルチ検定の為の自由度
         
     | 
| 
      
 70 
     | 
    
         
            +
                public int df4welch(double[] xi1, double[] xi2) {
         
     | 
| 
      
 71 
     | 
    
         
            +
                    int n1 = xi1.length;
         
     | 
| 
      
 72 
     | 
    
         
            +
                    int n2 = xi2.length;
         
     | 
| 
      
 73 
     | 
    
         
            +
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
      
 74 
     | 
    
         
            +
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
      
 75 
     | 
    
         
            +
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
      
 76 
     | 
    
         
            +
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
      
 79 
     | 
    
         
            +
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
      
 80 
     | 
    
         
            +
                    double s14 = s12 * s12;
         
     | 
| 
      
 81 
     | 
    
         
            +
                    double s24 = s22 * s22;
         
     | 
| 
      
 82 
     | 
    
         
            +
                    int n12 = n1 * n1;
         
     | 
| 
      
 83 
     | 
    
         
            +
                    int n22 = n2 * n2;
         
     | 
| 
      
 84 
     | 
    
         
            +
                    double ns = (s12 / n1) + (s22 / n2);
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                    return (int)
         
     | 
| 
      
 87 
     | 
    
         
            +
                    (
         
     | 
| 
      
 88 
     | 
    
         
            +
                       (ns * ns) / 
         
     | 
| 
      
 89 
     | 
    
         
            +
                       (
         
     | 
| 
      
 90 
     | 
    
         
            +
                         s14 / (n12 * (n1 - 1)) + s24 / (n22 * (n2 - 1))
         
     | 
| 
      
 91 
     | 
    
         
            +
                       )
         
     | 
| 
      
 92 
     | 
    
         
            +
                    );
         
     | 
| 
      
 93 
     | 
    
         
            +
                }
         
     | 
| 
      
 94 
     | 
    
         
            +
                // 対応のある2つの母平均の差の検定量
         
     | 
| 
      
 95 
     | 
    
         
            +
                public double diffPopulationMean(double[] xi1, double[] xi2) {
         
     | 
| 
      
 96 
     | 
    
         
            +
                    int n = xi1.length;
         
     | 
| 
      
 97 
     | 
    
         
            +
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                    for(int i = 0; i < n; i++) {
         
     | 
| 
      
 100 
     | 
    
         
            +
                        stat.addValue(xi1[i] - xi2[i]);
         
     | 
| 
      
 101 
     | 
    
         
            +
                    }
         
     | 
| 
      
 102 
     | 
    
         
            +
                    double m = stat.getMean();
         
     | 
| 
      
 103 
     | 
    
         
            +
                    double s2 = stat.getVariance();// 分散
         
     | 
| 
      
 104 
     | 
    
         
            +
                  
         
     | 
| 
      
 105 
     | 
    
         
            +
                    return (m - 0) / Math.sqrt(s2/n);
         
     | 
| 
      
 106 
     | 
    
         
            +
                }
         
     | 
| 
      
 107 
     | 
    
         
            +
                // 2つの母分散の差の検定量
         
     | 
| 
      
 108 
     | 
    
         
            +
                public double diffPopulationVar(double[] xi1, double[] xi2) {
         
     | 
| 
      
 109 
     | 
    
         
            +
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
      
 110 
     | 
    
         
            +
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
      
 111 
     | 
    
         
            +
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
      
 112 
     | 
    
         
            +
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
      
 115 
     | 
    
         
            +
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
      
 116 
     | 
    
         
            +
                    return s12 / s22;
         
     | 
| 
      
 117 
     | 
    
         
            +
                }
         
     | 
| 
      
 118 
     | 
    
         
            +
                // 2つの母比率の差の検定量
         
     | 
| 
      
 119 
     | 
    
         
            +
                public double diffPopulationRatio(int m1, int n1, int m2, int n2) {
         
     | 
| 
      
 120 
     | 
    
         
            +
                    double p1 = (double)m1 / (double)n1;
         
     | 
| 
      
 121 
     | 
    
         
            +
                    double p2 = (double)m2 / (double)n2;
         
     | 
| 
      
 122 
     | 
    
         
            +
                    double p = (double)(m1 + m2) / (double)(n1 + n2);
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                    return (p1 - p2) / Math.sqrt(p * (1 - p) * (1.0 / n1 + 1.0 / n2));
         
     | 
| 
      
 125 
     | 
    
         
            +
                }
         
     | 
| 
      
 126 
     | 
    
         
            +
                // ピアソン相関係数
         
     | 
| 
      
 127 
     | 
    
         
            +
                public double pearsoCorrelation(double[] x, double[] y) {
         
     | 
| 
      
 128 
     | 
    
         
            +
                    PearsonsCorrelation corel = new PearsonsCorrelation();
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                    return corel.correlation(x, y);
         
     | 
| 
      
 131 
     | 
    
         
            +
                }
         
     | 
| 
      
 132 
     | 
    
         
            +
                // 適合度の検定量
         
     | 
| 
      
 133 
     | 
    
         
            +
                public double fidelity(double[] fi, double[] pi) {
         
     | 
| 
      
 134 
     | 
    
         
            +
                    double[] e = new double[fi.length];
         
     | 
| 
      
 135 
     | 
    
         
            +
                    double t = 0.0;
         
     | 
| 
      
 136 
     | 
    
         
            +
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                    Arrays.stream(fi).forEach(stat::addValue);
         
     | 
| 
      
 139 
     | 
    
         
            +
                    double s = stat.getSum();
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                    for (int i = 0; i < fi.length; i++) {
         
     | 
| 
      
 142 
     | 
    
         
            +
                        e[i] = s * pi[i];
         
     | 
| 
      
 143 
     | 
    
         
            +
                        double f_e = fi[i] - e[i];
         
     | 
| 
      
 144 
     | 
    
         
            +
                        t += f_e * f_e / e[i];
         
     | 
| 
      
 145 
     | 
    
         
            +
                    }
         
     | 
| 
      
 146 
     | 
    
         
            +
                    return t;
         
     | 
| 
      
 147 
     | 
    
         
            +
                }
         
     | 
| 
      
 148 
     | 
    
         
            +
                // 独立性の検定量
         
     | 
| 
      
 149 
     | 
    
         
            +
                public double independency(double[][] fij) {
         
     | 
| 
      
 150 
     | 
    
         
            +
                    Independency indep = new Independency(fij);
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                    indep.calsCells();
         
     | 
| 
      
 153 
     | 
    
         
            +
                    double t = indep.calcStatistic();
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                    return t;
         
     | 
| 
      
 156 
     | 
    
         
            +
                }
         
     | 
| 
      
 157 
     | 
    
         
            +
                private class Independency {
         
     | 
| 
      
 158 
     | 
    
         
            +
                    private double[] fa = null;
         
     | 
| 
      
 159 
     | 
    
         
            +
                    private double[] fb = null;
         
     | 
| 
      
 160 
     | 
    
         
            +
                    private double[][] fij = null;
         
     | 
| 
      
 161 
     | 
    
         
            +
                    private long n = 0;
         
     | 
| 
      
 162 
     | 
    
         
            +
                    public Independency(double[][] fij) {
         
     | 
| 
      
 163 
     | 
    
         
            +
                        fa = new double[fij.length];
         
     | 
| 
      
 164 
     | 
    
         
            +
                        fb = new double[fij[0].length];
         
     | 
| 
      
 165 
     | 
    
         
            +
                        this.fij = fij;
         
     | 
| 
      
 166 
     | 
    
         
            +
                    }
         
     | 
| 
      
 167 
     | 
    
         
            +
                    // 各セルの計算
         
     | 
| 
      
 168 
     | 
    
         
            +
                    public void calsCells() {
         
     | 
| 
      
 169 
     | 
    
         
            +
                        for (int i = 0; i < fij.length; i++) {
         
     | 
| 
      
 170 
     | 
    
         
            +
                            fa[i] = 0.0;
         
     | 
| 
      
 171 
     | 
    
         
            +
                            for (int j = 0; j < fij[i].length; j++)  {
         
     | 
| 
      
 172 
     | 
    
         
            +
                                fa[i] += fij[i][j];
         
     | 
| 
      
 173 
     | 
    
         
            +
                                fb[j] += fij[i][j];
         
     | 
| 
      
 174 
     | 
    
         
            +
                                n += fij[i][j];
         
     | 
| 
      
 175 
     | 
    
         
            +
                            }
         
     | 
| 
      
 176 
     | 
    
         
            +
                        }
         
     | 
| 
      
 177 
     | 
    
         
            +
                    }
         
     | 
| 
      
 178 
     | 
    
         
            +
                    // 検定統計量計算
         
     | 
| 
      
 179 
     | 
    
         
            +
                    public double calcStatistic() {
         
     | 
| 
      
 180 
     | 
    
         
            +
                        double t = 0.0;
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                        for (int i = 0; i < fij.length; i++) {
         
     | 
| 
      
 183 
     | 
    
         
            +
                            for (int j = 0; j < fij[i].length; j++)  {
         
     | 
| 
      
 184 
     | 
    
         
            +
                                double f_e = n * fij[i][j] - fa[i] * fb[j];
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                                t += f_e * f_e / (n * fa[i] * fb[j]);
         
     | 
| 
      
 187 
     | 
    
         
            +
                            }
         
     | 
| 
      
 188 
     | 
    
         
            +
                        }
         
     | 
| 
      
 189 
     | 
    
         
            +
                        return t;
         
     | 
| 
      
 190 
     | 
    
         
            +
                    }
         
     | 
| 
      
 191 
     | 
    
         
            +
                }
         
     | 
| 
      
 192 
     | 
    
         
            +
            }
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
         @@ -1,177 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            import java.util.Arrays;
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
         
     | 
| 
       4 
     | 
    
         
            -
            import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;
         
     | 
| 
       5 
     | 
    
         
            -
            import org.apache.commons.math3.stat.inference.WilcoxonSignedRankTest;
         
     | 
| 
       6 
4 
     | 
    
         
             
            public class TstStatistic {
         
     | 
| 
       7 
     | 
    
         
            -
                public static double populationMean(double[] xi, double m0) {
         
     | 
| 
       8 
     | 
    
         
            -
                    int n = xi.length;
         
     | 
| 
       9 
     | 
    
         
            -
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                    Arrays.stream(xi).forEach(stat::addValue);
         
     | 
| 
       12 
     | 
    
         
            -
                    double m = stat.getMean();     // 平均
         
     | 
| 
       13 
     | 
    
         
            -
                    double s2 = stat.getVariance();// 分散
         
     | 
| 
       14 
     | 
    
         
            -
                    return (m - m0) / Math.sqrt(s2 / n);
         
     | 
| 
       15 
     | 
    
         
            -
                }
         
     | 
| 
       16 
     | 
    
         
            -
                public static double populationVar(double[] xi, double sig0) {
         
     | 
| 
       17 
     | 
    
         
            -
                    int n = xi.length;
         
     | 
| 
       18 
     | 
    
         
            -
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
       19 
     | 
    
         
            -
                    Arrays.stream(xi).forEach(stat::addValue);
         
     | 
| 
       20 
     | 
    
         
            -
                    double s2 = stat.getVariance();// 分散
         
     | 
| 
       21 
     | 
    
         
            -
                    
         
     | 
| 
       22 
     | 
    
         
            -
                    return (n - 1) * s2 / sig0;
         
     | 
| 
       23 
     | 
    
         
            -
                }
         
     | 
| 
       24 
     | 
    
         
            -
                public static double populationRatio(int m, int n, double p0) {
         
     | 
| 
       25 
     | 
    
         
            -
                    double p = (double)m / (double)n;
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                    return (p - p0) / Math.sqrt(p0 * (1-p0) / n);
         
     | 
| 
       28 
     | 
    
         
            -
                }
         
     | 
| 
       29 
     | 
    
         
            -
                public static double diffPopulationMean2EquVar(double[] xi1, double[] xi2) {
         
     | 
| 
       30 
     | 
    
         
            -
                    int n1 = xi1.length;
         
     | 
| 
       31 
     | 
    
         
            -
                    int n2 = xi2.length;
         
     | 
| 
       32 
     | 
    
         
            -
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
       33 
     | 
    
         
            -
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
       34 
     | 
    
         
            -
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
       35 
     | 
    
         
            -
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                    double m1 = stat1.getMean();
         
     | 
| 
       38 
     | 
    
         
            -
                    double m2 = stat2.getMean();
         
     | 
| 
       39 
     | 
    
         
            -
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
       40 
     | 
    
         
            -
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
       41 
     | 
    
         
            -
                    double s2 = ((n1 - 1) * s12 + (n2 - 1) * s22) / (n1 + n2 - 2);
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                    return (m1 - m2) / Math.sqrt((1.0 / n1 + 1.0 / n2) * s2);
         
     | 
| 
       44 
     | 
    
         
            -
                }
         
     | 
| 
       45 
     | 
    
         
            -
                public static double diffPopulationMean2UnEquVar(double[] xi1, double[] xi2) {
         
     | 
| 
       46 
     | 
    
         
            -
                    int n1 = xi1.length;
         
     | 
| 
       47 
     | 
    
         
            -
                    int n2 = xi2.length;
         
     | 
| 
       48 
     | 
    
         
            -
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
       49 
     | 
    
         
            -
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
       50 
     | 
    
         
            -
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
       51 
     | 
    
         
            -
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
                    double m1 = stat1.getMean();
         
     | 
| 
       54 
     | 
    
         
            -
                    double m2 = stat2.getMean();
         
     | 
| 
       55 
     | 
    
         
            -
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
       56 
     | 
    
         
            -
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                    return (m1 - m2) / Math.sqrt(s12 / n1 + s22 / n2);
         
     | 
| 
       59 
     | 
    
         
            -
                }
         
     | 
| 
       60 
     | 
    
         
            -
                public static int df4welch(double[] xi1, double[] xi2) {
         
     | 
| 
       61 
     | 
    
         
            -
                    int n1 = xi1.length;
         
     | 
| 
       62 
     | 
    
         
            -
                    int n2 = xi2.length;
         
     | 
| 
       63 
     | 
    
         
            -
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
       64 
     | 
    
         
            -
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
       65 
     | 
    
         
            -
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
       66 
     | 
    
         
            -
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
       69 
     | 
    
         
            -
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
       70 
     | 
    
         
            -
                    double s14 = s12 * s12;
         
     | 
| 
       71 
     | 
    
         
            -
                    double s24 = s22 * s22;
         
     | 
| 
       72 
     | 
    
         
            -
                    int n12 = n1 * n1;
         
     | 
| 
       73 
     | 
    
         
            -
                    int n22 = n2 * n2;
         
     | 
| 
       74 
     | 
    
         
            -
                    double ns = (s12 / n1) + (s22 / n2);
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                    return (int)
         
     | 
| 
       77 
     | 
    
         
            -
                    (
         
     | 
| 
       78 
     | 
    
         
            -
                       (ns * ns) / 
         
     | 
| 
       79 
     | 
    
         
            -
                       (
         
     | 
| 
       80 
     | 
    
         
            -
                         s14 / (n12 * (n1 - 1)) + s24 / (n22 * (n2 - 1))
         
     | 
| 
       81 
     | 
    
         
            -
                       )
         
     | 
| 
       82 
     | 
    
         
            -
                     );
         
     | 
| 
       83 
     | 
    
         
            -
                }
         
     | 
| 
       84 
     | 
    
         
            -
                public static double diffPopulationMean(double[] xi1, double[] xi2) {
         
     | 
| 
       85 
     | 
    
         
            -
                    int n = xi1.length;
         
     | 
| 
       86 
     | 
    
         
            -
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
                    for(int i = 0; i < n; i++) {
         
     | 
| 
       89 
     | 
    
         
            -
                        stat.addValue(xi1[i] - xi2[i]);
         
     | 
| 
       90 
     | 
    
         
            -
                    }
         
     | 
| 
       91 
     | 
    
         
            -
                    double m = stat.getMean();
         
     | 
| 
       92 
     | 
    
         
            -
                    double s2 = stat.getVariance();// 分散
         
     | 
| 
       93 
     | 
    
         
            -
                    
         
     | 
| 
       94 
     | 
    
         
            -
                    return (m - 0) / Math.sqrt(s2/n);
         
     | 
| 
       95 
     | 
    
         
            -
                }
         
     | 
| 
       96 
     | 
    
         
            -
                public static double diffPopulationVar(double[] xi1, double[] xi2) {
         
     | 
| 
       97 
     | 
    
         
            -
                    SummaryStatistics stat1 = new SummaryStatistics();
         
     | 
| 
       98 
     | 
    
         
            -
                    SummaryStatistics stat2 = new SummaryStatistics();
         
     | 
| 
       99 
     | 
    
         
            -
                    Arrays.stream(xi1).forEach(stat1::addValue);
         
     | 
| 
       100 
     | 
    
         
            -
                    Arrays.stream(xi2).forEach(stat2::addValue);
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                    double s12 = stat1.getVariance();// 分散
         
     | 
| 
       103 
     | 
    
         
            -
                    double s22 = stat2.getVariance();// 分散
         
     | 
| 
       104 
     | 
    
         
            -
                    return s12 / s22;
         
     | 
| 
       105 
     | 
    
         
            -
                }
         
     | 
| 
       106 
     | 
    
         
            -
                public static double diffPopulationRatio(int m1, int n1, int m2, int n2) {
         
     | 
| 
       107 
     | 
    
         
            -
                    double p1 = (double)m1 / (double)n1;
         
     | 
| 
       108 
     | 
    
         
            -
                    double p2 = (double)m2 / (double)n2;
         
     | 
| 
       109 
     | 
    
         
            -
                    double p = (double)(m1 + m2) / (double)(n1 + n2);
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                    return (p1 - p2) / Math.sqrt(p * (1 - p) * (1.0 / n1 + 1.0 / n2));
         
     | 
| 
       112 
     | 
    
         
            -
                }
         
     | 
| 
       113 
     | 
    
         
            -
                public static double unCorrelation(double[] x, double[] y) {
         
     | 
| 
       114 
     | 
    
         
            -
                    int n = x.length;
         
     | 
| 
       115 
     | 
    
         
            -
                    PearsonsCorrelation corel = new PearsonsCorrelation();
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
                    double r = corel.correlation(x, y);
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                    return r * Math.sqrt(n - 2.0) / Math.sqrt(1.0 - r * r);
         
     | 
| 
       120 
     | 
    
         
            -
                }
         
     | 
| 
       121 
     | 
    
         
            -
                public static double populationCorre(double[] x, double[] y, double rth0) {
         
     | 
| 
       122 
     | 
    
         
            -
                    int n = x.length;
         
     | 
| 
       123 
     | 
    
         
            -
                    PearsonsCorrelation corel = new PearsonsCorrelation();
         
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
                    double r = corel.correlation(x, y);
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                    return Math.sqrt(n-3.0) * 
         
     | 
| 
       128 
     | 
    
         
            -
                           (
         
     | 
| 
       129 
     | 
    
         
            -
                           0.5 * Math.log((1.0 + r) / (1.0 - r)) 
         
     | 
| 
       130 
     | 
    
         
            -
                         - 0.5 * Math.log((1.0 + rth0) / (1.0 - rth0))
         
     | 
| 
       131 
     | 
    
         
            -
                           );
         
     | 
| 
       132 
     | 
    
         
            -
                }
         
     | 
| 
       133 
     | 
    
         
            -
                public static double fidelity(double[] fi, double[] pi) {
         
     | 
| 
       134 
     | 
    
         
            -
                    double[] e = new double[fi.length];
         
     | 
| 
       135 
     | 
    
         
            -
                    double t = 0.0;
         
     | 
| 
       136 
     | 
    
         
            -
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
                    Arrays.stream(fi).forEach(stat::addValue);
         
     | 
| 
       139 
     | 
    
         
            -
                    double s = stat.getSum();
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
                    for (int i = 0; i < fi.length; i++) {
         
     | 
| 
       142 
     | 
    
         
            -
                        e[i] = s * pi[i];
         
     | 
| 
       143 
     | 
    
         
            -
                        double f_e = fi[i] - e[i];
         
     | 
| 
       144 
     | 
    
         
            -
                        t += f_e * f_e / e[i];
         
     | 
| 
       145 
     | 
    
         
            -
                    }
         
     | 
| 
       146 
     | 
    
         
            -
                    return t;
         
     | 
| 
       147 
     | 
    
         
            -
                }
         
     | 
| 
       148 
     | 
    
         
            -
                public static double independency(double[][] fij) {
         
     | 
| 
       149 
     | 
    
         
            -
                    double t = 0.0;
         
     | 
| 
       150 
     | 
    
         
            -
                    long n = 0;
         
     | 
| 
       151 
     | 
    
         
            -
                    double[] fa = new double[fij.length];
         
     | 
| 
       152 
     | 
    
         
            -
                    double[] fb = new double[fij[0].length];
         
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
                    // 各セルの計算
         
     | 
| 
       155 
     | 
    
         
            -
                    for (int i = 0; i < fij.length; i++) {
         
     | 
| 
       156 
     | 
    
         
            -
                        fa[i] = 0.0;
         
     | 
| 
       157 
     | 
    
         
            -
                        for (int j = 0; j < fij[i].length; j++)  {
         
     | 
| 
       158 
     | 
    
         
            -
                            fa[i] += fij[i][j];
         
     | 
| 
       159 
     | 
    
         
            -
                            fb[j] += fij[i][j];
         
     | 
| 
       160 
     | 
    
         
            -
                            n += fij[i][j];
         
     | 
| 
       161 
     | 
    
         
            -
                        }
         
     | 
| 
       162 
     | 
    
         
            -
                    }
         
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
                    // 検定統計量計算
         
     | 
| 
       165 
     | 
    
         
            -
                    for (int i = 0; i < fij.length; i++) {
         
     | 
| 
       166 
     | 
    
         
            -
                        for (int j = 0; j < fij[i].length; j++)  {
         
     | 
| 
       167 
     | 
    
         
            -
                            double f_e = n * fij[i][j] - fa[i] * fb[j];
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
                            t += f_e * f_e / (n * fa[i] * fb[j]);
         
     | 
| 
       170 
     | 
    
         
            -
                        }
         
     | 
| 
       171 
     | 
    
         
            -
                    }
         
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
                    return t;
         
     | 
| 
       174 
     | 
    
         
            -
                }
         
     | 
| 
       175 
5 
     | 
    
         
             
                public static double grubbs(double[] xi, double xk) {
         
     | 
| 
       176 
6 
     | 
    
         
             
                    SummaryStatistics stat = new SummaryStatistics();
         
     | 
| 
       177 
7 
     | 
    
         | 
| 
         @@ -186,11 +16,6 @@ public class TstStatistic { 
     | 
|
| 
       186 
16 
     | 
    
         
             
                    if (xk == max) { t = (xk - m) / sd; }
         
     | 
| 
       187 
17 
     | 
    
         
             
                    return t;
         
     | 
| 
       188 
18 
     | 
    
         
             
                }
         
     | 
| 
       189 
     | 
    
         
            -
                public static double wilcoxon(double[] x, double[] y) {
         
     | 
| 
       190 
     | 
    
         
            -
                    WilcoxonSignedRankTest wilcox = new WilcoxonSignedRankTest();
         
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
                    return wilcox.wilcoxonSignedRank(x, y); 
         
     | 
| 
       193 
     | 
    
         
            -
                }
         
     | 
| 
       194 
19 
     | 
    
         
             
            }
         
     | 
| 
       195 
20 
     | 
    
         | 
| 
       196 
21 
     | 
    
         | 
    
        data/lib/num4tststatistic.rb
    CHANGED
    
    | 
         @@ -3,11 +3,16 @@ require 'num4tststatistic.jar' 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'commons-math3-3.6.1.jar'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            java_import 'TstStatistic'
         
     | 
| 
      
 6 
     | 
    
         
            +
            java_import 'ParametrixTest'
         
     | 
| 
      
 7 
     | 
    
         
            +
            java_import 'NonParametrixTest'
         
     | 
| 
       6 
8 
     | 
    
         | 
| 
       7 
9 
     | 
    
         
             
            # 検定統計量を計算
         
     | 
| 
       8 
10 
     | 
    
         
             
            #  (Apache commoms math3使用)
         
     | 
| 
       9 
11 
     | 
    
         
             
            module Num4TstStatisticLib
         
     | 
| 
       10 
     | 
    
         
            -
                class  
     | 
| 
      
 12 
     | 
    
         
            +
                class ParametrixTestLib
         
     | 
| 
      
 13 
     | 
    
         
            +
                    def initialize
         
     | 
| 
      
 14 
     | 
    
         
            +
                        @paramTest = ParametrixTest.getInstance()
         
     | 
| 
      
 15 
     | 
    
         
            +
                    end
         
     | 
| 
       11 
16 
     | 
    
         
             
                    # 正規母集団の母平均の検定量
         
     | 
| 
       12 
17 
     | 
    
         
             
                    #
         
     | 
| 
       13 
18 
     | 
    
         
             
                    # @overload populationMean(xi, m0)
         
     | 
| 
         @@ -16,12 +21,13 @@ module Num4TstStatisticLib 
     | 
|
| 
       16 
21 
     | 
    
         
             
                    #   @return [double] 検定統計量
         
     | 
| 
       17 
22 
     | 
    
         
             
                    # @example
         
     | 
| 
       18 
23 
     | 
    
         
             
                    #   xi = [15.5, 15.7, 15.4, 15.4, 15.6, 15.4, 15.6, 15.5, 15.4]
         
     | 
| 
       19 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 24 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 25 
     | 
    
         
            +
                    #   paraTest.populationMean(xi, 15.4)
         
     | 
| 
       20 
26 
     | 
    
         
             
                    #   => 2.683
         
     | 
| 
       21 
27 
     | 
    
         
             
                    # @note
         
     | 
| 
       22 
28 
     | 
    
         
             
                    #   自由度(N-1)のt分布に従う
         
     | 
| 
       23 
29 
     | 
    
         
             
                    def populationMean(xi, m0)
         
     | 
| 
       24 
     | 
    
         
            -
                        return  
     | 
| 
      
 30 
     | 
    
         
            +
                        return @paramTest.populationMean(xi.to_java(Java::double), m0)
         
     | 
| 
       25 
31 
     | 
    
         
             
                    end
         
     | 
| 
       26 
32 
     | 
    
         
             
                    # 正規母集団の母分散の検定量
         
     | 
| 
       27 
33 
     | 
    
         
             
                    #
         
     | 
| 
         @@ -32,26 +38,29 @@ module Num4TstStatisticLib 
     | 
|
| 
       32 
38 
     | 
    
         
             
                    # @example
         
     | 
| 
       33 
39 
     | 
    
         
             
                    #   xi = xi = [35.2, 34.5, 34.9, 35.2, 34.8, 35.1, 34.9, 35.2, 34.9, 34.8]
         
     | 
| 
       34 
40 
     | 
    
         
             
                    #   sd = 0.4
         
     | 
| 
       35 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 41 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 42 
     | 
    
         
            +
                    #   paraTest.populationVar(xi, sd*sd)
         
     | 
| 
       36 
43 
     | 
    
         
             
                    #   => 2.906
         
     | 
| 
       37 
44 
     | 
    
         
             
                    # @note
         
     | 
| 
       38 
45 
     | 
    
         
             
                    #   自由度(N-1)の階2乗分布に従う
         
     | 
| 
       39 
46 
     | 
    
         
             
                    def populationVar(xi, sig0)
         
     | 
| 
       40 
     | 
    
         
            -
                        return  
     | 
| 
      
 47 
     | 
    
         
            +
                        return @paramTest.populationVar(xi.to_java(Java::double), sig0)
         
     | 
| 
       41 
48 
     | 
    
         
             
                    end
         
     | 
| 
       42 
49 
     | 
    
         
             
                    # 母比率の検定量
         
     | 
| 
      
 50 
     | 
    
         
            +
                    #
         
     | 
| 
       43 
51 
     | 
    
         
             
                    # @overload populationRatio(m, n, p0)
         
     | 
| 
       44 
52 
     | 
    
         
             
                    #   @param [int]     m m値
         
     | 
| 
       45 
53 
     | 
    
         
             
                    #   @param [int]     n N値
         
     | 
| 
       46 
54 
     | 
    
         
             
                    #   @param [double]  p0 母比率
         
     | 
| 
       47 
55 
     | 
    
         
             
                    #   @return [double] 検定統計量
         
     | 
| 
       48 
56 
     | 
    
         
             
                    # @example
         
     | 
| 
       49 
     | 
    
         
            -
                    #    
     | 
| 
      
 57 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 58 
     | 
    
         
            +
                    #   paraTest.populationRatio(29, 346, 0.12)
         
     | 
| 
       50 
59 
     | 
    
         
             
                    #   => -2.071
         
     | 
| 
       51 
60 
     | 
    
         
             
                    # @note
         
     | 
| 
       52 
61 
     | 
    
         
             
                    #   標準正規分布 N(0,1*1)に従う
         
     | 
| 
       53 
62 
     | 
    
         
             
                    def populationRatio(m, n, p0)
         
     | 
| 
       54 
     | 
    
         
            -
                        return  
     | 
| 
      
 63 
     | 
    
         
            +
                        return @paramTest.populationRatio(m, n, p0)
         
     | 
| 
       55 
64 
     | 
    
         
             
                    end
         
     | 
| 
       56 
65 
     | 
    
         
             
                    # 2つの母平均の差の検定量
         
     | 
| 
       57 
66 
     | 
    
         
             
                    # (等分散性を仮定)
         
     | 
| 
         @@ -63,12 +72,13 @@ module Num4TstStatisticLib 
     | 
|
| 
       63 
72 
     | 
    
         
             
                    # @example
         
     | 
| 
       64 
73 
     | 
    
         
             
                    #   xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
         
     | 
| 
       65 
74 
     | 
    
         
             
                    #   xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
         
     | 
| 
       66 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 75 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 76 
     | 
    
         
            +
                    #   paraTest.diffPopulationMean2EquVar(xi1, xi2)
         
     | 
| 
       67 
77 
     | 
    
         
             
                    #   => -1.765
         
     | 
| 
       68 
78 
     | 
    
         
             
                    # @note
         
     | 
| 
       69 
79 
     | 
    
         
             
                    #   N1+N2-2のt分布に従う
         
     | 
| 
       70 
80 
     | 
    
         
             
                    def diffPopulationMean2EquVar(xi1, xi2)
         
     | 
| 
       71 
     | 
    
         
            -
                        return  
     | 
| 
      
 81 
     | 
    
         
            +
                        return @paramTest.diffPopulationMean2EquVar(
         
     | 
| 
       72 
82 
     | 
    
         
             
                            xi1.to_java(Java::double), xi2.to_java(Java::double)
         
     | 
| 
       73 
83 
     | 
    
         
             
                        )
         
     | 
| 
       74 
84 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -82,16 +92,18 @@ module Num4TstStatisticLib 
     | 
|
| 
       82 
92 
     | 
    
         
             
                    # @example
         
     | 
| 
       83 
93 
     | 
    
         
             
                    #   xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
         
     | 
| 
       84 
94 
     | 
    
         
             
                    #   xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
         
     | 
| 
       85 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 95 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 96 
     | 
    
         
            +
                    #   paraTest.diffPopulationMean2UnEquVar(xi1, xi2)
         
     | 
| 
       86 
97 
     | 
    
         
             
                    #   => -1.636
         
     | 
| 
       87 
98 
     | 
    
         
             
                    # @note
         
     | 
| 
       88 
99 
     | 
    
         
             
                    #   df4welch関数で求めた自由度のt分布に従う
         
     | 
| 
       89 
100 
     | 
    
         
             
                    def diffPopulationMean2UnEquVar(xi1, xi2)
         
     | 
| 
       90 
     | 
    
         
            -
                        return  
     | 
| 
      
 101 
     | 
    
         
            +
                        return @paramTest.diffPopulationMean2UnEquVar(
         
     | 
| 
       91 
102 
     | 
    
         
             
                            xi1.to_java(Java::double), xi2.to_java(Java::double)
         
     | 
| 
       92 
103 
     | 
    
         
             
                        )
         
     | 
| 
       93 
104 
     | 
    
         
             
                    end
         
     | 
| 
       94 
105 
     | 
    
         
             
                    # ウェルチ検定の為の自由度
         
     | 
| 
      
 106 
     | 
    
         
            +
                    #
         
     | 
| 
       95 
107 
     | 
    
         
             
                    # @overload df4welch(xi1, xi2)
         
     | 
| 
       96 
108 
     | 
    
         
             
                    #   @param [Array] xi1 x1のデータ(double[])
         
     | 
| 
       97 
109 
     | 
    
         
             
                    #   @param [Array] xi2 x2のデータ(double[])
         
     | 
| 
         @@ -99,10 +111,11 @@ module Num4TstStatisticLib 
     | 
|
| 
       99 
111 
     | 
    
         
             
                    # @example
         
     | 
| 
       100 
112 
     | 
    
         
             
                    #   xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
         
     | 
| 
       101 
113 
     | 
    
         
             
                    #   xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
         
     | 
| 
       102 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 114 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 115 
     | 
    
         
            +
                    #   paraTest.df4welch(xi1, xi2)
         
     | 
| 
       103 
116 
     | 
    
         
             
                    #   => 11
         
     | 
| 
       104 
117 
     | 
    
         
             
                    def df4welch(xi1, xi2)
         
     | 
| 
       105 
     | 
    
         
            -
                        return  
     | 
| 
      
 118 
     | 
    
         
            +
                        return @paramTest.df4welch(
         
     | 
| 
       106 
119 
     | 
    
         
             
                            xi1.to_java(Java::double), xi2.to_java(Java::double)
         
     | 
| 
       107 
120 
     | 
    
         
             
                        )
         
     | 
| 
       108 
121 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -115,12 +128,13 @@ module Num4TstStatisticLib 
     | 
|
| 
       115 
128 
     | 
    
         
             
                    # @example
         
     | 
| 
       116 
129 
     | 
    
         
             
                    #   xi1 = [37.1, 36.2, 36.6, 37.4, 36.8, 36.7, 36.9, 37.4, 36.6, 36.7]
         
     | 
| 
       117 
130 
     | 
    
         
             
                    #   xi2 = [36.8, 36.6, 36.5, 37.0, 36.0, 36.5, 36.6, 37.1, 36.4, 36.7]
         
     | 
| 
       118 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 131 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 132 
     | 
    
         
            +
                    #   paraTest.diffPopulationMean(xi1, xi2)
         
     | 
| 
       119 
133 
     | 
    
         
             
                    #   => 2.283
         
     | 
| 
       120 
134 
     | 
    
         
             
                    # @note
         
     | 
| 
       121 
135 
     | 
    
         
             
                    #   自由度(N-1)のt分布に従う
         
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                        return  
     | 
| 
      
 136 
     | 
    
         
            +
                    def diffPopulationMean(xi1, xi2)
         
     | 
| 
      
 137 
     | 
    
         
            +
                        return @paramTest.diffPopulationMean(
         
     | 
| 
       124 
138 
     | 
    
         
             
                            xi1.to_java(Java::double), xi2.to_java(Java::double)
         
     | 
| 
       125 
139 
     | 
    
         
             
                        )
         
     | 
| 
       126 
140 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -133,12 +147,13 @@ module Num4TstStatisticLib 
     | 
|
| 
       133 
147 
     | 
    
         
             
                    # @example
         
     | 
| 
       134 
148 
     | 
    
         
             
                    #   xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
         
     | 
| 
       135 
149 
     | 
    
         
             
                    #   xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
         
     | 
| 
       136 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 150 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 151 
     | 
    
         
            +
                    #   paraTest.diffPopulationVar(xi1, xi2)
         
     | 
| 
       137 
152 
     | 
    
         
             
                    #   => 0.4727
         
     | 
| 
       138 
153 
     | 
    
         
             
                    # @note
         
     | 
| 
       139 
154 
     | 
    
         
             
                    #   自由度(N1-1,N2-1)のF分布に従う
         
     | 
| 
       140 
155 
     | 
    
         
             
                    def diffPopulationVar(xi1, xi2)
         
     | 
| 
       141 
     | 
    
         
            -
                        return  
     | 
| 
      
 156 
     | 
    
         
            +
                        return @paramTest.diffPopulationVar(
         
     | 
| 
       142 
157 
     | 
    
         
             
                            xi1.to_java(Java::double), xi2.to_java(Java::double)
         
     | 
| 
       143 
158 
     | 
    
         
             
                        )
         
     | 
| 
       144 
159 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -151,50 +166,32 @@ module Num4TstStatisticLib 
     | 
|
| 
       151 
166 
     | 
    
         
             
                    #   @param [int] n2 N2値
         
     | 
| 
       152 
167 
     | 
    
         
             
                    #   @return [double] 検定統計量
         
     | 
| 
       153 
168 
     | 
    
         
             
                    # @example
         
     | 
| 
       154 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 169 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 170 
     | 
    
         
            +
                    #   paraTest.diffPopulationRatio(469, 1200, 308, 900)
         
     | 
| 
       155 
171 
     | 
    
         
             
                    #   => 2.283
         
     | 
| 
       156 
172 
     | 
    
         
             
                    # @note
         
     | 
| 
       157 
173 
     | 
    
         
             
                    #   標準正規分布 N(0,1*1)に従う
         
     | 
| 
       158 
174 
     | 
    
         
             
                    def diffPopulationRatio(m1, n1, m2, n2)
         
     | 
| 
       159 
     | 
    
         
            -
                        return  
     | 
| 
      
 175 
     | 
    
         
            +
                        return @paramTest.diffPopulationRatio(m1, n1, m2, n2)
         
     | 
| 
       160 
176 
     | 
    
         
             
                    end
         
     | 
| 
       161 
     | 
    
         
            -
                    #  
     | 
| 
      
 177 
     | 
    
         
            +
                    # ピアソン相関係数
         
     | 
| 
      
 178 
     | 
    
         
            +
                    #  (相関係数の検定)
         
     | 
| 
       162 
179 
     | 
    
         
             
                    #
         
     | 
| 
       163 
     | 
    
         
            -
                    # @overload  
     | 
| 
      
 180 
     | 
    
         
            +
                    # @overload pearsoCorrelation(x, y)
         
     | 
| 
       164 
181 
     | 
    
         
             
                    #   @param [Array] x xのデータ(double[])
         
     | 
| 
       165 
182 
     | 
    
         
             
                    #   @param [Array] y yのデータ(double[])
         
     | 
| 
       166 
     | 
    
         
            -
                    #   @return [double]  
     | 
| 
      
 183 
     | 
    
         
            +
                    #   @return [double] 相関係数
         
     | 
| 
       167 
184 
     | 
    
         
             
                    # @example
         
     | 
| 
       168 
185 
     | 
    
         
             
                    #   x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
         
     | 
| 
       169 
186 
     | 
    
         
             
                    #   y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
         
     | 
| 
       170 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 187 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 188 
     | 
    
         
            +
                    #   paraTest.pearsoCorrelation(x, y)
         
     | 
| 
       171 
189 
     | 
    
         
             
                    #   => 3.1035
         
     | 
| 
       172 
     | 
    
         
            -
                     
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
                    def unCorrelation(x, y)
         
     | 
| 
       175 
     | 
    
         
            -
                        return TstStatistic.unCorrelation(
         
     | 
| 
      
 190 
     | 
    
         
            +
                    def pearsoCorrelation(x, y)
         
     | 
| 
      
 191 
     | 
    
         
            +
                        return @paramTest.pearsoCorrelation(
         
     | 
| 
       176 
192 
     | 
    
         
             
                            x.to_java(Java::double), y.to_java(Java::double)
         
     | 
| 
       177 
193 
     | 
    
         
             
                        )
         
     | 
| 
       178 
194 
     | 
    
         
             
                    end
         
     | 
| 
       179 
     | 
    
         
            -
                    # 母相関係数の検定量
         
     | 
| 
       180 
     | 
    
         
            -
                    #
         
     | 
| 
       181 
     | 
    
         
            -
                    # @overload populationCorre(x, y, rth0)
         
     | 
| 
       182 
     | 
    
         
            -
                    #   @param [Array] x xのデータ(double[])
         
     | 
| 
       183 
     | 
    
         
            -
                    #   @param [Array] y yのデータ(double[])
         
     | 
| 
       184 
     | 
    
         
            -
                    #   @param [double] rth0 母相関係数
         
     | 
| 
       185 
     | 
    
         
            -
                    #   @return [double] 検定統計量
         
     | 
| 
       186 
     | 
    
         
            -
                    # @example
         
     | 
| 
       187 
     | 
    
         
            -
                    #   x = [2750, 2956, 2675, 3198, 1816, 2233, 2375, 2288, 1932, 2036, 2183, 2882]
         
     | 
| 
       188 
     | 
    
         
            -
                    #   y = [249, 713, 1136, 575, 5654, 2107, 915, 4193, 7225, 3730, 472, 291]
         
     | 
| 
       189 
     | 
    
         
            -
                    #   Num4TstStatisticLib.populationCorre(x, y, -0.3)
         
     | 
| 
       190 
     | 
    
         
            -
                    #   => -2.107168
         
     | 
| 
       191 
     | 
    
         
            -
                    # @note
         
     | 
| 
       192 
     | 
    
         
            -
                    #   標準正規分布 N(0,1*1)に従う
         
     | 
| 
       193 
     | 
    
         
            -
                    def populationCorre(x, y, rth0)
         
     | 
| 
       194 
     | 
    
         
            -
                        return TstStatistic.populationCorre(
         
     | 
| 
       195 
     | 
    
         
            -
                            x.to_java(Java::double), y.to_java(Java::double), rth0
         
     | 
| 
       196 
     | 
    
         
            -
                        )
         
     | 
| 
       197 
     | 
    
         
            -
                    end
         
     | 
| 
       198 
195 
     | 
    
         
             
                    # 適合度の検定量
         
     | 
| 
       199 
196 
     | 
    
         
             
                    #
         
     | 
| 
       200 
197 
     | 
    
         
             
                    # @overload fidelity(fi, pi)
         
     | 
| 
         @@ -204,12 +201,13 @@ module Num4TstStatisticLib 
     | 
|
| 
       204 
201 
     | 
    
         
             
                    # @example
         
     | 
| 
       205 
202 
     | 
    
         
             
                    #   fi = [57, 33, 46, 14]
         
     | 
| 
       206 
203 
     | 
    
         
             
                    #   pi = [0.4, 0.2, 0.3, 0.1]
         
     | 
| 
       207 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 204 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 205 
     | 
    
         
            +
                    #   paraTest.fidelity(fi, pi)
         
     | 
| 
       208 
206 
     | 
    
         
             
                    #   => 0.5389
         
     | 
| 
       209 
207 
     | 
    
         
             
                    # @note
         
     | 
| 
       210 
208 
     | 
    
         
             
                    #   自由度(n-1)の階2乗分布に従う
         
     | 
| 
       211 
209 
     | 
    
         
             
                    def fidelity(fi, pi)
         
     | 
| 
       212 
     | 
    
         
            -
                        return  
     | 
| 
      
 210 
     | 
    
         
            +
                        return @paramTest.fidelity(fi.to_java(Java::double), pi.to_java(Java::double))
         
     | 
| 
       213 
211 
     | 
    
         
             
                    end
         
     | 
| 
       214 
212 
     | 
    
         
             
                    # 独立性の検定量
         
     | 
| 
       215 
213 
     | 
    
         
             
                    #
         
     | 
| 
         @@ -221,43 +219,121 @@ module Num4TstStatisticLib 
     | 
|
| 
       221 
219 
     | 
    
         
             
                    #     [57, 33, 46, 14],
         
     | 
| 
       222 
220 
     | 
    
         
             
                    #     [89, 24, 75, 12],
         
     | 
| 
       223 
221 
     | 
    
         
             
                    #   ]
         
     | 
| 
       224 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
      
 222 
     | 
    
         
            +
                    #   paraTest = Num4TstStatisticLib::ParametrixTestLib.new
         
     | 
| 
      
 223 
     | 
    
         
            +
                    #   paraTest.independency(fij)
         
     | 
| 
       225 
224 
     | 
    
         
             
                    #   => 8.5711
         
     | 
| 
       226 
225 
     | 
    
         
             
                    # @note
         
     | 
| 
       227 
226 
     | 
    
         
             
                    #   自由度(m-1)(n-1)の階2乗分布に従う
         
     | 
| 
       228 
227 
     | 
    
         
             
                    def independency(fij)
         
     | 
| 
       229 
     | 
    
         
            -
                        return  
     | 
| 
      
 228 
     | 
    
         
            +
                        return @paramTest.independency(fij.to_java(Java::double[]))
         
     | 
| 
       230 
229 
     | 
    
         
             
                    end
         
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
      
 230 
     | 
    
         
            +
                end
         
     | 
| 
      
 231 
     | 
    
         
            +
                class NonParametrixTestLib
         
     | 
| 
      
 232 
     | 
    
         
            +
                    def initialize
         
     | 
| 
      
 233 
     | 
    
         
            +
                        @nonParamTest = NonParametrixTest.getInstance()
         
     | 
| 
      
 234 
     | 
    
         
            +
                    end
         
     | 
| 
      
 235 
     | 
    
         
            +
                    # マン・ホイットニーのU検定
         
     | 
| 
       232 
236 
     | 
    
         
             
                    #
         
     | 
| 
       233 
     | 
    
         
            -
                    # @overload  
     | 
| 
       234 
     | 
    
         
            -
                    #   @param [Array]  
     | 
| 
       235 
     | 
    
         
            -
                    #   @param [ 
     | 
| 
      
 237 
     | 
    
         
            +
                    # @overload utest(x, y)
         
     | 
| 
      
 238 
     | 
    
         
            +
                    #   @param [Array] x xのデータ(double[])
         
     | 
| 
      
 239 
     | 
    
         
            +
                    #   @param [Array] y yのデータ(double[])
         
     | 
| 
       236 
240 
     | 
    
         
             
                    #   @return [double] 検定統計量
         
     | 
| 
       237 
241 
     | 
    
         
             
                    # @example
         
     | 
| 
       238 
     | 
    
         
            -
                    #    
     | 
| 
       239 
     | 
    
         
            -
                    #    
     | 
| 
       240 
     | 
    
         
            -
                    #    
     | 
| 
      
 242 
     | 
    
         
            +
                    #   x = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
         
     | 
| 
      
 243 
     | 
    
         
            +
                    #   y = [180, 180, 235, 270, 240, 285, 164, 152]
         
     | 
| 
      
 244 
     | 
    
         
            +
                    #   nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
         
     | 
| 
      
 245 
     | 
    
         
            +
                    #   nonParaTest.utest(x, y)
         
     | 
| 
      
 246 
     | 
    
         
            +
                    #   => 63.0
         
     | 
| 
       241 
247 
     | 
    
         
             
                    # @note
         
     | 
| 
       242 
     | 
    
         
            -
                    #    
     | 
| 
       243 
     | 
    
         
            -
                    def  
     | 
| 
       244 
     | 
    
         
            -
                        return  
     | 
| 
      
 248 
     | 
    
         
            +
                    #   近似的に標準正規分布 N(0,1*1)に従う
         
     | 
| 
      
 249 
     | 
    
         
            +
                    def utest(x, y)
         
     | 
| 
      
 250 
     | 
    
         
            +
                        return @nonParamTest.utest(x.to_java(Java::double), y.to_java(Java::double))
         
     | 
| 
       245 
251 
     | 
    
         
             
                    end
         
     | 
| 
       246 
252 
     | 
    
         
             
                    # ウィルコクス符号付き順位検定
         
     | 
| 
       247 
253 
     | 
    
         
             
                    #
         
     | 
| 
       248 
     | 
    
         
            -
                    # @overload  
     | 
| 
      
 254 
     | 
    
         
            +
                    # @overload wilcoxontest(x, y)
         
     | 
| 
       249 
255 
     | 
    
         
             
                    #   @param [Array] x xのデータ(double[])
         
     | 
| 
       250 
256 
     | 
    
         
             
                    #   @param [Array] y yのデータ(double[])
         
     | 
| 
       251 
257 
     | 
    
         
             
                    #   @return [double] 検定統計量
         
     | 
| 
       252 
258 
     | 
    
         
             
                    # @example
         
     | 
| 
       253 
     | 
    
         
            -
                    #   x = [ 
     | 
| 
       254 
     | 
    
         
            -
                    #   y = [ 
     | 
| 
       255 
     | 
    
         
            -
                    #   Num4TstStatisticLib. 
     | 
| 
       256 
     | 
    
         
            -
                    #    
     | 
| 
      
 259 
     | 
    
         
            +
                    #   x = [37.1, 36.2, 36.6, 37.4, 36.8, 36.7, 36.9, 37.4, 36.6, 36.7]
         
     | 
| 
      
 260 
     | 
    
         
            +
                    #   y = [36.8, 36.6, 36.5, 37.0, 36.0, 36.5, 36.6, 37.1, 36.4, 36.7]
         
     | 
| 
      
 261 
     | 
    
         
            +
                    #   nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
         
     | 
| 
      
 262 
     | 
    
         
            +
                    #   nonParaTest.wilcoxon(x, y)
         
     | 
| 
      
 263 
     | 
    
         
            +
                    #   => 46.5
         
     | 
| 
       257 
264 
     | 
    
         
             
                    # @note
         
     | 
| 
       258 
     | 
    
         
            -
                    #    
     | 
| 
      
 265 
     | 
    
         
            +
                    #   近似的に標準正規分布 N(0,1*1)に従う
         
     | 
| 
       259 
266 
     | 
    
         
             
                    def wilcoxon(x, y)
         
     | 
| 
       260 
     | 
    
         
            -
                        return  
     | 
| 
      
 267 
     | 
    
         
            +
                        return @nonParamTest.wilcoxon(x.to_java(Java::double), y.to_java(Java::double))
         
     | 
| 
      
 268 
     | 
    
         
            +
                    end
         
     | 
| 
      
 269 
     | 
    
         
            +
                    # スピアマンの順位相関係数
         
     | 
| 
      
 270 
     | 
    
         
            +
                    #
         
     | 
| 
      
 271 
     | 
    
         
            +
                    # @overload spearmanscorr(x, y)
         
     | 
| 
      
 272 
     | 
    
         
            +
                    #   @param [Array] x xのデータ(double[])
         
     | 
| 
      
 273 
     | 
    
         
            +
                    #   @param [Array] y yのデータ(double[])
         
     | 
| 
      
 274 
     | 
    
         
            +
                    #   @return [double] 相関係数
         
     | 
| 
      
 275 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 276 
     | 
    
         
            +
                    #   x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
         
     | 
| 
      
 277 
     | 
    
         
            +
                    #   y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
         
     | 
| 
      
 278 
     | 
    
         
            +
                    #   nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
         
     | 
| 
      
 279 
     | 
    
         
            +
                    #   nonParaTest.spearmanscorr(x, y)
         
     | 
| 
      
 280 
     | 
    
         
            +
                    #   => 0.745
         
     | 
| 
      
 281 
     | 
    
         
            +
                    # @note
         
     | 
| 
      
 282 
     | 
    
         
            +
                    #   無相関検定
         
     | 
| 
      
 283 
     | 
    
         
            +
                    def spearmanscorr(x, y)
         
     | 
| 
      
 284 
     | 
    
         
            +
                        return @nonParamTest.spearmanscorr(x.to_java(Java::double), y.to_java(Java::double))
         
     | 
| 
      
 285 
     | 
    
         
            +
                    end
         
     | 
| 
      
 286 
     | 
    
         
            +
                    # ケンドールの順位相関係数
         
     | 
| 
      
 287 
     | 
    
         
            +
                    #
         
     | 
| 
      
 288 
     | 
    
         
            +
                    # @overload kendallscorr(x, y)
         
     | 
| 
      
 289 
     | 
    
         
            +
                    #   @param [Array] x xのデータ(double[])
         
     | 
| 
      
 290 
     | 
    
         
            +
                    #   @param [Array] y yのデータ(double[])
         
     | 
| 
      
 291 
     | 
    
         
            +
                    #   @return [double] 相関係数
         
     | 
| 
      
 292 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 293 
     | 
    
         
            +
                    #   x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
         
     | 
| 
      
 294 
     | 
    
         
            +
                    #   y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
         
     | 
| 
      
 295 
     | 
    
         
            +
                    #   nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
         
     | 
| 
      
 296 
     | 
    
         
            +
                    #   nonParaTest.kendallscorr(x, y)
         
     | 
| 
      
 297 
     | 
    
         
            +
                    #   => 0.592
         
     | 
| 
      
 298 
     | 
    
         
            +
                    # @note
         
     | 
| 
      
 299 
     | 
    
         
            +
                    #   無相関検定
         
     | 
| 
      
 300 
     | 
    
         
            +
                    def kendallscorr(x, y)
         
     | 
| 
      
 301 
     | 
    
         
            +
                        return @nonParamTest.kendallscorr(x.to_java(Java::double), y.to_java(Java::double))
         
     | 
| 
      
 302 
     | 
    
         
            +
                    end
         
     | 
| 
      
 303 
     | 
    
         
            +
                    # コルモゴルフ・スミルノフ検定(2標本)
         
     | 
| 
      
 304 
     | 
    
         
            +
                    #
         
     | 
| 
      
 305 
     | 
    
         
            +
                    # @overload ks2test(xi1, xi2)
         
     | 
| 
      
 306 
     | 
    
         
            +
                    #   @param [Array] xi1 x1のデータ(double[])
         
     | 
| 
      
 307 
     | 
    
         
            +
                    #   @param [Array] xi2 x2のデータ(double[])
         
     | 
| 
      
 308 
     | 
    
         
            +
                    #   @param [double] xi2 x2のデータ(double[])
         
     | 
| 
      
 309 
     | 
    
         
            +
                    #   @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
         
     | 
| 
      
 310 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 311 
     | 
    
         
            +
                    #   xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
         
     | 
| 
      
 312 
     | 
    
         
            +
                    #   xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
         
     | 
| 
      
 313 
     | 
    
         
            +
                    #   nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
         
     | 
| 
      
 314 
     | 
    
         
            +
                    #   nonParaTest.ks2test(xi1, xi2, 0.05)
         
     | 
| 
      
 315 
     | 
    
         
            +
                    #   => false
         
     | 
| 
      
 316 
     | 
    
         
            +
                    # @note
         
     | 
| 
      
 317 
     | 
    
         
            +
                    #   N1+N2-2のt分布に従う
         
     | 
| 
      
 318 
     | 
    
         
            +
                    def ks2test(xi1, xi2, a)
         
     | 
| 
      
 319 
     | 
    
         
            +
                        return @nonParamTest.ks2test(xi1.to_java(Java::double), xi2.to_java(Java::double), a)
         
     | 
| 
      
 320 
     | 
    
         
            +
                    end
         
     | 
| 
      
 321 
     | 
    
         
            +
                end
         
     | 
| 
      
 322 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 323 
     | 
    
         
            +
                    # グラプス・スミルノフの外れ値の検定量
         
     | 
| 
      
 324 
     | 
    
         
            +
                    #
         
     | 
| 
      
 325 
     | 
    
         
            +
                    # @overload grubbs(xi, xk)
         
     | 
| 
      
 326 
     | 
    
         
            +
                    #   @param [Array] xi xiのデータ(double[])
         
     | 
| 
      
 327 
     | 
    
         
            +
                    #   @param [double] xk 外れ値
         
     | 
| 
      
 328 
     | 
    
         
            +
                    #   @return [double] 検定統計量
         
     | 
| 
      
 329 
     | 
    
         
            +
                    # @example
         
     | 
| 
      
 330 
     | 
    
         
            +
                    #   xi = [3.4, 3.5, 3.3, 2.2, 3.3, 3.4, 3.6, 3.2]
         
     | 
| 
      
 331 
     | 
    
         
            +
                    #   Num4TstStatisticLib.grubbs(xi, 2.2)
         
     | 
| 
      
 332 
     | 
    
         
            +
                    #   => 2.3724
         
     | 
| 
      
 333 
     | 
    
         
            +
                    # @note
         
     | 
| 
      
 334 
     | 
    
         
            +
                    #   外れ値の検定に従う
         
     | 
| 
      
 335 
     | 
    
         
            +
                    def grubbs(xi, xk)
         
     | 
| 
      
 336 
     | 
    
         
            +
                        return TstStatistic.grubbs(xi.to_java(Java::double), xk)
         
     | 
| 
       261 
337 
     | 
    
         
             
                    end
         
     | 
| 
       262 
338 
     | 
    
         
             
                end
         
     | 
| 
       263 
339 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: num4tststatistic
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: java
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - siranovel
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2023-12- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2023-12-27 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rake
         
     | 
| 
         @@ -61,6 +61,8 @@ files: 
     | 
|
| 
       61 
61 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       62 
62 
     | 
    
         
             
            - LICENSE
         
     | 
| 
       63 
63 
     | 
    
         
             
            - Rakefile
         
     | 
| 
      
 64 
     | 
    
         
            +
            - ext/num4tststatistic/NonParametrixTest.java
         
     | 
| 
      
 65 
     | 
    
         
            +
            - ext/num4tststatistic/ParametrixTest.java
         
     | 
| 
       64 
66 
     | 
    
         
             
            - ext/num4tststatistic/TstStatistic.java
         
     | 
| 
       65 
67 
     | 
    
         
             
            - lib/commons-math3-3.6.1.jar
         
     | 
| 
       66 
68 
     | 
    
         
             
            - lib/num4tststatistic.rb
         
     |