[R] Simulate I x J contingency tables using correlation coefficient using bivariate normal distribution

Thierry Onkelinx th|erry@onke||nx @end|ng |rom |nbo@be
Mon Aug 19 11:22:59 CEST 2019

Dear Sripriya,

Step 1. generate random values from a multivariate normal distribution
Step 2. convert the random values into probabilities
Step 3. convert the probabilities into values from the target distribution

n <- 1e3
correl <- 0.9
lambda <- c(10, 50)
sigma <- matrix(correl, ncol = length(lambda), nrow = length(lambda))
diag(sigma) <- 1
binorm <- rmvnorm(n, sigma = sigma)
bip <- apply(binorm, 2, pnorm)
bipois <- sapply(
  function(i) {
    qpois(bip[, i], lambda = lambda[i])

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx using inbo.be
Havenlaan 88 bus 73, 1000 Brussel

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey


Op ma 19 aug. 2019 om 10:29 schreef Sri Priya <sri.chocho using gmail.com>:

> Dear R Users,
> I am interested in generating contingency tables from bivariate normal
> distribution using different correlation coefficient values.
> I am experimenting numerous ways of generating contingency tables, and one
> possible way is to generate from multinomial distribution.
> I wonder how to generate the count variables from a continuous distribution
> using correlation structure. Generating bivariate normal variables can be
> easily done using mvrnorm() in R. I am struggling to write R code for
> generating count from continuous variables.
> Any suggestions is very much appreciated.
> Thanks.
> Sripriya.
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]

More information about the R-help mailing list