num4anova 0.0.11-java → 0.0.13-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: 84f7f49327e10a3da88a363daa4d6d5dec1dd4da00827d6f8e5c60ee6db4bc08
4
+ data.tar.gz: 495495a96d218034014971770b654431bb0df61aec47f8f3171fe351285022c4
5
5
  SHA512:
6
- metadata.gz: 42836d15f6460c2650a7c6cb17c15de206bbabb52c40d988714fe26564d019974a416db4c22f67ed0c535694022575d380603da7c029f0b04476d4994ffca7a5
7
- data.tar.gz: ed1698ed0b05da8d2f0d7417fd1271bcb41754d76fa68b19fb300245449a634c830636ea790a49b89d87066c320c55e2260464bb791ba795f8193664a0babb28
6
+ metadata.gz: 1b46cc7670940eb88343959c80bad55209a981388acdd823c3d9eeafa72a629d2319cfb49707f3f998d72f0d080480785129c948c8ebedb388693476be59add1
7
+ data.tar.gz: 83585b2c13c1f964b8bf92e507a005deb4d358a612e23b939cb9d9911175006a1378e16719c1b73073834aa510f245b4432f0aba9f5dfcdceb78ee2cf5638ba3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.13] - 2024-04-04
6
+
7
+ ### chg
8
+ - chg fuction of interval_estim.
9
+
10
+ ## [0.0.12] - 2024-03-27
11
+
12
+ ### add
13
+ - add fuction of interval_estim.
14
+
5
15
  ## [0.0.11] - 2024-03-21
6
16
 
7
17
  ### 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,93 @@ 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
+ Interval[] ret = new Interval[xi.length];
351
+ ni = calcNi(xi);
352
+ int sumn = calcSumn(xi);
353
+ n = sumn - xi.length - 1;
354
+ sumex = calcSex(xi, sumn);
355
+ double ve = calcVe(xi, sumn);
356
+ double b = calcB(xi, sumn);
357
+
358
+ double[] meanyi = calcMeanyi(xi);
359
+ double[] meanxi = calcMeanxi(xi);
360
+ double meanx = calcMeanx(xi);
361
+
362
+ TDistribution tDist = new TDistribution(n);
363
+ double t = tDist.inverseCumulativeProbability(1.0 - a / 2.0);
364
+ for(int i = 0; i < ret.length; i++) {
365
+ double wk = (meanxi[i] - meanx);
366
+ double wk2 = t * Math.sqrt((1/ni[i] + wk * wk / sumex) * ve);
367
+ double min = meanyi[i] - b * wk - wk2;
368
+ double max = meanyi[i] - b * wk + wk2;
369
+
370
+ ret[i] = new Interval(min, max);
371
+ }
372
+
373
+ return ret;
374
+ }
375
+ private int[] calcNi(double[][][] xi) {
376
+ int[] ni = new int[xi.length];
377
+
378
+ for(int i = 0; i < xi.length; i++) {
379
+ ni[i] = xi[i].length;
380
+ }
381
+ return ni;
382
+ }
383
+ private double calcVe(double[][][] xi, int sumn) {
384
+ double sumey = calcSey(xi, sumn);
385
+ double sumeyx = calcSeyx(xi, sumn);
386
+
387
+ return (sumey * sumex - sumeyx * sumeyx) / (n * sumex);
388
+ }
389
+ private double calcB(double[][][] xi, int sumn) {
390
+ double sumeyx = calcSeyx(xi, sumn);
391
+ double sex = calcSex(xi, sumn);
392
+
393
+ return sumeyx / sex;
394
+ }
395
+ private double[] calcMeanyi(double[][][] xi) {
396
+ double[] meanyi = new double[xi.length];
397
+
398
+ for(int i = 0; i < xi.length; i++) {
399
+ double sum = 0.0;
400
+ for(int j = 0; j < xi[i].length; j++) {
401
+ sum += xi[i][j][0];
402
+ }
403
+ meanyi[i] = sum / xi[i].length;
404
+ }
405
+ return meanyi;
406
+ }
407
+ private double[] calcMeanxi(double[][][] xi) {
408
+ double[] meanxi = new double[xi.length];
409
+
410
+ for(int i = 0; i < xi.length; i++) {
411
+ double sum = 0.0;
412
+ for(int j = 0; j < xi[i].length; j++) {
413
+ sum += xi[i][j][1];
414
+ }
415
+ meanxi[i] = sum / xi[i].length;
416
+ }
417
+ return meanxi;
418
+ }
419
+ private double calcMeanx(double[][][] xi) {
420
+ double sum = 0.0;
421
+ double n = 0;
422
+ for(int i = 0; i < xi.length; i++) {
423
+ for(int j = 0; j < xi[i].length; j++) {
424
+ sum += xi[i][j][1];
425
+ n++;
426
+ }
427
+ }
428
+ return sum / n;
429
+ }
430
+ }
324
431
  }
325
432
 
data/lib/num4anova.rb CHANGED
@@ -314,6 +314,52 @@ 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
+ # {:min=>5.05699825110459, :max=>6.386335082228742}
346
+ # {:min=>2.510804295684195, :max=>4.250430272217034}
347
+ # {:min=>2.8089257316042135, :max=>2.9566298239513418}
348
+ # {:min=>-6.303283147572267, :max=>-0.6577045067487104}
349
+ def interval_estim(xi, a)
350
+ retRb = []
351
+ retJava = @ancova.intervalEstim(xi.to_java(Java::double[][]), a)
352
+ sz = retJava.size
353
+ sz.times do |i|
354
+ retRb.push(
355
+ {
356
+ "min": retJava[i].getMin(),
357
+ "max": retJava[i].getMax()
358
+ }
359
+ )
360
+ end
361
+ return retRb
362
+ end
317
363
  end
318
364
  end
319
365
 
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.13
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-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake