I have tried unsuccessfully to use Mathematica to derive both the expected value (mean) and variance of a particular statistical distribution of interest to me.
The distribution is a discretized version of the Gaussian, and the question is: what is the expected value of $\lfloor X \rfloor$, where $X\sim N(\mu, \sigma)$ and $\lfloor \cdot \rfloor$ denotes the floor function (i.e., in Mathematica, Floor[]
) ?
I have tried a direct integration approach (with assumptions) allowing for a general mean and standard deviation:
Integrate[
Floor[x]*PDF[NormalDistribution[\[Mu], \[Sigma]],
x], {x, -\[Infinity], \[Infinity]},
Assumptions -> {\[Mu] \[Element] Reals, \[Sigma] \[Element]
PositiveReals}]
and also tried restricting the question to one involving an underlying standard normal distribution:
Integrate[
Floor[x]*PDF[NormalDistribution[0, 1],
x], {x, -\[Infinity], \[Infinity]}]
Equivalently, for the 2nd raw moment:
Integrate[
(Floor[x])^2 * PDF[NormalDistribution[\[Mu], \[Sigma]],
x], {x, -\[Infinity], \[Infinity]},
Assumptions -> {\[Mu] \[Element] Reals, \[Sigma] \[Element]
PositiveReals}]
The approach fails in both instances, but the problem is solvable. One solution, for the mean, which uses the Poisson summation formula, is:
$$ \mathbb E\lfloor X \rfloor = \mu - \mathbb E \{X\} = \mu - \frac{1}{2} + \frac{1}{\pi} \sum_{k=1}^\infty e^{-2\pi^2\sigma^2 k^2} \frac{\sin(2\pi k \mu)}{k} $$
and, indeed, it strikes me that using the Poisson summation formula is likely to yield a solution for the question about variance also. However, to use the Poisson summation formula, one needs the Fourier transform of the distribution, but with that I have also been unsuccessful.
What is an appropriate way of using Mathematica to obtain a solution both for the mean, and the variance for my distribution.
Further explanation: I've just seen Bob Hanlon's very instructive numerical-methods solution ... but I'd really like to find a way of reproducing the Poisson summation/Fourier-based analytic solution.
One very significant reason for preferring a solution involving the Poisson summation formula (and associated Fourier description) is that it clearly reveals the oscillatory nature of the function, and it is the oscillation that particularly interests me. It's true that I have displayed an analytic description of the mean for the Floor[]
function, but there are several other distributions of interest, so I'll like to learn a general Mathematica approach.
pmf[x_, \[Mu]_, \[Sigma]_] := CDF[NormalDistribution[\[Mu], \[Sigma]], x + 1] - CDF[NormalDistribution[\[Mu], \[Sigma]], x]
. It also seems that if $\mu$ is an integer, then the mean simplifies to $\mu-1/2$ and if $\mu$ and $\sigma$ are integers, then the variance is $\sigma^2+1/12$. $\endgroup$