TransformedDistribution in Mathematica

2019-04-10 13:47发布

问题:

I have developed some code to generate random variates from the product of a LogNormalDistribution and a StableDistribution:

LNStableRV[{\[Alpha]_, \[Beta]_, \[Gamma]_, \[Sigma]_, \[Delta]_}, 

n_] := Module[{LNRV, SDRV, LNSRV},
  LNRV = RandomVariate[LogNormalDistribution[Log[\[Gamma]], \[Sigma]],
     n];
  SDRV = RandomVariate[
    StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]], n];
  LNRV * SDRV + \[Delta]
  ]

(* Note the delta serves as a location parameter *)

I think this works fine:

LNStableRV[{1.5, 1, 1, 0.5, 1}, 50000];
Histogram[%, Automatic, "ProbabilityDensity", 
 PlotRange -> {{-4, 6}, All}, ImageSize -> 250]
ListPlot[%%, Joined -> True, PlotRange -> All]

Now I'd like to create a TransformedDistribution along the same lines so that I can use PDF[], CDF[], etc. on this custom distribution and easily do plots and other analysis.

Extrapolating from an example in Documentation Center > TransformedDistribution:

\[ScriptCapitalD] = 
  TransformedDistribution[
   u v, {u \[Distributed] ExponentialDistribution[1/2], 
    v \[Distributed] ExponentialDistribution[1/3]}];

I've tried this:

LogNormalStableDistribution[\[Alpha]_, \[Beta]_, \[Gamma]_, \
\[Sigma]_, \[Delta]_] := Module[{u, v},
   TransformedDistribution[
    u * v + \[Delta], {u \[Distributed] 
      LogNormalDistribution[Log[\[Gamma]], \[Sigma]], 
     v \[Distributed] 
      StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]]}]
   ];

\[ScriptCapitalD] = LogNormalStableDistribution[1.5, 1, 1, 0.5, 1]

Which gives me this:

TransformedDistribution[
 1 + \[FormalX]1 \[FormalX]2, {\[FormalX]1 \[Distributed] 
   LogNormalDistribution[0, 0.5], \[FormalX]2 \[Distributed] 
   StableDistribution[1, 1.5, 1, 1, 0.5]}]

But when I try to plot a PDF of the distribution it never seems to finish (granted I haven't let it run more than a minute or 2):

Plot[PDF[\[ScriptCapitalD], x], {x, -4, 6}] (* This should plot over the same range as the Histogram above *)

So, some questions:

Does my function: LogNormalStableDistribution[] make sense to do this kind of thing?

If yes do I:

  • Just need to let the Plot[] run longer?
  • Change it somehow?
  • What can I do to make it run faster?

If not:

  • Do I need to approach this in a different way?
  • Use MixtureDistribution?
  • Use Something else?

Any ideas appreciated.

Best,

J

回答1:

Your approach using transformed distribution is just fine, but since distribution's PDF does not exist in closed form, PDF[TransformedDistribution[..],x] is not the way to go, as for every x a symbolic solver will be applied. It is better to massage your distribution to arrive at pdf. Let X be LogNormal-Stable random variate. Then

CDF[LogNormalStableDistribution[params], x] == Probability[X <= x] 

But X==U*V + delta hence X<=x translates into V<=(x-delta)/U. This gives

LogNormalStableCDF[{\[Alpha]_, \[Beta]_, \[Gamma]_, \[Sigma]_, \
\[Delta]_}, x_Real] := 
 Block[{u}, 
  NExpectation[
   CDF[StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]], (x \
- \[Delta])/u], 
   u \[Distributed] LogNormalDistribution[Log[\[Gamma]], \[Sigma]]]]

Differentiating with respect to x we get PDF:

LogNormalStablePDF[{\[Alpha]_, \[Beta]_, \[Gamma]_, \[Sigma]_, \
\[Delta]_}, x_Real] := 
 Block[{u}, 
  NExpectation[
   PDF[StableDistribution[\[Alpha], \[Beta], \[Gamma], \[Sigma]], (x \
- \[Delta])/u]/u, 
   u \[Distributed] LogNormalDistribution[Log[\[Gamma]], \[Sigma]]]]

Using this, here is the plot