/
get_info.R
34 lines (34 loc) · 1.11 KB
/
get_info.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#' getRotationMatrix
#'
#' Extract the rotation matrix from \code{\link{dimRedResult}} objects derived from PCA and FastICA
#'
#' The data has to be pre-processed the same way as the method does, e.g.
#' centering and/or scaling.
#'
#' @param x of type \code{\link{dimRedResult}}
#' @return a matrix
#'
#' @examples
#' dat <- loadDataSet("Iris")
#'
#' pca <- embed(dat, "PCA")
#' rot_pca <- getRotationMatrix(pca)
#' scale(getData(dat), TRUE, FALSE) %*% rot_pca - getData(getDimRedData(pca))
#'
#'
#' if(requireNamespace("fastICA", quietly = TRUE)) {
#' ica <- embed(dat, "FastICA")
#' rot_ica <- getRotationMatrix(ica)
#' scale(getData(dat), TRUE, FALSE) %*% rot_ica - getData(getDimRedData(ica))
#' }
#'
#'
#' @family convenience functions
#' @export
getRotationMatrix <- function(x) {
if(!inherits(x, "dimRedResult")) stop("x must be of type 'dimRedResult'")
if(x@method == "PCA") return(environment(x@apply)$rot)
if(x@method == "PCA_L1") return(environment(x@apply)$rot)
if(x@method == "FastICA") return(environment(x@apply)$res$K %*% environment(x@apply)$res$W)
stop(paste("Not implemented for", x@method))
}