|
|
@@ -1,188 +1,270 @@
|
|
|
package com.lc.ibps.components.verification.model2;
|
|
|
|
|
|
+import com.lc.ibps.components.verification.report.TableDTO;
|
|
|
import org.apache.commons.math3.stat.StatUtils;
|
|
|
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
|
|
|
|
|
|
-public class PrecisionEP15 extends CalcVO {
|
|
|
-
|
|
|
- private double[][] data;
|
|
|
-
|
|
|
- /*
|
|
|
-
|
|
|
- Number of replicates 3
|
|
|
- Number of days 5
|
|
|
- A B C D E F G
|
|
|
- Rep 1 Rep 2 Rep 3 Run mean Run SD Variance
|
|
|
- 5 Day 1 3.3 3.23 3.43 3.320 0.101 0.010
|
|
|
- 6 Day 2 3.21 3.45 3.42 3.360 0.131 0.017
|
|
|
- 7 Day 3 3.21 3.24 3.45 3.300 0.131 0.017
|
|
|
- 8 Day 4 3.5 3.45 3.51 3.487 0.032 0.001
|
|
|
- 9 Day 5 3.33 3.45 3.32 3.367 0.072 0.005
|
|
|
-
|
|
|
- 11 Over all mean [ Average E5:E9] 3.367 总均值
|
|
|
- 12 Within run variance Vr [ average G5:G9] 0.010
|
|
|
- 13 Within run SD [SQRT(B12)] 0.101 批内标准差(Sr)
|
|
|
- 14 Between run SD [SD(E5:E9)] 0.073
|
|
|
- 15 Between run variance Vb [B14*B14] 0.005 批间方差
|
|
|
- 16 Ratio Vr/Vb [+B12/B15] 1.928
|
|
|
- 17 Total variance [((B2-1)/B2)*B12+B15] 0.012
|
|
|
- 18 Laboratory SD [SQRT B17] 0.110 室内标准差
|
|
|
- 19 Laboratory CV[ (B18/B11)*100] 3.259
|
|
|
- */
|
|
|
- private double mean;
|
|
|
- private double sr;
|
|
|
- private double vb;
|
|
|
- private double s1;
|
|
|
-
|
|
|
- private double cvr;
|
|
|
- private double cv1;
|
|
|
- private double n;
|
|
|
- private int decimal;
|
|
|
-
|
|
|
- private double allowableCvr;
|
|
|
- private double allowableCv1;
|
|
|
- private double allowableSr;
|
|
|
- private double allowableS1;
|
|
|
-
|
|
|
- public PrecisionEP15(double[][] data, double allowableCvr, double allowableCv1, int decimal) {
|
|
|
- this.data = data;
|
|
|
- this.n = data[0].length;
|
|
|
- this.allowableCvr = allowableCvr;
|
|
|
- this.allowableCv1 = allowableCv1;
|
|
|
- this.decimal = decimal;
|
|
|
- calculate();
|
|
|
- }
|
|
|
+import java.util.*;
|
|
|
|
|
|
- public double getSr() {
|
|
|
- return sr;
|
|
|
- }
|
|
|
+public class PrecisionEP15 extends PVModel {
|
|
|
|
|
|
- public double getVb() {
|
|
|
- return vb;
|
|
|
- }
|
|
|
+ private List<Item> items = new ArrayList<>(); //[day][replicate]
|
|
|
|
|
|
- public double getMean() {
|
|
|
- return mean;
|
|
|
- }
|
|
|
+ private String[] specimensName;
|
|
|
|
|
|
- public void setMean(double mean) {
|
|
|
- this.mean = mean;
|
|
|
+ public PrecisionEP15(String[] specimensName, int decimal) {
|
|
|
+ this.specimensName = specimensName;
|
|
|
+ this.setScale(decimal);
|
|
|
}
|
|
|
|
|
|
- public void setSr(double sr) {
|
|
|
- this.sr = sr;
|
|
|
+ public void buildItem(String name,double[][] data, double allowableCvr, double allowableCv1 ){
|
|
|
+ items.add(new Item(name,data,allowableCvr,allowableCv1));
|
|
|
}
|
|
|
|
|
|
- public void setVb(double vb) {
|
|
|
- this.vb = vb;
|
|
|
- }
|
|
|
|
|
|
- public double getS1() {
|
|
|
- return s1;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public TableDTO buildDataTableDTO() {
|
|
|
+ String[] h = new String[specimensName.length+1];
|
|
|
+ Map<String,String[]> child = new HashMap<>();
|
|
|
+ String[] c = new String[items.get(0).data[0].length ];
|
|
|
+ for (int i = 0; i < c.length ; i++) {
|
|
|
+ c[i] = String.format("重复 %d",(i+1));
|
|
|
+ }
|
|
|
+ h[0] = "天数";
|
|
|
+ for (int i = 0; i < specimensName.length; i++) {
|
|
|
+ h[1+i] = specimensName[i];
|
|
|
+ child.put(h[i+1],c);
|
|
|
+ }
|
|
|
+ TableDTO table = new TableDTO();
|
|
|
+ table.buildHeader(h,child);
|
|
|
|
|
|
- public void setS1(double s1) {
|
|
|
- this.s1 = s1;
|
|
|
- }
|
|
|
+ List<double[]> temp = new ArrayList<>();
|
|
|
+ double[] first = new double[items.get(0).data.length];
|
|
|
+ for (int i = 0; i <items.get(0).data.length; i++) {
|
|
|
+ first[i] = i+1;
|
|
|
+ }
|
|
|
+ temp.add(first);
|
|
|
+ for (int i = 0; i < specimensName.length; i++) {
|
|
|
+ temp.addAll(Arrays.<double[]>asList(transposeMatrix(items.get(i).data)));
|
|
|
+ }
|
|
|
|
|
|
- public double getCvr() {
|
|
|
- return cvr;
|
|
|
- }
|
|
|
+ double[][] toArray = temp.toArray(new double[0][0]);
|
|
|
+ table.buildData(transposeMatrix(toArray),getScale());
|
|
|
+ return table;
|
|
|
|
|
|
- public void setCvr(double cvr) {
|
|
|
- this.cvr = cvr;
|
|
|
}
|
|
|
|
|
|
- public double getCv1() {
|
|
|
- return cv1;
|
|
|
+ @Override
|
|
|
+ public Map<String, TableDTO> buildReportTableDTO() {
|
|
|
+ Map<String, TableDTO> reports = new HashMap<>();
|
|
|
+ for (Item item : items) {
|
|
|
+ reports.putAll(buildTable1DTO(item));
|
|
|
+ }
|
|
|
+ return reports;
|
|
|
}
|
|
|
|
|
|
- public void setCv1(double cv1) {
|
|
|
- this.cv1 = cv1;
|
|
|
+ private Map<String, TableDTO> buildTable1DTO(Item item) {
|
|
|
+ Map<String, TableDTO> reports = new HashMap<>();
|
|
|
+ TableDTO table = new TableDTO();
|
|
|
+ String[][] data = new String[8][2];
|
|
|
+
|
|
|
+ data[0] =new String[]{"总均值" , format(item.mean)};
|
|
|
+ data[1] =new String[]{"批内方差 (V<sub>r</sub>)" , format(item.vr)};
|
|
|
+ data[2] =new String[]{"批内标准差 (S<sub>r</sub>)" , format(item.sr)};
|
|
|
+ data[3] =new String[]{"批内变异系数 (CV<sub>r</sub>)" , format(item.cvr)};
|
|
|
+ data[4] =new String[]{"",""};
|
|
|
+ data[5] =new String[]{"批间方差 (V<sub>b</sub>)" , format(item.vb)};
|
|
|
+// data[4] =new String[]{"批间标准差 (S<sub>b</sub>)" , format(item.sb)};
|
|
|
+ data[6] =new String[]{"实验室内标准差 (S<sub>1</sub>)" , format(item.s1)};
|
|
|
+ data[7] =new String[]{"实验室变异系数 (CV)" , format(item.cv1)};
|
|
|
+ table.buildData(data);
|
|
|
+ reports.put(item.name,table);
|
|
|
+ return reports;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public double getAllowableCvr() {
|
|
|
- return allowableCvr;
|
|
|
- }
|
|
|
+ class Item {
|
|
|
+
|
|
|
+ private double[][] data;
|
|
|
+ private String name;
|
|
|
+
|
|
|
+ /*
|
|
|
+
|
|
|
+ Number of replicates 3
|
|
|
+ Number of days 5
|
|
|
+ A B C D E F G
|
|
|
+ Rep 1 Rep 2 Rep 3 Run mean Run SD Variance
|
|
|
+ 5 Day 1 3.3 3.23 3.43 3.320 0.101 0.010
|
|
|
+ 6 Day 2 3.21 3.45 3.42 3.360 0.131 0.017
|
|
|
+ 7 Day 3 3.21 3.24 3.45 3.300 0.131 0.017
|
|
|
+ 8 Day 4 3.5 3.45 3.51 3.487 0.032 0.001
|
|
|
+ 9 Day 5 3.33 3.45 3.32 3.367 0.072 0.005
|
|
|
+
|
|
|
+ 11 Over all mean [ Average E5:E9] 3.367 总均值
|
|
|
+ 12 Within run variance Vr [ average G5:G9] 0.010
|
|
|
+ 13 Within run SD [SQRT(B12)] 0.101 批内标准差(Sr)
|
|
|
+ 14 Between run SD [SD(E5:E9)] 0.073
|
|
|
+ 15 Between run variance Vb [B14*B14] 0.005 批间方差
|
|
|
+ 16 Ratio Vr/Vb [+B12/B15] 1.928
|
|
|
+ 17 Total variance [((B2-1)/B2)*B12+B15] 0.012
|
|
|
+ 18 Laboratory SD [SQRT B17] 0.110 室内标准差
|
|
|
+ 19 Laboratory CV[ (B18/B11)*100] 3.259
|
|
|
+ */
|
|
|
+ private double mean;
|
|
|
+ private double sr;
|
|
|
+ private double vb;
|
|
|
+ private double s1;
|
|
|
+
|
|
|
+ private double cvr;
|
|
|
+ private double cv1;
|
|
|
+ private double n;
|
|
|
+
|
|
|
+
|
|
|
+ private double allowableCvr;
|
|
|
+ private double allowableCv1;
|
|
|
+ private double allowableSr;
|
|
|
+ private double allowableS1;
|
|
|
+ private double vr;
|
|
|
+ private double sb;
|
|
|
+
|
|
|
+ public Item(String name,double[][] data, double allowableCvr, double allowableCv1) {
|
|
|
+ this.name = name;
|
|
|
+ this.data = data;
|
|
|
+ this.n = data[0].length;
|
|
|
+ this.allowableCvr = allowableCvr;
|
|
|
+ this.allowableCv1 = allowableCv1;
|
|
|
+ calculate();
|
|
|
+ }
|
|
|
|
|
|
- public void setAllowableCvr(double allowableCvr) {
|
|
|
- this.allowableCvr = allowableCvr;
|
|
|
- }
|
|
|
+ public double getSr() {
|
|
|
+ return sr;
|
|
|
+ }
|
|
|
|
|
|
- public double getAllowableCv1() {
|
|
|
- return allowableCv1;
|
|
|
- }
|
|
|
+ public double getVb() {
|
|
|
+ return vb;
|
|
|
+ }
|
|
|
|
|
|
- public void setAllowableCv1(double allowableCv1) {
|
|
|
- this.allowableCv1 = allowableCv1;
|
|
|
- }
|
|
|
+ public double getMean() {
|
|
|
+ return mean;
|
|
|
+ }
|
|
|
|
|
|
- public double getAllowableSr() {
|
|
|
- return allowableSr;
|
|
|
- }
|
|
|
+ public void setMean(double mean) {
|
|
|
+ this.mean = mean;
|
|
|
+ }
|
|
|
|
|
|
- public void setAllowableSr(double allowableSr) {
|
|
|
- this.allowableSr = allowableSr;
|
|
|
- }
|
|
|
+ public void setSr(double sr) {
|
|
|
+ this.sr = sr;
|
|
|
+ }
|
|
|
|
|
|
- public double getAllowableS1() {
|
|
|
- return allowableS1;
|
|
|
- }
|
|
|
+ public void setVb(double vb) {
|
|
|
+ this.vb = vb;
|
|
|
+ }
|
|
|
|
|
|
- public void setAllowableS1(double allowableS1) {
|
|
|
- this.allowableS1 = allowableS1;
|
|
|
- }
|
|
|
+ public double getS1() {
|
|
|
+ return s1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setS1(double s1) {
|
|
|
+ this.s1 = s1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getCvr() {
|
|
|
+ return cvr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCvr(double cvr) {
|
|
|
+ this.cvr = cvr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getCv1() {
|
|
|
+ return cv1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setCv1(double cv1) {
|
|
|
+ this.cv1 = cv1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public double getAllowableCvr() {
|
|
|
+ return allowableCvr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAllowableCvr(double allowableCvr) {
|
|
|
+ this.allowableCvr = allowableCvr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getAllowableCv1() {
|
|
|
+ return allowableCv1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAllowableCv1(double allowableCv1) {
|
|
|
+ this.allowableCv1 = allowableCv1;
|
|
|
+ }
|
|
|
|
|
|
- public void calculate() {
|
|
|
- //批内标准差
|
|
|
+ public double getAllowableSr() {
|
|
|
+ return allowableSr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAllowableSr(double allowableSr) {
|
|
|
+ this.allowableSr = allowableSr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getAllowableS1() {
|
|
|
+ return allowableS1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAllowableS1(double allowableS1) {
|
|
|
+ this.allowableS1 = allowableS1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void calculate() {
|
|
|
+ //批内标准差
|
|
|
// xValue[] vrs = Arrays.stream(data).map(SpecimensCalcVO::getVariance).toArray(xValue[]::new);
|
|
|
// double withinVr = xAverage.eval(vrs).getDoub();
|
|
|
// sr = Math.sqrt(withinVr);
|
|
|
- double[] vrs = new double[data.length];
|
|
|
- for (int i = 0; i < data.length; i++) {
|
|
|
- vrs[i] = StatUtils.variance(data[i]);
|
|
|
- }
|
|
|
- double withinVr = StatUtils.mean(vrs);
|
|
|
- sr = Math.sqrt(withinVr);
|
|
|
- //总均值
|
|
|
+ double[] vrs = new double[data.length];
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ vrs[i] = StatUtils.variance(data[i]);
|
|
|
+ }
|
|
|
+ vr = StatUtils.mean(vrs);
|
|
|
+ sr = Math.sqrt(vr);
|
|
|
+ //总均值
|
|
|
// xValue[] means = Arrays.stream(data).map(SpecimensCalcVO::getMean).toArray(xValue[]::new);
|
|
|
- double[] means = new double[data.length];
|
|
|
- for (int i = 0; i < data.length; i++) {
|
|
|
- means[i] = StatUtils.mean(data[i]);
|
|
|
- }
|
|
|
- DescriptiveStatistics stat = new DescriptiveStatistics(means);
|
|
|
- mean = stat.getMean();
|
|
|
- //批间方差
|
|
|
- double x = stat.getStandardDeviation();
|
|
|
- vb = Math.pow(x, 2);
|
|
|
-
|
|
|
- //室内标准差
|
|
|
- double v = (n - 1) / n;
|
|
|
- s1 = Math.sqrt(v * withinVr + vb);
|
|
|
-
|
|
|
- cvr = (sr / mean) * 100;
|
|
|
- cv1 = (s1 / mean) * 100;
|
|
|
-
|
|
|
- //实验室允许不精密度
|
|
|
- allowableSr = allowableCvr * mean / 100;
|
|
|
- allowableS1 = allowableCv1 * mean / 100;
|
|
|
-
|
|
|
- //format
|
|
|
- allowableSr = format(allowableSr, decimal);
|
|
|
- allowableS1 = format(allowableS1, decimal);
|
|
|
- cv1 = format(cv1, decimal);
|
|
|
- cvr = format(cvr, decimal);
|
|
|
- vb = format(vb, decimal);
|
|
|
- mean = format(mean, decimal);
|
|
|
- sr = format(sr, decimal);
|
|
|
- s1 = format(s1, decimal);
|
|
|
+ double[] means = new double[data.length];
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ means[i] = StatUtils.mean(data[i]);
|
|
|
+ }
|
|
|
+ DescriptiveStatistics stat = new DescriptiveStatistics(means);
|
|
|
+ mean = stat.getMean();
|
|
|
+ //批间标准差
|
|
|
+ sb = stat.getStandardDeviation();
|
|
|
+ //批间方差
|
|
|
+ vb = Math.pow(sb, 2);
|
|
|
+
|
|
|
+ //室内标准差
|
|
|
+ double v = (n - 1) / n;
|
|
|
+ s1 = Math.sqrt(v * vr + vb);
|
|
|
+
|
|
|
+ cvr = (sr / mean) * 100;
|
|
|
+ cv1 = (s1 / mean) * 100;
|
|
|
+
|
|
|
+ //实验室允许不精密度
|
|
|
+ allowableSr = allowableCvr * mean / 100;
|
|
|
+ allowableS1 = allowableCv1 * mean / 100;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
double[][] data = {{3.3, 3.23, 3.43}, {3.21, 3.45, 3.42}, {3.21, 3.24, 3.45}, {3.5, 3.45, 3.51}, {3.33, 3.45, 3.32}};
|
|
|
- PrecisionEP15 precisionEP15 = new PrecisionEP15(data, 0, 0, 3);
|
|
|
-
|
|
|
+ PrecisionEP15 precisionEP15 = new PrecisionEP15(new String[]{"test 1","test 2"},3);
|
|
|
+ precisionEP15.buildItem("test 1",data, 0, 0 );
|
|
|
+ precisionEP15.buildItem("test 2",data, 0, 0 );
|
|
|
+ TableDTO tableDTO = precisionEP15.buildDataTableDTO();
|
|
|
+ Map<String, TableDTO> stringTableDTOMap = precisionEP15.buildReportTableDTO();
|
|
|
+// ChiSquaredDistribution x2 = new ChiSquaredDistribution( 10 );
|
|
|
+// double result = x2.inverseCumulativeProbability(1 - 0.05/2);//level
|
|
|
System.out.println(precisionEP15);
|
|
|
}
|
|
|
}
|