createTable              package:BGcom              R Documentation

_F_u_n_c_t_i_o_n _t_o _c_r_e_a_t_e _a_n _o_u_t_p_u_t _t_a_b_l_e

_D_e_s_c_r_i_p_t_i_o_n:

     This function creates an output table with the results from the
     Bayesian model in a csv format.

_U_s_a_g_e:

     createTable(dir,output.ratio,output.bay,name)
             

_A_r_g_u_m_e_n_t_s:

     dir: directory for storing the table

output.ratio: The output object from the Frequentist model (ratio
          function)

output.bay: The output object from the Bayesian model (baymod function)

    name: Name of the .csv file where the output is stored

_D_e_t_a_i_l_s:

     To select a list of interesting features from the Bayesian model
     we suggest two decision rules in the paper: 1. the maximum of
     Median(R(q)) only for the subset of credibility intervals which do
     not include 1 2. the largest threshold q for which the ratio R(q)
     il bigger than 2

     The first one is pointing out the strongest deviation from
     independence, whilst the second is the largest threshold where the
     number of genes called in common at least doubles the number of
     genes in common under independence.

_V_a_l_u_e:

     An object of the class list with two recommended decision rules: 

     max: the results of the Rmax statistic

   rule2: the results using the rule R larger than 2 (see details)

_A_u_t_h_o_r(_s):

     Marta Blangiardo

_R_e_f_e_r_e_n_c_e_s:

     1. M.Blangiardo and S.Richardson Statistical tools for
     synthesizing lists of differentially expressed features in related
     experiments , Genome Biology, 8, R54

_E_x_a_m_p_l_e_s:

     data = simulation(n=500,GammaA=1,GammaB=1,r1=0.5,r2=0.8,DEfirst=300,DEsecond=200,DEcommon=100)
     T<- ratio(data$Pval,interval=0.01,dir="D:/",name="CompData1Data2",pvalue=TRUE)
     BayesianModel<- baymod(data$Pval,repl=100,output.ratio=T,dir="D:/")
     output.table <- createTable(dir="D:/",output.ratio=T,output.bay=BayesianModel,name="OutputTable")
      
     ## The function is currently defined as
     function(dir,output.ratio,output.bay,name){
     if(output.ratio$pvalue==TRUE){
     matrix.results =  cbind(output.ratio$q,round(output.bay,3),output.ratio$DECommon,output.ratio$DE)
     lists = dim(output.ratio$DE)[2]
     namesDE = paste("O",seq(1,lists),rep("+",lists))
     names.matrix = c("q","LowCI","MedCI","HighCI","O11",namesDE)
     dimnames(matrix.results)[[2]]<-names.matrix
     }
     if(output.ratio$pvalue==FALSE){
     matrix.results =  cbind(1-output.ratio$q,round(output.bay,3),output.ratio$DECommon,output.ratio$DE)
     lists = dim(output.ratio$DE)[2]
     namesDE = paste("O",seq(1,lists),rep("+",lists))
     names.matrix = c("q","LowCI","MedCI","HighCI","O11",namesDE)
     dimnames(matrix.results)[[2]]<-names.matrix
     }

     #Decision rules:
     #1) Maximum for CI not including 1
     max.R = max(matrix.results[round(round(matrix.results[,2],2),1)>1,3])
     maximum = matrix.results[matrix.results[,3]==max.R,]

     if(length(matrix.results[matrix.results[round(matrix.results[,2],2)>1,3]>=2,1])>0){
     #2) Rule 2
     R2 = max(matrix.results[round(round(matrix.results[,3],2),3)>=2 & round(round(matrix.results[,2],2),1)>1 ,1])
     rule2 = matrix.results[matrix.results[,1]==R2,]

     setwd(dir)
     write.csv(matrix.results,paste(name,".csv"),row.names=FALSE)
     return(list(maximum=maximum,rule2=rule2))
             }

     if(length(matrix.results[matrix.results[round(matrix.results[,2],2)>1,3]>=2,1])==0){
     #2) Rule 2
     setwd(dir)
     write.csv(matrix.results,paste(name,".csv"),row.names=FALSE)
     return(maximum=maximum)
             }

     }

