num4tststatistic 0.0.4-java → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b8a5b476ae860590efbcc631f0851e19d12b37f7f43e127d0637d7754912d4c
4
- data.tar.gz: 2cd3007bd6872e547a7bc594d4d9d9af1b4b1ebcd8a45c12c69c5568752ff923
3
+ metadata.gz: 53537fb9aa34673abd7db4fd6de0bdf1c32094c719d91cbec7be5ee030c8df14
4
+ data.tar.gz: 6e1f38c4918b3476dca195f41b5182e6122e96b6e1f86886708a54b8c318fa48
5
5
  SHA512:
6
- metadata.gz: 1cf442842fe6bd7fd8447c12910c214aabdbe63aa0ab3811e984e289e5fd14276d99391672898c14c4a61368d403165f7a5e9d3c3cfccc9b640f095cb1f2f209
7
- data.tar.gz: 7af0e381b6833ae5215d1048e7bdcb4fc8080d3fd0013eb3c7aabe868b5e44ebbb9ba5d89e5030a2428dd39d62e3f7d44f35772a162c4a6f3543c95aa9a6d25f
6
+ metadata.gz: a8c31d24cde63ff7e098de9d56bac19e3cc11d33ba611b5de7ae63de768b7af010d303d96529533b6c793cf0a7f248c594e4dbf6dcb5cc6473c52b1725fd52ae
7
+ data.tar.gz: 2d05cd849ef9e963cfd93c23da369250e304976a7b0a92d27ec7625a0bc7496a2520226eb2d28cb7f98c09cca514e45e3c65d0ed11836328d4f55b367ad6db59
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.2.1] - 2024-01-07
6
+ ### add
7
+ - add function of errbar.
8
+
9
+ ## [0.1.1] - 2023-12-27
10
+
11
+ ### add
12
+ - add function of utest.
13
+ - add function of spearmanscorr.
14
+ - add function of kendallscorr.
15
+ - add function of ks2test.
16
+
17
+ ### change
18
+ - chg function name from unCorrelation to pearsoCorrelation.
19
+
20
+ ### delete
21
+ - del function of populationCorre.
22
+
5
23
  ## [0.0.4] - 2023-12-18
6
24
 
7
25
  ### add
data/Rakefile CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'rake/javaextensiontask'
2
2
 
3
+ jars = Dir.glob("lib/*.jar")
3
4
  Rake::JavaExtensionTask.new(name='num4tststatistic') do | ext |
4
5
  ext.release = '11'
5
- ext.classpath = 'lib/commons-math3-3.6.1.jar'
6
+ ext.classpath = jars.map { |x| File.expand_path x }.join ":"
6
7
  end
7
8
  task :default => [:compile]
@@ -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,167 @@
1
+ import org.jfree.chart.ChartFactory;
2
+ import org.jfree.chart.StandardChartTheme;
3
+ import org.jfree.chart.JFreeChart;
4
+ import org.jfree.chart.StandardChartTheme;
5
+ import org.jfree.chart.plot.CategoryPlot;
6
+ import org.jfree.data.statistics.BoxAndWhiskerCategoryDataset;
7
+ import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
8
+ import org.jfree.data.statistics.BoxAndWhiskerCalculator;
9
+ import org.jfree.data.statistics.BoxAndWhiskerItem;
10
+ import org.jfree.data.category.CategoryDataset;
11
+ import org.jfree.data.category.DefaultCategoryDataset;
12
+ import org.jfree.chart.renderer.category.BoxAndWhiskerRenderer;
13
+ import org.jfree.chart.labels.BoxAndWhiskerToolTipGenerator;
14
+ import org.jfree.chart.plot.PlotOrientation;
15
+ import org.jfree.chart.plot.DatasetRenderingOrder;
16
+ import org.jfree.chart.axis.CategoryAxis;
17
+ import org.jfree.chart.axis.NumberAxis;
18
+ import org.jfree.chart.renderer.category.LineAndShapeRenderer;
19
+ import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
20
+
21
+ import org.jfree.chart.ChartUtils;
22
+ import java.io.File;
23
+ import java.io.IOException;
24
+
25
+ import java.util.Arrays;
26
+ import java.util.List;
27
+ import java.util.ArrayList;
28
+
29
+ import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
30
+ public class Outlier {
31
+ private static Outlier outlier = new Outlier();
32
+ public static Outlier getInstance() {
33
+ return outlier;
34
+ }
35
+ public double grubbs(double[] xi, double xk) {
36
+ Grubbs g = new Grubbs();
37
+
38
+ return g.calcStatistics(xi, xk);
39
+ }
40
+
41
+ public void errbar(String dname, double[] xi) {
42
+ ChartPlot plot = new ErrorBarChartPlot();
43
+ JFreeChart chart = plot.createChart("エラーバー", dname, xi);
44
+
45
+ plot.writeJPEG("errbar.jpeg", chart, 800, 500);
46
+
47
+ }
48
+ /*********************************/
49
+ /* interface define */
50
+ /*********************************/
51
+ private interface ChartPlot {
52
+ JFreeChart createChart(String title, String dname, double[] xi);
53
+ default void writeJPEG(String fname, JFreeChart chart, int width, int height) {
54
+ File file = new File(fname);
55
+ try {
56
+ ChartUtils.saveChartAsJPEG(file, chart, width, height);
57
+ } catch (IOException e) {
58
+ e.printStackTrace();
59
+ }
60
+ }
61
+ }
62
+ private interface CreatePlot {
63
+ CategoryPlot createPlot(String dname, double[] xi);
64
+ }
65
+ /*********************************/
66
+ /* Class define */
67
+ /*********************************/
68
+ //
69
+ private class Grubbs {
70
+ private SummaryStatistics stat = new SummaryStatistics();
71
+ public double calcStatistics(double[] xi, double xk) {
72
+ Arrays.stream(xi).forEach(stat::addValue);
73
+ double m = stat.getMean(); // 平均
74
+ double sd = stat.getStandardDeviation();// 標準偏差
75
+ double min = stat.getMin();
76
+ double max = stat.getMax();
77
+ double t = 0.0;
78
+
79
+ if (xk == min) { t = (m - xk) / sd; }
80
+ if (xk == max) { t = (xk - m) / sd; }
81
+ return t;
82
+ }
83
+ }
84
+ // error bar
85
+ private class ErrorBarChartPlot implements ChartPlot{
86
+ public JFreeChart createChart(String title, String dname, double[] xi) {
87
+ CategoryPlot plot = createPlot(dname, xi);
88
+
89
+ ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
90
+ JFreeChart chart = new JFreeChart(title, plot);
91
+
92
+ ChartUtils.applyCurrentTheme(chart);
93
+ return chart;
94
+ }
95
+ private CategoryPlot createPlot(String dname, double[] xi) {
96
+ CreatePlot plotImpl = new ErrorBarPlot();
97
+
98
+ return plotImpl.createPlot(dname, xi);
99
+ }
100
+ public class ErrorBarPlot implements CreatePlot {
101
+ public CategoryPlot createPlot(String dname, double[] xi) {
102
+ BoxAndWhiskerRenderer renderer0 = new BoxAndWhiskerRenderer();
103
+ LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(false, true);
104
+
105
+ renderer0.setDefaultToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
106
+ renderer0.setMaximumBarWidth(0.2);
107
+ renderer1.setDefaultToolTipGenerator(
108
+ new StandardCategoryToolTipGenerator());
109
+
110
+ CategoryPlot plot = new CategoryPlot();
111
+ plot.setOrientation(PlotOrientation.VERTICAL);
112
+ plot.mapDatasetToRangeAxis(0,0);
113
+ plot.mapDatasetToRangeAxis(1,0);
114
+ plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
115
+
116
+ /*--- 横軸 ---*/
117
+ CategoryAxis categoryAxis = new CategoryAxis();
118
+ plot.setDomainAxis(categoryAxis);
119
+
120
+ /*--- 縦軸 ---*/
121
+ NumberAxis valueAxis = new NumberAxis();
122
+ valueAxis.setAutoRangeIncludesZero(false);
123
+ plot.setRangeAxis(valueAxis);
124
+
125
+ plot.setRenderer(0, renderer0);
126
+ plot.setDataset(0, createDataset0(dname, xi));
127
+ plot.setRenderer(1, renderer1);
128
+ plot.setDataset(1, createDataset1(dname, xi));
129
+
130
+ return plot;
131
+ }
132
+ private CategoryDataset createDataset0(String dname, double[] xi) {
133
+ DefaultBoxAndWhiskerCategoryDataset data =
134
+ new DefaultBoxAndWhiskerCategoryDataset();
135
+ List<Double> values = new ArrayList<Double>();
136
+ Arrays.stream(xi).forEach(values::add);
137
+
138
+ BoxAndWhiskerItem item =
139
+ BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values);
140
+
141
+ data.add(item, dname, "dt1");
142
+ return data;
143
+ }
144
+ private CategoryDataset createDataset1(String dname, double[] xi) {
145
+ DefaultCategoryDataset data = new DefaultCategoryDataset();
146
+ SummaryStatistics stat = new SummaryStatistics();
147
+ List<Double> values = new ArrayList<Double>();
148
+
149
+ Arrays.stream(xi).forEach(stat::addValue);
150
+ Arrays.stream(xi).forEach(values::add);
151
+
152
+ BoxAndWhiskerItem item =
153
+ BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values);
154
+ double minQ = ((Double)item.getMinOutlier()).doubleValue();
155
+ double min = stat.getMin();
156
+ double maxQ = ((Double)item.getMaxOutlier()).doubleValue();
157
+ double max = stat.getMax();
158
+
159
+ if (min < minQ) { data.addValue(min, dname, "dt1"); };
160
+ if (max > maxQ) { data.addValue(max, dname, "dt1"); };
161
+ return data;
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+
@@ -1,10 +1,14 @@
1
1
  import java.util.Arrays;
2
-
3
2
  import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
4
3
  import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;
5
- import org.apache.commons.math3.stat.inference.WilcoxonSignedRankTest;
6
- public class TstStatistic {
7
- public static double populationMean(double[] xi, double m0) {
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) {
8
12
  int n = xi.length;
9
13
  SummaryStatistics stat = new SummaryStatistics();
10
14
 
@@ -13,20 +17,23 @@ public class TstStatistic {
13
17
  double s2 = stat.getVariance();// 分散
14
18
  return (m - m0) / Math.sqrt(s2 / n);
15
19
  }
16
- public static double populationVar(double[] xi, double sig0) {
20
+ // 正規母集団の母分散の検定量
21
+ public double populationVar(double[] xi, double sig0) {
17
22
  int n = xi.length;
18
23
  SummaryStatistics stat = new SummaryStatistics();
19
24
  Arrays.stream(xi).forEach(stat::addValue);
20
25
  double s2 = stat.getVariance();// 分散
21
-
26
+
22
27
  return (n - 1) * s2 / sig0;
23
28
  }
24
- public static double populationRatio(int m, int n, double p0) {
29
+ // 母比率の検定量
30
+ public double populationRatio(int m, int n, double p0) {
25
31
  double p = (double)m / (double)n;
26
-
27
32
  return (p - p0) / Math.sqrt(p0 * (1-p0) / n);
28
33
  }
29
- public static double diffPopulationMean2EquVar(double[] xi1, double[] xi2) {
34
+ // 2つの母平均の差の検定量
35
+ // (等分散性を仮定)
36
+ public double diffPopulationMean2EquVar(double[] xi1, double[] xi2) {
30
37
  int n1 = xi1.length;
31
38
  int n2 = xi2.length;
32
39
  SummaryStatistics stat1 = new SummaryStatistics();
@@ -42,7 +49,9 @@ public class TstStatistic {
42
49
 
43
50
  return (m1 - m2) / Math.sqrt((1.0 / n1 + 1.0 / n2) * s2);
44
51
  }
45
- public static double diffPopulationMean2UnEquVar(double[] xi1, double[] xi2) {
52
+ // 2つの母平均の差の検定量
53
+ // (不等分散性を仮定)
54
+ public double diffPopulationMean2UnEquVar(double[] xi1, double[] xi2) {
46
55
  int n1 = xi1.length;
47
56
  int n2 = xi2.length;
48
57
  SummaryStatistics stat1 = new SummaryStatistics();
@@ -57,7 +66,8 @@ public class TstStatistic {
57
66
 
58
67
  return (m1 - m2) / Math.sqrt(s12 / n1 + s22 / n2);
59
68
  }
60
- public static int df4welch(double[] xi1, double[] xi2) {
69
+ // ウェルチ検定の為の自由度
70
+ public int df4welch(double[] xi1, double[] xi2) {
61
71
  int n1 = xi1.length;
62
72
  int n2 = xi2.length;
63
73
  SummaryStatistics stat1 = new SummaryStatistics();
@@ -79,9 +89,10 @@ public class TstStatistic {
79
89
  (
80
90
  s14 / (n12 * (n1 - 1)) + s24 / (n22 * (n2 - 1))
81
91
  )
82
- );
92
+ );
83
93
  }
84
- public static double diffPopulationMean(double[] xi1, double[] xi2) {
94
+ // 対応のある2つの母平均の差の検定量
95
+ public double diffPopulationMean(double[] xi1, double[] xi2) {
85
96
  int n = xi1.length;
86
97
  SummaryStatistics stat = new SummaryStatistics();
87
98
 
@@ -90,10 +101,11 @@ public class TstStatistic {
90
101
  }
91
102
  double m = stat.getMean();
92
103
  double s2 = stat.getVariance();// 分散
93
-
104
+
94
105
  return (m - 0) / Math.sqrt(s2/n);
95
106
  }
96
- public static double diffPopulationVar(double[] xi1, double[] xi2) {
107
+ // 2つの母分散の差の検定量
108
+ public double diffPopulationVar(double[] xi1, double[] xi2) {
97
109
  SummaryStatistics stat1 = new SummaryStatistics();
98
110
  SummaryStatistics stat2 = new SummaryStatistics();
99
111
  Arrays.stream(xi1).forEach(stat1::addValue);
@@ -103,34 +115,22 @@ public class TstStatistic {
103
115
  double s22 = stat2.getVariance();// 分散
104
116
  return s12 / s22;
105
117
  }
106
- public static double diffPopulationRatio(int m1, int n1, int m2, int n2) {
118
+ // 2つの母比率の差の検定量
119
+ public double diffPopulationRatio(int m1, int n1, int m2, int n2) {
107
120
  double p1 = (double)m1 / (double)n1;
108
121
  double p2 = (double)m2 / (double)n2;
109
122
  double p = (double)(m1 + m2) / (double)(n1 + n2);
110
123
 
111
124
  return (p1 - p2) / Math.sqrt(p * (1 - p) * (1.0 / n1 + 1.0 / n2));
112
125
  }
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;
126
+ // ピアソン相関係数
127
+ public double pearsoCorrelation(double[] x, double[] y) {
123
128
  PearsonsCorrelation corel = new PearsonsCorrelation();
124
129
 
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
- );
130
+ return corel.correlation(x, y);
132
131
  }
133
- public static double fidelity(double[] fi, double[] pi) {
132
+ // 適合度の検定量
133
+ public double fidelity(double[] fi, double[] pi) {
134
134
  double[] e = new double[fi.length];
135
135
  double t = 0.0;
136
136
  SummaryStatistics stat = new SummaryStatistics();
@@ -145,52 +145,49 @@ public class TstStatistic {
145
145
  }
146
146
  return t;
147
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];
148
+ // 独立性の検定量
149
+ public double independency(double[][] fij) {
150
+ Independency indep = new Independency(fij);
153
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
+ }
154
167
  // 各セルの計算
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];
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
+ }
161
176
  }
162
177
  }
163
-
164
178
  // 検定統計量計算
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];
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];
168
185
 
169
- t += f_e * f_e / (n * fa[i] * fb[j]);
186
+ t += f_e * f_e / (n * fa[i] * fb[j]);
187
+ }
170
188
  }
189
+ return t;
171
190
  }
172
-
173
- return t;
174
- }
175
- public static double grubbs(double[] xi, double xk) {
176
- SummaryStatistics stat = new SummaryStatistics();
177
-
178
- Arrays.stream(xi).forEach(stat::addValue);
179
- double m = stat.getMean(); // 平均
180
- double sd = stat.getStandardDeviation();// 標準偏差
181
- double min = stat.getMin();
182
- double max = stat.getMax();
183
- double t = 0.0;
184
-
185
- if (xk == min) { t = (m - xk) / sd; }
186
- if (xk == max) { t = (xk - m) / sd; }
187
- return t;
188
- }
189
- public static double wilcoxon(double[] x, double[] y) {
190
- WilcoxonSignedRankTest wilcox = new WilcoxonSignedRankTest();
191
-
192
- return wilcox.wilcoxonSignedRank(x, y);
193
191
  }
194
192
  }
195
193
 
196
-
Binary file
Binary file
@@ -1,13 +1,19 @@
1
1
  require 'java'
2
2
  require 'num4tststatistic.jar'
3
3
  require 'commons-math3-3.6.1.jar'
4
+ require 'jfreechart-1.5.4.jar'
4
5
 
5
- java_import 'TstStatistic'
6
+ java_import 'Outlier'
7
+ java_import 'ParametrixTest'
8
+ java_import 'NonParametrixTest'
6
9
 
7
10
  # 検定統計量を計算
8
11
  # (Apache commoms math3使用)
9
12
  module Num4TstStatisticLib
10
- class << self
13
+ class ParametrixTestLib
14
+ def initialize
15
+ @paramTest = ParametrixTest.getInstance()
16
+ end
11
17
  # 正規母集団の母平均の検定量
12
18
  #
13
19
  # @overload populationMean(xi, m0)
@@ -16,12 +22,13 @@ module Num4TstStatisticLib
16
22
  # @return [double] 検定統計量
17
23
  # @example
18
24
  # xi = [15.5, 15.7, 15.4, 15.4, 15.6, 15.4, 15.6, 15.5, 15.4]
19
- # Num4TstStatisticLib.populationMean(xi, 15.4)
25
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
26
+ # paraTest.populationMean(xi, 15.4)
20
27
  # => 2.683
21
28
  # @note
22
29
  # 自由度(N-1)のt分布に従う
23
30
  def populationMean(xi, m0)
24
- return TstStatistic.populationMean(xi.to_java(Java::double), m0)
31
+ return @paramTest.populationMean(xi.to_java(Java::double), m0)
25
32
  end
26
33
  # 正規母集団の母分散の検定量
27
34
  #
@@ -32,26 +39,29 @@ module Num4TstStatisticLib
32
39
  # @example
33
40
  # xi = xi = [35.2, 34.5, 34.9, 35.2, 34.8, 35.1, 34.9, 35.2, 34.9, 34.8]
34
41
  # sd = 0.4
35
- # Num4TstStatisticLib.populationVar(xi, sd*sd)
42
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
43
+ # paraTest.populationVar(xi, sd*sd)
36
44
  # => 2.906
37
45
  # @note
38
46
  # 自由度(N-1)の階2乗分布に従う
39
47
  def populationVar(xi, sig0)
40
- return TstStatistic.populationVar(xi.to_java(Java::double), sig0)
48
+ return @paramTest.populationVar(xi.to_java(Java::double), sig0)
41
49
  end
42
50
  # 母比率の検定量
51
+ #
43
52
  # @overload populationRatio(m, n, p0)
44
53
  # @param [int] m m値
45
54
  # @param [int] n N値
46
55
  # @param [double] p0 母比率
47
56
  # @return [double] 検定統計量
48
57
  # @example
49
- # Num4TstStatisticLib.populationRatio(29, 346, 0.12)
58
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
59
+ # paraTest.populationRatio(29, 346, 0.12)
50
60
  # => -2.071
51
61
  # @note
52
62
  # 標準正規分布 N(0,1*1)に従う
53
63
  def populationRatio(m, n, p0)
54
- return TstStatistic.populationRatio(m, n, p0)
64
+ return @paramTest.populationRatio(m, n, p0)
55
65
  end
56
66
  # 2つの母平均の差の検定量
57
67
  # (等分散性を仮定)
@@ -63,12 +73,13 @@ module Num4TstStatisticLib
63
73
  # @example
64
74
  # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
65
75
  # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
66
- # Num4TstStatisticLib.diffPopulationMean2EquVar(xi1, xi2)
76
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
77
+ # paraTest.diffPopulationMean2EquVar(xi1, xi2)
67
78
  # => -1.765
68
79
  # @note
69
80
  # N1+N2-2のt分布に従う
70
81
  def diffPopulationMean2EquVar(xi1, xi2)
71
- return TstStatistic.diffPopulationMean2EquVar(
82
+ return @paramTest.diffPopulationMean2EquVar(
72
83
  xi1.to_java(Java::double), xi2.to_java(Java::double)
73
84
  )
74
85
  end
@@ -82,16 +93,18 @@ module Num4TstStatisticLib
82
93
  # @example
83
94
  # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
84
95
  # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
85
- # Num4TstStatisticLib.diffPopulationMean2UnEquVar(xi1, xi2)
96
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
97
+ # paraTest.diffPopulationMean2UnEquVar(xi1, xi2)
86
98
  # => -1.636
87
99
  # @note
88
100
  # df4welch関数で求めた自由度のt分布に従う
89
101
  def diffPopulationMean2UnEquVar(xi1, xi2)
90
- return TstStatistic.diffPopulationMean2UnEquVar(
102
+ return @paramTest.diffPopulationMean2UnEquVar(
91
103
  xi1.to_java(Java::double), xi2.to_java(Java::double)
92
104
  )
93
105
  end
94
106
  # ウェルチ検定の為の自由度
107
+ #
95
108
  # @overload df4welch(xi1, xi2)
96
109
  # @param [Array] xi1 x1のデータ(double[])
97
110
  # @param [Array] xi2 x2のデータ(double[])
@@ -99,10 +112,11 @@ module Num4TstStatisticLib
99
112
  # @example
100
113
  # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
101
114
  # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
102
- # Num4TstStatisticLib.df4welch(xi1, xi2)
115
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
116
+ # paraTest.df4welch(xi1, xi2)
103
117
  # => 11
104
118
  def df4welch(xi1, xi2)
105
- return TstStatistic.df4welch(
119
+ return @paramTest.df4welch(
106
120
  xi1.to_java(Java::double), xi2.to_java(Java::double)
107
121
  )
108
122
  end
@@ -115,12 +129,13 @@ module Num4TstStatisticLib
115
129
  # @example
116
130
  # xi1 = [37.1, 36.2, 36.6, 37.4, 36.8, 36.7, 36.9, 37.4, 36.6, 36.7]
117
131
  # xi2 = [36.8, 36.6, 36.5, 37.0, 36.0, 36.5, 36.6, 37.1, 36.4, 36.7]
118
- # Num4TstStatisticLib.diffPopulationMean(xi1, xi2)
132
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
133
+ # paraTest.diffPopulationMean(xi1, xi2)
119
134
  # => 2.283
120
135
  # @note
121
136
  # 自由度(N-1)のt分布に従う
122
- def diffPopulationMean(xi1, xi2)
123
- return TstStatistic.diffPopulationMean(
137
+ def diffPopulationMean(xi1, xi2)
138
+ return @paramTest.diffPopulationMean(
124
139
  xi1.to_java(Java::double), xi2.to_java(Java::double)
125
140
  )
126
141
  end
@@ -133,12 +148,13 @@ module Num4TstStatisticLib
133
148
  # @example
134
149
  # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
135
150
  # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
136
- # Num4TstStatisticLib.diffPopulationVar(xi1, xi2)
151
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
152
+ # paraTest.diffPopulationVar(xi1, xi2)
137
153
  # => 0.4727
138
154
  # @note
139
155
  # 自由度(N1-1,N2-1)のF分布に従う
140
156
  def diffPopulationVar(xi1, xi2)
141
- return TstStatistic.diffPopulationVar(
157
+ return @paramTest.diffPopulationVar(
142
158
  xi1.to_java(Java::double), xi2.to_java(Java::double)
143
159
  )
144
160
  end
@@ -151,50 +167,32 @@ module Num4TstStatisticLib
151
167
  # @param [int] n2 N2値
152
168
  # @return [double] 検定統計量
153
169
  # @example
154
- # Num4TstStatisticLib.diffPopulationRatio(469, 1200, 308, 900)
170
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
171
+ # paraTest.diffPopulationRatio(469, 1200, 308, 900)
155
172
  # => 2.283
156
173
  # @note
157
174
  # 標準正規分布 N(0,1*1)に従う
158
175
  def diffPopulationRatio(m1, n1, m2, n2)
159
- return TstStatistic.diffPopulationRatio(m1, n1, m2, n2)
176
+ return @paramTest.diffPopulationRatio(m1, n1, m2, n2)
160
177
  end
161
- # 無相関の検定量
178
+ # ピアソン相関係数
179
+ # (相関係数の検定)
162
180
  #
163
- # @overload unCorrelation(x, y)
181
+ # @overload pearsoCorrelation(x, y)
164
182
  # @param [Array] x xのデータ(double[])
165
183
  # @param [Array] y yのデータ(double[])
166
- # @return [double] 検定統計量
184
+ # @return [double] 相関係数
167
185
  # @example
168
186
  # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
169
187
  # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
170
- # Num4TstStatisticLib.unCorrelation(x, y)
188
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
189
+ # paraTest.pearsoCorrelation(x, y)
171
190
  # => 3.1035
172
- # @note
173
- # 自由度(N-2)t分布に従う
174
- def unCorrelation(x, y)
175
- return TstStatistic.unCorrelation(
191
+ def pearsoCorrelation(x, y)
192
+ return @paramTest.pearsoCorrelation(
176
193
  x.to_java(Java::double), y.to_java(Java::double)
177
194
  )
178
195
  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
196
  # 適合度の検定量
199
197
  #
200
198
  # @overload fidelity(fi, pi)
@@ -204,12 +202,13 @@ module Num4TstStatisticLib
204
202
  # @example
205
203
  # fi = [57, 33, 46, 14]
206
204
  # pi = [0.4, 0.2, 0.3, 0.1]
207
- # Num4TstStatisticLib.fidelity(fi, pi)
205
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
206
+ # paraTest.fidelity(fi, pi)
208
207
  # => 0.5389
209
208
  # @note
210
209
  # 自由度(n-1)の階2乗分布に従う
211
210
  def fidelity(fi, pi)
212
- return TstStatistic.fidelity(fi.to_java(Java::double), pi.to_java(Java::double))
211
+ return @paramTest.fidelity(fi.to_java(Java::double), pi.to_java(Java::double))
213
212
  end
214
213
  # 独立性の検定量
215
214
  #
@@ -221,12 +220,109 @@ module Num4TstStatisticLib
221
220
  # [57, 33, 46, 14],
222
221
  # [89, 24, 75, 12],
223
222
  # ]
224
- # Num4TstStatisticLib.independency(fij)
223
+ # paraTest = Num4TstStatisticLib::ParametrixTestLib.new
224
+ # paraTest.independency(fij)
225
225
  # => 8.5711
226
226
  # @note
227
227
  # 自由度(m-1)(n-1)の階2乗分布に従う
228
228
  def independency(fij)
229
- return TstStatistic.independency(fij.to_java(Java::double[]))
229
+ return @paramTest.independency(fij.to_java(Java::double[]))
230
+ end
231
+ end
232
+ class NonParametrixTestLib
233
+ def initialize
234
+ @nonParamTest = NonParametrixTest.getInstance()
235
+ end
236
+ # マン・ホイットニーのU検定
237
+ #
238
+ # @overload utest(x, y)
239
+ # @param [Array] x xのデータ(double[])
240
+ # @param [Array] y yのデータ(double[])
241
+ # @return [double] 検定統計量
242
+ # @example
243
+ # x = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
244
+ # y = [180, 180, 235, 270, 240, 285, 164, 152]
245
+ # nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
246
+ # nonParaTest.utest(x, y)
247
+ # => 63.0
248
+ # @note
249
+ # 近似的に標準正規分布 N(0,1*1)に従う
250
+ def utest(x, y)
251
+ return @nonParamTest.utest(x.to_java(Java::double), y.to_java(Java::double))
252
+ end
253
+ # ウィルコクス符号付き順位検定
254
+ #
255
+ # @overload wilcoxontest(x, y)
256
+ # @param [Array] x xのデータ(double[])
257
+ # @param [Array] y yのデータ(double[])
258
+ # @return [double] 検定統計量
259
+ # @example
260
+ # x = [37.1, 36.2, 36.6, 37.4, 36.8, 36.7, 36.9, 37.4, 36.6, 36.7]
261
+ # y = [36.8, 36.6, 36.5, 37.0, 36.0, 36.5, 36.6, 37.1, 36.4, 36.7]
262
+ # nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
263
+ # nonParaTest.wilcoxon(x, y)
264
+ # => 46.5
265
+ # @note
266
+ # 近似的に標準正規分布 N(0,1*1)に従う
267
+ def wilcoxon(x, y)
268
+ return @nonParamTest.wilcoxon(x.to_java(Java::double), y.to_java(Java::double))
269
+ end
270
+ # スピアマンの順位相関係数
271
+ #
272
+ # @overload spearmanscorr(x, y)
273
+ # @param [Array] x xのデータ(double[])
274
+ # @param [Array] y yのデータ(double[])
275
+ # @return [double] 相関係数
276
+ # @example
277
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
278
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
279
+ # nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
280
+ # nonParaTest.spearmanscorr(x, y)
281
+ # => 0.745
282
+ # @note
283
+ # 無相関検定
284
+ def spearmanscorr(x, y)
285
+ return @nonParamTest.spearmanscorr(x.to_java(Java::double), y.to_java(Java::double))
286
+ end
287
+ # ケンドールの順位相関係数
288
+ #
289
+ # @overload kendallscorr(x, y)
290
+ # @param [Array] x xのデータ(double[])
291
+ # @param [Array] y yのデータ(double[])
292
+ # @return [double] 相関係数
293
+ # @example
294
+ # x = [113, 64, 16, 45, 28, 19, 30, 82, 76]
295
+ # y = [31, 5, 2, 17, 18, 2, 9, 25, 13]
296
+ # nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
297
+ # nonParaTest.kendallscorr(x, y)
298
+ # => 0.592
299
+ # @note
300
+ # 無相関検定
301
+ def kendallscorr(x, y)
302
+ return @nonParamTest.kendallscorr(x.to_java(Java::double), y.to_java(Java::double))
303
+ end
304
+ # コルモゴルフ・スミルノフ検定(2標本)
305
+ #
306
+ # @overload ks2test(xi1, xi2)
307
+ # @param [Array] xi1 x1のデータ(double[])
308
+ # @param [Array] xi2 x2のデータ(double[])
309
+ # @param [double] xi2 x2のデータ(double[])
310
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
311
+ # @example
312
+ # xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
313
+ # xi2 = [180, 180, 235, 270, 240, 285, 164, 152]
314
+ # nonParaTest = Num4TstStatisticLib::NonParametrixTestLib.new
315
+ # nonParaTest.ks2test(xi1, xi2, 0.05)
316
+ # => false
317
+ # @note
318
+ # N1+N2-2のt分布に従う
319
+ def ks2test(xi1, xi2, a)
320
+ return @nonParamTest.ks2test(xi1.to_java(Java::double), xi2.to_java(Java::double), a)
321
+ end
322
+ end
323
+ class OutlierLib
324
+ def initialize
325
+ @outlier = Outlier.getInstance()
230
326
  end
231
327
  # グラプス・スミルノフの外れ値の検定量
232
328
  #
@@ -239,25 +335,24 @@ module Num4TstStatisticLib
239
335
  # Num4TstStatisticLib.grubbs(xi, 2.2)
240
336
  # => 2.3724
241
337
  # @note
242
- # グラプス・スミルノフの数表に従う
338
+ # 外れ値の検定に従う
243
339
  def grubbs(xi, xk)
244
- return TstStatistic.grubbs(xi.to_java(Java::double), xk)
340
+ return @outlier.grubbs(xi.to_java(Java::double), xk)
245
341
  end
246
- # ウィルコクス符号付き順位検定
342
+ # エラーバー出力
247
343
  #
248
- # @overload wilcoxon(x, y)
249
- # @param [Array] x xのデータ(double[])
250
- # @param [Array] y yのデータ(double[])
251
- # @return [double] 検定統計量
344
+ # @overload errbar(dname, xi)
345
+ # @param [String] dname データ名
346
+ # @param [Array] xi xiのデータ(double[])
347
+ # @return [void] errbar.jpegファイルを出力
252
348
  # @example
253
- # x = [28, 25, 29, 28, 30, 20, 31, 27, 24, 26, 35, 23, 27, 32]
254
- # y = [32, 30, 31, 27, 35, 25, 40, 30, 45, 28, 32, 30, 30, 38]
255
- # Num4TstStatisticLib.wilcoxon(x, y)
256
- # => 99
349
+ # xi = [3.4, 3.5, 3.3, 2.2, 3.3, 3.4, 3.6, 3.2]
350
+ # Num4TstStatisticLib.grubbs("LDH", xi)
351
+ # => errbar.jpeg
257
352
  # @note
258
- # 標準正規分布 N(0,1*1)に従う
259
- def wilcoxon(x, y)
260
- return TstStatistic.wilcoxon(x.to_java(Java::double), y.to_java(Java::double))
353
+ # グラフは、jfreechartを使用
354
+ def errbar(dname, xi)
355
+ return @outlier.errbar(dname, xi.to_java(Java::double))
261
356
  end
262
357
  end
263
358
  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.0.4
4
+ version: 0.2.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-18 00:00:00.000000000 Z
11
+ date: 2024-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -61,8 +61,12 @@ files:
61
61
  - Gemfile
62
62
  - LICENSE
63
63
  - Rakefile
64
- - ext/num4tststatistic/TstStatistic.java
64
+ - ext/num4tststatistic/NonParametrixTest.java
65
+ - ext/num4tststatistic/Outlier.java
66
+ - ext/num4tststatistic/ParametrixTest.java
65
67
  - lib/commons-math3-3.6.1.jar
68
+ - lib/jcommon-1.0.23.jar
69
+ - lib/jfreechart-1.5.4.jar
66
70
  - lib/num4tststatistic.rb
67
71
  homepage: http://github.com/siranovel/num4tststatistic
68
72
  licenses: