Skip to content

Expectation ​

E[f(x)]E[f(x)] — the expected value of f under x's distribution.

Expectation(f, Distributed(x, dist))exact for f constant, linear or quadratic in x; otherwise stays unevaluated.
Typed signatures
TypePackageApplies
(any, expression<Distributed>) -> realstatisticsalways

Domain: Statistics

Details
  • Closed forms: E[c]=cE[c] = c; E[x]=Mean(dist)E[x] = Mean(dist); E[x2]=Variance(dist)+Mean(dist)2E[x^2] = Variance(dist) + Mean(dist)^2; extended over Add and Multiply-by-constant by linearity — E[2x+1]=2 E[x]+1E[2x+1] = 2\,E[x]+1, and so on, recursively.
  • Never approximated on its own — apply N to the result for a numeric value.
  • Anything past a linear/quadratic polynomial in x (e.g. E[sin⁡x]E[\sin x]) has no closed form here and stays unevaluated, rather than falling back to numeric integration.

Examples

Basic #
live ↗
InExpectation(x,Distributed(x,NormalDistribution⁡(2,3)))\mathrm{Expectation}(x, \mathrm{Distributed}(x, \operatorname{NormalDistribution}(2, 3)))Out22

Var+Mean2=9+4Var + Mean^2 = 9 + 4

live ↗
InExpectation(x2,Distributed(x,NormalDistribution⁡(2,3)))\mathrm{Expectation}(x^2, \mathrm{Distributed}(x, \operatorname{NormalDistribution}(2, 3)))Out1313
live ↗
InExpectation(2x+1,Distributed(x,NormalDistribution⁡(2,3)))\mathrm{Expectation}(2x+1, \mathrm{Distributed}(x, \operatorname{NormalDistribution}(2, 3)))Out55
Possible issues #
live ↗
InExpectation(sin⁡(x),Distributed(x,NormalDistribution⁡(2,3)))\mathrm{Expectation}(\sin(x), \mathrm{Distributed}(x, \operatorname{NormalDistribution}(2, 3)))OutExpectation(sin⁡(x),Distributed(x,NormalDistribution⁡(2,3)))\mathrm{Expectation}(\sin(x), \mathrm{Distributed}(x, \operatorname{NormalDistribution}(2, 3)))
About
Examples4

See also: Distributed, Probability, Mean