Repository 'oghma'
hg clone https://toolshed.g2.bx.psu.edu/repos/nicolas/oghma

Changeset 71:37d3d073b51d (2016-10-28)
Previous changeset 70:8cc5a7448ca6 (2016-10-28) Next changeset 72:366a9dbec192 (2016-10-28)
Commit message:
Uploaded
added:
computeR2.R
b
diff -r 8cc5a7448ca6 -r 37d3d073b51d computeR2.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/computeR2.R Fri Oct 28 08:44:42 2016 -0400
[
@@ -0,0 +1,26 @@
+########################################################
+#
+# creation date : 27/06/16
+# last modification : 22/10/16
+# author : Dr Nicolas Beaume
+# owner : IRRI
+#
+########################################################
+
+# compute r2 by computing the classic formula
+# compare the sum of square difference from target to prediciton
+# to the sum of square difference from target to the mean of the target
+computeR2 <- function(target, prediction) {
+  sst <- sum((target-mean(target))^2)
+  ssr <- sum((target-prediction)^2)
+  return(1-ssr/sst)
+}
+############################ main #############################
+# extract argument
+cmd <- commandArgs(trailingOnly = T)
+source(cmd[1])
+# load target and prediction
+phenotype <- read.table(phenotype, sep="\t", h=T)[,1] 
+predicted <- read.table(predicted, sep = "\t", h=T)[,2]
+# compute r2
+cat(computeR2(phenotype, predicted), file=out)
\ No newline at end of file