get.nrmlzd.sample.covariance: Converts allele count and sample size data to a normalized...

View source: R/space.mix.MCMC.R

get.nrmlzd.sample.covarianceR Documentation

Converts allele count and sample size data to a normalized allele frequency covariance matrix

Description

This function generates a normalized covariance matrix from allele count and sample size data. The output can be used to run a SpaceMix analysis using the run.spacemix.analysis function. Running a SpaceMix analysis on this normalized covariance matrix (rather than on raw allele count and sample size data, or on sample allele frequency data) is recommended when there are many loci for which there are missing data, as its use results in pairwise, rather than listwise, deletion of missing data.

Usage

get.nrmlzd.sample.covariance(counts, sample.sizes)

Arguments

counts

A matrix of allele counts for which each row corresponds to a sample and each column corresponds to a locus. The ijth entry gives the number of times the counted allele at the jth locus is observed in the ith sample. Please see the vignette for a discussion of what the allele count data matrix should look like.

sample.sizes

A matrix of sample sizes for which each row corresponds to a sample and each column corresponds to a locus. The ijth entry gives the number of chromosomes genotyped in the ith sample at the jth locus.

Details

The normalization is used to standardize the variance in allele frequencies across loci, and is performed by dividing the allele frequencies at a locus by √{\bar{f}(1-\bar{f})} where \bar{f} is the average of the K sample allele frequencies, weighted by mean population size. That is,

\bar{f}_{\ell} = \frac{1}{∑_K S_{k,\ell}} ∑_K \hat{f}_{k,\ell} S_{k,\ell}

.

Value

This function returns a list with three components:

  • norm.sample.covariance - normalized sample allele frequency covariance matrix.

  • mean.sample.sizes - The vector of length K giving the mean sample size across loci in each of the K samples.

  • loci - The number of loci in the dataset.

Examples

# load example dataset
data(spacemix.example.dataset)

# generate normalized sample allele frequency covariance
norm.samp.cov <- get.nrmlzd.sample.covariance(counts = spacemix.example.dataset$allele.counts,
				sample.sizes = spacemix.example.dataset$sample.sizes)

# visualize results
image(norm.samp.cov$norm.sample.covariance,
		  main="Normalized sample allele frequency covariance",
		  xaxt='n',yaxt='n',xlab="Population",ylab="Population")
axis(side=1,c(0:29)/29,labels=c(paste(1:30)))
axis(side=2,c(0:29)/29,labels=c(paste(1:30)),las=2)

gbradburd/SpaceMix documentation built on Oct. 19, 2022, 12:43 p.m.