num4anova 0.0.11-java → 0.0.12-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: 2a278a4c32d7e1ef21ccbb1200573d5c1b4e326c59602327f9968afb29f134b6
4
- data.tar.gz: e8520453d70e0276e6bb0587aefcd31b90b84d703cf670ae25297af73172bcdd
3
+ metadata.gz: 87febfd8031fd924430223c93fad6b0606aa212ab109e1b758db2c1d23b6dace
4
+ data.tar.gz: 48b610b93d2c5341f05c25ef230acea09b02fa75c924129f5dafba56fcb6051f
5
5
  SHA512:
6
- metadata.gz: 42836d15f6460c2650a7c6cb17c15de206bbabb52c40d988714fe26564d019974a416db4c22f67ed0c535694022575d380603da7c029f0b04476d4994ffca7a5
7
- data.tar.gz: ed1698ed0b05da8d2f0d7417fd1271bcb41754d76fa68b19fb300245449a634c830636ea790a49b89d87066c320c55e2260464bb791ba795f8193664a0babb28
6
+ metadata.gz: 979fe122d0cf17086e80a45ff6c44b67153822a8d89d83bceb84a25d3d68190f087c3ed8bf4b192e9afd48a38b3ec0d1456fa0821c84256113154e04d5a6e461
7
+ data.tar.gz: 0bcad9f7a234a96759697440f540f0caddf70c1a25cf46409dead11478faa0017cfe9e98d2a23feaad2648bea641d5bca80cb73adab5001ec46d93ef8899ce70
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.12] - 2024-03-27
6
+
7
+ ### add
8
+ - add fuction of interval_estim.
9
+
5
10
  ## [0.0.11] - 2024-03-21
6
11
 
7
12
  ### add
@@ -1,4 +1,5 @@
1
1
  import org.apache.commons.math3.distribution.FDistribution;
2
+ import org.apache.commons.math3.distribution.TDistribution;
2
3
 
