Select your font size 
 
about us products & services consulting & support news & events contact us
Paul Meagher gives an example of calculating conditional probability using the set enumeration method.

Conditional probability - Ontario

print this article 
 

A conditional probability refers to the probability of observing an event A given that you have observed a separate event B. The mathematical shorthand for expressing this idea is:

P(A | B)

Imagine that A refers to "customer buys product A" and B refers to "customer buys product B". P(A | B) would then read as the "probability that a customer will buy product A given that they have bought product B." If A tends to occur when B occurs, then knowing that B has occurred allows you to assign a higher probability to A's occurrence than in a situation in which you did not know that B occurred.

More generally, if A and B systematically co-vary in some way, then P(A | B) will not be equal to P(A). Conversely, if A and B are independent events, then P(A | B) would be expected to equal P(A).

The need to compute a conditional probability thus arises any time you think the occurence of some event has a bearing on the probability of another event's occurring.

The most basic and intuitive method for computing P(A | B) is the set enumeration method. Using this method, P(A | B) can be computed by counting the number of times A and B occur together {A & B} and dividing by the number of times B occurs {B}:

P(A | B) = {A & B} / {B}

If you observe that 12 customers to date bought product B and of those 12, 10 also bought product A, then P(A | B) would be estimated at 10/12 or 0.833. In other words, the probability of a customer buying product A given that they have purchased product B can be estimated at 83 percent by using a method that involves enumerating relative frequencies of A and B events from the data gathered to date.

You can compute a conditional probability using the set enumeration method with the following PHP code:

Listing 1. Computing conditional probability using set enumeration
<?php

/**
* Returns conditional probability of $A given $B and $Data.
* $Data is an indexed array.  Each element of the $Data array 
* consists of an A measurement and B measurment on a sample 
* item.
*/
function getConditionalProbabilty($A, $B, $Data) {
  $NumAB   = 0;
  $NumB    = 0;
  $NumData = count($Data);
  for ($i=0; $i < $NumData; $i++) {
    if (in_array($B, $Data[$i])) {
      $NumB++;
      if (in_array($A, $Data[$i])) {
        $NumAB++;
      }
    }
  }
  return $NumAB / $NumB;
}

?>


Page:   1  2  3  4  5  6  7  8  9  10  11 Next Page: Learning from experience

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

 Corporate Services Within Canada
Transparen Corporation is based in Canada. We provide remote Windows support, remote Linux support, data recovery, software development and technical writing to businesses throughout Canada.

 
 Web Writing Attracts Positive Results
Out-do the competition through skillful and colorful writing, aimed at both searchers and search engines. An effective message is worth many times its cost.

 
 New One-Stop Access To Legal Information
McGuinty Government Launches "Justice Ontario" Website And Hotline

 
 Creating Jobs, Building Ontario
Investing in Ontario Act Delivers $1.1 Billion for Municipal Infrastructure

 
 Improving Access To Care In The North
Expansion At Northern Ontario School Of Medicine To Put More Medical Students In Small, Remote and Aboriginal Communities

 
 Ontario Releases McMurtry Victim Services Report
McGuinty Government Helping Victims Of Crime

 
 Gearing Up For New Skills At Mohawk College
McGuinty Government Expands Training Opportunities In Hamilton

 
 More Students Build Skills At Conestoga College
McGuinty Government Invests In Robotics, Welding Training

 
 Ontario Aerospace Supplier Creating Jobs
McGuinty Government Backs Innovative Mississauga Manufacturer

 
 Canada and Ontario sign $6.2-billion Building Canada Infrastructure Agreement
Improvements to Highway 11/17 in northwestern Ontario, Ontario rural broadband coverage, Waterloo Region rapid transit, and the Huron Elgin London Project for clean water are priorities under Building Canada and ReNew Ontario

 
 Green Jobs, New Plant Coming To Vaughan
McGuinty Government Investing In Next Generation Manufacturing

 
 Ontario To Join Climate Change Leaders
McGuinty Government Unites With Provinces, States Tackling Climate Change

 

Google
 
Web transparen.com

Contact Information

Related Information

 
  TORONTO ON
LONDON ON
OTTAWA ON
HAMILTON ON
 
 
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, the photo genie, 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, mortgage brokers in calgary
Toronto, Ottawa, Kanata, Hamilton, London - view entire list