chi-squared test for hardy-weinberg equilibrium in r
1
1
Entering edit mode
9.1 years ago
tonja.r ▴ 600

I was searching for a function in R to perform a chi-squared test for hardy-weinberg equilibrium.

Strait-forward would be to compute a chi-squared-value by my own and then take a look at a p-value with a given degree of freedom:

nAA=18
nAa=104
naa=109
n=nAA+nAa+naa
pA=(2*nAA+nAa)/(2*n)
pa=1-pA
obs= c(nAA,nAa,naa)
exp=c(n*pA*pA,2*n*pA*pa,n*pa^2)
sum(((obs-exp)^2)/exp)
[1] 1.001318
1-pchisq(1.001318,df=1)
[1] 0.3169918

My degrees of freedom are 1, as number of genotypes = 3 and of alleles = 2 (df=3-2=1). So, p-value is 0.31699, I am happy, everything is in HWE. Then I decided to have a look if there is a function in R for that within standard packages and have found the following:

chisq.test(obs, p = exp/sum(exp)) 
Chi-squared test for given probabilities data: obs X-squared = 1.0013, df = 2, p-value = 0.6061

It seems that chisq.test is not suitable for HWE as it computes the df as 2. Are there any functions that can compute the chisq.test for HWE problems?

Thank you.

R • 9.0k views
ADD COMMENT
1
Entering edit mode
9.1 years ago
Brice Sarver ★ 3.8k

A quick search turns up the HardyWeinberg R package. Specifically, HWChisq() performs the test you want.

ADD COMMENT

Login before adding your answer.

Traffic: 2011 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6