R/examine_residuals.R

Defines functions examine_residuals

examine_residuals <- function(ddCt, plot=FALSE){
  resids <- matrix(FALSE,nrow=nrow(ddCt), ncol=ncol(ddCt))
  for(i in 1:nrow(ddCt)){
    for(j in 1:ncol(ddCt)){
      ind <- which(colData(ddCt)$sampleType==colData(ddCt)$sampleType[j])
      resids[i,j] <- assay(ddCt,1)[i,j]-mean(assay(ddCt,1)[i,ind])
    }
  }

  if(plot){
    boxes <- list("both\nobserved"=resids[which(assay(ddCt, 2)=="none",arr.ind=TRUE)], 
                  "perturbation\nnon-detect"=resids[which(assay(ddCt, 2)=="perturbation",arr.ind=TRUE)], 
                  "control\nnon-detect"=resids[which(assay(ddCt, 2)=="control",arr.ind=TRUE)], 
                  "both\nnon-detects"=resids[which(assay(ddCt, 2)=="both",arr.ind=TRUE)])
    boxplot(boxes)
  }
  
  return(resids)
}
mccallm/crgnet documentation built on May 1, 2022, 2:21 a.m.