Asia: expert system

This is the chest-clinic network of Lauritzen and Spiegelhalter (1988), a small fictitious expert system for diagnosing a patient who presents with shortness of breath. Seven binary variables are linked in a directed graph: whether the patient recently visited Asia, whether they smoke, whether they have tuberculosis, lung cancer or bronchitis, whether their chest X-ray is abnormal, and whether they suffer dyspnoea. There is no dataset of cases here. What is supplied as "data" are the conditional probability tables for the network, together with the findings for one particular patient: this patient did visit Asia and does have dyspnoea, and everything else is unknown.

Every node is categorical, drawn with dcat, and coded with state 1 for "no" and state 2 for "yes". The tables encode the usual epidemiological story. A visit to Asia lifts the probability of tuberculosis from 0.01 to 0.05; smoking, taken to be an even chance a priori, lifts lung cancer from 0.01 to 0.10 and bronchitis from 0.30 to 0.60; an abnormal X-ray is nearly certain if either lung disease is present and unlikely otherwise; and dyspnoea depends jointly on bronchitis and on the presence of either lung disease. The intermediate node either is defined as max(tuberculosis, lung_cancer), which under this 1-and-2 coding is exactly a logical OR.

Given the two findings, the inference problem is to work out posterior probabilities for the five unobserved nodes, in effect propagating evidence backwards through the network: the observed dyspnoea and Asia visit make tuberculosis, lung cancer and bronchitis all more plausible than their prior rates, and they also compete with one another to explain the symptom. Because each node takes only the values 1 or 2, a posterior mean reported for it translates directly into a probability: subtract 1 and you have the posterior probability that the node is in its "yes" state. See Volume 2 of the classic BUGS examples and the OpenBUGS Asia page.

The model definition, data, initial values, and published reference results shown here all come from JuliaBUGS.BUGSExamples.VOLUME_2.asia, which ships with the package.

Model

using JuliaBUGS

example = JuliaBUGS.BUGSExamples.VOLUME_2.asia
example.model_def
quote
    smoking ~ dcat(var"p.smoking"[1:2])
    tuberculosis ~ dcat(var"p.tuberculosis"[asia, 1:2])
    lung_cancer ~ dcat(var"p.lung.cancer"[smoking, 1:2])
    bronchitis ~ dcat(var"p.bronchitis"[smoking, 1:2])
    either = max(tuberculosis, lung_cancer)
    xray ~ dcat(var"p.xray"[either, 1:2])
    dyspnoea ~ dcat(var"p.dyspnoea"[either, bronchitis, 1:2])
end

The program as it appears in the original BUGS distribution:

print(example.original_syntax_program)
model {
    smoking ~ dcat(p.smoking[1:2])
    tuberculosis ~ dcat(p.tuberculosis[asia,1:2])
    lung.cancer ~ dcat(p.lung.cancer[smoking,1:2])
    bronchitis ~ dcat(p.bronchitis[smoking,1:2])
    either <- max(tuberculosis, lung.cancer)
    xray ~ dcat(p.xray[either,1:2])
    dyspnoea ~ dcat(p.dyspnoea[either, bronchitis,1:2])
}

Data

example.data
(asia = 2, dyspnoea = 2, var"p.tuberculosis" = [0.99 0.01; 0.95 0.05], var"p.bronchitis" = [0.7 0.3; 0.4 0.6], var"p.smoking" = [0.5, 0.5], var"p.lung.cancer" = [0.99 0.01; 0.9 0.1], var"p.xray" = [0.95 0.05; 0.02 0.98], var"p.dyspnoea" = [0.9 0.3; 0.2 0.1;;; 0.1 0.7; 0.8 0.9])

Compiling the model

model = JuliaBUGS.compile(example.model_def, example.data, example.inits)
BUGSModel (parameters are in transformed (unconstrained) space, with dimension 4):

  Model parameters:
    xray
    smoking
    lung_cancer
    bronchitis
    tuberculosis

  Variable sizes and types:
    p.xray: size = (2, 2), type = Matrix{Float64}
    p.smoking: size = (2,), type = Vector{Float64}
    p.bronchitis: size = (2, 2), type = Matrix{Float64}
    p.lung.cancer: size = (2, 2), type = Matrix{Float64}
    either: type = Int64
    smoking: type = Int64
    tuberculosis: type = Int64
    xray: type = Int64
    lung_cancer: type = Int64
    bronchitis: type = Int64
    p.tuberculosis: size = (2, 2), type = Matrix{Float64}
    p.dyspnoea: size = (2, 2, 2), type = Array{Float64, 3}
    dyspnoea: type = Int64
    asia: type = Int64

The example's own initial values are passed in here. Several of these models fail from random starting values, so example.inits is not optional in practice; a second set is available as example.inits_alternative.

See Getting Started for the recipe that takes a compiled model to posterior samples.

Reference results

The posterior summaries published with the original example. A converged chain should reproduce these up to Monte Carlo error.

example.reference_results
(bronchitis = (mean = 1.811, std = 0.3918), either = (mean = 1.185, std = 0.3885), lung_cancer = (mean = 1.101, std = 0.3011), smoking = (mean = 1.628, std = 0.4833), tuberculosis = (mean = 1.089, std = 0.2854), xray = (mean = 1.223, std = 0.4161))