Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate correlated random numbers from binomial distributions

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

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

like image 399
Arnaud Avatar asked May 10 '12 13:05

Arnaud


People also ask

How do you generate a correlated random data?

To generate correlated normally distributed random samples, one can first generate uncorrelated samples, and then multiply them by a matrix C such that CCT=R, where R is the desired covariance matrix. C can be created, for example, by using the Cholesky decomposition of R, or from the eigenvalues and eigenvectors of R.

How do you generate a random number in a binomial distribution?

r = binornd( n , p ) generates random numbers from the binomial distribution specified by the number of trials n and the probability of success for each trial p . n and p can be vectors, matrices, or multidimensional arrays of the same size. Alternatively, one or more arguments can be scalars.

How do you find the correlation between random variables?

2 The correlation of X and Y is the number defined by ρXY = Cov(X, Y ) σXσY . The value ρXY is also called the correlation coefficient. Theorem 4.5. 3 For any random variables X and Y , Cov(X, Y ) = EXY − µXµY .

Can two random variables be correlated?

In statistics, correlation or dependence is any statistical relationship, whether causal or not, between two random variables or bivariate data.


1 Answers

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) )

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

like image 72
Greg Snow Avatar answered Oct 11 '22 09:10

Greg Snow