num4regana 0.0.2-java → 0.0.3-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad6fa72619eb7a02bdc561494b9aae197c37b6a8558fd21106bdf15210a9af81
4
- data.tar.gz: c7a55ac44970c164dc7379a11955f29416392ceba4605118f8bcbba459724e94
3
+ metadata.gz: e3b63549f4e9c8d1779a21f7247bae8c034c4066e9907b53c76281c84c18c114
4
+ data.tar.gz: 19bd91c1939a3055b03a5bf35b516e09f31360cdeb227baab648c5277f843de9
5
5
  SHA512:
6
- metadata.gz: dd9e09e45d35384a3bfa9eb50a0132f4b3b3e970c2f97d241264a18a08986c3a46753d2292caf10c0ae1fcab8ec4f45f6456c97fe14df2ee9334168cd429a60a
7
- data.tar.gz: 1cf8a55a5444c5e1e1a151adbb4d142bceaa9344cde28a859848b5642ce36660b6b919410907f8964105ec35df991591670ba8722658a708822e0840d790ce23
6
+ metadata.gz: ed0417b5fd2374d6ce4b3253484f532c40675fdf920e0bd7f10ec65e1c14ff7d1cf8be8fc748d9c68fe173613e67c4bcfa97235c43dbd4a9a65533a7a5fa38f1
7
+ data.tar.gz: a630e9d0ea9b931542b439617f9b28b38f1b0ac6e857ae95538cb04da60407af0882bf2654ec444abcbe150109c5e40bfcaf372d8514f5f621eb9af23cdb13fc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## [0.0.3] - 2024-09-05
6
+
7
+ ### add
8
+ - add GLM
9
+ logistic regression analystis
10
+ poisson regression analystis
11
+
5
12
  ## [0.0.2] - 2024-08-08
6
13
 
7
14
  ### fix
@@ -0,0 +1,82 @@
1
+ public class LogitRegAna {
2
+ private static LogitRegAna regana = new LogitRegAna();
3
+ public static LogitRegAna getInstance() {
4
+ return regana;
5
+ }
6
+ public LineReg nonLineRegAna(double[] yi, double xij[][]) {
7
+ NonLineRegAna line = new NonLineRegAna();
8
+
9
+ return line.nonLineRegAna(yi, xij);
10
+ }
11
+ /*********************************/
12
+ /* interface define */
13
+ /*********************************/
14
+ /*********************************/
15
+ /* class define */
16
+ /*********************************/
17
+ public class LineReg {
18
+ private double a = 0.0;
19
+ private double[] b = null;
20
+ public LineReg(double[] b) {
21
+ this.a = b[0];
22
+ this.b = new double[b.length - 1];
23
+ for (int i = 0; i < this.b.length; i++) {
24
+ this.b[i] = b[i + 1];
25
+ }
26
+ }
27
+ public double getIntercept() {
28
+ return a;
29
+ }
30
+ public double[] getSlope() {
31
+ return b;
32
+ }
33
+ }
34
+ private class NonLineRegAna {
35
+ private final double eta = 0.001;
36
+ private final int num = 10000;
37
+ public LineReg nonLineRegAna(double[] yi, double[][] xij) {
38
+ double[] b = new double[1 + xij[0].length];
39
+
40
+ for(int i = 0; i < b.length; i++) {
41
+ b[i] = 0.0;
42
+ }
43
+ for (int i = 0; i < num; i++) {
44
+ b = grand_metod(yi, b, xij);
45
+ }
46
+ return new LineReg(b);
47
+ }
48
+ // q = b0 + b1 * x0
49
+ private double rereion(double[] b, double[] xi) {
50
+ double ret = b[0];
51
+
52
+ for(int i = 0; i < xi.length; i++) {
53
+ ret += b[i + 1] * xi[i];
54
+ }
55
+ return ret;
56
+ }
57
+ // p = 1 / (1 + exp( -q))
58
+ private double sigmoid(double q) {
59
+ return 1.0 / (1.0 + Math.exp(-1.0 * q));
60
+ }
61
+ private double[] grand_metod(double[] yi, double[] b, double[][] xij) {
62
+ double e0 = 0.0;
63
+ double[] en = new double[xij[0].length];
64
+
65
+ for(int i = 0; i < yi.length; i++) {
66
+ double q = rereion(b, xij[i]);
67
+ double p = sigmoid(q);
68
+
69
+ e0 += (yi[i] - p);
70
+ for(int j = 0; j < en.length; j++) {
71
+ en[j] += (yi[i] - p) * xij[i][j];
72
+ }
73
+ }
74
+ b[0] = b[0] + eta * e0;
75
+ for(int j = 0; j < en.length; j++) {
76
+ b[1 + j] += eta * en[j];
77
+ }
78
+ return b;
79
+ }
80
+ }
81
+ }
82
+
@@ -12,33 +12,23 @@ public class MultRegAna {
12
12
  return regana;
13
13
  }
