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:
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?