crossVmap: maps groups from old to new communities for phylofactor...

View source: R/crossVmap.R

crossVmapR Documentation

maps groups from old to new communities for phylofactor cross-validation

Description

maps groups from old to new communities for phylofactor cross-validation

Usage

crossVmap(Grps, tree, original_community, new_community,
  ignore.interruptions = T)

Arguments

Grps

list of length two containing the names of taxa (found in tip-labels of tree) in two groups separated by an edge or chain of edges.

tree

phylo class object. Must contain all Grps, original_community and new_community

original_community

original community being factored (strings corresponding to tip-labels of tree. This helps us ID the new branches in the new_community

new_community

new community being cross-validated (strings corresponding to tip-labels of tree)

ignore.interruptions

Logical on whether or not to ignore edges in new-community that interrupt the edges separating Grps

Examples


set.seed(1)
tree <- ape::rtree(7)
c1 <- c('t2','t5','t6','t3','t4','t7')
c2 <- setdiff(tree$tip.label,c('t3','t4','t5'))

grp1 <- c('t3','t6')
grp2 <- c('t2','t7')
Grps <- list(grp1,grp2)

factored.edges <- getFactoredEdges(grp1=match(grp1,tree$tip.label),
                                  grp2=match(grp2,tree$tip.label),tree=tree)

ecols <- rep('grey',ape::Nedge(tree))
ecols[factored.edges] <- 'red'
ecols[12] <- 'yellow'
ecols[c(2,3,10,11)] <- 'blue'
plot(tree,use.edge.length = FALSE,
            edge.width = 3,edge.color = ecols)
tiplabels(tree$tip.label,cex=3)
# one clade interrupts our chain of branches: t1
# another clade: [t4,t5], was factored out previously and is not in our Grps

# We have an optional output "ignore.interruptions=T' which omits interruptions
# in output of group comparisons. 
# if ignore.interruptions=F, we want to output the list of possible groups
# for iteration and refinement of which edge along the chain holds an effect.

# the default is to ignore interruptions, and it should output
# [[t2,t7]],[[t6]]
# by succesfully ignoring t1.

crossVmap(Grps,tree,c1,c2)

#correct

#Quick check - let's include two interruptions, one of which contains the root
grp1 <- c('t4','t5')
grp2 <- c('t1')
Grps <- list(grp1,grp2)
c1 <- c(grp1,grp2,'t6')
c2 <- setdiff(tree$tip.label,'t4')

#correct output should be [[t3]],[[t5]]
crossVmap(Grps,tree,c1,c2)


# Now, suppose we wanted to use those interruptions to refine phylofactorization
# to a subset of the original edges

crossVmap(Grps,tree,c1,c2,ignore.interruptions = FALSE)

#notice the output: the first and last entries are our output from crossVmap
#when ignore.interruptions=T. The intervening elements are the interrupting clades
#in the order in which they interrupt the factored edges.

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