Learn R Programming

miraculix (version 0.9.23)

vectorGeno: Multiplication of a vector to a compressed SNP matrix

Description

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

genoVector does it from the right.

Usage

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

Value

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

Details

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

Examples

Run this code
# NOT RUN {
 
# }
# NOT RUN {
<!-- %   library(miraculix); RFoptions(cores=1) -->
# }
# NOT RUN {
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)))
# }

Run the code above in your browser using DataLab