PEM-utils: Utility Function for Phylogenetic Eigenvector Maps

PEM-utilsR Documentation

Utility Function for Phylogenetic Eigenvector Maps

Description

A set of functions to help in calculating Phylogenetic Eigenvector Maps (PEM).

Usage

isUnderEdge(x, e)

isUnderVertex(x, v)

aggregateOnVertex(
  x,
  data,
  fun,
  ...,
  v = 1L:NROW(x),
  default = rep(0, NCOL(data))
)

Arguments

x

A graph-class object.

e

A numeric vector of indices or a character vector of names representing one or more edges.

v

A numeric vector of indices or a character vector of names representing one or more vertices. The default for function aggregateOnVertex is all the vertices of x.

data

A matrix or data.frame containing edge data to be aggregated on the graph's vertices.

fun

A function to be applied on the incoming edges of the vertices.

...

Supplementary arguments to be internally passed to fun.

default

A vector of values to be assigned to vertices that have no incoming edges. The default is a vector of zeros with the same length as the number of columns is data.

Details

Functions isUnderEdge and isUnderVertex are used to set individual graph locations, in terms of edges or vertices where shifts in the values of selection (a) and/or evolution rate (psi) parameters are occurring. The binary contrasts matrices generated by function isUnderEdge and isUnderVertex are used as descriptors in models representing these subordinate parameters using higher order ones.

Function aggregateOnVertex allows one to aggregate variables associated with the edges on their destination vertices using a user-defined function.

Value

Functions isUnderEdge and isUnderVertex return a matrix of binary contrasts whose rows represent the edges of the graph and columns the edges or vertices given as indices or names to function isUnderEdge (argument e) or isUnderVertex (argument v), respectively. Function aggregateOnVertex returns a matrix whose rows represent the vertices specified by its argument v and columns represent the variables given using its argument data.

Functions

  • isUnderEdge(): Edges Under or At an Edge

    Identify which of the edges of a graph are located at or under one or more of the graph's edges using a binary contrast matrix.

  • isUnderVertex(): Edges Under a Vertex

    Identify which of the edges of a graph are located under one or more of the graph's vertices using a binary contrast matrix.

  • aggregateOnVertex(): Aggregate on Vertex

    Aggregate incoming edge values on a vertex or a set of vertices.

Author(s)

Guillaume Guénard [aut, cre] (<https://orcid.org/0000-0003-0761-3072>), Pierre Legendre [ctb] (<https://orcid.org/0000-0002-3838-3305>) – Maintainer: Guillaume Guénard <guillaume.guenard@umontreal.ca>

References

Guénard, G., Legendre, P., and Peres-Neto, P. 2013. Phylogenetic eigenvector maps: a framework to model and predict species traits. Methods in Ecology and Evolution. 4: 1120–1131

Makarenkov, V., Legendre, L. & Desdevise, Y. 2004. Modelling phylogenetic relationships using reticulated networks. Zoologica Scripta 33: 89–96

Blanchet, F. G., Legendre, P. & Borcard, D. 2008. Modelling directional spatial processes in ecological data. Ecological Modelling 215: 325–336

See Also

PEM-functions, PEM-class

Examples

## Synthetic example
data.frame(
  species = as.logical(c(0,0,1,0,0,0,0,0,0,0,1,1,1)),
  type = c(2,2,3,1,2,2,2,2,2,2,3,3,3),
  x = c(1,3,4,0,1.67,4,1,1.33,2.33,3.33,4.33,4,5),
  y = c(1,1,1,0,0.5,0,-1,0,0,-0.5,-1,-0.5,-0.5),
  row.names = sprintf("V%d",1:13)
) %>%
st_as_sf(
  coords=c("x","y"),
  crs = NA
) %>%
graph %>%
add.edge(
  from = c(1,2,1,5,4,4,5,9,4,8,9,4,7,7,6,6,9,10,10),
  to = c(2,3,5,2,1,5,9,2,8,9,6,7,8,9,3,13,10,12,11),
  data = data.frame(
    distance = c(4.2,4.7,3.9,3.0,3.6,2.7,4.4,3.4,3.6,3.3,
                 4.8,3.2,3.5,4.4,2.5,3.4,4.3,3.1,2.2),
    row.names = sprintf("E%d",1:19)
  )
) -> gr_ex

## Plot the graph:
plot(gr_ex, cex.min=3, cex.lab=0.6)

## Show the edges of the graph:
edge(gr_ex)

## Identify the edges that are under or at the edges E7 or E17 using a binary
## contrast matrix:
isUnderEdge(gr_ex, c("E7","E17"))

## Identify the edges that are under vertices V5 or V9 using a binary
## contrast matrix:
tmp <- isUnderVertex(gr_ex, c("V5","V9"))
tmp

## Aggregate the result of isUnderVertex() using the following function
## enables one to determine which of the vertices are found under V5 and V9:
aggregateOnVertex(gr_ex, tmp, function(x) ifelse(any(as.logical(x)),1,0))



guenardg/MPSEM documentation built on April 14, 2025, 3:53 p.m.