/packages/archive/2010/04.2010/04.29.2010/spacodi/man/randomization.test.sp.Rd

http://github.com/eastman/spacodiR · Unknown · 65 lines · 52 code · 13 blank · 0 comment · 0 complexity · 1f98d9b29b8361da17ef6e4ae805ca52 MD5 · raw file

  1. \name{randomization.test.sp}
  2. \alias{randomization.test.sp}
  3. \title{testing significant by randomization}
  4. \description{\code{randomization.test.sp} is a function for conducting significance-testing by randomization.}
  5. \usage{randomization.test.sp(obs = obs, exp = exp, iter = 10000, return.all = FALSE, two.tailed = TRUE)}
  6. \arguments{
  7. \item{obs}{an vector of observed data}
  8. \item{exp}{an vector of expected values}
  9. \item{iter}{number of randomization iterations to perform}
  10. \item{return.all}{a logical identifier controlling whether all randomization comparisons are output into a vector}
  11. \item{two.tailed}{a logical identifier indicating whether randomization test should be two-tailed}
  12. }
  13. \details{Given a set of observed and expected values, \code{iter} comparisons between the vectors are performed.
  14. Expecting the sign of these comparisons to be random, if a large proportion of comparisons are in a particular
  15. direction, support is lent for a true difference in means. For instance, if 90 percent of comparisons suggest
  16. that observed data are larger than expected, an approximate randomization \code{p}-value is interpreted to be 0.20. If
  17. a single value is supplied for the observed data, this method will be akin to finding the quantile (\code{q})in the expected values
  18. where the observed datum appears. Under \code{two.tailed=TRUE}, the resulting \code{p.value} from this function will be twice (\code{q}),
  19. for an observed datum in the left tail of the expected distribution, or twice (\code{1-q}) for the opposite tail. }
  20. \value{ A list of at most two primary elements:
  21. \itemize{
  22. \item \code{differences}{: the vector of all comparisons between \code{obs} and \code{exp} if \code{return.all=TRUE}}
  23. \item \code{p.value}{: result(s) from the randomization test; if \code{two.tailed=FALSE}, \code{p}-values from both tails are returned}
  24. }
  25. Note: be wary of significant results that are based off few comparisons. If the number of iterations exceeds the length of the
  26. empirical data, a warning will be issued.
  27. }
  28. \author{Jonathan Eastman}
  29. \examples{
  30. # generate a random tree
  31. foo=bd.tree(b=0.02, d=0, taxa.stop=25)
  32. # get nodes and times
  33. node.time.extractor(foo, start.time=0.35, stop.time=0.80, return.times=TRUE, proportion=TRUE)
  34. # visualize the correspondence
  35. plot(foo)
  36. nodelabels()
  37. ## an example of comparing observed and expected Bst at nodes ##
  38. sim=sim.spacodi(missing=0.01,sim.tree=TRUE)
  39. s=sim$sp.plot
  40. p=sim$sp.tree
  41. # get nodes for a time-slice
  42. n.t=node.time.extractor(phy=p,start.time=0.25,stop.time=0.75)
  43. # get Bsts for nodes
  44. o=Bst.by.nodes(sp.plot=s, phy=p, obs.only=TRUE)[[1]]
  45. obs=o[!is.na(match(o[,"node.ID"], n.t$nodes)),1]
  46. # compile expected Bst-values from data reshuffling
  47. Bst.by.nodes(sp.plot=s, phy=p, n.rep=5, method="1s")[[2]]->exps
  48. e=exps[!is.na(match(row.names(exps), n.t$nodes)),]
  49. exp=unname(unlist(e))
  50. # randomization test of observed and expected Bst
  51. randomization.test.sp(obs=obs, exp=exp, iter=100, two.tailed=TRUE)
  52. }