R/getxpvorth.R

Defines functions getxpvorth

Documented in getxpvorth

#' Generates the orthogonal part for Xpv
#' @param q.k
#' vector with orthogonal distances for cross-validation set for segment k
#' @param X.k
#' matrix with local validation set for segment k
#' @param PRM
#' projecton matrix for orthogonalization of residuals
#'
#' @return
#' A matrix with orthogonal part for Xpv
#'
#' @importFrom stats runif
#'
#' @export
getxpvorth <- function(q.k, X.k, PRM) {

   nobj <- length(q.k)

   # compute the orthogonal component of Xpv
   Xpv.orth <- matrix(runif(nobj^2, -1, 1), nobj, nobj) %*% X.k           # - project Xk to a random vector
   Xpv.orth <- Xpv.orth %*% diag(1 / sqrt(colSums(Xpv.orth^2)))                # - normalize columns
   Xpv.orth <- Xpv.orth %*% PRM                                                # - orthogonalize to global component space
   Xpv.orth <- diag(sqrt(q.k / rowSums(Xpv.orth^2)), nobj, nobj) %*% Xpv.orth  # - rescale rows

   return (Xpv.orth)
}

Try the pcv package in your browser

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

pcv documentation built on Aug. 13, 2023, 1:07 a.m.