vectorGeno: Multiplication of a vector to a compressed SNP matrix

Description Usage Arguments Details Value Author(s) Examples

View source: R/haplogeno.R

Description

vectorGeno multiplies a vector from the left onto a compressed SNP matrix.

genoVector does it from the right.

Usage

1
2
vectorGeno(V, SNPxIndiv, do.centering=FALSE, decode=TRUE)
genoVector(SNPxIndiv, V, do.centering=FALSE)

Arguments

SNPxIndiv

a compressed SNP (genotype) vector or matrix obtained from genomicmatrix. Uncoded SNP matrix is also possible.

do.centering

not programmed yet.

decode

Logical. This option only applies when RFoptions()$genetics$snpcoding equals Shuffle256, Shuffle, Packed256, Packed, Multiply, or TwoBit. If TRUE the matrix is decoded and standard matrix multiplication performed afterwards. This is currently faster than to operate on the coded version (decode=FALSE), but takes (considerably) more memory.

V

numerical vector

Details

Let G be a (SNP\times Indiv) matrix. vectorGeno and genoVector return VG and GV, respectively.

Value

vector of length nrow(SNPxIndiv) and ncol(SNPxIndiv) for vectorGeno and genoVector, respectively.

Author(s)

\martin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
require(RandomFieldsUtils)
set.seed(0)

indiv <- 1 + sample(500, 1)
snps <- indiv * 2^sample(7, 1)
snps <- indiv * 100
M <- matrix(ncol=indiv, sample(0:2, indiv * snps, replace=TRUE))
print(system.time(CM <- genomicmatrix(M)))


## V %*% G
Vl <- runif(snps)
print(system.time(VM1 <- vectorGeno(Vl, CM))) # 1.2x slower than '%*%'
print(system.time(VM <- as.vector(Vl %*% M)))
stopifnot(all.equal(as.double(VM), as.double(VM1)))

## G %*% V
Vr <- runif(indiv)
print(system.time(MV1 <- genoVector(CM, Vr))) ## 3x faster than '%*%'
print(system.time(MV <- as.vector(M %*% Vr)))
stopifnot(all.equal(as.double(MV), as.double(MV1)))

miraculix documentation built on Sept. 22, 2021, 5:07 p.m.