Home > Community > Can anyone help me with the Hardy Weinberg Equilibrium?
Upvote

26

Downvote
+ Human genetics
Posted by
Al Martin

Can anyone help me with the Hardy Weinberg Equilibrium?

Donald Montecalvo  Follow

Hi Fatima,

To do hwe test in R you could do the following:

#### R-code ###
dat <- data.frame(AA = c(30, 20), Aa = c(60, 40), aa = c(8, 0), row.names = c("control", "cases"))

# The table will look like this:
AA Aa aa
control 30 60 8
cases 20 40 0

# Next we want to calculate allele frequencies so we can work out expected genotype
# proportions (e.g. 1 = p^2+q^2+2pq)

allele_freq <- cbind(((2*dat$AA) + dat$Aa)/(2*rowSums(dat)),
((2*dat$aa) + dat$Aa)/(2*rowSums(dat)))
colnames(allele_freq) <- c("A", "a")

# allele frequency table looks like this:
A a
control 0.6122449 0.3877551
cases 0.6666667 0.3333333

# Now we calculate expected genotype proportions

HWEexpected <- t(apply(allele_freq, 1, function(x){
AA <- x["A"]^2
Aa <- 2*x["A"]*x["a"]
aa <- x["a"]^2
return(cbind(AA, Aa, aa))
}))

# The expected genotype proportions are:
AA Aa aa
control 0.3748438 0.4748022 0.1503540
cases 0.4444444 0.4444444 0.1111111

# Now, using our observed numbers and expected proportions, we can test HWE
# using the function "chisq.test"

# convert genotypes and proportions into lists for efficient tests

dat <- lapply(1:nrow(dat), function(i) return(as.vector(dat[i,])))

HWEexpected <- lapply(1:nrow(HWEexpected), function(i){
return(as.vector(HWEexpected[i,]))
})

# Run HWE test
mapply(FUN = chisq.test, x = dat, p = HWEexpected, SIMPLIFY = FALSE)

# results
[[1]]

Chi-squared test for given probabilities

data: dots[[1L]][[1L]]
X-squared = 8.2119, df = 2, p-value = 0.01647


[[2]]

Chi-squared test for given probabilities

data: dots[[1L]][[2L]]
X-squared = 15, df = 2, p-value = 0.0005531

#### END ####

You can see that neither your controls or cases are in HWE.

Kevin

EDIT: Forgot to elaborate in the interpretation of results.
As both the cases and controls are in HW dis-equilibrium some HWE assumptions are violated in your data. These could be selection, non-random mating etc. For more information about HWE and case-control studies, see this rg question/answers (https://www.researchgate.net/post/Can_anyone_help_with_the_Hardy_Weinberg_equilibrium)


More

Upvote

VOTE

Downvote
Brian Rexit  Follow

Fatima,

In R language there is a package Hardy-Weinberg available in many functions implemented. I used it for my computations. Also in a PLINK programy by Purcell there is a command to test for HW: http://pngu.mgh.harvard.edu/~purcell/plink/summary.shtml#hardy

It depends on you what you chose, however if have SNPs count I believe R package would be better.


More

Upvote

VOTE

Downvote