如何生成相关的Uniform [0,1]变量

编程入门 行业动态 更新时间:2024-10-24 20:23:50
本文介绍了如何生成相关的Uniform [0,1]变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

(此问题与如何生成具有不同分布的相关变量的数据集?)

在Stata中,说我按照Uniform [0,1]分布创建一个随机变量:

In Stata, say that I create a random variable following a Uniform[0,1] distribution:

set seed 100 gen random1 = runiform()

我现在想创建一个与第一个变量相关的第二个随机变量(相关性应为0.75,但以0和1为界).我希望这个第二个变量也或多或少更少Uniform [0,1].我该怎么办?

I now want to create a second random variable that is correlated with the first (the correlation should be .75, say), but is bounded by 0 and 1. I would like this second variable to also be more-or-less Uniform[0,1]. How can I do this?

推荐答案

这不是确切的方法,但是NORTA/copula方法应该非常接近并且易于实现.

This won't be exact, but the NORTA/copula method should be pretty close and easy to implement.

相关引用为:

Cario,Marne C.和Barry L. Nelson. 建模和生成具有任意边际分布和相关矩阵的随机向量.西北大学工业工程与管理科学系技术报告,伊利诺伊州埃文斯顿,1997年.

Cario, Marne C., and Barry L. Nelson. Modeling and generating random vectors with arbitrary marginal distributions and correlation matrix. Technical Report, Department of Industrial Engineering and Management Sciences, Northwestern University, Evanston, Illinois, 1997.

可以在此处找到该论文.

从任何分布生成相关随机变量的一般方法是:

The general recipe to generate correlated random variables from any distribution is:

  • 使用corr2data
  • 从联合标准正态分布中绘制两个(或多个)相关变量
  • 使用normal()
  • 计算每个变量的单变量正态CDF
  • 应用任何分布的逆CDF来模拟该分布的绘制.
  • Draw two (or more) correlated variables from a joint standard normal distribution using corr2data
  • Calculate the univariate normal CDF of each of these variables using normal()
  • Apply the inverse CDF of any distribution to simulate draws from that distribution.
  • 使用 [0,1]统一,第三步非常简单a>:您甚至不需要它.通常,您所获得的相关性的幅度将小于原始(正常)相关性的幅度,因此将这些相关性提高一点可能会很有用.

    The third step is pretty easy with the [0,1] uniform: you don't even need it. Typically, the magnitude of the correlations you get will be less than the magnitudes of the original (normal) correlations, so it might be useful to bump those up a bit.

    状态代码,用于2个相关系数为0.75的统一变量:

    clear // Step 1 matrix C = (1, .75 \ .75, 1) corr2data x y, n(10000) corr(C) double corr x y, means // Steps 2-3 replace x = normal(x) replace y = normal(y) // Make sure things worked corr x y, means stack x y, into(z) clear lab define vars 1 "x" 2 "y" lab val _stack vars capture ssc install bihist bihist z, by(_stack) density tw1(yline(-1 0 1))

    如果您想改善均匀情况下的近似值 ,则可以像这样转换相关性(请参见链接论文的第5节):

    If you want to improve the approximation for the uniform case, you can transform the correlations like this (see section 5 of the linked paper):

    matrix C = (1,2*sin(.75*_pi/6)\2*sin(.75*_pi/6),1)

    这是0.76536686,而不是0.75.

    This is 0.76536686 instead of the 0.75.

    评论中问题的代码

    相关矩阵C编写得更紧凑,我正在应用转换:

    The correlation matrix C written more compactly, and I am applying the transformation:

    clear matrix C = ( 1, /// 2*sin(-.46*_pi/6), 1, /// 2*sin(.53*_pi/6), 2*sin(-.80*_pi/6), 1, /// 2*sin(0*_pi/6), 2*sin(-.41*_pi/6), 2*sin(.48*_pi/6), 1 ) corr2data v1 v2 v3 v4, n(10000) corr(C) cstorage(lower) forvalues i=1/4 { replace v`i' = normal(v`i') }

    更多推荐

    如何生成相关的Uniform [0,1]变量

    本文发布于:2023-11-30 00:37:55,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1648143.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:变量   Uniform

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!