View source: R/twoSampleFactor.R
twoSampleFactor | R Documentation |
Phylofactorization of vector data using two-sample tests
twoSampleFactor(Z, tree, nfactors, method = "contrast",
TestFunction = NULL, ncores = NULL, stop.fcn = NULL,
cluster.depends = "", Metropolis = F, sampleFcn = NULL,
lambda = 1, ...)
Z |
Vector of data. |
tree |
phylo class object |
nfactors |
number of factors to compute |
method |
string indicating two-sample test two use. Can take values of "contrast" (default), "Fisher", "Wilcox", 't.test', or "custom", indicating the two-sample test to be used. |
TestFunction |
optional input customized test function, taking input |
ncores |
number of cores to use for parallelization |
stop.fcn |
stop function taking as input the output from |
cluster.depends |
expression loading dependencies for |
Metropolis |
logical. If true, phylofactorization will be implemented by stochastically sample edges using |
sampleFcn |
function taking argument |
lambda |
Parameter for default Metropolis phylofactorization in which groups are drawn with probability proportional to omega^lambda. |
... |
additional arguments passed to |
library(phylofactor)
library(ggtree)
library(viridis)
set.seed(1)
D <- 300
tree <- rtree(D)
n1 <- 477
n2 <- 332
c1 <- phangorn::Descendants(tree,n1,'tips')[[1]]
c2 <- phangorn::Descendants(tree,n2,'tips')[[1]]
Z <- rnorm(D)
Z[c1] <- Z[c1]+1
Z[c2] <- Z[c2]-2
pf <- twoSampleFactor(Z,tree,2,ncores=2)
cbind(c(length(c2),length(c1)),pf$factors)
pp <- pf.tree(pf,layout='rectangular')$ggplot
tipcolors <- rgb(ecdf(Z)(Z),0,1-ecdf(Z)(Z))
pp+geom_cladelabel(node=n1,'clade_1')+
geom_cladelabel(node=n2,'clade_2')+
geom_tippoint(color=tipcolors,size=3)
############# binary data #################
Z <- rbinom(D,1,0.3)
Z[c1] <- rbinom(length(c1),1,0.9)
Z[c2] <- 0
pf <- twoSampleFactor(Z,tree,nfactors=2,method='Fisher',alternative='two.sided')
pp <- pf.tree(pf,layout='rectangular')$ggplot
tipcolors <- viridis(2)[Z+1]
pp+geom_cladelabel(node=n1,'clade_1')+
geom_cladelabel(node=n2,'clade_2')+
geom_tippoint(color=tipcolors,size=3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.