Class MarkovCheck

java.lang.Object
edu.cmu.tetrad.search.MarkovCheck

public class MarkovCheck extends Object
Checks whether a graph is Markov given a data set. First, a list of m-separation predictions are made for each pair of variables in the graph given the parents of one of the variables. One list (for Markov) is for where the m-separation holds and another list (for dependency checks) where the m-separation does not hold. Then the predictions are tested against the data set using the independence test. For the Markov test, since an independence test yielding p-values should be Uniform under the null hypothesis, these p-values are tested for Uniformity using the Kolmogorov-Smirnov test. Also, a fraction of dependent judgments is returned, which should equal the alpha level of the independence test if the test is Uniform under the null hypothesis. For the Faithfulness test, the p-values are tested for Uniformity using the Kolmogorov-Smirnov test; these should be dependent. Also, a fraction of dependent judgments is returned.

Knowledge may be supplied to the Markov check. This knowledge is used to specify independence and conditioning ranges. For facts of the form X _||_ Y | Z, X and Y should be in the last tier of the knowledge, and Z should be in previous tiers. Additional forbidden or required edges are not allowed.

Version:
$Id: $Id
Author:
josephramsey
  • Constructor Details

    • MarkovCheck

      public MarkovCheck(Graph graph, IndependenceTest independenceTest, ConditioningSetType setType)
      Constructor. Takes a graph and an independence test over the variables of the graph.
      Parameters:
      graph - The graph.
      independenceTest - The test over the variables of the graph.
      setType - The type of conditioning sets to use in the Markov check.
  • Method Details

    • getAllSubsetsIndependenceFacts

      @NotNull public @NotNull MarkovCheck.AllSubsetsIndependenceFacts getAllSubsetsIndependenceFacts()
      Returns the set of independence facts used in the Markov check, for dseparation and dconnection separately.
      Returns:
      The set of independence facts used in the Markov check, for dseparation and dconnection separately.
    • getLocalIndependenceFacts

      public List<IndependenceFact> getLocalIndependenceFacts(Node x)
      Retrieves the list of local independence facts for a given node.
      Parameters:
      x - The node for which to retrieve the local independence facts.
      Returns:
      The list of local independence facts for the given node.
    • getLocalPValues

      public List<Double> getLocalPValues(IndependenceTest independenceTest, List<IndependenceFact> facts)
      Calculates the local p-values for a given independence test and a list of independence facts.
      Parameters:
      independenceTest - The independence test used for calculating the p-values.
      facts - The list of independence facts.
      Returns:
      The list of local p-values.
    • checkAgainstAndersonDarlingTest

      public Double checkAgainstAndersonDarlingTest(List<Double> pValues)
      Tests a list of p-values against the Anderson-Darling Test.
      Parameters:
      pValues - the list of p-values to be tested
      Returns:
      the p-value obtained from the Anderson-Darling Test
    • getAndersonDarlingTestAcceptsRejectsNodesForAllNodes

      public List<List<Node>> getAndersonDarlingTestAcceptsRejectsNodesForAllNodes(IndependenceTest independenceTest, Graph graph, Double threshold)
      Calculates the Anderson-Darling test and classifies nodes as accepted or rejected based on the given threshold.
      Parameters:
      independenceTest - The independence test to be used for calculating p-values.
      graph - The graph containing the nodes for testing.
      threshold - The threshold value for classifying nodes.
      Returns:
      A list containing two lists: the first list contains the accepted nodes and the second list contains the rejected nodes.
    • getPrecisionAndRecallOnMarkovBlanketGraph

      public void getPrecisionAndRecallOnMarkovBlanketGraph(Node x, Graph estimatedGraph, Graph trueGraph)
      Calculates the precision and recall on the Markov Blanket graph for a given node. Prints the statistics to the console.
      Parameters:
      x - The target node.
      estimatedGraph - The estimated graph.
      trueGraph - The true graph.
    • getVariables

      public List<Node> getVariables(List<Node> graphNodes, List<Node> independenceNodes, List<Node> conditioningNodes)
      Returns the variables of the independence test.
      Parameters:
      graphNodes - a List object
      independenceNodes - a List object
      conditioningNodes - a List object
      Returns:
      The variables of the independence test.
    • generateResults

      public void generateResults(boolean clear)
      Generates all results, for both the Markov and dependency checks, for each node in the graph given the parents of that node. These results are stored in the resultsIndep and resultsDep lists. This should be called before any of the result methods. Note that only results for X _||_ Y | Z1,...,Zn are generated, where X and Y are in the independenceNodes list and Z1,...,Zn are in the conditioningNodes list.
      Parameters:
      clear - True, if the results should be cleared before generating new results; otherwise, the new results are appended to the existing results.
      See Also:
    • getSetType

      public ConditioningSetType getSetType()
      Returns type of conditioning sets to use in the Markov check.
      Returns:
      The type of conditioning sets to use in the Markov check.
      See Also:
    • setSetType

      public void setSetType(ConditioningSetType setType)
      Sets the type of conditioning sets to use in the Markov check.
      Parameters:
      setType - The type of conditioning sets to use in the Markov check.
      See Also:
    • setParallelized

      public void setParallelized(boolean parallelized)
      True if the checks should be parallelized. (Not always a good idea.)
      Parameters:
      parallelized - True if the checks should be parallelized.
    • getResults

      public List<IndependenceResult> getResults(boolean indep)
      After the generateResults method has been called, this method returns the results for the Markov or dependency check, depending on the value of the indep parameter.
      Parameters:
      indep - True for the Markov results, false for the dependency results.
      Returns:
      The results for the Markov or dependency check.
    • getPValues

      public List<Double> getPValues(List<IndependenceResult> results)
      Returns the list of p-values for the given list of results.
      Parameters:
      results - The results.
      Returns:
      Their p-values.
    • getFractionDependent

      public double getFractionDependent(boolean indep)
      Returns the fraction of dependent judgments for the given list of results.
      Parameters:
      indep - True for the Markov results, false for the dependency results.
      Returns:
      The fraction of dependent judgments for this condition.
    • getFractionDependent

      public double getFractionDependent(List<IndependenceResult> results)
      Calculates the fraction of dependent results.
      Parameters:
      results - the list of IndependenceResult objects
      Returns:
      the fraction of dependent results as a double value
    • getKsPValue

      public double getKsPValue(boolean indep)
      Returns the Kolmorogov-Smirnov p-value for the given list of results.
      Parameters:
      indep - True for the Markov results, false for the dependency results.
      Returns:
      The Kolmorogov-Smirnov p-value for this condition.
    • getAndersonDarlingA2

      public double getAndersonDarlingA2(boolean indep)
      Returns the Anderson-Darling A^2 statistic for the given list of results.
      Parameters:
      indep - True if for implied independencies, false if for implied dependencies.
      Returns:
      The Anderson-Darling A^2 statistic for the given list of results.
    • getAndersonDarlingA2Star

      public double getAndersonDarlingA2Star(boolean indep)
      Returns the Anderson-Darling A^2* statistic for the given list of results.
      Parameters:
      indep - True if for implied independencies, false if for implied dependencies.
      Returns:
      The Anderson-Darling A^2* statistic for the given list of results.
    • getAndersonDarlingP

      public double getAndersonDarlingP(boolean indep)
      Returns the Anderson-Darling p-value for the given list of results.
      Parameters:
      indep - True if for implied independencies, false if for implied dependencies.
      Returns:
      The Anderson-Darling p-value for the given list of results.
    • getBinomialPValue

      public double getBinomialPValue(boolean indep)
      Returns the Binomial p-value for the given list of results.
      Parameters:
      indep - True if for implied independencies, false if for implied dependencies.
      Returns:
      The Binomial p-value for the given list of results.
    • getNumTests

      public int getNumTests(boolean indep)
      Returns the number of tests for the given list of results.
      Parameters:
      indep - True if for implied independencies, false if for implied dependencies.
      Returns:
      The number of tests for the given list of results.
    • getVariable

      public Node getVariable(String name)
      Returns the variable with the given name.
      Parameters:
      name - The name of the variables.
      Returns:
      The variable with the given name.
    • getIndependenceTest

      public IndependenceTest getIndependenceTest()
      Returns the independence test being used.
      Returns:
      This test.
    • setIndependenceTest

      public void setIndependenceTest(IndependenceTest test)
      Sets the independence test to be used for determining independence between variables.
      Parameters:
      test - the independence test to be set
      Throws:
      IllegalArgumentException - if the test parameter is null
    • setPercentResample

      public void setPercentResample(double percentResample)
      Sets the percentage of all samples to use when resampling for each conditional independence test.
      Parameters:
      percentResample - The percentage of all samples to use when resampling for each conditional independence test.
    • getKnowledge

      public Knowledge getKnowledge()
      Returns the knowledge object for the Markov checker. This knowledge object should contain the tier knowledge for the Markov checker. The last tier contains the possible X and Y for X _||_ Y | Z1,...,Zn, and the previous tiers contain the possible Z1,...,Zn for X _||_ Y | Z1,...,Zn. Additional forbidden or required edges are ignored.
      Returns:
      The knowledge object.
    • setKnowledge

      public void setKnowledge(Knowledge knowledge)
      Sets the knowledge object for the Markov checker. The knowledge object should contain the tier knowledge for the Markov checker. The last tier contains the possible X and Y for X _||_ Y | Z1,...,Zn, and the previous tiers contain the possible Z1,...,Zn for X _||_ Y | Z1,...,Zn. Additional forbidden or required edges are ignored.
      Parameters:
      knowledge - The knowledge object.
    • getMarkovCheckRecord

      public MarkovCheck.MarkovCheckRecord getMarkovCheckRecord()
      Generates the results for the given set of independence facts as a single record.
      Returns:
      The Markov check record.
      See Also:
    • getMarkovCheckRecordString

      public String getMarkovCheckRecordString()
      Returns the Markov check record as a string.
      Returns:
      The Markov check record as a string.
      See Also:
    • getIndependenceNodes

      public List<Node> getIndependenceNodes()
      Returns the nodes that are possible X and Y for X _||_ Y | Z1,...,Zn.
      Returns:
      The nodes that are possible X and Y for X _||_ Y | Z1,...,Zn.
    • getConditioningNodes

      public List<Node> getConditioningNodes()
      Returns the nodes that are possible Z1,...,Zn for X _||_ Y | Z1,...,Zn.
      Returns:
      The nodes that are possible Z1,...,Zn for X _||_ Y | Z1,...,Zn.
    • isCpdag

      public boolean isCpdag()
      Checks whether the given graph is a CPDAG (Completed Partially Directed Acyclic Graph).
      Returns:
      true if the graph is a CPDAG, false otherwise
    • getKsPValue

      public double getKsPValue(List<IndependenceResult> visiblePairs)
      Calculates the Kolmogorov-Smirnov (KS) p-value for a list of independence test results.
      Parameters:
      visiblePairs - a list of IndependenceResult objects representing the observed values and expected values for a series of tests
      Returns:
      the KS p-value calculated using the list of independence test results
    • getBinomialPValue

      public double getBinomialPValue(List<IndependenceResult> visiblePairs)
      Calculates the binomial p-value based on the list of visible pairs.
      Parameters:
      visiblePairs - a list of IndependenceResult representing the visible pairs.
      Returns:
      the binomial p-value.
    • getAndersonDarlingA2

      public double getAndersonDarlingA2(List<IndependenceResult> visiblePairs)
      Calculates the Anderson-Darling A2 value for a list of independence results.
      Parameters:
      visiblePairs - the list of independence results
      Returns:
      the Anderson-Darling A2 value
    • getAndersonDarlingPValue

      public double getAndersonDarlingPValue(List<IndependenceResult> visiblePairs)
      Calculates the Anderson-Darling p-value for a given list of independence results.
      Parameters:
      visiblePairs - the list of independence results
      Returns:
      the Anderson-Darling p-value