| 0 | 1 ######################################################## | 
|  | 2 # | 
|  | 3 # creation date : 27/06/16 | 
| 28 | 4 # last modification : 22/10/16 | 
| 0 | 5 # author : Dr Nicolas Beaume | 
|  | 6 # owner : IRRI | 
|  | 7 # | 
|  | 8 ######################################################## | 
|  | 9 | 
| 28 | 10 # compute r2 by computing the classic formula | 
|  | 11 # compare the sum of square difference from target to prediciton | 
|  | 12 # to the sum of square difference from target to the mean of the target | 
|  | 13 computeR2 <- function(target, prediction) { | 
|  | 14   sst <- sum((target-mean(target))^2) | 
|  | 15   ssr <- sum((target-prediction)^2) | 
|  | 16   return(1-ssr/sst) | 
| 0 | 17 } | 
|  | 18 ############################ main ############################# | 
| 28 | 19 # extract argument | 
| 0 | 20 cmd <- commandArgs(trailingOnly = T) | 
|  | 21 source(cmd[1]) | 
| 28 | 22 # load target and prediction | 
| 0 | 23 phenotype <- read.table(phenotype, sep="\t", h=T)[,1] | 
|  | 24 predicted <- read.table(predicted, sep = "\t", h=T)[,2] | 
| 28 | 25 # compute r2 | 
| 0 | 26 cat(computeR2(phenotype, predicted), file=out) |