Mathematica中的变换分布 [英] TransformedDistribution in Mathematica
问题描述
我开发了一些代码,以从LogNormalDistribution和StableDistribution的乘积生成随机变量:
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 *)
我认为这很好:
LNStableRV[{1.5, 1, 1, 0.5, 1}, 50000];
Histogram[%, Automatic, "ProbabilityDensity",
PlotRange -> {{-4, 6}, All}, ImageSize -> 250]
ListPlot[%%, Joined -> True, PlotRange -> All]
现在我想沿相同的行创建一个TransformedDistribution,以便可以使用PDF [],CDF []等在此自定义分布上,并且可以轻松进行绘图和其他分析。
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.
从文档中心> TransformedDistribution中的示例中推断:
Extrapolating from an example in Documentation Center > TransformedDistribution:
\[ScriptCapitalD] =
TransformedDistribution[
u v, {u \[Distributed] ExponentialDistribution[1/2],
v \[Distributed] ExponentialDistribution[1/3]}];
我已经尝试过:
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]
哪个给我这个:
TransformedDistribution[
1 + \[FormalX]1 \[FormalX]2, {\[FormalX]1 \[Distributed]
LogNormalDistribution[0, 0.5], \[FormalX]2 \[Distributed]
StableDistribution[1, 1.5, 1, 1, 0.5]}]
但是当我尝试绘制分布的PDF时,似乎从来没有完成(请允许我让它运行一分钟或两分钟以上):
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 *)
那么,一些问题:
我的函数LogNormalStableDistribution []有意义吗?
Does my function: LogNormalStableDistribution[] make sense to do this kind of thing?
如果是的话,我会这样做:
If yes do I:
- 只需要让图[]多跑
? - 以某种方式更改它?
- 如何使
运行更快?
如果没有:
- 是否需要以其他方式处理?
- 使用MixtureDistribution吗?
- 还有其他用途吗?
任何想法都值得赞赏。
最佳
J
推荐答案
您的方法使用转换的发行版本就可以了,但是由于发行版本的 PDF
不以封闭形式存在,因此 PDF [TransformedDistribution [..],x]
并非可行之路,因为每 x
都将使用一个符号求解器。最好对您的分布进行按摩以得到pdf。令X为对数正态稳定随机变量。然后
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]
但是 X == U * V +增量
因此 X< = x
转换为 V< =(x-delta)/ U
。这样会得到
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]]]]
关于 x
的差异,我们得到 PDF
:
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]]]]
使用它,这是情节
这篇关于Mathematica中的变换分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!