chiSqSnpGenos: Chi-squared for Hardy-Weinberg

View source: R/quantgen.R

chiSqSnpGenosR Documentation

Chi-squared for Hardy-Weinberg

Description

Calculate the chi2 statistic to test for Hardy-Weinberg equilibrium. See Graffelman & Camarena (2007) and Shriner (2011).

Usage

chiSqSnpGenos(
  X,
  mafs = NULL,
  c = 0.5,
  thresh.c = 0.01,
  calc.with.D = TRUE,
  calc.pval = TRUE
)

Arguments

X

matrix of bi-allelic SNP genotypes encoded as allele doses in 0,1,2, with genotypes in rows and SNPs in columns; missing values should be encoded as NA

mafs

vector of minor allele frequencies; if NULL, the frequencies will be estimated by feeding X to estimSnpMaf

c

continuity correction (0 means "no correction"; usually, 0.5 is used, from Yates (1934))

thresh.c

threshold on minor allele frequencies below which the continuity correction isn't applied (used when c > 0); see Graffelman (2010)

calc.with.D

calculate the chi2 statistic with D, the deviation from independence for the heterozygote, as in equation 1 from Graffelman & Camarena (2007), which only requires the number of heterozygotes; otherwise, use equation 4

calc.pval

calculate the p values associated with the test statistics (Chi-squared distribution with one degree of freedom)

Value

matrix

Author(s)

Timothee Flutre

See Also

estimSnpMaf, countGenotypicClasses

Examples

## Not run: set.seed(1859)
library(scrm)
nb.genos <- 100
Ne <- 10^4
chrom.len <- 10^5
mu <- 10^(-8)
c <- 10^(-8)
genomes <- simulCoalescent(nb.inds=nb.genos,
                           pop.mut.rate=4 * Ne * mu * chrom.len,
                           pop.recomb.rate=4 * Ne * c * chrom.len,
                           chrom.len=chrom.len)
X <- genomes$genos
out <- chiSqSnpGenos(X)
head(out)
sum(p.adjust(out[,"pvalue"], "BH") <= 0.05)
## library(HardyWeinberg) # available on CRAN
## cts <- countGenotypicClasses(X=X)[, -4]
## colnames(cts) <- c("AA","AB","BB")
## out2 <- HWChisqMat(X=cts, cc=0.5, verbose=FALSE)
## lapply(out2, head)
## HWTernaryPlot(X=cts, region=2)

## End(Not run)

timflutre/rutilstimflutre documentation built on Feb. 7, 2024, 8:17 a.m.