Let's say I want to create 50 binary variables of length 100 that are each correlated with each other.
For I create a correlation matrix with the specified rho's:
cor.mat <- matrix(0.2,nrow=50, ncol=50)
diag(cor.mat) <- 1
next I use rmvbin
:
library(bindata)
rmvbin<-rmvbin(100, margprob=x, bincorr=cor.mat)
However, I'm not sure how to calculate the margprob argument. Can someone help?
SHould it be a vector of the sum of probabilities in each row and column?
margprob
should simply be a repeated vector of the probability that any single binary variable is 1, independent of the rest; call this value p
. Assuming identically distributed variables (which given your correlation matrix seems to be the case), margprob=rep(p,50)
.
It should NOT be a vector of the sum of probabilities in each row and column, as the correlation matrix cannot be used to determine the marginal probabilities. If you're having trouble figuring out what the marginal probabilities for your random variables are, you will have to give more context for the problem and it would be a question more appropriate for math.stackexchange.com.