Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 61.57 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #####################################################################
  2. # Created by Scott Chamberlain
  3. # Ecology and Evolutionary Biology Dept., Rice University
  4. # Houston, TX 77005, USA
  5. # myrmecocystus@gmail.com
  6. #####################################################################
  7.  
  8. # Function to split confidence intervals, this function is required in the below functions
  9. CI_split <- function(a){
  10.         dd<-c(gsub("\\(","",unlist(strsplit(a[5],","))[1]),gsub("\\)","",unlist(strsplit(a[5],","))[2]))
  11.         b22<-a[2:8]
  12.         b222<-b22[-4]
  13.         b222<-append(b222,dd,after=3)
  14.         b222
  15. }
  16.  
  17. ### Functions to run meta-analysis in Phylometa
  18. # 1 group in the moderator variable
  19. maketables_1group <- function(output){ #DONE IF/ELSE REFORMATTING
  20.  
  21.         #Table 1, traditional
  22.         #a1<-unlist(strsplit(output[6]," +"))[-1] #Table header
  23.         a2 <- unlist(strsplit(output[8],"  +"))[-1] #Data row 1, between groups, fixed effects
  24.         a3 <- unlist(strsplit(output[9],"  +"))[-1] #Data row 2, within groups
  25.         a4 <- if(length(unlist(strsplit(output[10]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[10]," +"))[-1][1],unlist(strsplit(output[10]," +"))[-1][2],unlist(strsplit(output[10]," +"))[-1][3]),unlist(strsplit(output[10]," +"))[-1][4:6])} else
  26.                         if(length(unlist(strsplit(output[10]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[10]," +"))[-1][1],unlist(strsplit(output[10]," +"))[-1][2],unlist(strsplit(output[10]," +"))[-1][3]),unlist(strsplit(output[10]," +"))[-1][4:8])} else
  27.                                                 end
  28.         a7 <- unlist(strsplit(output[11]," +"))[-1] #Data row 6, Total
  29.         a8 <- unlist(strsplit(output[14],"  +"))[-1] #Data row 7, between groups, random effects
  30.         rownaames<-c(a2[1],a3[1],a4[1],a7[1],a8[1]) #make vector of first column names
  31.         numbers<-t(data.frame(as.numeric(a2[2:4]),as.numeric(a3[2:4]),as.numeric(a4[2:4]),append(as.numeric(a7[2]),c(-9999,-9999),after=1),as.numeric(a8[2:4]))) #make data frame of numbers
  32.         numbers<-data.frame(numbers,rownaames) #Make data frame of row names and numbers
  33.         colnames(numbers)<-c("Q","df","P","Source") #Assign column names
  34.         summaryfitstats_table1_trad<-data.frame(Source=numbers$Source,Q=numbers$Q,df=numbers$df,P=numbers$P) #Reorder columns
  35.         #summaryfitstats_table1_trad #See table
  36.  
  37.         #Table 2, traditional
  38.         #b1<-unlist(strsplit(output[23]," +"))[-1] #Table header
  39.         b2 <- if(length(unlist(strsplit(output[27]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[27]," +"))[-1])[1],(unlist(strsplit(output[27]," +"))[-1])[2]),unlist(strsplit(output[27]," +"))[-1][3:9])} else
  40.                                 if(str_detect(unlist(strsplit(output[27]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[27],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[27]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[27]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[27],"  +"))[-1][6:7])} else
  41.                                                 end
  42.         b3 <- if(length(unlist(strsplit(output[28]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[28]," +"))[-1])[1],(unlist(strsplit(output[28]," +"))[-1])[2]),unlist(strsplit(output[28]," +"))[-1][3:9])} else
  43.                                 if(str_detect(unlist(strsplit(output[28]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[28],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[28]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[28]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[28],"  +"))[-1][6:7])} else
  44.                                                 end
  45.         b6 <- if(length(unlist(strsplit(output[32]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[32]," +"))[-1])[1],(unlist(strsplit(output[32]," +"))[-1])[2]),unlist(strsplit(output[32]," +"))[-1][3:9])} else
  46.                                 if(str_detect(unlist(strsplit(output[32]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[32],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[32]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[32]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[32],"  +"))[-1][6:7])} else
  47.                                                 end
  48.         b7 <- if(length(unlist(strsplit(output[33]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[33]," +"))[-1])[1],(unlist(strsplit(output[33]," +"))[-1])[2]),unlist(strsplit(output[33]," +"))[-1][3:9])} else
  49.                                 if(str_detect(unlist(strsplit(output[33]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[33],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[33]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[33]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[33],"  +"))[-1][6:7])} else
  50.                                                 end
  51.         rownaames1<-c(b2[1],b3[1],b6[1],b7[1]) #make vector of first column names
  52.         b22<-CI_split(b2) #Split confidence interval numbers apart and reinsert to vector of data
  53.         b33<-CI_split(b3)
  54.         b66<-CI_split(b6)
  55.         b77<-CI_split(b7)
  56.         numbers1<-t(data.frame(as.numeric(b22),as.numeric(b33),as.numeric(b66),as.numeric(b77)))  #make data frame of numbers
  57.         numbers1<-data.frame(numbers1,rownaames1) #Make data frame of row names and numbers
  58.         colnames(numbers1)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  59.         summaryeffsizes_table2_trad<-data.frame(Group=numbers1[,9],k=numbers1[,1],effsize=numbers1[,2],var=numbers1[,3],CI_low=numbers1[,4],CI_high=numbers1[,5],Z=numbers1[,6],df=numbers1[,7],P=numbers1[,8]) #Reorder columns
  60.         #summaryeffsizes_table2_trad #See table
  61.  
  62.         #Table 1, phylogenetic
  63.         #d1 <- unlist(strsplit(output[47]," +"))[-1] #Table header
  64.         d2 <- unlist(strsplit(output[49],"  +"))[-1] #Data row 1, between groups, fixed effects
  65.         d3 <- unlist(strsplit(output[50],"  +"))[-1] #Data row 2, within groups
  66.         d4 <- if(length(unlist(strsplit(output[51]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[51]," +"))[-1][1],unlist(strsplit(output[51]," +"))[-1][2],unlist(strsplit(output[51]," +"))[-1][3]),unlist(strsplit(output[51]," +"))[-1][4:6])} else
  67.                         if(length(unlist(strsplit(output[51]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[51]," +"))[-1][1],unlist(strsplit(output[51]," +"))[-1][2],unlist(strsplit(output[51]," +"))[-1][3]),unlist(strsplit(output[51]," +"))[-1][4:8])} else
  68.                                                 end
  69.         d7 <- unlist(strsplit(output[52]," +"))[-1] #Data row 6, Total
  70.         d8 <- unlist(strsplit(output[55],"  +"))[-1] #Data row 7, between groups, random effects
  71.         rownaames2<-c(d2[1],d3[1],d4[1],d7[1],d8[1]) #make vector of first column names
  72.         numbers2<-t(data.frame(append(as.numeric(d2[2:4]),c(-9999,-9999),after=3),as.numeric(d3[2:6]),as.numeric(d4[2:6]),append(as.numeric(d7[2]),c(-9999,-9999,-9999,-9999),after=1),append(as.numeric(d8[2:4]),c(-9999,-9999),after=3))) #make data frame of numbers
  73.         numbers2<-data.frame(numbers2,rownaames2) #Make data frame of row names and numbers
  74.         colnames(numbers2)<-c("Q","df","P","df_polytadj","P_polytadj","Source") #Assign column names
  75.         summaryfitstats_table1_phyl<-data.frame(Source=numbers2[,6],Q=numbers2[,1],df=numbers2[,2],P=numbers2[,3],df_polytadj=numbers2[,4],P_polytadj=numbers2[,5]) #Reorder columns
  76.         #summaryfitstats_table1_phyl #See table
  77.  
  78.         #Table 2, phylogenetic
  79.         #e1<-unlist(strsplit(output[64]," +"))[-1] #Table header
  80.         e2 <- if(length(unlist(strsplit(output[68]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[68]," +"))[-1])[1],(unlist(strsplit(output[68]," +"))[-1])[2]),unlist(strsplit(output[68]," +"))[-1][3:9])} else
  81.                                 if(str_detect(unlist(strsplit(output[68]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[68],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[68]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[68]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[68],"  +"))[-1][6:7])} else
  82.                                                 end
  83.         e3 <- if(length(unlist(strsplit(output[69]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[69]," +"))[-1])[1],(unlist(strsplit(output[69]," +"))[-1])[2]),unlist(strsplit(output[69]," +"))[-1][3:9])} else
  84.                                 if(str_detect(unlist(strsplit(output[69]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[69],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[69]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[69]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[69],"  +"))[-1][6:7])} else
  85.                                                 end
  86.         e6 <- if(length(unlist(strsplit(output[73]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[73]," +"))[-1])[1],(unlist(strsplit(output[73]," +"))[-1])[2]),unlist(strsplit(output[73]," +"))[-1][3:9])} else
  87.                                 if(str_detect(unlist(strsplit(output[73]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[73],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[73]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[73]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[73],"  +"))[-1][6:7])} else
  88.                                                 end
  89.         e7 <- if(length(unlist(strsplit(output[74]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[74]," +"))[-1])[1],(unlist(strsplit(output[74]," +"))[-1])[2]),unlist(strsplit(output[74]," +"))[-1][3:9])} else
  90.                                 if(str_detect(unlist(strsplit(output[74]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[74],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[74]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[74]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[74],"  +"))[-1][6:7])} else
  91.                                                 end
  92.         rownaames3<-c(e2[1],e3[1],e6[1],e7[1]) #make vector of first column names
  93.         e22<-CI_split(e2) #Split confidence interval numbers apart and reinsert to vector of data
  94.         e33<-CI_split(e3)
  95.         e66<-CI_split(e6)
  96.         e77<-CI_split(e7)
  97.         numbers3<-t(data.frame(as.numeric(e22),as.numeric(e33),as.numeric(e66),as.numeric(e77)))  #make data frame of numbers
  98.         numbers3<-data.frame(numbers3,rownaames3) #Make data frame of row names and numbers
  99.         colnames(numbers3)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  100.         summaryeffsizes_table2_phyl<-data.frame(Group=numbers3[,9],k=numbers3[,1],effsize=numbers3[,2],var=numbers3[,3],CI_low=numbers3[,4],CI_high=numbers3[,5],Z=numbers3[,6],df=numbers3[,7],P=numbers3[,8]) #Reorder columns
  101.         #summaryeffsizes_table2_phyl #See table
  102.  
  103.         ### Model fit table, AIC
  104.         f1<-unlist(strsplit(output[89]," +"))[-1] #Table header
  105.         f2<-unlist(strsplit(output[90]," +"))[-1] #Data row 1, fixed effects, all studies
  106.         rownaames4<-c(f1[1],f2[1]) #make vector of first column names
  107.         numbers4<-t(data.frame(as.numeric(f1[2:3]),as.numeric(f2[2:3])))  #make data frame of numbers
  108.         numbers4<-data.frame(numbers4,rownaames4) #Make data frame of row names and numbers
  109.         colnames(numbers4)<-c("AIC_fixed","AIC_random","Analysis") #Assign column names
  110.         summarymodelfits_AIC_table<-data.frame(Analysis=numbers4[,3],AIC_fixed=numbers4[,1],AIC_random=numbers4[,2]) #Reorder columns
  111.         #summarymodelfits_table #See table
  112.  
  113.         ### Model fit table, -2(likelihood)
  114.         g1 <- unlist(strsplit(output[101]," +"))[-1] #Traditional AIC data
  115.         g2 <- unlist(strsplit(output[102]," +"))[-1] #Phylogenetically controlled AIC data
  116.         rownaames5 <- c(g1[1],g2[1]) #make vector of first column names
  117.         numbers5 <- t(data.frame(as.numeric(g1[2:3]), as.numeric(g2[2:3])))  #make data frame of numbers
  118.         numbers5 <- data.frame(numbers5, rownaames5) #Make data frame of row names and numbers
  119.         colnames(numbers5) <- c("twoln_fixed", "twoln_random", "Analysis") #Assign column names
  120.         summarymodelfits_twoln_table <- data.frame(Analysis = numbers5[,3], twoln_fixed = numbers5[,1], twoln_random = numbers5[,2]) #Reorder columns
  121.         #summarymodelfits_twoln_table #See table
  122.  
  123.         #Make list of tables
  124.         tables <- list(summaryfitstats_table1_trad, summaryeffsizes_table2_trad, summaryfitstats_table1_phyl, summaryeffsizes_table2_phyl, summarymodelfits_AIC_table, summarymodelfits_twoln_table)
  125.         tables
  126. }
  127.  
  128. # 2 groups in the moderator variable
  129. maketables_2group <- function(output){ #DONE IF/ELSE REFORMATTING
  130. #Table 1, Traditional meta-analysis
  131. a1 <- unlist(strsplit(output[6]," +"))[-1] #Table header
  132. a2 <- unlist(strsplit(output[8],"  +"))[-1] #Data row 1, between groups, fixed effects
  133. a3 <- unlist(strsplit(output[9],"  +"))[-1] #Data row 2, within groups
  134. a4 <- if(length(unlist(strsplit(output[10]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[10]," +"))[-1][1],unlist(strsplit(output[10]," +"))[-1][2],unlist(strsplit(output[10]," +"))[-1][3]),unlist(strsplit(output[10]," +"))[-1][4:6])} else
  135.                         if(length(unlist(strsplit(output[10]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[10]," +"))[-1][1],unlist(strsplit(output[10]," +"))[-1][2],unlist(strsplit(output[10]," +"))[-1][3]),unlist(strsplit(output[10]," +"))[-1][4:8])} else
  136.                                                 end
  137. a5 <- if(length(unlist(strsplit(output[11]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[11]," +"))[-1][1],unlist(strsplit(output[11]," +"))[-1][2],unlist(strsplit(output[11]," +"))[-1][3]),unlist(strsplit(output[11]," +"))[-1][4:6])} else
  138.                         if(length(unlist(strsplit(output[11]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[11]," +"))[-1][1],unlist(strsplit(output[11]," +"))[-1][2],unlist(strsplit(output[11]," +"))[-1][3]),unlist(strsplit(output[11]," +"))[-1][4:8])} else
  139.                                                 end
  140. a7 <- unlist(strsplit(output[12]," +"))[-1] #Data row 6, Total
  141. a8 <- unlist(strsplit(output[15]," +"))[-1] #Data row 7, between groups, random effects
  142. rownaames<-c(a2[1],a3[1],a4[1],a5[1],a7[1],a8[1]) #make vector of first column names
  143. numbers<-t(data.frame(as.numeric(a2[2:4]),as.numeric(a3[2:4]),as.numeric(a4[2:4]),as.numeric(a5[2:4]),append(as.numeric(a7[2]),c(-9999,-9999),after=1),as.numeric(a8[2:4]))) #make data frame of numbers
  144. numbers<-data.frame(numbers,rownaames) #Make data frame of row names and numbers
  145. colnames(numbers)<-c("Q","df","P","Source") #Assign column names
  146. summaryfitstats_table1_trad<-data.frame(Source=numbers$Source,Q=numbers$Q,df=numbers$df,P=numbers$P) #Reorder columns
  147. #summaryfitstats_table1_trad #See table
  148.  
  149. #Table 2, Traditional meta-analysis
  150. #b1<-unlist(strsplit(output[24]," +"))[-1] #Table header
  151.         b2 <- if(length(unlist(strsplit(output[28]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[28]," +"))[-1])[1],(unlist(strsplit(output[28]," +"))[-1])[2]),unlist(strsplit(output[28]," +"))[-1][3:9])} else
  152.                                 if(str_detect(unlist(strsplit(output[28]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[28],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[28]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[28]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[28],"  +"))[-1][6:7])} else
  153.                                                 end
  154.         b3 <- if(length(unlist(strsplit(output[29]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[29]," +"))[-1])[1],(unlist(strsplit(output[29]," +"))[-1])[2]),unlist(strsplit(output[29]," +"))[-1][3:9])} else
  155.                                 if(str_detect(unlist(strsplit(output[29]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[29],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[29]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[29]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[29],"  +"))[-1][6:7])} else
  156.                                                 end
  157.         b4 <- if(length(unlist(strsplit(output[30]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[30]," +"))[-1])[1],(unlist(strsplit(output[30]," +"))[-1])[2]),unlist(strsplit(output[30]," +"))[-1][3:9])} else
  158.                                 if(str_detect(unlist(strsplit(output[30]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[30],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[30]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[30]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[30],"  +"))[-1][6:7])} else
  159.                                                 end
  160.         b6 <- if(length(unlist(strsplit(output[34]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[34]," +"))[-1])[1],(unlist(strsplit(output[34]," +"))[-1])[2]),unlist(strsplit(output[34]," +"))[-1][3:9])} else
  161.                                 if(str_detect(unlist(strsplit(output[34]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[34],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[34]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[34]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[34],"  +"))[-1][6:7])} else
  162.                                                 end
  163.         b7 <- if(length(unlist(strsplit(output[35]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[35]," +"))[-1])[1],(unlist(strsplit(output[35]," +"))[-1])[2]),unlist(strsplit(output[35]," +"))[-1][3:9])} else
  164.                                 if(str_detect(unlist(strsplit(output[35]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[35],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[35]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[35]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[35],"  +"))[-1][6:7])} else
  165.                                                 end
  166.         b8 <- if(length(unlist(strsplit(output[36]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[36]," +"))[-1])[1],(unlist(strsplit(output[36]," +"))[-1])[2]),unlist(strsplit(output[36]," +"))[-1][3:9])} else
  167.                                 if(str_detect(unlist(strsplit(output[36]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[36],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[36]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[36]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[36],"  +"))[-1][6:7])} else
  168.                                                 end
  169. rownaames1<-c(b2[1],b3[1],b4[1],b6[1],b7[1],b8[1]) #make vector of first column names
  170. b22<-CI_split(b2) #Split confidence interval numbers apart and reinsert to vector of data
  171. b33<-CI_split(b3)
  172. b44<-CI_split(b4)
  173. b66<-CI_split(b6)
  174. b77<-CI_split(b7)
  175. b88<-CI_split(b8)
  176. numbers1<-t(data.frame(as.numeric(b22),as.numeric(b33),as.numeric(b44),as.numeric(b66),as.numeric(b77),as.numeric(b88)))  #make data frame of numbers
  177. numbers1<-data.frame(numbers1,rownaames1) #Make data frame of row names and numbers
  178. colnames(numbers1)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  179. summaryeffsizes_table2_trad<-data.frame(Group=numbers1[,9],k=numbers1[,1],effsize=numbers1[,2],var=numbers1[,3],CI_low=numbers1[,4],CI_high=numbers1[,5],Z=numbers1[,6],df=numbers1[,7],P=numbers1[,8]) #Reorder columns
  180. #summaryeffsizes_table2_trad #See table
  181.  
  182. ###Phylogenetic meta-analysis
  183. #Table 1, Phylogenetic meta-analysis
  184. d1<-unlist(strsplit(output[50]," +"))[-1] #Table header
  185. d2<-unlist(strsplit(output[52],"  +"))[-1] #Data row 1, between groups, fixed effects
  186. d3<-unlist(strsplit(output[53],"  +"))[-1] #Data row 2, within groups
  187. d4 <- if(length(unlist(strsplit(output[54]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[54]," +"))[-1][1],unlist(strsplit(output[54]," +"))[-1][2],unlist(strsplit(output[54]," +"))[-1][3]),unlist(strsplit(output[54]," +"))[-1][4:6])} else
  188.                         if(length(unlist(strsplit(output[54]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[54]," +"))[-1][1],unlist(strsplit(output[54]," +"))[-1][2],unlist(strsplit(output[54]," +"))[-1][3]),unlist(strsplit(output[54]," +"))[-1][4:8])} else
  189.                                                 end
  190. d5 <- if(length(unlist(strsplit(output[55]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[55]," +"))[-1][1],unlist(strsplit(output[55]," +"))[-1][2],unlist(strsplit(output[55]," +"))[-1][3]),unlist(strsplit(output[55]," +"))[-1][4:6])} else
  191.                         if(length(unlist(strsplit(output[55]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[55]," +"))[-1][1],unlist(strsplit(output[55]," +"))[-1][2],unlist(strsplit(output[55]," +"))[-1][3]),unlist(strsplit(output[55]," +"))[-1][4:8])} else
  192.                                                 end
  193. d7<-unlist(strsplit(output[56]," +"))[-1] #Data row 6, Total
  194. d8<-unlist(strsplit(output[59],"  +"))[-1] #Data row 7, between groups, random effects
  195. rownaames2<-c(d2[1],d3[1],d4[1],d5[1],d7[1],d8[1]) #make vector of first column names
  196. numbers2<-t(data.frame(append(as.numeric(d2[2:4]),c(-9999,-9999),after=3),as.numeric(d3[2:6]),as.numeric(d4[2:6]),as.numeric(d5[2:6]),append(as.numeric(d7[2]),c(-9999,-9999,-9999,-9999),after=1),append(as.numeric(d8[2:4]),c(-9999,-9999),after=3))) #make data frame of numbers
  197. numbers2<-data.frame(numbers2,rownaames2) #Make data frame of row names and numbers
  198. colnames(numbers2)<-c("Q","df","P","df_polytadj","P_polytadj","Source") #Assign column names
  199. summaryfitstats_table1_phyl<-data.frame(Source=numbers2[,6],Q=numbers2[,1],df=numbers2[,2],P=numbers2[,3],df_polytadj=numbers2[,4],P_polytadj=numbers2[,5]) #Reorder columns
  200. #summaryfitstats_table1_phyl #See table
  201.  
  202. #Table 2, Phylogenetic meta-analysis
  203. #e1<-unlist(strsplit(output[68]," +"))[-1] #Table header
  204.         e2 <- if(length(unlist(strsplit(output[72]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[72]," +"))[-1])[1],(unlist(strsplit(output[72]," +"))[-1])[2]),unlist(strsplit(output[72]," +"))[-1][3:9])} else
  205.                                 if(str_detect(unlist(strsplit(output[72]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[72],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[72]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[72]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[72],"  +"))[-1][6:7])} else
  206.                                                 end
  207.         e3 <- if(length(unlist(strsplit(output[73]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[73]," +"))[-1])[1],(unlist(strsplit(output[73]," +"))[-1])[2]),unlist(strsplit(output[73]," +"))[-1][3:9])} else
  208.                                 if(str_detect(unlist(strsplit(output[73]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[73],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[73]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[73]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[73],"  +"))[-1][6:7])} else
  209.                                                 end
  210.         e4 <- if(length(unlist(strsplit(output[74]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[74]," +"))[-1])[1],(unlist(strsplit(output[74]," +"))[-1])[2]),unlist(strsplit(output[74]," +"))[-1][3:9])} else
  211.                                 if(str_detect(unlist(strsplit(output[74]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[74],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[74]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[74]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[74],"  +"))[-1][6:7])} else
  212.                                                 end
  213.         e6 <- if(length(unlist(strsplit(output[78]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[78]," +"))[-1])[1],(unlist(strsplit(output[78]," +"))[-1])[2]),unlist(strsplit(output[78]," +"))[-1][3:9])} else
  214.                                 if(str_detect(unlist(strsplit(output[78]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[78],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[78]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[78]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[78],"  +"))[-1][6:7])} else
  215.                                                 end
  216.         e7 <- if(length(unlist(strsplit(output[79]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[79]," +"))[-1])[1],(unlist(strsplit(output[79]," +"))[-1])[2]),unlist(strsplit(output[79]," +"))[-1][3:9])} else
  217.                                 if(str_detect(unlist(strsplit(output[79]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[79],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[79]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[79]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[79],"  +"))[-1][6:7])} else
  218.                                                 end
  219.         e8 <- if(length(unlist(strsplit(output[80]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[80]," +"))[-1])[1],(unlist(strsplit(output[80]," +"))[-1])[2]),unlist(strsplit(output[80]," +"))[-1][3:9])} else
  220.                                 if(str_detect(unlist(strsplit(output[80]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[80],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[80]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[80]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[80],"  +"))[-1][6:7])} else
  221.                                                 end
  222. rownaames3<-c(e2[1],e3[1],e4[1],e6[1],e7[1],e8[1]) #make vector of first column names
  223. e22<-CI_split(e2) #Split confidence interval numbers apart and reinsert to vector of data
  224. e33<-CI_split(e3)
  225. e44<-CI_split(e4)
  226. e66<-CI_split(e6)
  227. e77<-CI_split(e7)
  228. e88<-CI_split(e8)
  229. numbers3<-t(data.frame(as.numeric(e22),as.numeric(e33),as.numeric(e44),as.numeric(e66),as.numeric(e77),as.numeric(e88)))  #make data frame of numbers
  230. numbers3<-data.frame(numbers3,rownaames3) #Make data frame of row names and numbers
  231. colnames(numbers3)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  232. summaryeffsizes_table2_phyl<-data.frame(Group=numbers3[,9],k=numbers3[,1],effsize=numbers3[,2],var=numbers3[,3],CI_low=numbers3[,4],CI_high=numbers3[,5],Z=numbers3[,6],df=numbers3[,7],P=numbers3[,8]) #Reorder columns
  233. #summaryeffsizes_table2_phyl #See table
  234.  
  235. ### Model fit table, AIC
  236. f1<-unlist(strsplit(output[95]," +"))[-1] #Traditional AIC data
  237. f2<-unlist(strsplit(output[96]," +"))[-1] #Phylogenetically controlled AIC data
  238. rownaames4<-c(f1[1],f2[1]) #make vector of first column names
  239. numbers4<-t(data.frame(as.numeric(f1[2:3]),as.numeric(f2[2:3])))  #make data frame of numbers
  240. numbers4<-data.frame(numbers4,rownaames4) #Make data frame of row names and numbers
  241. colnames(numbers4)<-c("AIC_fixed","AIC_random","Analysis") #Assign column names
  242. summarymodelfits_AIC_table<-data.frame(Analysis=numbers4[,3],AIC_fixed=numbers4[,1],AIC_random=numbers4[,2]) #Reorder columns
  243. #summarymodelfits_AIC_table #See table
  244.  
  245. ### Model fit table, -2(likelihood)
  246. g1 <- unlist(strsplit(output[107]," +"))[-1] #Traditional AIC data
  247. g2 <- unlist(strsplit(output[108]," +"))[-1] #Phylogenetically controlled AIC data
  248. rownaames5 <- c(g1[1],g2[1]) #make vector of first column names
  249. numbers5 <- t(data.frame(as.numeric(g1[2:3]), as.numeric(g2[2:3])))  #make data frame of numbers
  250. numbers5 <- data.frame(numbers5, rownaames5) #Make data frame of row names and numbers
  251. colnames(numbers5) <- c("twoln_fixed", "twoln_random", "Analysis") #Assign column names
  252. summarymodelfits_twoln_table <- data.frame(Analysis = numbers5[,3], twoln_fixed = numbers5[,1], twoln_random = numbers5[,2]) #Reorder columns
  253. #summarymodelfits_twoln_table #See table
  254.  
  255. #Make list of tables
  256.         tables <- list(summaryfitstats_table1_trad, summaryeffsizes_table2_trad, summaryfitstats_table1_phyl, summaryeffsizes_table2_phyl, summarymodelfits_AIC_table, summarymodelfits_twoln_table)
  257.         tables
  258. }
  259.  
  260. # 3 groups in the moderator variable
  261. maketables_3group <- function(output){ #DONE IF/ELSE REFORMATTING
  262. #Table 1, Traditional meta-analysis
  263. #a1<-unlist(strsplit(output[6]," +"))[-1] #Table header
  264. a2<-unlist(strsplit(output[8],"  +"))[-1] #Data row 1, between groups, fixed effects
  265. a3<-unlist(strsplit(output[9],"  +"))[-1] #Data row 2, within groups
  266. a4 <- if(length(unlist(strsplit(output[10]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[10]," +"))[-1][1],unlist(strsplit(output[10]," +"))[-1][2],unlist(strsplit(output[10]," +"))[-1][3]),unlist(strsplit(output[10]," +"))[-1][4:6])} else
  267.                         if(length(unlist(strsplit(output[10]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[10]," +"))[-1][1],unlist(strsplit(output[10]," +"))[-1][2],unlist(strsplit(output[10]," +"))[-1][3]),unlist(strsplit(output[10]," +"))[-1][4:8])} else
  268.                                                 end
  269. a5 <- if(length(unlist(strsplit(output[11]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[11]," +"))[-1][1],unlist(strsplit(output[11]," +"))[-1][2],unlist(strsplit(output[11]," +"))[-1][3]),unlist(strsplit(output[11]," +"))[-1][4:6])} else
  270.                         if(length(unlist(strsplit(output[11]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[11]," +"))[-1][1],unlist(strsplit(output[11]," +"))[-1][2],unlist(strsplit(output[11]," +"))[-1][3]),unlist(strsplit(output[11]," +"))[-1][4:8])} else
  271.                                                 end
  272. a6 <- if(length(unlist(strsplit(output[12]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[12]," +"))[-1][1],unlist(strsplit(output[12]," +"))[-1][2],unlist(strsplit(output[12]," +"))[-1][3]),unlist(strsplit(output[12]," +"))[-1][4:6])} else
  273.                         if(length(unlist(strsplit(output[12]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[12]," +"))[-1][1],unlist(strsplit(output[12]," +"))[-1][2],unlist(strsplit(output[12]," +"))[-1][3]),unlist(strsplit(output[12]," +"))[-1][4:8])} else
  274.                                                 end
  275. a7<-unlist(strsplit(output[13]," +"))[-1] #Data row 6, Total
  276. a8<-unlist(strsplit(output[16],"  +"))[-1] #Data row 7, between groups, random effects
  277. rownaames<-c(a2[1],a3[1],a4[1],a5[1],a6[1],a7[1],a8[1]) #make vector of first column names
  278. numbers<-t(data.frame(as.numeric(a2[2:4]),as.numeric(a3[2:4]),as.numeric(a4[2:4]),as.numeric(a5[2:4]),as.numeric(a6[2:4]),append(as.numeric(a7[2]),c(-9999,-9999),after=1),as.numeric(a8[2:4]))) #make data frame of numbers
  279. numbers<-data.frame(numbers,rownaames) #Make data frame of row names and numbers
  280. colnames(numbers)<-c("Q","df","P","Source") #Assign column names
  281. summaryfitstats_table1_trad<-data.frame(Source=numbers$Source,Q=numbers$Q,df=numbers$df,P=numbers$P) #Reorder columns
  282. #summaryfitstats_table1_trad #See table
  283.  
  284. #Table 2, Traditional meta-analysis
  285. #b1<-unlist(strsplit(output[25]," +"))[-1] #Table header
  286.         b2 <- if(length(unlist(strsplit(output[29]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[29]," +"))[-1])[1],(unlist(strsplit(output[29]," +"))[-1])[2]),unlist(strsplit(output[29]," +"))[-1][3:9])} else
  287.                                 if(str_detect(unlist(strsplit(output[29]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[29],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[29]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[29]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[29],"  +"))[-1][6:7])} else
  288.                                                 end
  289.         b3 <- if(length(unlist(strsplit(output[30]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[30]," +"))[-1])[1],(unlist(strsplit(output[30]," +"))[-1])[2]),unlist(strsplit(output[30]," +"))[-1][3:9])} else
  290.                                 if(str_detect(unlist(strsplit(output[30]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[30],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[30]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[30]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[30],"  +"))[-1][6:7])} else
  291.                                                 end
  292.         b4 <- if(length(unlist(strsplit(output[31]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[31]," +"))[-1])[1],(unlist(strsplit(output[31]," +"))[-1])[2]),unlist(strsplit(output[31]," +"))[-1][3:9])} else
  293.                                 if(str_detect(unlist(strsplit(output[31]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[31],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[31]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[31]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[31],"  +"))[-1][6:7])} else
  294.                                                 end
  295.         b5 <- if(length(unlist(strsplit(output[32]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[32]," +"))[-1])[1],(unlist(strsplit(output[32]," +"))[-1])[2]),unlist(strsplit(output[32]," +"))[-1][3:9])} else
  296.                                 if(str_detect(unlist(strsplit(output[32]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[32],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[32]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[32]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[32],"  +"))[-1][6:7])} else
  297.                                                 end
  298.         b6 <- if(length(unlist(strsplit(output[36]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[36]," +"))[-1])[1],(unlist(strsplit(output[36]," +"))[-1])[2]),unlist(strsplit(output[36]," +"))[-1][3:9])} else
  299.                                 if(str_detect(unlist(strsplit(output[36]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[36],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[36]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[36]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[36],"  +"))[-1][6:7])} else
  300.                                                 end
  301.         b7 <- if(length(unlist(strsplit(output[37]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[37]," +"))[-1])[1],(unlist(strsplit(output[37]," +"))[-1])[2]),unlist(strsplit(output[37]," +"))[-1][3:9])} else
  302.                                 if(str_detect(unlist(strsplit(output[37]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[37],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[37]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[37]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[37],"  +"))[-1][6:7])} else
  303.                                                 end
  304.         b8 <- if(length(unlist(strsplit(output[38]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[38]," +"))[-1])[1],(unlist(strsplit(output[38]," +"))[-1])[2]),unlist(strsplit(output[38]," +"))[-1][3:9])} else
  305.                                 if(str_detect(unlist(strsplit(output[38]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[38],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[38]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[38]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[38],"  +"))[-1][6:7])} else
  306.                                                 end
  307.         b9 <- if(length(unlist(strsplit(output[39]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[39]," +"))[-1])[1],(unlist(strsplit(output[39]," +"))[-1])[2]),unlist(strsplit(output[39]," +"))[-1][3:9])} else
  308.                                 if(str_detect(unlist(strsplit(output[39]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[39],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[39]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[39]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[39],"  +"))[-1][6:7])} else
  309.                                                 end
  310. rownaames1<-c(b2[1],b3[1],b4[1],b5[1],b6[1],b7[1],b8[1],b9[1]) #make vector of first column names
  311. b22<-CI_split(b2) #Split confidence interval numbers apart and reinsert to vector of data
  312. b33<-CI_split(b3)
  313. b44<-CI_split(b4)
  314. b55<-CI_split(b5)
  315. b66<-CI_split(b6)
  316. b77<-CI_split(b7)
  317. b88<-CI_split(b8)
  318. b99<-CI_split(b9)
  319. numbers1<-t(data.frame(as.numeric(b22),as.numeric(b33),as.numeric(b44),as.numeric(b55),as.numeric(b66),as.numeric(b77),as.numeric(b88),as.numeric(b99)))  #make data frame of numbers
  320. numbers1<-data.frame(numbers1,rownaames1) #Make data frame of row names and numbers
  321. colnames(numbers1)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  322. summaryeffsizes_table2_trad<-data.frame(Group=numbers1[,9],k=numbers1[,1],effsize=numbers1[,2],var=numbers1[,3],CI_low=numbers1[,4],CI_high=numbers1[,5],Z=numbers1[,6],df=numbers1[,7],P=numbers1[,8]) #Reorder columns
  323. #summaryeffsizes_table2_trad #See table
  324.  
  325. ###Phylogenetic meta-analysis
  326. #Table 1, Phylogenetic meta-analysis
  327. #d1<-unlist(strsplit(output[53]," +"))[-1] #Table header
  328. d2 <- unlist(strsplit(output[55],"  +"))[-1] #Data row 1, between groups, fixed effects
  329. d3 <- unlist(strsplit(output[56],"  +"))[-1] #Data row 2, within groups
  330. d4 <- if(length(unlist(strsplit(output[57]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[57]," +"))[-1][1],unlist(strsplit(output[57]," +"))[-1][2],unlist(strsplit(output[57]," +"))[-1][3]),unlist(strsplit(output[57]," +"))[-1][4:6])} else
  331.                         if(length(unlist(strsplit(output[57]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[57]," +"))[-1][1],unlist(strsplit(output[57]," +"))[-1][2],unlist(strsplit(output[57]," +"))[-1][3]),unlist(strsplit(output[57]," +"))[-1][4:8])} else
  332.                                                 end
  333. d5 <- if(length(unlist(strsplit(output[58]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[58]," +"))[-1][1],unlist(strsplit(output[58]," +"))[-1][2],unlist(strsplit(output[58]," +"))[-1][3]),unlist(strsplit(output[58]," +"))[-1][4:6])} else
  334.                         if(length(unlist(strsplit(output[58]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[58]," +"))[-1][1],unlist(strsplit(output[58]," +"))[-1][2],unlist(strsplit(output[58]," +"))[-1][3]),unlist(strsplit(output[58]," +"))[-1][4:8])} else
  335.                                                 end
  336. d6 <- if(length(unlist(strsplit(output[59]," +"))[-1]) == 6) {c(paste(unlist(strsplit(output[59]," +"))[-1][1],unlist(strsplit(output[59]," +"))[-1][2],unlist(strsplit(output[59]," +"))[-1][3]),unlist(strsplit(output[59]," +"))[-1][4:6])} else
  337.                         if(length(unlist(strsplit(output[59]," +"))[-1]) == 8) {c(paste(unlist(strsplit(output[59]," +"))[-1][1],unlist(strsplit(output[59]," +"))[-1][2],unlist(strsplit(output[59]," +"))[-1][3]),unlist(strsplit(output[59]," +"))[-1][4:8])} else
  338.                                                 end
  339. d7 <- unlist(strsplit(output[60]," +"))[-1] #Data row 6, Total
  340. d8 <- unlist(strsplit(output[63],"  +"))[-1] #Data row 7, between groups, random effects
  341. rownaames2<-c(d2[1],d3[1],d4[1],d5[1],d6[1],d7[1],d8[1]) #make vector of first column names
  342. numbers2<-t(data.frame(append(as.numeric(d2[2:4]),c(-9999,-9999),after=3),as.numeric(d3[2:6]),as.numeric(d4[2:6]),as.numeric(d5[2:6]),as.numeric(d6[2:6]),append(as.numeric(d7[2]),c(-9999,-9999,-9999,-9999),after=1),append(as.numeric(d8[2:4]),c(-9999,-9999),after=3))) #make data frame of numbers
  343. numbers2<-data.frame(numbers2,rownaames2) #Make data frame of row names and numbers
  344. colnames(numbers2)<-c("Q","df","P","df_polytadj","P_polytadj","Source") #Assign column names
  345. summaryfitstats_table1_phyl<-data.frame(Source=numbers2[,6],Q=numbers2[,1],df=numbers2[,2],P=numbers2[,3],df_polytadj=numbers2[,4],P_polytadj=numbers2[,5]) #Reorder columns
  346. #summaryfitstats_table1_phyl #See table
  347.  
  348. #Table 2, Phylogenetic meta-analysis
  349. #e1<-unlist(strsplit(output[72]," +"))[-1] #Table header
  350.         e2 <- if(length(unlist(strsplit(output[76]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[76]," +"))[-1])[1],(unlist(strsplit(output[76]," +"))[-1])[2]),unlist(strsplit(output[76]," +"))[-1][3:9])} else
  351.                                 if(str_detect(unlist(strsplit(output[76]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[76],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[76]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[76]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[76],"  +"))[-1][6:7])} else
  352.                                                 end
  353.         e3 <- if(length(unlist(strsplit(output[77]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[77]," +"))[-1])[1],(unlist(strsplit(output[77]," +"))[-1])[2]),unlist(strsplit(output[77]," +"))[-1][3:9])} else
  354.                                 if(str_detect(unlist(strsplit(output[77]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[77],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[77]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[77]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[77],"  +"))[-1][6:7])} else
  355.                                                 end
  356.         e4 <- if(length(unlist(strsplit(output[78]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[78]," +"))[-1])[1],(unlist(strsplit(output[78]," +"))[-1])[2]),unlist(strsplit(output[78]," +"))[-1][3:9])} else
  357.                                 if(str_detect(unlist(strsplit(output[78]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[78],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[78]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[78]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[78],"  +"))[-1][6:7])} else
  358.                                                 end
  359.         e5 <- if(length(unlist(strsplit(output[79]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[79]," +"))[-1])[1],(unlist(strsplit(output[79]," +"))[-1])[2]),unlist(strsplit(output[79]," +"))[-1][3:9])} else
  360.                                 if(str_detect(unlist(strsplit(output[79]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[79],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[79]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[79]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[79],"  +"))[-1][6:7])} else
  361.                                                 end
  362.         e6 <- if(length(unlist(strsplit(output[83]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[83]," +"))[-1])[1],(unlist(strsplit(output[83]," +"))[-1])[2]),unlist(strsplit(output[83]," +"))[-1][3:9])} else
  363.                                 if(str_detect(unlist(strsplit(output[83]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[83],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[83]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[83]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[83],"  +"))[-1][6:7])} else
  364.                                                 end
  365.         e7 <- if(length(unlist(strsplit(output[84]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[84]," +"))[-1])[1],(unlist(strsplit(output[84]," +"))[-1])[2]),unlist(strsplit(output[84]," +"))[-1][3:9])} else
  366.                                 if(str_detect(unlist(strsplit(output[84]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[84],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[84]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[84]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[84],"  +"))[-1][6:7])} else
  367.                                                 end
  368.         e8 <- if(length(unlist(strsplit(output[85]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[85]," +"))[-1])[1],(unlist(strsplit(output[85]," +"))[-1])[2]),unlist(strsplit(output[85]," +"))[-1][3:9])} else
  369.                                 if(str_detect(unlist(strsplit(output[85]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[85],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[85]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[85]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[85],"  +"))[-1][6:7])} else
  370.                                                 end
  371.         e9 <- if(length(unlist(strsplit(output[86]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[86]," +"))[-1])[1],(unlist(strsplit(output[86]," +"))[-1])[2]),unlist(strsplit(output[86]," +"))[-1][3:9])} else
  372.                                 if(str_detect(unlist(strsplit(output[86]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[86],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[86]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[86]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[86],"  +"))[-1][6:7])} else
  373.                                                 end
  374. rownaames3<-c(e2[1],e3[1],e4[1],e5[1],e6[1],e7[1],e8[1],e9[1]) #make vector of first column names
  375. e22<-CI_split(e2) #Split confidence interval numbers apart and reinsert to vector of data
  376. e33<-CI_split(e3)
  377. e44<-CI_split(e4)
  378. e55<-CI_split(e5)
  379. e66<-CI_split(e6)
  380. e77<-CI_split(e7)
  381. e88<-CI_split(e8)
  382. e99<-CI_split(e9)
  383. numbers3<-t(data.frame(as.numeric(e22),as.numeric(e33),as.numeric(e44),as.numeric(e55),as.numeric(e66),as.numeric(e77),as.numeric(e88),as.numeric(e99)))  #make data frame of numbers
  384. numbers3<-data.frame(numbers3,rownaames3) #Make data frame of row names and numbers
  385. colnames(numbers3)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  386. summaryeffsizes_table2_phyl<-data.frame(Group=numbers3[,9],k=numbers3[,1],effsize=numbers3[,2],var=numbers3[,3],CI_low=numbers3[,4],CI_high=numbers3[,5],Z=numbers3[,6],df=numbers3[,7],P=numbers3[,8]) #Reorder columns
  387. #summaryeffsizes_table2_phyl #See table
  388.  
  389. ### Model fit table, AIC
  390. f1<-unlist(strsplit(output[101]," +"))[-1] #Table header
  391. f2<-unlist(strsplit(output[102]," +"))[-1] #Data row 1, fixed effects, all studies
  392. rownaames4<-c(f1[1],f2[1]) #make vector of first column names
  393. numbers4<-t(data.frame(as.numeric(f1[2:3]),as.numeric(f2[2:3])))  #make data frame of numbers
  394. numbers4<-data.frame(numbers4,rownaames4) #Make data frame of row names and numbers
  395. colnames(numbers4)<-c("AIC_fixed","AIC_random","Analysis") #Assign column names
  396. summarymodelfits_AIC_table<-data.frame(Analysis=numbers4[,3],AIC_fixed=numbers4[,1],AIC_random=numbers4[,2]) #Reorder columns
  397. #summarymodelfits_AIC_table #See table
  398.  
  399.         ### Model fit table, -2(likelihood)
  400.         g1 <- unlist(strsplit(output[113]," +"))[-1] #Traditional AIC data
  401.         g2 <- unlist(strsplit(output[114]," +"))[-1] #Phylogenetically controlled AIC data
  402.         rownaames5 <- c(g1[1],g2[1]) #make vector of first column names
  403.         numbers5 <- t(data.frame(as.numeric(g1[2:3]), as.numeric(g2[2:3])))  #make data frame of numbers
  404.         numbers5 <- data.frame(numbers5, rownaames5) #Make data frame of row names and numbers
  405.         colnames(numbers5) <- c("twoln_fixed", "twoln_random", "Analysis") #Assign column names
  406.         summarymodelfits_twoln_table <- data.frame(Analysis = numbers5[,3], twoln_fixed = numbers5[,1], twoln_random = numbers5[,2]) #Reorder columns
  407.         #summarymodelfits_twoln_table #See table
  408.  
  409.         #Make list of tables
  410.         tables <- list(summaryfitstats_table1_trad, summaryeffsizes_table2_trad, summaryfitstats_table1_phyl, summaryeffsizes_table2_phyl, summarymodelfits_AIC_table, summarymodelfits_twoln_table)
  411.         tables
  412. }
  413.  
  414. # 4 groups in the moderator variable
  415. maketables_4group <- function(output){ #DONE IF/ELSE REFORMATTING
  416. #Table 1, Traditional meta-analysis
  417. a1<-unlist(strsplit(output[6],"  +"))[-1] #Table header
  418. a2<-unlist(strsplit(output[8],"  +"))[-1] #Data row 1, between groups, fixed effects
  419. a3<-unlist(strsplit(output[9],"  +"))[-1] #Data row 2, within groups
  420. a4<-unlist(strsplit(output[10],"  +"))[-1] #Data row 3, within goup 0
  421. a5<-unlist(strsplit(output[11],"  +"))[-1] #Data row 4, within goup 1
  422. a6<-unlist(strsplit(output[12],"  +"))[-1] #Data row 5, within goup 2
  423. a7<-unlist(strsplit(output[13],"  +"))[-1] #Data row 6, Total
  424. a8<-unlist(strsplit(output[14],"  +"))[-1] #Data row 7, between groups, random effects
  425. a9<-unlist(strsplit(output[17],"  +"))[-1] #Data row 7, between groups, random effects
  426. rownaames<-c(a2[1],a3[1],a4[1],a5[1],a6[1],a7[1],a8[1],a9[1]) #make vector of first column names
  427. numbers<-t(data.frame(as.numeric(a2[2:4]),as.numeric(a3[2:4]),as.numeric(a4[2:4]),as.numeric(a5[2:4]),as.numeric(a6[2:4]),as.numeric(a7[2:4]),append(as.numeric(a8[2]),c(-9999,-9999),after=1),as.numeric(a9[2:4]))) #make data frame of numbers
  428. numbers<-data.frame(numbers,rownaames) #Make data frame of row names and numbers
  429. colnames(numbers)<-c("Q","df","P","Source") #Assign column names
  430. summaryfitstats_table1_trad<-data.frame(Source=numbers$Source,Q=numbers$Q,df=numbers$df,P=numbers$P) #Reorder columns
  431. #summaryfitstats_table1_trad #See table
  432.  
  433. #Table 2, Traditional meta-analysis
  434. b1<-unlist(strsplit(output[26],"  +"))[-1] #Table header
  435. b2 <- if(length(unlist(strsplit(output[30]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[30]," +"))[-1])[1],(unlist(strsplit(output[30]," +"))[-1])[2]),unlist(strsplit(output[30]," +"))[-1][3:9])} else
  436.                         if(str_detect(unlist(strsplit(output[30]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[30],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[30]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[30]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[30],"  +"))[-1][6:7])} else
  437.                                         end
  438. b3 <- if(length(unlist(strsplit(output[31]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[31]," +"))[-1])[1],(unlist(strsplit(output[31]," +"))[-1])[2]),unlist(strsplit(output[31]," +"))[-1][3:9])} else
  439.                         if(str_detect(unlist(strsplit(output[31]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[31],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[31]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[31]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[31],"  +"))[-1][6:7])} else
  440.                                         end
  441. b4 <- if(length(unlist(strsplit(output[32]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[32]," +"))[-1])[1],(unlist(strsplit(output[32]," +"))[-1])[2]),unlist(strsplit(output[32]," +"))[-1][3:9])} else
  442.                         if(str_detect(unlist(strsplit(output[32]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[32],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[32]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[32]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[32],"  +"))[-1][6:7])} else
  443.                                         end
  444. b5 <- if(length(unlist(strsplit(output[33]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[33]," +"))[-1])[1],(unlist(strsplit(output[33]," +"))[-1])[2]),unlist(strsplit(output[33]," +"))[-1][3:9])} else
  445.                         if(str_detect(unlist(strsplit(output[33]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[33],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[33]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[33]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[33],"  +"))[-1][6:7])} else
  446.                                         end
  447. b6 <- if(length(unlist(strsplit(output[34]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[34]," +"))[-1])[1],(unlist(strsplit(output[34]," +"))[-1])[2]),unlist(strsplit(output[34]," +"))[-1][3:9])} else
  448.                         if(str_detect(unlist(strsplit(output[34]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[34],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[34]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[34]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[34],"  +"))[-1][6:7])} else
  449.                                         end
  450. b7 <- if(length(unlist(strsplit(output[38]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[38]," +"))[-1])[1],(unlist(strsplit(output[38]," +"))[-1])[2]),unlist(strsplit(output[38]," +"))[-1][3:9])} else
  451.                         if(str_detect(unlist(strsplit(output[38]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[38],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[38]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[38]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[38],"  +"))[-1][6:7])} else
  452.                                         end
  453. b8 <- if(length(unlist(strsplit(output[39]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[39]," +"))[-1])[1],(unlist(strsplit(output[39]," +"))[-1])[2]),unlist(strsplit(output[39]," +"))[-1][3:9])} else
  454.                         if(str_detect(unlist(strsplit(output[39]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[39],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[39]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[39]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[39],"  +"))[-1][6:7])} else
  455.                                         end
  456. b9 <- if(length(unlist(strsplit(output[40]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[40]," +"))[-1])[1],(unlist(strsplit(output[40]," +"))[-1])[2]),unlist(strsplit(output[40]," +"))[-1][3:9])} else
  457.                         if(str_detect(unlist(strsplit(output[40]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[40],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[40]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[40]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[40],"  +"))[-1][6:7])} else
  458.                                         end
  459. b10 <- if(length(unlist(strsplit(output[41]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[41]," +"))[-1])[1],(unlist(strsplit(output[41]," +"))[-1])[2]),unlist(strsplit(output[41]," +"))[-1][3:9])} else
  460.                         if(str_detect(unlist(strsplit(output[41]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[41],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[41]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[41]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[41],"  +"))[-1][6:7])} else
  461.                                         end
  462. b11 <- if(length(unlist(strsplit(output[42]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[42]," +"))[-1])[1],(unlist(strsplit(output[42]," +"))[-1])[2]),unlist(strsplit(output[42]," +"))[-1][3:9])} else
  463.                         if(str_detect(unlist(strsplit(output[42]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[42],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[42]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[42]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[42],"  +"))[-1][6:7])} else
  464.                                         end
  465. rownaames1<-c(b2[1],b3[1],b4[1],b5[1],b6[1],b7[1],b8[1],b9[1],b10[1],b11[1]) #make vector of first column names
  466. b22<-CI_split(b2) #Split confidence interval numbers apart and reinsert to vector of data
  467. b33<-CI_split(b3)
  468. b44<-CI_split(b4)
  469. b55<-CI_split(b5)
  470. b66<-CI_split(b6)
  471. b77<-CI_split(b7)
  472. b88<-CI_split(b8)
  473. b99<-CI_split(b9)
  474. b1010<-CI_split(b10)
  475. b1111<-CI_split(b11)
  476. numbers1<-t(data.frame(as.numeric(b22),as.numeric(b33),as.numeric(b44),as.numeric(b55),as.numeric(b66),as.numeric(b77),as.numeric(b88),as.numeric(b99),as.numeric(b1010),as.numeric(b1111)))  #make data frame of numbers
  477. numbers1<-data.frame(numbers1,rownaames1) #Make data frame of row names and numbers
  478. colnames(numbers1)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  479. summaryeffsizes_table2_trad<-data.frame(Group=numbers1[,9],k=numbers1[,1],effsize=numbers1[,2],var=numbers1[,3],CI_low=numbers1[,4],CI_high=numbers1[,5],Z=numbers1[,6],df=numbers1[,7],P=numbers1[,8]) #Reorder columns
  480. #summaryeffsizes_table2_trad #See table
  481.  
  482. ###Phylogenetic meta-analysis
  483. #Table 1, Phylogenetic meta-analysis
  484. d1<-unlist(strsplit(output[56],"  +"))[-1] #Table header
  485. d2<-unlist(strsplit(output[58],"  +"))[-1] #Data row 1, between groups, fixed effects
  486. d3<-unlist(strsplit(output[59],"  +"))[-1] #Data row 2, within groups
  487. d4<-unlist(strsplit(output[60],"  +"))[-1] #Data row 3, within goup 0
  488. d5<-unlist(strsplit(output[61],"  +"))[-1] #Data row 4, within goup 1
  489. d6<-unlist(strsplit(output[62],"  +"))[-1] #Data row 5, within goup 2
  490. d7<-unlist(strsplit(output[63],"  +"))[-1] #Data row 6, Total
  491. d8<-unlist(strsplit(output[64],"  +"))[-1] #Data row 7, between groups, random effects
  492. d9<-unlist(strsplit(output[67],"  +"))[-1] #Data row 7, between groups, random effects
  493. rownaames2<-c(d2[1],d3[1],d4[1],d5[1],d6[1],d7[1],d8[1],d9[1]) #make vector of first column names
  494. numbers2<-t(data.frame(append(as.numeric(d2[2:4]),c(-9999,-9999),after=3),as.numeric(d3[2:6]),as.numeric(d4[2:6]),as.numeric(d5[2:6]),as.numeric(d6[2:6]),as.numeric(d7[2:6]),append(as.numeric(d8[2]),c(-9999,-9999,-9999,-9999),after=3),append(as.numeric(d9[2:4]),c(-9999,-9999),after=3))) #make data frame of numbers
  495. numbers2<-data.frame(numbers2,rownaames2) #Make data frame of row names and numbers
  496. colnames(numbers2)<-c("Q","df","P","df_polytadj","P_polytadj","Source") #Assign column names
  497. summaryfitstats_table1_phyl<-data.frame(Source=numbers2[,6],Q=numbers2[,1],df=numbers2[,2],P=numbers2[,3],df_polytadj=numbers2[,4],P_polytadj=numbers2[,5]) #Reorder columns
  498. #summaryfitstats_table1_phyl #See table
  499.  
  500. #Table 2, Phylogenetic meta-analysis
  501. e1 <- unlist(strsplit(output[76],"  +"))[-1] #Table header
  502. e2 <- if(length(unlist(strsplit(output[80]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[80]," +"))[-1])[1],(unlist(strsplit(output[80]," +"))[-1])[2]),unlist(strsplit(output[80]," +"))[-1][3:9])} else
  503.                         if(str_detect(unlist(strsplit(output[80]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[80],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[80]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[80]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[80],"  +"))[-1][6:7])} else
  504.                                         end
  505. e3 <- if(length(unlist(strsplit(output[81]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[81]," +"))[-1])[1],(unlist(strsplit(output[81]," +"))[-1])[2]),unlist(strsplit(output[81]," +"))[-1][3:9])} else
  506.                         if(str_detect(unlist(strsplit(output[81]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[81],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[81]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[81]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[81],"  +"))[-1][6:7])} else
  507.                                         end
  508. e4 <- if(length(unlist(strsplit(output[82]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[82]," +"))[-1])[1],(unlist(strsplit(output[82]," +"))[-1])[2]),unlist(strsplit(output[82]," +"))[-1][3:9])} else
  509.                         if(str_detect(unlist(strsplit(output[82]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[82],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[82]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[82]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[82],"  +"))[-1][6:7])} else
  510.                                         end
  511. e5 <- if(length(unlist(strsplit(output[83]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[83]," +"))[-1])[1],(unlist(strsplit(output[83]," +"))[-1])[2]),unlist(strsplit(output[83]," +"))[-1][3:9])} else
  512.                         if(str_detect(unlist(strsplit(output[83]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[83],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[83]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[83]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[83],"  +"))[-1][6:7])} else
  513.                                         end
  514. e6 <- if(length(unlist(strsplit(output[84]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[84]," +"))[-1])[1],(unlist(strsplit(output[84]," +"))[-1])[2]),unlist(strsplit(output[84]," +"))[-1][3:9])} else
  515.                         if(str_detect(unlist(strsplit(output[84]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[84],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[84]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[84]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[84],"  +"))[-1][6:7])} else
  516.                                         end
  517. e7 <- if(length(unlist(strsplit(output[88]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[88]," +"))[-1])[1],(unlist(strsplit(output[88]," +"))[-1])[2]),unlist(strsplit(output[88]," +"))[-1][3:9])} else
  518.                         if(str_detect(unlist(strsplit(output[88]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[88],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[88]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[88]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[88],"  +"))[-1][6:7])} else
  519.                                         end
  520. e8 <- if(length(unlist(strsplit(output[89]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[89]," +"))[-1])[1],(unlist(strsplit(output[89]," +"))[-1])[2]),unlist(strsplit(output[89]," +"))[-1][3:9])} else
  521.                         if(str_detect(unlist(strsplit(output[89]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[89],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[89]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[89]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[89],"  +"))[-1][6:7])} else
  522.                                         end
  523. e9 <- if(length(unlist(strsplit(output[90]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[90]," +"))[-1])[1],(unlist(strsplit(output[90]," +"))[-1])[2]),unlist(strsplit(output[90]," +"))[-1][3:9])} else
  524.                         if(str_detect(unlist(strsplit(output[90]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[90],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[90]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[90]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[90],"  +"))[-1][6:7])} else
  525.                                         end
  526. e10 <- if(length(unlist(strsplit(output[91]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[91]," +"))[-1])[1],(unlist(strsplit(output[91]," +"))[-1])[2]),unlist(strsplit(output[91]," +"))[-1][3:9])} else
  527.                         if(str_detect(unlist(strsplit(output[91]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[91],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[91]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[91]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[91],"  +"))[-1][6:7])} else
  528.                                         end
  529. e11 <- if(length(unlist(strsplit(output[92]," +"))[-1]) == 9) {c(paste((unlist(strsplit(output[92]," +"))[-1])[1],(unlist(strsplit(output[92]," +"))[-1])[2]),unlist(strsplit(output[92]," +"))[-1][3:9])} else
  530.                         if(str_detect(unlist(strsplit(output[92]," +"))[-1][6], ")") == "TRUE") {c(unlist(strsplit(output[92],"  +"))[-1][1:4], paste(str_split(unlist(strsplit(output[92]," +"))[-1][6], ")")[[1]][1],")", sep=""), str_split(unlist(strsplit(output[92]," +"))[-1][6], ")")[[1]][2], unlist(strsplit(output[92],"  +"))[-1][6:7])} else
  531.                                         end
  532. rownaames3<-c(e2[1],e3[1],e4[1],e5[1],e6[1],e7[1],e8[1],e9[1],e10[1],e11[1]) #make vector of first column names
  533. e22<-CI_split(e2) #Split confidence interval numbers apart and reinsert to vector of data
  534. e33<-CI_split(e3)
  535. e44<-CI_split(e4)
  536. e55<-CI_split(e5)
  537. e66<-CI_split(e6)
  538. e77<-CI_split(e7)
  539. e88<-CI_split(e8)
  540. e99<-CI_split(e9)
  541. e1010<-CI_split(e10)
  542. e1111<-CI_split(e11)
  543. numbers3<-t(data.frame(as.numeric(e22),as.numeric(e33),as.numeric(e44),as.numeric(e55),as.numeric(e66),as.numeric(e77),as.numeric(e88),as.numeric(e99),as.numeric(e1010),as.numeric(e1111)))  #make data frame of numbers
  544. numbers3<-data.frame(numbers3,rownaames3) #Make data frame of row names and numbers
  545. colnames(numbers3)<-c("k","effsize","var","95CI_low","95CI_high","Z","df","P","Group") #Assign column names
  546. summaryeffsizes_table2_phyl<-data.frame(Group=numbers3[,9],k=numbers3[,1],effsize=numbers3[,2],var=numbers3[,3],CI_low=numbers3[,4],CI_high=numbers3[,5],Z=numbers3[,6],df=numbers3[,7],P=numbers3[,8]) #Reorder columns
  547. #summaryeffsizes_table2_phyl #See table
  548.  
  549. ###Model fit table
  550. f1<-unlist(strsplit(output[107],"  +"))[-1] #Table header
  551. f2<-unlist(strsplit(output[108],"  +"))[-1] #Data row 1, fixed effects, all studies
  552. rownaames4<-c(f1[1],f2[1]) #make vector of first column names
  553. numbers4<-t(data.frame(as.numeric(f1[2:3]),as.numeric(f2[2:3])))  #make data frame of numbers
  554. numbers4<-data.frame(numbers4,rownaames4) #Make data frame of row names and numbers
  555. colnames(numbers4)<-c("AIC_fixed","AIC_random","Analysis") #Assign column names
  556. summarymodelfits_AIC_table<-data.frame(Analysis=numbers4[,3],AIC_fixed=numbers4[,1],AIC_random=numbers4[,2]) #Reorder columns
  557. #summarymodelfits_table #See table
  558.  
  559.         ### Model fit table, -2(likelihood)
  560.         g1 <- unlist(strsplit(output[119]," +"))[-1] #Traditional AIC data
  561.         g2 <- unlist(strsplit(output[120]," +"))[-1] #Phylogenetically controlled AIC data
  562.         rownaames5 <- c(g1[1],g2[1]) #make vector of first column names
  563.         numbers5 <- t(data.frame(as.numeric(g1[2:3]), as.numeric(g2[2:3])))  #make data frame of numbers
  564.         numbers5 <- data.frame(numbers5, rownaames5) #Make data frame of row names and numbers
  565.         colnames(numbers5) <- c("twoln_fixed", "twoln_random", "Analysis") #Assign column names
  566.         summarymodelfits_twoln_table <- data.frame(Analysis = numbers5[,3], twoln_fixed = numbers5[,1], twoln_random = numbers5[,2]) #Reorder columns
  567.         #summarymodelfits_twoln_table #See table
  568.  
  569.         #Make list of tables
  570.         tables <- list(summaryfitstats_table1_trad, summaryeffsizes_table2_trad, summaryfitstats_table1_phyl, summaryeffsizes_table2_phyl, summarymodelfits_AIC_table, summarymodelfits_twoln_table)
  571.         tables
  572. }
  573.  
  574. # Process phylometa output
  575. phylometa.process <- function(phylometa.run,groups){
  576.         aaa <- data.frame(phylometa.run)
  577.         if(length(subset(aaa,aaa[,1]=="poly")[,1]) == 1) {phylometa.run <- phylometa.run[-as.numeric(rownames(subset(aaa,aaa[,1]=="poly")))]} else (phylometa.run <- phylometa.run)
  578.         aaaa <- data.frame(phylometa.run)
  579.         x <- as.numeric(rownames(subset(aaaa,aaaa[,1]=="RESULTS SECTION A. Traditional meta-analysis.")))
  580.         y <- as.numeric(rownames(subset(aaaa,aaaa[,1]=="For further details on these methods see:")))
  581.         bbb <- phylometa.run[x:y]
  582.         outputtables <- (
  583.         if (groups == 1) {maketables_1group(bbb)} else
  584.                 if (groups == 2) {maketables_2group(bbb)} else
  585.                         if (groups == 3) {maketables_3group(bbb)} else
  586.                                 if (groups == 4) {maketables_4group(bbb)} else
  587.         end)
  588.         outputtables
  589. }
  590.  
  591. # Get output from phylometa.process
  592. phylometa.output <- function(a) {
  593.         a
  594. }
  595. phylometa.output.table <- function(a,b) {
  596.         a[[b]]
  597. }
  598.  
  599. # Function used below in the function 'arrange'
  600. vp.layout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y)
  601. arrange_ <- function(..., nrow=NULL, ncol=NULL, as.table=FALSE) {
  602.  dots <- list(...)
  603.  n <- length(dots)
  604.  if(is.null(nrow) & is.null(ncol)) { nrow = floor(n/2) ; ncol = ceiling(n/nrow)}
  605.  if(is.null(nrow)) { nrow = ceiling(n/ncol)}
  606.  if(is.null(ncol)) { ncol = ceiling(n/nrow)}
  607.         ## NOTE see n2mfrow in grDevices for possible alternative
  608. grid.newpage()
  609. pushViewport(viewport(layout=grid.layout(nrow,ncol) ) )
  610.  ii.p <- 1
  611.  for(ii.row in seq(1, nrow)){
  612.  ii.table.row <- ii.row
  613.  if(as.table) {ii.table.row <- nrow - ii.table.row + 1}
  614.   for(ii.col in seq(1, ncol)){
  615.    ii.table <- ii.p
  616.    if(ii.p > n) break
  617.    print(dots[[ii.table]], vp=vp.layout(ii.table.row, ii.col))
  618.    ii.p <- ii.p + 1
  619.   }
  620.  }
  621. }
  622.  
  623. # Function to write trees to directory for use by Phylometa
  624. WriteTrees2 <- function(xxx) {
  625.     for(i in 1:length(xxx)){
  626.         write.tree(xxx[[i]], paste("tree",i,".txt","",sep=""))
  627.         }
  628. }
  629. Created by Pretty R at inside-R.org