#' Check the contrasts built manually
#'
#' Check the contrasts built manually when using a GLM to analyse complex designs
#'
#' @param coefs vector of regression parameters from DESeq2 (\code{resultsNames(dds)}) or edgeR (\code{colnames(fit$design)})
#' @param contrasts a list of vectors defining contrasts to be tested
#' @param versionName versionName of the project
#' @return A matrix with the names of the contrasts and the linear combination to be tested
#' @author Hugo Varet
# created Oct 16th, 2014
# modified July 28th, 2015 (export the result in a txt file in the tables directory)
# modified August 11th, 2016 (rounded values for contrasts with 1/3...)
checkContrasts <- function(coefs,contrasts,versionName="."){
out <- matrix(nrow=length(contrasts),ncol=1,dimnames=list(paste0(names(contrasts),":"),""))
for (i in 1:length(contrasts)){
contrast <- round(contrasts[[i]],2)
contrast <- paste(ifelse(contrast>0,"+ ",""),contrast,sep="")
contrast <- gsub("( 1)|(1)","",contrast)
out[i,] <- paste(contrast[contrast!=0],coefs[contrast!=0],collapse=" ",sep=" ")
}
sink(paste0("tables/",versionName,"-checkContrasts.txt"))
cat("Coefficients of the model:\n")
print(coefs)
cat("Contrasts defined by the user:\n")
print(contrasts)
cat("Linear combinations tested:\n")
print(out)
sink()
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.