Last active
July 23, 2018 07:35
-
-
Save jeffreypullin/1174d48247884ad94a70e9d16a477985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ruv) | |
library(rsvd) | |
fastRUVIII = function(Y, M, ctl, k=NULL, eta=NULL, average=FALSE, fullalpha=NULL){ | |
# Assumes good input | |
Y = RUV1(Y,eta,ctl) | |
m = nrow(Y) | |
Y0 = fast_residop(Y, M) | |
fullalpha = diag(rsvd(Y0)$d) %*% t(rsvd(Y0)$v) | |
alpha = fullalpha[1:k,,drop=FALSE] | |
ac = alpha[,ctl,drop=FALSE] | |
W = Y[,ctl]%*%t(ac)%*%solve(ac%*%t(ac)) | |
newY = Y - W%*%alpha | |
return(list(newY = newY, fullalpha=fullalpha)) | |
} | |
fast_residop <- function (A, B) { | |
return(A - B %*% solve(t(B) %*% B) %*% (t(B) %*% A)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment