use of org.apache.commons.math3.distribution.ChiSquaredDistribution in project tetrad by cmu-phil.
the class IndTestMixedMultipleTTest method dependencePvalsLinear.
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;
}
use of org.apache.commons.math3.distribution.ChiSquaredDistribution in project presto by prestodb.
the class MathFunctions method chiSquaredCdf.
@Description("ChiSquared cdf given the df parameter and value")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double chiSquaredCdf(@SqlType(StandardTypes.DOUBLE) double df, @SqlType(StandardTypes.DOUBLE) double value) {
checkCondition(value >= 0, INVALID_FUNCTION_ARGUMENT, "value must non-negative");
checkCondition(df > 0, INVALID_FUNCTION_ARGUMENT, "df must be greater than 0");
ChiSquaredDistribution distribution = new ChiSquaredDistribution(null, df, ChiSquaredDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
return distribution.cumulativeProbability(value);
}
Aggregations