Beispiel #1
0
  @Override
  public final void compute() {

    if (!m.isDefined() || (n != null && !n.isDefined()) || inputText == null) {
      outputText.setTextString("");
      return;
    }

    String str = inputText.getTextString();

    if (str == null) {
      outputText.setUndefined();
      return;
    }

    size = str.length();
    int start = (int) m.getDouble();
    double nVal = n == null ? size : n.getDouble();
    int end = (int) nVal;

    if (nVal == 0 && inputText.isDefined() && start > 0 && start <= size) {
      outputText.setTextString("");
      return;
    }

    if (!inputText.isDefined() || size == 0 || start <= 0 || end > size || start > end) {
      outputText.setUndefined();
      return;
    }

    outputText.setTextString(str.substring(start - 1, end));
  }
  @Override
  public final void compute() {

    String testType;
    if (tail.getTextString().equals("<")) {
      testType = "left";
    } else if (tail.getTextString().equals(">")) {
      testType = "right";
    } else if (StringUtil.isNotEqual(tail.getTextString())) {
      testType = "two";
    } else {
      result.setUndefined();
      return;
    }

    double n1 = n.getDouble();
    double phat1 = proportion.getDouble();
    double n2 = n_2.getDouble();
    double phat2 = proportion2.getDouble();

    double x1 = phat1 * n1;
    double x2 = phat2 * n2;
    double phatTotal = (x1 + x2) / (n1 + n2);
    se = Math.sqrt(phatTotal * (1 - phatTotal) * (1 / n1 + 1 / n2));
    double testStatistic = (phat1 - phat2) / se;

    NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1);
    double P = 0;
    try {
      P = normalDist.cumulativeProbability(testStatistic);
    } catch (Exception e) {
      result.setUndefined();
      return;
    }

    if ("right".equals(testType)) {
      P = 1 - P;
    } else if ("two".equals(testType)) {
      if (testStatistic < 0) {
        P = 2 * P;
      } else {
        P = 2 * (1 - P);
      }
    }

    // put these results into the output list
    result.clear();
    result.addNumber(P, null);
    result.addNumber(testStatistic, null);
  }