Thursday, November 23, 2006

Simple Pregnancy Testing (revisited)

A little more detailed description of the simple pregnancy testing example described here. This is a description of the network, that can be downloaded as the HUGIN netfile DRGTTEST.NET

The standard management procedure in sow production is to make a pregnancy test four weeks after mating in order to establish, whether a sow is pregnant or not. Often the farmer will know the expected pregnancy rate in the herd. The test precision will depend on the skill of the farmer. This can be modelled in a Bayesian Network (BN) as shown in the figure

The graph consists of three nodes:

  • S, Pregnancy state. Indicates the true state of the sow. The node has two states: (No, Yes). The á priori probabilities are (0.3, 0.7).
  • M, Method for pregnancy testing. Indicates the quality of the pregnancy tester. The node has two states (Good, Bad) with á priori probabilities (0.5, 0.5).
  • T, Outcome of Pregnancy Test Indicates the outcome of the pregnancy test. The node has two states (Neg, Pos) indicating a negative and a positive outcome respectively.
Method Good Bad
State no yes no yes
neg 0.85 0.15 0.65 0.15
pos 0.15 0.95 0.35 0.85

Using GRAPPA

The network is available as a Hugin netfile here, but there are several options for handling the network.

One possibility is Peter Greens GRAPPA program available for use in R, which is a free software environment for statistical computing and graphics. R can be downloaded from a CRAN mirror.

Unfortunately, GRAPPA is not available as a standard R-package, which would make it easier to install and use. But if you visit the home page you simple need to download the R source code, the Windows DLL (or the Fortran source code if you're not using Windows), and the user guide in PDF format.

Then you can proceed as follows (currently R produces some warnings, which you may ignorere).

 # load grappa source code
 source("grappa.r")

 # define the three nodes
 query('S',c(0.3,0.7))
 query('M',c(0.5,0.5))

 tab(c('T','S','M'),,
     c(0.85,0.15,
       0.05,0.95,
       0.65,0.35,
       0.15,0.85),c("neg","pos"))

 vs('S',c('no','yes'))
 vs('M',c('Good','Bad'))

# compile, initialise and equilibrate

 compile()
 initcliqs()
 trav()
Now you may use the network for inference
 # remove previous evidence 
  equil()

 # add new evidence and 
 # read the posterior probabilities
 prop.evid('T','neg')

 pnmarg('S')
 pnmarg('M')

 # If you know you are good at testing
 prop.evid('M','Good')
 pnmarg('S')

Thus, if you observe a negative test result, the probability of being non-pregnant changes from 0.3 to 0.76, and there is a slight increase in the probability that the method M is a bad method (posterior 50.8 vs the prior 50 %). If you know that the method is good, the probability of no pregnancy increases to 88 %.

Monday, November 20, 2006

Links to other BN repositories

I have just checked my del.icio.us links for other BN-repositories and have added them to the links in the left column. Currently, I have only listed three.

I will follow up with similar links to software.

Thursday, November 16, 2006

Decisions

These are examples used in the 2003 Ph.D. course Reasoning under Uncertainty in Agriculture: Bayesian Networks and Graphical Models organised by the Nordic Informatics Network in the Agricultural Sciences (Nina)

Building of expert systems.

These are examples used in the 2003 Ph.D. course Reasoning under Uncertainty in Agriculture: Bayesian Networks and Graphical Models organised by the Nordic Informatics Network in the Agricultural Sciences (Nina)

Monitoring of pregnancy rate.

This is an example used in the 2003 Ph.D. course Reasoning under Uncertainty in Agriculture: Bayesian Networks and Graphical Models organised by the Nordic Informatics Network in the Agricultural Sciences (Nina)

Monday, November 06, 2006

Simple Pregnancy Testing

  • Simple pregnancy testing (DRGTTEST.net) The standard management procedure is to make a pregnancy test four weeks after mating in order to establish whether a sow is pregnant or not. This can be modelled in a Bayesian Network (BN).
  • Enhanced pregnancy testing ( DRGTTST1.net) A more realistic example includes the heat detection at three weeks after mating, and allows for the possibility of different herd levels for the pregnancy rate.

Friday, November 03, 2006

Why Blog about Bayesian Networks in agriculture

I have gathered a lot of examples about the use of Bayesian Networks and Markov Processes during the last 15 years. They have been used for different lectures, presentations and workshops. At the moment the examples are more or less scattered on different obsolete servers and some of them on my own hard disk. My plan is to add the examples to this blog, when I have some spare time.

I realise that a wiki may be a better format for this exercise, but it was easier to set up as a blog.

My original intention was to use the name BayesianNetworks.blogspot.com but this address was already in use. As most of my examples are mainly within the agricultural domain, the addition of agriculture is not a big problem.