1

The expected value of a function of multiple random variables can be approximated by a Taylor expansion. How this can be done in MMA is described in other posts (Link1, Link2).

Let's assume we have a function of 3 iid normal variables

$f=\sqrt{(x_1-x_2)^4+x_3^4}$ with $x_i\sim\mathcal{N}(\mu_i,\sigma^2)$ and are looking for the expectation $\mathbb{E}[f]$.

The MMA code for a Taylor expansion of order 2 applying the cited descriptions would look like this:

f = Sqrt[(x[1] - x[2])^4 + x[3]^4]; (*our function*)
f = f /. x[i_] -> (z[i] - \[Mu][i]) t + \[Mu][i]; (*introduce dummy variable t*)
taylor = (Series[f, {t, 0, 2}] // Normal) /. t -> 1 // Expand;
mean = taylor //. z[i_]^2 -> \[Sigma]^2 + \[Mu][i]^2;
mean = FullSimplify[mean //. z[i_] -> \[Mu][i]]  (*output of 2nd order Taylor approximation*)

What is the reason to make the replacement in the form $z_i^2\to\sigma^2+\mu_i^2$ in the second last line, why is there an addition?

granular_bastard
  • 593
  • 4
  • 12
  • 2
    The expectation of $z_i^2$ is the sum of the variance ($\sigma^2$) and the square of the mean ($\mu_i^2). Rather than performing the known integration one uses a replacement rule. – JimB Jan 11 '21 at 20:28
  • Your f expression in code an TeX are different. Also, would TransformedDistribution help here? – MarcoB Jan 11 '21 at 20:29
  • Just to make sure: you do know that a large proportion of the values of $f$ could be imaginary? – JimB Jan 11 '21 at 21:49
  • example function f was corrected – granular_bastard Jan 11 '21 at 21:51
  • 1
    If you just need a function within Mathematica to estimate the mean, then directly doing the numerical integration for the two random variables ($x_1-x_2$ and $x_3$ with the 3 parameters $\mu_1-mu_2$, $\mu_3$, and $\sigma$ is more accurate and just as quick as any Taylor expansion approach. If you need a formula for use outside of Mathematica, then interpolation approaches might be feasible and more accurate than a Taylor expansion approach. Is there a particular set of values for the parameters? – JimB Jan 12 '21 at 03:30
  • you are right, the given function f was only a too simple example, just assume that f would be more complex – granular_bastard Jan 12 '21 at 16:29
  • I wrote it just a few minutes ago for me. (*function must be 1d*) deltaApprox[f_, dist_] := Module[{moment, getDelta}, moment[b_] := CentralMoment[dist, b]; getDelta[g_, mu_] := ((Table[D[g[x], {x, b}]/Factorial[b], {b, 0, 4}] /. x -> (x + mu))) . Table[moment[b], {b, 0, 4}]; getDelta[f, Mean@dist] ] – Xminer Nov 13 '23 at 09:30

0 Answers0