Select your font size 
 
about us products & services consulting & support news & events contact us
To make it clear how Bayes theorem works, you will develop an online

Medical diagnosis wizard - Nova Scotia

print this article 
 

To make it clear how Bayes theorem works, you will develop an online medical diagnosis wizard using PHP. This wizard could also have been called a calculator except that it takes four input steps to supply the prerequisite information then a step to review the result.

The wizard works by asking the user to supply the various pieces of information critical to computing the full posterior probability. The user can examine the posterior distribution to determine which which disease hypothesis enjoys the highest probability based on:

  1. The diagnositic test information
  2. The sample data used to estimate the prior and likelihood distributions

Bayes Wizard: Step 1

Step 1 in using Bayes theorem to make a medical diagnosis involves specifying the number of disease alternatives that you will examine along with the number of symptoms or evidence keys. In the generic example you will look at, you will evaluate three disease alternatives based on evidence from two diagnostic tests. Each diagnostic test can only produce a positive or negative result. This means that the total number of symptom combinations, or evidence keys, you can observe is four (++, +-, -+, or --).

Figure 3. Form to enter disease hypotheses and symptom possibilities
Form to enter  disease hypotheses and symptom possibilities

Bayes Wizard: Step 2

Step 2 involves entering the disease and symptom labels. In this case, you are just going to enter d1, d2, and d3 for the disease labels and ++, +-, -+ and -- for the symptom labels. The two symbols used for symptom labels signify whether the results of the two diagnostic tests came out positive or negative.

Figure 4. Form to enter disease and symptom labels
Form to enter disease and symptom labels

Bayes Wizard: Step 3

Step 3 involves entering the prior probabilities for each disease. You will use the data table below to determine the prior probabilities to enter for step three and the likelihood to enter for step four (this data table originally appeared in Introduction to Probability). Using this example allows you to confirm that the final result you obtain from the wizard agrees with the results you can find in this book.

Figure 5. Joint frequency of diseases and symptoms
Joint frequency of diseases and symptoms

The prior probability of each disease refers to the number of patients diagnosed with each disease divided by the total number of diagnosed cases in this sample. The relevant prior probabilities for each disease are entered in the following:

Figure 6. Form to enter disease priors
Form to enter disease priors

You do not have to rely upon a data table such as the previous one to derive the prior probability estimates. In some cases, you can derive prior probabilities by using common-sense reasoning: The prior probability of a fair two-sided coin coming up heads is 0.5. The prior probability of selecting a queen of hearts from a randomized deck of cards is 1/52.

You also commonly run into situations where you intially have no good estimates of what the prior probability of each hypothesis might be. In such cases, it is common to posit noninformative priors. If you have four hypothesis alternatives, then the noninformative prior distribution would be 1/4 or 0.25 for each hypothesis. You might note here that Bayesians often criticize the use of a null hypothesis in significance testing because it amounts to assuming noninformative priors in cases where positing informative priors might be more theoretically or empirically justified.

A final way to derive estimates of the prior probability of each hypothesis P(Hi) is through a subjective estimate of what those probabilities might be given everything you have learned about the way the world works up to that point P( H=h | Everything you know). You will often find Bayesian inference sharing the same bed with a subjective view of probability in which the probability of a proposition is equated with one's subjective degree of belief in the proposition.

What it important in this discussion is that Bayesian inference is a flexible technique that allows you to estimate prior probabilities using objective methods, common-sense logical methods, and subjective methods. When using subjective methods, you must still be willing to defend your prior probability estimates. You may use objective data to help set and justify your subjective estimates which means that Bayesian inference is not necessarily in conflict with more objectively oriented approaches to statistical inference.

Bayes Wizard: Step 4

The data table provides you with information you can use to compute the probability of the symptoms (like test results) given the disease, also known as the likelihood distribution P(E | H).

To see how the likelihood values entered below were computed, you can unpack P(E|H) using the frequency format for computing conditional probabilities:

P(E | H) = {E & H} / {H}

This tells us that you need to divide a joint frequency count {E & H} by a marginal frequency count {H} to obtain the likelihood value for each cell in your likelihood matrix. The top left cell of your likelihood matrix P(E='++' | H='d1) can be immediately computed from the joint and marginal frequency counts appearing in the data table:

P(E='++' | H='d1) = 2110 / 3125 = .6562

All the likelihood values entered in Step 4 were computed in this manner.

Figure 7. Form to enter likelihood of symptoms given the disease
Form to enter likelihood of symptoms given the disease

It should be noted that many statisticians use likelihood as a system of inference instead of, or in addition to, Bayesian inference. This is because likelihoods also provide a metric one can use to evaluate the relative degree of support for several hypotheses given the data.

In the previous example, you can see that the probability of a particular evidence key varies for each hypothesis under consideration. The probability of the ++ evidence key is the greatest for the d1 hypothesis. You can assess which hypothesis is best supported by the data by:

  1. Examining the likelihood of the evidence key given each hypothesis key
  2. Selecting the hypothesis that maximizes the likelihood of the evidence key

Doing so would be an example of inference according to the principle of maximum likelihood.

Another interesting point to note is that all the values in the above likelihood distibution sum to a value greater than 1. What this means is that the likelihood distribution is not really a probability distribution because it lacks the defining property that the distribution of values sum to 1. This summation property is not essential for the purposes of evaluating the relative support for different hypotheses. What is important for this purpose is that the "likelihood supplies a natural order of preference among the possibilities under consideration" (from R.A. Fisher's Statistical Methods and Scientific Inference, p. 68).

You may not understand fully the concept of likelihood from this brief discussion, but I do hope that you appreciate its importance to the overall Bayes theorem calculation and its importance as the foundation for another system of inference. The likelihood system of inference is preferred by many statisticians because you don't have to resort to the dubious practice of trying to estimate the prior probability of each hypothesis.

Maximum likelihood estimators also have many desirable mathematical properties that make them nice to work with (the properties include transitivity, additivity, a lack of bias, and invariance under transformations, among others). For these reasons, it is often a good idea to closely examine your likelihood distribution in addition to your posterior distibution when making inferences from your data.

Bayes Wizard: Step 5

The final step of the process involves displaying the posterior distribution of the diseases given the symptoms P(H | E):

Figure 8. Probability of each disease given symptoms
Probability of each disease given symptoms

The section of the script that was used to compute and display the posterior distribution looks like this:

Listing 4. Computing and displaying the posterior distribution
<?php
include "Bayes.php";

$disease_labels = $_POST["disease_labels"];
$symptom_labels = $_POST["symptom_labels"];
$priors         = $_POST["priors"];
$likelihoods    = $_POST["likelihoods"];

$bayes = new Bayes($priors, $likelihoods);
$bayes->getPosterior();
$bayes->setRowLabels($symptom_labels);    // aka evidence labels
$bayes->setColumnLabels($disease_labels); // aka hypothesis labels
$bayes->toHTML();
?>

You begin by loading the Bayes constructor with the priors and likelihoods obtained from previous wizard steps. Using this information, you compute the posterior using the $bayes->getPosterior() method. To output the posterior distribution to the browser, you first set the row and column labels to display, then output the posterior distribution using the $bayes->toHTML() method.



Page:   1  2  3  4  5  6  7  8  9  10  11 Next Page: Implementing the calculation with Bayes.php

The content shown in this page was first published by IBM developerWorks and is reprinted with permission from Paul Meagher (www.datavore.com)


Most Recent Website and Regional Updates

 Research Tools
Measure human resource allocation and collect data with the goal of determining patterns that will bring forward actionable insights which may lead to policy changes, saving money and improving quality of service.

 
 Process Evaluation Questions
Questions to help focus discussion about process improvement

 
 Operations Research
Operations Research (frequently called OR), is the methodical study of how to do things better. It is also called Optimization Theory.

 
 Our Role in Operations Optimization
Meet objectives more efficiently by improving operational effectiveness and profitability.

 
 Monte Carlo Method
Short description of the Monte Carlo Method in optimization theory.

 
 Introduction to Markov Process
Introduction to Markov Chains and Markov Processes, with a link to an introductory PDF which provides essential details about Markov analysis, along with helpful examples and exercises.

 
 With new website, community news is just a click away
Dear Readers: We're pleased to announce the launch of our new website www.

 
 Crowd wants it built right the first time: Build It Right, supporters gather against secrecy
Protesters marched across the site of the Mainland Common last Saturday to demonstrate against what they call the secrecy of the plans.

 
 Boy has a 'helping out' spirit: IWK telethon organizers praise nine-year-old's accomplishment
Ben Ryan is a young man with a plan. This weekend, the nine-year-old Basinview Drive Elementary School student, his younger brother Alex and at least one friend will be featured on the IWK Telethon for Children where they'll hand over $1,041.

 
 Local Sparks hope to keep the flame alight
Despite an increase in the number of girls signed up in the program, the 2nd Dartmouth Sparks unit may have to close its doors unless new leaders are found next year.

 
 Whalen slams premier's 'paternalistic' attitude: Clayton Park MLA calls for full disclosure of Mainland Common plans
Fed up with the secrecy surrounding the Mainland Common plans, and fearing a rerun of the Commonwealth Games debacle, MLA Diana Whalen is calling on the Progressive Conservatives to pass a bill that would force governments to be open about major projects they are funding.

 
 If voters have to choose ...: While both have declined, Kelly holds majority over Fougere
When given the choice between Peter Kelly and Sheila Fougere as mayor of Halifax Regional Municipality, just under one-half of residents choose Kelly, and two in 10 support Fougere, a recent Corporate Research Associates poll suggests.

 
 Massive new development sparks little public interest
Last week's public hearing about a large development proposed for Middle Sackville may have garnered more than two hours of debate, but local Coun.

 
 Plaque to honour a fallen soldier
There were tears and laughter as people gathered last week to honour Pte. Braun Woodfield by dedicating a plaque to his memory at the Royal Canadian Legion (Branch 164) in Eastern Passage.

 
 Respite care offers much-needed break: Workshop offers help for parents of special-needs children
6,210. That's the number of children under the age of 15 in this province who have some form of disability.

 
 Have your say in a greener community
Your chance to have a say in how we treat our natural environment is coming to a conference room near you.

 
 Car crashes through house
The RCMP Halifax District and RCMP Metro Traffic Services responded to a vehicle, which crashed into a residence at 5:15 p.m. Monday afternoon on Prospect Road.

 
 Central library plans announced
After months of public consultations and planning, Halifax Public Libraries and the HOK Planning Group are excited to present the chosen building concept for the new Central Library for HRM.

 
 Website celebrates HRM Bike Week
A new website for HRM's Bike Week activities has gone live and Coun. Sheila Fougere is urging residents to visit the site to learn about the many events planned for this year.

 
 Province invests money in playground equipment
School children will soon get to spend their recesses and lunch hours on new playground equipment thanks to $192,000 worth of investments announced by the province this week.

 
 Community program funding helps prevent crime
More than 30 communities are receiving one-time grants this week from the Department of Justice for projects that support Nova Scotia's crime prevention strategy, Time to Fight Crime Together.

 
 Do you know someone who should be awarded for bravery?
Nominations are being sought for Nova Scotia's new Medal of Bravery.

 
 Don't burn that brush without a fire permit
Halifax Regional Fire and Emergency reminds residents that it is illegal to burn brush without a burning permit in Halifax Regional Municipality and in many areas of HRM (including Bedford, Halifax, Dartmouth, Cole Harbour, Timberlea and parts of Sackville), burning is not permitted at all.

 
 Nova Scotian youth get hooked on fishing
Youth from across Nova Scotia are baiting their hooks and heading to the province's fishing spots as part of the Learn to Fish (L2F) program.

 
 Website makes researching older homes easier
Nova Scotians interested in researching the history of their homes and properties now have a new Internet resource on their side.

 
 'I run for hope and a cure': HEALTH Relay for Life raises money for cancer
The fifth anniversary of the Canadian Cancer Relay for Life in Sackville is fast approaching and with more than 50 teams registered and a first-ever event sponsor, organizers are confident this relay will create more awareness and raise more funds than ever before.

 
 Cancer Care invites you to 'Celebrate Life 2008' festivities
For the seventh year in a row, Cancer Care Nova Scotia will present Celebrate Life 2008, an afternoon of music and festivities as Nova Scotians mark National Cancer Survivors Day.

 
 Wilderness areas targeted by joint forces' operation
Officers from provincial and federal agencies joined forces through early May to increase awareness of rules affecting back country angling and proper use of Nova Scotia wilderness areas.

 

Google
 
Web transparen.com

Contact Information

Related Information

 
   
 
E C M | © 2003-2007 Transparen Corp.      

Standardized Services: Data Recovery Service / Creative Services / Premium Web Hosting Services / System Administration Tech Support Services
Recent Projects: Full-Service Mortgage and Financing Company / System to manage flights from Vancouver to Tofino / Photo exchange verification service
Our Vancouver BC Server Proudly Hosts: automated parking and revenue control systems, leafside lane at southlands, cost effective alternative power sources, Higher Grade Learning Centres, pacific forage bag supply, sunburst medical, neosonic design, roger mahler photography - passionate, intriguing, desirable, the connection between east and west, affordable flights to victoria and tofino, low interest mortgage brokers in vancouver, richmond, surrey, toronto, Toronto Calgary and Vancouver IT staffing and talent search
* Annapolis County, Nova Scotia * Antigonish County, Nova Scotia * Argyle, Nova Scotia * Barrington, Nova Scotia * Cape Breton Regional Municipality, Nova Scotia * Chester, Nova Scotia * Clare, Nova Scotia * Colchester County, Nova Scotia * Cumberland County, Nova Scotia * Digby, Nova Scotia * Guysborough, Nova Scotia * Halifax Regional Municipality, Nova Scotia * East Hants, Nova Scotia * West Hants, Nova Scotia * Inverness County * Kings County * Lunenburg, Nova Scotia * Pictou County, Nova Scotia * Queens Regional Municipality, Nova Scotia (see also Queens County, Nova Scotia) * Richmond County, Nova Scotia * Shelburne, Nova Scotia * St. Mary's, Nova Scotia * Victoria County, Nova Scotia * Yarmouth, Nova Scotia * Amherst, Nova Scotia * Annapolis Royal, Nova Scotia * Antigonish, Nova Scotia * Berwick, Nova Scotia * Bridgetown, Nova Scotia * Bridgewater, Nova Scotia * Canso, Nova Scotia * Clark's Harbour, Nova Scotia * Digby, Nova Scotia * Hantsport, Nova Scotia * Kentville, Nova Scotia * Lockeport, Nova Scotia * Louisdale, Nova Scotia * Lunenburg, Nova Scotia * Mahone Bay, Nova Scotia * Middleton, Nova Scotia * Mulgrave, Nova Scotia * New Glasgow, Nova Scotia * Oxford, Nova Scotia * Parrsboro, Nova Scotia * Pictou, Nova Scotia * Port Hawkesbury, Nova Scotia * Port Joli, Nova Scotia * Port Mouton, Nova Scotia * Shelburne, Nova Scotia * Springhill, Nova Scotia * Stellarton, Nova Scotia * Stewiacke, Nova Scotia * Trenton, Nova Scotia * Truro, Nova Scotia * Westville, Nova Scotia * Windsor, Nova Scotia * Wolfville, Nova Scotia * Yarmouth, Nova Scotia * Bear River 6, Nova Scotia * Bear River 6B, Nova Scotia * Cambridge 32, Nova Scotia * Chapel Island 5, Nova Scotia * Cole Harbour 30, Nova Scotia * Eskasoni 3, Nova Scotia * Fisher's Grant 24, Nova Scotia * Gold River 21, Nova Scotia * Horton 35, Nova Scotia * Indian Brook 14, Nova Scotia * Membertou 28B, Nova Scotia * Merigomish Harbour 31, Nova Scotia * Millbrook 27, Nova Scotia * New Ross 20, Nova Scotia * Pennal 19, Nova Scotia * Pomquet and Afton 23, Nova Scotia * Sheet Harbour 36, Nova Scotia * Shubenacadie 13, Nova Scotia * Summerside 38, Nova Scotia * Wagmatcook 1, Nova Scotia * Whycocomagh 2, Nova Scotia * Wildcat 12, Nova Scotia * Yarmouth 33, Nova Scotia * Aylesford, Nova Scotia * Baddeck, Nova Scotia * Bible Hill, Nova Scotia * Canning, Nova Scotia * Caribou, Nova Scotia * Chester, Nova Scotia * Collingwood, Nova Scotia * Cornwallis Square, Nova Scotia * Dover, Nova Scotia * Freeport, Nova Scotia * Greenwood, Nova Scotia * Havre Boucher, Nova Scotia * Hebbville, Nova Scotia * Kingston, Nova Scotia * Lawrencetown, Annapolis County, Nova Scotia * New Minas, Nova Scotia * Port Williams, Nova Scotia * Pugwash, Nova Scotia * River Hebert, Nova Scotia * St. Peter's, Nova Scotia * Tatamagouche, Nova Scotia * Tiverton, Nova Scotia * Westport, Nova Scotia * Weymouth, Nova Scotia * Advocate Harbour, Nova Scotia * Arichat, Nova Scotia * Arisaig, Nova Scotia * Arlington, Nova Scotia * Aspen, Nova Scotia * Atlanta, Nova Scotia * Bangor, Nova Scotia * Barrachois, Cape Breton County, Nova Scotia * Barrachois, Colchester County, Nova Scotia * Barrington, Nova Scotia * Barrington Passage, Nova Scotia * Bass River, Nova Scotia * Bay St. Lawrence, Nova Scotia * Bear River, Nova Scotia * Bedford, Nova Scotia (was a town) * Beinn Bhreagh, Nova Scotia * Beinn Scalpie, Nova Scotia * Benn Eoin, Nova Scotia * Borneo, Nova Scotia * Brighton, Nova Scotia * Brookfield, Nova Scotia * Brooklyn, Nova Scotia * Caledonia, Nova Scotia * Cambridge, Hants County, Nova Scotia * Cambridge, Kings County, Nova Scotia * Canaan, Kings County, Nova Scotia * Canaan, Lunenburg County, Nova Scotia * Canaan, Yarmouth County, Nova Scotia * Cape North, Nova Scotia * Capstick, Nova Scotia * Cannes, Nova Scotia * Chéticamp, Nova Scotia * Cheverie, Nova Scotia * Church Point, Nova Scotia * Clementsport, Nova Scotia * Clementsvale, Nova Scotia * Conquerall Mills, Nova Scotia * Country Harbour, Nova Scotia * Creignish, Nova Scotia * Cumberland, Nova Scotia * Dartmouth, Nova Scotia (was a city) * Debert, Nova Scotia * Deep Brook, Nova Scotia * Dingwall, Nova Scotia * Dominion, Nova Scotia * Donkin, Nova Scotia * Economy, Nova Scotia * East Berlin, Nova Scotia * Ecum Secum, Nova Scotia * Elmsdale, Nova Scotia * Enfield, Nova Scotia * Falmouth, Nova Scotia * Fauxburg, Nova Scotia * Five Islands, Nova Scotia * Glace Bay, Nova Scotia * Glen Haven, Nova Scotia * Goshen, Nova Scotia * Grand Etang, Nova Scotia * Granville Ferry, Nova Scotia * Great Village, Nova Scotia * Guinea, Nova Scotia * Guysborough, Nova Scotia * Halifax, Nova Scotia (former city) * Halls Harbour, Nova Scotia * Harpellville, Nova Scotia * Hebron, Nova Scotia * Hebb's Cross, Nova Scotia * Hectanooga, Nova Scotia * Hilden, Nova Scotia * Hopewell, Nova Scotia * Hubbards, Nova Scotia * Indian Harbour Lake, Nova Scotia * Indian Point, Nova Scotia * Ingonish, Nova Scotia * Ingonish Beach, Nova Scotia * Inverness, Nova Scotia * Joggins, Nova Scotia * Kingsburg, Nova Scotia * L'Ardoise, Nova Scotia * Larrys River, Nova Scotia * Lawrencetown, Nova Scotia in Halifax Regional Municipality * Little Brook, Nova Scotia * Liverpool, Nova Scotia (was a town) * Londonderry, Nova Scotia * Louisbourg, Nova Scotia * Louisdale, Nova Scotia * Lucas, Nova Scotia * Mabou, Nova Scotia * Maccan, Nova Scotia * Marion Bridge, Nova Scotia * Maitland, Nova Scotia * Martinique, Nova Scotia * Meat Cove, Nova scotia * Melrose, Nova Scotia * Meteghan, Nova Scotia * Meteghan River, Nova Scotia * Middle Musquodoboit, Nova Scotia * Milford Station, Nova Scotia * Milton, Nova Scotia * Miramichi, Nova Scotia * Mount Denson, Nova Scotia * Mount Uniacke, Nova Scotia * Musquodoboit Harbour, Nova Scotia * Necum Teuch, Nova Scotia * New Canada, Nova Scotia * New Germany, Nova Scotia * New Grafton, Nova Scotia * New Ross, Nova Scotia * New Waterford, Nova Scotia * Newcombville, Nova Scotia * Nictaux, Nova Scotia * Nineveh, Lunenburg County, Nova Scotia * Nineveh, Victoria County, Nova Scotia * North Alton, Nova Scotia * North Preston, Nova Scotia * North Sydney, Nova Scotia * Oakland, Nova Scotia * Ohio, Nova Scotia * Oregon, Nova Scotia * Passchendaele, Nova Scotia * Petite Riviere, Nova Scotia * Pleasant Bay, Nova Scotia * Pockwock, Nova Scotia * Port Bickerton, Nova Scotia * Port Hastings, Nova Scotia * Port Hood, Nova Scotia * Port Maitland, Nova Scotia * Port Medway, Nova Scotia * Port Morien, Nova Scotia * Pubnico, Nova Scotia * Renfrew, Nova Scotia * River John, Nova Scotia * Selma, Nova Scotia * Sheet Harbour, Nova Scotia * Sherbrooke, Nova Scotia * Sherose Island, Nova Scotia * Shinimicas Bridge, Nova Scotia * Ship Harbour, Nova Scotia * Shubenacadie, Nova Scotia * Sonora, Nova Scotia * Springfield, Nova Scotia * Spryfield, Nova Scotia * Sydney, Nova Scotia * Sydney Mines, Nova Scotia * Terra Nova, Nova Scotia * Three Mile Plains, Nova Scotia * Trafalgar, Nova Scotia * Tremont, Nova Scotia * Troy, Nova Scotia * Tusket, Nova Scotia * Upper Musquodoboit, Nova Scotia * Upper Stewiacke, Nova Scotia * Valley, Nova Scotia * Victoria, Nova Scotia * Walden, Nova Scotia * Waterville, Nova Scotia * Waverley, Nova Scotia * Wedgeport, Nova Scotia * West Arichat, Nova Scotia * West Berlin, Nova Scotia * Western Shore, Nova Scotia * Whycocomagh, Nova Scotia * Wine Harbour, Nova Scotia * Yankeetown, Nova Scotia