/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. prepare.data <-
  4. function(phy, data, SE) {
  5. td <- treedata(phy, data, sort = TRUE)
  6. if(any(SE!=0)) {
  7. if(!is.null(names(SE))) {
  8. se=rep(0,length(td$phy$tip.label))
  9. names(se)=td$phy$tip.label
  10. ss.match=match(names(SE), names(se))
  11. if(any(is.na(ss.match))) warning(paste(names(SE[is.na(ss.match)]), "not found in the dataset", sep=" "))
  12. se[match(names(SE[!is.na(ss.match)]),names(se))]=SE[!is.na(ss.match)]
  13. SE=se
  14. } else {
  15. if(name.check(phy,data)=="OK" & length(data)==length(SE)) {
  16. names(SE)=td$phy$tip.label
  17. warning("ordering of values in SE assumed to be in perfect correspondence with phy$tip.label")
  18. } else {
  19. stop("SE must be a named vector of measurement error")
  20. }
  21. }
  22. } else {
  23. SE=rep(0,length(td$phy$tip.label))
  24. names(SE)=td$phy$tip.label
  25. }
  26. return(list(ape.tre=td$phy, orig.dat=td$data[,1], SE=SE))
  27. }