[R] Hardy Weinberg

Mike Miller mbmiller+l at gmail.com
Thu Jun 23 04:21:03 CEST 2011


On Thu, 23 Jun 2011, David Duffy wrote:

>> I am interested in simulating 10,000 2 x 3 tables for SNPs data with 
>> the Hardy Weinberg formulation. Is there a quick way to do this? I am 
>> assuming that the minor allelle frequency is uniform in (0.05, 0.25).
>
> rmultinom() with HWE expectations


I'm also unsure of what the 2x3 table is (what are the rows?), and David 
gave you a good answer for how to make tabular data, but I just thought 
I'd add some info for those who may be interested...

If you want to make genotype data in the form of minor allele counts under 
HW, you can use rbinom() with size=2 and prob=MAF.

Suppose variable "n" is the number of subjects for whom data is to be 
generated, "maf" is a vector of minor allele frequencies, and "m" is the 
length of maf (i.e., the number of markers to be generated.  Then this 
will produce a data matrix (subjects by markers):

> maf <- c( .1, .2, .5 )
> n <- 7
> m <- length( maf )
> t( matrix( rbinom( n*m, 2, maf ), m, n ) )
      [,1] [,2] [,3]
[1,]    0    0    2
[2,]    0    1    1
[3,]    1    0    2
[4,]    0    2    1
[5,]    1    1    1
[6,]    0    1    2
[7,]    0    0    1

Of course, when data are produced that way, the markers are in linkage 
equilibrium (an unfortunate term meaning that the genotypes for pairs of 
markers are not associated).

Mike

--
Michael B. Miller, Ph.D.
Minnesota Center for Twin and Family Research
Department of Psychology
University of Minnesota



More information about the R-help mailing list