information:extraction
Random variables with density

Now consider a random variable X which has a probability density function given by a function f on the real number line. This means that the probability of X taking on a value in any given open interval is given by the integral of f over that interval. The expectation of X is then given by the integral E = ∫ − ∞ ∞ x f (x) d x. {\displaystyle \operatorname {E} =\int _{-\infty }^{\infty }xf(x)\,dx.} A general and mathematically precise formulation of this definition uses measure theory and Lebesgue integration, and the corresponding theory of absolutely continuous random variables is described in the next section. The density functions of many common distributions are piecewise continuous, and as such the theory is often developed in this restricted setting. For such functions, it is sufficient to only consider the standard Riemann integration. Sometimes continuous random variables are defined as those corresponding to this special class of densities, although the term is used differently by various authors.

Analogously to the countably-infinite case above, there are subtleties with this expression due to the infinite region of integration. Such subtleties can be seen concretely if the distribution of X is given by the Cauchy distribution Cauchy(0, π), so that f (x) = (x + π). It is straightforward to compute in this case that ∫ a b x f (x) d x = ∫ a b x x 2 + π 2 d x = 1 2 ln b 2 + π 2 a 2 + π 2. {\displaystyle \int _{a}^{b}xf(x)\,dx=\int _{a}^{b}{\frac {x}{x^{2}+\pi ^{2}}}\,dx={\frac {1}{2}}\ln {\frac {b^{2}+\pi ^{2}}{a^{2}+\pi ^{2}}}.} The limit of this expression as a → −∞ and b → ∞ does not exist: if the limits are taken so that a = − b, then the limit is zero, while if the constraint 2 a = − b is taken, then the limit is ln(2).

To avoid such ambiguities, in mathematical textbooks it is common to require that the given integral converges absolutely, with E left undefined otherwise. However, measure-theoretic notions as given below can be used to give a systematic definition of E for more general random variables X.