且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何用不同的分布生成相关变量的数据集?

更新时间:2023-01-27 09:32:11

如果您可以访问统计工具箱以及MATLAB你可以使用copula功能来做相当容易的操作。使用Copula,您可以指定每个变量的边际分布,以及变量之间的相关结构。



然后可以从copula生成随机数,使其适合数据等。



请参见MATLAB文档:



Copulas:生成相关样本


For teaching purposes, I need to generate random datasets of correlated random variables with different distributions. I have tried corr2data in Stata but it will not allow me to specify max and min values of the variables to be generated, just means, sd's and the covariance matrix. Therefore, I need to do messy adjustments after generation of the data. Various other details annoy me with corr2data. Is there a simpler way of doing this with MATLAB? I am not as familiar with this software as I am with Stata.

If you have access to Statistics Toolbox as well as MATLAB, you can use the copula functionality to do this fairly easily. Using a copula, you can specify the marginal distributions of each variable, and a correlation structure between the variables.

You can then generate random numbers from the copula, fit it to data etc. as well.

See in the MATLAB documentation:

Copulas: Generate Correlated Samples