1
$\begingroup$

I was trying to calculate the expectation value of the standard deviation, if I only take two data points into account. My code is the following:

n[x_] = PDF[NormalDistribution[μ, σ], x];
σ2[x1_, x2_] = 
  FullSimplify[
   Sqrt[1/2*((x1 - (x1 + x2)/2)^2 + (x2 - (x1 + x2)/2)^2)]];
E2[x1_, x2_] = σ2[x1, x2]*n[x1]*n[x2]
Assuming[{σ > 0, μ > 0}, 
 Integrate[
  E2[x1, x2], {x1, -Infinity, Infinity}, {x2, -Infinity, Infinity}]]

The results I get are:

$$\frac{\sqrt{(\text{x1}-\text{x2})^2} e^{-\frac{(\text{x1}-\mu )^2}{2 \sigma ^2}-\frac{(\text{x2}-\mu )^2}{2 \sigma ^2}}}{4 \pi \sigma ^2}$$ $$0$$

Where the first line is the function I integrate from $-\infty$ to $\infty$ in two dimension. The result $0$ can not be true since both parts, the exponential and the root are non-negative functions and clearly give a positive value for almost all possible values.

I must have made some mistake at some point, but I do not know where...

Thanks in advance, Glostas

$\endgroup$
  • 2
    $\begingroup$ A manual derivation for me yields (σ/(2 Sqrt[2]π)) Integrate[Exp[-x1^2/2 - x2^2/2]Piecewise[{{x2 - x1, x2 > x1}}, x1 - x2], {x1, -∞, ∞}, {x2, -∞, ∞}]. However, Assuming[{x1, x2, μ} ∈ Reals && σ > 0, Expectation[StandardDeviation[{x1, x2}], {x1 \[Distributed] NormalDistribution[μ, σ], x2 \[Distributed] NormalDistribution[μ, σ]}]] yields 0. Hmm... $\endgroup$ – J. M. is away Aug 16 '17 at 15:38
  • 3
    $\begingroup$ Assuming[σ > 0 && μ > 0 && {x1, x2} ∈ Reals, Integrate[FullSimplify[E2[x1, x2]], {x1,-∞, ∞}, {x2,-∞,∞}]] gives σ/Sqrt[π] $\endgroup$ – rhermans Aug 16 '17 at 16:04
  • $\begingroup$ @rhermans This works perfect, thanks. I still fo not really understand he problem with my original function $\endgroup$ – Glostas Aug 17 '17 at 9:03
  • $\begingroup$ I don't understand it either, that is why I didn't leave it as an answer. I would not discard a BUG. $\endgroup$ – rhermans Aug 17 '17 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.