{
  "id": "probability",
  "version": "09675a8743bd",
  "status": "published",
  "name": "Probability Calculator",
  "question": "What is the probability of A and B?",
  "summary": "Computes the probability of two events both happening, either happening, exactly one, or neither, and the conditional probabilities, from P(A) and P(B).",
  "category": "statistics",
  "subcategory": "probability",
  "url": "https://www.acalculator.org/statistics/probability-calculator",
  "markdown": "https://www.acalculator.org/statistics/probability-calculator.md",
  "kind": "function",
  "method": "P(A and B) = P(A) × P(B) for independent events, 0 for mutually exclusive events; P(A or B) = P(A) + P(B) − P(A and B); P(neither) = 1 − P(A or B); P(A given B) = P(A and B) ÷ P(B).",
  "assumptions": [
    "Probabilities are decimals from 0 to 1 (0.25 means a 25% chance).",
    "The arithmetic is exact on the decimals you type, then rounded once for display."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "pa": {
        "title": "P(A)",
        "description": "The probability of event A, from 0 to 1.",
        "type": "number",
        "minimum": 0,
        "maximum": 1
      },
      "pb": {
        "title": "P(B)",
        "description": "The probability of event B, from 0 to 1.",
        "type": "number",
        "minimum": 0,
        "maximum": 1
      },
      "rel": {
        "title": "A and B are",
        "description": "Independent (one does not change the chance of the other), mutually exclusive (they cannot both happen), or neither, with a known P(A and B).",
        "type": "string",
        "enum": [
          "independent",
          "exclusive",
          "joint"
        ]
      },
      "pab": {
        "title": "P(A and B)",
        "description": "The probability that A and B both happen, from 0 to 1.",
        "type": "number",
        "minimum": 0,
        "maximum": 1
      }
    }
  },
  "outputs": {
    "and": {
      "label": "P(A and B)",
      "description": "The probability that both A and B happen, P(A ∩ B).",
      "format": "number"
    },
    "or": {
      "label": "P(A or B)",
      "description": "The probability that A, B, or both happen, P(A ∪ B).",
      "format": "number"
    },
    "exactlyOne": {
      "label": "P(exactly one)",
      "description": "The probability that A or B happens but not both.",
      "format": "number"
    },
    "neither": {
      "label": "P(neither)",
      "description": "The probability that neither A nor B happens.",
      "format": "number"
    },
    "notA": {
      "label": "P(not A)",
      "description": "The probability that A does not happen, 1 − P(A).",
      "format": "number"
    },
    "notB": {
      "label": "P(not B)",
      "description": "The probability that B does not happen, 1 − P(B).",
      "format": "number"
    },
    "aGivenB": {
      "label": "P(A given B)",
      "description": "The probability of A when B has happened, P(A and B) ÷ P(B). Shown when P(B) is above 0.",
      "format": "number"
    },
    "bGivenA": {
      "label": "P(B given A)",
      "description": "The probability of B when A has happened, P(A and B) ÷ P(A). Shown when P(A) is above 0.",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "rel": "independent",
      "pa": 0.5,
      "pb": 0.4
    },
    "outputs": {
      "and": 0.2,
      "or": 0.7,
      "exactlyOne": 0.5,
      "neither": 0.3,
      "notA": 0.5,
      "notB": 0.6,
      "aGivenB": 0.5,
      "bGivenA": 0.4
    },
    "text": "With P(A) = 0.5 and P(B) = 0.4, P(A and B) is 0.2 and P(A or B) is 0.7."
  },
  "examples": [
    {
      "given": {
        "pa": 0.5,
        "pb": 0.4,
        "rel": "independent"
      },
      "expect": {
        "and": 0.2,
        "or": 0.7,
        "exactlyOne": 0.5,
        "neither": 0.3,
        "notA": 0.5,
        "notB": 0.6,
        "aGivenB": 0.5,
        "bGivenA": 0.4
      },
      "source": "hand calculation in content.mdx: 0.5 × 0.4 = 0.2, 0.5 + 0.4 − 0.2 = 0.7; OpenStax, Introductory Statistics 2e, §3.3 Two Basic Rules of Probability. https://openstax.org/books/introductory-statistics-2e/pages/3-3-two-basic-rules-of-probability"
    },
    {
      "given": {
        "pa": 0.3,
        "pb": 0.45,
        "rel": "exclusive"
      },
      "expect": {
        "and": 0,
        "or": 0.75,
        "exactlyOne": 0.75,
        "neither": 0.25,
        "aGivenB": 0
      },
      "source": "hand calculation in content.mdx: 0.3 + 0.45 = 0.75; OpenStax, Introductory Statistics 2e, §3.2 Independent and Mutually Exclusive Events. https://openstax.org/books/introductory-statistics-2e/pages/3-2-independent-and-mutually-exclusive-events"
    },
    {
      "given": {
        "pa": 0.4,
        "pb": 0.5,
        "rel": "joint",
        "pab": 0.2
      },
      "expect": {
        "or": 0.7,
        "aGivenB": 0.4,
        "bGivenA": 0.5
      },
      "source": "hand calculation in content.mdx: 0.4 + 0.5 − 0.2 = 0.7, 0.2 ÷ 0.5 = 0.4; OpenStax, Introductory Statistics 2e, §3.3 Two Basic Rules of Probability. https://openstax.org/books/introductory-statistics-2e/pages/3-3-two-basic-rules-of-probability"
    },
    {
      "given": {
        "pa": 0.1,
        "pb": 0.2,
        "rel": "independent"
      },
      "expect": {
        "and": 0.02,
        "or": 0.28,
        "neither": 0.72
      },
      "source": "hand calculation in content.mdx: 0.1 × 0.2 = 0.02, 0.1 + 0.2 − 0.02 = 0.28; OpenStax, Introductory Statistics 2e, §3.3 Two Basic Rules of Probability. https://openstax.org/books/introductory-statistics-2e/pages/3-3-two-basic-rules-of-probability"
    }
  ],
  "sources": [
    "OpenStax, Introductory Statistics 2e, §3.2 Independent and Mutually Exclusive Events. https://openstax.org/books/introductory-statistics-2e/pages/3-2-independent-and-mutually-exclusive-events",
    "OpenStax, Introductory Statistics 2e, §3.3 Two Basic Rules of Probability. https://openstax.org/books/introductory-statistics-2e/pages/3-3-two-basic-rules-of-probability"
  ],
  "related": [
    "binomial-distribution",
    "dice-probability",
    "expected-value",
    "odds"
  ],
  "changelog": []
}
