PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/working/auteur/R/prepare.data.R

http://github.com/eastman/auteur
R | 30 lines | 25 code | 3 blank | 2 comment | 7 complexity | c783a3ff30929c268566b28858ccb221 MD5 | raw file
 1#general phylogentic utility wrapping geiger:::treedata for checking data consistency
 2#author: JM EASTMAN 2010
 3
 4prepare.data <-
 5function(phy, data, SE) {
 6	td <- treedata(phy, data, sort = TRUE)	
 7	if(any(SE!=0)) {
 8		if(!is.null(names(SE))) {
 9			se=rep(0,length(td$phy$tip.label))
10			names(se)=td$phy$tip.label
11			ss.match=match(names(SE), names(se))
12			if(any(is.na(ss.match))) warning(paste(names(SE[is.na(ss.match)]), "not found in the dataset", sep=" "))
13			se[match(names(SE[!is.na(ss.match)]),names(se))]=SE[!is.na(ss.match)]
14			SE=se
15		} else {
16			if(name.check(phy,data)=="OK" & length(data)==length(SE)) {
17				names(SE)=td$phy$tip.label
18				warning("ordering of values in SE assumed to be in perfect correspondence with phy$tip.label")
19			} else {
20				stop("SE must be a named vector of measurement error")
21			}
22		}
23	} else {
24		SE=rep(0,length(td$phy$tip.label))
25		names(SE)=td$phy$tip.label
26	}
27	
28	return(list(ape.tre=td$phy, orig.dat=td$data[,1], SE=SE))
29}
30