HWChisqStats: Fast computation of chi-square statistics for Hardy-Weinberg...

View source: R/HWChisqStats.R

HWChisqStatsR Documentation

Fast computation of chi-square statistics for Hardy-Weinberg equilibrium

Description

HWChisqStats is a function for the fast computation of chi-square statistics (or the corresponding p-values) for a large set of bi-allelic markers (typically SNPs).

Usage

HWChisqStats(X, x.linked = FALSE, pvalues = FALSE)

Arguments

X

A matrix with genotype counts, one row per marker. X should have 5 columns for an X-chromosomal data set and 3 columns for an autosomal data set.

x.linked

Logical indicating whether the markers are autosomal (x.linked=FALSE) or X-chromosomal (x.linked=TRUE).

pvalues

Logical indicated whether chi-square statistics should be returned (pvalues=FALSE) or whether p-values should be returned (pvalues=TRUE).

Details

Matrix X should strictly comply with the following format. For an autosomal dataset is should contain the 3 genotype counts in order (AA,AB,BB). For an X-chromosomal dataset it should contain the 5 genotype counts in order (A,B,AA,AB,BB) where A and B are the male counts and AA, AB and BB the female counts.

This function was written for speed improvement, and should be much faster than looping over the rows of X with HWChisq. There is no error checking on the supplied data matrix.

Value

A vector of chi-square statistics

Author(s)

Jan Graffelman jan.graffelman@upc.edu

References

Graffelman, J. and Weir, B.S. (2016) Testing for Hardy-Weinberg equilibrium at 2 bi-allelic genetic markers on the X chromosome.

See Also

HWChisq

Examples

#
# Autosomal example
#
set.seed(123)
X <- HWData(1000,100)
monom <- (X[,2]==0 & X[,1]==0) | (X[,2]==0 & X[,3]==0)
X <- X[!monom,] # exclude monomorphics
Chisq.stats <- HWChisqStats(X,x.linked=FALSE,pvalues=FALSE)
Chisq.pvals <- HWChisqStats(X,x.linked=FALSE,pvalues=TRUE)
#
# X-chromosomal example
#
X <- HWData(1000,100,n.males=50,nA=75,x.linked=TRUE)
Chisq.stats <- HWChisqStats(X,x.linked=TRUE,pvalues=FALSE)
Chisq.pvals <- HWChisqStats(X,x.linked=TRUE,pvalues=TRUE)

HardyWeinberg documentation built on May 7, 2022, 5:05 p.m.