Esempio n. 1
0
 public void testCorr() {
   SimpleRegression regression = new SimpleRegression();
   regression.addData(corrData);
   assertEquals("number of observations", 17, regression.getN());
   assertEquals("r-square", .896123, regression.getRSquare(), 10E-6);
   assertEquals("r", -0.94663767742, regression.getR(), 1E-10);
 }
Esempio n. 2
0
 // Jira MATH-85 = Bugzilla 39432
 public void testSSENonNegative() {
   double[] y = {8915.102, 8919.302, 8923.502};
   double[] x = {1.107178495E2, 1.107264895E2, 1.107351295E2};
   SimpleRegression reg = new SimpleRegression();
   for (int i = 0; i < x.length; i++) {
     reg.addData(x[i], y[i]);
   }
   assertTrue(reg.getSumSquaredErrors() >= 0.0);
 }
Esempio n. 3
0
  public void testPerfectNegative() throws Exception {
    SimpleRegression regression = new SimpleRegression();
    int n = 100;
    for (int i = 0; i < n; i++) {
      regression.addData(-((double) i) / (n - 1), i);
    }

    assertEquals(0.0, regression.getSignificance(), 1.0e-5);
    assertTrue(regression.getSlope() < 0.0);
  }
Esempio n. 4
0
  public void testRandom() throws Exception {
    SimpleRegression regression = new SimpleRegression();
    Random random = new Random(1);
    int n = 100;
    for (int i = 0; i < n; i++) {
      regression.addData(((double) i) / (n - 1), random.nextDouble());
    }

    assertTrue(0.0 < regression.getSignificance() && regression.getSignificance() < 1.0);
  }
 /**
  * Computes the Pearson's product-moment correlation coefficient between the two arrays. Throws
  * IllegalArgumentException if the arrays do not have the same length or their common length is
  * less than 2
  *
  * @param xArray first data array
  * @param yArray second data array
  * @return Returns Pearson's correlation coefficient for the two arrays
  * @throws IllegalArgumentException if the arrays lengths do not match or there is insufficient
  *     data
  */
 public double correlation(final double[] xArray, final double[] yArray)
     throws IllegalArgumentException {
   SimpleRegression regression = new SimpleRegression();
   if (xArray.length == yArray.length && xArray.length > 1) {
     for (int i = 0; i < xArray.length; i++) {
       regression.addData(xArray[i], yArray[i]);
     }
     return regression.getR();
   } else {
     throw MathRuntimeException.createIllegalArgumentException(
         "invalid array dimensions. xArray has size {0}; yArray has {1} elements",
         xArray.length, yArray.length);
   }
 }
Esempio n. 6
0
 public void testClear() {
   SimpleRegression regression = new SimpleRegression();
   regression.addData(corrData);
   assertEquals("number of observations", 17, regression.getN());
   regression.clear();
   assertEquals("number of observations", 0, regression.getN());
   regression.addData(corrData);
   assertEquals("r-square", .896123, regression.getRSquare(), 10E-6);
   regression.addData(data);
   assertEquals("number of observations", 53, regression.getN());
 }
Esempio n. 7
0
  /**
   * Adds a sample to the model with the given frequency and length values.
   *
   * @param averageStepFrequency
   * @param averageStepLength
   */
  public void addSampleToModel(Double averageStepFrequency, Double averageStepLength) {
    // ...insert it into the regression model
    reg.addData(averageStepFrequency, averageStepLength);

    // ...and sample list
    sampleList.add(new AutoGaitSample(averageStepFrequency, averageStepLength));
  }
Esempio n. 8
0
  public AutoGaitModel(double[][] samples) {
    // Add samples to the regression model
    reg.addData(samples);

    // Add values to the sample list
    for (double[] line : samples) addSampleToModel(line[0], line[1]);
  }
Esempio n. 9
0
 // Test remove multiple observations
 public void testRemoveMultiple() throws Exception {
   // Create regression with inference data then remove to test
   SimpleRegression regression = new SimpleRegression();
   regression.addData(infData);
   regression.removeData(removeMultiple);
   regression.addData(removeMultiple);
   // Use the inference assertions to make sure that everything worked
   assertEquals("slope std err", 0.011448491, regression.getSlopeStdErr(), 1E-10);
   assertEquals("std err intercept", 0.286036932, regression.getInterceptStdErr(), 1E-8);
   assertEquals("significance", 4.596e-07, regression.getSignificance(), 1E-8);
   assertEquals(
       "slope conf interval half-width",
       0.0270713794287,
       regression.getSlopeConfidenceInterval(),
       1E-8);
 }
