diff --git a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java index 5fe9a7b82b..bec7c71c1b 100644 --- a/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java +++ b/tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java @@ -260,6 +260,39 @@ public List getLocalPValues(IndependenceTest independenceTest, List> getLocalPValues(IndependenceTest independenceTest, List facts, Double shuffleThreshold) { + // Call pvalue function on each item, only include the non-null ones. + // pVals is a list of lists of the p values for each shuffled results. + List> pVals_list = new ArrayList<>(); + for (IndependenceFact f : facts) { + Double pV; + // For now, check if the test is FisherZ test. + if (independenceTest instanceof IndTestFisherZ) { + // Shuffle to generate more data from the same graph. + int shuffleTimes = (int) Math.ceil(1 / shuffleThreshold); + List pVals = new ArrayList<>(); + for (int i = 0; i < shuffleTimes; i++) { + List rows = getSubsampleRows(shuffleThreshold); // Default as 0.5 + ((RowsSettable) independenceTest).setRows(rows); // FisherZ will only calc pvalues to those rows + pV = ((IndTestFisherZ) independenceTest).getPValue(f.getX(), f.getY(), f.getZ()); + pVals.add(pV); + } + pVals_list.add(pVals); + } else if (independenceTest instanceof IndTestChiSquare) { + pV = ((IndTestChiSquare) independenceTest).getPValue(f.getX(), f.getY(), f.getZ()); + if (pV != null) pVals_list.add(Arrays.asList(pV)); + } + } + return pVals_list; + } + /** * Tests a list of p-values against the Anderson-Darling Test. *