R/combine_est_props.R

Defines functions combine_est_props

Documented in combine_est_props

#' combine_est_props
#'
#' @param M_est a list containing matrices with deconvolution results
#' @param M a matrix of cell-type proportions
#'
#'
#'@import graphics
#'@import stats
#'
#'@export

combine_est_props = function(M_est,M){
  f1 = function(M_est1,M1){
    diff1 = sum(abs(M1-M_est1))
    diff2 = sum(abs(M1-matrix(c(M_est1[2,],M_est1[1,]), nrow = 2, byrow = T)))
    if (diff1<=diff2){
      return(M_est1)
    }
    else{
      return(matrix(c(M_est1[2,],M_est1[1,]), nrow = 2, byrow = T))
    }
  }
  M_est2 = lapply(M_est,f1,M)
  M_est2 = Reduce('+', M_est2)
  return(M_est2/length(M_est))
}
kpcoleman/SMC-Deconvolution documentation built on Dec. 21, 2021, 7:44 a.m.