Esempio n. 10
0
 public Double getAlpha() {
   return reg.getSlope();
 }
Esempio n. 11
0
 // Remove multiple observations past empty (i.e. size of array > n)
 public void testRemoveMultiplePastEmpty() {
   SimpleRegression regression = new SimpleRegression();
   regression.addData(removeX, removeY);
   regression.removeData(removeMultiple);
   assertEquals(regression.getN(), 0);
 }
Esempio n. 12
0
 // Remove single observation to empty
 public void testRemoveObsFromSingle() {
   SimpleRegression regression = new SimpleRegression();
   regression.addData(removeX, removeY);
   regression.removeData(removeX, removeY);
   assertEquals(regression.getN(), 0);
 }
Esempio n. 13
0
  public void SummuarySimulation() {
    calculatePower();
    PrintStream Pout1 = null;
    PrintStream Pout2 = null;
    PrintStream Pout3 = null;
    PrintStream Pout4 = null;
    PrintStream Pout5 = null;
    PrintStream Pout6 = null;
    ChiSquaredDistribution chi = new ChiSquaredDistributionImpl(weight.length);
    try {
      Pout1 = new PrintStream(new BufferedOutputStream(new FileOutputStream("LogAP.txt")));
      Pout2 = new PrintStream(new BufferedOutputStream(new FileOutputStream("LNP.txt")));
      Pout3 = new PrintStream(new BufferedOutputStream(new FileOutputStream("LN.txt")));
      Pout4 = new PrintStream(new BufferedOutputStream(new FileOutputStream("Wald.txt")));
      Pout5 = new PrintStream(new BufferedOutputStream(new FileOutputStream("F.txt")));
      Pout6 = new PrintStream(new BufferedOutputStream(new FileOutputStream("LogDP.txt")));
    } catch (Exception E) {
      E.printStackTrace(System.err);
    }
    for (int i = 0; i < SimulationResults.size(); i++) {
      ArrayList PointStatistics = (ArrayList) SimulationResults.get(i);
      double[] LRT = new double[PointStatistics.size()];
      double[] WALD = new double[PointStatistics.size()];
      DescriptiveStatistics dsLRT = new DescriptiveStatisticsImpl();
      DescriptiveStatistics dsWALD = new DescriptiveStatisticsImpl();
      SimpleRegression sr = new SimpleRegression();
      for (int j = 0; j < PointStatistics.size(); j++) {
        PointMappingStatistic pms = (PointMappingStatistic) PointStatistics.get(j);
        double lod = pms.get_LOD() > 0 ? pms.get_LOD() : 0;
        double ln = pms.get_LN();
        double p = 0;
        try {
          p = chi.cumulativeProbability(ln);
        } catch (Exception E) {
          E.printStackTrace(System.err);
        }
        double logLOD = -1 * Math.log10(1 - p);
        Pout1.print(pms.get_logP_additive() + " ");
        Pout2.print(logLOD + " ");
        Pout3.print(pms.get_LN() + " ");
        Pout4.print(pms.get_wald() + " ");
        Pout5.print(pms.get_logP_F() + " ");
        Pout6.print(pms.get_logP_dominance() + " ");

        dsLRT.addValue(pms.get_LN());
        dsWALD.addValue(pms.get_wald());
        LRT[j] = pms.get_LN();
        WALD[j] = pms.get_wald();
        sr.addData(pms.get_LN(), pms.get_wald());
      }
      System.out.println(
          dsLRT.getMean()
              + " +- "
              + dsLRT.getStandardDeviation()
              + " "
              + dsWALD.getMean()
              + " +- "
              + dsWALD.getStandardDeviation()
              + " cor "
              + sr.getR());
      dsLRT.clear();
      dsWALD.clear();
      sr.clear();
      Pout1.println();
      Pout2.println();
      Pout3.println();
      Pout4.println();
      Pout5.println();
      Pout6.println();
    }
    Pout1.close();
    Pout2.close();
    Pout3.close();
    Pout4.close();
    Pout5.close();
    Pout6.close();
  }
