Group Abstract Group Abstract

Message Boards Message Boards

0
|
12.2K Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Probability density of a Cos function for Normal variable?

Posted 3 years ago

Hello

I am reading the Wikipedia article about the normal distribution (section Operations and functions of normal variables), and I am unable to obtain with Mathematica the first example given, namely:

Probability density of the function cos( x^2) of a normal variable x with μ = − 2 and σ = 3 .

PDF cannot be of help as it applies to a distribution of a variable and not to a function of a variable whose distribution is normal, and I do know not other Mathematica functions to compute probability density.

Thanks.

POSTED BY: Jan Potocki
6 Replies
Posted 3 years ago

For whatever it's worth the second answer followed what's done for a "wrapped normal" distribution.

For the first answer, I chose a 1-to-1 formula and Abs[xx] is not 1-to-1.

POSTED BY: Jim Baldwin
Posted 3 years ago

Thanks Jim for your second answer which is thorough and well explained., A solution to get inspiration from when the function TransformedDistribution does not work.

In your first answer could you comment more on the way you choose to scale xx to be between 0 and 1 ? Why the simpler Abs[xx] is not suitable ? I tried that with a smaller sample but the result obtained afterwards is wrong..

POSTED BY: Jan Potocki
Posted 3 years ago
POSTED BY: Jim Baldwin
Posted 3 years ago

The closed-form solution for this probability density is in the eye of the beholder as it is expressed with an infinite number of terms.

$$\sum _{k=1}^{\infty} \frac{e^{-\frac{1}{18} \left(2-\sqrt{2 \pi k-\cos ^{-1}(c)}\right)^2}}{6 \sqrt{2 \pi } \sqrt{1-c^2} \sqrt{2 \pi k-\cos ^{-1}(c)}}+\sum _{k=1}^{\infty} \frac{e^{-\frac{1}{18} \left(\sqrt{2 \pi k-\cos ^{-1}(c)}+2\right)^2}}{6 \sqrt{2 \pi } \sqrt{1-c^2} \sqrt{2 \pi k-\cos ^{-1}(c)}}+\sum _{k=0}^{\infty} \frac{e^{-\frac{1}{18} \left(2-\sqrt{\cos ^{-1}(c)+2 \pi k}\right)^2}}{6 \sqrt{2 \pi } \sqrt{1-c^2} \sqrt{\cos ^{-1}(c)+2 \pi k}}+\sum _{k=0}^{\infty} \frac{e^{-\frac{1}{18} \left(\sqrt{\cos ^{-1}(c)+2 \pi k}+2\right)^2}}{6 \sqrt{2 \pi } \sqrt{1-c^2} \sqrt{\cos ^{-1}(c)+2 \pi k}}$$

but a good approximation can be had with 40 to 50 terms per summation.

Here is the Mathematica code:

kmax =.
pdf =
 Sum[PDF[NormalDistribution[-2, 3], Sqrt[ArcCos[c] + 2 \[Pi] k]] 1/(2 Sqrt[1 - c^2] Sqrt[2 k \[Pi] + ArcCos[c]]), {k, 0, kmax}] +
  Sum[PDF[NormalDistribution[-2, 3], Sqrt[-ArcCos[c] + 2 \[Pi] k]] 1/(2 Sqrt[1 - c^2] Sqrt[2 k \[Pi] - ArcCos[c]]), {k, 1, kmax}] +
  Sum[PDF[NormalDistribution[-2, 3], -Sqrt[ArcCos[c] + 2 \[Pi] k]] 1/(2 Sqrt[1 - c^2] Sqrt[2 k \[Pi] + ArcCos[c]]), {k, 0, kmax}] +
  Sum[PDF[NormalDistribution[-2, 3], -Sqrt[-ArcCos[c] + 2 \[Pi] k]] 1/(2 Sqrt[1 - c^2] Sqrt[2 k \[Pi] - ArcCos[c]]), {k, 1, kmax}]

I'll put in the details sometime soon.

POSTED BY: Updating Name
Posted 3 years ago

As Eric Rimbey mentions TransformedDistribution is the function to try. However, in this case Mathematica does not find a pdf (and a closed-form might not even exist).

The next thing to try is to take a large sample and look at the resulting shape of the distribution. In this case, it appears that a beta distribution might provide a good fit (but properly scaled to have values between -1 and 1).

dist = TransformedDistribution[Cos[x^2], x \[Distributed] NormalDistribution[-2, 3]];
xx = RandomVariate[dist, 10000000];

(* Scale xx to be between 0 and 1 *)
z = (1 + xx)/2;

(* Solve for the corresponding moments of a beta distribution *)
sol = Solve[{Mean[z] == Mean[BetaDistribution[a, b]],
    Variance[z] == Variance[BetaDistribution[a, b]]}, {a, b}][[1]]
(* {a -> 0.485618, b -> 0.369652} *)

(* Show results *)
Show[Histogram[xx, "FreedmanDiaconis", "PDF"],
 Plot[PDF[BetaDistribution[a, b] /. sol, (1 + x)/2]/2, {x, -1, 1}, PlotRange -> {{0.01, 0.99}, {0, 8}}]]

Beta distribution fitted with method of moments

POSTED BY: Jim Baldwin
Posted 3 years ago

I think you might be able to use TransformedDistribution.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard