snp.pre: Pre- or post-multiply a snp.matrix object by a general matrix

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/structure.R

Description

These functions first standardize the input snp.matrix in the same way as does the function xxt. The standardized matrix is then either pre-multiplied (snp.pre) or post-multiplied (snp.post) by a general matrix. Allele frequencies for standardizing the input snp.matrix may be supplied but, otherwise, are calculated from the input snp.matrix

Usage

1
2
snp.pre(snps, mat, frequency=NULL)
snp.post(snps, mat, frequency=NULL)

Arguments

snps

An object of class "snp.matrix" or "X.snp.matrix"

mat

A general (numeric) matrix

frequency

A numeric vector giving the allele (relative) frequencies to be used for standardizing the columns of snps. If NULL, allele frequencies will be calculated internally. Frequencies should refer to the second (B) allele

Details

The two matrices must be conformant, as with standard matrix multiplication. The main use envisaged for these functions is the calculation of factor loadings in principal component analyses of large scale SNP data, and the application of these loadings to other datasets. The use of externally supplied allele frequencies for standardizing the input snp.matrix is required when applying loadings calculated from one dataset to a different dataset

Value

The resulting matrix product

Author(s)

David Clayton david.clayton@cimr.cam.ac.uk

See Also

xxt

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
##--
##-- Calculate first two principal components and their loading, and verify
##--	
# Make a snp.matrix with a small number of rows
data(testdata)
small <- Autosomes[1:20,]
# Calculate the X.X-transpose matrix
xx <- xxt(small, correct.for.missing=FALSE)
# Calculate the first two principal components and corresponding eigenvalues
eigvv <- eigen(xx, symmetric=TRUE)
pc <- eigvv$vectors[,1:2]
ev <- eigvv$values[1:2]
# Calculate loadings for first two principal components
Dinv <- diag(1/sqrt(ev))
loadings <- snp.pre(small,  Dinv %*% t(pc))
# Now apply loadings back to recalculate the principal components
pc.again <- snp.post(small, t(loadings) %*% Dinv)
print(cbind(pc, pc.again))

chopsticks documentation built on Nov. 8, 2020, 7:51 p.m.