resid <- y - with(s,sweep(u[, 1:3], 2, d[1:3], FUN="*") %*% t(v[, 1:3]))
my_image(cor(resid[index,]), zlim = c(-1,1))
title("Residual Y - (PC1+PC2+PC3)")
Warning message in cor(resid[index, ]): “the standard deviation is zero”
Finally we have one more step, calculating the fourth 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} + d_{4,4}U_{4}V_{4}^{T}$
matrix <- (s$u[index,4, drop=FALSE]*s$d[4]) %*% t(s$v[,4, drop=FALSE])
my_image(matrix)
title("PC4")