3
4
  public class Ancova {
4
5
  private static Ancova ancova = new Ancova();
@@ -23,6 +24,11 @@ public class Ancova {
23
24
  double statistic = hypoth.calcTestStatistic(xi);
24
25
  return hypoth.executeTest(statistic, a);
25
26
  }
27
+ public Interval intervalEstim(double[][][] xi, double a) {
28
+ Estim estim = new IntervalEstim();
29
+
30
+ return estim.calcInterval(xi, a);
31
+ }
26
32
  /*********************************/
27
33
  /* interface define */
28
34
  /*********************************/
@@ -30,9 +36,22 @@ public class Ancova {
30
36
  double calcTestStatistic(double[][][] xi);
31
37
  boolean executeTest(double statistic, double a);
32
38
  }
39
+ private interface Estim {
40
+ Interval calcInterval(double[][][] xi, double a);
41
+ }
33
42
  /*********************************/
34
43
  /* class define */
35
44
  /*********************************/
45
+ public class Interval {
46
+ private double min;
47
+ private double max;
48
+ public Interval(double min, double max) {
49
+ this.min = min;
50
+ this.max = max;
51
+ }
52
+ public double getMin() { return this.min; }
53
+ public double getMax() { return this.max; }
54
+ }
36
55
  private class RegressionLine {
37
56
  protected int calcSumn(double[][][] xi) {
38
57
  int sum = 0;
@@ -321,5 +340,88 @@ public class Ancova {
321
340
  return (sumey * sumex - sumeyx * sumeyx) / (m * sumex);
322
341
  }
323
342
  }
343
+ //
344
+ private class IntervalEstim extends RegressionLine
345
+ implements Estim {
346
+ private int n = 0;
347
+ private int[] ni = null;
348
+ private double sumex = 0.0;
349
+ public Interval calcInterval(double[][][] xi, double a) {
350
+ ni = calcNi(xi);
351
+ int sumn = calcSumn(xi);
352
+ n = sumn - xi.length - 1;
353
+ sumex = calcSex(xi, sumn);
354
+ double ve = calcVe(xi, sumn);
355
+ double b = calcB(xi, sumn);
356
+
357
+ double[] meanyi = calcMeanyi(xi);
358
+ double[] meanxi = calcMeanxi(xi);
359
+ double meanx = calcMeanx(xi);
360
+
361
+ TDistribution tDist = new TDistribution(n);
362
+ double t = tDist.inverseCumulativeProbability(1.0 - a / 2.0);
363
+ double wk = (meanxi[0] - meanx);
364
+ double wk2 = t * Math.sqrt((1/ni[0] + wk * wk / sumex) * ve);
365
+ double min = meanyi[0] - b * wk - wk2;
366
+ double max = meanyi[0] - b * wk + wk2;
367
+
368
+ return new Interval(min, max);
369
+ }
370
+ private int[] calcNi(double[][][] xi) {
371
+ int[] ni = new int[xi.length];
372
+
373
+ for(int i = 0; i < xi.length; i++) {
374
+ ni[i] = xi[i].length;
375
+ }
376
+ return ni;
377
+ }
378
+ private double calcVe(double[][][] xi, int sumn) {
379
+ double sumey = calcSey(xi, sumn);
380
+ double sumeyx = calcSeyx(xi, sumn);
381
+
382
+ return (sumey * sumex - sumeyx * sumeyx) / (n * sumex);
383
+ }
384
+ private double calcB(double[][][] xi, int sumn) {
385
+ double sumeyx = calcSeyx(xi, sumn);
386
+ double sex = calcSex(xi, sumn);
387
+
388
+ return sumeyx / sex;
389
+ }
390
+ private double[] calcMeanyi(double[][][] xi) {
391
+ double[] meanyi = new double[xi.length];
392
+
393
+ for(int i = 0; i < xi.length; i++) {
394
+ double sum = 0.0;
395
+ for(int j = 0; j < xi[i].length; j++) {
396
+ sum += xi[i][j][0];
397
+ }
398
+ meanyi[i] = sum / xi[i].length;
399
+ }
400
+ return meanyi;
401
+ }
402
+ private double[] calcMeanxi(double[][][] xi) {
403
+ double[] meanxi = new double[xi.length];
404
+
405
+ for(int i = 0; i < xi.length; i++) {
406
+ double sum = 0.0;
407
+ for(int j = 0; j < xi[i].length; j++) {
408
+ sum += xi[i][j][1];
409
+ }
410
+ meanxi[i] = sum / xi[i].length;
411
+ }
412
+ return meanxi;
413
+ }
414
+ private double calcMeanx(double[][][] xi) {
415
+ double sum = 0.0;
416
+ double n = 0;
417
+ for(int i = 0; i < xi.length; i++) {
418
+ for(int j = 0; j < xi[i].length; j++) {
419
+ sum += xi[i][j][1];
420
+ n++;
421
+ }
422
+ }
423
+ return sum / n;
424
+ }
425
+ }
324
426
  }
325
427
 
data/lib/num4anova.rb CHANGED
@@ -314,6 +314,42 @@ module Num4AnovaLib
314
314
  def difference_test(xi, a)
315
315
  @ancova.differenceTest(xi.to_java(Java::double[][]), a)
316
316
  end
317
+ # 区間推定
318
+ #
319
+ # @overload interval_estim(xi, a)
320
+ # @param [array] xi データ(double[][][])
321
+ # @param [double] a 有意水準
322
+ # @return [Hash] (min:下限信頼区間 max:上限信頼区間)
323
+ # @example
324
+ # xi = [
325
+ # [
326
+ # [3,35], [5,38], [3,39],
327
+ # ],
328
+ # [
329
+ # [3,36], [3,39], [8,54],
330
+ # ],
331
+ # [
332
+ # [2,40], [2,45], [2,39],
333
+ # ],
334
+ # [
335
+ # [3,47], [4,52], [2,48],
336
+ # ],
337
+ # [
338
+ # [1,64], [2,80], [0,70],
339
+ # ],
340
+ # ]
341
+ # ancova = Num4AnovaLib::Num4AncovaLib.new
342
+ # ancova.interval_estim(xi, 0.05)
343
+ # =>
344
+ # {:min=>4.466605469341916, :max=>7.1909253948556096}
345
+ def interval_estim(xi, a)
346
+ retJava = @ancova.intervalEstim(xi.to_java(Java::double[][]), a)
347
+ retHash = {
348
+ "min": retJava.getMin(),
349
+ "max": retJava.getMax()
350
+ }
351
+ return retHash
352
+ end
317
353
  end
318
354
  end
319
355
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4anova
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-21 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake