twoSampleFactor: Phylofactorization of vector data using two-sample tests

View source: R/twoSampleFactor.R

twoSampleFactorR Documentation

Phylofactorization of vector data using two-sample tests

Description

Phylofactorization of vector data using two-sample tests

Usage

twoSampleFactor(Z, tree, nfactors, method = "contrast",
  TestFunction = NULL, ncores = NULL, stop.fcn = NULL,
  cluster.depends = "", Metropolis = F, sampleFcn = NULL,
  lambda = 1, ...)

Arguments

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 {grps,tree,Z,PF.output,..} and output objective omega. grps is a two-element list containing indexes for each group; see getPhyloGroups. PF.output is a logical: the output from PF.output=T should be a P-value and can be input into the stop.fcn.

ncores

number of cores to use for parallelization

stop.fcn

stop function taking as input the output from TestFunction when PF.output=T and returning logical where an output of TRUE will stop phylofactorization. Inputting character string "KS", will use KS-test on the P-values output from TestFunction.

cluster.depends

expression loading dependencies for TestFunction onto cluster.

Metropolis

logical. If true, phylofactorization will be implemented by stochastically sample edges using sampleFcn.

sampleFcn

function taking argument omegas, which is used to implement Metropolis phylofactorization.

lambda

Parameter for default Metropolis phylofactorization in which groups are drawn with probability proportional to omega^lambda.

...

additional arguments passed to TestFunction

Examples

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)

reptalex/phylofactor documentation built on Feb. 28, 2024, 3:19 p.m.