build_kernel: Relationship Matrix

Description Usage Arguments Value Examples

View source: R/kernel_algorithms.R

Description

build_kernel generates kinship matrices from raw feature matrices

Usage

1
build_kernel(M, lambda = 0.01, algorithm = "RadenII", feat_weights = NULL)

Arguments

M

A matrix. Genotype names are stored in rows whereas feature names are stored in columns.

lambda

Numeric vector (scalar) to add to diagonal of the relationship matrix. This avoids numerical issues (singularities) when inverting the output.

algorithm

Character vector (scalar) to generate the relationship matrix.

feat_weights

Numeric vector specifying the call weights each feature has in the relationship matrix.

Value

If algorithm is RadenII and feat_weights is set to NULL, features will be centered and scaled to unit variance; otherwise features will be centered and divided by √{w_{i} * σ^{2}_{i}}, where w_{i} is the weight of the ith feature and m_{i} is the ith feature. A typical use case for w would be a vector of heritabilities for each feature.

If algorithm is Zhang, features will be centered and scaled by the sum of their variances.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 # Load a matrix with SNP genotypes encoded as numeric values
 data(mice, package = "BGLR")
 mice.snp <- mice.X[1:200, ]

 # Generate a vector of feature weights.
 set.seed(90402)
 weights <- runif(n = ncol(mice.snp), min = 0, max = 1)

 # Compute a SNP-based relationship matrix based on RadenII.
 radenII <- build_kernel(mice.snp, algorithm = "RadenII")
 dim(radenII)
 summary(c(radenII))

 # Compute a SNP-based relationship matrix based on RadenII with weighted
 # features.
 weighted_radenII <- build_kernel(mice.snp, algorithm = "RadenII",
                                  feat_weights = weights)

 #  Compute a SNP-based relationship matrix based on Zhang.
 zhang <- build_kernel(mice.snp, algorithm = "Zhang")
 all.equal(radenII, zhang)

mwesthues/sspredr documentation built on May 23, 2019, 10:56 a.m.