R/PVE.R

Defines functions PVE

Documented in PVE

#' PVE computing
#'
#' @param data alist of original data of size $n x J_k$
#' @param H a list of feature matrix $p x J_k$
#' @param W a matrix of weights size $n x p$
#'
#' @return pve percentage of variance explained
#' @export
#'
PVE <- function(data, H, W){
  ind <- 1:length(data)
  pve <- 100*mean(sapply(ind, function(ss){
    Y <- data[[ss]]
    h <- H[[ss]]
    Ybar <- rowMeans(Y)
    pve_s <- 1-sum((Y-W%*%h)^2)/sum((Y-Ybar)^2)
    return(pve_s)
  }))
  return(pve)
}
CNRGH/pintmf documentation built on Feb. 23, 2022, 12:02 a.m.