python - 在 Python 中生成具有指定边际的 copula 相关样本

标签 python random statistics

我有 N 个随机变量 (X1,...,XN),每个变量分布在特定的边际(正态、对数正态、泊松...)上,我想生成 p 个联合实现的样本这些变量 Xi,考虑到这些变量与给定的 Copula 相关,使用 Python 3。我知道 R 是一个更好的选择,但我想用 Python 来做。

已关注 this我设法用高斯 Copula 来做到这一点。现在我想调整方法以使用阿基米德 Copula(Gumbel、Frank...)或 Student Copula。在高斯联结方法的开始,您从多元正态分布中抽取 p 个实现的样本。为了使其适应另一个联结,例如二元 Gumbel,我的想法是从 joint distribution of a bivariate Gumbel 中抽取样本。 ,但我不确定如何实现。

我尝试过使用几个 Python 3 软件包: copulae , copulacopulas都提供了将特定联结拟合到数据集的选项,但不允许从给定联结中抽取随机样本。

您能否提供一些关于如何从具有均匀边缘的给定 Copula 中抽取多元随机样本的算法见解?

最佳答案

请查看此页面"Create a composed distribution" 。我想这就是您要找的

例如,如果您有 2 个分布 x1: Uniform on [1, 3] 和 x2: Normal(0,2) 并且您知道依赖结构 copula,则可以构建多维分布 X = (x1, x2 )非常容易。

import openturns as ot

x1 = ot.Uniform(1, 3)
x2 = ot.Normal(0, 2)
copula = ot.IndependentCopula()

X = ot.ComposedDistribution([x1, x2], copula)

X.getSample(5) 将返回大小 = 5 的样本:

>>>   [ X0         X1         ]
0 : [  1.87016    0.802719  ]
1 : [  1.72333    2.73565   ]
2 : [  1.00422    2.00869   ]
3 : [  1.47887    1.4831    ]
4 : [  1.51031   -0.0872247 ]

您可以以 2D 方式查看云

import matplotlib.pyplot as plt

sample = dist.getSample(1000)
plt.scatter(sample[:, 0], sample[:, 1], s=2)

enter image description here

如果您选择copula = ot.ClaytonCopula(2),结果将是:

enter image description here

与 GumbelCopula(2):

enter image description here

关于python - 在 Python 中生成具有指定边际的 copula 相关样本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58094554/

相关文章:

Python - 检查作为字典一部分的列表中的值的便捷方法?

javascript - 是否可以使用 Array.prototype.reduce 创建数组的线性随机选择?

javascript - 如何产生两个不同的随机数?

r - 使用R的收缩率计算模型平均数据的置信区间

python - 两步过滤,pandas

python - Pymongo如何使用全文搜索

java - 在java中设置随机数的精度?

r - 从 data.frame 中的组中获取均值和标准差

python - 如何将 statsmodels 的 VAR 函数拟合的对数差分数据转换回实际值

python - txt文件中的熵