[Picante-commits] r49 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 11 08:13:23 CEST 2008


Author: pdc
Date: 2008-04-11 08:13:22 +0200 (Fri, 11 Apr 2008)
New Revision: 49

Modified:
   pkg/R/pic.circular.R
Log:
add comments

Modified: pkg/R/pic.circular.R
===================================================================
--- pkg/R/pic.circular.R	2008-04-11 04:19:31 UTC (rev 48)
+++ pkg/R/pic.circular.R	2008-04-11 06:13:22 UTC (rev 49)
@@ -63,12 +63,17 @@
 		des2 <- phy$edge[j, 2]
 		sumbl <- bl[i] + bl[j]
 		ic <- anc - nb.tip
-		tempcontr <- phenotype[des1]  - phenotype[des2]
+		## get the differences between the decendant nodes
+		tempcontr <- phenotype[des1] - phenotype[des2]
 		abtemp <- abs(tempcontr)
+		## sanity check on the difference
 		if(abtemp > (2 * pi)) {
 			stop("ERROR. contrast between ", substitute(phenotype[des1] ),
 			 ' and ', substitute(phenotype[des2]), "is", substitute(tempcontr))
 		}
+		## ensure that contrasts record the short distance
+		## if the diff is greater than pi recalculate 
+		## then shorter side, while retaining directionality
 		if(abtemp > pi) {
 			if(phenotype[des1]  > phenotype[des2]) {
 				tempcontr <- tempcontr - (2 * pi)
@@ -82,12 +87,14 @@
 		if (scaled) contr[ic] <- contr[ic]/sqrt(sumbl)
 		if (var.contrasts) var.con[ic] <- sumbl
 		
+		## get vector components and weight by the branch lengths
 		sin_des1 <- sin(as.numeric(phenotype[des1])) * bl[j]
 		cos_des1 <- cos(as.numeric(phenotype[des1])) * bl[j]
 
 		sin_des2 <- sin(as.numeric(phenotype[des2])) * bl[i]
 		cos_des2 <- cos(as.numeric(phenotype[des2])) * bl[i]
-    	
+	
+		## calculate the ancestral node value
 		phenotype[anc] <- as.circular(atan2(sin_des1 + sin_des2, cos_des1 + cos_des2), 
 							type = "angles", units = "radians", template = "none", 
 							rotation = "counter", zero = 0, modulo = "2pi"



More information about the Picante-commits mailing list