14
14
  public LineReg lineRegAna(double[] yi, double xij[][]) {
15
- double[][] data = createData(yi, xij);
16
- LineRegAna line = createLineRegAna(data);
15
+ LineRegAna line = createLineRegAna(yi, xij);
17
16
 
18
17
  return line.lineRegAna(yi, xij);
19
18
  }
20
19
  public double getR2(double[] yi, double xij[][]) {
21
- double[][] data = createData(yi, xij);
22
- LineRegAna line = createLineRegAna(data);
20
+ LineRegAna line = createLineRegAna(yi, xij);
23
21
 
24
22
  return line.getR2(yi, xij);
25
23
  }
26
24
  public double getAdjR2(double[] yi, double xij[][]) {
27
- double[][] data = createData(yi, xij);
28
- LineRegAna line = createLineRegAna(data);
25
+ LineRegAna line = createLineRegAna(yi, xij);
29
26
 
30
27
  return line.getAdjR2(yi, xij);
31
28
  }
32
- private double[][] createData(double[] yi, double xij[][]) {
33
- double[][] data = new double[yi.length][1 + xij[0].length];
29
+ private LineRegAna createLineRegAna(double[] yi, double xij[][]) {
30
+ double[][] data = createData(yi, xij);
34
31
 
35
- for (int i = 0; i < yi.length; i++) {
36
- data[i][0] = yi[i];
37
- System.arraycopy(xij[i], 0, data[i], 1, xij[0].length);
38
- }
39
- return data;
40
- }
41
- private LineRegAna createLineRegAna(double data[][]) {
42
32
  // 等分散性の検定
43
33
  if (false == bartletTest(data)) { // 等分散性
44
34
  return new OLSMultRegAna();
@@ -47,6 +37,15 @@ public class MultRegAna {
47
37
  return new GLSMultRegAna(data);
48
38
  }
49
39
  }
40
+ private double[][] createData(double[] yi, double xij[][]) {
41
+ double[][] data = new double[yi.length][1 + xij[0].length];
42
+
43
+ for (int i = 0; i < yi.length; i++) {
44
+ data[i][0] = yi[i];
45
+ System.arraycopy(xij[i], 0, data[i], 1, xij[0].length);
46
+ }
47
+ return data;
48
+ }
50
49
  private boolean bartletTest(double data[][]) {
51
50
  OneWayAnovaTest anova = new BartletTest();
52
51
  double statistic = anova.calcTestStatistic(data);
@@ -0,0 +1,82 @@
1
+ public class PoissonRegAna {
2
+ private static PoissonRegAna regana = new PoissonRegAna();
3
+ public static PoissonRegAna getInstance() {
4
+ return regana;
5
+ }
6
+ public LineReg nonLineRegAna(double[] yi, double[][] xij) {
7
+ NonLineRegAna line = new NonLineRegAna();
8
+
9
+ return line.nonLineRegAna(yi, xij);
10
+ }
11
+ /*********************************/
12
+ /* interface define */
13
+ /*********************************/
14
+ /*********************************/
15
+ /* class define */
16
+ /*********************************/
17
+ public class LineReg {
18
+ private double a = 0.0;
19
+ private double[] b = null;
20
+ public LineReg(double[] b) {
21
+ this.a = b[0];
22
+ this.b = new double[b.length - 1];
23
+ for (int i = 0; i < this.b.length; i++) {
24
+ this.b[i] = b[i + 1];
25
+ }
26
+ }
27
+ public double getIntercept() {
28
+ return a;
29
+ }
30
+ public double[] getSlope() {
31
+ return b;
32
+ }
33
+ }
34
+ private class NonLineRegAna {
35
+ private final double eta = 0.005;
36
+ private final int num = 1000;
37
+ public LineReg nonLineRegAna(double[] yi, double[][] xij) {
38
+ double[] b = new double[1 + xij[0].length];
39
+
40
+ for(int i = 0; i < b.length; i++) {
41
+ b[i] = 0.0;
42
+ }
43
+ for (int i = 0; i < num; i++) {
44
+ b = grand_metod(yi, b, xij);
45
+ }
46
+
47
+ return new LineReg(b);
48
+ }
49
+ // q = b0 + b1 * x0
50
+ private double rereion(double[] b, double[] xi) {
51
+ double ret = b[0];
52
+
53
+ for(int i = 0; i < xi.length; i++) {
54
+ ret += b[i + 1] * xi[i];
55
+ }
56
+ return ret;
57
+ }
58
+ private double linkFunc(double q) {
59
+ return Math.exp(q);
60
+ }
61
+ private double[] grand_metod(double[] yi, double[] b, double[][] xij) {
62
+ double e0 = 0.0;
63
+ double[] en = new double[xij[0].length];
64
+
65
+ for(int i = 0; i < yi.length; i++) {
66
+ double q = rereion(b, xij[i]);
67
+ double p = linkFunc(q);
68
+
69
+ e0 += (yi[i] - p);
70
+ for(int j = 0; j < en.length; j++) {
71
+ en[j] += (yi[i] - p) * xij[i][j];
72
+ }
73
+ }
74
+ b[0] += eta * e0;
75
+ for(int j = 0; j < en.length; j++) {
76
+ b[1 + j] += eta * en[j];
77
+ }
78
+ return b;
79
+ }
80
+ }
81
+ }
82
+
@@ -0,0 +1,100 @@
1
+ require 'java'
2
+ require 'num4regana.jar'
3
+ require 'commons-math3-3.6.1.jar'
4
+
5
+ java_import 'LogitRegAna'
6
+ java_import 'PoissonRegAna'
7
+
8
+ # 一般化線形回帰分析
9
+ # (Apache commoms math3使用)
10
+ module Num4GLMRegAnaLib
11
+ # (2項)ロジスティック回帰分析
12
+ class LogitRegAnaLib
13
+ def initialize
14
+ @multana = LogitRegAna.getInstance()
15
+ end
16
+ # (2項)ロジスティック回帰分析
17
+ #
18
+ # @overload non_line_reg_ana(yi, xij)
19
+ # @param [Array] yi yの値(double[])
20
+ # @param [Array] xij xの値(double[][])
21
+ # @return [Hash] (intercept:定数項 slope:回帰係数)
22
+ # @example
23
+ # glsyi = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
24
+ # glsxij = [
25
+ # [95],
26
+ # [90],
27
+ # [85],
28
+ # [80],
29
+ # [80],
30
+ # [75],
31
+ # [70],
32
+ # [70],
33
+ # [65],
34
+ # [50],
35
+ # [60],
36
+ # [55],
37
+ # [45],
38
+ # [65],
39
+ # [40],
40
+ # [35],
41
+ # [55],
42
+ # [50],
43
+ # [50],
44
+ # [45],
45
+ # ]
46
+ # regana = Num4RegAnaLib::LogitRegAnaLib.new
47
+ # regana.non_line_reg_ana(glsyi, glsxij)
48
+ # =>
49
+ # {
50
+ # "intercept": -17.81, # 定数項
51
+ # "slope": [0.16], # 回帰係数
52
+ # }
53
+ def non_line_reg_ana(yi, xij)
54
+ multRet = @multana.nonLineRegAna(yi.to_java(Java::double), xij.to_java(Java::double[]))
55
+ retRb = {
56
+ "intercept": multRet.getIntercept(), # 定数項
57
+ "slope": multRet.getSlope().to_a, # 回帰係数
58
+ }
59
+ return retRb
60
+ end
61
+ end
62
+ # ポアソン回帰分析
63
+ class PoissonRegAnaLib
64
+ def initialize
65
+ @multana = PoissonRegAna.getInstance()
66
+ end
67
+ # ポアソン回帰分析
68
+ #
69
+ # @overload non_line_reg_ana(yi, xij)
70
+ # @param [Array] yi yの値(double[])
71
+ # @param [Array] xij xの値(double[][])
72
+ # @return [Hash] (intercept:定数項 slope:回帰係数)
73
+ # @example
74
+ # glsyi = [4, 10, 7, 14]
75
+ # glsxij = [
76
+ # [1],
77
+ # [2],
78
+ # [3],
79
+ # [4],
80
+ # ]
81
+ # regana = Num4RegAnaLib::PoissonRegAnaLib.new
82
+ # regana.non_line_reg_ana(glsyi, glsxij)
83
+ # =>
84
+ # {
85
+ # "intercept": 1.3138, # 定数項
86
+ # "slope": [0.3173], # 回帰係数
87
+ # }
88
+ def non_line_reg_ana(yi, xij)
89
+ multRet = @multana.nonLineRegAna(yi.to_java(Java::double), xij.to_java(Java::double[]))
90
+ retRb = {
91
+ "intercept": multRet.getIntercept(), # 定数項
92
+ "slope": multRet.getSlope().to_a, # 回帰係数
93
+ }
94
+ return retRb
95
+ end
96
+ end
97
+ end
98
+
99
+
100
+
@@ -0,0 +1,165 @@
1
+ require 'java'
2
+ require 'num4regana.jar'
3
+ require 'commons-math3-3.6.1.jar'
4
+
5
+ java_import 'SmplRegAna'
6
+ java_import 'MultRegAna'
7
+ # 線形回帰分析
8
+ # (Apache commoms math3使用)
9
+ module Num4LineRegAnaLib
10
+ # 単回帰分析
11
+ class SmplRegAnaLib
12
+ def initialize
13
+ @regana = SmplRegAna.getInstance()
14
+ end
15
+ # 単回帰分析
16
+ #
17
+ # @overload line_reg_ana(yi, xi)
18
+ # @param [Array] yi yの値(double[])
19
+ # @param [Array] xi xの値(double[])
20
+ # @return [Hash] (intercept:定数項 slope:回帰係数)
21
+ # @example
22
+ # yi = [286, 851, 589, 389, 158, 1037, 463, 563, 372, 1020]
23
+ # xi = [107, 336, 233, 82, 61, 378, 129, 313, 142, 428]
24
+ # regana = Num4RegAnaLib::SmplRegAnaLib.new
25
+ # regana.line_reg_ana(yi, xi)
26
+ # =>
27
+ # {
28
+ # "intercept": 99.075, # 定数項
29
+ # "slope": 2.145, # 回帰係数
30
+ # }
31
+ def line_reg_ana(yi, xi)
32
+ ret = @regana.lineRegAna(yi.to_java(Java::double), xi.to_java(Java::double))
33
+ retRb = {
34
+ "intercept": ret.getIntercept(), # 定数項
35
+ "slope": ret.getSlope(), # 回帰係数
36
+ }
37
+ return retRb
38
+ end
39
+ # 決定係数
40
+ #
41
+ # @overload getr2(yi, xi)
42
+ # @param [Array] yi yの値(double[])
43
+ # @param [Array] xi xの値(double[])
44
+ # @return [double] 決定係数
45
+ # @example
46
+ # yi = [286, 851, 589, 389, 158, 1037, 463, 563, 372, 1020]
47
+ # xi = [107, 336, 233, 82, 61, 378, 129, 313, 142, 428]
48
+ # regana = Num4RegAnaLib::SmplRegAnaLib.new
49
+ # regana.getr2(yi, xi)
50
+ # => 0.893
51
+ def getr2(yi, xi)
52
+ return @regana.getR2(yi.to_java(Java::double), xi.to_java(Java::double))
53
+ end
54
+ # 相関係数
55
+ #
56
+ # @overload getr(yi, xi)
57
+ # @param [Array] yi yの値(double[])
58
+ # @param [Array] xi xの値(double[])
59
+ # @return [double] 決定係数
60
+ # @example
61
+ # yi = [286, 851, 589, 389, 158, 1037, 463, 563, 372, 1020]
62
+ # xi = [107, 336, 233, 82, 61, 378, 129, 313, 142, 428]
63
+ # regana = Num4RegAnaLib::SmplRegAnaLib.new
64
+ # regana.getr(yi, xi)
65
+ # => 0.945
66
+ def getr(yi, xi)
67
+ return @regana.getR(yi.to_java(Java::double), xi.to_java(Java::double))
68
+ end
69
+ end
70
+ # 重回帰分析(最小2乗法:等分散性checkあり)
71
+ class OLSMultRegAnaLib
72
+ def initialize
73
+ @multana = MultRegAna.getInstance()
74
+ end
75
+ # 重回帰分析
76
+ #
77
+ # @overload line_reg_ana(yi, xij)
78
+ # @param [Array] yi yの値(double[])
79
+ # @param [Array] xij xの値(double[][])
80
+ # @return [Hash] (intercept:定数項 slope:回帰係数)
81
+ # @example
82
+ # olsyi = [45, 38, 41, 34, 59, 47, 35, 43, 54, 52]
83
+ # olsxij = [
84
+ # [17.5, 30],
85
+ # [17.0, 25],
86
+ # [18.5, 20],
87
+ # [16.0, 30],
88
+ # [19.0, 45],
89
+ # [19.5, 35],
90
+ # [16.0, 25],
91
+ # [18.0, 35],
92
+ # [19.0, 35],
93
+ # [19.5, 40],
94
+ # ]
95
+ # regana = Num4RegAnaLib::OLSMultRegAnaLib.new
96
+ # regana.line_reg_ana(olsyi, olsxij)
97
+ # =>
98
+ # {
99
+ # "intercept": -34.71, # 定数項
100
+ # "slope": [3.47, 0.53], # 回帰係数
101
+ # }
102
+ def line_reg_ana(yi, xij)
103
+ multRet = @multana.lineRegAna(yi.to_java(Java::double), xij.to_java(Java::double[]))
104
+
105
+ retRb = {
106
+ "intercept": multRet.getIntercept(), # 定数項
107
+ "slope": multRet.getSlope().to_a, # 回帰係数
108
+ }
109
+ return retRb
110
+ end
111
+ # 決定係数
112
+ #
113
+ # @overload getr2(yi, xij)
114
+ # @param [Array] yi yの値(double[])
115
+ # @param [Array] xij xの値(double[][])
116
+ # @return [double] 決定係数
117
+ # @example
118
+ # olsyi = [45, 38, 41, 34, 59, 47, 35, 43, 54, 52]
119
+ # olsxij = [
120
+ # [17.5, 30],
121
+ # [17.0, 25],
122
+ # [18.5, 20],
123
+ # [16.0, 30],
124
+ # [19.0, 45],
125
+ # [19.5, 35],
126
+ # [16.0, 25],
127
+ # [18.0, 35],
128
+ # [19.0, 35],
129
+ # [19.5, 40],
130
+ # ]
131
+ # regana = Num4RegAnaLib::OLSMultRegAnaLib.new
132
+ # regana.getr2(yi, xi)
133
+ # => 0.858
134
+ def getr2(yi, xij)
135
+ return @multana.getR2(yi.to_java(Java::double), xij.to_java(Java::double[]))
136
+ end
137
+ # 自由度調整済み決定係数
138
+ #
139
+ # @overload getadjr2(yi, xij)
140
+ # @param [Array] yi yの値(double[])
141
+ # @param [Array] xij xの値(double[][])
142
+ # @return [double] 決定係数
143
+ # @example
144
+ # olsyi = [45, 38, 41, 34, 59, 47, 35, 43, 54, 52]
145
+ # olsxij = [
146
+ # [17.5, 30],
147
+ # [17.0, 25],
148
+ # [18.5, 20],
149
+ # [16.0, 30],
150
+ # [19.0, 45],
151
+ # [19.5, 35],
152
+ # [16.0, 25],
153
+ # [18.0, 35],
154
+ # [19.0, 35],
155
+ # [19.5, 40],
156
+ # ]
157
+ # regana = Num4RegAnaLib::OLSMultRegAnaLib.new
158
+ # regana.getadjr2(yi, xij)
159
+ # => 0.8176
160
+ def getadjr2(yi, xij)
161
+ return @multana.getAdjR2(yi.to_java(Java::double), xij.to_java(Java::double[]))
162
+ end
163
+ end
164
+ end
165
+
data/lib/num4regana.rb CHANGED
@@ -1,166 +1,9 @@
1
- require 'java'
2
- require 'num4regana.jar'
3
- require 'commons-math3-3.6.1.jar'
1
+ require_relative('num4lineregana')
2
+ require_relative('num4glmregana')
4
3
 
5
- java_import 'SmplRegAna'
6
- java_import 'MultRegAna'
7
- # 回帰分析
8
- # (Apache commoms math3使用)
9
4
  module Num4RegAnaLib
10
- # 単回帰分析
11
- class SmplRegAnaLib
12
- def initialize
13
- @regana = SmplRegAna.getInstance()
14
- end
15
- # 単回帰分析
16
- #
17
- # @overload line_reg_ana(yi, xi)
18
- # @param [Array] yi yの値(double[])
19
- # @param [Array] xi xの値(double[])
20
- # @return [Hash] (intercept:定数項 slope:回帰係数)
21
- # @example
22
- # yi = [286, 851, 589, 389, 158, 1037, 463, 563, 372, 1020]
23
- # xi = [107, 336, 233, 82, 61, 378, 129, 313, 142, 428]
24
- # regana = Num4RegAnaLib::SmplRegAnaLib.new
25
- # regana.line_reg_ana(yi, xi)
26
- # =>
27
- # {
28
- # "intercept": 99.075, # 定数項
29
- # "slope": 2.145, # 回帰係数
30
- # }
31
- def line_reg_ana(yi, xi)
32
- ret = @regana.lineRegAna(yi.to_java(Java::double), xi.to_java(Java::double))
33
- retRb = {
34
- "intercept": ret.getIntercept(), # 定数項
35
- "slope": ret.getSlope(), # 回帰係数
36
- }
37
- return retRb
38
- end
39
- # 決定係数
40
- #
41
- # @overload getr2(yi, xi)
42
- # @param [Array] yi yの値(double[])
43
- # @param [Array] xi xの値(double[])
44
- # @return [double] 決定係数
45
- # @example
46
- # yi = [286, 851, 589, 389, 158, 1037, 463, 563, 372, 1020]
47
- # xi = [107, 336, 233, 82, 61, 378, 129, 313, 142, 428]
48
- # regana = Num4RegAnaLib::SmplRegAnaLib.new
49
- # regana.getr2(yi, xi)
50
- # => 0.893
51
- def getr2(yi, xi)
52
- return @regana.getR2(yi.to_java(Java::double), xi.to_java(Java::double))
53
- end
54
- # 相関係数
55
- #
56
- # @overload getr(yi, xi)
57
- # @param [Array] yi yの値(double[])
58
- # @param [Array] xi xの値(double[])
59
- # @return [double] 決定係数
60
- # @example
61
- # yi = [286, 851, 589, 389, 158, 1037, 463, 563, 372, 1020]
62
- # xi = [107, 336, 233, 82, 61, 378, 129, 313, 142, 428]
63
- # regana = Num4RegAnaLib::SmplRegAnaLib.new
64
- # regana.getr(yi, xi)
65
- # => 0.945
66
- def getr(yi, xi)
67
- return @regana.getR(yi.to_java(Java::double), xi.to_java(Java::double))
68
- end
69
- end
70
- # 重回帰分析(最小2乗法:等分散性checkあり)
71
- class OLSMultRegAnaLib
72
- def initialize
73
- @multana = MultRegAna.getInstance()
74
- end
75
- # 重回帰分析
76
- #
77
- # @overload line_reg_ana(yi, xij)
78
- # @param [Array] yi yの値(double[])
79
- # @param [Array] xij xの値(double[][])
80
- # @return [Hash] (intercept:定数項 slope:回帰係数)
81
- # @example
82
- # olsyi = [45, 38, 41, 34, 59, 47, 35, 43, 54, 52]
83
- # olsxij = [
84
- # [17.5, 30],
85
- # [17.0, 25],
86
- # [18.5, 20],
87
- # [16.0, 30],
88
- # [19.0, 45],
89
- # [19.5, 35],
90
- # [16.0, 25],
91
- # [18.0, 35],
92
- # [19.0, 35],
93
- # [19.5, 40],
94
- # ]
95
- # regana = Num4RegAnaLib::OLSMultRegAnaLib.new
96
- # regana.line_reg_ana(olsyi, olsxij)
97
- # =>
98
- # {
99
- # "intercept": -34.71, # 定数項
100
- # "slope": [3.47, 0.53], # 回帰係数
101
- # }
102
- def line_reg_ana(yi, xij)
103
- multRet = @multana.lineRegAna(yi.to_java(Java::double), xij.to_java(Java::double[]))
104
-
105
- retRb = {
106
- "intercept": multRet.getIntercept(), # 定数項
107
- "slope": multRet.getSlope().to_a, # 回帰係数
108
- }
109
- return retRb
110
- end
111
- # 決定係数
112
- #
113
- # @overload getr2(yi, xij)
114
- # @param [Array] yi yの値(double[])
115
- # @param [Array] xij xの値(double[][])
116
- # @return [double] 決定係数
117
- # @example
118
- # olsyi = [45, 38, 41, 34, 59, 47, 35, 43, 54, 52]
119
- # olsxij = [
120
- # [17.5, 30],
121
- # [17.0, 25],
122
- # [18.5, 20],
123
- # [16.0, 30],
124
- # [19.0, 45],
125
- # [19.5, 35],
126
- # [16.0, 25],
127
- # [18.0, 35],
128
- # [19.0, 35],
129
- # [19.5, 40],
130
- # ]
131
- # regana = Num4RegAnaLib::OLSMultRegAnaLib.new
132
- # regana.getr2(yi, xi)
133
- # => 0.858
134
- def getr2(yi, xij)
135
- return @multana.getR2(yi.to_java(Java::double), xij.to_java(Java::double[]))
136
- end
137
- # 自由度調整済み決定係数
138
- #
139
- # @overload getadjr2(yi, xij)
140
- # @param [Array] yi yの値(double[])
141
- # @param [Array] xij xの値(double[][])
142
- # @return [double] 決定係数
143
- # @example
144
- # olsyi = [45, 38, 41, 34, 59, 47, 35, 43, 54, 52]
145
- # olsxij = [
146
- # [17.5, 30],
147
- # [17.0, 25],
148
- # [18.5, 20],
149
- # [16.0, 30],
150
- # [19.0, 45],
151
- # [19.5, 35],
152
- # [16.0, 25],
153
- # [18.0, 35],
154
- # [19.0, 35],
155
- # [19.5, 40],
156
- # ]
157
- # regana = Num4RegAnaLib::OLSMultRegAnaLib.new
158
- # regana.getadjr2(yi, xij)
159
- # => 0.8176
160
- def getadjr2(yi, xij)
161
- return @multana.getAdjR2(yi.to_java(Java::double), xij.to_java(Java::double[]))
162
- end
163
-
164
- end
5
+ include Num4LineRegAnaLib
6
+ include Num4GLMRegAnaLib
165
7
  end
166
8
 
9
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: num4regana
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: java
6
6
  authors:
7
7
  - siranovel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-08 00:00:00.000000000 Z
11
+ date: 2024-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -61,9 +61,13 @@ files:
61
61
  - Gemfile
62
62
  - LICENSE
63
63
  - Rakefile
64
+ - ext/num4regana/LogitRegAna.java
64
65
  - ext/num4regana/MultRegAna.java
66
+ - ext/num4regana/PoissonRegAna.java
65
67
  - ext/num4regana/SmplRegAna.java
66
68
  - lib/commons-math3-3.6.1.jar
69
+ - lib/num4glmregana.rb
70
+ - lib/num4lineregana.rb
67
71
  - lib/num4regana.rb
68
72
  homepage: http://github.com/siranovel/num4regana
69
73
  licenses: