Singular Value Decomposition
Mice data
library(BGLR)
data(mice)
W <- mice.X[1:7, 1:3]
SVD
UDV <- svd(W)
# left singular vectors
dim(UDV$u)
UDV$u
# singular values
length(UDV$d)
UDV$d
# right singular vectors
dim(UDV$v)
UDV$v
Examples
# Reconstruct W
W2 <- UDV$u %*% diag(UDV$d) %*% t(UDV$v)
W
W2
all.equal(c(W), c(W2), tol = 1e-04)
t(UDV$u) %*% UDV$u # U'U
t(UDV$v) %*% UDV$v # V'V
UDV$v %*% t(UDV$v) # VV'
UDV$u %*% t(UDV$u) # UU'
t(UDV$v) # V'
solve(UDV$v) # V^{-1}
solve(t(UDV$v)) # V'^{-1}
UDV$v # V
Marker effects
# Phenotype
y <- mice.pheno$Obesity.BMI[1:7]
# Standard OLS
solve(t(W) %*% W) %*% t(W) %*% y
# SVD-based OLS
UDV$v %*% solve(diag(UDV$d)) %*% t(UDV$u) %*% y