R/l2projection.R

l2projection <- function (X, loadings)
{
  if (!inherits(X, "matrix")) {
    if (inherits(X, "data.frame"))
      X <- as.matrix(X)
    else
      X <- matrix(X, ncol = 1)
  }
  if (!inherits(loadings, "matrix")) {
    if (inherits(loadings, "data.frame"))
      loadings <- as.matrix(loadings)
    else
      loadings <- matrix(loadings, ncol = 1)
  }

  solution <- new.env()
  solution$projPoints <- as.matrix(t(loadings %*% t(loadings) %*% t(X)))
  solution$scores <- as.matrix(X %*% loadings)

  row.names(solution$projPoints) <- rownames(X)
  
  solution <- as.list(solution)
  class(solution) <- "l2projection"
  solution
}

Try the pcaL1 package in your browser

Any scripts or data that you put into this service are public.

pcaL1 documentation built on Jan. 22, 2023, 1:55 a.m.