Question: chi-squared test for hardy-weinberg equilibrium in r
1
tonja.r460 wrote:

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.001318
1-pchisq(1.001318,df=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 • 4.9k views
ADD COMMENTlink
modified 4.4 years ago by Brice Sarver2.8k • written 4.4 years ago by tonja.r460
1
Brice Sarver2.8k wrote:

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

ADD COMMENTlink written 4.4 years ago by Brice Sarver2.8k
Please log in to add an answer.

Content
Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1260 users visited in the last hour