num4tststatistic 0.1.1-java → 0.2.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Rakefile +2 -1
- data/ext/num4tststatistic/Outlier.java +167 -0
- data/lib/jcommon-1.0.23.jar +0 -0
- data/lib/jfreechart-1.5.4.jar +0 -0
- data/lib/num4tststatistic.rb +24 -5
- metadata +5 -3
- data/ext/num4tststatistic/TstStatistic.java +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62b37b59313675f7368ad7b832a2e1c0854c052c1b8c3974955a47163541c3be
|
4
|
+
data.tar.gz: 6a9eb3010d68e6ac2e32c83b4c4721961f7c1f11ee719c6d97fc7067d1a58715
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf6e1c470ccdf7678e1dca59d665272afed757599655a3538ab5e5e2fb833605791951ad51a46d588372dcbf2a5a064edbf86d4d1c8df6a2b3d1b70a121a546e
|
7
|
+
data.tar.gz: deb89b3b2b3da1cea324f3c37ee49c1898450776dc45a7db61282b322734ec521988da85cb682cfb6c90b642fe1ceed37eefc2d378c07147457347463ffa3239
|
data/CHANGELOG.md
CHANGED
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 =
|
6
|
+
ext.classpath = jars.map { |x| File.expand_path x }.join ":"
|
6
7
|
end
|
7
8
|
task :default => [:compile]
|
@@ -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, "外れ値", "dt1"); };
|
160
|
+
if (max > maxQ) { data.addValue(max, "外れ値", "dt1"); };
|
161
|
+
return data;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
|
Binary file
|
Binary file
|
data/lib/num4tststatistic.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
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 '
|
6
|
+
java_import 'Outlier'
|
6
7
|
java_import 'ParametrixTest'
|
7
8
|
java_import 'NonParametrixTest'
|
8
9
|
|
@@ -302,10 +303,10 @@ module Num4TstStatisticLib
|
|
302
303
|
end
|
303
304
|
# コルモゴルフ・スミルノフ検定(2標本)
|
304
305
|
#
|
305
|
-
# @overload ks2test(xi1, xi2)
|
306
|
+
# @overload ks2test(xi1, xi2, a)
|
306
307
|
# @param [Array] xi1 x1のデータ(double[])
|
307
308
|
# @param [Array] xi2 x2のデータ(double[])
|
308
|
-
# @param [double]
|
309
|
+
# @param [double] a 有意水準
|
309
310
|
# @return [boolean] 検定結果(true:棄却域内 false:棄却域外)
|
310
311
|
# @example
|
311
312
|
# xi1 = [165, 130, 182, 178, 194, 206, 160, 122, 212, 165, 247, 195]
|
@@ -319,7 +320,10 @@ module Num4TstStatisticLib
|
|
319
320
|
return @nonParamTest.ks2test(xi1.to_java(Java::double), xi2.to_java(Java::double), a)
|
320
321
|
end
|
321
322
|
end
|
322
|
-
class
|
323
|
+
class OutlierLib
|
324
|
+
def initialize
|
325
|
+
@outlier = Outlier.getInstance()
|
326
|
+
end
|
323
327
|
# グラプス・スミルノフの外れ値の検定量
|
324
328
|
#
|
325
329
|
# @overload grubbs(xi, xk)
|
@@ -333,7 +337,22 @@ module Num4TstStatisticLib
|
|
333
337
|
# @note
|
334
338
|
# 外れ値の検定に従う
|
335
339
|
def grubbs(xi, xk)
|
336
|
-
return
|
340
|
+
return @outlier.grubbs(xi.to_java(Java::double), xk)
|
341
|
+
end
|
342
|
+
# エラーバー出力
|
343
|
+
#
|
344
|
+
# @overload errbar(dname, xi)
|
345
|
+
# @param [String] dname データ名
|
346
|
+
# @param [Array] xi xiのデータ(double[])
|
347
|
+
# @return [void] errbar.jpegファイルを出力
|
348
|
+
# @example
|
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
|
352
|
+
# @note
|
353
|
+
# グラフは、jfreechartを使用
|
354
|
+
def errbar(dname, xi)
|
355
|
+
return @outlier.errbar(dname, xi.to_java(Java::double))
|
337
356
|
end
|
338
357
|
end
|
339
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- siranovel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -62,9 +62,11 @@ files:
|
|
62
62
|
- LICENSE
|
63
63
|
- Rakefile
|
64
64
|
- ext/num4tststatistic/NonParametrixTest.java
|
65
|
+
- ext/num4tststatistic/Outlier.java
|
65
66
|
- ext/num4tststatistic/ParametrixTest.java
|
66
|
-
- ext/num4tststatistic/TstStatistic.java
|
67
67
|
- lib/commons-math3-3.6.1.jar
|
68
|
+
- lib/jcommon-1.0.23.jar
|
69
|
+
- lib/jfreechart-1.5.4.jar
|
68
70
|
- lib/num4tststatistic.rb
|
69
71
|
homepage: http://github.com/siranovel/num4tststatistic
|
70
72
|
licenses:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import java.util.Arrays;
|
2
|
-
|
3
|
-
import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
|
4
|
-
public class TstStatistic {
|
5
|
-
public static double grubbs(double[] xi, double xk) {
|
6
|
-
SummaryStatistics stat = new SummaryStatistics();
|
7
|
-
|
8
|
-
Arrays.stream(xi).forEach(stat::addValue);
|
9
|
-
double m = stat.getMean(); // 平均
|
10
|
-
double sd = stat.getStandardDeviation();// 標準偏差
|
11
|
-
double min = stat.getMin();
|
12
|
-
double max = stat.getMax();
|
13
|
-
double t = 0.0;
|
14
|
-
|
15
|
-
if (xk == min) { t = (m - xk) / sd; }
|
16
|
-
if (xk == max) { t = (xk - m) / sd; }
|
17
|
-
return t;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
|