procuste.R 946 Bytes
Newer Older
Eric Coissac committed
1 2 3
#' @include internals.R
#'
#' @title ProcMod
4
#' @name procmod
Eric Coissac committed
5 6 7 8 9 10
#' @description blabla
#' @author Christelle Gonindard-Melodelima
#' @author Eric Coissac
#'
NULL

11 12 13 14
#' Rotate the \code{src} matrix to fit into the space of the \code{dest} matrix.
#'
#' The optimal rotation is computed according to the procruste methode.
#' Rotation is based on singular value decomposition (SVD).
15
#' No scaling and no centrering are done, before computing the SVD.
16 17 18 19 20 21 22
#'
#' @param src a numeric matrix to be rotated
#' @param dest a numeric matrix used as reference space
#'
#' @return a numeric matrix
#'
#' @examples
23 24 25 26
#' # Renerate a random matrix of size 10 x 15
#' m1 <- simulate_matrix(10, 15)
#' m2 <- simulate_matrix(10, 20)
#' mr <- protate(m1, m2)
27
#'
28 29
#' @author Christelle Gonindard-Melodelima
#' @author Eric Coissac
Eric Coissac committed
30
#' @export
31 32 33 34
protate <- function(src, dest) {
  YX <- crossprod(dest, src)
  svd.YX <- svd(YX)
  rot <- svd.YX$v %*% t(svd.YX$u)
Eric Coissac committed
35 36
  src %*% rot
}