{
  "id": "expected-value",
  "version": "565d224a87c9",
  "status": "published",
  "name": "Expected Value Calculator",
  "question": "What is the expected value?",
  "summary": "Computes the expected value (mean), variance, and standard deviation of a discrete random variable from its outcomes and their probabilities.",
  "category": "statistics",
  "subcategory": "probability",
  "url": "https://www.acalculator.org/statistics/expected-value-calculator",
  "markdown": "https://www.acalculator.org/statistics/expected-value-calculator.md",
  "kind": "function",
  "method": "E(X) = μ = Σ x × P(x); σ² = Σ (x − μ)² × P(x); σ = √σ².",
  "assumptions": [
    "Each probability is from 0 to 1, and together they add up to exactly 1.",
    "The sums are exact on the decimals and fractions you type, then rounded once for display."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "outcomes": {
        "title": "Outcomes and probabilities",
        "description": "One row per outcome: its value and its probability. The probabilities must add up to 1.",
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "x": {
              "title": "Value (x)",
              "description": "The value of the outcome, such as a win or loss in dollars. It may be negative.",
              "type": "number",
              "minimum": -1000000000000000,
              "maximum": 1000000000000000
            },
            "p": {
              "title": "Probability P(x)",
              "description": "The probability of the outcome, from 0 to 1, as a decimal or a fraction.",
              "type": "string",
              "pattern": "^-?\\d+( \\d+)?(/\\d+)?$"
            }
          }
        }
      }
    }
  },
  "outputs": {
    "ev": {
      "label": "Expected value E(X)",
      "description": "The probability-weighted average of the values: Σ x × P(x).",
      "format": "number"
    },
    "variance": {
      "label": "Variance σ²",
      "description": "The probability-weighted average of the squared distances from the expected value: Σ (x − μ)² × P(x).",
      "format": "number"
    },
    "sd": {
      "label": "Standard deviation σ",
      "description": "The square root of the variance.",
      "format": "number"
    },
    "count": {
      "label": "Outcomes",
      "description": "How many outcomes (rows) there are.",
      "format": "integer"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "outcomes": [
        {
          "x": 10,
          "p": "0.2"
        },
        {
          "x": 0,
          "p": "0.5"
        },
        {
          "x": -5,
          "p": "0.3"
        }
      ]
    },
    "outputs": {
      "ev": 0.5,
      "variance": 27.25,
      "sd": 5.220153254455275,
      "count": 3
    },
    "text": "The expected value is 0.5, with a standard deviation of 5.220153."
  },
  "examples": [
    {
      "given": {
        "outcomes": [
          {
            "x": 10,
            "p": "0.2"
          },
          {
            "x": 0,
            "p": "0.5"
          },
          {
            "x": -5,
            "p": "0.3"
          }
        ]
      },
      "expect": {
        "ev": 0.5,
        "variance": 27.25,
        "sd": 5.220153254455275
      },
      "source": "hand calculation in content.mdx: 10 × 0.2 + 0 × 0.5 − 5 × 0.3 = 0.5; OpenStax, Introductory Statistics 2e, §4.2 Mean or Expected Value and Standard Deviation. https://openstax.org/books/introductory-statistics-2e/pages/4-2-mean-or-expected-value-and-standard-deviation"
    },
    {
      "given": {
        "outcomes": [
          {
            "x": 0,
            "p": "0.2"
          },
          {
            "x": 1,
            "p": "0.5"
          },
          {
            "x": 2,
            "p": "0.3"
          }
        ]
      },
      "expect": {
        "ev": 1.1,
        "variance": 0.49,
        "sd": 0.7
      },
      "source": "OpenStax, Introductory Statistics 2e, §4.2 Mean or Expected Value and Standard Deviation. https://openstax.org/books/introductory-statistics-2e/pages/4-2-mean-or-expected-value-and-standard-deviation, Example 4.3 (μ = 1.1, σ = 0.7)"
    },
    {
      "given": {
        "outcomes": [
          {
            "x": -2,
            "p": "0.99999"
          },
          {
            "x": 100000,
            "p": "0.00001"
          }
        ]
      },
      "expect": {
        "ev": -0.99998
      },
      "source": "OpenStax, Introductory Statistics 2e, §4.2 Mean or Expected Value and Standard Deviation. https://openstax.org/books/introductory-statistics-2e/pages/4-2-mean-or-expected-value-and-standard-deviation, Example 4.5 (−1.99998 + 1 = −0.99998)"
    },
    {
      "given": {
        "outcomes": [
          {
            "x": 1,
            "p": "1/6"
          },
          {
            "x": 2,
            "p": "1/6"
          },
          {
            "x": 3,
            "p": "1/6"
          },
          {
            "x": 4,
            "p": "1/6"
          },
          {
            "x": 5,
            "p": "1/6"
          },
          {
            "x": 6,
            "p": "1/6"
          }
        ]
      },
      "expect": {
        "ev": 3.5,
        "variance": 2.9166666666666665,
        "sd": 1.707825127659933
      },
      "source": "hand calculation in content.mdx: 21 ÷ 6 = 3.5, variance 17.5 ÷ 6 = 35/12; OpenStax, Introductory Statistics 2e, §4.2 Mean or Expected Value and Standard Deviation. https://openstax.org/books/introductory-statistics-2e/pages/4-2-mean-or-expected-value-and-standard-deviation"
    }
  ],
  "sources": [
    "OpenStax, Introductory Statistics 2e, §4.2 Mean or Expected Value and Standard Deviation. https://openstax.org/books/introductory-statistics-2e/pages/4-2-mean-or-expected-value-and-standard-deviation",
    "Grinstead and Snell, Introduction to Probability, 1997, Chapter 6 Expected Value and Variance. https://math.dartmouth.edu/~prob/prob/prob.pdf"
  ],
  "related": [
    "weighted-average",
    "probability",
    "standard-deviation"
  ],
  "changelog": []
}
