# Inverse CDF of non-builtin probability distribution

I'm trying to get the inverse CDF of the Raised Cosine probability distribution function.

It has parameters $$\mu$$ and $$s$$, support $$x \in [\mu - s, \mu + s]$$,

PDF 1/(2 s) (1 + Cos[((x - μ)/s) π])

and CDF 1/2 (1 + (x - μ)/s + 1/π Sin[((x - μ)/s) π])

How can I compute its analytic inverse CDF?

I tried the ProbabilityDistribution[] construct like

RaisedCosineDistribution = ProbabilityDistribution[
1/(2 s) (1 + Cos[((x - μ)/s) π]), {x, μ - s, μ +
s}]


but then taking CDF[RaisedCosineDistribution] didn't even give me the CDF presented above.

I'm pretty sure I am doing something in the wrong way, but don't know what.

Clear[RaisedCosineDistribution]


As with built-in distributions, you need to include the parameters in the distribution definition, and the constraints on the parameters as Assumptions in the ProbabilityDistribution

RaisedCosineDistribution[μ_, s_] =
ProbabilityDistribution[
1/(2 s) (1 + Cos[((x - μ)/s) π]), {x, μ - s, μ + s},
Assumptions -> {Element[μ, Reals], s > 0}] // Simplify;


These Assumptions are then available to other related built-in functions through DistributionParameterAssumptions

DistributionParameterAssumptions[RaisedCosineDistribution[μ, s]] PDF[RaisedCosineDistribution[μ, s], x] Verifying that this is equivalent to your input

Assuming[{s > 0 && s + μ > x && s + x > μ},
PDF[RaisedCosineDistribution[μ, s], x] ==
1/(2 s) (1 + Cos[((x - μ)/s) π]) // Simplify]

(*  True  *)


The Assumptions are used by CDF

CDF[RaisedCosineDistribution[μ, s], x] // Simplify Verifying that this is equivalent to your expected result

Assuming[{s > 0 && s + μ > x && s + x > μ},
CDF[RaisedCosineDistribution[μ, s], x] ==
1/2 (1 + (x - μ)/s + 1/π Sin[((x - μ)/s) π]) // Simplify]

(*  True  *)


The InverseCDF is then just used directly for numeric values of {μ, s} -- albeit slowly

Plot[InverseCDF[RaisedCosineDistribution[0, 1/2], q], {q, 0, 1}] This function might do the job:

invCDF[p_, μ_, s_] := x /. FindRoot[1/2 (1 + (x - μ)/s + 1/π Sin[((x - μ)/s) π]) == p,
{x, μ}]


So the value associated with the CDF = 0.975 would be

invCDF[0.975, 6, 2]
(* 7.36539 *)


As a check (which one should always do):

1/2 (1 + (x - μ)/s + 1/π Sin[((x - μ)/s) π]) /. {x -> 7.36539, μ -> 6, s -> 2}
(* 0.975 *)

• Thanks, but I would compute the analytic symbolic function, not a numerical result. – plasmacel May 9 '17 at 18:19
• I'd like to see a symbolic function, too. But do you think it exists? – JimB May 9 '17 at 18:20
• Yes, I'm pretty sure about that. I've seen an analytic formula for the inverse CDF of this distribution, but with implicit parameters $\mu = s = 0.5$. So it must exist. – plasmacel May 9 '17 at 18:21
• I'm skeptical about that. The basic equation to be solved for $x$ is $\frac{1}{2} \left(x+\frac{\sin (\pi x)}{\pi }+1\right)=p$. That looks pretty transcendental to me. If you have a reference for that special case, it would be helpful to include that information in your question. – JimB May 9 '17 at 20:52