[R] cpquery problem

Marco Scutari marco.scutari at gmail.com
Mon Aug 1 11:35:35 CEST 2016

Hi Ross,

On 31 July 2016 at 09:11, Ross Chapman <ross.chapman at ecogeonomix.com> wrote:
> I have tried running the cpquery in the debug mode, and found that it
> typically returns the following for instances where the conditional
> probability is returned as 0:
>    > event matches 0 samples out of 0 (p = 0)
> Am I right in understanding that the Monte Carlo sampling has been unable
> to create any cases that match the query?  If so, why would this be if the
> evidence used is very typical of an average case in the data used to train
> the network?

Yes, that is what is happening. As to the reason why, I guess that the
dependencies in the data may not be adequately represented in the
fitted Bayesian network for some reason. What is apparent is that
(EST=='y' & TR>9 & BU>15819 &  RF>2989) has an associated probability
low enough that you do not observe any such sample in rejection
sampling. Now, that being the case, you have two options:

1) use a much larger "n" with a smaller "batch = 10^6" to generate a
lot more particles;
2) switch to likelihood weighting, i.e.

cpquery(fitted,event=(ABW<=11), evidence=list(EST ='y', TR = c(9,
max(data$TR)), BU = c(15819, max(data$BU)), RF = c(2989,
max(data$RF)), n=10^6, method = "lw")

3) look at the parameters in your fitted network and diagnose why this
is happening.


Marco Scutari, Ph.D.
Lecturer in Statistics, Department of Statistics
University of Oxford, United Kingdom

More information about the R-help mailing list