Esempio n. 14
0
 public Double getBeta() {
   return reg.getIntercept();
 }
Esempio n. 15
0
  public void testInference() throws Exception {
    // ----------  verified against R, version 1.8.1 -----
    // infData
    SimpleRegression regression = new SimpleRegression();
    regression.addData(infData);
    assertEquals("slope std err", 0.011448491, regression.getSlopeStdErr(), 1E-10);
    assertEquals("std err intercept", 0.286036932, regression.getInterceptStdErr(), 1E-8);
    assertEquals("significance", 4.596e-07, regression.getSignificance(), 1E-8);
    assertEquals(
        "slope conf interval half-width",
        0.0270713794287,
        regression.getSlopeConfidenceInterval(),
        1E-8);
    // infData2
    regression = new SimpleRegression();
    regression.addData(infData2);
    assertEquals("slope std err", 1.07260253, regression.getSlopeStdErr(), 1E-8);
    assertEquals("std err intercept", 4.17718672, regression.getInterceptStdErr(), 1E-8);
    assertEquals("significance", 0.261829133982, regression.getSignificance(), 1E-11);
    assertEquals(
        "slope conf interval half-width",
        2.97802204827,
        regression.getSlopeConfidenceInterval(),
        1E-8);
    // ------------- End R-verified tests -------------------------------

    // FIXME: get a real example to test against with alpha = .01
    assertTrue(
        "tighter means wider",
        regression.getSlopeConfidenceInterval() < regression.getSlopeConfidenceInterval(0.01));

    try {
      regression.getSlopeConfidenceInterval(1);
      fail("expecting IllegalArgumentException for alpha = 1");
    } catch (IllegalArgumentException ex) {
      // ignored
    }
  }
Esempio n. 16
0
  public void testNaNs() {
    SimpleRegression regression = new SimpleRegression();
    assertTrue("intercept not NaN", Double.isNaN(regression.getIntercept()));
    assertTrue("slope not NaN", Double.isNaN(regression.getSlope()));
    assertTrue("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err not NaN", Double.isNaN(regression.getInterceptStdErr()));
    assertTrue("MSE not NaN", Double.isNaN(regression.getMeanSquareError()));
    assertTrue("e not NaN", Double.isNaN(regression.getR()));
    assertTrue("r-square not NaN", Double.isNaN(regression.getRSquare()));
    assertTrue("RSS not NaN", Double.isNaN(regression.getRegressionSumSquares()));
    assertTrue("SSE not NaN", Double.isNaN(regression.getSumSquaredErrors()));
    assertTrue("SSTO not NaN", Double.isNaN(regression.getTotalSumSquares()));
    assertTrue("predict not NaN", Double.isNaN(regression.predict(0)));

    regression.addData(1, 2);
    regression.addData(1, 3);

    // No x variation, so these should still blow...
    assertTrue("intercept not NaN", Double.isNaN(regression.getIntercept()));
    assertTrue("slope not NaN", Double.isNaN(regression.getSlope()));
    assertTrue("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err not NaN", Double.isNaN(regression.getInterceptStdErr()));
    assertTrue("MSE not NaN", Double.isNaN(regression.getMeanSquareError()));
    assertTrue("e not NaN", Double.isNaN(regression.getR()));
    assertTrue("r-square not NaN", Double.isNaN(regression.getRSquare()));
    assertTrue("RSS not NaN", Double.isNaN(regression.getRegressionSumSquares()));
    assertTrue("SSE not NaN", Double.isNaN(regression.getSumSquaredErrors()));
    assertTrue("predict not NaN", Double.isNaN(regression.predict(0)));

    // but SSTO should be OK
    assertTrue("SSTO NaN", !Double.isNaN(regression.getTotalSumSquares()));

    regression = new SimpleRegression();

    regression.addData(1, 2);
    regression.addData(3, 3);

    // All should be OK except MSE, s(b0), s(b1) which need one more df
    assertTrue("interceptNaN", !Double.isNaN(regression.getIntercept()));
    assertTrue("slope NaN", !Double.isNaN(regression.getSlope()));
    assertTrue("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err not NaN", Double.isNaN(regression.getInterceptStdErr()));
    assertTrue("MSE not NaN", Double.isNaN(regression.getMeanSquareError()));
    assertTrue("r NaN", !Double.isNaN(regression.getR()));
    assertTrue("r-square NaN", !Double.isNaN(regression.getRSquare()));
    assertTrue("RSS NaN", !Double.isNaN(regression.getRegressionSumSquares()));
    assertTrue("SSE NaN", !Double.isNaN(regression.getSumSquaredErrors()));
    assertTrue("SSTO NaN", !Double.isNaN(regression.getTotalSumSquares()));
    assertTrue("predict NaN", !Double.isNaN(regression.predict(0)));

    regression.addData(1, 4);

    // MSE, MSE, s(b0), s(b1) should all be OK now
    assertTrue("MSE NaN", !Double.isNaN(regression.getMeanSquareError()));
    assertTrue("slope std err NaN", !Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err NaN", !Double.isNaN(regression.getInterceptStdErr()));
  }
Esempio n. 17
0
  public void testNorris() {
    SimpleRegression regression = new SimpleRegression();
    for (int i = 0; i < data.length; i++) {
      regression.addData(data[i][1], data[i][0]);
    }
    // Tests against certified values from
    // http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Norris.dat
    assertEquals("slope", 1.00211681802045, regression.getSlope(), 10E-12);
    assertEquals("slope std err", 0.429796848199937E-03, regression.getSlopeStdErr(), 10E-12);
    assertEquals("number of observations", 36, regression.getN());
    assertEquals("intercept", -0.262323073774029, regression.getIntercept(), 10E-12);
    assertEquals("std err intercept", 0.232818234301152, regression.getInterceptStdErr(), 10E-12);
    assertEquals("r-square", 0.999993745883712, regression.getRSquare(), 10E-12);
    assertEquals("SSR", 4255954.13232369, regression.getRegressionSumSquares(), 10E-9);
    assertEquals("MSE", 0.782864662630069, regression.getMeanSquareError(), 10E-10);
    assertEquals("SSE", 26.6173985294224, regression.getSumSquaredErrors(), 10E-9);
    // ------------  End certified data tests

    assertEquals("predict(0)", -0.262323073774029, regression.predict(0), 10E-12);
    assertEquals("predict(1)", 1.00211681802045 - 0.262323073774029, regression.predict(1), 10E-12);
  }
Esempio n. 18
0
 /**
  * Returns the coefficient of determination for the underlying linear regression. A value of 1
  * denotes a perfect fit.
  *
  * @return
  */
 public double getRegressionFit() {
   return reg.getRSquare();
 }
Esempio n. 19
0
  public static void calcCharts() throws Exception {

    // alle Dateien einlesen im obigen Ordner
    File[] files = new File(folderIN).listFiles();
    int i = 0;

    Messreihe[] RQs = new Messreihe[zINTER];
    Messreihe[] RISs = new Messreihe[zINTER];
    Vector<Messreihe>[] vRISs = new Vector[zINTER];
    Vector<Messreihe>[] vFITDATA = new Vector[zINTER];

    ReturnIntervallStatistik[] ris = new ReturnIntervallStatistik[zINTER];

    // 58 files and 9 sections ...
    double tTEST_DATA[][][] = new double[files.length][zINTER][5];
    // 0=RQs,  1=m  2=RR  3=FEHLENDE-m  4=FEHLENDE-RR

    for (int ii = 0; ii < zINTER; ii++) {

      ris[ii] = new ReturnIntervallStatistik(pScale, pBinning);
      //            ris[ii].scaleY_LN = sLN;
      //            ris[ii].scaleY_LOG = sLOG;

      RQs[ii] = new Messreihe("RQ_" + ii);

      RISs[ii] = new Messreihe("RIS_" + ii);
      vRISs[ii] = new Vector<Messreihe>();
      vFITDATA[ii] = new Vector<Messreihe>();
    }

    Vector<Messreihe> all = new Vector<Messreihe>();

    double linFitMIN;
    double linFitMAX;

    for (File f : files) {

      if (f.getName().endsWith(".txt")) {

        DecimalFormat nf = new DecimalFormat("0.0000000");

        Messreihe data =
            MessreihenLoader.getLoader().loadMessreihe(new File(folderIN + f.getName()));

        Messreihe[] parts = data.split(zL, zINTER);

        int j = 0;

        // r ist die Messreihe mit den normalen Daten
        for (Messreihe r : parts) {

          double vRQ = r.getAvarage();
          // System.out.print(  "file -> " + i + " part -> " + j + "\t" + nf.format( vRQ ) + "\t" );
          // System.out.print( r.toString() );
          tTEST_DATA[i][j][0] = vRQ;

          vRISs[j].add(r);

          RQs[j].addValue(vRQ);

          ReturnIntervallStatistik rr = new ReturnIntervallStatistik(pScale, pBinning);

          rr.doScale_by_Rq = scaleRQ;
          //                    rr.scaleY_LN = sLN;
          //                    rr.scaleY_LOG = sLOG;
          rr.setRQ(vRQ);

          rr.addDistData(r.getYValues());

          if (scaleRQ) {

            linFitMIN = linFit_MIN * vRQ;
            linFitMAX = linFit_MAX * vRQ;
            // System.out.println( "( " + linFit_MIN + ", " + linFit_MAX + ") ");

          } else {
            linFitMIN = linFit_MIN;
            linFitMAX = linFit_MAX;
            // System.out.println( "( " + linFitMIN + ", " + linFitMAX + ") ");
          }
          ;

          // hier sollten nun die Daten für jede Reihe da sein ...

          /** Problem: in den einzelnen Reihen kann man nicht sinnvoll den Anstieg bestimmen !!! */
          Messreihe toFit = rr.mrHaeufigkeit.shrinkX(linFit_MIN, linFit_MAX);

          SimpleRegression reg;
          try {
            reg = toFit.linFit(linFit_MIN, linFit_MAX);

            double slope = reg.getSlope();
            double RR = reg.getRSquare();

            // System.out.println("m=" + slope + " \tRR=" + RR);
            tTEST_DATA[i][j][1] = slope;
            tTEST_DATA[i][j][2] = RR;
            all.add(toFit);

          } catch (Exception ex) {
            // Logger.getLogger(RISAnalyse3.class.getName()).log(Level.SEVERE, null, ex);

          }

          vFITDATA[j].add(rr.mrHaeufigkeit);
          try {
            ris[j].add(rr);
          } catch (Exception ex) {
            Logger.getLogger(RISAnalyse3.class.getName()).log(Level.SEVERE, null, ex);
          }
          j++;
        }
        i++;
      }
    }

    if (showRAWData) {
      for (int i3 = 0; i3 < zINTER; i3++) {
        MultiChart.openAndStore(
            vRISs[i3],
            label + " Intervall: " + i3 + " - scale=" + pScale + ", binning=" + pBinning,
            "r",
            "P(r)",
            false,
            folderOUT,
            label + "_P(r)",
            getParameterSet());
      }
    }

    System.out.print(folderOUT);
    Messreihe rq = new Messreihe("Rq(i)");
    Messreihe rqSIGMA = new Messreihe("sigma(Rq(i))");
    Vector<Messreihe> chart2Data = new Vector<Messreihe>();
    chart2Data.add(rq);
    chart2Data.add(rqSIGMA);

    Vector<Messreihe> vMR = new Vector<Messreihe>();
    // für alle Intervalle des Files ...
    for (int d = 0; d < zINTER; d++) {
      try {
        ris[d].calcMessreihen();
      } catch (Exception ex) {
        Logger.getLogger(RISAnalyse3.class.getName()).log(Level.SEVERE, null, ex);
      }
      RISs[d] = ris[d].mrHaeufigkeit;

      // System.out.println( "(b)\n" + ris[d].toString() );
      ris[d].mrVerteilung.setLabel("Int_" + (d + 1));
      vMR.add(ris[d].mrVerteilung);

      RQs[d].calcAverage();

      rq.addValuePair((double) d, RQs[d].getAvarage());

      rqSIGMA.addValuePair((double) d, RQs[d].getStddev());
    }
    rq.normalize();
    rqSIGMA.normalize();

    // auf VMR nun den Fit ANWENDEN ...
    Messreihe fitData1 = new Messreihe();
    fitData1.setLabel("m");

    Messreihe fitData2 = new Messreihe();
    fitData2.setLabel("RR");

    Vector<Messreihe> vFITS = new Vector<Messreihe>();

    SimpleRegression reg2;
    int c = 0;
    for (Messreihe mr : vMR) {
      try {
        reg2 = mr.linFit(linFit_MIN, linFit_MAX);

        double slope = reg2.getSlope();
        double RR = reg2.getRSquare();

        fitData1.addValuePair(c, slope);
        fitData2.addValuePair(c, RR);

        System.out.println("\tm=" + slope + " \tRR=" + RR);
        c++;
      } catch (Exception ex) {

      }
    }
    ;
    fitData1.normalize();
    fitData2.normalize();

    vFITS.add(fitData1);
    vFITS.add(fitData2);

    if (showRAWRIS) {
      for (int i3 = 0; i3 < zINTER; i3++) {
        MultiChart.openAndStore(
            vFITDATA[i3],
            "vFIT " + label + " Intervall: " + i3 + " - scale=" + pScale + ", binning=" + pBinning,
            "r",
            "P(r)",
            false,
            folderOUT,
            label + "_P(r)",
            getParameterSet());
      }
    }

    String labelX = "r/Rq";
    String labelY = "P(r)*Rq";

    if (!scaleRQ) {
      labelX = "r";
      labelY = "P(r)";
    }
    if (sLOG) {
      labelY = "log(" + labelY + ")";
    }
    if (sLN) {
      labelY = "ln(" + labelY + ")";
    }

    if (showCharts) {
      MultiChart.openAndStore(
          vMR,
          label + " - scale=" + pScale + ", binning=" + pBinning,
          labelX,
          labelY,
          true,
          folderOUT,
          label + "_P(r)",
          getParameterSet());

      MultiChart.openAndStore(
          vFITS,
          "FIT " + label + " - scale=" + pScale + ", binning=" + pBinning,
          "i",
          "m(i) RR(i)",
          true,
          folderOUT,
          label + "_m(i)_RR(i)",
          getParameterSet());

      MultiChart.openAndStore(
          chart2Data,
          label + " - Rq(i)",
          "i",
          "<Rq>, <sigma(Rq)>",
          true,
          folderOUT,
          label + "_Rq(i)",
          getParameterSet());

      MultiChart.open(
          all,
          "ALL " + label + " - scale=" + pScale + ", binning=" + pBinning,
          "x",
          "y",
          false,
          getParameterSet());
    }

    MesswertTabelle tab1 = new MesswertTabelle();
    tab1.setHeader(getParameterSet());
    tab1.setLabel(label + "_P(r)");
    tab1.setMessReihen(vMR);
    tab1.writeToFile(new File(folderOUT + File.separator + tab1.getLabel() + ".dat"));

    MesswertTabelle tab6 = new MesswertTabelle();
    tab6.setHeader(getParameterSet());
    tab6.setLabel(label + "_m(i)_RR(i)");
    tab6.setMessReihen(vFITS);
    tab6.writeToFile(
        new File(folderOUT + File.separator + "out" + File.separator + tab6.getLabel() + ".dat"));

    MesswertTabelle tab2 = new MesswertTabelle();
    tab2.setHeader(getParameterSet());
    tab2.setLabel(label + "_Rq(i)");
    tab2.setMessReihen(chart2Data);
    tab2.writeToFile(new File(folderOUT + File.separator + tab2.getLabel() + ".dat"));

    String fn = folderOUT + "/tTests_" + label + ".xls";
    String fnTEMPL = folderOUT + "/tTests.xls";

    HSSFWorkbook wb = null;
    HSSFSheet[] sheets = new HSSFSheet[3];

    File f2 = new File(fn);
    File f1 = new File(fnTEMPL);

    // Lesen der bestehenden Tabelle
    FileInputStream fis = null;
    try {
      //
      // Create a FileInputStream that will be use to read the excel file.
      //
      fis = new FileInputStream(fn);

      //
      // Create an excel workbook from the file system.
      //
      wb = new HSSFWorkbook(fis);
      //
      // Get the first sheet on the workbook.
      //
    } catch (Exception ex) {
      ex.printStackTrace();

      System.err.println(">>> " + ex.getMessage());
      System.out.println("> Erzeuge neue XLS Datei ... ");

      wb = new HSSFWorkbook();
      sheets[0] = wb.createSheet("R_q");
      sheets[1] = wb.createSheet("m");
      sheets[2] = wb.createSheet("RR");
    }

    Messreihe[] mrRESULTS = new Messreihe[5];
    try {
      sheets[0] = wb.getSheet("R_q");
      sheets[1] = wb.getSheet("m");
      sheets[2] = wb.getSheet("RR");

      // zur Sammlung der Mittelwerte für die Resultate ...
      mrRESULTS[0] = new Messreihe("<R_q>");
      mrRESULTS[1] = new Messreihe("<m>");
      mrRESULTS[2] = new Messreihe("<RR>");
      mrRESULTS[3] = new Messreihe("{m}");
      mrRESULTS[4] = new Messreihe("{RR}");

      // SCHRANKE für auszulassende Werte
      double epsilon = 1e-6;

      // ANZAHL der Reihen
      for (int i2 = 1; i2 < files.length; i2++) {
        // ANZAHL der INTERVALLE
        for (int j2 = 0; j2 < zINTER; j2++) {
          // ANZAHL der MESSSGRÖSSEN
          for (int k2 = 0; k2 < 3; k2++) {

            HSSFRow row = sheets[k2].getRow(i2);
            if (row == null) row = sheets[k2].createRow(i2);

            row.createCell(1).setCellValue(i2);
            double value = tTEST_DATA[i2][j2][k2];
            if (!Double.isNaN(value)) {
              if (value > epsilon) {
                row.createCell(j2 + 1).setCellValue(value);
              }
            } else {
              row.createCell(j2 + 1).setCellValue("");
            }
            // System.out.println( i2 +"\t" + j2 + "\t" + k2 + "\t" + tTEST_DATA[i2][j2][k2]);

          }
        }
      }

      // MW für alle Spalten berechnen ... für drei Messwerte ...
      for (int x = 0; x < 3; x++) {

        double eps = 1e-3;

        double anz = 0.0;
        double summe = 0.0;

        int counterNAN_values = 0;
        // ANZAHL der INTERVALLE
        for (int j2 = 0; j2 < zINTER; j2++) {

          // ANZAHL der Reihen
          for (int i2 = 1; i2 < files.length; i2++) {
            double value = tTEST_DATA[i2][j2][x];

            double RR = tTEST_DATA[i2][j2][2];

            if (!Double.isNaN(value)) {
              //                            if ( value > eps ) {  // Variante 1
              //                            if ( RR > 0.75) {  // Variante 2
              summe = summe + value;
              anz++;
              //                            }
            } else {
              counterNAN_values++;
            }
          }
          double mw = summe / anz;
          mrRESULTS[x].addValuePair(j2, mw);
          if (x > 0) mrRESULTS[x + 2].addValuePair(j2, counterNAN_values);

          anz = 0.0;
          summe = 0.0;
          counterNAN_values = 0;
        }
      }

      mrRESULTS[3].normalize();
      mrRESULTS[4].normalize();

      Vector<Messreihe> v = new Vector<Messreihe>();
      v.add(mrRESULTS[0]);
      v.add(mrRESULTS[1]);
      v.add(mrRESULTS[2]);
      v.add(mrRESULTS[3]);
      v.add(mrRESULTS[4]);

      if (showCharts) {
        MultiChart.openAndStore(
            v,
            label + " - scale=" + pScale + ", binning=" + pBinning,
            "i",
            "f(i)",
            true,
            folderOUT,
            label + "_chart3",
            getParameterSet());
      }

      FileOutputStream fout2 = new FileOutputStream(f2.getAbsolutePath());
      wb.write(fout2);
      fout2.close();

      String[] titles = {"P(r)", "Rq(i)", "chart3", "m(i)_RR(i)"};
      report.createResultlinePNG(label, titles, getParameterSetHTML());

      System.out.println("[READY] " + label + "");

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }