num4normality 0.0.9-java → 0.0.11-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: 28c1bcf4f9952a2f18587d5b23d301a43ea31cd109d6a2d99ce665f900877bbf
4
- data.tar.gz: 29a902d3ef52739cb913bc523c5488ebcc14ac3288d8babc8d7e64fd28448cbf
3
+ metadata.gz: e05aa008cb138a008afea68e92fd7df22fa5155f709ac2649e11db122bc28e44
4
+ data.tar.gz: 011e3a5473bf128c2946cc23126b59ff977b3b4d937b24405baa655a8d7b6b3f
5
5
  SHA512:
6
- metadata.gz: 66fe7346cae038b6a399395d46863b2a7aaecff96687b451075e2affa08236c1f8eb5b18066eed22eafac9f1ac7c719989e43c07082fceb3d17b9b6d4310fe4b
7
- data.tar.gz: 3b621221e49cfaabf960cb5f8d413aadb53ec1e280e7f3c65b1cb2d70dd8c960129e239aee017365d9910c609b84b35d875f7e12fcc5a3f0f84284db3a9d78b6
6
+ metadata.gz: 8fdb7fe9d57d14a3bd0a7584cbd0f19803f651799ab4d3cbdf14d1ed5f057d480cbf274ca086037adfd28402a991e7b07cdb4d13ec29e6b02fde5f6985dd0906
7
+ data.tar.gz: b311f196404a1bd3e37b084d3dcca33100e36ff1e8ea5df3fc9a986e56e7a008693e9c01993a74bbe26ad9afbdc5b5e5d9110900b78c7be3d2335e3c25f486bb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.11] - 2024-06-05
6
+ ### add
7
+ - add fiducial interval in qqplot.
8
+
9
+ ## [0.0.10] - 2024-05-18
10
+ ### add
11
+ - add function of jbtest.
12
+
5
13
  ## [0.0.9] - 2024-05-11
6
14
  ### add
7
15
  - add function of adtest.
@@ -94,6 +94,12 @@ public class Normality {
94
94
 
95
95
  return daigo.test(x, HypothesisTest.P);
96
96
  }
97
+ public static boolean jbTest(double[] xi) {
98
+ HypothesisTest daigo = new JBTest();
99
+ double x = daigo.calcTestStatistic(xi);
100
+
101
+ return daigo.test(x, HypothesisTest.P);
102
+ }
97
103
  /*********************************/
98
104
  /* interface define */
99
105
  /*********************************/
@@ -143,6 +149,7 @@ public class Normality {
143
149
  return plotImpl.createPlot(dname, xi);
144
150
  }
145
151
  public static class QQPlot implements CreatePlot {
152
+ private double xbar = 0.0;
146
153
  private double[][] createData(double[] xi) {
147
154
  DescriptiveStatistics stat = new DescriptiveStatistics();
148
155
  NormalDistribution ndist = new NormalDistribution(0, 1);
@@ -153,15 +160,18 @@ public class Normality {
153
160
  double sum = stat.getSum();
154
161
  double[][] data = new double[n][2];
155
162
  double p = 0.0;
163
+ double sumx = 0.0;
156
164
 
157
165
  for (int i = 0; i < n; i++) {
158
166
  p += xi[i] / sum;
159
167
  double x =
160
168
  ndist.inverseCumulativeProbability(p * (i + 1.0) / (n + 1.0));
161
169
 
170
+ sumx += x;
162
171
  data[i][0] = x;
163
172
  data[i][1] = xi[i];
164
173
  }
174
+ xbar = sumx / n;
165
175
  return data;
166
176
  }
167
177
  public XYPlot createPlot(String dname, double[] xi) {
@@ -218,16 +228,35 @@ public class Normality {
218
228
  XYSeries cu = new XYSeries("累積");
219
229
 
220
230
  simpleReg.addData(data);
221
- double a = simpleReg.getSlope();
222
- double b = simpleReg.getIntercept();
223
-
224
231
  for (double x = ChartPlot.CLASS_MIN; x < ChartPlot.CLASS_MAX; x += 0.01) {
225
- double y = a * x + b;
226
-
227
- cu.add(x, y);
232
+ cu.add(x, simpleReg.predict(x));
228
233
  }
234
+ // 信頼区間
235
+ long n = simpleReg.getN();
236
+ double ve = simpleReg.getMeanSquareError();
237
+ double sxx = simpleReg.getXSumSquares();
238
+ TDistribution tDist = new TDistribution(n - 2);
239
+ double t = tDist.inverseCumulativeProbability(0.975);
240
+ XYSeries p05m = new XYSeries("P05-");
241
+ XYSeries p05p = new XYSeries("P05+");
242
+
243
+ for(int i = 0; i < n; i++) {
244
+ double x = data[i][0];
245
+ double residual = (x - xbar);
246
+ double interval = t * Math.sqrt(
247
+ (1 + 1.0 / n + residual * residual / sxx) * ve
248
+ );
249
+ double y01 = simpleReg.predict(x) - interval;
250
+ double y02 = simpleReg.predict(x) + interval;
251
+
252
+ p05m.add(x, y01);
253
+ p05p.add(x, y02);
254
+ }
255
+
229
256
  XYSeriesCollection series = new XYSeriesCollection();
230
257
  series.addSeries(cu);
258
+ series.addSeries(p05m);
259
+ series.addSeries(p05p);
231
260
  return series;
232
261
  }
233
262
  }
@@ -644,5 +673,27 @@ public class Normality {
644
673
  return a2 * (1.0 + 0.75 / n + 2.25 / (n * n));
645
674
  }
646
675
  }
676
+ // Jarque-Bera検定
677
+ private static class JBTest implements HypothesisTest {
678
+ private HypothesisTest skewness = null;
679
+ private HypothesisTest kurtosis = null;
680
+ public JBTest() {
681
+ skewness = new SkewnessTest();
682
+ kurtosis = new KurtosisTest();
683
+ }
684
+ public double calcTestStatistic(double[] xi) {
685
+ int n = xi.length;
686
+ double x1 = skewness.calcTestStatistic(xi);
687
+ double x2 = kurtosis.calcTestStatistic(xi);
688
+
689
+ return n / 6.0 * (x1 *x1 + x2 * x2 / 4.0);
690
+ }
691
+ public boolean test(double statistic, double a) {
692
+ ChiSquaredDistribution chi2Dist = new ChiSquaredDistribution(2);
693
+ double p = chi2Dist.cumulativeProbability(statistic);
694
+
695
+ return (p < a) ? true : false;
696
+ }
697
+ }
647
698
  }
648
699
 
data/lib/num4normality.rb CHANGED
@@ -145,6 +145,18 @@ module Num4NormalityLib
145
145
  def adtest(xi)
146
146
  Normality.adTest(xi.to_java(Java::double))
147
147
  end
148
+ # Jarque-Bera検定
149
+ #
150
+ # @overload jbtest(xi)
151
+ # @param [Array] xi データ(double[])
152
+ # @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
153
+ # @example
154
+ # xi = [320, 240, 402, 325, 440, 286, 362, 281, 560, 212, 198, 209, 374]
155
+ # Num4NormalityLib.jbtest(xi)
156
+ # => false
157
+ def jbtest(xi)
158
+ Normality.jbTest(xi.to_java(Java::double))
159
+ end
148
160
  end
149
161
  end
150
162
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4normality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-11 00:00:00.000000000 Z
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake