title: R package bnlearn: cpquery vs predict - different results?
body: <p>I want to use my bayesian network as a classifier, first on complete evidence data (<code>predict</code>), but also on incomplete data (<code>bnlearn::cpquery</code>). But it seems that, even working with the same evidence, the functions give different results (not only based on slight deviation due to sampling).</p>
  
  <p>With complete data, one can easily use R's <code>predict</code> function:</p>
  
  <pre><code>predict(object = BN,
          node = "TargetVar",
          data = FullEvidence ,
          method = "bayes-lw",
          prob = TRUE)
  </code></pre>
  
  <p>By analyzing the <code>prob</code> attribute, I understood that the <code>predict</code>-function simply chooses the factor level with the highest probability assigned.</p>
  
  <p>When it comes to incomplete evidence (only outcomes of some nodes are known), <code>predict</code> doesn't work anymore:</p>
  
  <pre><code>    Error in check.fit.vs.data(fitted = fitted, 
                                 data = data, 
                                 subset = setdiff(names(fitted),  : 
      required variables [.....] are not present in the data.` 
  </code></pre>
  
  <p>So, I want to use <code>bnlearn::cpquery</code> with a list of known evidence:</p>
  
  <pre><code>cpquery(fitted = BN, 
          event = TargetVar == "TRUE", 
          evidence = evidenceList, 
          method = "lw",
          n = 100000)
  </code></pre>
  
  <p>Again, I simply want to use the factor with the highest probability as prediction. So if the result of <code>cpquery</code> is higher than 0.5, I set the prediction to TRUE, else to FALSE.</p>
  
  <p>I tried to monitor the process by giving the same (complete) data to both functions, but they don't give me back the same results. There are large differences, e.g. <code>predict</code>'s "prob"-attribute gives me a p(false) = 27% whereas <code>cpquery</code> gives me p(false) = 2,2%.</p>
  
  <p>What is the "right" way of doing this? Using only cpquery, also for complete data? Why are there large differences?</p>
  
  <p>Thanks for your help!</p>