从二项分布生成相关随机数 [英] Generate correlated random numbers from binomial distributions

查看:28
本文介绍了从二项分布生成相关随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法来从几个二项式分布中生成相关的随机数.

I am trying to find a way to generate correlated random numbers from several binomial distributions.

我知道如何处理正态分布(使用 MASS::mvrnorm),但我没有找到适用于二项式响应的函数.

I know how to do it with normal distributions (using MASS::mvrnorm), but I did not find a function applicable to binomial responses.

推荐答案

您可以使用 copula 包生成相关的制服,然后使用 qbinom 函数将它们转换为二项式变量.这是一个简单的例子:

You can generate correlated uniforms using the copula package, then use the qbinom function to convert those to binomial variables. Here is one quick example:

library(copula)

tmp <- normalCopula( 0.75, dim=2 )
x <- rcopula(tmp, 1000)
x2 <- cbind( qbinom(x[,1], 10, 0.5), qbinom(x[,2], 15, 0.7) )

现在 x2 是一个矩阵,其中 2 列代表 2 个相关的二项式变量.

Now x2 is a matrix with the 2 columns representing 2 binomial variables that are correlated.

这篇关于从二项分布生成相关随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