You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry to be lazy and not submit a PR -- I added some data checks and modified the code to take a model matrix Z rather than vector z. I realize you can submit a matrix (minus the intercept) to z, but I think requiring a model matrix explicitly will be more familiar to most users.
OG <- function(X, Z, k = max(2, round(NCOL(X)/10)), rescale = FALSE) {
## Data checks
if (!is.matrix(X) || !is.numeric(X)) stop("X must be a numeric matrix")
if (!is.matrix(Z) || !is.numeric(Z)) stop("Z must be a numeric matrix")
if (NROW(X) != NROW(Z)) stop("X and Z must have the same rows")
if (k > NCOL(X)) stop("'k' must be <= ncol(X).")
stopifnot(is.numeric(k))
if (length(k) > 1) {
k <- k[1]
warning("length(k) > 1, only using first element.")
}
## Perform algorithm
if (rescale) X <- scale(X)
SVD <- svd(X, nu = k, nv = k)
LM <- lm(SVD$u %*% diag(SVD$d[1:k]) ~ -1 + Z)
S <- SVD$u %*% diag(SVD$d[1:k]) - Z %*% LM$coef
list(S = S, U = t(SVD$v))
}
Also, will this be submitted to CRAN? Happy to help work on getting it ready for submission.
The text was updated successfully, but these errors were encountered:
Sorry to be lazy and not submit a PR -- I added some data checks and modified the code to take a model matrix
Z
rather than vectorz
. I realize you can submit a matrix (minus the intercept) toz
, but I think requiring a model matrix explicitly will be more familiar to most users.Also, will this be submitted to CRAN? Happy to help work on getting it ready for submission.
The text was updated successfully, but these errors were encountered: