コード例 #1
0
  private double[] dependencePvalsLinear(Node x, Node y, List<Node> z) {
    if (!variablesPerNode.containsKey(x)) {
      throw new IllegalArgumentException("Unrecogized node: " + x);
    }

    if (!variablesPerNode.containsKey(y)) {
      throw new IllegalArgumentException("Unrecogized node: " + y);
    }

    for (Node node : z) {
      if (!variablesPerNode.containsKey(node)) {
        throw new IllegalArgumentException("Unrecogized node: " + node);
      }
    }

    List<Node> yzDumList = new ArrayList<>();
    List<Node> yzList = new ArrayList<>();
    yzList.add(y);
    yzList.addAll(z);
    // List<Node> zList = new ArrayList<>();

    yzDumList.addAll(variablesPerNode.get(y));
    for (Node _z : z) {
      yzDumList.addAll(variablesPerNode.get(_z));
      // zList.addAll(variablesPerNode.get(_z));
    }

    int[] _rows = getNonMissingRows(x, y, z);
    regression.setRows(_rows);

    RegressionResult result;

    try {
      result = regression.regress(x, yzDumList);
    } catch (Exception e) {
      return null;
    }

    double[] pVec = new double[yzList.size()];
    double[] pCoef = result.getP();

    // skip intercept at 0
    int coeffInd = 1;

    for (int i = 0; i < pVec.length; i++) {
      List<Node> curDummy = variablesPerNode.get(yzList.get(i));
      if (curDummy.size() == 1) {
        pVec[i] = pCoef[coeffInd];
        coeffInd++;
        continue;
      } else {
        pVec[i] = 0;
      }

      for (Node n : curDummy) {
        pVec[i] += Math.log(pCoef[coeffInd]);
        coeffInd++;
      }

      if (pVec[i] == Double.NEGATIVE_INFINITY) pVec[i] = 0.0;
      else
        pVec[i] =
            1.0
                - new ChiSquaredDistribution(2 * curDummy.size())
                    .cumulativeProbability(-2 * pVec[i]);
    }

    return pVec;
  }