resid <- y - with(s,sweep(u[, 1:2], 2, d[1:2], FUN="*") %*% t(v[, 1:2]))
my_image(cor(resid[index,]), zlim = c(-1,1))
title("Residual Y - (PC1+PC2)")
Warning message in cor(resid[index, ]): “the standard deviation is zero”
We repeat the process, calculating the third matrix factorization and its residual:
$Y \approx d_{1,1}U_{1}V_{1}^{T} + d_{2,2}U_{2}V_{2}^{T} + d_{3,3}U_{3}V_{3}^{T}$
matrix <- (s$u[index,3, drop=FALSE]*s$d[3]) %*% t(s$v[,3, drop=FALSE])
my_image(matrix)
title("PC3")