Skip to content

Commit

Permalink
Merge pull request #1774 from cmu-phil/vbc-05-21-2
Browse files Browse the repository at this point in the history
Introduce shuffle trick to get more local P-values
  • Loading branch information
jdramsey authored May 23, 2024
2 parents 6b40b61 + fd12edc commit 7795487
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tetrad-lib/src/main/java/edu/cmu/tetrad/search/MarkovCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,39 @@ public List<Double> getLocalPValues(IndependenceTest independenceTest, List<Inde
return pVals;
}

/**
* Get Local P values with shuffle threshold provided.
* @param independenceTest
* @param facts
* @param shuffleThreshold
* @return
*/
public List<List<Double>> getLocalPValues(IndependenceTest independenceTest, List<IndependenceFact> 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<List<Double>> 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<Double> pVals = new ArrayList<>();
for (int i = 0; i < shuffleTimes; i++) {
List<Integer> 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.
*
Expand Down

0 comments on commit 7795487

Please sign in to comment.