Skip to content

Instantly share code, notes, and snippets.

@jeffreypullin
Last active July 23, 2018 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreypullin/1174d48247884ad94a70e9d16a477985 to your computer and use it in GitHub Desktop.
Save jeffreypullin/1174d48247884ad94a70e9d16a477985 to your computer and use it in GitHub Desktop.
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