diff --git a/DESCRIPTION b/DESCRIPTION
index 6a540d25..216cb463 100755
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -7,8 +7,8 @@ Authors@R: c(person("Thomas", "Guillerme", role = c("aut", "cre", "cph"),
person("Jack", "Hatfield", role = c("aut", "cph"))
)
Maintainer: Thomas Guillerme
@@ -273,13 +304,15 @@
pair.plot
reduce.matrix
select.axes
slice.tree
slide.nodes
and remove.zero.brlen
tree.age
multi.ace
+set.root.time
slice.tree
slide.nodes
and remove.zero.brlen
tree.age
multi.ace
-
char.diff
to get distance matriceschar.diff
to get distance matricesdispRity
package
@@ -293,7 +326,7 @@
@@ -273,13 +304,15 @@
pair.plot
reduce.matrix
select.axes
slice.tree
slide.nodes
and remove.zero.brlen
tree.age
multi.ace
+set.root.time
slice.tree
slide.nodes
and remove.zero.brlen
tree.age
multi.ace
-
char.diff
to get distance matriceschar.diff
to get distance matricesdispRity
package
@@ -293,7 +326,7 @@
4 Details of specific functionsThe following section contains information specific to some functions.
If any of your questions are not covered in these sections, please refer to the function help files in
R
, send me an email (guillert@tcd.ie), or raise an issue on GitHub.
The several tutorials below describe specific functionalities of certain functions; please always refer to the function help files for the full function documentation!
Before each section, make sure you loaded the Beck and Lee (2014) data (see example data for more details).
-## Loading the data
-data(BeckLee_mat50)
-data(BeckLee_mat99)
-data(BeckLee_tree)
-data(BeckLee_ages)
Before each section, make sure you loaded the Beck and Lee (2014) data (see example data for more details).
+## Loading the data
+data(BeckLee_mat50)
+data(BeckLee_mat99)
+data(BeckLee_tree)
+data(BeckLee_ages)
The function chrono.subsets
allows users to divide the matrix into different time subsets or slices given a dated phylogeny that contains all the elements (i.e. taxa) from the matrix.
@@ -378,7 +411,7 @@
For the time-slicing method details see T. Guillerme and Cooper (2018).
For both methods, the function takes the time
argument which can be a vector of numeric
values for:
method = discrete
)Here is an example for the time binning method (method = discrete
):
## Generating three time bins containing the taxa present every 40 Ma
-chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree,
-method = "discrete",
- time = c(120, 80, 40, 0))
## Generating three time bins containing the taxa present every 40 Ma
+chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree,
+ method = "discrete",
+ time = c(120, 80, 40, 0))
## ---- dispRity object ----
## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree
## 120 - 80, 80 - 40, 40 - 0.
Note that we can also generate equivalent results by just telling the function that we want three time-bins as follow:
-## Automatically generate three equal length bins:
-chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree,
-method = "discrete",
- time = 3)
## Automatically generate three equal length bins:
+chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree,
+ method = "discrete",
+ time = 3)
## ---- dispRity object ----
## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree
## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0.
@@ -409,9 +442,9 @@ ## Displaying the table of first and last occurrence dates
-## for each taxa
-head(BeckLee_ages)
## FAD LAD
## Adapis 37.2 36.8
## Asioryctes 83.6 72.1
@@ -419,10 +452,10 @@ 4.1.1 Time-binning## Generating time bins including taxa that might span between them
-chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree,
- method = "discrete",
- time = c(120, 80, 40, 0), FADLAD = BeckLee_ages)
+## Generating time bins including taxa that might span between them
+chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree,
+ method = "discrete",
+ time = c(120, 80, 40, 0), FADLAD = BeckLee_ages)
## ---- dispRity object ----
## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree
## 120 - 80, 80 - 40, 40 - 0.
@@ -457,20 +490,20 @@ 4.1.2 Time-slicingGuillerme and Cooper (2018).
-## Generating four time slices every 40 million years
-## under a model of proximity evolution
-chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree,
-method = "continuous", model = "proximity",
- time = c(120, 80, 40, 0),
- FADLAD = BeckLee_ages)
+
More details about the differences between these methods can be found in T. Guillerme and Cooper (2018).
+## Generating four time slices every 40 million years
+## under a model of proximity evolution
+chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree,
+ method = "continuous", model = "proximity",
+ time = c(120, 80, 40, 0),
+ FADLAD = BeckLee_ages)
## ---- dispRity object ----
## 4 continuous (proximity) time subsets for 99 elements in one matrix with 1 phylogenetic tree
## 120, 80, 40, 0.
-## Generating four time slices automatically
-chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree,
-method = "continuous", model = "proximity",
- time = 4, FADLAD = BeckLee_ages)
+## Generating four time slices automatically
+chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree,
+ method = "continuous", model = "proximity",
+ time = 4, FADLAD = BeckLee_ages)
## ---- dispRity object ----
## 4 continuous (proximity) time subsets for 99 elements in one matrix with 1 phylogenetic tree
## 133.51, 89.01, 44.5, 0.
@@ -480,23 +513,23 @@ 4.1.2 Time-slicing4.2 Customised subsets
Another way of separating elements into different categories is to use customised subsets as briefly explained above.
This function simply takes the list of elements to put in each group (whether they are the actual element names or their position in the matrix).
-## Creating the two groups (crown and stems)
- crown.stem(BeckLee_tree, inc.nodes = FALSE)
- mammal_groups <-
-## Separating the dataset into two different groups
-custom.subsets(BeckLee_mat50, group = mammal_groups)
+## Creating the two groups (crown and stems)
+mammal_groups <- crown.stem(BeckLee_tree, inc.nodes = FALSE)
+
+## Separating the dataset into two different groups
+custom.subsets(BeckLee_mat50, group = mammal_groups)
## ---- dispRity object ----
## 2 customised subsets for 50 elements in one matrix:
## crown, stem.
Like in this example, you can use the utility function crown.stem
that allows to automatically separate the crown and stems taxa given a phylogenetic tree.
Also, elements can easily be assigned to different groups if necessary!
-## Creating the three groups as a list
- list("even" = seq(from = 1, to = 49, by = 2),
- weird_groups <-"odd" = seq(from = 2, to = 50, by = 2),
- "all" = c(1:50))
+## Creating the three groups as a list
+weird_groups <- list("even" = seq(from = 1, to = 49, by = 2),
+ "odd" = seq(from = 2, to = 50, by = 2),
+ "all" = c(1:50))
The custom.subsets
function can also take a phylogeny (as a phylo
object) as an argument to create groups as clades:
-## Creating groups as clades
-custom.subsets(BeckLee_mat50, group = BeckLee_tree)
+
This automatically creates 49 (the number of nodes) groups containing between two and 50 (the number of tips) elements.
@@ -504,11 +537,11 @@ 4.3 Bootstraps and rarefactionsOne important step in analysing ordinated matrices is to pseudo-replicate the data to see how robust the results are, and how sensitive they are to outliers in the dataset.
This can be achieved using the function boot.matrix
to bootstrap and/or rarefy the data.
The default options will bootstrap the matrix 100 times without rarefaction using the “full” bootstrap method (see below):
-## Default bootstrapping
-boot.matrix(data = BeckLee_mat50)
+
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
The number of bootstrap replicates can be defined using the bootstraps
option.
The method can be modified by controlling which bootstrap algorithm to use through the boot.type
argument.
Currently two algorithms are implemented:
@@ -517,79 +550,95 @@ 4.3 Bootstraps and rarefactions"single"
where only one random element is replaced by one other random element for each pseudo-replicate
"null"
where every element is resampled across the whole matrix (not just the subsets). I.e. for each subset of n elements, this algorithm resamples n elements across ALL subsets (not just the current one). If only one subset (or none) is used, this does the same as the "full"
algorithm.
-## Bootstrapping with the single bootstrap method
-boot.matrix(BeckLee_mat50, boot.type = "single")
+
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 100 times (method:"single").
+## Rows were bootstrapped 100 times (method:"single").
This function also allows users to rarefy the data using the rarefaction
argument.
Rarefaction allows users to limit the number of elements to be drawn at each bootstrap replication.
This is useful if, for example, one is interested in looking at the effect of reducing the number of elements on the results of an analysis.
This can be achieved by using the rarefaction
option that draws only n-x at each bootstrap replicate (where x is the number of elements not sampled).
The default argument is FALSE
but it can be set to TRUE
to fully rarefy the data (i.e. remove x elements for the number of pseudo-replicates, where x varies from the maximum number of elements present in each subset to a minimum of three elements).
It can also be set to one or more numeric
values to only rarefy to the corresponding number of elements.
-## Bootstrapping with the full rarefaction
-boot.matrix(BeckLee_mat50, bootstraps = 20,
-rarefaction = TRUE)
+## Bootstrapping with the full rarefaction
+boot.matrix(BeckLee_mat50, bootstraps = 20,
+ rarefaction = TRUE)
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 20 times (method:"full") and fully rarefied.
-## Or with a set number of rarefaction levels
-boot.matrix(BeckLee_mat50, bootstraps = 20,
-rarefaction = c(6:8, 3))
+## Rows were bootstrapped 20 times (method:"full") and fully rarefied.
+## Or with a set number of rarefaction levels
+boot.matrix(BeckLee_mat50, bootstraps = 20,
+ rarefaction = c(6:8, 3))
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements.
+## Rows were bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements.
Note that using the rarefaction
argument also bootstraps the data. In these examples, the function bootstraps the data (without rarefaction) AND also bootstraps the data with the different rarefaction levels.
-One other argument is dimensions
that specifies how many dimensions from the matrix should be used for further analysis.
-When missing, all dimensions from the ordinated matrix are used.
-## Using the first 50% of the dimensions
-boot.matrix(BeckLee_mat50, dimensions = 0.5)
+## Creating subsets of crown and stem mammals
+crown_stem <- custom.subsets(BeckLee_mat50,
+ group = crown.stem(BeckLee_tree,
+ inc.nodes = FALSE))
+## Bootstrapping and rarefying these groups
+boot.matrix(crown_stem, bootstraps = 200, rarefaction = TRUE)
## ---- dispRity object ----
-## 50 elements in one matrix with 24 dimensions.
-## Data was bootstrapped 100 times (method:"full").
-## Using the first 10 dimensions
-boot.matrix(BeckLee_mat50, dimensions = 10)
+## 2 customised subsets for 50 elements in one matrix with 48 dimensions:
+## crown, stem.
+## Rows were bootstrapped 200 times (method:"full") and fully rarefied.
+## Creating time slice subsets
+time_slices <- chrono.subsets(data = BeckLee_mat99,
+ tree = BeckLee_tree,
+ method = "continuous",
+ model = "proximity",
+ time = c(120, 80, 40, 0),
+ FADLAD = BeckLee_ages)
+
+## Bootstrapping the time slice subsets
+boot.matrix(time_slices, bootstraps = 100)
## ---- dispRity object ----
-## 50 elements in one matrix with 1 dimensions.
-## Data was bootstrapped 100 times (method:"full").
+## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
+## 120, 80, 40, 0.
+## Rows were bootstrapped 100 times (method:"full").
+
+4.3.1 Bootstrapping with probabilities
It is also possible to specify the sampling probability in the bootstrap for each elements.
This can be useful for weighting analysis for example (i.e. giving more importance to specific elements).
These probabilities can be passed to the prob
argument individually with a vector with the elements names or with a matrix with the rownames as elements names.
The elements with no specified probability will be assigned a probability of 1 (or 1/maximum weight if the argument is weights rather than probabilities).
-## Attributing a weight of 0 to Cimolestes and 10 to Maelestes
-boot.matrix(BeckLee_mat50,
-prob = c("Cimolestes" = 0, "Maelestes" = 10))
+## Attributing a weight of 0 to Cimolestes and 10 to Maelestes
+boot.matrix(BeckLee_mat50,
+ prob = c("Cimolestes" = 0, "Maelestes" = 10))
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 100 times (method:"full").
-Of course, one could directly supply the subsets generated above (using chrono.subsets
or custom.subsets
) to this function.
-## Creating subsets of crown and stem mammals
- custom.subsets(BeckLee_mat50,
- crown_stem <-group = crown.stem(BeckLee_tree,
- inc.nodes = FALSE))
- ## Bootstrapping and rarefying these groups
-boot.matrix(crown_stem, bootstraps = 200, rarefaction = TRUE)
-## ---- dispRity object ----
-## 2 customised subsets for 50 elements in one matrix with 48 dimensions:
-## crown, stem.
-## Data was bootstrapped 200 times (method:"full") and fully rarefied.
-## Creating time slice subsets
- chrono.subsets(data = BeckLee_mat99,
- time_slices <-tree = BeckLee_tree,
- method = "continuous",
- model = "proximity",
- time = c(120, 80, 40, 0),
- FADLAD = BeckLee_ages)
-
-## Bootstrapping the time slice subsets
-boot.matrix(time_slices, bootstraps = 100)
-## ---- dispRity object ----
-## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
-## 120, 80, 40, 0.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
+
+
+4.3.2 Bootstrapping dimensions
+In some cases, you might also be interested in bootstrapping dimensions rather than observations.
+I.e. bootstrapping the columns of a matrix rather than the rows.
+It’s pretty easy! By default, boot.matrix
uses the option boot.by = "rows"
which you can toggle to boot.by = "columns"
+## Bootstrapping the observations (default)
+set.seed(1)
+boot_obs <- boot.matrix(data = crown_stem, boot.by = "rows")
+
+## Bootstrapping the columns rather than the rows
+set.seed(1)
+boot_dim <- boot.matrix(data = crown_stem, boot.by = "columns")
+In these two examples, the first one boot_obs
bootstraps the rows as showed before (default behaviour).
+But the second one, boot_dim
bootstraps the dimensions.
+That means that for each bootstrap sample, the value calculated is actually obtained by reshuffling the dimensions (columns) rather than the observations (rows).
+
+## subsets n obs bs.median 2.5% 25% 75% 97.5%
+## 1 crown 30 -1.1 -2.04 -19.4 -7.56 3.621 14.64
+## 2 stem 20 1.1 1.52 -10.8 -1.99 6.712 13.97
+
+## subsets n obs bs.median 2.5% 25% 75% 97.5%
+## 1 crown 30 -1.1 -2.04 -18.5 -8.84 5.440 19.80
+## 2 stem 20 1.1 1.31 -16.7 -2.99 6.338 14.99
+Note here how the observed sum is the same (no bootstrapping) but the bootstrapping distributions are quiet different even though the same seed was used.
+
4.4 Disparity metrics
@@ -612,51 +661,51 @@ 4.4 Disparity metrics4.4.1 The function dimension-levels
The metric function dimension-levels determine the “dimensionality of decomposition” of the input matrix.
In other words, each dimension-level designates the dimensions of the output, i.e. either three (a matrix
); two (a vector
); or one (a single numeric
value) dimension.
-
-
-
+
+
4.4.1.1 Dimension-level 1 functions
A dimension-level 1 function will decompose a matrix
or a vector
into a single value:
-## Creating a dummy matrix
- matrix(rnorm(12), 4, 3)
- dummy_matrix <-
-## Example of dimension-level 1 functions
-mean(dummy_matrix)
-## [1] 0.1012674
-median(dummy_matrix)
-## [1] 0.3345108
+## Creating a dummy matrix
+dummy_matrix <- matrix(rnorm(12), 4, 3)
+
+## Example of dimension-level 1 functions
+mean(dummy_matrix)
+## [1] -0.183358
+
+## [1] -0.3909538
Any summary metric such as mean or median are good examples of dimension-level 1 functions as they reduce the matrix to a single dimension (i.e. one value).
4.4.1.2 Dimension-level 2 functions
A dimension-level 2 function will decompose a matrix
into a vector
.
-## Defining the function as the product of rows
- function(matrix) apply(matrix, 1, prod)
- prod.rows <-
-## A dimension-level 2 metric
-prod.rows(dummy_matrix)
-## [1] 0.72217818 2.48612354 -0.08986575 0.58266449
+## Defining the function as the product of rows
+prod.rows <- function(matrix) apply(matrix, 1, prod)
+
+## A dimension-level 2 metric
+prod.rows(dummy_matrix)
+## [1] 0.63727584 -0.09516528 -1.24477435 -0.10958022
Several dimension-level 2 functions are implemented in dispRity
(see ?dispRity.metric
) such as the variances
or ranges
functions that calculate the variance or the range of each dimension of the ordinated matrix respectively.
4.4.1.3 Dimension-level 3 functions
Finally a dimension-level 3 function will transform the matrix into another matrix.
Note that the dimension of the output matrix doesn’t need to match the the input matrix:
-## A dimension-level 3 metric
-var(dummy_matrix)
-## [,1] [,2] [,3]
-## [1,] 1.8570383 0.7417569 -0.5131686
-## [2,] 0.7417569 1.3194330 -1.5344429
-## [3,] -0.5131686 -1.5344429 2.8070556
-## A dimension-level 3 metric with a forced matrix output
-as.matrix(dist(dummy_matrix))
+
+## [,1] [,2] [,3]
+## [1,] 0.6356714 -0.2017617 0.2095042
+## [2,] -0.2017617 1.3656124 1.0850900
+## [3,] 0.2095042 1.0850900 1.0879400
+
## 1 2 3 4
-## 1 0.000000 4.794738 3.382990 3.297110
-## 2 4.794738 0.000000 2.400321 3.993864
-## 3 3.382990 2.400321 0.000000 2.187412
-## 4 3.297110 3.993864 2.187412 0.000000
+## 1 0.000000 1.390687 2.156388 2.984951
+## 2 1.390687 0.000000 2.557670 1.602143
+## 3 2.156388 2.557670 0.000000 3.531033
+## 4 2.984951 1.602143 3.531033 0.000000
+
@@ -666,71 +715,71 @@ 4.4.2 Between groups metricsmatrix and matrix2
(and of course any other additional arguments).
For example, this metric measures the difference in mean between two matrices:
-## A simple example
- function(matrix, matrix2) {
- mean.difference <-mean(matrix) - mean(matrix2)
- }
+## A simple example
+mean.difference <- function(matrix, matrix2) {
+ mean(matrix) - mean(matrix2)
+}
You can find the list of implemented between groups metric here or design them yourself for your specific needs (potentially using make.metric
for help).
The function works by simply using the two available matrices, with no restriction in terms of dimensions (although you’d probably want both matrices to have the same number of dimensions)
-## A second matrix
- matrix(runif(12), 4, 3)
- dummy_matrix2 <-
-## The difference between groups
-mean.difference(dummy_matrix, dummy_matrix2)
-## [1] -0.3194556
+## A second matrix
+dummy_matrix2 <- matrix(runif(12), 4, 3)
+
+## The difference between groups
+mean.difference(dummy_matrix, dummy_matrix2)
+## [1] -0.5620336
Beyond this super simple example, it might probably be interesting to use this metric on dispRity
objects, especially the ones from custom.subsets
and chrono.subsets
.
In fact, the dispRity
function allows to apply the between groups metric directly to the dispRity
objects using the between.groups = TRUE
option.
For example:
-## Combining both matrices
- rbind(dummy_matrix, dummy_matrix2)
- big_matrix <-rownames(big_matrix) <- 1:8
-
-## Making a dispRity object with both groups
- custom.subsets(big_matrix,
- grouped_matrix <-group = c(list(1:4), list(1:4)))
-
-## Calculating the mean difference between groups
- dispRity(grouped_matrix,
- (mean_differences <-metric = mean.difference,
- between.groups = TRUE))
+## Combining both matrices
+big_matrix <- rbind(dummy_matrix, dummy_matrix2)
+rownames(big_matrix) <- 1:8
+
+## Making a dispRity object with both groups
+grouped_matrix <- custom.subsets(big_matrix,
+ group = c(list(1:4), list(1:4)))
+
+## Calculating the mean difference between groups
+(mean_differences <- dispRity(grouped_matrix,
+ metric = mean.difference,
+ between.groups = TRUE))
## ---- dispRity object ----
## 2 customised subsets for 8 elements in one matrix with 3 dimensions:
## 1, 2.
## Disparity was calculated as: mean.difference between groups.
-## Summarising the object
-summary(mean_differences)
+
## subsets n_1 n_2 obs
## 1 1:2 4 4 0
-## Note how the summary table now indicates
-## the number of elements for each group
+
For dispRity
objects generated by custom.subsets
, the dispRity
function will by default apply the metric on the groups in a pairwise fashion.
For example, if the object contains multiple groups, all groups will be compared to each other:
-## A dispRity object with multiple groups
- custom.subsets(big_matrix,
- grouped_matrix <-group = c("A" = list(1:4),
- "B" = list(1:4),
- "C" = list(2:6),
- "D" = list(1:8)))
-
-## Measuring disparity between all groups
-summary(dispRity(grouped_matrix, metric = mean.difference,
-between.groups = TRUE))
+## A dispRity object with multiple groups
+grouped_matrix <- custom.subsets(big_matrix,
+ group = c("A" = list(1:4),
+ "B" = list(1:4),
+ "C" = list(2:6),
+ "D" = list(1:8)))
+
+## Measuring disparity between all groups
+summary(dispRity(grouped_matrix, metric = mean.difference,
+ between.groups = TRUE))
## subsets n_1 n_2 obs
## 1 A:B 4 4 0.000
-## 2 A:C 4 5 -0.172
-## 3 A:D 4 8 -0.160
-## 4 B:C 4 5 -0.172
-## 5 B:D 4 8 -0.160
-## 6 C:D 5 8 0.012
+## 2 A:C 4 5 -0.269
+## 3 A:D 4 8 -0.281
+## 4 B:C 4 5 -0.269
+## 5 B:D 4 8 -0.281
+## 6 C:D 5 8 -0.012
For dispRity
objects generated by chrono.subsets
(not shown here), the dispRity
function will by default apply the metric on the groups in a serial way (group 1 vs. group 2, group 2 vs. group 3, group 3 vs. group 4, etc…).
However, in both cases (for objects from custom.subsets
or chrono.subsets
) it is possible to manually specific the list of pairs of comparisons through their ID numbers:
-## Measuring disparity between specific groups
-summary(dispRity(grouped_matrix, metric = mean.difference,
-between.groups = list(c(1,3), c(3,1), c(4,1))))
+## Measuring disparity between specific groups
+summary(dispRity(grouped_matrix, metric = mean.difference,
+ between.groups = list(c(1,3), c(3,1), c(4,1))))
## subsets n_1 n_2 obs
-## 1 A:C 4 5 -0.172
-## 2 C:A 5 4 0.172
-## 3 D:A 8 4 0.160
+## 1 A:C 4 5 -0.269
+## 2 C:A 5 4 0.269
+## 3 D:A 8 4 0.281
Note that in any case, the order of the comparison can matter.
In our example, it is obvious that mean(matrix) - mean(matrix2)
is not the same as mean(matrix2) - mean(matrix)
.
@@ -745,69 +794,69 @@ 4.4.3 make.metric
Whether the function can be implemented in the dispRity
function (the function is fed into a lapply
loop).
For example, let’s see if the functions described above are the right dimension-levels:
-## Which dimension-level is the mean function?
-## And can it be used in dispRity?
-make.metric(mean)
+## Which dimension-level is the mean function?
+## And can it be used in dispRity?
+make.metric(mean)
## mean outputs a single value.
## mean is detected as being a dimension-level 1 function.
-## Which dimension-level is the prod.rows function?
-## And can it be used in dispRity?
-make.metric(prod.rows)
+## Which dimension-level is the prod.rows function?
+## And can it be used in dispRity?
+make.metric(prod.rows)
## prod.rows outputs a matrix object.
## prod.rows is detected as being a dimension-level 2 function.
-## Which dimension-level is the var function?
-## And can it be used in dispRity?
-make.metric(var)
+
## var outputs a matrix object.
## var is detected as being a dimension-level 3 function.
## Additional dimension-level 2 and/or 1 function(s) will be needed.
A non verbose version of the function is also available.
This can be done using the option silent = TRUE
and will simply output the dimension-level of the metric.
-## Testing whether mean is dimension-level 1
-if(make.metric(mean, silent = TRUE)$type != "level1") {
-message("The metric is not dimension-level 1.")
-
- }## Testing whether var is dimension-level 1
-if(make.metric(var, silent = TRUE)$type != "level1") {
-message("The metric is not dimension-level 1.")
- }
+## Testing whether mean is dimension-level 1
+if(make.metric(mean, silent = TRUE)$type != "level1") {
+ message("The metric is not dimension-level 1.")
+}
+## Testing whether var is dimension-level 1
+if(make.metric(var, silent = TRUE)$type != "level1") {
+ message("The metric is not dimension-level 1.")
+}
## The metric is not dimension-level 1.
4.4.4 Metrics in the dispRity
function
Using this metric structure, we can easily use any disparity metric in the dispRity
function as follows:
-## Measuring disparity as the standard deviation
-## of all the values of the
-## ordinated matrix (dimension-level 1 function).
-summary(dispRity(BeckLee_mat50, metric = sd))
+## Measuring disparity as the standard deviation
+## of all the values of the
+## ordinated matrix (dimension-level 1 function).
+summary(dispRity(BeckLee_mat50, metric = sd))
## subsets n obs
## 1 1 50 0.227
-## Measuring disparity as the standard deviation
-## of the variance of each axis of
-## the ordinated matrix (dimension-level 1 and 2 functions).
-summary(dispRity(BeckLee_mat50, metric = c(sd, variances)))
+## Measuring disparity as the standard deviation
+## of the variance of each axis of
+## the ordinated matrix (dimension-level 1 and 2 functions).
+summary(dispRity(BeckLee_mat50, metric = c(sd, variances)))
## subsets n obs
## 1 1 50 0.032
-## Measuring disparity as the standard deviation
-## of the variance of each axis of
-## the variance covariance matrix (dimension-level 1, 2 and 3 functions).
-summary(dispRity(BeckLee_mat50, metric = c(sd, variances, var)), round = 10)
+## Measuring disparity as the standard deviation
+## of the variance of each axis of
+## the variance covariance matrix (dimension-level 1, 2 and 3 functions).
+summary(dispRity(BeckLee_mat50, metric = c(sd, variances, var)), round = 10)
## subsets n obs
## 1 1 50 0
Note that the order of each function in the metric argument does not matter, the dispRity
function will automatically detect the function dimension-levels (using make.metric
) and apply them to the data in decreasing order (dimension-level 3 > 2 > 1).
-## Disparity as the standard deviation of the variance of each axis of the
-## variance covariance matrix:
- summary(dispRity(BeckLee_mat50,
- disparity1 <-metric = c(sd, variances, var)),
- round = 10)
-
-## Same as above but using a different function order for the metric argument
- summary(dispRity(BeckLee_mat50,
- disparity2 <-metric = c(variances, sd, var)),
- round = 10)
-
-## Both ways output the same disparity values:
-== disparity2 disparity1
+## Disparity as the standard deviation of the variance of each axis of the
+## variance covariance matrix:
+disparity1 <- summary(dispRity(BeckLee_mat50,
+ metric = c(sd, variances, var)),
+ round = 10)
+
+## Same as above but using a different function order for the metric argument
+disparity2 <- summary(dispRity(BeckLee_mat50,
+ metric = c(variances, sd, var)),
+ round = 10)
+
+## Both ways output the same disparity values:
+disparity1 == disparity2
## subsets n obs
## [1,] TRUE TRUE TRUE
In these examples, we considered disparity to be a single value.
@@ -867,137 +916,143 @@
4.4.5 Metrics implemented in
2
+count.neighbours
+The number of neigbhours to each element in a specified radius
+dispRity
+
+
+2
deviations
The minimal distance between each element and a hyperplane
dispRity
-
+
1
diagonal
The longest distance in the ordinated space (like the diagonal in two dimensions)
dispRity
-
+
1
disalignment
The rejection of the centroid of a matrix from the major axis of another (typically an "as.covar"
metric)
dispRity
-
+
2
displacements
The ratio between the distance from a reference and the distance from the centroid
dispRity
-
+
1
edge.length.tree
The edge lengths of the elements on a tree
ape
-
+
1
ellipsoid.volume
1
The volume of the ellipsoid of the space
Donohue et al. (2013)
-
+
1
func.div
The functional divergence (the ratio of deviation from the centroid)
dispRity
(similar to FD
::dbFD$FDiv
but without abundance)
-
+
1
func.eve
The functional evenness (the minimal spanning tree distances evenness)
dispRity
(similar to FD
::dbFD$FEve
but without abundance)
-
+
1
group.dist
The distance between two groups
dispRity
-
+
1
mode.val
The modal value
dispRity
-
+
1
n.ball.volume
The hyper-spherical (n-ball) volume
dispRity
-
+
2
neighbours
The distance to specific neighbours (e.g. the nearest neighbours - by default)
dispRity
-
+
2
pairwise.dist
The pairwise distances between elements
vegan
::vegist
-
+
2
point.dist
The distance between one group and the point of another group
dispRity
-
+
2
projections
The distance on (projection) or from (rejection) an arbitrary vector
dispRity
-
+
1
projections.between
projections
metric applied between groups
dispRity
-
+
2
projections.tree
The projections
metric but where the vector can be based on a tree
dispRity
-
+
2
quantiles
The nth quantile range per axis
dispRity
-
+
2
radius
The radius of each dimensions
dispRity
-
+
2
ranges
The range of each dimension
dispRity
-
+
1
roundness
The integral of the ranked scaled eigenvalues of a variance-covariance matrix
dispRity
-
+
2
span.tree.length
The minimal spanning tree length
vegan
::spantree
-
+
2
variances
The variance of each dimension
@@ -1072,32 +1127,32 @@ 4.4.6 Equations and implementatio
4.4.7 Using the different disparity metrics
Here is a brief demonstration of the main metrics implemented in dispRity
.
First, we will create a dummy/simulated ordinated space using the space.maker
utility function (more about that here:
-## Creating a 10*5 normal space
-set.seed(1)
- space.maker(10, 5, rnorm)
- dummy_space <-rownames(dummy_space) <- 1:10
+## Creating a 10*5 normal space
+set.seed(1)
+dummy_space <- space.maker(10, 5, rnorm)
+rownames(dummy_space) <- 1:10
We will use this simulated space to demonstrate the different metrics.
4.4.7.1 Volumes and surface metrics
The functions ellipsoid.volume
, convhull.surface
, convhull.volume
and n.ball.volume
all measure the surface or the volume of the ordinated space occupied:
Because there is only one subset (i.e. one matrix) in the dispRity object, the operations below are the equivalent of metric(dummy_space)
(with rounding).
-## Calculating the ellipsoid volume
-summary(dispRity(dummy_space, metric = ellipsoid.volume))
+
## subsets n obs
## 1 1 10 1.061
WARNING: in such dummy space, this gives the estimation of the ellipsoid volume, not the real ellipsoid volume! See the cautionary note in ?ellipsoid.volume
.
-## Calculating the convex hull surface
-summary(dispRity(dummy_space, metric = convhull.surface))
+
## subsets n obs
## 1 1 10 11.91
-## Calculating the convex hull volume
-summary(dispRity(dummy_space, metric = convhull.volume))
+
## subsets n obs
## 1 1 10 1.031
-## Calculating the convex hull volume
-summary(dispRity(dummy_space, metric = n.ball.volume))
+
## subsets n obs
## 1 1 10 4.43
The convex hull based functions are a call to the geometry::convhulln
function with the "FA"
option (computes total area and volume).
@@ -1106,97 +1161,109 @@
4.4.7.1 Volumes and surface metri
Cautionary note: measuring volumes in a high number of dimensions can be strongly affected by the curse of dimensionality that often results in near 0 disparity values. I strongly recommend reading this really intuitive explanation from Toph Tucker.
-
-4.4.7.2 Ranges, variances, quantiles, radius, pairwise distance, neighbours, modal value and diagonal
+
+4.4.7.2 Ranges, variances, quantiles, radius, pairwise distance, neighbours (and counting them), modal value and diagonal
The functions ranges
, variances
radius
, pairwise.dist
, mode.val
and diagonal
all measure properties of the ordinated space based on its dimensional properties (they are also less affected by the “curse of dimensionality”):
ranges
, variances
quantiles
and radius
work on the same principle and measure the range/variance/radius of each dimension:
-## Calculating the ranges of each dimension in the ordinated space
-ranges(dummy_space)
+
## [1] 2.430909 3.726481 2.908329 2.735739 1.588603
-## Calculating disparity as the distribution of these ranges
-summary(dispRity(dummy_space, metric = ranges))
+## Calculating disparity as the distribution of these ranges
+summary(dispRity(dummy_space, metric = ranges))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 2.736 1.673 2.431 2.908 3.645
-## Calculating disparity as the sum and the product of these ranges
-summary(dispRity(dummy_space, metric = c(sum, ranges)))
+## Calculating disparity as the sum and the product of these ranges
+summary(dispRity(dummy_space, metric = c(sum, ranges)))
## subsets n obs
## 1 1 10 13.39
-summary(dispRity(dummy_space, metric = c(prod, ranges)))
+
## subsets n obs
## 1 1 10 114.5
-## Calculating the variances of each dimension in the
-## ordinated space
-variances(dummy_space)
+
## [1] 0.6093144 1.1438620 0.9131859 0.6537768 0.3549372
-## Calculating disparity as the distribution of these variances
-summary(dispRity(dummy_space, metric = variances))
+## Calculating disparity as the distribution of these variances
+summary(dispRity(dummy_space, metric = variances))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 0.654 0.38 0.609 0.913 1.121
-## Calculating disparity as the sum and
-## the product of these variances
-summary(dispRity(dummy_space, metric = c(sum, variances)))
+## Calculating disparity as the sum and
+## the product of these variances
+summary(dispRity(dummy_space, metric = c(sum, variances)))
## subsets n obs
## 1 1 10 3.675
-summary(dispRity(dummy_space, metric = c(prod, variances)))
+
## subsets n obs
## 1 1 10 0.148
-## Calculating the quantiles of each dimension
-## in the ordinated space
-quantiles(dummy_space)
+
## [1] 2.234683 3.280911 2.760855 2.461077 1.559057
-## Calculating disparity as the distribution of these variances
-summary(dispRity(dummy_space, metric = quantiles))
+## Calculating disparity as the distribution of these variances
+summary(dispRity(dummy_space, metric = quantiles))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 2.461 1.627 2.235 2.761 3.229
-## By default, the quantile calculated is the 95%
-## (i.e. 95% of the data on each axis)
-## this can be changed using the option quantile:
-summary(dispRity(dummy_space, metric = quantiles, quantile = 50))
+## By default, the quantile calculated is the 95%
+## (i.e. 95% of the data on each axis)
+## this can be changed using the option quantile:
+summary(dispRity(dummy_space, metric = quantiles, quantile = 50))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 0.967 0.899 0.951 0.991 1.089
-## Calculating the radius of each dimension in the ordinated space
-radius(dummy_space)
+
## [1] 1.4630780 2.4635449 1.8556785 1.4977898 0.8416318
-## By default the radius is the maximum distance from the centre of
-## the dimension. It can however be changed to any function:
-radius(dummy_space, type = min)
+## By default the radius is the maximum distance from the centre of
+## the dimension. It can however be changed to any function:
+radius(dummy_space, type = min)
## [1] 0.05144054 0.14099827 0.02212226 0.17453525 0.23044528
-radius(dummy_space, type = mean)
+
## [1] 0.6233501 0.7784888 0.7118713 0.6253263 0.5194332
-## Calculating disparity as the mean average radius
-summary(dispRity(dummy_space,
-metric = c(mean, radius),
- type = mean))
+## Calculating disparity as the mean average radius
+summary(dispRity(dummy_space,
+ metric = c(mean, radius),
+ type = mean))
## subsets n obs
## 1 1 10 0.652
The pairwise distances and the neighbours distances uses the function vegan::vegdist
and can take the normal vegdist
options:
-## The average pairwise euclidean distance
-summary(dispRity(dummy_space, metric = c(mean, pairwise.dist)))
+## The average pairwise euclidean distance
+summary(dispRity(dummy_space, metric = c(mean, pairwise.dist)))
## subsets n obs
## 1 1 10 2.539
-## The distribution of the Manhattan distances
-summary(dispRity(dummy_space, metric = pairwise.dist,
-method = "manhattan"))
+## The distribution of the Manhattan distances
+summary(dispRity(dummy_space, metric = pairwise.dist,
+ method = "manhattan"))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 4.427 2.566 3.335 5.672 9.63
-## The average nearest neighbour distances
-summary(dispRity(dummy_space, metric = neighbours))
+
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 1.517 1.266 1.432 1.646 2.787
-## The average furthest neighbour manhattan distances
-summary(dispRity(dummy_space, metric = neighbours,
-which = max, method = "manhattan"))
+## The average furthest neighbour manhattan distances
+summary(dispRity(dummy_space, metric = neighbours,
+ which = max, method = "manhattan"))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 7.895 6.15 6.852 9.402 10.99
+## The overall number of neighbours per point
+summary(dispRity(dummy_space, metric = count.neighbours,
+ relative = FALSE))
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 10 6.5 0.675 4.25 7 7.775
+## The relative number of neigbhours
+## two standard deviations of each element
+summary(dispRity(dummy_space, metric = count.neighbours,
+ radius = function(x)(sd(x)*2),
+ relative = TRUE))
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 10 0.55 0.068 0.3 0.7 0.7
Note that this function is a direct call to vegan::vegdist(matrix, method = method, diag = FALSE, upper = FALSE, ...)
.
The diagonal
function measures the multidimensional diagonal of the whole space (i.e. in our case the longest Euclidean distance in our five dimensional space).
The mode.val
function measures the modal value of the matrix:
-## Calculating the ordinated space's diagonal
-summary(dispRity(dummy_space, metric = diagonal))
+
## subsets n obs
## 1 1 10 3.659
-## Calculating the modal value of the matrix
-summary(dispRity(dummy_space, metric = mode.val))
+
## subsets n obs
## 1 1 10 -2.21
@@ -1207,76 +1274,76 @@ 4.4.7.2 Ranges, variances, quanti
4.4.7.3 Centroids, displacements and ancestral distances metrics
The centroids
metric allows users to measure the position of the different elements compared to a fixed point in the ordinated space.
By default, this function measures the distance between each element and their centroid (centre point):
-## The distribution of the distances between each element and their centroid
-summary(dispRity(dummy_space, metric = centroids))
+## The distribution of the distances between each element and their centroid
+summary(dispRity(dummy_space, metric = centroids))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 1.435 0.788 1.267 1.993 3.167
-## Disparity as the median value of these distances
-summary(dispRity(dummy_space, metric = c(median, centroids)))
+## Disparity as the median value of these distances
+summary(dispRity(dummy_space, metric = c(median, centroids)))
## subsets n obs
## 1 1 10 1.435
It is however possible to fix the coordinates of the centroid to a specific point in the ordinated space, as long as it has the correct number of dimensions:
-## The distance between each element and the origin
-## of the ordinated space
-summary(dispRity(dummy_space, metric = centroids, centroid = 0))
+## The distance between each element and the origin
+## of the ordinated space
+summary(dispRity(dummy_space, metric = centroids, centroid = 0))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 1.487 0.785 1.2 2.044 3.176
-## Disparity as the distance between each element
-## and a specific point in space
-summary(dispRity(dummy_space, metric = centroids,
-centroid = c(0,1,2,3,4)))
+## Disparity as the distance between each element
+## and a specific point in space
+summary(dispRity(dummy_space, metric = centroids,
+ centroid = c(0,1,2,3,4)))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 5.489 4.293 5.032 6.155 6.957
If you have subsets in your dispRity
object, you can also use the matrix.dispRity
(see utilities) and colMeans
to get the centre of a specific subgroup.
For example
-## Create a custom subsets object
- custom.subsets(dummy_space,
- dummy_groups <-group = list("group1" = 1:5,
- "group2" = 6:10))
- summary(dispRity(dummy_groups, metric = centroids,
-centroid = colMeans(get.matrix(dummy_groups, "group1"))))
+## Create a custom subsets object
+dummy_groups <- custom.subsets(dummy_space,
+ group = list("group1" = 1:5,
+ "group2" = 6:10))
+summary(dispRity(dummy_groups, metric = centroids,
+ centroid = colMeans(get.matrix(dummy_groups, "group1"))))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 group1 5 2.011 0.902 1.389 2.284 3.320
## 2 group2 5 1.362 0.760 1.296 1.505 1.985
The displacements
distance is the ratio between the centroids
distance and the centroids
distance with centroid = 0
.
Note that it is possible to measure a ratio from another point than 0
using the reference
argument.
It gives indication of the relative displacement of elements in the multidimensional space: a score >1 signifies a displacement away from the reference. A score of >1 signifies a displacement towards the reference.
-## The relative displacement of the group in space to the centre
-summary(dispRity(dummy_space, metric = displacements))
+## The relative displacement of the group in space to the centre
+summary(dispRity(dummy_space, metric = displacements))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 1.014 0.841 0.925 1.1 1.205
-## The relative displacement of the group to an arbitrary point
-summary(dispRity(dummy_space, metric = displacements,
-reference = c(0,1,2,3,4)))
+## The relative displacement of the group to an arbitrary point
+summary(dispRity(dummy_space, metric = displacements,
+ reference = c(0,1,2,3,4)))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 3.368 2.066 3.19 4.358 7.166
The ancestral.dist
metric works on a similar principle as the centroids
function but changes the centroid to be the coordinates of each element’s ancestor (if to.root = FALSE
; default) or to the root of the tree (to.root = TRUE
).
Therefore this function needs a matrix that contains tips and nodes and a tree as additional argument.
-## A generating a random tree with node labels
- makeNodeLabel(rtree(5), prefix = "n")
- my_tree <-## Adding the tip and node names to the matrix
- dummy_space[-1,]
- dummy_space2 <-rownames(dummy_space2) <- c(my_tree$tip.label,
-$node.label)
- my_tree
-## Calculating the distances from the ancestral nodes
- dispRity(dummy_space2, metric = ancestral.dist,
- ancestral_dist <-tree = my_tree)
-
-## The ancestral distances distributions
-summary(ancestral_dist)
+## A generating a random tree with node labels
+my_tree <- makeNodeLabel(rtree(5), prefix = "n")
+## Adding the tip and node names to the matrix
+dummy_space2 <- dummy_space[-1,]
+rownames(dummy_space2) <- c(my_tree$tip.label,
+ my_tree$node.label)
+
+## Calculating the distances from the ancestral nodes
+ancestral_dist <- dispRity(dummy_space2, metric = ancestral.dist,
+ tree = my_tree)
+
+## The ancestral distances distributions
+summary(ancestral_dist)
## subsets n obs.median 2.5% 25% 75% 97.5%
-## 1 1 9 1.729 0.286 1.653 1.843 3.981
-## Calculating disparity as the sum of the distances from all the ancestral nodes
-summary(dispRity(ancestral_dist, metric = sum))
+## 1 1 9 2.193 0.343 1.729 2.595 3.585
+## Calculating disparity as the sum of the distances from all the ancestral nodes
+summary(dispRity(ancestral_dist, metric = sum))
## subsets n obs
-## 1 1 9 17.28
+## 1 1 9 18.93
4.4.7.4 Minimal spanning tree length
The span.tree.length
uses the vegan::spantree
function to heuristically calculate the minimum spanning tree (the shortest multidimensional tree connecting each elements) and calculates its length as the sum of every branch lengths.
-## The length of the minimal spanning tree
-summary(dispRity(dummy_space, metric = c(sum, span.tree.length)))
+## The length of the minimal spanning tree
+summary(dispRity(dummy_space, metric = c(sum, span.tree.length)))
## subsets n obs
## 1 1 10 15.4
Note that because the solution is heuristic, this metric can take a long time to compute for big matrices.
@@ -1286,17 +1353,17 @@ 4.4.7.5 Functional divergence and
The func.div
and func.eve
functions are based on the FD::dpFD
package.
They are the equivalent to FD::dpFD(matrix)$FDiv
and FD::dpFD(matrix)$FEve
but a bit faster (since they don’t deal with abundance data).
They are pretty straightforward to use:
-## The ratio of deviation from the centroid
-summary(dispRity(dummy_space, metric = func.div))
+
## subsets n obs
## 1 1 10 0.747
-## The minimal spanning tree distances evenness
-summary(dispRity(dummy_space, metric = func.eve))
+
## subsets n obs
## 1 1 10 0.898
-## The minimal spanning tree manhanttan distances evenness
-summary(dispRity(dummy_space, metric = func.eve,
-method = "manhattan"))
+## The minimal spanning tree manhanttan distances evenness
+summary(dispRity(dummy_space, metric = func.eve,
+ method = "manhattan"))
## subsets n obs
## 1 1 10 0.913
@@ -1304,29 +1371,29 @@ 4.4.7.5 Functional divergence and
4.4.7.6 Orientation: angles and deviations
The angles
performs a least square regression (via the lm
function) and returns slope of the main axis of variation for each dimension. This slope can be converted into different units, "slope"
, "degree"
(the default) and "radian"
. This can be changed through the unit
argument.
By default, the angle is measured from the slope 0 (the horizontal line in a 2D plot) but this can be changed through the base
argument (using the defined unit
):
-## The distribution of each angles in degrees for each
-## main axis in the matrix
-summary(dispRity(dummy_space, metric = angles))
+## The distribution of each angles in degrees for each
+## main axis in the matrix
+summary(dispRity(dummy_space, metric = angles))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 21.26 -39.8 3.723 39.47 56
-## The distribution of slopes deviating from the 1:1 slope:
-summary(dispRity(dummy_space, metric = angles, unit = "slope",
-base = 1))
+## The distribution of slopes deviating from the 1:1 slope:
+summary(dispRity(dummy_space, metric = angles, unit = "slope",
+ base = 1))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 1.389 0.118 1.065 1.823 2.514
The deviations
function is based on a similar algorithm as above but measures the deviation from the main axis (or hyperplane) of variation.
In other words, it finds the least square line (for a 2D dataset), plane (for a 3D dataset) or hyperplane (for a >3D dataset) and measures the shortest distances between every points and the line/plane/hyperplane.
By default, the hyperplane is fitted using the least square algorithm from stats::glm
:
-## The distribution of the deviation of each point
-## from the least square hyperplane
-summary(dispRity(dummy_space, metric = deviations))
+## The distribution of the deviation of each point
+## from the least square hyperplane
+summary(dispRity(dummy_space, metric = deviations))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 0.274 0.02 0.236 0.453 0.776
It is also possible to specify the hyperplane equation through the hyperplane
equation. The equation must contain the intercept first and then all the slopes and is interpreted as \(intercept + Ax + By + ... + Nd = 0\). For example, a 2 line defined as beta + intercept (e.g. \(y = 2x + 1\)) should be defined as hyperplane = c(1, 2, 1)
(\(2x - y + 1 = 0\)).
-## The distribution of the deviation of each point
-## from a slope (with only the two first dimensions)
-summary(dispRity(dummy_space[, c(1:2)], metric = deviations,
-hyperplane = c(1, 2, -1)))
+## The distribution of the deviation of each point
+## from a slope (with only the two first dimensions)
+summary(dispRity(dummy_space[, c(1:2)], metric = deviations,
+ hyperplane = c(1, 2, -1)))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 0.516 0.038 0.246 0.763 2.42
Since both the functions angles
and deviations
effectively run a lm
or glm
to estimate slopes or hyperplanes, it is possible to use the option significant = TRUE
to only consider slopes or intercepts that have a slope significantly different than zero using an aov
with a significant threshold of \(p = 0.05\).
@@ -1335,31 +1402,31 @@
4.4.7.6 Orientation: angles and d
4.4.7.7 Projections and phylo projections: elaboration and exploration
-The projections
metric calculates the geometric projection and corresponding rejection of all the rows in a matrix on an arbitrary vector (respectively the distance on and the distance from that vector). The function is based on Aguilera and Pérez-Aguila (2004)’s n-dimensional rotation algorithm to use linear algebra in mutidimensional spaces. The projection or rejection can be seen as respectively the elaboration and exploration scores on a trajectory (sensu Endler et al. (2005)).
+The projections
metric calculates the geometric projection and corresponding rejection of all the rows in a matrix on an arbitrary vector (respectively the distance on and the distance from that vector). The function is based on Aguilera and Pérez-Aguila (2004)’s n-dimensional rotation algorithm to use linear algebra in mutidimensional spaces. The projection or rejection can be seen as respectively the elaboration and exploration scores on a trajectory (sensu Endler et al. (2005)).
By default, the vector (e.g. a trajectory, an axis), on which the data is projected is the one going from the centre of the space (coordinates 0,0, …) and the centroid of the matrix.
However, we advice you do define this axis to something more meaningful using the point1
and point2
options, to create the vector (the vector’s norm will be dist(point1, point2)
and its direction will be from point1
towards point2
).
-## The elaboration on the axis defined by the first and
-## second row in the dummy_space
-summary(dispRity(dummy_space, metric = projections,
-point1 = dummy_space[1,],
- point2 = dummy_space[2,]))
+## The elaboration on the axis defined by the first and
+## second row in the dummy_space
+summary(dispRity(dummy_space, metric = projections,
+ point1 = dummy_space[1,],
+ point2 = dummy_space[2,]))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 0.998 0.118 0.651 1.238 1.885
-## The exploration on the same axis
-summary(dispRity(dummy_space, metric = projections,
-point1 = dummy_space[1,],
- point2 = dummy_space[2,],
- measure = "distance"))
+## The exploration on the same axis
+summary(dispRity(dummy_space, metric = projections,
+ point1 = dummy_space[1,],
+ point2 = dummy_space[2,],
+ measure = "distance"))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 0.719 0 0.568 0.912 1.65
By default, the vector (point1, point2)
is used as unit vector of the projections (i.e. the Euclidean distance between (point1, point2)
is set to 1) meaning that a projection value ("distance"
or "position"
) of X means X times the distance between point1
and point2
.
If you want use the unit vector of the input matrix or are using a space where Euclidean distances are non-sensical, you can remove this option using scale = FALSE
:
-## The elaboration on the same axis using the dummy_space's
-## unit vector
-summary(dispRity(dummy_space, metric = projections,
-point1 = dummy_space[1,],
- point2 = dummy_space[2,],
- scale = FALSE))
+## The elaboration on the same axis using the dummy_space's
+## unit vector
+summary(dispRity(dummy_space, metric = projections,
+ point1 = dummy_space[1,],
+ point2 = dummy_space[2,],
+ scale = FALSE))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 4.068 0.481 2.655 5.05 7.685
The projections.tree
is the same as the projections
metric but allows to determine the vector ((point1, point2)
) using a tree rather than manually entering these points.
@@ -1377,65 +1444,64 @@
4.4.7.7 Projections and phylo pro
or a user defined function that with the inputs matrix
and phy
and row
(the element’s ID, i.e. the row number in matrix
).
For example, if you want to measure the projection of each element in the matrix (tips and nodes) on the axis from the root of the tree to each element’s most recent ancestor, you can define the vector as type = c("root", "ancestor")
.
-## Adding a extra row to dummy matrix (to match dummy_tree)
- rbind(dummy_space, root = rnorm(5))
- tree_space <-## Creating a random dummy tree (with labels matching the ones from tree_space)
- rtree(6)
- dummy_tree <-$tip.label <- rownames(tree_space)[1:6]
- dummy_tree$node.label <- rownames(tree_space)[rev(7:11)]
- dummy_tree
-## Measuring the disparity as the projection of each element
-## on its root-ancestor vector
-summary(dispRity(tree_space, metric = projections.tree,
-tree = dummy_tree,
- type = c("root", "ancestor")))
+## Adding a extra row to dummy matrix (to match dummy_tree)
+tree_space <- rbind(dummy_space, root = rnorm(5))
+## Creating a random dummy tree (with labels matching the ones from tree_space)
+dummy_tree <- rtree(6)
+dummy_tree$tip.label <- rownames(tree_space)[1:6]
+dummy_tree$node.label <- rownames(tree_space)[rev(7:11)]
+
+## Measuring the disparity as the projection of each element
+## on its root-ancestor vector
+summary(dispRity(tree_space, metric = projections.tree,
+ tree = dummy_tree,
+ type = c("root", "ancestor")))
## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to
## max; returning -Inf
-
## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to
## max; returning -Inf
-## subsets n obs.median 2.5% 25% 75% 97.5%
-## 1 1 11 NA 0.229 0.416 0.712 1.016
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 11 NA -0.7 -0.196 0.908 1.774
Of course you can also use any other options from the projections function:
-## A user defined function that's returns the centroid of
-## the first three nodes
- function(matrix, tree, row = NULL) {
- fun.root <-return(colMeans(matrix[tree$node.label[1:3], ]))
-
- }## Measuring the unscaled rejection from the vector from the
-## centroid of the three first nodes
-## to the coordinates of the first tip
-summary(dispRity(tree_space, metric = projections.tree,
-tree = dummy_tree,
- measure = "distance",
- type = list(fun.root,
- 1, ]))) tree_space[
-## subsets n obs.median 2.5% 25% 75% 97.5%
-## 1 1 11 0.606 0.064 0.462 0.733 0.999
+## A user defined function that's returns the centroid of
+## the first three nodes
+fun.root <- function(matrix, tree, row = NULL) {
+ return(colMeans(matrix[tree$node.label[1:3], ]))
+}
+## Measuring the unscaled rejection from the vector from the
+## centroid of the three first nodes
+## to the coordinates of the first tip
+summary(dispRity(tree_space, metric = projections.tree,
+ tree = dummy_tree,
+ measure = "distance",
+ type = list(fun.root,
+ tree_space[1, ])))
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 11 0.763 0.07 0.459 0.873 1.371
4.4.7.8 Roundness
The roundness coefficient (or metric) ranges between 0 and 1 and expresses the distribution of and ellipse’ major axis ranging from 1, a totally round ellipse (i.e. a circle) to 0 a totally flat ellipse (i.e. a line). A value of \(0.5\) represents a regular ellipse where each major axis is half the size of the previous major axis. A value \(> 0.5\) describes a pancake where the major axis distribution is convex (values close to 1 can be pictured in 3D as a cr`{e}pes with the first two axis being rather big - a circle - and the third axis being particularly thin; values closer to \(0.5\) can be pictured as flying saucers). Conversely, a value \(< 0.5\) describes a cigar where the major axis distribution is concave (values close to 0 can be pictured in 3D as a spaghetti with the first axis rather big and the two next ones being small; values closer to \(0.5\) can be pictured in 3D as a fat cigar).
This is what it looks for example for three simulated variance-covariance matrices in 3D:
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
4.4.7.9 Between group metrics
@@ -1449,23 +1515,23 @@ 4.4.7.9.1 group.dist
For example, one might be interested in only considering the 95% CI for each group.
This can be done through the option probs = c(0.025, 0.975)
that is passed to the quantile
function.
It is also possible to use this function to measure the distance between the groups centroids by calculating the 50% quantile (probs = c(0.5)
).
-## Creating a dispRity object with two groups
- custom.subsets(dummy_space,
- grouped_space <-group = list(c(1:5), c(6:10)))
-
-## Measuring the minimum distance between both groups
-summary(dispRity(grouped_space, metric = group.dist,
-between.groups = TRUE))
+## Creating a dispRity object with two groups
+grouped_space <- custom.subsets(dummy_space,
+ group = list(c(1:5), c(6:10)))
+
+## Measuring the minimum distance between both groups
+summary(dispRity(grouped_space, metric = group.dist,
+ between.groups = TRUE))
## subsets n_1 n_2 obs
## 1 1:2 5 5 0
-## Measuring the centroid distance between both groups
-summary(dispRity(grouped_space, metric = group.dist,
-between.groups = TRUE, probs = 0.5))
+## Measuring the centroid distance between both groups
+summary(dispRity(grouped_space, metric = group.dist,
+ between.groups = TRUE, probs = 0.5))
## subsets n_1 n_2 obs
## 1 1:2 5 5 0.708
-## Measuring the distance between both group's 75% CI
-summary(dispRity(grouped_space, metric = group.dist,
-between.groups = TRUE, probs = c(0.25, 0.75)))
+## Measuring the distance between both group's 75% CI
+summary(dispRity(grouped_space, metric = group.dist,
+ between.groups = TRUE, probs = c(0.25, 0.75)))
## subsets n_1 n_2 obs
## 1 1:2 5 5 0.059
@@ -1475,25 +1541,25 @@ 4.4.7.9.2 point.dist
By default this point is the centroid but can be any point defined by a function passed to the point
argument.
For example, the centroid of matrix2
is the mean of each column of that matrix so point = colMeans
(default).
This function also takes the method
argument like previous one described above to measure either the "euclidean"
(default) or the "manhattan"
distances:
-## Measuring the distance between the elements of the first group
-## and the centroid of the second group
-summary(dispRity(grouped_space, metric = point.dist,
-between.groups = TRUE))
+## Measuring the distance between the elements of the first group
+## and the centroid of the second group
+summary(dispRity(grouped_space, metric = point.dist,
+ between.groups = TRUE))
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
## 1 1:2 5 5 2.182 1.304 1.592 2.191 3.355
-## Measuring the distance between the elements of the second group
-## and the centroid of the first group
-summary(dispRity(grouped_space, metric = point.dist,
-between.groups = list(c(2,1))))
+## Measuring the distance between the elements of the second group
+## and the centroid of the first group
+summary(dispRity(grouped_space, metric = point.dist,
+ between.groups = list(c(2,1))))
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
## 1 2:1 5 5 1.362 0.76 1.296 1.505 1.985
-## Measuring the distance between the elements of the first group
-## a point defined as the standard deviation of each column
-## in the second group
- function(matrix2) {apply(matrix2, 2, sd)}
- sd.point <-summary(dispRity(grouped_space, metric = point.dist,
-point = sd.point, method = "manhattan",
- between.groups = TRUE))
+## Measuring the distance between the elements of the first group
+## a point defined as the standard deviation of each column
+## in the second group
+sd.point <- function(matrix2) {apply(matrix2, 2, sd)}
+summary(dispRity(grouped_space, metric = point.dist,
+ point = sd.point, method = "manhattan",
+ between.groups = TRUE))
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
## 1 1:2 5 5 4.043 2.467 3.567 4.501 6.884
@@ -1503,58 +1569,58 @@ 4.4.7.9.3 projections.betwe
Both are based on the projections
metric and can take the same optional arguments (more info here).
The examples and explanations below are based on the default arguments but it is possible (and easy!) to change them.
We are going to use the charadriiformes
example for both metrics (see more about that here).
-## Loading the charadriiformes data
-data(charadriiformes)
-
-## Creating the dispRity object (see the #covar section in the manual for more info)
- MCMCglmm.subsets(n = 50,
- my_covar <-data = charadriiformes$data,
- posteriors = charadriiformes$posteriors,
- group = MCMCglmm.levels(charadriiformes$posteriors)[1:4],
- tree = charadriiformes$tree,
- rename.groups = c(levels(charadriiformes$data$clade), "phylogeny"))
+## Loading the charadriiformes data
+data(charadriiformes)
+
+## Creating the dispRity object (see the #covar section in the manual for more info)
+my_covar <- MCMCglmm.subsets(n = 50,
+ data = charadriiformes$data,
+ posteriors = charadriiformes$posteriors,
+ group = MCMCglmm.levels(charadriiformes$posteriors)[1:4],
+ tree = charadriiformes$tree,
+ rename.groups = c(levels(charadriiformes$data$clade), "phylogeny"))
The first metric, projections.between
projects the major axis of one group (matrix
) onto the major axis of another one (matrix2
).
For example we might want to know how some groups compare in terms of angle (orientation) to a base group:
-## Creating the list of groups to compare
- list(c("gulls", "phylogeny"),
- comparisons_list <-c("plovers", "phylogeny"),
- c("sandpipers", "phylogeny"))
-
-## Measuring the angles between each groups
-## (note that we set the metric as.covar, more on that in the #covar section below)
- dispRity(data = my_covar,
- groups_angles <-metric = as.covar(projections.between),
- between.groups = comparisons_list,
- measure = "degree")
- ## And here are the angles in degrees:
-summary(groups_angles)
+## Creating the list of groups to compare
+comparisons_list <- list(c("gulls", "phylogeny"),
+ c("plovers", "phylogeny"),
+ c("sandpipers", "phylogeny"))
+
+## Measuring the angles between each groups
+## (note that we set the metric as.covar, more on that in the #covar section below)
+groups_angles <- dispRity(data = my_covar,
+ metric = as.covar(projections.between),
+ between.groups = comparisons_list,
+ measure = "degree")
+## And here are the angles in degrees:
+summary(groups_angles)
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
-## 1 gulls:phylogeny 159 359 8.25 2.101 6.25 14.98 41.8
-## 2 plovers:phylogeny 98 359 33.75 5.700 16.33 75.50 131.5
-## 3 sandpipers:phylogeny 102 359 10.79 3.876 8.10 16.59 95.9
+## 1 gulls:phylogeny 159 359 9.39 2.480 5.95 16.67 43.2
+## 2 plovers:phylogeny 98 359 20.42 4.500 12.36 51.31 129.8
+## 3 sandpipers:phylogeny 102 359 10.82 1.777 7.60 13.89 43.0
The second metric, disalignment
rejects the centroid of a group (matrix
) onto the major axis of another one (matrix2
).
This allows to measure wether the center of a group is aligned with the major axis of another.
A disalignement value of 0 means that the groups are aligned. A higher disalignment value means the groups are more and more disaligned.
We can use the same set of comparisons as in the projections.between
examples to measure which group is most aligned (less disaligned) with the phylogenetic major axis:
-## Measuring the disalignement of each group
- dispRity(data = my_covar,
- groups_alignement <-metric = as.covar(disalignment),
- between.groups = comparisons_list)
- ## And here are the groups alignment (0 = aligned)
-summary(groups_alignement)
+## Measuring the disalignement of each group
+groups_alignement <- dispRity(data = my_covar,
+ metric = as.covar(disalignment),
+ between.groups = comparisons_list)
+## And here are the groups alignment (0 = aligned)
+summary(groups_alignement)
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
-## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.015
+## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.021
## 2 plovers:phylogeny 98 359 0.001 0.000 0.001 0.001 0.006
-## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.003 0.009
+## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.005 0.018
4.4.8 Which disparity metric to choose?
The disparity metric that gives the most consistent results is the following one:
- function() return(42) best.metric <-
+
Joke aside, this is a legitimate question that has no simple answer: it depends on the dataset and question at hand.
-Thoughts on which metric to choose can be find in Thomas Guillerme, Puttick, et al. (2020) and Thomas Guillerme, Cooper, et al. (2020) but again, will ultimately depend on the question and dataset.
+Thoughts on which metric to choose can be find in Thomas Guillerme, Puttick, et al. (2020) and Thomas Guillerme, Cooper, et al. (2020) but again, will ultimately depend on the question and dataset.
The question should help figuring out which type of metric is desired: for example, in the question “does the extinction released niches for mammals to evolve”, the metric in interest should probably pick up a change in size in the trait space (the release could result in some expansion of the mammalian morphospace); or if the question is “does group X compete with group Y”, maybe the metric of interested should pick up changes in position (group X can be displaced by group Y).
In order to visualise what signal different disparity metrics are picking, you can use the moms
that come with a detailed manual on how to use it.
Alternatively, you can use the test.metric
function:
@@ -1562,39 +1628,39 @@ 4.4.8 Which disparity metric to c
4.4.8.1 test.metric
This function allows to test whether a metric picks different changes in disparity. It intakes the space on which to test the metric, the disparity metric and the type of changes to apply gradually to the space.
Basically this is a type of biased data rarefaction (or non-biased for "random"
) to see how the metric reacts to specific changes in trait space.
-## Creating a 2D uniform space
- space.maker(300, 2, runif)
- example_space <-
-## Testing the product of ranges metric on the example space
- test.metric(example_space, metric = c(prod, ranges),
- example_test <-shifts = c("random", "size"))
-By default, the test runs three replicates of space reduction as described in Thomas Guillerme, Puttick, et al. (2020) by gradually removing 10% of the data points following the different algorithms from Thomas Guillerme, Puttick, et al. (2020) (here the "random"
reduction and the "size"
) reduction, resulting in a dispRity
object that can be summarised or plotted.
+
## Creating a 2D uniform space
+example_space <- space.maker(300, 2, runif)
+
+## Testing the product of ranges metric on the example space
+example_test <- test.metric(example_space, metric = c(prod, ranges),
+ shifts = c("random", "size"))
+By default, the test runs three replicates of space reduction as described in Thomas Guillerme, Puttick, et al. (2020) by gradually removing 10% of the data points following the different algorithms from Thomas Guillerme, Puttick, et al. (2020) (here the "random"
reduction and the "size"
) reduction, resulting in a dispRity
object that can be summarised or plotted.
The number of replicates can be changed using the replicates
option.
Still by default, the function then runs a linear model on the simulated data to measure some potential trend in the changes in disparity.
The model can be changed using the model
option.
Finally, the function runs 10 reductions by default from keeping 10% of the data (removing 90%) and way up to keeping 100% of the data (removing 0%).
This can be changed using the steps
option.
A good disparity metric for your dataset will typically have no trend in the "random"
reduction (the metric is ideally not affected by sample size) but should have a trend for the reduction of interest.
-## The results as a dispRity object
- example_test
+
## Metric testing:
## The following metric was tested: c(prod, ranges).
## The test was run on the random, size shifts for 3 replicates using the following model:
## lm(disparity ~ reduction, data = data)
## Use summary(x) or plot(x) for more details.
-## Summarising these results
-summary(example_test)
+
## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope
-## random 0.84 0.88 0.94 0.95 0.96 0.98 0.97 0.98 0.96 0.98 1.450100e-03
-## size.increase 0.10 0.21 0.31 0.45 0.54 0.70 0.78 0.94 0.96 0.98 1.054925e-02
-## size.hollowness 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 1.453782e-05
+## random 0.94 0.97 0.94 0.97 0.98 0.98 0.99 0.99 0.99 0.99 6.389477e-04
+## size.increase 0.11 0.21 0.38 0.54 0.68 0.79 0.87 0.93 0.98 0.99 1.040938e-02
+## size.hollowness 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1.880225e-05
## p_value R^2(adj)
-## random 2.439179e-06 0.5377136
-## size.increase 4.450564e-25 0.9783976
-## size.hollowness 1.925262e-05 0.4664502
-## Or visualising them
-plot(example_test)
-
+## random 5.891773e-06 0.5084747
+## size.increase 4.331947e-19 0.9422289
+## size.hollowness 3.073793e-03 0.2467532
+
+
@@ -1605,60 +1671,60 @@ 4.5 Summarising dispRity data (pl
4.5.1 Summarising dispRity
data
This function is an S3 function (summary.dispRity
) allowing users to summarise the content of dispRity
objects that contain disparity calculations.
-## Example data from previous sections
- custom.subsets(BeckLee_mat50,
- crown_stem <-group = crown.stem(BeckLee_tree,
- inc.nodes = FALSE))
- ## Bootstrapping and rarefying these groups
- boot.matrix(crown_stem, bootstraps = 100,
- boot_crown_stem <-rarefaction = TRUE)
- ## Calculate disparity
- dispRity(boot_crown_stem,
- disparity_crown_stem <-metric = c(sum, variances))
-
-## Creating time slice subsets
- chrono.subsets(data = BeckLee_mat99,
- time_slices <-tree = BeckLee_tree,
- method = "continuous",
- model = "proximity",
- time = c(120, 80, 40, 0),
- FADLAD = BeckLee_ages)
- ## Bootstrapping the time slice subsets
- boot.matrix(time_slices, bootstraps = 100)
- boot_time_slices <-## Calculate disparity
- dispRity(boot_time_slices,
- disparity_time_slices <-metric = c(sum, variances))
-
-## Creating time bin subsets
- chrono.subsets(data = BeckLee_mat99,
- time_bins <-tree = BeckLee_tree,
- method = "discrete",
- time = c(120, 80, 40, 0),
- FADLAD = BeckLee_ages,
- inc.nodes = TRUE)
- ## Bootstrapping the time bin subsets
- boot.matrix(time_bins, bootstraps = 100)
- boot_time_bins <-## Calculate disparity
- dispRity(boot_time_bins,
- disparity_time_bins <-metric = c(sum, variances))
+## Example data from previous sections
+crown_stem <- custom.subsets(BeckLee_mat50,
+ group = crown.stem(BeckLee_tree,
+ inc.nodes = FALSE))
+## Bootstrapping and rarefying these groups
+boot_crown_stem <- boot.matrix(crown_stem, bootstraps = 100,
+ rarefaction = TRUE)
+## Calculate disparity
+disparity_crown_stem <- dispRity(boot_crown_stem,
+ metric = c(sum, variances))
+
+## Creating time slice subsets
+time_slices <- chrono.subsets(data = BeckLee_mat99,
+ tree = BeckLee_tree,
+ method = "continuous",
+ model = "proximity",
+ time = c(120, 80, 40, 0),
+ FADLAD = BeckLee_ages)
+## Bootstrapping the time slice subsets
+boot_time_slices <- boot.matrix(time_slices, bootstraps = 100)
+## Calculate disparity
+disparity_time_slices <- dispRity(boot_time_slices,
+ metric = c(sum, variances))
+
+## Creating time bin subsets
+time_bins <- chrono.subsets(data = BeckLee_mat99,
+ tree = BeckLee_tree,
+ method = "discrete",
+ time = c(120, 80, 40, 0),
+ FADLAD = BeckLee_ages,
+ inc.nodes = TRUE)
+## Bootstrapping the time bin subsets
+boot_time_bins <- boot.matrix(time_bins, bootstraps = 100)
+## Calculate disparity
+disparity_time_bins <- dispRity(boot_time_bins,
+ metric = c(sum, variances))
These objects are easy to summarise as follows:
-## Default summary
-summary(disparity_time_slices)
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 3.258 2.675 1.264 2.436 2.948 3.085
-## 2 80 19 3.491 3.315 3.128 3.266 3.362 3.453
-## 3 40 15 3.677 3.453 3.157 3.349 3.547 3.681
-## 4 0 10 4.092 3.726 3.293 3.578 3.828 3.950
+## 1 120 5 3.126 2.556 1.446 2.365 2.799 2.975
+## 2 80 19 3.351 3.188 3.019 3.137 3.235 3.291
+## 3 40 15 3.538 3.346 3.052 3.226 3.402 3.538
+## 4 0 10 3.934 3.601 3.219 3.446 3.681 3.819
Information about the number of elements in each subset and the observed (i.e. non-bootstrapped) disparity are also calculated.
This is specifically handy when rarefying the data for example:
-head(summary(disparity_crown_stem))
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 crown 30 2.526 2.441 2.367 2.420 2.466 2.487
-## 2 crown 29 NA 2.449 2.354 2.428 2.468 2.490
-## 3 crown 28 NA 2.441 2.385 2.422 2.457 2.485
-## 4 crown 27 NA 2.442 2.363 2.411 2.465 2.490
-## 5 crown 26 NA 2.438 2.350 2.416 2.458 2.494
-## 6 crown 25 NA 2.447 2.359 2.423 2.471 2.496
+## 1 crown 30 2.526 2.444 2.374 2.420 2.466 2.490
+## 2 crown 29 NA 2.454 2.387 2.427 2.470 2.490
+## 3 crown 28 NA 2.443 2.387 2.423 2.462 2.489
+## 4 crown 27 NA 2.440 2.366 2.417 2.468 2.493
+## 5 crown 26 NA 2.442 2.357 2.408 2.459 2.492
+## 6 crown 25 NA 2.445 2.344 2.425 2.469 2.490
The summary functions can also take various options such as:
quantiles
values for the confidence interval levels (by default, the 50 and 95 quantiles are calculated)
@@ -1667,31 +1733,31 @@ 4.5.1 Summarising dispRity<
recall
option for printing the call of the dispRity
object as well (default is FALSE
)
These options can easily be changed from the defaults as follows:
-## Same as above but using the 88th quantile and the standard deviation as the summary
-summary(disparity_time_slices, quantiles = 88, cent.tend = sd)
+## Same as above but using the 88th quantile and the standard deviation as the summary
+summary(disparity_time_slices, quantiles = 88, cent.tend = sd)
## subsets n obs bs.sd 6% 94%
-## 1 120 5 3.258 0.426 1.864 3.075
-## 2 80 19 3.491 0.084 3.156 3.435
-## 3 40 15 3.677 0.149 3.231 3.650
-## 4 0 10 4.092 0.195 3.335 3.904
-## Printing the details of the object and digits the values to the 5th decimal place
-summary(disparity_time_slices, recall = TRUE, digits = 5)
+## 1 120 5 3.126 0.366 2.043 2.947
+## 2 80 19 3.351 0.072 3.048 3.277
+## 3 40 15 3.538 0.133 3.095 3.525
+## 4 0 10 3.934 0.167 3.292 3.776
+## Printing the details of the object and digits the values to the 5th decimal place
+summary(disparity_time_slices, recall = TRUE, digits = 5)
## ---- dispRity object ----
## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
## 120, 80, 40, 0.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: c(sum, variances).
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 3.25815 2.67517 1.26366 2.43637 2.94780 3.08485
-## 2 80 19 3.49145 3.31487 3.12837 3.26601 3.36182 3.45336
-## 3 40 15 3.67702 3.45329 3.15729 3.34867 3.54670 3.68134
-## 4 0 10 4.09234 3.72554 3.29285 3.57797 3.82814 3.95046
+## 1 120 5 3.12580 2.55631 1.44593 2.36454 2.79905 2.97520
+## 2 80 19 3.35072 3.18751 3.01906 3.13720 3.23534 3.29113
+## 3 40 15 3.53811 3.34647 3.05242 3.22616 3.40199 3.53793
+## 4 0 10 3.93353 3.60071 3.21947 3.44555 3.68095 3.81856
Note that the summary table is a data.frame
, hence it is as easy to modify as any dataframe using dplyr
.
You can also export it in csv
format using write.csv
or write_csv
or even directly export into LaTeX
format using the following;
-## Loading the xtable package
-require(xtable)
-## Converting the table in LaTeX
-xtable(summary(disparity_time_slices))
+
4.5.2 Plotting dispRity
data
@@ -1708,80 +1774,80 @@ 4.5.2 Plotting dispRity
It is also possible to display the number of elements in each subset (as a horizontal dotted line) using the option elements = TRUE
.
Additionally, when the data is rarefied, one can indicate which level of rarefaction to display (i.e. only display the results for a certain number of elements) by using the rarefaction
argument.
-## Graphical parameters
- par(mfrow = c(2, 2), bty = "n")
- op <-
-## Plotting continuous disparity results
-plot(disparity_time_slices, type = "continuous")
-
-## Plotting discrete disparity results
-plot(disparity_crown_stem, type = "box")
-
-## As above but using lines for the rarefaction level of 20 elements only
-plot(disparity_crown_stem, type = "line", rarefaction = 20)
-
-## As above but using polygons while also displaying the number of elements
-plot(disparity_crown_stem, type = "polygon", elements = TRUE)
-
-## Resetting graphical parameters
-par(op)
-Since plot.dispRity
uses the arguments from the generic plot
method, it is of course possible to change pretty much everything using the regular plot arguments:
-## Graphical options
- par(bty = "n")
- op <-
-## Plotting the results with some classic options from plot
-plot(disparity_time_slices, col = c("blue", "orange", "green"),
-ylab = c("Some measurement"), xlab = "Some other measurement",
- main = "Many options...", ylim = c(10, 0), xlim = c(4, 0))
-
-## Adding a legend
-legend("topleft", legend = c("Central tendency",
-"Confidence interval 1",
- "Confidence interval 2"),
- col = c("blue", "orange", "green"), pch = 19)
+## Graphical parameters
+op <- par(mfrow = c(2, 2), bty = "n")
+
+## Plotting continuous disparity results
+plot(disparity_time_slices, type = "continuous")
+
+## Plotting discrete disparity results
+plot(disparity_crown_stem, type = "box")
+
+## As above but using lines for the rarefaction level of 20 elements only
+plot(disparity_crown_stem, type = "line", rarefaction = 20)
+
+## As above but using polygons while also displaying the number of elements
+plot(disparity_crown_stem, type = "polygon", elements = TRUE)
-## Resetting graphical parameters
-par(op)
-In addition to the classic plot
arguments, the function can also take arguments that are specific to plot.dispRity
like adding the number of elements or rarefaction level (as described above), and also changing the values of the quantiles to plot as well as the central tendency.
-## Graphical options
- par(bty = "n")
- op <-
-## Plotting the results with some plot.dispRity arguments
-plot(disparity_time_slices,
-quantiles = c(seq(from = 10, to = 100, by = 10)),
- cent.tend = sd, type = "c", elements = TRUE,
- col = c("black", rainbow(10)),
- ylab = c("Disparity", "Diversity"),
- xlab = "Time (in in units from past to present)",
- observed = TRUE,
- main = "Many more options...")
+
+Since plot.dispRity
uses the arguments from the generic plot
method, it is of course possible to change pretty much everything using the regular plot arguments:
+## Graphical options
+op <- par(bty = "n")
+
+## Plotting the results with some classic options from plot
+plot(disparity_time_slices, col = c("blue", "orange", "green"),
+ ylab = c("Some measurement"), xlab = "Some other measurement",
+ main = "Many options...", ylim = c(10, 0), xlim = c(4, 0))
+
+## Adding a legend
+legend("topleft", legend = c("Central tendency",
+ "Confidence interval 1",
+ "Confidence interval 2"),
+ col = c("blue", "orange", "green"), pch = 19)
-## Resetting graphical parameters
-par(op)
+
+In addition to the classic plot
arguments, the function can also take arguments that are specific to plot.dispRity
like adding the number of elements or rarefaction level (as described above), and also changing the values of the quantiles to plot as well as the central tendency.
+## Graphical options
+op <- par(bty = "n")
+
+## Plotting the results with some plot.dispRity arguments
+plot(disparity_time_slices,
+ quantiles = c(seq(from = 10, to = 100, by = 10)),
+ cent.tend = sd, type = "c", elements = TRUE,
+ col = c("black", rainbow(10)),
+ ylab = c("Disparity", "Diversity"),
+ xlab = "Time (in in units from past to present)",
+ observed = TRUE,
+ main = "Many more options...")
+
+
Note that the argument observed = TRUE
allows to plot the disparity values calculated from the non-bootstrapped data as crosses on the plot.
For comparing results, it is also possible to add a plot to the existent plot by using add = TRUE
:
-## Graphical options
- par(bty = "n")
- op <-
-## Plotting the continuous disparity with a fixed y axis
-plot(disparity_time_slices, ylim = c(3, 9))
-## Adding the discrete data
-plot(disparity_time_bins, type = "line", ylim = c(3, 9),
-xlab = "", ylab = "", add = TRUE)
-
-## Resetting graphical parameters
-par(op)
-Finally, if your data has been fully rarefied, it is also possible to easily look at rarefaction curves by using the rarefaction = TRUE
argument:
-## Graphical options
- par(bty = "n")
- op <-
-## Plotting the rarefaction curves
-plot(disparity_crown_stem, rarefaction = TRUE)
+## Graphical options
+op <- par(bty = "n")
+
+## Plotting the continuous disparity with a fixed y axis
+plot(disparity_time_slices, ylim = c(3, 9))
+## Adding the discrete data
+plot(disparity_time_bins, type = "line", ylim = c(3, 9),
+ xlab = "", ylab = "", add = TRUE)
-## Resetting graphical parameters
-par(op)
+
+Finally, if your data has been fully rarefied, it is also possible to easily look at rarefaction curves by using the rarefaction = TRUE
argument:
+
+
+
4.5.3 type = preview
@@ -1790,41 +1856,41 @@ 4.5.3 type = preview
This can be done by plotting dispRity
objects with no calculated disparity!
For example, we might be interested in looking at how the distribution of elements change as a function of the distributions of different sub-settings.
For example custom subsets vs. time subsets:
-## Making the different subsets
- custom.subsets(BeckLee_mat99,
- cust_subsets <-crown.stem(BeckLee_tree,
- inc.nodes = TRUE))
- chrono.subsets(BeckLee_mat99,
- time_subsets <-tree = BeckLee_tree,
- method = "discrete",
- time = 5)
-
-## Note that no disparity has been calculated here:
-is.null(cust_subsets$disparity)
+## Making the different subsets
+cust_subsets <- custom.subsets(BeckLee_mat99,
+ crown.stem(BeckLee_tree,
+ inc.nodes = TRUE))
+time_subsets <- chrono.subsets(BeckLee_mat99,
+ tree = BeckLee_tree,
+ method = "discrete",
+ time = 5)
+
+## Note that no disparity has been calculated here:
+is.null(cust_subsets$disparity)
## [1] TRUE
-is.null(time_subsets$disparity)
+
## [1] TRUE
-## But we can still plot both spaces by using the default plot functions
-par(mfrow = c(1,2))
-## Default plotting
-plot(cust_subsets)
-## Plotting with more arguments
-plot(time_subsets, specific.args = list(dimensions = c(1,2)),
-main = "Some \"low\" dimensions")
-
+## But we can still plot both spaces by using the default plot functions
+par(mfrow = c(1,2))
+## Default plotting
+plot(cust_subsets)
+## Plotting with more arguments
+plot(time_subsets, specific.args = list(dimensions = c(1,2)),
+ main = "Some \"low\" dimensions")
+
DISCLAIMER: This functionality can be handy for exploring the data (e.g. to visually check whether the subset attribution worked) but it might be misleading on how the data is actually distributed in the multidimensional space!
Groups that don’t overlap on two set dimensions can totally overlap in all other dimensions!
For dispRity
objects that do contain disparity data, the default option is to plot your disparity data.
However you can always force the preview
option using the following:
-par(mfrow = c(2,1))
-## Default plotting
-plot(disparity_time_slices, main = "Disparity through time")
-## Plotting with more arguments
-plot(disparity_time_slices, type = "preview",
-main = "Two first dimensions of the trait space")
-
+
+
4.5.4 Graphical options with ...
@@ -1834,36 +1900,36 @@ 4.5.4 Graphical options with points), you can decide to colour everything in blue using the normal col = "blue"
option.
But you can also decide to only colour the circles in blue using points.col = "blue"
!
Here is an example with multiple elements (lines and points) taken from the disparity with trees section below:
-## Loading some demo data:
-## An ordinated matrix with node and tip labels
-data(BeckLee_mat99)
-## The corresponding tree with tip and node labels
-data(BeckLee_tree)
-## A list of tips ages for the fossil data
-data(BeckLee_ages)
-
-## Time slicing through the tree using the equal split algorithm
- chrono.subsets(data = BeckLee_mat99,
- time_slices <-tree = BeckLee_tree,
- FADLAD = BeckLee_ages,
- method = "continuous",
- model = "acctran",
- time = 15)
-
-par(mfrow = c(2,2))
-## The preview plot with the tree using only defaults
-plot(time_slices, type = "preview", specific.args = list(tree = TRUE))
-## The same plot but by applying general options
-plot(time_slices, type = "preview", specific.args = list(tree = TRUE),
-col = "blue", main = "General options")
- ## The same plot but by applying the colour only to the lines
-## and change of shape only to the points
-plot(time_slices, type = "preview", specific.args = list(tree = TRUE),
-lines.col = "blue", points.pch = 15, main = "Specific options")
- ## And now without the legend
-plot(time_slices, type = "preview", specific.args = list(tree = TRUE),
-lines.col = "blue", points.pch = 15, legend = FALSE)
-
+## Loading some demo data:
+## An ordinated matrix with node and tip labels
+data(BeckLee_mat99)
+## The corresponding tree with tip and node labels
+data(BeckLee_tree)
+## A list of tips ages for the fossil data
+data(BeckLee_ages)
+
+## Time slicing through the tree using the equal split algorithm
+time_slices <- chrono.subsets(data = BeckLee_mat99,
+ tree = BeckLee_tree,
+ FADLAD = BeckLee_ages,
+ method = "continuous",
+ model = "acctran",
+ time = 15)
+
+par(mfrow = c(2,2))
+## The preview plot with the tree using only defaults
+plot(time_slices, type = "preview", specific.args = list(tree = TRUE))
+## The same plot but by applying general options
+plot(time_slices, type = "preview", specific.args = list(tree = TRUE),
+ col = "blue", main = "General options")
+## The same plot but by applying the colour only to the lines
+## and change of shape only to the points
+plot(time_slices, type = "preview", specific.args = list(tree = TRUE),
+ lines.col = "blue", points.pch = 15, main = "Specific options")
+## And now without the legend
+plot(time_slices, type = "preview", specific.args = list(tree = TRUE),
+ lines.col = "blue", points.pch = 15, legend = FALSE)
+
@@ -1887,149 +1953,147 @@ 4.6 Testing disparity hypotheses<
Note that the test.dispRity
algorithm deals with some classical test outputs (h.test
, lm
and numeric
vector) and summarises the test output.
It is, however, possible to get the full detailed output by using the options details = TRUE
.
Here we are using the variables generated in the section above:
-## T-test to test for a difference in disparity between crown and stem mammals
-test.dispRity(disparity_crown_stem, test = t.test)
+## T-test to test for a difference in disparity between crown and stem mammals
+test.dispRity(disparity_crown_stem, test = t.test)
## [[1]]
## statistic: t
-## crown : stem 57.38116
+## crown : stem 54.10423
##
## [[2]]
## parameter: df
-## crown : stem 184.8496
+## crown : stem 177.9857
##
## [[3]]
## p.value
-## crown : stem 9.763665e-120
+## crown : stem 1.928983e-112
##
## [[4]]
## stderr
-## crown : stem 0.005417012
-## Performing the same test but with the detailed t.test output
-test.dispRity(disparity_crown_stem, test = t.test, details = TRUE)
+## crown : stem 0.005649615
+## Performing the same test but with the detailed t.test output
+test.dispRity(disparity_crown_stem, test = t.test, details = TRUE)
## $`crown : stem`
## $`crown : stem`[[1]]
##
## Welch Two Sample t-test
##
## data: dots[[1L]][[1L]] and dots[[2L]][[1L]]
-## t = 57.381, df = 184.85, p-value < 2.2e-16
+## t = 54.104, df = 177.99, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
-## 0.3001473 0.3215215
+## 0.2945193 0.3168170
## sample estimates:
## mean of x mean of y
-## 2.440611 2.129776
-## Wilcoxon test applied to time sliced disparity with sequential comparisons,
-## with Bonferroni correction
-test.dispRity(disparity_time_slices, test = wilcox.test,
-comparisons = "sequential", correction = "bonferroni")
+## 2.440968 2.135299
+## Wilcoxon test applied to time sliced disparity with sequential comparisons,
+## with Bonferroni correction
+test.dispRity(disparity_time_slices, test = wilcox.test,
+ comparisons = "sequential", correction = "bonferroni")
## [[1]]
## statistic: W
-## 120 : 80 42
-## 80 : 40 2065
-## 40 : 0 1485
+## 120 : 80 40
+## 80 : 40 1812
+## 40 : 0 1463
##
## [[2]]
## p.value
-## 120 : 80 2.682431e-33
-## 80 : 40 2.247885e-12
-## 40 : 0 2.671335e-17
-## Measuring the overlap between distributions in the time bins (using the
-## implemented Bhattacharyya Coefficient function - see ?bhatt.coeff)
-test.dispRity(disparity_time_bins, test = bhatt.coeff)
+## 120 : 80 2.534081e-33
+## 80 : 40 2.037470e-14
+## 40 : 0 1.671038e-17
+## Measuring the overlap between distributions in the time bins (using the
+## implemented Bhattacharyya Coefficient function - see ?bhatt.coeff)
+test.dispRity(disparity_time_bins, test = bhatt.coeff)
## bhatt.coeff
-## 120 - 80 : 80 - 40 0.00000000
-## 120 - 80 : 40 - 0 0.02236068
-## 80 - 40 : 40 - 0 0.42018008
+## 120 - 80 : 80 - 40 0.000000
+## 120 - 80 : 40 - 0 0.000000
+## 80 - 40 : 40 - 0 0.450877
Because of the modular design of the package, tests can always be made by the user (the same way disparity metrics can be user made).
The only condition is that the test can be applied to at least two distributions.
In practice, the test.dispRity
function will pass the calculated disparity data (distributions) to the provided function in either pairs of distributions (if the comparisons
argument is set to pairwise
, referential
or sequential
) or a table containing all the distributions (comparisons = all
; this should be in the same format as data passed to lm
-type functions for example).
4.6.1 NPMANOVA in dispRity
-One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices vegan::adonis
.
+
One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices vegan::adonis2
.
This can be done on dispRity
objects using the adonis.dispRity
wrapper function.
Basically, this function takes the exact same arguments as adonis
and a dispRity
object for data and performs a PERMANOVA based on the distance matrix of the multidimensional space (unless the multidimensional space was already defined as a distance matrix).
The adonis.dispRity
function uses the information from the dispRity
object to generate default formulas:
-- If the object contains customised subsets, it applies the default formula
matrix ~ group
testing the effect of group
as a predictor on matrix
(called from the dispRity
object as data$matrix
see dispRitu
object details)
+- If the object contains customised subsets, it applies the default formula
matrix ~ group
testing the effect of group
as a predictor on matrix
(called from the dispRity
object as data$matrix
see dispRity
object details)
- If the object contains time subsets, it applies the default formula
matrix ~ time
testing the effect of time
as a predictor (were the different levels of time
are the different time slices/bins)
-set.seed(1)
-## Generating a random character matrix
- sim.morpho(rtree(20), 50,
- character_matrix <-rates = c(rnorm, 1, 0))
-
-## Calculating the distance matrix
- as.matrix(dist(character_matrix))
- distance_matrix <-
-## Creating two groups
- list("group1" = 1:10, "group2" = 11:20)
- random_groups <-
-## Generating a dispRity object
- custom.subsets(distance_matrix, random_groups) random_disparity <-
+set.seed(1)
+## Generating a random character matrix
+character_matrix <- sim.morpho(rtree(20), 50,
+ rates = c(rnorm, 1, 0))
+
+## Calculating the distance matrix
+distance_matrix <- as.matrix(dist(character_matrix))
+
+## Creating two groups
+random_groups <- list("group1" = 1:10, "group2" = 11:20)
+
+## Generating a dispRity object
+random_disparity <- custom.subsets(distance_matrix, random_groups)
## Warning: custom.subsets is applied on what seems to be a distance matrix.
-## The resulting matrices won't be distance matrices anymore!
-## Running a default NPMANOVA
-adonis.dispRity(random_disparity)
+## The resulting matrices won't be distance matrices anymore!
+## You can use dist.data = TRUE, if you want to keep the data as a distance matrix.
+
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = matrix ~ group, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## group 1 14.2 0.06443 1.2396 0.166
+## Model 1 14.2 0.06443 1.2396 0.166
## Residual 18 206.2 0.93557
## Total 19 220.4 1.00000
Of course, it is possible to pass customised formulas if the disparity object contains more more groups.
In that case the predictors must correspond to the names of the groups explained data must be set as matrix
:
-## Creating two groups with two states each
- as.data.frame(matrix(data = c(rep(1,10),
- groups <-rep(2,10),
- rep(c(1,2), 10)),
- nrow = 20, ncol = 2,
- dimnames = list(paste0("t", 1:20),
- c("g1", "g2"))))
-
-## Creating the dispRity object
- custom.subsets(distance_matrix, groups) multi_groups <-
+## Creating two groups with two states each
+groups <- as.data.frame(matrix(data = c(rep(1,10),
+ rep(2,10),
+ rep(c(1,2), 10)),
+ nrow = 20, ncol = 2,
+ dimnames = list(paste0("t", 1:20),
+ c("g1", "g2"))))
+
+## Creating the dispRity object
+multi_groups <- custom.subsets(distance_matrix, groups)
## Warning: custom.subsets is applied on what seems to be a distance matrix.
-## The resulting matrices won't be distance matrices anymore!
-## Running the NPMANOVA
-adonis.dispRity(multi_groups, matrix ~ g1 + g2)
+## The resulting matrices won't be distance matrices anymore!
+## You can use dist.data = TRUE, if you want to keep the data as a distance matrix.
+
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = matrix ~ g1 + g2, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## g1 1 11.0 0.04991 0.9359 0.549
-## g2 1 9.6 0.04356 0.8168 0.766
+## Model 2 20.6 0.09347 0.8764 0.746
## Residual 17 199.8 0.90653
## Total 19 220.4 1.00000
Finally, it is possible to use objects generated by chrono.subsets
.
In this case, adonis.dispRity
will applied the matrix ~ time
formula by default:
-## Creating time series
- chrono.subsets(BeckLee_mat50, BeckLee_tree,
- time_subsets <-method = "discrete",
- inc.nodes = FALSE,
- time = c(100, 85, 65, 0),
- FADLAD = BeckLee_ages)
-
-## Running the NPMANOVA with time as a predictor
-adonis.dispRity(time_subsets)
+## Creating time series
+time_subsets <- chrono.subsets(BeckLee_mat50, BeckLee_tree,
+ method = "discrete",
+ inc.nodes = FALSE,
+ time = c(100, 85, 65, 0),
+ FADLAD = BeckLee_ages)
+
+## Running the NPMANOVA with time as a predictor
+adonis.dispRity(time_subsets)
## Warning in adonis.dispRity(time_subsets): The input data for adonis.dispRity was not a distance matrix.
## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])).
## Make sure that this is the desired methodological approach!
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = dist(matrix) ~ time, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## time 2 9.593 0.07769 1.9796 0.001 ***
+## Model 2 9.593 0.07769 1.9796 0.001 ***
## Residual 47 113.884 0.92231
## Total 49 123.477 1.00000
## ---
@@ -2037,20 +2101,18 @@ 4.6.1 NPMANOVA in dispRity<
Note that the function warns you that the input data was transformed into a distance matrix.
This is reflected in the Call part of the output (formula = dist(matrix) ~ time
).
To use each time subset as a separate predictor, you can use the matrix ~ chrono.subsets
formula; this is equivalent to matrix ~ first_time_subset + second_time_subset + ...
:
-## Running the NPMANOVA with each time bin as a predictor
-adonis.dispRity(time_subsets, matrix ~ chrono.subsets)
+## Running the NPMANOVA with each time bin as a predictor
+adonis.dispRity(time_subsets, matrix ~ chrono.subsets)
## Warning in adonis.dispRity(time_subsets, matrix ~ chrono.subsets): The input data for adonis.dispRity was not a distance matrix.
## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])).
## Make sure that this is the desired methodological approach!
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = dist(matrix) ~ chrono.subsets, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## t100to85 1 3.714 0.03008 1.5329 0.006 **
-## t85to65 1 5.879 0.04761 2.4262 0.001 ***
+## Model 2 9.593 0.07769 1.9796 0.001 ***
## Residual 47 113.884 0.92231
## Total 49 123.477 1.00000
## ---
@@ -2061,39 +2123,39 @@ 4.6.2 geiger::dtt
mo
The dtt
function from the geiger
package is also often used to compare a trait’s disparity observed in living taxa to the disparity of a simulated trait based on a given phylogeny.
The dispRity
package proposes a wrapper function for geiger::dtt
, dtt.dispRity
that allows the use of any disparity metric.
Unfortunately, this implementation is slower that geiger::dtt
(so if you’re using the metrics implemented in geiger
prefer the original version) and, as the original function, is limited to ultrametric trees (only living taxa!)…
-require(geiger)
+
## Loading required package: geiger
- get(data(geospiza))
- geiger_data <-
-## Calculate the disparity of the dataset using the sum of variance
- dtt.dispRity(data = geiger_data$dat,
- dispRity_dtt <-metric = c(sum, variances),
- tree = geiger_data$phy,
- nsim = 100)
+geiger_data <- get(data(geospiza))
+
+## Calculate the disparity of the dataset using the sum of variance
+dispRity_dtt <- dtt.dispRity(data = geiger_data$dat,
+ metric = c(sum, variances),
+ tree = geiger_data$phy,
+ nsim = 100)
## Warning in dtt.dispRity(data = geiger_data$dat, metric = c(sum, variances), :
## The following tip(s) was not present in the data: olivacea.
-## Plotting the results
-plot(dispRity_dtt)
-
+
+
Note that, like in the original dtt
function, it is possible to change the evolutionary model (see ?geiger::sim.char
documentation).
4.6.3 null morphospace testing with null.test
-This test is equivalent to the test performed in Dı́az et al. (2016).
+
This test is equivalent to the test performed in Dı́az et al. (2016).
It compares the disparity measured in the observed space to the disparity measured in a set of simulated spaces.
These simulated spaces can be built with based on the hypothesis assumptions: for example, we can test whether our space is normal.
-set.seed(123)
-## A "normal" multidimensional space with 50 dimensions and 10 elements
- matrix(rnorm(1000), ncol = 50)
- normal_space <-
-## Calculating the disparity as the average pairwise distances
- dispRity(normal_space,
- obs_disparity <-metric = c(mean, pairwise.dist))
+set.seed(123)
+## A "normal" multidimensional space with 50 dimensions and 10 elements
+normal_space <- matrix(rnorm(1000), ncol = 50)
+
+## Calculating the disparity as the average pairwise distances
+obs_disparity <- dispRity(normal_space,
+ metric = c(mean, pairwise.dist))
## Warning in check.data(data, match_call): Row names have been automatically
## added to data.
-## Testing against 100 randomly generated normal spaces
- null.test(obs_disparity, replicates = 100,
- (results <-null.distrib = rnorm))
+## Testing against 100 randomly generated normal spaces
+(results <- null.test(obs_disparity, replicates = 100,
+ null.distrib = rnorm))
## Monte-Carlo test
## Call: [1] "dispRity::null.test"
##
@@ -2108,15 +2170,15 @@ 4.6.3 null morphospace testing wi
Here the results show that disparity measured in our observed space is not significantly different than the one measured in a normal space.
We can then propose that our observed space is normal!
These results have an attributed dispRity
and randtest
class and can be plotted as randtest
objects using the dispRity
S3 plot
method:
-## Plotting the results
-plot(results, main = "Is this space normal?")
-
+
+
For more details on generating spaces see the space.maker
function tutorial.
4.7 Fitting modes of evolution to disparity data
-The code used for these models is based on those developed by Gene Hunt (Hunt 2006, 2012; Hunt, Hopkins, and Lidgard 2015).
+
The code used for these models is based on those developed by Gene Hunt (Hunt 2006, 2012; Hunt, Hopkins, and Lidgard 2015).
So we acknowledge and thank Gene Hunt for developing these models and writing the original R code that served as inspiration for these models.
DISCLAIMER: this method of analysing disparity has not been published yet and has not been peer reviewed. Caution should be used in interpreting these results: it is unclear what “a disparity curve fitting a Brownian motion” actually means biologically.
@@ -2129,12 +2191,12 @@ 4.7.1.1 model.test
Changes in disparity-through-time can follow a range of models, such as random walks, stasis, constrained evolution, trends, or an early burst model of evolution.
We will start with by fitting the simplest modes of evolution to our data.
For example we may have a null expectation of time-invariant change in disparity in which values fluctuate with a variance around the mean - this would be best describe by a Stasis model:
-## Loading premade disparity data
-data(BeckLee_disparity)
- model.test(data = BeckLee_disparity, model = "Stasis") disp_time <-
+## Loading premade disparity data
+data(BeckLee_disparity)
+disp_time <- model.test(data = BeckLee_disparity, model = "Stasis")
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
+## Running Stasis model...Done. Log-likelihood = -15.562
We can see the standard output from model.test
.
The first output message tells us it has tested for equal variances in each sample.
The model uses Bartlett’s test of equal variances to assess if variances are equal, so if p > 0.05 then variance is treated as the same for all samples, but if (p < 0.05) then each bin variance is unique.
@@ -2142,68 +2204,68 @@
4.7.1.1 model.test
By default model.test
will use Bartlett’s test to assess for homogeneity of variances, and then use this to decide to pool variances or not.
This is ignored if the argument pool.variance
in model.test
is changed from the default NULL
to TRUE
or FALSE
.
For example, to ignore Bartlett’s test and pool variances manually we would do the following:
- model.test(data = BeckLee_disparity,
- disp_time_pooled <-model = "Stasis",
- pool.variance = TRUE)
-## Running Stasis model...Done. Log-likelihood = -16.884
+disp_time_pooled <- model.test(data = BeckLee_disparity,
+ model = "Stasis",
+ pool.variance = TRUE)
+## Running Stasis model...Done. Log-likelihood = -13.682
However, unless you have good reason to choose otherwise it is recommended to use the default of pool.variance = NULL
:
- model.test(data = BeckLee_disparity,
- disp_time <-model = "Stasis",
- pool.variance = NULL)
+
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
- disp_time
+## Running Stasis model...Done. Log-likelihood = -15.562
+
## Disparity evolution model fitting:
## Call: model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL)
##
## aicc delta_aicc weight_aicc
-## Stasis 41.48967 0 1
+## Stasis 35.22653 0 1
##
## Use x$full.details for displaying the models details
## or summary(x) for summarising them.
-The remaining output gives us the log-likelihood of the Stasis model of -18.7 (you may notice this change when we pooled variances above).
+
The remaining output gives us the log-likelihood of the Stasis model of -15.6 (you may notice this change when we pooled variances above).
The output also gives us the small sample Akaike Information Criterion (AICc), the delta AICc (the distance from the best fitting model), and the AICc weights (~the relative support of this model compared to all models, scaled to one).
These are all metrics of relative fit, so when we test a single model they are not useful.
By using the function summary in dispRity
we can see the maximum likelihood estimates of the model parameters:
-summary(disp_time)
+
## aicc delta_aicc weight_aicc log.lik param theta.1 omega
-## Stasis 41.5 0 1 -18.7 2 3.6 0.1
+## Stasis 35.2 0 1 -15.6 2 3.5 0.1
So we again see the AICc, delta AICc, AICc weight, and the log-likelihood we saw previously.
-We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.6).
+We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.5).
The model.test
function is designed to test relative model fit, so we need to test more than one model to make relative comparisons.
So let’s compare to the fit of the Stasis model to another model with two parameters: the Brownian motion.
Brownian motion assumes a constant mean that is equal to the ancestral estimate of the sequence, and the variance around this mean increases linearly with time.
The easier way to compare these models is to simply add "BM"
to the models
vector argument:
- model.test(data = BeckLee_disparity,
- disp_time <-model = c("Stasis", "BM"))
+
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
- disp_time
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+
## Disparity evolution model fitting:
## Call: model.test(data = BeckLee_disparity, model = c("Stasis", "BM"))
##
## aicc delta_aicc weight_aicc
-## Stasis 41.48967 335.9656 1.111708e-73
-## BM -294.47595 0.0000 1.000000e+00
+## Stasis 35.22653 334.3978 2.434618e-73
+## BM -299.17132 0.0000 1.000000e+00
##
## Use x$full.details for displaying the models details
## or summary(x) for summarising them.
Et voilà! Here we can see by the log-likelihood, AICc, delta AICc, and AICc weight Brownian motion has a much better relative fit to these data than the Stasis model.
-Brownian motion has a relative AICc fit336 units better than Stasis, and has a AICc weight of 1.
+Brownian motion has a relative AICc fit334.4 units better than Stasis, and has a AICc weight of 1.
We can also all the information about the relative fit of models alongside the maximum likelihood estimates of model parameters using the summary function
-summary(disp_time)
+
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Stasis 41 336 0 -18.7 2 3.629 0.074 NA
-## BM -294 0 1 149.3 2 NA NA 3.267
+## Stasis 35 334.4 0 -15.6 2 3.486 0.07 NA
+## BM -299 0.0 1 151.6 2 NA NA 3.132
## sigma squared
## Stasis NA
## BM 0.001
Not that because the parameters per models differ, the summary includes NA
for inapplicable parameters per models (e.g. the theta and omega parameters from the Stasis models are inapplicable for a Brownian motion model).
We can plot the relative fit of our models using the plot
function
-plot(disp_time)
+
4.7.1.1 model.test
Here we see and overwhelming support for the Brownian motion model.
Alternatively, we could test all available models single modes: Stasis, Brownian motion, Ornstein-Uhlenbeck (evolution constrained to an optima), Trend (increasing or decreasing mean through time), and Early Burst (exponentially decreasing rate through time)
- model.test(data = BeckLee_disparity,
- disp_time <-model = c("Stasis", "BM", "OU", "Trend", "EB"))
+
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 152.119
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
-summary(disp_time)
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 154.512
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
+
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
-## BM -294 3.6 0.112 149.3 2 NA NA 3.267
-## OU -296 2.1 0.227 152.1 4 NA NA 3.254
-## Trend -298 0.0 0.661 152.1 3 NA NA 3.255
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
+## BM -299 3.6 0.108 151.6 2 NA NA 3.132
+## OU -301 2.1 0.229 154.5 4 NA NA 3.118
+## Trend -303 0.0 0.664 154.5 3 NA NA 3.119
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
## sigma squared alpha optima.1 trend eb
## Stasis NA NA NA NA NA
## BM 0.001 NA NA NA NA
-## OU 0.001 0.001 12.35 NA NA
+## OU 0.001 0.001 10.18 NA NA
## Trend 0.001 NA NA 0.007 NA
-## EB 0.000 NA NA NA -0.032
+## EB 0.000 NA NA NA -0.034
These models indicate support for a Trend model, and we can plot the relative support of all model AICc weights.
-plot(disp_time)
+
4.7.1.1 model.test
Note that although AIC values are indicator of model best fit, it is also important to look at the parameters themselves.
-For example OU can be really well supported but with an alpha parameter really close to 0, making it effectively a BM model (Cooper et al. 2016).
+For example OU can be really well supported but with an alpha parameter really close to 0, making it effectively a BM model (Cooper et al. 2016).
Is this a trend of increasing or decreasing disparity through time? One way to find out is to look at the summary function for the Trend model:
-summary(disp_time)["Trend",]
+
## aicc delta_aicc weight_aicc log.lik param
-## -298.000 0.000 0.661 152.100 3.000
+## -303.000 0.000 0.664 154.500 3.000
## theta.1 omega ancestral state sigma squared alpha
-## NA NA 3.255 0.001 NA
+## NA NA 3.119 0.001 NA
## optima.1 trend eb
## NA 0.007 NA
This show a positive trend (0.007) of increasing disparity through time.
@@ -2262,83 +2324,83 @@ 4.7.2 Plot and run simulation tes
4.7.2.1 model.test.wrapper
Patterns of evolution can be fit using model.test
, but the model.test.wrapper
fits the same models as model.test
as well as running predictive tests and plots.
-The predictive tests use the maximum likelihood estimates of model parameters to simulate a number of datasets (default = 1000), and analyse whether this is significantly different to the empirical input data using the Rank Envelope test (Murrell 2018).
+
The predictive tests use the maximum likelihood estimates of model parameters to simulate a number of datasets (default = 1000), and analyse whether this is significantly different to the empirical input data using the Rank Envelope test (Murrell 2018).
Finally we can plot the empirical data, simulated data, and the Rank Envelope test p values.
This can all be done using the function model.test.wrapper
, and we will set the argument show.p = TRUE
so p values from the Rank Envelope test are printed on the plot:
- model.test.wrapper(data = BeckLee_disparity,
- disp_time <-model = c("Stasis", "BM", "OU", "Trend", "EB"),
- show.p = TRUE)
+disp_time <- model.test.wrapper(data = BeckLee_disparity,
+ model = c("Stasis", "BM", "OU", "Trend", "EB"),
+ show.p = TRUE)
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 152.119
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 154.512
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
-
disp_time
+
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Trend -298 0.0 0.661 152.1 3 NA NA 3.255
-## OU -296 2.1 0.227 152.1 4 NA NA 3.254
-## BM -294 3.6 0.112 149.3 2 NA NA 3.267
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
+## Trend -303 0.0 0.664 154.5 3 NA NA 3.119
+## OU -301 2.1 0.229 154.5 4 NA NA 3.118
+## BM -299 3.6 0.108 151.6 2 NA NA 3.132
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
## sigma squared alpha optima.1 trend eb median p value lower p value
-## Trend 0.001 NA NA 0.007 NA 0.978021978 0.9760240
-## OU 0.001 0.001 12.35 NA NA 0.978021978 0.9770230
-## BM 0.001 NA NA NA NA 0.143856144 0.1368631
-## EB 0.000 NA NA NA -0.032 0.000999001 0.0000000
+## Trend 0.001 NA NA 0.007 NA 0.986013986 0.9850150
+## OU 0.001 0.001 10.18 NA NA 0.979020979 0.9770230
+## BM 0.001 NA NA NA NA 0.107892108 0.0969031
+## EB 0.000 NA NA NA -0.034 0.000999001 0.0000000
## Stasis NA NA NA NA NA 1.000000000 0.9990010
## upper p value
-## Trend 0.9780220
-## OU 0.9780220
-## BM 0.1878122
-## EB 0.1368631
+## Trend 0.9860140
+## OU 0.9800200
+## BM 0.1388611
+## EB 0.1378621
## Stasis 1.0000000
From this plot we can see the empirical estimates of disparity through time (pink) compared to the predictive data based upon the simulations using the estimated parameters from each model.
There is no significant differences between the empirical data and simulated data, except for the Early Burst model.
Trend is the best-fitting model but the plot suggests the OU model also follows a trend-like pattern.
-This is because the optima for the OU model (12.35) is different to the ancestral state (3.254) and outside the observed value.
+This is because the optima for the OU model (10.18) is different to the ancestral state (3.118) and outside the observed value.
This is potentially unrealistic, and one way to alleviate this issue is to set the optima of the OU model to equal the ancestral estimate - this is the normal practice for OU models in comparative phylogenetics.
To set the optima to the ancestral value we change the argument fixed.optima = TRUE
:
- model.test.wrapper(data = BeckLee_disparity,
- disp_time <-model = c("Stasis", "BM", "OU", "Trend", "EB"),
- show.p = TRUE, fixed.optima = TRUE)
+disp_time <- model.test.wrapper(data = BeckLee_disparity,
+ model = c("Stasis", "BM", "OU", "Trend", "EB"),
+ show.p = TRUE, fixed.optima = TRUE)
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 149.289
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 151.637
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
-
disp_time
+
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Trend -298 0.0 0.814 152.1 3 NA NA 3.255
-## BM -294 3.6 0.138 149.3 2 NA NA 3.267
-## OU -292 5.7 0.048 149.3 3 NA NA 3.267
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
+## Trend -303 0.0 0.821 154.5 3 NA NA 3.119
+## BM -299 3.6 0.133 151.6 2 NA NA 3.132
+## OU -297 5.7 0.046 151.6 3 NA NA 3.132
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
## sigma squared alpha trend eb median p value lower p value
-## Trend 0.001 NA 0.007 NA 0.984015984 0.9820180
-## BM 0.001 NA NA NA 0.256743257 0.2487512
-## OU 0.001 0 NA NA 0.293706294 0.2917083
-## EB 0.000 NA NA -0.032 0.000999001 0.0000000
+## Trend 0.001 NA 0.007 NA 0.989010989 0.9880120
+## BM 0.001 NA NA NA 0.224775225 0.2117882
+## OU 0.001 0 NA NA 0.264735265 0.2637363
+## EB 0.000 NA NA -0.034 0.000999001 0.0000000
## Stasis NA NA NA NA 0.999000999 0.9980020
## upper p value
-## Trend 0.9840160
-## BM 0.2797203
-## OU 0.3166833
+## Trend 0.9890110
+## BM 0.2507493
+## OU 0.2967033
## EB 0.1378621
## Stasis 0.9990010
The relative fit of the OU model is decreased by constraining the fit of the optima to equal the ancestral state value.
@@ -2354,97 +2416,97 @@
4.7.3 Multiple modes of evolution
Here we will compare the relative fit of Brownian motion, Trend, Ornstein-Uhlenbeck and a multi-mode Ornstein Uhlenbck model in which the optima changes at 66 million years ago, the Cretaceous-Palaeogene boundary.
For example, we could be testing the hypothesis that the extinction of non-avian dinosaurs allowed mammals to go from scurrying in the undergrowth (low optima/low disparity) to dominating all habitats (high optima/high disparity).
We will constrain the optima of OU model in the first time begin (i.e, pre-66 Mya) to equal the ancestral value:
- model.test.wrapper(data = BeckLee_disparity,
- disp_time <-model = c("BM", "Trend", "OU", "multi.OU"),
- time.split = 66,
- pool.variance = NULL,
- show.p = TRUE,
- fixed.optima = TRUE)
+disp_time <- model.test.wrapper(data = BeckLee_disparity,
+ model = c("BM", "Trend", "OU", "multi.OU"),
+ time.split = 66,
+ pool.variance = NULL,
+ show.p = TRUE,
+ fixed.optima = TRUE)
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running BM model...Done. Log-likelihood = 149.289
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running OU model...Done. Log-likelihood = 149.289
-## Running multi.OU model...Done. Log-likelihood = 151.958
+## Running BM model...Done. Log-likelihood = 151.637
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running OU model...Done. Log-likelihood = 151.637
+## Running multi.OU model...Done. Log-likelihood = 154.492
-
disp_time
+
## aicc delta_aicc weight_aicc log.lik param ancestral state
-## Trend -298 0.000 0.657 152.1 3 3.255
-## multi.OU -296 2.456 0.193 152.0 4 3.253
-## BM -294 3.550 0.111 149.3 2 3.267
-## OU -292 5.654 0.039 149.3 3 3.267
+## Trend -303 0.000 0.642 154.5 3 3.119
+## multi.OU -301 2.170 0.217 154.5 4 3.117
+## BM -299 3.639 0.104 151.6 2 3.132
+## OU -297 5.742 0.036 151.6 3 3.132
## sigma squared trend alpha optima.2 median p value lower p value
## Trend 0.001 0.007 NA NA 0.9870130 0.9860140
-## multi.OU 0.001 NA 0.006 4.686 0.9570430 0.9560440
-## BM 0.001 NA NA NA 0.1868132 0.1808192
-## OU 0.001 NA 0.000 NA 0.2727273 0.2707293
+## multi.OU 0.001 NA 0.003 5.582 0.9620380 0.9610390
+## BM 0.001 NA NA NA 0.1848152 0.1838162
+## OU 0.001 NA 0.000 NA 0.2787213 0.2757243
## upper p value
## Trend 0.9870130
-## multi.OU 0.9590410
-## BM 0.2207792
-## OU 0.3016983
+## multi.OU 0.9620380
+## BM 0.2217782
+## OU 0.3046953
The multi-OU model shows an increase an optima at the Cretaceous-Palaeogene boundary, indicating a shift in disparity.
However, this model does not fit as well as a model in which there is an increasing trend through time.
We can also fit a model in which the we specify a heterogeneous model but we do not give a time.split
.
In this instance the model will test all splits that have at least 10 time slices on either side of the split.
That’s 102 potential time shifts in this example dataset so be warned, the following code will estimate 105 models!
-## An example of a time split model in which all potential splits are tested
-## WARNING: this will take between 20 minutes and half and hour to run!
- model.test.wrapper(data = BeckLee_disparity,
- disp_time <-model = c("BM", "Trend", "OU", "multi.OU"),
- show.p = TRUE, fixed.optima = TRUE)
+## An example of a time split model in which all potential splits are tested
+## WARNING: this will take between 20 minutes and half and hour to run!
+disp_time <- model.test.wrapper(data = BeckLee_disparity,
+ model = c("BM", "Trend", "OU", "multi.OU"),
+ show.p = TRUE, fixed.optima = TRUE)
As well as specifying a multi-OU model we can run any combination of models.
For example we could fit a model at the Cretaceous-Palaeogene boundary that goes from an OU to a BM model, a Trend to an OU model, a Stasis to a Trend model or any combination you want to use.
The only model that can’t be used in combination is a multi-OU model.
These can be introduced by changing the input for the models into a list, and supplying a vector with the two models.
This is easier to see with an example:
-## The models to test
- list(c("BM", "OU"),
- my_models <-c("Stasis", "OU"),
- c("BM", "Stasis"),
- c("OU", "Trend"),
- c("Stasis", "BM"))
-
-## Testing the models
- model.test.wrapper(data = BeckLee_disparity,
- disp_time <-model = my_models, time.split = 66,
- show.p = TRUE, fixed.optima = TRUE)
+## The models to test
+my_models <- list(c("BM", "OU"),
+ c("Stasis", "OU"),
+ c("BM", "Stasis"),
+ c("OU", "Trend"),
+ c("Stasis", "BM"))
+
+## Testing the models
+disp_time <- model.test.wrapper(data = BeckLee_disparity,
+ model = my_models, time.split = 66,
+ show.p = TRUE, fixed.optima = TRUE)
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running BM:OU model...Done. Log-likelihood = 144.102
-## Running Stasis:OU model...Done. Log-likelihood = 125.066
-## Running BM:Stasis model...Done. Log-likelihood = 69.265
-## Running OU:Trend model...Done. Log-likelihood = 147.839
-## Running Stasis:BM model...Done. Log-likelihood = 125.066
+## Running BM:OU model...Done. Log-likelihood = 146.472
+## Running Stasis:OU model...Done. Log-likelihood = 127.707
+## Running BM:Stasis model...Done. Log-likelihood = 72.456
+## Running OU:Trend model...Done. Log-likelihood = 150.208
+## Running Stasis:BM model...Done. Log-likelihood = 127.707
-
disp_time
+
## aicc delta_aicc weight_aicc log.lik param ancestral state
-## OU:Trend -287 0.0 0.977 147.8 4 3.352
-## BM:OU -280 7.5 0.023 144.1 4 3.350
-## Stasis:BM -244 43.4 0.000 125.1 3 NA
-## Stasis:OU -240 47.7 0.000 125.1 5 NA
-## BM:Stasis -130 157.1 0.000 69.3 4 3.268
+## OU:Trend -292 0.0 0.977 150.2 4 3.218
+## BM:OU -285 7.5 0.023 146.5 4 3.216
+## Stasis:BM -249 42.9 0.000 127.7 3 NA
+## Stasis:OU -245 47.2 0.000 127.7 5 NA
+## BM:Stasis -137 155.5 0.000 72.5 4 3.132
## sigma squared alpha optima.1 theta.1 omega trend median p value
-## OU:Trend 0.001 0.041 NA NA NA 0.011 0.2987013
-## BM:OU 0.001 0.000 4.092 NA NA NA 0.4925075
-## Stasis:BM 0.002 NA NA 3.390 0.004 NA 0.9970030
-## Stasis:OU 0.002 0.000 4.092 3.390 0.004 NA 1.0000000
-## BM:Stasis 0.000 NA NA 3.806 0.058 NA 1.0000000
+## OU:Trend 0.001 0.042 NA NA NA 0.011 0.3066933
+## BM:OU 0.001 0.000 3.934 NA NA NA 0.4985015
+## Stasis:BM 0.002 NA NA 3.25 0.004 NA 0.9960040
+## Stasis:OU 0.002 0.000 3.934 3.25 0.004 NA 0.9990010
+## BM:Stasis 0.000 NA NA 3.66 0.053 NA 1.0000000
## lower p value upper p value
-## OU:Trend 0.2947053 0.3536464
-## BM:OU 0.4875125 0.5134865
-## Stasis:BM 0.9960040 0.9970030
-## Stasis:OU 0.9990010 1.0000000
+## OU:Trend 0.3026973 0.3626374
+## BM:OU 0.4945055 0.5184815
+## Stasis:BM 0.9950050 0.9960040
+## Stasis:OU 0.9980020 1.0000000
## BM:Stasis 0.9990010 1.0000000
@@ -2457,12 +2519,12 @@ 4.7.4 model.test.sim
The model.test.sim
allows to simulate disparity evolution given a dispRity
object input (as in model.test.wrapper
) or given a model and its specification.
For example, it is possible to simulate a simple Brownian motion model (or any of the other models or models combination described above):
-## A simple BM model
- model.test.sim(sim = 1000, model = "BM",
- model_simulation <-time.span = 50, variance = 0.1,
- sample.size = 100,
- parameters = list(ancestral.state = 0))
- model_simulation
+## A simple BM model
+model_simulation <- model.test.sim(sim = 1000, model = "BM",
+ time.span = 50, variance = 0.1,
+ sample.size = 100,
+ parameters = list(ancestral.state = 0))
+model_simulation
## Disparity evolution model simulation:
## Call: model.test.sim(sim = 1000, model = "BM", time.span = 50, variance = 0.1, sample.size = 100, parameters = list(ancestral.state = 0))
##
@@ -2471,8 +2533,8 @@ 4.7.4 model.test.sim
This will simulate 1000 Brownian motions for 50 units of time with 100 sampled elements, a variance of 0.1 and an ancestral state of 0.
We can also pass multiple models in the same way we did it for model.test
This model can then be summarised and plotted as most dispRity
objects:
-## Displaying the 5 first rows of the summary
-head(summary(model_simulation))
+
## subsets n var median 2.5% 25% 75% 97.5%
## 1 50 100 0.1 -0.06195918 -1.963569 -0.7361336 0.5556715 1.806730
## 2 49 100 0.1 -0.09905061 -2.799025 -1.0670018 0.8836605 2.693583
@@ -2480,8 +2542,8 @@ 4.7.4 model.test.sim
## 4 47 100 0.1 -0.10602238 -3.949521 -1.4363010 1.2234625 3.931000
## 5 46 100 0.1 -0.09016928 -4.277897 -1.5791755 1.3889584 4.507491
## 6 45 100 0.1 -0.13183180 -5.115647 -1.7791878 1.6270527 5.144023
-## Plotting the simulations
-plot(model_simulation)
+
4.7.4 model.test.sim
4.7.4.1 Simulating tested models
Maybe more interestingly though, it is possible to pass the output of model.test
directly to model.test.sim
to simulate the models that fits the data the best and calculate the Rank Envelope test p value.
Let’s see that using the simple example from the start:
-## Fitting multiple models on the data set
- model.test(data = BeckLee_disparity,
- disp_time <-model = c("Stasis", "BM", "OU", "Trend", "EB"))
+## Fitting multiple models on the data set
+disp_time <- model.test(data = BeckLee_disparity,
+ model = c("Stasis", "BM", "OU", "Trend", "EB"))
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 152.119
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
-summary(disp_time)
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 154.512
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
+
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
-## BM -294 3.6 0.112 149.3 2 NA NA 3.267
-## OU -296 2.1 0.227 152.1 4 NA NA 3.254
-## Trend -298 0.0 0.661 152.1 3 NA NA 3.255
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
+## BM -299 3.6 0.108 151.6 2 NA NA 3.132
+## OU -301 2.1 0.229 154.5 4 NA NA 3.118
+## Trend -303 0.0 0.664 154.5 3 NA NA 3.119
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
## sigma squared alpha optima.1 trend eb
## Stasis NA NA NA NA NA
## BM 0.001 NA NA NA NA
-## OU 0.001 0.001 12.35 NA NA
+## OU 0.001 0.001 10.18 NA NA
## Trend 0.001 NA NA 0.007 NA
-## EB 0.000 NA NA NA -0.032
+## EB 0.000 NA NA NA -0.034
As seen before, the Trend model fitted this dataset the best.
-To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with model.test
(here the ancestral state being 3.255, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to model.test.sim
:
-## Simulating 1000 Trend model with the observed parameters
- model.test.sim(sim = 1000, model = disp_time)
- sim_trend <- sim_trend
+To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with model.test
(here the ancestral state being 3.119, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to model.test.sim
:
+## Simulating 1000 Trend model with the observed parameters
+sim_trend <- model.test.sim(sim = 1000, model = disp_time)
+sim_trend
## Disparity evolution model simulation:
## Call: model.test.sim(sim = 1000, model = disp_time)
##
## Model simulated (1000 times):
## aicc log.lik param ancestral state sigma squared trend
-## Trend -298 152.1 3 3.255 0.001 0.007
+## Trend -303 154.5 3 3.119 0.001 0.007
##
## Rank envelope test:
-## p-value of the global test: 0.99001 (ties method: erl)
-## p-interval : (0.989011, 0.99001)
+## p-value of the global test: 0.992008 (ties method: erl)
+## p-interval : (0.991009, 0.992008)
By default, the model simulated is the one with the lowest AICc (model.rank = 1
) but it is possible to choose any ranked model, for example, the OU (second one):
-## Simulating 1000 OU model with the observed parameters
- model.test.sim(sim = 1000, model = disp_time,
- sim_OU <-model.rank = 2)
- sim_OU
+## Simulating 1000 OU model with the observed parameters
+sim_OU <- model.test.sim(sim = 1000, model = disp_time,
+ model.rank = 2)
+sim_OU
## Disparity evolution model simulation:
## Call: model.test.sim(sim = 1000, model = disp_time, model.rank = 2)
##
## Model simulated (1000 times):
## aicc log.lik param ancestral state sigma squared alpha optima.1
-## OU -296 152.1 4 3.254 0.001 0.001 12.35
+## OU -301 154.5 4 3.118 0.001 0.001 10.18
##
## Rank envelope test:
-## p-value of the global test: 0.992008 (ties method: erl)
-## p-interval : (0.99001, 0.992008)
+## p-value of the global test: 0.991009 (ties method: erl)
+## p-interval : (0.989011, 0.991009)
And as the example above, the simulated data can be plotted or summarised:
-head(summary(sim_trend))
+
## subsets n var median 2.5% 25% 75% 97.5%
-## 1 120 5 0.01723152 3.255121 3.135057 3.219150 3.293407 3.375118
-## 2 119 5 0.03555816 3.265538 3.093355 3.200493 3.323520 3.440795
-## 3 118 6 0.03833089 3.269497 3.090438 3.212015 3.329629 3.443074
-## 4 117 7 0.03264826 3.279180 3.112205 3.224810 3.336801 3.447997
-## 5 116 7 0.03264826 3.284500 3.114788 3.223247 3.347970 3.463631
-## 6 115 7 0.03264826 3.293918 3.101298 3.231659 3.354321 3.474645
-head(summary(sim_OU))
+## 1 120 5 0.01791717 3.119216 2.996786 3.082536 3.158256 3.241577
+## 2 119 5 0.03522253 3.129400 2.958681 3.064908 3.186889 3.303168
+## 3 118 6 0.03783622 3.133125 2.957150 3.076447 3.192556 3.304469
+## 4 117 7 0.03214472 3.143511 2.978352 3.089036 3.199075 3.307842
+## 5 116 7 0.03214472 3.147732 2.981253 3.087695 3.210136 3.321990
+## 6 115 7 0.03214472 3.157588 2.969189 3.094733 3.216221 3.335341
+
## subsets n var median 2.5% 25% 75% 97.5%
-## 1 120 5 0.01723152 3.253367 3.141471 3.212180 3.293760 3.371622
-## 2 119 5 0.03555816 3.263167 3.083477 3.197442 3.324438 3.440447
-## 3 118 6 0.03833089 3.262952 3.101351 3.203860 3.332595 3.440163
-## 4 117 7 0.03264826 3.272569 3.104476 3.214511 3.330587 3.442792
-## 5 116 7 0.03264826 3.280423 3.100220 3.219765 3.342726 3.475877
-## 6 115 7 0.03264826 3.287359 3.094699 3.222523 3.355278 3.477518
-## The trend model with some graphical options
-plot(sim_trend, xlab = "Time (Mya)", ylab = "sum of variances",
-col = c("#F65205", "#F38336", "#F7B27E"))
-
-## Adding the observed disparity through time
-plot(BeckLee_disparity, add = TRUE, col = c("#3E9CBA", "#98D4CF90", "#BFE4E390"))
+## 1 120 5 0.01791717 3.116975 3.002874 3.074977 3.158164 3.237559
+## 2 119 5 0.03522253 3.126662 2.948491 3.061492 3.187414 3.302442
+## 3 118 6 0.03783622 3.126408 2.966988 3.068517 3.195251 3.301177
+## 4 117 7 0.03214472 3.136145 2.970973 3.079345 3.192427 3.301722
+## 5 116 7 0.03214472 3.144302 2.967779 3.083789 3.205035 3.336560
+## 6 115 7 0.03214472 3.151057 2.961801 3.086444 3.216077 3.336897
+## The trend model with some graphical options
+plot(sim_trend, xlab = "Time (Mya)", ylab = "sum of variances",
+ col = c("#F65205", "#F38336", "#F7B27E"))
+
+## Adding the observed disparity through time
+plot(BeckLee_disparity, add = TRUE, col = c("#3E9CBA", "#98D4CF90", "#BFE4E390"))
4.8 Disparity as a distributionwhole distribution rather than just a summary metric (e.g. the variances or the ranges).
This is possible in the dispRity
package by calculating disparity as a dimension-level 2 metric only!
Let’s have a look using our previous example of bootstrapped time slices but by measuring the distances between each taxon and their centroid as disparity.
-## Measuring disparity as a whole distribution
- dispRity(boot_time_slices,
- disparity_centroids <-metric = centroids)
+## Measuring disparity as a whole distribution
+disparity_centroids <- dispRity(boot_time_slices,
+ metric = centroids)
The resulting disparity object is of dimension-level 2, so it can easily be transformed into a dimension-level 1 object by, for example, measuring the median distance of all these distributions:
-## Measuring median disparity in each time slice
- dispRity(disparity_centroids,
- disparity_centroids_median <-metric = median)
+## Measuring median disparity in each time slice
+disparity_centroids_median <- dispRity(disparity_centroids,
+ metric = median)
And we can now compare the differences between these methods:
-## Summarising both disparity measurements:
-## The distributions:
-summary(disparity_centroids)
+
## subsets n obs.median bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 1.605 1.376 0.503 1.247 1.695 1.895
-## 2 80 19 1.834 1.774 1.514 1.691 1.853 1.968
-## 3 40 15 1.804 1.789 1.468 1.684 1.889 2.095
-## 4 0 10 1.911 1.809 1.337 1.721 1.968 2.099
-## The summary of the distributions (as median)
-summary(disparity_centroids_median)
+## 1 120 5 1.569 1.338 0.834 1.230 1.650 1.894
+## 2 80 19 1.796 1.739 1.498 1.652 1.812 1.928
+## 3 40 15 1.767 1.764 1.427 1.654 1.859 2.052
+## 4 0 10 1.873 1.779 1.361 1.685 1.934 2.058
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 1.605 1.395 0.503 0.994 1.625 1.686
-## 2 80 19 1.834 1.774 1.682 1.749 1.799 1.823
-## 3 40 15 1.804 1.790 1.579 1.750 1.830 1.875
-## 4 0 10 1.911 1.812 1.659 1.784 1.859 1.930
+## 1 120 5 1.569 1.351 0.648 1.282 1.596 1.641
+## 2 80 19 1.796 1.739 1.655 1.721 1.756 1.787
+## 3 40 15 1.767 1.757 1.623 1.721 1.793 1.837
+## 4 0 10 1.873 1.781 1.564 1.756 1.834 1.900
We can see that the summary message for the distribution is slightly different than before.
Here summary
also displays the observed central tendency (i.e. the central tendency of the measured distributions).
Note that, as expected, this central tendency is the same in both metrics!
Another, maybe more intuitive way, to compare both approaches for measuring disparity is to plot the distributions:
-## Graphical parameters
- par(bty = "n", mfrow = c(1, 2))
- op <-
-## Plotting both disparity measurements
-plot(disparity_centroids,
-ylab = "Distribution of all the distances")
- plot(disparity_centroids_median,
-ylab = "Distribution of the medians of all the distances")
-
-par(op)
+## Graphical parameters
+op <- par(bty = "n", mfrow = c(1, 2))
+
+## Plotting both disparity measurements
+plot(disparity_centroids,
+ ylab = "Distribution of all the distances")
+plot(disparity_centroids_median,
+ ylab = "Distribution of the medians of all the distances")
+
+
We can then test for differences in the resulting distributions using test.dispRity
and the bhatt.coeff
test as described above.
-## Probability of overlap in the distribution of medians
-test.dispRity(disparity_centroids_median, test = bhatt.coeff)
+## Probability of overlap in the distribution of medians
+test.dispRity(disparity_centroids_median, test = bhatt.coeff)
## bhatt.coeff
-## 120 : 80 0.09486833
-## 120 : 40 0.18256185
-## 120 : 0 0.18800657
-## 80 : 40 0.80759884
-## 80 : 0 0.71503765
-## 40 : 0 0.84542569
+## 120 : 80 0.08831761
+## 120 : 40 0.10583005
+## 120 : 0 0.15297059
+## 80 : 40 0.83840952
+## 80 : 0 0.63913150
+## 40 : 0 0.78405839
In this case, we are looking at the probability of overlap of the distribution of median distances from centroids among each pair of time slices.
In other words, we are measuring whether the medians from each bootstrap pseudo-replicate for each time slice overlap.
But of course, we might be interested in the actual distribution of the distances from the centroid rather than simply their central tendencies.
This can be problematic depending on the research question asked since we are effectively comparing non-independent medians distributions (because of the pseudo-replication).
One solution, therefore, is to look at the full distribution:
-## Probability of overlap for the full distributions
-test.dispRity(disparity_centroids, test = bhatt.coeff)
+## Probability of overlap for the full distributions
+test.dispRity(disparity_centroids, test = bhatt.coeff)
## bhatt.coeff
-## 120 : 80 0.6088450
-## 120 : 40 0.6380217
-## 120 : 0 0.6340849
-## 80 : 40 0.9325982
-## 80 : 0 0.8614280
-## 40 : 0 0.9464329
+## 120 : 80 0.6163631
+## 120 : 40 0.6351473
+## 120 : 0 0.6315225
+## 80 : 40 0.9416508
+## 80 : 0 0.8551990
+## 40 : 0 0.9568684
These results show the actual overlap among all the measured distances from centroids concatenated across all the bootstraps.
For example, when comparing the slices 120 and 80, we are effectively comparing the 5 \(\times\) 100 distances (the distances of the five elements in slice 120 bootstrapped 100 times) to the 19 \(\times\) 100 distances from slice 80.
However, this can also be problematic for some specific tests since the n \(\times\) 100 distances are also pseudo-replicates and thus are still not independent.
A second solution is to compare the distributions to each other for each replicate:
-## Boostrapped probability of overlap for the full distributions
-test.dispRity(disparity_centroids, test = bhatt.coeff,
-concatenate = FALSE)
-## bhatt.coeff 2.5% 25% 75% 97.5%
-## 120 : 80 0.2641856 0.0000000 0.1450953 0.3964076 0.5468831
-## 120 : 40 0.2705336 0.0000000 0.1632993 0.3987346 0.6282038
-## 120 : 0 0.2841992 0.0000000 0.2000000 0.4000000 0.7083356
-## 80 : 40 0.6024121 0.3280389 0.4800810 0.7480791 0.8902989
-## 80 : 0 0.4495822 0.1450953 0.3292496 0.5715531 0.7332155
-## 40 : 0 0.5569422 0.2000000 0.4543681 0.6843217 0.8786504
+## Boostrapped probability of overlap for the full distributions
+test.dispRity(disparity_centroids, test = bhatt.coeff,
+ concatenate = FALSE)
+## bhatt.coeff 2.5% 25% 75% 97.5%
+## 120 : 80 0.2671081 0.00000000 0.1450953 0.3964076 0.6084459
+## 120 : 40 0.2864771 0.00000000 0.1632993 0.4238587 0.6444474
+## 120 : 0 0.2864716 0.00000000 0.2000000 0.4000000 0.5837006
+## 80 : 40 0.6187295 0.24391229 0.5284793 0.7440196 0.8961621
+## 80 : 0 0.4790692 0.04873397 0.3754429 0.5946595 0.7797225
+## 40 : 0 0.5513580 0.19542869 0.4207790 0.6870177 0.9066824
These results show the median overlap among pairs of distributions in the first column (bhatt.coeff
) and then the distribution of these overlaps among each pair of bootstraps.
In other words, when two distributions are compared, they are now compared for each bootstrap pseudo-replicate, thus effectively creating a distribution of probabilities of overlap.
For example, when comparing the slices 120 and 80, we have a mean probability of overlap of 0.28 and a probability between 0.18 and 0.43 in 50% of the pseudo-replicates.
@@ -2673,68 +2735,69 @@
4.9 Disparity from other matrices
It is totally possible to perform the same analysis detailed above using other types of matrices as long as your elements are rows in your matrix.
For example, we can use the data set eurodist
, an R
inbuilt dataset that contains the distances (in km) between European cities.
We can check for example, if Northern European cities are closer to each other than Southern ones:
-## Making the eurodist data set into a matrix (rather than "dist" object)
- as.matrix(eurodist)
- eurodist <-1:5, 1:5] eurodist[
+## Making the eurodist data set into a matrix (rather than "dist" object)
+eurodist <- as.matrix(eurodist)
+eurodist[1:5, 1:5]
## Athens Barcelona Brussels Calais Cherbourg
## Athens 0 3313 2963 3175 3339
## Barcelona 3313 0 1318 1326 1294
## Brussels 2963 1318 0 204 583
## Calais 3175 1326 204 0 460
## Cherbourg 3339 1294 583 460 0
-## The two groups of cities
- c("Brussels", "Calais", "Cherbourg", "Cologne", "Copenhagen",
- Northern <-"Hamburg", "Hook of Holland", "Paris", "Stockholm")
- c("Athens", "Barcelona", "Geneva", "Gibraltar", "Lisbon", "Lyons",
- Southern <-"Madrid", "Marseilles", "Milan", "Munich", "Rome", "Vienna")
-
-## Creating the subset dispRity object
- custom.subsets(eurodist, group = list("Northern" = Northern,
- eurodist_subsets <-"Southern" = Southern))
+## The two groups of cities
+Northern <- c("Brussels", "Calais", "Cherbourg", "Cologne", "Copenhagen",
+ "Hamburg", "Hook of Holland", "Paris", "Stockholm")
+Southern <- c("Athens", "Barcelona", "Geneva", "Gibraltar", "Lisbon", "Lyons",
+ "Madrid", "Marseilles", "Milan", "Munich", "Rome", "Vienna")
+
+## Creating the subset dispRity object
+eurodist_subsets <- custom.subsets(eurodist, group = list("Northern" = Northern,
+ "Southern" = Southern))
## Warning: custom.subsets is applied on what seems to be a distance matrix.
-## The resulting matrices won't be distance matrices anymore!
-## Bootstrapping and rarefying to 9 elements (the number of Northern cities)
- boot.matrix(eurodist_subsets, rarefaction = 9)
- eurodist_bs <-
-## Measuring disparity as the median distance from group's centroid
- dispRity(eurodist_bs, metric = c(median, centroids))
- euro_disp <-
-## Testing the differences using a simple wilcox.test
- test.dispRity(euro_disp, test = wilcox.test)
- euro_diff <- test.dispRity(euro_disp, test = wilcox.test, rarefaction = 9) euro_diff_rar <-
+## The resulting matrices won't be distance matrices anymore!
+## You can use dist.data = TRUE, if you want to keep the data as a distance matrix.
+## Bootstrapping and rarefying to 9 elements (the number of Northern cities)
+eurodist_bs <- boot.matrix(eurodist_subsets, rarefaction = 9)
+
+## Measuring disparity as the median distance from group's centroid
+euro_disp <- dispRity(eurodist_bs, metric = c(median, centroids))
+
+## Testing the differences using a simple wilcox.test
+euro_diff <- test.dispRity(euro_disp, test = wilcox.test)
+euro_diff_rar <- test.dispRity(euro_disp, test = wilcox.test, rarefaction = 9)
We can compare this approach to an ordination one:
-## Ordinating the eurodist matrix (with 11 dimensions)
- cmdscale(eurodist, k = 11)
- euro_ord <-
-## Calculating disparity on the bootstrapped and rarefied subset data
- dispRity(boot.matrix(custom.subsets(euro_ord, group =
- euro_ord_disp <-list("Northern" = Northern, "Southern" = Southern)), rarefaction = 9),
- metric = c(median, centroids))
-
-## Testing the differences using a simple wilcox.test
- test.dispRity(euro_ord_disp, test = wilcox.test)
- euro_ord_diff <- test.dispRity(euro_ord_disp, test = wilcox.test, rarefaction = 9) euro_ord_diff_rar <-
+## Ordinating the eurodist matrix (with 11 dimensions)
+euro_ord <- cmdscale(eurodist, k = 11)
+
+## Calculating disparity on the bootstrapped and rarefied subset data
+euro_ord_disp <- dispRity(boot.matrix(custom.subsets(euro_ord, group =
+ list("Northern" = Northern, "Southern" = Southern)), rarefaction = 9),
+ metric = c(median, centroids))
+
+## Testing the differences using a simple wilcox.test
+euro_ord_diff <- test.dispRity(euro_ord_disp, test = wilcox.test)
+euro_ord_diff_rar <- test.dispRity(euro_ord_disp, test = wilcox.test, rarefaction = 9)
And visualise the differences:
-## Plotting the differences
-par(mfrow = c(2,2), bty = "n")
-## Plotting the normal disparity
-plot(euro_disp, main = "Distance differences")
-## Adding the p-value
-text(1.5, 4000, paste0("p=",round(euro_diff[[2]][[1]], digit = 5)))
-## Plotting the rarefied disparity
-plot(euro_disp, rarefaction = 9, main = "Distance differences (rarefied)")
-## Adding the p-value
-text(1.5, 4000, paste0("p=",round(euro_diff_rar[[2]][[1]], digit = 5)))
-
-## Plotting the ordinated disparity
-plot(euro_ord_disp, main = "Ordinated differences")
-## Adding the p-value
-text(1.5, 1400, paste0("p=",round(euro_ord_diff[[2]][[1]], digit = 5) ))
-## Plotting the rarefied disparity
-plot(euro_ord_disp, rarefaction = 9, main = "Ordinated differences (rarefied)")
-## Adding the p-value
-text(1.5, 1400, paste0("p=",round(euro_ord_diff_rar[[2]][[1]], digit = 5) ))
-
+## Plotting the differences
+par(mfrow = c(2,2), bty = "n")
+## Plotting the normal disparity
+plot(euro_disp, main = "Distance differences")
+## Adding the p-value
+text(1.5, 4000, paste0("p=",round(euro_diff[[2]][[1]], digit = 5)))
+## Plotting the rarefied disparity
+plot(euro_disp, rarefaction = 9, main = "Distance differences (rarefied)")
+## Adding the p-value
+text(1.5, 4000, paste0("p=",round(euro_diff_rar[[2]][[1]], digit = 5)))
+
+## Plotting the ordinated disparity
+plot(euro_ord_disp, main = "Ordinated differences")
+## Adding the p-value
+text(1.5, 1400, paste0("p=",round(euro_ord_diff[[2]][[1]], digit = 5) ))
+## Plotting the rarefied disparity
+plot(euro_ord_disp, rarefaction = 9, main = "Ordinated differences (rarefied)")
+## Adding the p-value
+text(1.5, 1400, paste0("p=",round(euro_ord_diff_rar[[2]][[1]], digit = 5) ))
+
As expected, the results are pretty similar in pattern but different in terms of scale.
The median centroids distance is expressed in km in the “Distance differences” plots and in Euclidean units of variation in the “Ordinated differences” plots.
@@ -2742,18 +2805,18 @@ 4.9 Disparity from other matrices
4.10 Disparity from multiple matrices (and multiple trees!)
Since the version 1.4
of this package, it is possible to use multiple trees and multiple matrices in dispRity
objects.
To use multiple matrices, this is rather easy: just supply a list of matrices to any of the dispRity
functions and, as long as they have the same size and the same rownames they will be handled as a distribution of matrices.
-set.seed(1)
-## Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...)
- replicate(3, matrix(rnorm(40), 10, 4, dimnames = list(paste0("t", 1:10))),
- matrix_list <-simplify = FALSE)
- class(matrix_list) # This is a list of matrices
+set.seed(1)
+## Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...)
+matrix_list <- replicate(3, matrix(rnorm(40), 10, 4, dimnames = list(paste0("t", 1:10))),
+ simplify = FALSE)
+class(matrix_list) # This is a list of matrices
## [1] "list"
-## Measuring some disparity metric on one of the matrices
-summary(dispRity(matrix_list[[1]], metric = c(sum, variances)))
+## Measuring some disparity metric on one of the matrices
+summary(dispRity(matrix_list[[1]], metric = c(sum, variances)))
## subsets n obs
## 1 1 10 3.32
-## Measuring the same disparity metric on the three matrices
-summary(dispRity(matrix_list, metric = c(sum, variances)))
+## Measuring the same disparity metric on the three matrices
+summary(dispRity(matrix_list, metric = c(sum, variances)))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 1 10 3.32 3.044 3.175 3.381 3.435
As you can see, when measuring the sum of variances on multiple matrices, we now have a distribution of sum of variances rather than a single observed value.
@@ -2761,96 +2824,96 @@ 4.10 Disparity from multiple matr
This can be useful if you want to use a tree posterior distribution rather than a single consensus tree.
These trees can be passed to chrono.subsets
as a "multiPhylo"
object (with the same node and tip labels in each tree).
First let’s define a function to generate multiple trees with the same labels and root ages:
-set.seed(1)
-## Matches the trees and the matrices
-## A bunch of trees
- function(n, fun = rtree) {
- make.tree <-## Make the tree
- fun(n)
- tree <- chronos(tree, quiet = TRUE,
- tree <-calibration = makeChronosCalib(tree, age.min = 10, age.max = 10))
- class(tree) <- "phylo"
- ## Add the node labels
- $node.label <- paste0("n", 1:Nnode(tree))
- tree## Add the root time
- $root.time <- max(tree.age(tree)$ages)
- treereturn(tree)
-
- } replicate(3, make.tree(10), simplify = FALSE)
- trees <-class(trees) <- "multiPhylo"
- trees
+set.seed(1)
+## Matches the trees and the matrices
+## A bunch of trees
+make.tree <- function(n, fun = rtree) {
+ ## Make the tree
+ tree <- fun(n)
+ tree <- chronos(tree, quiet = TRUE,
+ calibration = makeChronosCalib(tree, age.min = 10, age.max = 10))
+ class(tree) <- "phylo"
+ ## Add the node labels
+ tree$node.label <- paste0("n", 1:Nnode(tree))
+ ## Add the root time
+ tree$root.time <- max(tree.age(tree)$ages)
+ return(tree)
+}
+trees <- replicate(3, make.tree(10), simplify = FALSE)
+class(trees) <- "multiPhylo"
+trees
## 3 phylogenetic trees
We can now simulate some ancestral states for the matrices in the example above to have multiple matrices associated with the multiple trees.
-## A function for running the ancestral states estimations
- function(tree, matrix) {
- do.ace <-## Run one ace
- function(character, tree) {
- fun.ace <- ace(character, phy = tree)$ace
- results <-names(results) <- paste0("n", 1:Nnode(tree))
- return(results)
-
- }## Run all ace
- return(rbind(matrix, apply(matrix, 2, fun.ace, tree = tree)))
-
- }
-## All matrices
- mapply(do.ace, trees, matrix_list, SIMPLIFY = FALSE) matrices <-
+## A function for running the ancestral states estimations
+do.ace <- function(tree, matrix) {
+ ## Run one ace
+ fun.ace <- function(character, tree) {
+ results <- ace(character, phy = tree)$ace
+ names(results) <- paste0("n", 1:Nnode(tree))
+ return(results)
+ }
+ ## Run all ace
+ return(rbind(matrix, apply(matrix, 2, fun.ace, tree = tree)))
+}
+
+## All matrices
+matrices <- mapply(do.ace, trees, matrix_list, SIMPLIFY = FALSE)
Let’s first see an example of time-slicing with one matrix and multiple trees.
This assumes that your tip values (observed) and node values (estimated) are fixed with no error on them.
It also assumes that the nodes in the matrix always corresponds to the node in the trees (in other words, the tree topologies are fixed):
-## Making three "proximity" time slices across one tree
- chrono.subsets(matrices[[1]], trees[[1]],
- one_tree <-method = "continuous",
- model = "proximity", time = 3)
- ## Making three "proximity" time slices across the three trees
- chrono.subsets(matrices[[1]], trees,
- three_tree <-method = "continuous",
- model = "proximity", time = 3)
- ## Measuring disparity as the sum of variances and summarising it
-summary(dispRity(one_tree, metric = c(sum, variances)))
+## Making three "proximity" time slices across one tree
+one_tree <- chrono.subsets(matrices[[1]], trees[[1]],
+ method = "continuous",
+ model = "proximity", time = 3)
+## Making three "proximity" time slices across the three trees
+three_tree <- chrono.subsets(matrices[[1]], trees,
+ method = "continuous",
+ model = "proximity", time = 3)
+## Measuring disparity as the sum of variances and summarising it
+summary(dispRity(one_tree, metric = c(sum, variances)))
## subsets n obs
## 1 8.3 3 0.079
## 2 4.15 5 2.905
## 3 0 10 3.320
-summary(dispRity(three_tree, metric = c(sum, variances)))
+
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 7.9 3 0.253 0.088 0.166 0.309 0.360
## 2 3.95 5 0.257 0.133 0.192 1.581 2.773
## 3 0 10 3.320 3.320 3.320 3.320 3.320
This results show the effect of considering a tree distribution: in the first case (one_tree
) the time slice at 3.95 Mya has a sum of variances of 2.9 but this values goes down to 0.256 in the second case (three_tree
) which is due to the differences in branch lengths distributions:
-par(mfrow = c(3,1))
- c(7.9, 3.95, 0)
- slices <- function(tree) {
- fun.plot <-plot(tree)
- nodelabels(tree$node.label, cex = 0.8)
- axisPhylo()
- abline(v = tree$root.time - slices)
-
- } lapply(trees, fun.plot) silent <-
-
+par(mfrow = c(3,1))
+slices <- c(7.9, 3.95, 0)
+fun.plot <- function(tree) {
+ plot(tree)
+ nodelabels(tree$node.label, cex = 0.8)
+ axisPhylo()
+ abline(v = tree$root.time - slices)
+}
+silent <- lapply(trees, fun.plot)
+
Note that in this example, the nodes are actually even different in each tree! The node n4
for example, is not direct descendent of t4
and t6
in all trees!
To fix that, it is possible to input a list of trees and a list of matrices that correspond to each tree in chrono.subsets
by using the bind.data = TRUE
option.
In this case, the matrices need to all have the same row names and the trees all need the same labels as before:
-## Making three "proximity" time slices across three trees and three bound matrices
- chrono.subsets(matrices, trees,
- bound_data <-method = "continuous",
- model = "proximity",
- time = 3,
- bind.data = TRUE)
- ## Making three "proximity" time slices across three trees and three matrices
- chrono.subsets(matrices, trees,
- unbound_data <-method = "continuous",
- model = "proximity",
- time = 3,
- bind.data = FALSE)
-
-## Measuring disparity as the sum of variances and summarising it
-summary(dispRity(bound_data, metric = c(sum, variances)))
+## Making three "proximity" time slices across three trees and three bound matrices
+bound_data <- chrono.subsets(matrices, trees,
+ method = "continuous",
+ model = "proximity",
+ time = 3,
+ bind.data = TRUE)
+## Making three "proximity" time slices across three trees and three matrices
+unbound_data <- chrono.subsets(matrices, trees,
+ method = "continuous",
+ model = "proximity",
+ time = 3,
+ bind.data = FALSE)
+
+## Measuring disparity as the sum of variances and summarising it
+summary(dispRity(bound_data, metric = c(sum, variances)))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 7.9 3 0.079 0.076 0.077 0.273 0.447
## 2 3.95 5 1.790 0.354 1.034 2.348 2.850
## 3 0 10 3.320 3.044 3.175 3.381 3.435
-summary(dispRity(unbound_data, metric = c(sum, variances)))
+
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 7.9 3 0.79 0.48 0.63 0.83 0.85
## 2 3.95 5 3.25 1.36 2.25 3.94 4.56
@@ -2872,33 +2935,33 @@ 4.11 Disparity with trees: di
If the tree has node labels, their node labels must also match the data.
Similarly if the data has entries for node labels, they must be present in the tree.
Here is a quick demo on how attaching trees to dispRity
objects can work and make your life easy: for example here we will measure how the sum of branch length changes through time when time slicing through some demo data with a acctran split time slice model (see more info here).
-## Loading some demo data:
-## An ordinated matrix with node and tip labels
-data(BeckLee_mat99)
-## The corresponding tree with tip and node labels
-data(BeckLee_tree)
-## A list of tips ages for the fossil data
-data(BeckLee_ages)
-
-## Time slicing through the tree using the equal split algorithm
- chrono.subsets(data = BeckLee_mat99,
- time_slices <-tree = BeckLee_tree,
- FADLAD = BeckLee_ages,
- method = "continuous",
- model = "acctran",
- time = 15)
-
-## We can visualise the resulting trait space with the phylogeny
-## (using the specific argument as follows)
-plot(time_slices, type = "preview",
-specific.args = list(tree = TRUE))
-
-## Note that some nodes are never selected thus explaining the branches not reaching them.
+## Loading some demo data:
+## An ordinated matrix with node and tip labels
+data(BeckLee_mat99)
+## The corresponding tree with tip and node labels
+data(BeckLee_tree)
+## A list of tips ages for the fossil data
+data(BeckLee_ages)
+
+## Time slicing through the tree using the equal split algorithm
+time_slices <- chrono.subsets(data = BeckLee_mat99,
+ tree = BeckLee_tree,
+ FADLAD = BeckLee_ages,
+ method = "continuous",
+ model = "acctran",
+ time = 15)
+
+## We can visualise the resulting trait space with the phylogeny
+## (using the specific argument as follows)
+plot(time_slices, type = "preview",
+ specific.args = list(tree = TRUE))
+
+
And we can then measure disparity as the sum of the edge length at each time slice on the bootstrapped data:
-## Measuring the sum of the edge length per slice
- dispRity(boot.matrix(time_slices), metric = c(sum, edge.length.tree))
- sum_edge_length <-## Summarising and plotting
-summary(sum_edge_length)
+## Measuring the sum of the edge length per slice
+sum_edge_length <- dispRity(boot.matrix(time_slices), metric = c(sum, edge.length.tree))
+## Summarising and plotting
+summary(sum_edge_length)
## subsets n obs bs.median 2.5% 25% 75% 97.5%
## 1 133.51 3 51 51 36 40 61 69
## 2 123.97 6 163 166 141 158 172 188
@@ -2915,8 +2978,8 @@ 4.11 Disparity with trees: di
## 13 19.07 10 1391 1391 1391 1391 1391 1391
## 14 9.54 10 1391 1391 1391 1391 1391 1391
## 15 0 10 1391 1391 1391 1391 1391 1391
-plot(sum_edge_length)
-
+
+
Of course this can be done with multiple trees and be combined with an approach using multiple matrices (see here)!
@@ -2928,61 +2991,62 @@ 4.12 Disparity of variance-covari
For example, you might have a multidimensional dataset where your observations have a nested structure (e.g. they are part of the same phylogeny).
You can then analyse this data using a glmm with something like my_data ~ observations + phylogeny + redisduals
.
For more info on these models start here.
-For more details on running these models, I suggest using the MCMCglmm
package (Hadfield (2010a)) from Hadfield (2010b) (but see also Guillerme and Healy (2014)).
+For more details on running these models, I suggest using the MCMCglmm
package (Hadfield (2010a)) from Hadfield (2010b) (but see also Thomas Guillerme and Healy (2014)).
+For an example use of this code, see Thomas Guillerme et al. (2023).
4.12.1 Creating a dispRity
object with a $covar
component
Once you have a trait space and variance-covariance matrices output from the MCMCglmm
model, you can use the function MCMCglmm.subsets
to create a "dispRity"
object that contains the classic "dispRity"
data (the matrix, the subsets, etc…) but also a the new $covar
element:
-## Loading the charadriiformes data
-data(charadriiformes)
+
Here we using precaculated variance-covariance matrices from the charadriiformes dataset that contains a set of posteriors from a MCMCglmm
model.
The model here was data ~ traits + clade specific phylogenetic effect + global phylogenetic effect + residuals
.
We can retrieve the model information using the MCMCglmm
utilities tools, namely the MCMCglmm.levels
function to directly extract the terms names as used in the model and then build our "dispRity"
object with the correct data, the posteriors and the correct term names:
-## The term names
- MCMCglmm.levels(charadriiformes$posteriors)[1:4]
- model_terms <-## Note that we're ignoring the 5th term of the model that's just the normal residuals
-
-## The dispRity object
-MCMCglmm.subsets(data = charadriiformes$data,
-posteriors = charadriiformes$posteriors,
- group = model_terms)
+## The term names
+model_terms <- MCMCglmm.levels(charadriiformes$posteriors)[1:4]
+## Note that we're ignoring the 5th term of the model that's just the normal residuals
+
+## The dispRity object
+MCMCglmm.subsets(data = charadriiformes$data,
+ posteriors = charadriiformes$posteriors,
+ group = model_terms)
## ---- dispRity object ----
## 4 covar subsets for 359 elements in one matrix with 3 dimensions:
## animal:clade_1, animal:clade_2, animal:clade_3, animal.
## Data is based on 1000 posterior samples.
As you can see this creates a normal dispRity object with the information you are now familiar with.
However, we can be more fancy and provide more understandable names for the groups and provide the underlying phylogenetic structure used:
-## A fancier dispRity object
- MCMCglmm.subsets(data = charadriiformes$data,
- my_covar <-posteriors = charadriiformes$posteriors,
- group = model_terms,
- tree = charadriiformes$tree,
- rename.groups = c(levels(charadriiformes$data$clade), "phylogeny"))
- ## Note that the group names is contained in the clade column of the charadriiformes dataset as factors
+## A fancier dispRity object
+my_covar <- MCMCglmm.subsets(data = charadriiformes$data,
+ posteriors = charadriiformes$posteriors,
+ group = model_terms,
+ tree = charadriiformes$tree,
+ rename.groups = c(levels(charadriiformes$data$clade), "phylogeny"))
+## Note that the group names is contained in the clade column of the charadriiformes dataset as factors
4.12.2 Visualising covar objects
One useful thing to do with these objects is then to visualise them in 2D.
Here we can use the covar.plot
function (that has many different options that just plot.dispRity
for plotting covar objects) to plot the trait space, the 95% confidence interval ellipses of the variance-covariance matrices and the major axes from these ellipses.
See the ?covar.plot
help page for all the options available:
-par(mfrow = c(2,2))
-## The traitspace
-covar.plot(my_covar, col = c("orange", "darkgreen", "blue"), main = "Trait space")
-## The traitspace's variance-covariance mean ellipses
-covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean VCV ellipses",
-points = FALSE, ellipses = mean)
- ## The traitspace's variance-covariance mean ellipses
-covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean major axes",
-points = FALSE, major.axes = mean)
- ## A bit of everything
-covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Ten random VCV matrices",
-points = TRUE, major.axes = TRUE, points.cex = 1/3, n = 10, ellipses = TRUE, legend = TRUE)
-
+par(mfrow = c(2,2))
+## The traitspace
+covar.plot(my_covar, col = c("orange", "darkgreen", "blue"), main = "Trait space")
+## The traitspace's variance-covariance mean ellipses
+covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean VCV ellipses",
+ points = FALSE, ellipses = mean)
+## The traitspace's variance-covariance mean ellipses
+covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean major axes",
+ points = FALSE, major.axes = mean)
+## A bit of everything
+covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Ten random VCV matrices",
+ points = TRUE, major.axes = TRUE, points.cex = 1/3, n = 10, ellipses = TRUE, legend = TRUE)
+
4.12.3 Disparity analyses with a $covar
component
You can then calculate disparity on the "dispRity"
object like shown previously.
For example, you can get the variances of the groups that where used in the model by using the normal dispRity
function:
-summary(dispRity(my_covar, metric = variances))
+
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 gulls 159 0.009 0.009 0.009 0.129 0.238
## 2 plovers 98 0.008 0.003 0.005 0.173 0.321
@@ -2992,8 +3056,8 @@ 4.12.3 Disparity analyses with a
To do that, you need to modify the metric to be recognised as a “covar” metric using the as.covar
function.
This function transforms any disparity metric (or disparity metric style function) to be applied to the $covar
part of a "dispRity"
object.
Basically this $covar
part is a list containing, for each posterior sample $VCV
, the variance-covariance matrix and $loc
, it’s optional location in the traitspace.
-## The first variance covariance matrix for the "gulls" group
-$covar[["gulls"]][[1]] my_covar
+
## $VCV
## [,1] [,2] [,3]
## [1,] 0.23258067 -2.180519e-02 -2.837630e-02
@@ -3003,69 +3067,207 @@ 4.12.3 Disparity analyses with a
## $loc
## [1] 0.0007118691 0.1338917465 -0.0145412698
And this is how as.covar
modifies the disparity metric:
-## Using the variances function on a VCV matrix
-variances(my_covar$covar[["gulls"]][[1]]$VCV)
+
## [1] 0.0221423147 0.0007148342 0.0005779815
-## The same but using it as a covar metric
-as.covar(variances)(my_covar$covar[["gulls"]][[1]])
+
## [1] 0.0221423147 0.0007148342 0.0005779815
-## The same but applied to the dispRity function
-summary(dispRity(my_covar, metric = as.covar(variances)))
+## The same but applied to the dispRity function
+summary(dispRity(my_covar, metric = as.covar(variances)))
## subsets n obs.median 2.5% 25% 75% 97.5%
## 1 gulls 159 0.001 0 0 0.012 0.068
## 2 plovers 98 0.000 0 0 0.000 0.002
## 3 sandpipers 102 0.000 0 0 0.000 0.016
## 4 phylogeny 359 0.000 0 0 0.006 0.020
+
+
+
+4.13 Disparity and distances
+There are two ways to use distances in dispRity
, either with your input data being directly a distance matrix or with your disparity metric involving some kind of distance calculations.
+
+4.13.1 Disparity data is a distance
+If your disparity data is a distance matrix, you can use the option dist.data = TRUE
in dispRity
to make sure that all the operations done on your data take into account the fact that your disparity data has distance properties.
+For example, if you bootstrap the data, this will automatically bootstrap both rows AND columns (i.e. so that the bootstrapped matrices are still distances).
+This also improves speed on some calculations if you use disparity metrics directly implemented in the package by avoiding recalculating distances (the full list can be seen in ?dispRity.metric
- they are usually the metrics with dist
in their name).
+
+4.13.1.1 Subsets
+By default, the dispRity
package does not treat any matrix as a distance matrix.
+It will however try to guess whether your input data is a distance matrix or not.
+This means that if you input a distance matrix, you might get a warning letting you know the input matrix might not be treated correctly (e.g. when bootstrapping or subsetting).
+For the functions dispRity
, custom.subsets
and chrono.subsets
you can simply toggle the option dist.data = TRUE
to make sure you treat your input data as a distance matrix throughout your analysis.
+## Creating a distance matrix
+distance_data <- as.matrix(dist(BeckLee_mat50))
+
+## Measuring the diagonal of the distance matrix
+dispRity(distance_data, metric = diag, dist.data = TRUE)
+## ---- dispRity object ----
+## 50 elements in one matrix with 50 dimensions.
+## Disparity was calculated as: diag.
+If you use a pipeline of any of these functions, you only need to specify it once and the data will be treated as a distance matrix throughout.
+## Creating a distance matrix
+distance_data <- as.matrix(dist(BeckLee_mat50))
+
+## Creating two subsets specifying that the data is a distance matrix
+subsets <- custom.subsets(distance_data, group = list(c(1:5), c(6:10)), dist.data = TRUE)
+## Measuring disparity treating the data as distance matrices
+dispRity(subsets, metric = diag)
+## ---- dispRity object ----
+## 2 customised subsets for 50 elements in one matrix with 50 dimensions:
+## 1, 2.
+## Disparity was calculated as: diag.
+## Measuring disparity treating the data as a normal matrix (toggling the option to FALSE)
+dispRity(subsets, metric = diag, dist.data = FALSE)
+## Warning in dispRity(subsets, metric = diag, dist.data = FALSE): data.dist is
+## set to FALSE (the data will not be treated as a distance matrix) even though
+## subsets contains distance treated data.
+## ---- dispRity object ----
+## 2 customised subsets for 50 elements in one matrix with 50 dimensions:
+## 1, 2.
+## Disparity was calculated as: diag.
+
+
+
+4.13.1.2 Bootstrapping
+The function boot.matrix
also can deal with distance matrices by bootstrapping both rows and columns in a linked way (e.g. if a bootstrap pseudo-replicate draws the values 1, 2, and 5, it will select both columns 1, 2, and 5 and rows 1, 2, and 5 - keeping the distance structure of the data).
+You can do that by using the boot.by = "dist"
function that will bootstrap the data in a distance matrix fashion:
+
+## ---- dispRity object ----
+## 50 elements in one matrix with 50 dimensions.
+## Rows and columns were bootstrapped 100 times (method:"full").
+Similarly to the dispRity
, custom.subsets
and chrono.subsets
function above, the option to treat the input data as a distance matrix is recorded and recycled so there is no need to specify it each time.
+
+
+
+4.13.2 Disparity metric is a distance
+On the other hand if your data is not a distance matrix but you are using a metric that uses some kind of distance calculations, you can use the option dist.helper
to greatly speed up calculations.
+dist.helper
can be either a pre-calculated distance matrix (or a list of distance matrices) or, better yet, a function to calculate distance matrices, like stats::dist
or vegan::vegdist
.
+This option directly stores the distance matrix separately in the RAM and allows the disparity metric to directly access it at every disparity calculation iteration, making it much faster.
+Note that if you provide a function for dist.helper
, you can also provide any un-ambiguous optional argument to that function, for example method = "euclidean"
.
+If you use a disparity metric implemented in dispRity
, the dist.helper
option is correctly loaded onto the RAM regardless of the argument you provide (a matrix, a list of matrix or any function to calculate a distance matrix).
+On the other hand, if you use your own function for the disparity metric, make sure that dist.helper
exactly matches the internal distance calculation function.
+For example if you use the already implemented pairwise.dist
metric all the following options will be using dist.helper
optimally:
+## Using the dist function from stats (specifying it comes from stats)
+dispRity(my_data, metric = pairwise.dist, dist.helper = stats::dist)
+
+## Using the dist function from vegdist function (without specifying its origin)
+dispRity(my_data, metric = pairwise.dist, dist.helper = vegdist)
+
+## Using some pre-calculated distance with a generic function
+my_distance_matrix <- dist(my_distance_data)
+dispRity(my_data, metric = pairwise.dist, dist.helper = my_distance_matrix)
+
+## Using some pre-calculated distance with a user function defined elsewhere
+my_distance_matrix <- my.personalised.function(my_distance_data)
+dispRity(my_data, metric = pairwise.dist, dist.helper = my_distance_matrix)
+However, if you use a homemade metric for calculating distances like this:
+## a personalised distance function
+my.sum.of.dist <- function(matrix) {
+ return(sum(dist(matrix)))
+}
+The dist.helper
will only work if you specify the function using the same syntax as in the user function:
+## The following uses the helper correctly (as in saves a lot of calculation time)
+dispRity(my_data, metric = my.sum.of.dist, dist.helper = dist)
+
+## These ones however, work but don't use the dist.helper (don't save time)
+## The dist.helper is not a function
+dispRity(my_data, metric = my.sum.of.dist, dist.helper = dist(my_data))
+## The dist.helper is not the correct function (should be dist)
+dispRity(my_data, metric = my.sum.of.dist, dist.helper = vegdist)
+## The dist.helper is not the correct function (should be just dist)
+dispRity(my_data, metric = my.sum.of.dist, dist.helper = stats::dist)
+
References
-
-
-Aguilera, Antonio, and Ricardo Pérez-Aguila. 2004. “General N-Dimensional Rotations.” http://wscg.zcu.cz/wscg2004/Papers_2004_Short/N29.pdf.
+
+
+Aguilera, Antonio, and Ricardo Pérez-Aguila. 2004. “General n-Dimensional Rotations.” http://wscg.zcu.cz/wscg2004/Papers_2004_Short/N29.pdf.
+
+
+Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
-
-Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
+
+Cooper, Natalie, Gavin H. Thomas, Chris Venditti, Andrew Meade, and Rob P. Freckleton. 2016. “A Cautionary Note on the Use of Ornstein Uhlenbeck Models in Macroevolutionary Studies.” Biological Journal of the Linnean Society 118 (1): 64–77. https://doi.org/10.1111/bij.12701.
-
-Cooper, Natalie, Gavin H. Thomas, Chris Venditti, Andrew Meade, and Rob P. Freckleton. 2016. “A Cautionary Note on the Use of Ornstein Uhlenbeck Models in Macroevolutionary Studies.” Biological Journal of the Linnean Society 118 (1): 64–77. https://doi.org/10.1111/bij.12701.
+
+Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
-
-Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
+
+Endler, John A, David A Westcott, Joah R Madden, and Tim Robson. 2005. “Animal Visual Systems and the Evolution of Color Patterns: Sensory Processing Illuminates Signal Evolution.” Evolution 59 (8): 1795–1818.
-
-Endler, John A, David A Westcott, Joah R Madden, and Tim Robson. 2005. “Animal Visual Systems and the Evolution of Color Patterns: Sensory Processing Illuminates Signal Evolution.” Evolution 59 (8): 1795–1818.
+
+Guillerme, T., and N. Cooper. 2018. “Time for a Rethink: Time Sub-Sampling Methods in Disparity-Through-Time Analyses.” Palaeontology 61 (4): 481–93. https://doi.org/10.1111/pala.12364.
-
-Guillerme, T., and N. Cooper. 2018. “Time for a Rethink: Time Sub-Sampling Methods in Disparity-Through-Time Analyses.” Palaeontology 61 (4): 481–93. https://doi.org/10.1111/pala.12364.
+
+Guillerme, Thomas, Jen A Bright, Christopher R Cooney, Emma C Hughes, Zoë K Varley, Natalie Cooper, Andrew P Beckerman, and Gavin H Thomas. 2023. “Innovation and Elaboration on the Avian Tree of Life.” Science Advances 9 (43): eadg1641.
-
-Guillerme, Thomas, Natalie Cooper, Stephen L. Brusatte, Katie E. Davis, Andrew L. Jackson, Sylvain Gerber, Anjali Goswami, et al. 2020. “Disparities in the Analysis of Morphological Disparity.” Biology Letters 16 (7): 20200199. https://doi.org/10.1098/rsbl.2020.0199.
+
+Guillerme, Thomas, Natalie Cooper, Stephen L. Brusatte, Katie E. Davis, Andrew L. Jackson, Sylvain Gerber, Anjali Goswami, et al. 2020. “Disparities in the Analysis of Morphological Disparity.” Biology Letters 16 (7): 20200199. https://doi.org/10.1098/rsbl.2020.0199.
-
-Guillerme, Thomas, and Kevin Healy. 2014. mulTree: a package for running MCMCglmm analysis on multiple trees. Zenodo. https://doi.org/10.5281/zenodo.12902.
+
+Guillerme, Thomas, and Kevin Healy. 2014. “mulTree: a package for running MCMCglmm analysis on multiple trees.” Zenodo. https://doi.org/10.5281/zenodo.12902.
-
-Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
+
+Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
-
-Hadfield, Jarrod D. 2010a. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
+
+Hadfield, Jarrod D. 2010a. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
-
-Hadfield, Jarrod D. 2010b. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
+
+———. 2010b. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
-
-Hunt, Gene. 2006. “Fitting and Comparing Models of Phyletic Evolution: Random Walks and Beyond.” Paleobiology 32 (4): 578–601. https://doi.org/10.1666/05070.1.
+
+Hunt, Gene. 2006. “Fitting and Comparing Models of Phyletic Evolution: Random Walks and Beyond.” Paleobiology 32 (4): 578–601. https://doi.org/10.1666/05070.1.
-
-Hunt, Gene. 2012. “Measuring Rates of Phenotypic Evolution and the Inseparability of Tempo and Mode.” Paleobiology 38 (3): 351–73. https://doi.org/10.1666/11047.1.
+
+———. 2012. “Measuring Rates of Phenotypic Evolution and the Inseparability of Tempo and Mode.” Paleobiology 38 (3): 351–73. https://doi.org/10.1666/11047.1.
-
-Hunt, Gene, Melanie J Hopkins, and Scott Lidgard. 2015. “Simple Versus Complex Models of Trait Evolution and Stasis as a Response to Environmental Change.” Proceedings of the National Academy of Sciences, 201403662. https://doi.org/10.1073/pnas.1403662111.
+
+Hunt, Gene, Melanie J Hopkins, and Scott Lidgard. 2015. “Simple Versus Complex Models of Trait Evolution and Stasis as a Response to Environmental Change.” Proceedings of the National Academy of Sciences, 201403662. https://doi.org/10.1073/pnas.1403662111.
-
-Murrell, David J. 2018. “A Global Envelope Test to Detect Non-Random Bursts of Trait Evolution.” Methods in Ecology and Evolution 9 (7): 1739–48. https://doi.org/10.1111/2041-210X.13006.
+
+Murrell, David J. 2018. “A Global Envelope Test to Detect Non-Random Bursts of Trait Evolution.” Methods in Ecology and Evolution 9 (7): 1739–48. https://doi.org/10.1111/2041-210X.13006.
diff --git a/inst/gitbook/_book/dispRity_manual.pdf b/inst/gitbook/_book/dispRity_manual.pdf
index d8479089..6915fce8 100644
Binary files a/inst/gitbook/_book/dispRity_manual.pdf and b/inst/gitbook/_book/dispRity_manual.pdf differ
diff --git a/inst/gitbook/_book/dispRity_manual.tex b/inst/gitbook/_book/dispRity_manual.tex
index 481e3b2e..7907a96c 100644
--- a/inst/gitbook/_book/dispRity_manual.tex
+++ b/inst/gitbook/_book/dispRity_manual.tex
@@ -4,18 +4,21 @@
%
\documentclass[
]{book}
-\usepackage{lmodern}
-\usepackage{amssymb,amsmath}
-\usepackage{ifxetex,ifluatex}
-\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
+\usepackage{amsmath,amssymb}
+\usepackage{iftex}
+\ifPDFTeX
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
- \usepackage{unicode-math}
+ \usepackage{unicode-math} % this also loads fontspec
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
+\usepackage{lmodern}
+\ifPDFTeX\else
+ % xetex/luatex font selection
+\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
@@ -33,14 +36,6 @@
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
-\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
-\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
-\hypersetup{
- pdftitle={dispRity R package manual},
- pdfauthor={Thomas Guillerme (guillert@tcd.ie)},
- hidelinks,
- pdfcreator={LaTeX via pandoc}}
-\urlstyle{same} % disable monospaced font for URLs
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
@@ -52,13 +47,13 @@
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
-\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
+\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
-\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
+\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
@@ -66,7 +61,7 @@
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
-\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
+\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
@@ -75,13 +70,14 @@
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
-\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
+\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
-\usepackage{longtable,booktabs}
+\usepackage{longtable,booktabs,array}
+\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
@@ -108,12 +104,23 @@
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
\usepackage{booktabs}
+\ifLuaTeX
+ \usepackage{selnolig} % disable illegal ligatures
+\fi
\usepackage[]{natbib}
\bibliographystyle{plainnat}
+\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
+\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
+\urlstyle{same}
+\hypersetup{
+ pdftitle={dispRity R package manual},
+ pdfauthor={Thomas Guillerme (guillert@tcd.ie)},
+ hidelinks,
+ pdfcreator={LaTeX via pandoc}}
\title{dispRity R package manual}
\author{Thomas Guillerme (\href{mailto:guillert@tcd.ie}{\nolinkurl{guillert@tcd.ie}})}
-\date{2023-12-06}
+\date{2024-11-12}
\begin{document}
\maketitle
@@ -153,7 +160,7 @@ \section{Installing and running the package}\label{installing-and-running-the-pa
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{install.packages}\NormalTok{(}\StringTok{"dispRity"}\NormalTok{)}
+\FunctionTok{install.packages}\NormalTok{(}\StringTok{"dispRity"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -161,11 +168,11 @@ \section{Installing and running the package}\label{installing-and-running-the-pa
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Checking if devtools is already installed}
-\ControlFlowTok{if}\NormalTok{(}\OperatorTok{!}\KeywordTok{require}\NormalTok{(devtools)) }\KeywordTok{install.packages}\NormalTok{(}\StringTok{"devtools"}\NormalTok{)}
+\DocumentationTok{\#\# Checking if devtools is already installed}
+\ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{require}\NormalTok{(devtools)) }\FunctionTok{install.packages}\NormalTok{(}\StringTok{"devtools"}\NormalTok{)}
-\CommentTok{\#\# Installing the latest released version directly from GitHub}
-\KeywordTok{install\_github}\NormalTok{(}\StringTok{"TGuillerme/dispRity"}\NormalTok{, }\DataTypeTok{ref =} \StringTok{"release"}\NormalTok{)}
+\DocumentationTok{\#\# Installing the latest released version directly from GitHub}
+\FunctionTok{install\_github}\NormalTok{(}\StringTok{"TGuillerme/dispRity"}\NormalTok{, }\AttributeTok{ref =} \StringTok{"release"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -223,8 +230,8 @@ \section{\texorpdfstring{\texttt{dispRity} is always changing, how do I know it'
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{testthat}\OperatorTok{::}\KeywordTok{expect\_equal}\NormalTok{(}\DataTypeTok{object =} \KeywordTok{mean}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)),}
- \DataTypeTok{expected =} \DecValTok{2}\NormalTok{)}
+\NormalTok{testthat}\SpecialCharTok{::}\FunctionTok{expect\_equal}\NormalTok{(}\AttributeTok{object =} \FunctionTok{mean}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{)),}
+ \AttributeTok{expected =} \DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -317,65 +324,30 @@ \chapter{Glossary}\label{glossary}}
\hypertarget{glossary-equivalences-in-palaeobiology-and-ecology}{%
\section{Glossary equivalences in palaeobiology and ecology}\label{glossary-equivalences-in-palaeobiology-and-ecology}}
-\begin{longtable}[]{@{}llll@{}}
-\toprule
-\begin{minipage}[b]{0.22\columnwidth}\raggedright
-In this manual\strut
-\end{minipage} & \begin{minipage}[b]{0.22\columnwidth}\raggedright
-In \texttt{dispRity}\strut
-\end{minipage} & \begin{minipage}[b]{0.26\columnwidth}\raggedright
-E.g. in palaeobiology\strut
-\end{minipage} & \begin{minipage}[b]{0.19\columnwidth}\raggedright
-E.g. in ecology\strut
-\end{minipage}\tabularnewline
-\midrule
+\begin{longtable}[]{@{}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2459}}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2459}}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2951}}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.2131}}@{}}
+\toprule\noalign{}
+\begin{minipage}[b]{\linewidth}\raggedright
+In this manual
+\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
+In \texttt{dispRity}
+\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
+E.g. in palaeobiology
+\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
+E.g. in ecology
+\end{minipage} \\
+\midrule\noalign{}
\endhead
-\begin{minipage}[t]{0.22\columnwidth}\raggedright
-the multidimensional space\strut
-\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright
-a \texttt{matrix} object (\(n\times d\))\strut
-\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright
-a morphospace\strut
-\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright
-a function-space\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.22\columnwidth}\raggedright
-elements\strut
-\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright
-rows (\(n\))\strut
-\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright
-taxa\strut
-\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright
-field experiments\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.22\columnwidth}\raggedright
-dimensions\strut
-\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright
-columns (\(d\))\strut
-\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright
-morphological characters\strut
-\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright
-communities' compositions\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.22\columnwidth}\raggedright
-subsets\strut
-\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright
-a \texttt{matrix} (\(m \times d\), with \(m \leq n\))\strut
-\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright
-time series\strut
-\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright
-experimental treatments\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.22\columnwidth}\raggedright
-disparity\strut
-\end{minipage} & \begin{minipage}[t]{0.22\columnwidth}\raggedright
-a \texttt{function}\strut
-\end{minipage} & \begin{minipage}[t]{0.26\columnwidth}\raggedright
-sum of variances\strut
-\end{minipage} & \begin{minipage}[t]{0.19\columnwidth}\raggedright
-ellipsoid volume\strut
-\end{minipage}\tabularnewline
-\bottomrule
+\bottomrule\noalign{}
+\endlastfoot
+the multidimensional space & a \texttt{matrix} object (\(n\times d\)) & a morphospace & a function-space \\
+elements & rows (\(n\)) & taxa & field experiments \\
+dimensions & columns (\(d\)) & morphological characters & communities' compositions \\
+subsets & a \texttt{matrix} (\(m \times d\), with \(m \leq n\)) & time series & experimental treatments \\
+disparity & a \texttt{function} & sum of variances & ellipsoid volume \\
\end{longtable}
\hypertarget{getting-started-with-disprity}{%
@@ -408,17 +380,17 @@ \subsection{\texorpdfstring{Ordination matrices from \texttt{geomorph}}{Ordinati
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{require}\NormalTok{(geomorph)}
+\FunctionTok{require}\NormalTok{(geomorph)}
-\CommentTok{\#\# Loading the plethodon dataset}
-\KeywordTok{data}\NormalTok{(plethodon)}
+\DocumentationTok{\#\# Loading the plethodon dataset}
+\FunctionTok{data}\NormalTok{(plethodon)}
-\CommentTok{\#\# Performing a Procrustes transform on the landmarks}
-\NormalTok{procrustes \textless{}{-}}\StringTok{ }\KeywordTok{gpagen}\NormalTok{(plethodon}\OperatorTok{$}\NormalTok{land, }\DataTypeTok{PrinAxes =} \OtherTok{FALSE}\NormalTok{,}
- \DataTypeTok{print.progress =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Performing a Procrustes transform on the landmarks}
+\NormalTok{procrustes }\OtherTok{\textless{}{-}} \FunctionTok{gpagen}\NormalTok{(plethodon}\SpecialCharTok{$}\NormalTok{land, }\AttributeTok{PrinAxes =} \ConstantTok{FALSE}\NormalTok{,}
+ \AttributeTok{print.progress =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# Ordinating this data}
-\KeywordTok{geomorph.ordination}\NormalTok{(procrustes)[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{,}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{]}
+\DocumentationTok{\#\# Ordinating this data}
+\FunctionTok{geomorph.ordination}\NormalTok{(procrustes)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
@@ -437,12 +409,12 @@ \subsection{\texorpdfstring{Ordination matrices from \texttt{geomorph}}{Ordinati
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Using a geomorph.data.frame}
-\NormalTok{geomorph\_df \textless{}{-}}\StringTok{ }\KeywordTok{geomorph.data.frame}\NormalTok{(procrustes,}
- \DataTypeTok{species =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{species, }\DataTypeTok{site =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{site)}
+\DocumentationTok{\#\# Using a geomorph.data.frame}
+\NormalTok{geomorph\_df }\OtherTok{\textless{}{-}} \FunctionTok{geomorph.data.frame}\NormalTok{(procrustes,}
+ \AttributeTok{species =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{species, }\AttributeTok{site =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{site)}
-\CommentTok{\#\# Ordinating this data and making a dispRity object}
-\KeywordTok{geomorph.ordination}\NormalTok{(geomorph\_df)}
+\DocumentationTok{\#\# Ordinating this data and making a dispRity object}
+\FunctionTok{geomorph.ordination}\NormalTok{(geomorph\_df)}
\end{Highlighting}
\end{Shaded}
@@ -462,10 +434,10 @@ \subsection{\texorpdfstring{Ordination matrices from \texttt{Claddis}}{Ordinatio
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{require}\NormalTok{(Claddis)}
+\FunctionTok{require}\NormalTok{(Claddis)}
-\CommentTok{\#\# Ordinating the example data from Claddis}
-\KeywordTok{Claddis.ordination}\NormalTok{(michaux\_}\DecValTok{1989}\NormalTok{)}
+\DocumentationTok{\#\# Ordinating the example data from Claddis}
+\FunctionTok{Claddis.ordination}\NormalTok{(michaux\_1989)}
\end{Highlighting}
\end{Shaded}
@@ -495,8 +467,8 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A multivariate matrix}
-\KeywordTok{head}\NormalTok{(USArrests)}
+\DocumentationTok{\#\# A multivariate matrix}
+\FunctionTok{head}\NormalTok{(USArrests)}
\end{Highlighting}
\end{Shaded}
@@ -512,12 +484,12 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Ordinating the matrix using \textasciigrave{}prcomp\textasciigrave{} }
-\NormalTok{ordination \textless{}{-}}\StringTok{ }\KeywordTok{prcomp}\NormalTok{(USArrests)}
+\DocumentationTok{\#\# Ordinating the matrix using \textasciigrave{}prcomp\textasciigrave{} }
+\NormalTok{ordination }\OtherTok{\textless{}{-}} \FunctionTok{prcomp}\NormalTok{(USArrests)}
-\CommentTok{\#\# Selecting the ordinated matrix}
-\NormalTok{ordinated\_matrix \textless{}{-}}\StringTok{ }\NormalTok{ordination}\OperatorTok{$}\NormalTok{x}
-\KeywordTok{head}\NormalTok{(ordinated\_matrix)}
+\DocumentationTok{\#\# Selecting the ordinated matrix}
+\NormalTok{ordinated\_matrix }\OtherTok{\textless{}{-}}\NormalTok{ ordination}\SpecialCharTok{$}\NormalTok{x}
+\FunctionTok{head}\NormalTok{(ordinated\_matrix)}
\end{Highlighting}
\end{Shaded}
@@ -541,8 +513,8 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A matrix of distances between cities}
-\KeywordTok{str}\NormalTok{(eurodist)}
+\DocumentationTok{\#\# A matrix of distances between cities}
+\FunctionTok{str}\NormalTok{(eurodist)}
\end{Highlighting}
\end{Shaded}
@@ -554,9 +526,9 @@ \subsection{Other kinds of ordination matrices}\label{other-kinds-of-ordination-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Ordinating the matrix using cmdscale() with k = 5 dimensions }
-\NormalTok{ordinated\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{cmdscale}\NormalTok{(eurodist, }\DataTypeTok{k =} \DecValTok{5}\NormalTok{)}
-\KeywordTok{head}\NormalTok{(ordinated\_matrix)}
+\DocumentationTok{\#\# Ordinating the matrix using cmdscale() with k = 5 dimensions }
+\NormalTok{ordinated\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{cmdscale}\NormalTok{(eurodist, }\AttributeTok{k =} \DecValTok{5}\NormalTok{)}
+\FunctionTok{head}\NormalTok{(ordinated\_matrix)}
\end{Highlighting}
\end{Shaded}
@@ -602,45 +574,45 @@ \subsection{Example data}\label{example-data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the ordinated matrices}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat50)}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat99)}
+\DocumentationTok{\#\# Loading the ordinated matrices}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat50)}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat99)}
-\CommentTok{\#\# The first five taxa and dimensions of the 50 taxa matrix}
-\KeywordTok{head}\NormalTok{(BeckLee\_mat50[, }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])}
+\DocumentationTok{\#\# The first five taxa and dimensions of the 50 taxa matrix}
+\FunctionTok{head}\NormalTok{(BeckLee\_mat50[, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [,1] [,2] [,3] [,4] [,5]
-## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039
-## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479
-## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646
-## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626
-## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914
-## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351
+## [,1] [,2] [,3] [,4] [,5]
+## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039
+## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479
+## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646
+## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626
+## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914
+## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The first five taxa and dimensions of the 99 taxa + ancestors matrix}
-\NormalTok{BeckLee\_mat99[}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{98}\NormalTok{, }\DecValTok{99}\NormalTok{), }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{]}
+\DocumentationTok{\#\# The first five taxa and dimensions of the 99 taxa + ancestors matrix}
+\NormalTok{BeckLee\_mat99[}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{98}\NormalTok{, }\DecValTok{99}\NormalTok{), }\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [,1] [,2] [,3] [,4] [,5]
-## Cimolestes -0.6794737 0.15658591 0.04918307 0.22509831 -0.38139436
-## Maelestes -0.5797289 0.04223105 -0.20329542 -0.15453876 -0.06993258
-## n48 0.2614394 0.01712426 0.21997583 -0.05383777 0.07919679
-## n49 0.3881123 0.13771446 0.11966941 0.01856597 -0.15263921
+## [,1] [,2] [,3] [,4] [,5]
+## Cimolestes -0.6662114 0.152778203 0.04859246 -0.34158286 0.26817202
+## Maelestes -0.5719365 0.051636855 -0.19877079 -0.08318416 -0.14166592
+## n48 0.2511551 -0.002014967 0.22408002 0.06857018 -0.05660113
+## n49 0.3860798 0.131742956 0.12604056 -0.14738050 0.05095751
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading a list of first and last occurrence dates for the fossils}
-\KeywordTok{data}\NormalTok{(BeckLee\_ages)}
-\KeywordTok{head}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Loading a list of first and last occurrence dates for the fossils}
+\FunctionTok{data}\NormalTok{(BeckLee\_ages)}
+\FunctionTok{head}\NormalTok{(BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -656,11 +628,11 @@ \subsection{Example data}\label{example-data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading and plotting the phylogeny}
-\KeywordTok{data}\NormalTok{(BeckLee\_tree)}
-\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{cex =} \FloatTok{0.8}\NormalTok{) }
-\KeywordTok{axisPhylo}\NormalTok{(}\DataTypeTok{root =} \DecValTok{140}\NormalTok{)}
-\KeywordTok{nodelabels}\NormalTok{(}\DataTypeTok{cex =} \FloatTok{0.5}\NormalTok{)}
+\DocumentationTok{\#\# Loading and plotting the phylogeny}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree)}
+\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{cex =} \FloatTok{0.8}\NormalTok{) }
+\FunctionTok{axisPhylo}\NormalTok{(}\AttributeTok{root =} \DecValTok{140}\NormalTok{)}
+\FunctionTok{nodelabels}\NormalTok{(}\AttributeTok{cex =} \FloatTok{0.5}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -693,10 +665,10 @@ \subsection{Disparity through time}\label{disparity-through-time}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity through time}
-\NormalTok{disparity\_data \textless{}{-}}\StringTok{ }\KeywordTok{dispRity.through.time}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances),}
- \DataTypeTok{time =} \DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Measuring disparity through time}
+\NormalTok{disparity\_data }\OtherTok{\textless{}{-}} \FunctionTok{dispRity.through.time}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances),}
+ \AttributeTok{time =} \DecValTok{3}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -705,7 +677,7 @@ \subsection{Disparity through time}\label{disparity-through-time}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Print the disparity\_data object}
+\DocumentationTok{\#\# Print the disparity\_data object}
\NormalTok{disparity\_data}
\end{Highlighting}
\end{Shaded}
@@ -714,7 +686,7 @@ \subsection{Disparity through time}\label{disparity-through-time}}
## ---- dispRity object ----
## 3 discrete time subsets for 50 elements in one matrix with 48 dimensions with 1 phylogenetic tree
## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: metric.
\end{verbatim}
@@ -724,8 +696,8 @@ \subsection{Disparity through time}\label{disparity-through-time}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising disparity through time}
-\KeywordTok{summary}\NormalTok{(disparity\_data)}
+\DocumentationTok{\#\# Summarising disparity through time}
+\FunctionTok{summary}\NormalTok{(disparity\_data)}
\end{Highlighting}
\end{Shaded}
@@ -738,8 +710,8 @@ \subsection{Disparity through time}\label{disparity-through-time}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(disparity\_data, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(disparity\_data, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -747,10 +719,10 @@ \subsection{Disparity through time}\label{disparity-through-time}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing for an difference among the time bins}
-\NormalTok{disp\_lm \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(disparity\_data, }\DataTypeTok{test =}\NormalTok{ lm,}
- \DataTypeTok{comparisons =} \StringTok{"all"}\NormalTok{)}
-\KeywordTok{summary}\NormalTok{(disp\_lm)}
+\DocumentationTok{\#\# Testing for an difference among the time bins}
+\NormalTok{disp\_lm }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(disparity\_data, }\AttributeTok{test =}\NormalTok{ lm,}
+ \AttributeTok{comparisons =} \StringTok{"all"}\NormalTok{)}
+\FunctionTok{summary}\NormalTok{(disp\_lm)}
\end{Highlighting}
\end{Shaded}
@@ -801,13 +773,13 @@ \subsection{Disparity among groups}\label{disparity-among-groups}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating the two groups (crown versus stem) as a list}
-\NormalTok{mammal\_groups \textless{}{-}}\StringTok{ }\KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Creating the two groups (crown versus stem) as a list}
+\NormalTok{mammal\_groups }\OtherTok{\textless{}{-}} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# Measuring disparity for each group}
-\NormalTok{disparity\_data \textless{}{-}}\StringTok{ }\KeywordTok{dispRity.per.group}\NormalTok{(BeckLee\_mat50,}
- \DataTypeTok{group =}\NormalTok{ mammal\_groups,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))}
+\DocumentationTok{\#\# Measuring disparity for each group}
+\NormalTok{disparity\_data }\OtherTok{\textless{}{-}} \FunctionTok{dispRity.per.group}\NormalTok{(BeckLee\_mat50,}
+ \AttributeTok{group =}\NormalTok{ mammal\_groups,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))}
\end{Highlighting}
\end{Shaded}
@@ -815,7 +787,7 @@ \subsection{Disparity among groups}\label{disparity-among-groups}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Print the disparity\_data object}
+\DocumentationTok{\#\# Print the disparity\_data object}
\NormalTok{disparity\_data}
\end{Highlighting}
\end{Shaded}
@@ -824,14 +796,14 @@ \subsection{Disparity among groups}\label{disparity-among-groups}}
## ---- dispRity object ----
## 2 customised subsets for 50 elements in one matrix with 48 dimensions:
## crown, stem.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: metric.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising disparity in the different groups}
-\KeywordTok{summary}\NormalTok{(disparity\_data)}
+\DocumentationTok{\#\# Summarising disparity in the different groups}
+\FunctionTok{summary}\NormalTok{(disparity\_data)}
\end{Highlighting}
\end{Shaded}
@@ -843,8 +815,8 @@ \subsection{Disparity among groups}\label{disparity-among-groups}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(disparity\_data)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(disparity\_data)}
\end{Highlighting}
\end{Shaded}
@@ -852,8 +824,8 @@ \subsection{Disparity among groups}\label{disparity-among-groups}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing for a difference between the groups}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_data, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{details =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Testing for a difference between the groups}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_data, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{details =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -879,11 +851,11 @@ \chapter{Details of specific functions}\label{details-of-specific-functions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the data}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat50)}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat99)}
-\KeywordTok{data}\NormalTok{(BeckLee\_tree)}
-\KeywordTok{data}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Loading the data}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat50)}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat99)}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree)}
+\FunctionTok{data}\NormalTok{(BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -924,10 +896,10 @@ \subsection{Time-binning}\label{time-binning}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Generating three time bins containing the taxa present every 40 Ma}
-\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,}
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{))}
+\DocumentationTok{\#\# Generating three time bins containing the taxa present every 40 Ma}
+\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,}
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -941,10 +913,10 @@ \subsection{Time-binning}\label{time-binning}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Automatically generate three equal length bins:}
-\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Automatically generate three equal length bins:}
+\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{3}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -962,9 +934,9 @@ \subsection{Time-binning}\label{time-binning}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Displaying the table of first and last occurrence dates}
-\CommentTok{\#\# for each taxa}
-\KeywordTok{head}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Displaying the table of first and last occurrence dates}
+\DocumentationTok{\#\# for each taxa}
+\FunctionTok{head}\NormalTok{(BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -980,10 +952,10 @@ \subsection{Time-binning}\label{time-binning}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Generating time bins including taxa that might span between them}
-\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,}
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{), }\DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+\DocumentationTok{\#\# Generating time bins including taxa that might span between them}
+\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,}
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{), }\AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -1046,12 +1018,12 @@ \subsection{Time-slicing}\label{time-slicing}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Generating four time slices every 40 million years}
-\CommentTok{\#\# under a model of proximity evolution}
-\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree, }
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,}
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+\DocumentationTok{\#\# Generating four time slices every 40 million years}
+\DocumentationTok{\#\# under a model of proximity evolution}
+\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree, }
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,}
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -1063,10 +1035,10 @@ \subsection{Time-slicing}\label{time-slicing}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Generating four time slices automatically}
-\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{4}\NormalTok{, }\DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+\DocumentationTok{\#\# Generating four time slices automatically}
+\FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{4}\NormalTok{, }\AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -1084,11 +1056,11 @@ \section{Customised subsets}\label{custom-subsets}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating the two groups (crown and stems)}
-\NormalTok{mammal\_groups \textless{}{-}}\StringTok{ }\KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Creating the two groups (crown and stems)}
+\NormalTok{mammal\_groups }\OtherTok{\textless{}{-}} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# Separating the dataset into two different groups}
-\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{group =}\NormalTok{ mammal\_groups)}
+\DocumentationTok{\#\# Separating the dataset into two different groups}
+\FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\AttributeTok{group =}\NormalTok{ mammal\_groups)}
\end{Highlighting}
\end{Shaded}
@@ -1103,10 +1075,10 @@ \section{Customised subsets}\label{custom-subsets}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating the three groups as a list}
-\NormalTok{weird\_groups \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"even"}\NormalTok{ =}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{1}\NormalTok{, }\DataTypeTok{to =} \DecValTok{49}\NormalTok{, }\DataTypeTok{by =} \DecValTok{2}\NormalTok{),}
- \StringTok{"odd"}\NormalTok{ =}\StringTok{ }\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{2}\NormalTok{, }\DataTypeTok{to =} \DecValTok{50}\NormalTok{, }\DataTypeTok{by =} \DecValTok{2}\NormalTok{),}
- \StringTok{"all"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{50}\NormalTok{))}
+\DocumentationTok{\#\# Creating the three groups as a list}
+\NormalTok{weird\_groups }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"even"} \OtherTok{=} \FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{1}\NormalTok{, }\AttributeTok{to =} \DecValTok{49}\NormalTok{, }\AttributeTok{by =} \DecValTok{2}\NormalTok{),}
+ \StringTok{"odd"} \OtherTok{=} \FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{2}\NormalTok{, }\AttributeTok{to =} \DecValTok{50}\NormalTok{, }\AttributeTok{by =} \DecValTok{2}\NormalTok{),}
+ \StringTok{"all"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{50}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -1114,8 +1086,8 @@ \section{Customised subsets}\label{custom-subsets}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating groups as clades}
-\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{group =}\NormalTok{ BeckLee\_tree)}
+\DocumentationTok{\#\# Creating groups as clades}
+\FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50, }\AttributeTok{group =}\NormalTok{ BeckLee\_tree)}
\end{Highlighting}
\end{Shaded}
@@ -1130,15 +1102,15 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Default bootstrapping}
-\KeywordTok{boot.matrix}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat50)}
+\DocumentationTok{\#\# Default bootstrapping}
+\FunctionTok{boot.matrix}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat50)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
\end{verbatim}
The number of bootstrap replicates can be defined using the \texttt{bootstraps} option.
@@ -1157,15 +1129,15 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Bootstrapping with the single bootstrap method}
-\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{boot.type =} \StringTok{"single"}\NormalTok{)}
+\DocumentationTok{\#\# Bootstrapping with the single bootstrap method}
+\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\AttributeTok{boot.type =} \StringTok{"single"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 100 times (method:"single").
+## Rows were bootstrapped 100 times (method:"single").
\end{verbatim}
This function also allows users to rarefy the data using the \texttt{rarefaction} argument.
@@ -1178,65 +1150,79 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Bootstrapping with the full rarefaction}
-\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{bootstraps =} \DecValTok{20}\NormalTok{,}
- \DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Bootstrapping with the full rarefaction}
+\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\AttributeTok{bootstraps =} \DecValTok{20}\NormalTok{,}
+ \AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 20 times (method:"full") and fully rarefied.
+## Rows were bootstrapped 20 times (method:"full") and fully rarefied.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Or with a set number of rarefaction levels}
-\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{bootstraps =} \DecValTok{20}\NormalTok{,}
- \DataTypeTok{rarefaction =} \KeywordTok{c}\NormalTok{(}\DecValTok{6}\OperatorTok{:}\DecValTok{8}\NormalTok{, }\DecValTok{3}\NormalTok{))}
+\DocumentationTok{\#\# Or with a set number of rarefaction levels}
+\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\AttributeTok{bootstraps =} \DecValTok{20}\NormalTok{,}
+ \AttributeTok{rarefaction =} \FunctionTok{c}\NormalTok{(}\DecValTok{6}\SpecialCharTok{:}\DecValTok{8}\NormalTok{, }\DecValTok{3}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements.
+## Rows were bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements.
\end{verbatim}
\begin{quote}
Note that using the \texttt{rarefaction} argument also bootstraps the data. In these examples, the function bootstraps the data (without rarefaction) AND also bootstraps the data with the different rarefaction levels.
\end{quote}
-One other argument is \texttt{dimensions} that specifies how many dimensions from the matrix should be used for further analysis.
-When missing, all dimensions from the ordinated matrix are used.
-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Using the first 50\% of the dimensions}
-\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{dimensions =} \FloatTok{0.5}\NormalTok{)}
+\DocumentationTok{\#\# Creating subsets of crown and stem mammals}
+\NormalTok{crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50,}
+ \AttributeTok{group =} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree,}
+ \AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{))}
+\DocumentationTok{\#\# Bootstrapping and rarefying these groups}
+\FunctionTok{boot.matrix}\NormalTok{(crown\_stem, }\AttributeTok{bootstraps =} \DecValTok{200}\NormalTok{, }\AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
-## 50 elements in one matrix with 24 dimensions.
-## Data was bootstrapped 100 times (method:"full").
+## 2 customised subsets for 50 elements in one matrix with 48 dimensions:
+## crown, stem.
+## Rows were bootstrapped 200 times (method:"full") and fully rarefied.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Using the first 10 dimensions}
-\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{dimensions =} \DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Creating time slice subsets}
+\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,}
+ \AttributeTok{tree =}\NormalTok{ BeckLee\_tree, }
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{, }
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+
+\DocumentationTok{\#\# Bootstrapping the time slice subsets}
+\FunctionTok{boot.matrix}\NormalTok{(time\_slices, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
-## 50 elements in one matrix with 1 dimensions.
-## Data was bootstrapped 100 times (method:"full").
+## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
+## 120, 80, 40, 0.
+## Rows were bootstrapped 100 times (method:"full").
\end{verbatim}
+\hypertarget{bootstrapping-with-probabilities}{%
+\subsection{Bootstrapping with probabilities}\label{bootstrapping-with-probabilities}}
+
It is also possible to specify the sampling probability in the bootstrap for each elements.
This can be useful for weighting analysis for example (i.e.~giving more importance to specific elements).
These probabilities can be passed to the \texttt{prob} argument individually with a vector with the elements names or with a matrix with the rownames as elements names.
@@ -1244,60 +1230,69 @@ \section{Bootstraps and rarefactions}\label{bootstraps-and-rarefactions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Attributing a weight of 0 to Cimolestes and 10 to Maelestes}
-\KeywordTok{boot.matrix}\NormalTok{(BeckLee\_mat50,}
- \DataTypeTok{prob =} \KeywordTok{c}\NormalTok{(}\StringTok{"Cimolestes"}\NormalTok{ =}\StringTok{ }\DecValTok{0}\NormalTok{, }\StringTok{"Maelestes"}\NormalTok{ =}\StringTok{ }\DecValTok{10}\NormalTok{))}
+\DocumentationTok{\#\# Attributing a weight of 0 to Cimolestes and 10 to Maelestes}
+\FunctionTok{boot.matrix}\NormalTok{(BeckLee\_mat50,}
+ \AttributeTok{prob =} \FunctionTok{c}\NormalTok{(}\StringTok{"Cimolestes"} \OtherTok{=} \DecValTok{0}\NormalTok{, }\StringTok{"Maelestes"} \OtherTok{=} \DecValTok{10}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## ---- dispRity object ----
## 50 elements in one matrix with 48 dimensions.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
\end{verbatim}
-Of course, one could directly supply the subsets generated above (using \texttt{chrono.subsets} or \texttt{custom.subsets}) to this function.
+\hypertarget{bootstrapping-dimensions}{%
+\subsection{Bootstrapping dimensions}\label{bootstrapping-dimensions}}
+
+In some cases, you might also be interested in bootstrapping dimensions rather than observations.
+I.e. bootstrapping the columns of a matrix rather than the rows.
+
+It's pretty easy! By default, \texttt{boot.matrix} uses the option \texttt{boot.by\ =\ "rows"} which you can toggle to \texttt{boot.by\ =\ "columns"}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating subsets of crown and stem mammals}
-\NormalTok{crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50,}
- \DataTypeTok{group =} \KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree,}
- \DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{))}
-\CommentTok{\#\# Bootstrapping and rarefying these groups}
-\KeywordTok{boot.matrix}\NormalTok{(crown\_stem, }\DataTypeTok{bootstraps =} \DecValTok{200}\NormalTok{, }\DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Bootstrapping the observations (default)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\NormalTok{boot\_obs }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(}\AttributeTok{data =}\NormalTok{ crown\_stem, }\AttributeTok{boot.by =} \StringTok{"rows"}\NormalTok{)}
+
+\DocumentationTok{\#\# Bootstrapping the columns rather than the rows}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\NormalTok{boot\_dim }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(}\AttributeTok{data =}\NormalTok{ crown\_stem, }\AttributeTok{boot.by =} \StringTok{"columns"}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
+In these two examples, the first one \texttt{boot\_obs} bootstraps the rows as showed before (default behaviour).
+But the second one, \texttt{boot\_dim} bootstraps the dimensions.
+That means that for each bootstrap sample, the value calculated is actually obtained by reshuffling the dimensions (columns) rather than the observations (rows).
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Measuring disparity and summarising}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(boot\_obs, }\AttributeTok{metric =}\NormalTok{ sum))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## ---- dispRity object ----
-## 2 customised subsets for 50 elements in one matrix with 48 dimensions:
-## crown, stem.
-## Data was bootstrapped 200 times (method:"full") and fully rarefied.
+## subsets n obs bs.median 2.5% 25% 75% 97.5%
+## 1 crown 30 -1.1 -2.04 -19.4 -7.56 3.621 14.64
+## 2 stem 20 1.1 1.52 -10.8 -1.99 6.712 13.97
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating time slice subsets}
-\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,}
- \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree, }
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{, }
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
-
-\CommentTok{\#\# Bootstrapping the time slice subsets}
-\KeywordTok{boot.matrix}\NormalTok{(time\_slices, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{)}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(boot\_dim, }\AttributeTok{metric =}\NormalTok{ sum))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## ---- dispRity object ----
-## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
-## 120, 80, 40, 0.
-## Data was bootstrapped 100 times (method:"full").
+## subsets n obs bs.median 2.5% 25% 75% 97.5%
+## 1 crown 30 -1.1 -2.04 -18.5 -8.84 5.440 19.80
+## 2 stem 20 1.1 1.31 -16.7 -2.99 6.338 14.99
\end{verbatim}
+Note here how the observed sum is the same (no bootstrapping) but the bootstrapping distributions are quiet different even though the same seed was used.
+
\hypertarget{disparity-metrics}{%
\section{Disparity metrics}\label{disparity-metrics}}
@@ -1344,26 +1339,26 @@ \subsubsection{Dimension-level 1 functions}\label{dimension-level-1-functions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating a dummy matrix}
-\NormalTok{dummy\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Creating a dummy matrix}
+\NormalTok{dummy\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)}
-\CommentTok{\#\# Example of dimension{-}level 1 functions}
-\KeywordTok{mean}\NormalTok{(dummy\_matrix)}
+\DocumentationTok{\#\# Example of dimension{-}level 1 functions}
+\FunctionTok{mean}\NormalTok{(dummy\_matrix)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [1] 0.1012674
+## [1] -0.183358
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{median}\NormalTok{(dummy\_matrix)}
+\FunctionTok{median}\NormalTok{(dummy\_matrix)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [1] 0.3345108
+## [1] -0.3909538
\end{verbatim}
Any summary metric such as mean or median are good examples of dimension-level 1 functions as they reduce the matrix to a single dimension (i.e.~one value).
@@ -1375,16 +1370,16 @@ \subsubsection{Dimension-level 2 functions}\label{dimension-level-2-functions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Defining the function as the product of rows}
-\NormalTok{prod.rows \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix) }\KeywordTok{apply}\NormalTok{(matrix, }\DecValTok{1}\NormalTok{, prod)}
+\DocumentationTok{\#\# Defining the function as the product of rows}
+\NormalTok{prod.rows }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) }\FunctionTok{apply}\NormalTok{(matrix, }\DecValTok{1}\NormalTok{, prod)}
-\CommentTok{\#\# A dimension{-}level 2 metric}
-\KeywordTok{prod.rows}\NormalTok{(dummy\_matrix)}
+\DocumentationTok{\#\# A dimension{-}level 2 metric}
+\FunctionTok{prod.rows}\NormalTok{(dummy\_matrix)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [1] 0.72217818 2.48612354 -0.08986575 0.58266449
+## [1] 0.63727584 -0.09516528 -1.24477435 -0.10958022
\end{verbatim}
Several dimension-level 2 functions are implemented in \texttt{dispRity} (see \texttt{?dispRity.metric}) such as the \texttt{variances} or \texttt{ranges} functions that calculate the variance or the range of each dimension of the ordinated matrix respectively.
@@ -1397,31 +1392,31 @@ \subsubsection{Dimension-level 3 functions}\label{dimension-level-3-functions}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A dimension{-}level 3 metric}
-\KeywordTok{var}\NormalTok{(dummy\_matrix)}
+\DocumentationTok{\#\# A dimension{-}level 3 metric}
+\FunctionTok{var}\NormalTok{(dummy\_matrix)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [,1] [,2] [,3]
-## [1,] 1.8570383 0.7417569 -0.5131686
-## [2,] 0.7417569 1.3194330 -1.5344429
-## [3,] -0.5131686 -1.5344429 2.8070556
+## [,1] [,2] [,3]
+## [1,] 0.6356714 -0.2017617 0.2095042
+## [2,] -0.2017617 1.3656124 1.0850900
+## [3,] 0.2095042 1.0850900 1.0879400
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A dimension{-}level 3 metric with a forced matrix output}
-\KeywordTok{as.matrix}\NormalTok{(}\KeywordTok{dist}\NormalTok{(dummy\_matrix))}
+\DocumentationTok{\#\# A dimension{-}level 3 metric with a forced matrix output}
+\FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(dummy\_matrix))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## 1 2 3 4
-## 1 0.000000 4.794738 3.382990 3.297110
-## 2 4.794738 0.000000 2.400321 3.993864
-## 3 3.382990 2.400321 0.000000 2.187412
-## 4 3.297110 3.993864 2.187412 0.000000
+## 1 0.000000 1.390687 2.156388 2.984951
+## 2 1.390687 0.000000 2.557670 1.602143
+## 3 2.156388 2.557670 0.000000 3.531033
+## 4 2.984951 1.602143 3.531033 0.000000
\end{verbatim}
\hypertarget{betweengroupmetricsexplain}{%
@@ -1435,9 +1430,9 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A simple example}
-\NormalTok{mean.difference \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix, matrix2) \{}
- \KeywordTok{mean}\NormalTok{(matrix) }\OperatorTok{{-}}\StringTok{ }\KeywordTok{mean}\NormalTok{(matrix2)}
+\DocumentationTok{\#\# A simple example}
+\NormalTok{mean.difference }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix, matrix2) \{}
+ \FunctionTok{mean}\NormalTok{(matrix) }\SpecialCharTok{{-}} \FunctionTok{mean}\NormalTok{(matrix2)}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}
@@ -1448,16 +1443,16 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A second matrix}
-\NormalTok{dummy\_matrix2 \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{runif}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# A second matrix}
+\NormalTok{dummy\_matrix2 }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{runif}\NormalTok{(}\DecValTok{12}\NormalTok{), }\DecValTok{4}\NormalTok{, }\DecValTok{3}\NormalTok{)}
-\CommentTok{\#\# The difference between groups}
-\KeywordTok{mean.difference}\NormalTok{(dummy\_matrix, dummy\_matrix2)}
+\DocumentationTok{\#\# The difference between groups}
+\FunctionTok{mean.difference}\NormalTok{(dummy\_matrix, dummy\_matrix2)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [1] -0.3194556
+## [1] -0.5620336
\end{verbatim}
Beyond this super simple example, it might probably be interesting to use this metric on \texttt{dispRity} objects, especially the ones from \protect\hyperlink{custom-subsets}{\texttt{custom.subsets}} and \protect\hyperlink{chrono-subsets}{\texttt{chrono.subsets}}.
@@ -1466,18 +1461,18 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Combining both matrices}
-\NormalTok{big\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{rbind}\NormalTok{(dummy\_matrix, dummy\_matrix2)}
-\KeywordTok{rownames}\NormalTok{(big\_matrix) \textless{}{-}}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{8}
+\DocumentationTok{\#\# Combining both matrices}
+\NormalTok{big\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(dummy\_matrix, dummy\_matrix2)}
+\FunctionTok{rownames}\NormalTok{(big\_matrix) }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\DecValTok{8}
-\CommentTok{\#\# Making a dispRity object with both groups}
-\NormalTok{grouped\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(big\_matrix,}
- \DataTypeTok{group =} \KeywordTok{c}\NormalTok{(}\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{), }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{)))}
+\DocumentationTok{\#\# Making a dispRity object with both groups}
+\NormalTok{grouped\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(big\_matrix,}
+ \AttributeTok{group =} \FunctionTok{c}\NormalTok{(}\FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{), }\FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{)))}
-\CommentTok{\#\# Calculating the mean difference between groups}
-\NormalTok{(mean\_differences \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(grouped\_matrix,}
- \DataTypeTok{metric =}\NormalTok{ mean.difference,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# Calculating the mean difference between groups}
+\NormalTok{(mean\_differences }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(grouped\_matrix,}
+ \AttributeTok{metric =}\NormalTok{ mean.difference,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -1490,8 +1485,8 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising the object}
-\KeywordTok{summary}\NormalTok{(mean\_differences)}
+\DocumentationTok{\#\# Summarising the object}
+\FunctionTok{summary}\NormalTok{(mean\_differences)}
\end{Highlighting}
\end{Shaded}
@@ -1502,8 +1497,8 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Note how the summary table now indicates}
-\CommentTok{\#\# the number of elements for each group}
+\DocumentationTok{\#\# Note how the summary table now indicates}
+\DocumentationTok{\#\# the number of elements for each group}
\end{Highlighting}
\end{Shaded}
@@ -1512,27 +1507,27 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A dispRity object with multiple groups}
-\NormalTok{grouped\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(big\_matrix,}
- \DataTypeTok{group =} \KeywordTok{c}\NormalTok{(}\StringTok{"A"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{),}
- \StringTok{"B"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{),}
- \StringTok{"C"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{2}\OperatorTok{:}\DecValTok{6}\NormalTok{), }
- \StringTok{"D"}\NormalTok{ =}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{8}\NormalTok{)))}
+\DocumentationTok{\#\# A dispRity object with multiple groups}
+\NormalTok{grouped\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(big\_matrix,}
+ \AttributeTok{group =} \FunctionTok{c}\NormalTok{(}\StringTok{"A"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{),}
+ \StringTok{"B"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{),}
+ \StringTok{"C"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{2}\SpecialCharTok{:}\DecValTok{6}\NormalTok{), }
+ \StringTok{"D"} \OtherTok{=} \FunctionTok{list}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{8}\NormalTok{)))}
-\CommentTok{\#\# Measuring disparity between all groups}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_matrix, }\DataTypeTok{metric =}\NormalTok{ mean.difference,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# Measuring disparity between all groups}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_matrix, }\AttributeTok{metric =}\NormalTok{ mean.difference,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n_1 n_2 obs
## 1 A:B 4 4 0.000
-## 2 A:C 4 5 -0.172
-## 3 A:D 4 8 -0.160
-## 4 B:C 4 5 -0.172
-## 5 B:D 4 8 -0.160
-## 6 C:D 5 8 0.012
+## 2 A:C 4 5 -0.269
+## 3 A:D 4 8 -0.281
+## 4 B:C 4 5 -0.269
+## 5 B:D 4 8 -0.281
+## 6 C:D 5 8 -0.012
\end{verbatim}
For \texttt{dispRity} objects generated by \texttt{chrono.subsets} (not shown here), the \texttt{dispRity} function will by default apply the metric on the groups in a serial way (group 1 vs.~group 2, group 2 vs.~group 3, group 3 vs.~group 4, etc\ldots).
@@ -1540,17 +1535,17 @@ \subsection{Between groups metrics}\label{betweengroupmetricsexplain}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity between specific groups}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_matrix, }\DataTypeTok{metric =}\NormalTok{ mean.difference,}
- \DataTypeTok{between.groups =} \KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{), }\KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{), }\KeywordTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{,}\DecValTok{1}\NormalTok{))))}
+\DocumentationTok{\#\# Measuring disparity between specific groups}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_matrix, }\AttributeTok{metric =}\NormalTok{ mean.difference,}
+ \AttributeTok{between.groups =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{,}\DecValTok{1}\NormalTok{))))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n_1 n_2 obs
-## 1 A:C 4 5 -0.172
-## 2 C:A 5 4 0.172
-## 3 D:A 8 4 0.160
+## 1 A:C 4 5 -0.269
+## 2 C:A 5 4 0.269
+## 3 D:A 8 4 0.281
\end{verbatim}
Note that in any case, the order of the comparison can matter.
@@ -1578,9 +1573,9 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Which dimension{-}level is the mean function?}
-\CommentTok{\#\# And can it be used in dispRity?}
-\KeywordTok{make.metric}\NormalTok{(mean)}
+\DocumentationTok{\#\# Which dimension{-}level is the mean function?}
+\DocumentationTok{\#\# And can it be used in dispRity?}
+\FunctionTok{make.metric}\NormalTok{(mean)}
\end{Highlighting}
\end{Shaded}
@@ -1591,9 +1586,9 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Which dimension{-}level is the prod.rows function?}
-\CommentTok{\#\# And can it be used in dispRity?}
-\KeywordTok{make.metric}\NormalTok{(prod.rows)}
+\DocumentationTok{\#\# Which dimension{-}level is the prod.rows function?}
+\DocumentationTok{\#\# And can it be used in dispRity?}
+\FunctionTok{make.metric}\NormalTok{(prod.rows)}
\end{Highlighting}
\end{Shaded}
@@ -1604,9 +1599,9 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Which dimension{-}level is the var function?}
-\CommentTok{\#\# And can it be used in dispRity?}
-\KeywordTok{make.metric}\NormalTok{(var)}
+\DocumentationTok{\#\# Which dimension{-}level is the var function?}
+\DocumentationTok{\#\# And can it be used in dispRity?}
+\FunctionTok{make.metric}\NormalTok{(var)}
\end{Highlighting}
\end{Shaded}
@@ -1621,13 +1616,13 @@ \subsection{\texorpdfstring{\texttt{make.metric}}{make.metric}}\label{makemetric
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing whether mean is dimension{-}level 1}
-\ControlFlowTok{if}\NormalTok{(}\KeywordTok{make.metric}\NormalTok{(mean, }\DataTypeTok{silent =} \OtherTok{TRUE}\NormalTok{)}\OperatorTok{$}\NormalTok{type }\OperatorTok{!=}\StringTok{ "level1"}\NormalTok{) \{}
- \KeywordTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)}
+\DocumentationTok{\#\# Testing whether mean is dimension{-}level 1}
+\ControlFlowTok{if}\NormalTok{(}\FunctionTok{make.metric}\NormalTok{(mean, }\AttributeTok{silent =} \ConstantTok{TRUE}\NormalTok{)}\SpecialCharTok{$}\NormalTok{type }\SpecialCharTok{!=} \StringTok{"level1"}\NormalTok{) \{}
+ \FunctionTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)}
\NormalTok{\}}
-\CommentTok{\#\# Testing whether var is dimension{-}level 1}
-\ControlFlowTok{if}\NormalTok{(}\KeywordTok{make.metric}\NormalTok{(var, }\DataTypeTok{silent =} \OtherTok{TRUE}\NormalTok{)}\OperatorTok{$}\NormalTok{type }\OperatorTok{!=}\StringTok{ "level1"}\NormalTok{) \{}
- \KeywordTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)}
+\DocumentationTok{\#\# Testing whether var is dimension{-}level 1}
+\ControlFlowTok{if}\NormalTok{(}\FunctionTok{make.metric}\NormalTok{(var, }\AttributeTok{silent =} \ConstantTok{TRUE}\NormalTok{)}\SpecialCharTok{$}\NormalTok{type }\SpecialCharTok{!=} \StringTok{"level1"}\NormalTok{) \{}
+ \FunctionTok{message}\NormalTok{(}\StringTok{"The metric is not dimension{-}level 1."}\NormalTok{)}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}
@@ -1643,10 +1638,10 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity as the standard deviation}
-\CommentTok{\#\# of all the values of the}
-\CommentTok{\#\# ordinated matrix (dimension{-}level 1 function).}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =}\NormalTok{ sd))}
+\DocumentationTok{\#\# Measuring disparity as the standard deviation}
+\DocumentationTok{\#\# of all the values of the}
+\DocumentationTok{\#\# ordinated matrix (dimension{-}level 1 function).}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =}\NormalTok{ sd))}
\end{Highlighting}
\end{Shaded}
@@ -1657,10 +1652,10 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity as the standard deviation}
-\CommentTok{\#\# of the variance of each axis of}
-\CommentTok{\#\# the ordinated matrix (dimension{-}level 1 and 2 functions).}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sd, variances)))}
+\DocumentationTok{\#\# Measuring disparity as the standard deviation}
+\DocumentationTok{\#\# of the variance of each axis of}
+\DocumentationTok{\#\# the ordinated matrix (dimension{-}level 1 and 2 functions).}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sd, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -1671,10 +1666,10 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity as the standard deviation}
-\CommentTok{\#\# of the variance of each axis of}
-\CommentTok{\#\# the variance covariance matrix (dimension{-}level 1, 2 and 3 functions).}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sd, variances, var)), }\DataTypeTok{round =} \DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Measuring disparity as the standard deviation}
+\DocumentationTok{\#\# of the variance of each axis of}
+\DocumentationTok{\#\# the variance covariance matrix (dimension{-}level 1, 2 and 3 functions).}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sd, variances, var)), }\AttributeTok{round =} \DecValTok{10}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -1687,19 +1682,19 @@ \subsection{\texorpdfstring{Metrics in the \texttt{dispRity} function}{Metrics i
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Disparity as the standard deviation of the variance of each axis of the}
-\CommentTok{\#\# variance covariance matrix:}
-\NormalTok{disparity1 \textless{}{-}}\StringTok{ }\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sd, variances, var)),}
- \DataTypeTok{round =} \DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Disparity as the standard deviation of the variance of each axis of the}
+\DocumentationTok{\#\# variance covariance matrix:}
+\NormalTok{disparity1 }\OtherTok{\textless{}{-}} \FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sd, variances, var)),}
+ \AttributeTok{round =} \DecValTok{10}\NormalTok{)}
-\CommentTok{\#\# Same as above but using a different function order for the metric argument}
-\NormalTok{disparity2 \textless{}{-}}\StringTok{ }\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(variances, sd, var)),}
- \DataTypeTok{round =} \DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Same as above but using a different function order for the metric argument}
+\NormalTok{disparity2 }\OtherTok{\textless{}{-}} \FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(variances, sd, var)),}
+ \AttributeTok{round =} \DecValTok{10}\NormalTok{)}
-\CommentTok{\#\# Both ways output the same disparity values:}
-\NormalTok{disparity1 }\OperatorTok{==}\StringTok{ }\NormalTok{disparity2}
+\DocumentationTok{\#\# Both ways output the same disparity values:}
+\NormalTok{disparity1 }\SpecialCharTok{==}\NormalTok{ disparity2}
\end{Highlighting}
\end{Shaded}
@@ -1718,272 +1713,54 @@ \subsection{\texorpdfstring{Metrics implemented in \texttt{dispRity}}{Metrics im
Several disparity metrics are implemented in the \texttt{dispRity} package.
The detailed list can be found in \texttt{?dispRity.metric} along with some description of each metric.
-\begin{longtable}[]{@{}llll@{}}
-\toprule
-\begin{minipage}[b]{0.07\columnwidth}\raggedright
-Level\strut
-\end{minipage} & \begin{minipage}[b]{0.07\columnwidth}\raggedright
-Name\strut
-\end{minipage} & \begin{minipage}[b]{0.64\columnwidth}\raggedright
-Description\strut
-\end{minipage} & \begin{minipage}[b]{0.10\columnwidth}\raggedright
-Source\strut
-\end{minipage}\tabularnewline
-\midrule
+\begin{longtable}[]{@{}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.0845}}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.0845}}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.7183}}
+ >{\raggedright\arraybackslash}p{(\columnwidth - 6\tabcolsep) * \real{0.1127}}@{}}
+\toprule\noalign{}
+\begin{minipage}[b]{\linewidth}\raggedright
+Level
+\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
+Name
+\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
+Description
+\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
+Source
+\end{minipage} \\
+\midrule\noalign{}
\endhead
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{ancestral.dist}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The distance between an element and its ancestor\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{angles}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The angle of main variation of each dimensions\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{centroids}1\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The distance between each element and the centroid of the ordinated space\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{convhull.surface}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The surface of the convex hull formed by all the elements\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$area}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{convhull.volume}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The volume of the convex hull formed by all the elements\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$vol}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{deviations}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The minimal distance between each element and a hyperplane\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{diagonal}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The longest distance in the ordinated space (like the diagonal in two dimensions)\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{disalignment}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The rejection of the centroid of a matrix from the major axis of another (typically an \texttt{"as.covar"} metric)\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{displacements}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The ratio between the distance from a reference and the distance from the centroid\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{edge.length.tree}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The edge lengths of the elements on a tree\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{ape}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{ellipsoid.volume}1\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The volume of the ellipsoid of the space\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-Donohue \emph{et al.} (2013)\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{func.div}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The functional divergence (the ratio of deviation from the centroid)\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FDiv} but without abundance)\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{func.eve}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The functional evenness (the minimal spanning tree distances evenness)\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FEve} but without abundance)\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{group.dist}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The distance between two groups\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{mode.val}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The modal value\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{n.ball.volume}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The hyper-spherical (\emph{n}-ball) volume\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{neighbours}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The distance to specific neighbours (e.g.~the nearest neighbours - by default)\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{pairwise.dist}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The pairwise distances between elements\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::vegist}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{point.dist}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The distance between one group and the point of another group\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{projections}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The distance \emph{on} (projection) or \emph{from} (rejection) an arbitrary vector\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{projections.between}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-\texttt{projections} metric applied between groups\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{projections.tree}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The \texttt{projections} metric but where the vector can be based on a tree\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{quantiles}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The \emph{n}th quantile range per axis\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{radius}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The radius of each dimensions\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{ranges}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The range of each dimension\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-1\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{roundness}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The integral of the ranked scaled eigenvalues of a variance-covariance matrix\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{span.tree.length}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The minimal spanning tree length\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::spantree}\strut
-\end{minipage}\tabularnewline
-\begin{minipage}[t]{0.07\columnwidth}\raggedright
-2\strut
-\end{minipage} & \begin{minipage}[t]{0.07\columnwidth}\raggedright
-\texttt{variances}\strut
-\end{minipage} & \begin{minipage}[t]{0.64\columnwidth}\raggedright
-The variance of each dimension\strut
-\end{minipage} & \begin{minipage}[t]{0.10\columnwidth}\raggedright
-\texttt{dispRity}\strut
-\end{minipage}\tabularnewline
-\bottomrule
+\bottomrule\noalign{}
+\endlastfoot
+2 & \texttt{ancestral.dist} & The distance between an element and its ancestor & \texttt{dispRity} \\
+2 & \texttt{angles} & The angle of main variation of each dimensions & \texttt{dispRity} \\
+2 & \texttt{centroids}1 & The distance between each element and the centroid of the ordinated space & \texttt{dispRity} \\
+1 & \texttt{convhull.surface} & The surface of the convex hull formed by all the elements & \href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$area} \\
+1 & \texttt{convhull.volume} & The volume of the convex hull formed by all the elements & \href{https://cran.r-project.org/web/packages/geometry/index.html}{\texttt{geometry}}\texttt{::convhulln\$vol} \\
+2 & \texttt{count.neighbours} & The number of neigbhours to each element in a specified radius & \texttt{dispRity} \\
+2 & \texttt{deviations} & The minimal distance between each element and a hyperplane & \texttt{dispRity} \\
+1 & \texttt{diagonal} & The longest distance in the ordinated space (like the diagonal in two dimensions) & \texttt{dispRity} \\
+1 & \texttt{disalignment} & The rejection of the centroid of a matrix from the major axis of another (typically an \texttt{"as.covar"} metric) & \texttt{dispRity} \\
+2 & \texttt{displacements} & The ratio between the distance from a reference and the distance from the centroid & \texttt{dispRity} \\
+1 & \texttt{edge.length.tree} & The edge lengths of the elements on a tree & \texttt{ape} \\
+1 & \texttt{ellipsoid.volume}1 & The volume of the ellipsoid of the space & Donohue \emph{et al.} (2013) \\
+1 & \texttt{func.div} & The functional divergence (the ratio of deviation from the centroid) & \texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FDiv} but without abundance) \\
+1 & \texttt{func.eve} & The functional evenness (the minimal spanning tree distances evenness) & \texttt{dispRity} (similar to \href{https://cran.r-project.org/web/packages/FD/index.html}{\texttt{FD}}\texttt{::dbFD\$FEve} but without abundance) \\
+1 & \texttt{group.dist} & The distance between two groups & \texttt{dispRity} \\
+1 & \texttt{mode.val} & The modal value & \texttt{dispRity} \\
+1 & \texttt{n.ball.volume} & The hyper-spherical (\emph{n}-ball) volume & \texttt{dispRity} \\
+2 & \texttt{neighbours} & The distance to specific neighbours (e.g.~the nearest neighbours - by default) & \texttt{dispRity} \\
+2 & \texttt{pairwise.dist} & The pairwise distances between elements & \href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::vegist} \\
+2 & \texttt{point.dist} & The distance between one group and the point of another group & \texttt{dispRity} \\
+2 & \texttt{projections} & The distance \emph{on} (projection) or \emph{from} (rejection) an arbitrary vector & \texttt{dispRity} \\
+1 & \texttt{projections.between} & \texttt{projections} metric applied between groups & \texttt{dispRity} \\
+2 & \texttt{projections.tree} & The \texttt{projections} metric but where the vector can be based on a tree & \texttt{dispRity} \\
+2 & \texttt{quantiles} & The \emph{n}th quantile range per axis & \texttt{dispRity} \\
+2 & \texttt{radius} & The radius of each dimensions & \texttt{dispRity} \\
+2 & \texttt{ranges} & The range of each dimension & \texttt{dispRity} \\
+1 & \texttt{roundness} & The integral of the ranked scaled eigenvalues of a variance-covariance matrix & \texttt{dispRity} \\
+2 & \texttt{span.tree.length} & The minimal spanning tree length & \href{https://cran.r-project.org/web/packages/vegan/index.html}{\texttt{vegan}}\texttt{::spantree} \\
+2 & \texttt{variances} & The variance of each dimension & \texttt{dispRity} \\
\end{longtable}
1: Note that by default, the centroid is the centroid of the elements.
@@ -2074,10 +1851,10 @@ \subsection{Using the different disparity metrics}\label{using-the-different-dis
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating a 10*5 normal space}
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\NormalTok{dummy\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{, rnorm)}
-\KeywordTok{rownames}\NormalTok{(dummy\_space) \textless{}{-}}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{10}
+\DocumentationTok{\#\# Creating a 10*5 normal space}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\NormalTok{dummy\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{, rnorm)}
+\FunctionTok{rownames}\NormalTok{(dummy\_space) }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\DecValTok{10}
\end{Highlighting}
\end{Shaded}
@@ -2092,8 +1869,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the ellipsoid volume}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ ellipsoid.volume))}
+\DocumentationTok{\#\# Calculating the ellipsoid volume}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ ellipsoid.volume))}
\end{Highlighting}
\end{Shaded}
@@ -2108,8 +1885,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the convex hull surface}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ convhull.surface))}
+\DocumentationTok{\#\# Calculating the convex hull surface}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ convhull.surface))}
\end{Highlighting}
\end{Shaded}
@@ -2120,8 +1897,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the convex hull volume}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ convhull.volume))}
+\DocumentationTok{\#\# Calculating the convex hull volume}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ convhull.volume))}
\end{Highlighting}
\end{Shaded}
@@ -2132,8 +1909,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the convex hull volume}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ n.ball.volume))}
+\DocumentationTok{\#\# Calculating the convex hull volume}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ n.ball.volume))}
\end{Highlighting}
\end{Shaded}
@@ -2149,8 +1926,8 @@ \subsubsection{Volumes and surface metrics}\label{volumes-and-surface-metrics}}
Cautionary note: measuring volumes in a high number of dimensions can be strongly affected by the \href{https://en.wikipedia.org/wiki/Curse_of_dimensionality}{curse of dimensionality} that often results in near 0 disparity values. I strongly recommend reading \href{https://beta.observablehq.com/@tophtucker/theres-plenty-of-room-in-the-corners}{this really intuitive explanation} from \href{https://github.com/tophtucker}{Toph Tucker}.
\end{quote}
-\hypertarget{ranges-variances-quantiles-radius-pairwise-distance-neighbours-modal-value-and-diagonal}{%
-\subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbours, modal value and diagonal}\label{ranges-variances-quantiles-radius-pairwise-distance-neighbours-modal-value-and-diagonal}}
+\hypertarget{ranges-variances-quantiles-radius-pairwise-distance-neighbours-and-counting-them-modal-value-and-diagonal}{%
+\subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbours (and counting them), modal value and diagonal}\label{ranges-variances-quantiles-radius-pairwise-distance-neighbours-and-counting-them-modal-value-and-diagonal}}
The functions \texttt{ranges}, \texttt{variances} \texttt{radius}, \texttt{pairwise.dist}, \texttt{mode.val} and \texttt{diagonal} all measure properties of the ordinated space based on its dimensional properties (they are also less affected by the ``curse of dimensionality''):
@@ -2158,8 +1935,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the ranges of each dimension in the ordinated space}
-\KeywordTok{ranges}\NormalTok{(dummy\_space)}
+\DocumentationTok{\#\# Calculating the ranges of each dimension in the ordinated space}
+\FunctionTok{ranges}\NormalTok{(dummy\_space)}
\end{Highlighting}
\end{Shaded}
@@ -2169,8 +1946,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the distribution of these ranges}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ ranges))}
+\DocumentationTok{\#\# Calculating disparity as the distribution of these ranges}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ ranges))}
\end{Highlighting}
\end{Shaded}
@@ -2181,8 +1958,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the sum and the product of these ranges}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, ranges)))}
+\DocumentationTok{\#\# Calculating disparity as the sum and the product of these ranges}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, ranges)))}
\end{Highlighting}
\end{Shaded}
@@ -2193,7 +1970,7 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(prod, ranges)))}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(prod, ranges)))}
\end{Highlighting}
\end{Shaded}
@@ -2204,9 +1981,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the variances of each dimension in the}
-\CommentTok{\#\# ordinated space}
-\KeywordTok{variances}\NormalTok{(dummy\_space)}
+\DocumentationTok{\#\# Calculating the variances of each dimension in the}
+\DocumentationTok{\#\# ordinated space}
+\FunctionTok{variances}\NormalTok{(dummy\_space)}
\end{Highlighting}
\end{Shaded}
@@ -2216,8 +1993,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the distribution of these variances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ variances))}
+\DocumentationTok{\#\# Calculating disparity as the distribution of these variances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ variances))}
\end{Highlighting}
\end{Shaded}
@@ -2228,9 +2005,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the sum and}
-\CommentTok{\#\# the product of these variances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\DocumentationTok{\#\# Calculating disparity as the sum and}
+\DocumentationTok{\#\# the product of these variances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -2241,7 +2018,7 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(prod, variances)))}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(prod, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -2252,9 +2029,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the quantiles of each dimension}
-\CommentTok{\#\# in the ordinated space}
-\KeywordTok{quantiles}\NormalTok{(dummy\_space)}
+\DocumentationTok{\#\# Calculating the quantiles of each dimension}
+\DocumentationTok{\#\# in the ordinated space}
+\FunctionTok{quantiles}\NormalTok{(dummy\_space)}
\end{Highlighting}
\end{Shaded}
@@ -2264,8 +2041,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the distribution of these variances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ quantiles))}
+\DocumentationTok{\#\# Calculating disparity as the distribution of these variances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ quantiles))}
\end{Highlighting}
\end{Shaded}
@@ -2276,10 +2053,10 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# By default, the quantile calculated is the 95\%}
-\CommentTok{\#\# (i.e. 95\% of the data on each axis)}
-\CommentTok{\#\# this can be changed using the option quantile:}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ quantiles, }\DataTypeTok{quantile =} \DecValTok{50}\NormalTok{))}
+\DocumentationTok{\#\# By default, the quantile calculated is the 95\%}
+\DocumentationTok{\#\# (i.e. 95\% of the data on each axis)}
+\DocumentationTok{\#\# this can be changed using the option quantile:}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ quantiles, }\AttributeTok{quantile =} \DecValTok{50}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2290,8 +2067,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the radius of each dimension in the ordinated space}
-\KeywordTok{radius}\NormalTok{(dummy\_space)}
+\DocumentationTok{\#\# Calculating the radius of each dimension in the ordinated space}
+\FunctionTok{radius}\NormalTok{(dummy\_space)}
\end{Highlighting}
\end{Shaded}
@@ -2301,9 +2078,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# By default the radius is the maximum distance from the centre of}
-\CommentTok{\#\# the dimension. It can however be changed to any function:}
-\KeywordTok{radius}\NormalTok{(dummy\_space, }\DataTypeTok{type =}\NormalTok{ min)}
+\DocumentationTok{\#\# By default the radius is the maximum distance from the centre of}
+\DocumentationTok{\#\# the dimension. It can however be changed to any function:}
+\FunctionTok{radius}\NormalTok{(dummy\_space, }\AttributeTok{type =}\NormalTok{ min)}
\end{Highlighting}
\end{Shaded}
@@ -2313,7 +2090,7 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{radius}\NormalTok{(dummy\_space, }\DataTypeTok{type =}\NormalTok{ mean)}
+\FunctionTok{radius}\NormalTok{(dummy\_space, }\AttributeTok{type =}\NormalTok{ mean)}
\end{Highlighting}
\end{Shaded}
@@ -2323,10 +2100,10 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the mean average radius}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, radius),}
- \DataTypeTok{type =}\NormalTok{ mean))}
+\DocumentationTok{\#\# Calculating disparity as the mean average radius}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, radius),}
+ \AttributeTok{type =}\NormalTok{ mean))}
\end{Highlighting}
\end{Shaded}
@@ -2339,8 +2116,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The average pairwise euclidean distance}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, pairwise.dist)))}
+\DocumentationTok{\#\# The average pairwise euclidean distance}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, pairwise.dist)))}
\end{Highlighting}
\end{Shaded}
@@ -2351,9 +2128,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distribution of the Manhattan distances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ pairwise.dist,}
- \DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{))}
+\DocumentationTok{\#\# The distribution of the Manhattan distances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ pairwise.dist,}
+ \AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2364,8 +2141,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The average nearest neighbour distances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ neighbours))}
+\DocumentationTok{\#\# The average nearest neighbour distances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ neighbours))}
\end{Highlighting}
\end{Shaded}
@@ -2376,9 +2153,9 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The average furthest neighbour manhattan distances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ neighbours,}
- \DataTypeTok{which =}\NormalTok{ max, }\DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{))}
+\DocumentationTok{\#\# The average furthest neighbour manhattan distances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ neighbours,}
+ \AttributeTok{which =}\NormalTok{ max, }\AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2387,6 +2164,34 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
## 1 1 10 7.895 6.15 6.852 9.402 10.99
\end{verbatim}
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# The overall number of neighbours per point}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ count.neighbours,}
+ \AttributeTok{relative =} \ConstantTok{FALSE}\NormalTok{))}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 10 6.5 0.675 4.25 7 7.775
+\end{verbatim}
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# The relative number of neigbhours}
+\DocumentationTok{\#\# two standard deviations of each element}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ count.neighbours,}
+ \AttributeTok{radius =} \ControlFlowTok{function}\NormalTok{(x)(}\FunctionTok{sd}\NormalTok{(x)}\SpecialCharTok{*}\DecValTok{2}\NormalTok{),}
+ \AttributeTok{relative =} \ConstantTok{TRUE}\NormalTok{))}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 10 0.55 0.068 0.3 0.7 0.7
+\end{verbatim}
+
Note that this function is a direct call to \texttt{vegan::vegdist(matrix,\ method\ =\ method,\ diag\ =\ FALSE,\ upper\ =\ FALSE,\ ...)}.
The \texttt{diagonal} function measures the multidimensional diagonal of the whole space (i.e.~in our case the longest Euclidean distance in our five dimensional space).
@@ -2394,8 +2199,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the ordinated space\textquotesingle{}s diagonal}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ diagonal))}
+\DocumentationTok{\#\# Calculating the ordinated space\textquotesingle{}s diagonal}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ diagonal))}
\end{Highlighting}
\end{Shaded}
@@ -2406,8 +2211,8 @@ \subsubsection{Ranges, variances, quantiles, radius, pairwise distance, neighbou
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating the modal value of the matrix}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ mode.val))}
+\DocumentationTok{\#\# Calculating the modal value of the matrix}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ mode.val))}
\end{Highlighting}
\end{Shaded}
@@ -2428,8 +2233,8 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distribution of the distances between each element and their centroid}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ centroids))}
+\DocumentationTok{\#\# The distribution of the distances between each element and their centroid}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ centroids))}
\end{Highlighting}
\end{Shaded}
@@ -2440,8 +2245,8 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Disparity as the median value of these distances}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids)))}
+\DocumentationTok{\#\# Disparity as the median value of these distances}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids)))}
\end{Highlighting}
\end{Shaded}
@@ -2454,9 +2259,9 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distance between each element and the origin}
-\CommentTok{\#\# of the ordinated space}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ centroids, }\DataTypeTok{centroid =} \DecValTok{0}\NormalTok{))}
+\DocumentationTok{\#\# The distance between each element and the origin}
+\DocumentationTok{\#\# of the ordinated space}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ centroids, }\AttributeTok{centroid =} \DecValTok{0}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2467,10 +2272,10 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Disparity as the distance between each element}
-\CommentTok{\#\# and a specific point in space}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ centroids,}
- \DataTypeTok{centroid =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))}
+\DocumentationTok{\#\# Disparity as the distance between each element}
+\DocumentationTok{\#\# and a specific point in space}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ centroids,}
+ \AttributeTok{centroid =} \FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -2484,12 +2289,12 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Create a custom subsets object}
-\NormalTok{dummy\_groups \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(dummy\_space,}
- \DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}\StringTok{"group1"}\NormalTok{ =}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{,}
- \StringTok{"group2"}\NormalTok{ =}\StringTok{ }\DecValTok{6}\OperatorTok{:}\DecValTok{10}\NormalTok{))}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_groups, }\DataTypeTok{metric =}\NormalTok{ centroids,}
- \DataTypeTok{centroid =} \KeywordTok{colMeans}\NormalTok{(}\KeywordTok{get.matrix}\NormalTok{(dummy\_groups, }\StringTok{"group1"}\NormalTok{))))}
+\DocumentationTok{\#\# Create a custom subsets object}
+\NormalTok{dummy\_groups }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(dummy\_space,}
+ \AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\StringTok{"group1"} \OtherTok{=} \DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{,}
+ \StringTok{"group2"} \OtherTok{=} \DecValTok{6}\SpecialCharTok{:}\DecValTok{10}\NormalTok{))}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_groups, }\AttributeTok{metric =}\NormalTok{ centroids,}
+ \AttributeTok{centroid =} \FunctionTok{colMeans}\NormalTok{(}\FunctionTok{get.matrix}\NormalTok{(dummy\_groups, }\StringTok{"group1"}\NormalTok{))))}
\end{Highlighting}
\end{Shaded}
@@ -2505,8 +2310,8 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The relative displacement of the group in space to the centre}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ displacements))}
+\DocumentationTok{\#\# The relative displacement of the group in space to the centre}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ displacements))}
\end{Highlighting}
\end{Shaded}
@@ -2517,9 +2322,9 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The relative displacement of the group to an arbitrary point}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ displacements,}
- \DataTypeTok{reference =} \KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))}
+\DocumentationTok{\#\# The relative displacement of the group to an arbitrary point}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ displacements,}
+ \AttributeTok{reference =} \FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{,}\DecValTok{3}\NormalTok{,}\DecValTok{4}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -2533,37 +2338,37 @@ \subsubsection{Centroids, displacements and ancestral distances metrics}\label{c
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A generating a random tree with node labels}
-\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{makeNodeLabel}\NormalTok{(}\KeywordTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{), }\DataTypeTok{prefix =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Adding the tip and node names to the matrix}
-\NormalTok{dummy\_space2 \textless{}{-}}\StringTok{ }\NormalTok{dummy\_space[}\OperatorTok{{-}}\DecValTok{1}\NormalTok{,]}
-\KeywordTok{rownames}\NormalTok{(dummy\_space2) \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(my\_tree}\OperatorTok{$}\NormalTok{tip.label,}
-\NormalTok{ my\_tree}\OperatorTok{$}\NormalTok{node.label)}
+\DocumentationTok{\#\# A generating a random tree with node labels}
+\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{makeNodeLabel}\NormalTok{(}\FunctionTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{), }\AttributeTok{prefix =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Adding the tip and node names to the matrix}
+\NormalTok{dummy\_space2 }\OtherTok{\textless{}{-}}\NormalTok{ dummy\_space[}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{,]}
+\FunctionTok{rownames}\NormalTok{(dummy\_space2) }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(my\_tree}\SpecialCharTok{$}\NormalTok{tip.label,}
+\NormalTok{ my\_tree}\SpecialCharTok{$}\NormalTok{node.label)}
-\CommentTok{\#\# Calculating the distances from the ancestral nodes}
-\NormalTok{ancestral\_dist \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(dummy\_space2, }\DataTypeTok{metric =}\NormalTok{ ancestral.dist,}
- \DataTypeTok{tree =}\NormalTok{ my\_tree)}
+\DocumentationTok{\#\# Calculating the distances from the ancestral nodes}
+\NormalTok{ancestral\_dist }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(dummy\_space2, }\AttributeTok{metric =}\NormalTok{ ancestral.dist,}
+ \AttributeTok{tree =}\NormalTok{ my\_tree)}
-\CommentTok{\#\# The ancestral distances distributions}
-\KeywordTok{summary}\NormalTok{(ancestral\_dist)}
+\DocumentationTok{\#\# The ancestral distances distributions}
+\FunctionTok{summary}\NormalTok{(ancestral\_dist)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs.median 2.5% 25% 75% 97.5%
-## 1 1 9 1.729 0.286 1.653 1.843 3.981
+## 1 1 9 2.193 0.343 1.729 2.595 3.585
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the sum of the distances from all the ancestral nodes}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(ancestral\_dist, }\DataTypeTok{metric =}\NormalTok{ sum))}
+\DocumentationTok{\#\# Calculating disparity as the sum of the distances from all the ancestral nodes}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(ancestral\_dist, }\AttributeTok{metric =}\NormalTok{ sum))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs
-## 1 1 9 17.28
+## 1 1 9 18.93
\end{verbatim}
\hypertarget{minimal-spanning-tree-length}{%
@@ -2573,8 +2378,8 @@ \subsubsection{Minimal spanning tree length}\label{minimal-spanning-tree-length}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The length of the minimal spanning tree}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, span.tree.length)))}
+\DocumentationTok{\#\# The length of the minimal spanning tree}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, span.tree.length)))}
\end{Highlighting}
\end{Shaded}
@@ -2594,8 +2399,8 @@ \subsubsection{Functional divergence and evenness}\label{functional-divergence-a
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The ratio of deviation from the centroid }
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ func.div))}
+\DocumentationTok{\#\# The ratio of deviation from the centroid }
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ func.div))}
\end{Highlighting}
\end{Shaded}
@@ -2606,8 +2411,8 @@ \subsubsection{Functional divergence and evenness}\label{functional-divergence-a
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The minimal spanning tree distances evenness}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ func.eve))}
+\DocumentationTok{\#\# The minimal spanning tree distances evenness}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ func.eve))}
\end{Highlighting}
\end{Shaded}
@@ -2618,9 +2423,9 @@ \subsubsection{Functional divergence and evenness}\label{functional-divergence-a
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The minimal spanning tree manhanttan distances evenness}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ func.eve,}
- \DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{))}
+\DocumentationTok{\#\# The minimal spanning tree manhanttan distances evenness}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ func.eve,}
+ \AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2637,9 +2442,9 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distribution of each angles in degrees for each}
-\CommentTok{\#\# main axis in the matrix}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ angles))}
+\DocumentationTok{\#\# The distribution of each angles in degrees for each}
+\DocumentationTok{\#\# main axis in the matrix}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ angles))}
\end{Highlighting}
\end{Shaded}
@@ -2650,9 +2455,9 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distribution of slopes deviating from the 1:1 slope:}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ angles, }\DataTypeTok{unit =} \StringTok{"slope"}\NormalTok{,}
- \DataTypeTok{base =} \DecValTok{1}\NormalTok{))}
+\DocumentationTok{\#\# The distribution of slopes deviating from the 1:1 slope:}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ angles, }\AttributeTok{unit =} \StringTok{"slope"}\NormalTok{,}
+ \AttributeTok{base =} \DecValTok{1}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2667,9 +2472,9 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distribution of the deviation of each point}
-\CommentTok{\#\# from the least square hyperplane}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ deviations))}
+\DocumentationTok{\#\# The distribution of the deviation of each point}
+\DocumentationTok{\#\# from the least square hyperplane}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ deviations))}
\end{Highlighting}
\end{Shaded}
@@ -2682,10 +2487,10 @@ \subsubsection{Orientation: angles and deviations}\label{orientation-angles-and-
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The distribution of the deviation of each point}
-\CommentTok{\#\# from a slope (with only the two first dimensions)}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space[, }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{)], }\DataTypeTok{metric =}\NormalTok{ deviations,}
- \DataTypeTok{hyperplane =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{{-}1}\NormalTok{)))}
+\DocumentationTok{\#\# The distribution of the deviation of each point}
+\DocumentationTok{\#\# from a slope (with only the two first dimensions)}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space[, }\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{)], }\AttributeTok{metric =}\NormalTok{ deviations,}
+ \AttributeTok{hyperplane =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -2708,11 +2513,11 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The elaboration on the axis defined by the first and}
-\CommentTok{\#\# second row in the dummy\_space}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ projections,}
- \DataTypeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],}
- \DataTypeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,]))}
+\DocumentationTok{\#\# The elaboration on the axis defined by the first and}
+\DocumentationTok{\#\# second row in the dummy\_space}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ projections,}
+ \AttributeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],}
+ \AttributeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,]))}
\end{Highlighting}
\end{Shaded}
@@ -2723,11 +2528,11 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The exploration on the same axis}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ projections,}
- \DataTypeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],}
- \DataTypeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],}
- \DataTypeTok{measure =} \StringTok{"distance"}\NormalTok{))}
+\DocumentationTok{\#\# The exploration on the same axis}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ projections,}
+ \AttributeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],}
+ \AttributeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],}
+ \AttributeTok{measure =} \StringTok{"distance"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2741,12 +2546,12 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The elaboration on the same axis using the dummy\_space\textquotesingle{}s}
-\CommentTok{\#\# unit vector}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(dummy\_space, }\DataTypeTok{metric =}\NormalTok{ projections,}
- \DataTypeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],}
- \DataTypeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],}
- \DataTypeTok{scale =} \OtherTok{FALSE}\NormalTok{))}
+\DocumentationTok{\#\# The elaboration on the same axis using the dummy\_space\textquotesingle{}s}
+\DocumentationTok{\#\# unit vector}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(dummy\_space, }\AttributeTok{metric =}\NormalTok{ projections,}
+ \AttributeTok{point1 =}\NormalTok{ dummy\_space[}\DecValTok{1}\NormalTok{,],}
+ \AttributeTok{point2 =}\NormalTok{ dummy\_space[}\DecValTok{2}\NormalTok{,],}
+ \AttributeTok{scale =} \ConstantTok{FALSE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2784,57 +2589,56 @@ \subsubsection{Projections and phylo projections: elaboration and exploration}\l
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Adding a extra row to dummy matrix (to match dummy\_tree)}
-\NormalTok{tree\_space \textless{}{-}}\StringTok{ }\KeywordTok{rbind}\NormalTok{(dummy\_space, }\DataTypeTok{root =} \KeywordTok{rnorm}\NormalTok{(}\DecValTok{5}\NormalTok{))}
-\CommentTok{\#\# Creating a random dummy tree (with labels matching the ones from tree\_space)}
-\NormalTok{dummy\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{6}\NormalTok{)}
-\NormalTok{dummy\_tree}\OperatorTok{$}\NormalTok{tip.label \textless{}{-}}\StringTok{ }\KeywordTok{rownames}\NormalTok{(tree\_space)[}\DecValTok{1}\OperatorTok{:}\DecValTok{6}\NormalTok{]}
-\NormalTok{dummy\_tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\KeywordTok{rownames}\NormalTok{(tree\_space)[}\KeywordTok{rev}\NormalTok{(}\DecValTok{7}\OperatorTok{:}\DecValTok{11}\NormalTok{)]}
+\DocumentationTok{\#\# Adding a extra row to dummy matrix (to match dummy\_tree)}
+\NormalTok{tree\_space }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(dummy\_space, }\AttributeTok{root =} \FunctionTok{rnorm}\NormalTok{(}\DecValTok{5}\NormalTok{))}
+\DocumentationTok{\#\# Creating a random dummy tree (with labels matching the ones from tree\_space)}
+\NormalTok{dummy\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{6}\NormalTok{)}
+\NormalTok{dummy\_tree}\SpecialCharTok{$}\NormalTok{tip.label }\OtherTok{\textless{}{-}} \FunctionTok{rownames}\NormalTok{(tree\_space)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{6}\NormalTok{]}
+\NormalTok{dummy\_tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}} \FunctionTok{rownames}\NormalTok{(tree\_space)[}\FunctionTok{rev}\NormalTok{(}\DecValTok{7}\SpecialCharTok{:}\DecValTok{11}\NormalTok{)]}
-\CommentTok{\#\# Measuring the disparity as the projection of each element}
-\CommentTok{\#\# on its root{-}ancestor vector}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(tree\_space, }\DataTypeTok{metric =}\NormalTok{ projections.tree,}
- \DataTypeTok{tree =}\NormalTok{ dummy\_tree,}
- \DataTypeTok{type =} \KeywordTok{c}\NormalTok{(}\StringTok{"root"}\NormalTok{, }\StringTok{"ancestor"}\NormalTok{)))}
+\DocumentationTok{\#\# Measuring the disparity as the projection of each element}
+\DocumentationTok{\#\# on its root{-}ancestor vector}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(tree\_space, }\AttributeTok{metric =}\NormalTok{ projections.tree,}
+ \AttributeTok{tree =}\NormalTok{ dummy\_tree,}
+ \AttributeTok{type =} \FunctionTok{c}\NormalTok{(}\StringTok{"root"}\NormalTok{, }\StringTok{"ancestor"}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to
## max; returning -Inf
-
## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to
## max; returning -Inf
\end{verbatim}
\begin{verbatim}
-## subsets n obs.median 2.5% 25% 75% 97.5%
-## 1 1 11 NA 0.229 0.416 0.712 1.016
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 11 NA -0.7 -0.196 0.908 1.774
\end{verbatim}
Of course you can also use any other options from the projections function:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A user defined function that\textquotesingle{}s returns the centroid of}
-\CommentTok{\#\# the first three nodes}
-\NormalTok{fun.root \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix, tree, }\DataTypeTok{row =} \OtherTok{NULL}\NormalTok{) \{}
- \KeywordTok{return}\NormalTok{(}\KeywordTok{colMeans}\NormalTok{(matrix[tree}\OperatorTok{$}\NormalTok{node.label[}\DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{], ]))}
+\DocumentationTok{\#\# A user defined function that\textquotesingle{}s returns the centroid of}
+\DocumentationTok{\#\# the first three nodes}
+\NormalTok{fun.root }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix, tree, }\AttributeTok{row =} \ConstantTok{NULL}\NormalTok{) \{}
+ \FunctionTok{return}\NormalTok{(}\FunctionTok{colMeans}\NormalTok{(matrix[tree}\SpecialCharTok{$}\NormalTok{node.label[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{], ]))}
\NormalTok{\}}
-\CommentTok{\#\# Measuring the unscaled rejection from the vector from the}
-\CommentTok{\#\# centroid of the three first nodes}
-\CommentTok{\#\# to the coordinates of the first tip}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(tree\_space, }\DataTypeTok{metric =}\NormalTok{ projections.tree,}
- \DataTypeTok{tree =}\NormalTok{ dummy\_tree,}
- \DataTypeTok{measure =} \StringTok{"distance"}\NormalTok{,}
- \DataTypeTok{type =} \KeywordTok{list}\NormalTok{(fun.root,}
+\DocumentationTok{\#\# Measuring the unscaled rejection from the vector from the}
+\DocumentationTok{\#\# centroid of the three first nodes}
+\DocumentationTok{\#\# to the coordinates of the first tip}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(tree\_space, }\AttributeTok{metric =}\NormalTok{ projections.tree,}
+ \AttributeTok{tree =}\NormalTok{ dummy\_tree,}
+ \AttributeTok{measure =} \StringTok{"distance"}\NormalTok{,}
+ \AttributeTok{type =} \FunctionTok{list}\NormalTok{(fun.root,}
\NormalTok{ tree\_space[}\DecValTok{1}\NormalTok{, ])))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## subsets n obs.median 2.5% 25% 75% 97.5%
-## 1 1 11 0.606 0.064 0.462 0.733 0.999
+## subsets n obs.median 2.5% 25% 75% 97.5%
+## 1 1 11 0.763 0.07 0.459 0.873 1.371
\end{verbatim}
\hypertarget{roundness}{%
@@ -2855,7 +2659,7 @@ \subsubsection{Roundness}\label{roundness}}
## snapshots
\end{verbatim}
-\includegraphics[width=4in]{../../../../../../tmp/RtmpuRA2JU/file80cb6a29f05b}
+\includegraphics[width=4in]{../../../../../../tmp/RtmpNRJYtO/filedc8b70fa877c}
\begin{verbatim}
## Warning in snapshot3d(scene = x, width = width, height = height): webshot =
@@ -2868,7 +2672,7 @@ \subsubsection{Roundness}\label{roundness}}
## snapshots
\end{verbatim}
-\includegraphics[width=4in]{../../../../../../tmp/RtmpuRA2JU/file80cb29a4e334}
+\includegraphics[width=4in]{../../../../../../tmp/RtmpNRJYtO/filedc8b241ab6ff}
\begin{verbatim}
## Warning in snapshot3d(scene = x, width = width, height = height): webshot =
@@ -2881,8 +2685,8 @@ \subsubsection{Roundness}\label{roundness}}
## snapshots
\end{verbatim}
-\includegraphics[width=4in]{../../../../../../tmp/RtmpuRA2JU/file80cb4a93cfcb}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-69-1.pdf}
+\includegraphics[width=4in]{../../../../../../tmp/RtmpNRJYtO/filedc8b6be23fa7}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-70-1.pdf}
\hypertarget{betweengroupmetricslist}{%
\subsubsection{Between group metrics}\label{betweengroupmetricslist}}
@@ -2902,13 +2706,13 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating a dispRity object with two groups}
-\NormalTok{grouped\_space \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(dummy\_space,}
- \DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{), }\KeywordTok{c}\NormalTok{(}\DecValTok{6}\OperatorTok{:}\DecValTok{10}\NormalTok{)))}
+\DocumentationTok{\#\# Creating a dispRity object with two groups}
+\NormalTok{grouped\_space }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(dummy\_space,}
+ \AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{6}\SpecialCharTok{:}\DecValTok{10}\NormalTok{)))}
-\CommentTok{\#\# Measuring the minimum distance between both groups}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ group.dist,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# Measuring the minimum distance between both groups}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ group.dist,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2919,9 +2723,9 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the centroid distance between both groups}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ group.dist,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{probs =} \FloatTok{0.5}\NormalTok{))}
+\DocumentationTok{\#\# Measuring the centroid distance between both groups}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ group.dist,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{probs =} \FloatTok{0.5}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2932,9 +2736,9 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the distance between both group\textquotesingle{}s 75\% CI}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ group.dist,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{probs =} \KeywordTok{c}\NormalTok{(}\FloatTok{0.25}\NormalTok{, }\FloatTok{0.75}\NormalTok{)))}
+\DocumentationTok{\#\# Measuring the distance between both group\textquotesingle{}s 75\% CI}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ group.dist,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{probs =} \FunctionTok{c}\NormalTok{(}\FloatTok{0.25}\NormalTok{, }\FloatTok{0.75}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -2953,10 +2757,10 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the distance between the elements of the first group}
-\CommentTok{\#\# and the centroid of the second group}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ point.dist,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# Measuring the distance between the elements of the first group}
+\DocumentationTok{\#\# and the centroid of the second group}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ point.dist,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -2967,10 +2771,10 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the distance between the elements of the second group}
-\CommentTok{\#\# and the centroid of the first group}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ point.dist,}
- \DataTypeTok{between.groups =} \KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))))}
+\DocumentationTok{\#\# Measuring the distance between the elements of the second group}
+\DocumentationTok{\#\# and the centroid of the first group}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ point.dist,}
+ \AttributeTok{between.groups =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))))}
\end{Highlighting}
\end{Shaded}
@@ -2981,13 +2785,13 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the distance between the elements of the first group}
-\CommentTok{\#\# a point defined as the standard deviation of each column}
-\CommentTok{\#\# in the second group}
-\NormalTok{sd.point \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix2) \{}\KeywordTok{apply}\NormalTok{(matrix2, }\DecValTok{2}\NormalTok{, sd)\}}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(grouped\_space, }\DataTypeTok{metric =}\NormalTok{ point.dist,}
- \DataTypeTok{point =}\NormalTok{ sd.point, }\DataTypeTok{method =} \StringTok{"manhattan"}\NormalTok{,}
- \DataTypeTok{between.groups =} \OtherTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# Measuring the distance between the elements of the first group}
+\DocumentationTok{\#\# a point defined as the standard deviation of each column}
+\DocumentationTok{\#\# in the second group}
+\NormalTok{sd.point }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix2) \{}\FunctionTok{apply}\NormalTok{(matrix2, }\DecValTok{2}\NormalTok{, sd)\}}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(grouped\_space, }\AttributeTok{metric =}\NormalTok{ point.dist,}
+ \AttributeTok{point =}\NormalTok{ sd.point, }\AttributeTok{method =} \StringTok{"manhattan"}\NormalTok{,}
+ \AttributeTok{between.groups =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -3007,16 +2811,16 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the charadriiformes data}
-\KeywordTok{data}\NormalTok{(charadriiformes)}
+\DocumentationTok{\#\# Loading the charadriiformes data}
+\FunctionTok{data}\NormalTok{(charadriiformes)}
-\CommentTok{\#\# Creating the dispRity object (see the \#covar section in the manual for more info)}
-\NormalTok{my\_covar \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.subsets}\NormalTok{(}\DataTypeTok{n =} \DecValTok{50}\NormalTok{,}
- \DataTypeTok{data =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{data,}
- \DataTypeTok{posteriors =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{posteriors,}
- \DataTypeTok{group =} \KeywordTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{posteriors)[}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{],}
- \DataTypeTok{tree =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{tree,}
- \DataTypeTok{rename.groups =} \KeywordTok{c}\NormalTok{(}\KeywordTok{levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{data}\OperatorTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))}
+\DocumentationTok{\#\# Creating the dispRity object (see the \#covar section in the manual for more info)}
+\NormalTok{my\_covar }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.subsets}\NormalTok{(}\AttributeTok{n =} \DecValTok{50}\NormalTok{,}
+ \AttributeTok{data =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data,}
+ \AttributeTok{posteriors =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors,}
+ \AttributeTok{group =} \FunctionTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{],}
+ \AttributeTok{tree =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{tree,}
+ \AttributeTok{rename.groups =} \FunctionTok{c}\NormalTok{(}\FunctionTok{levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{data}\SpecialCharTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -3025,27 +2829,27 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating the list of groups to compare}
-\NormalTok{comparisons\_list \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"gulls"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"plovers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"sandpipers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{))}
+\DocumentationTok{\#\# Creating the list of groups to compare}
+\NormalTok{comparisons\_list }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"gulls"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"plovers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"sandpipers"}\NormalTok{, }\StringTok{"phylogeny"}\NormalTok{))}
-\CommentTok{\#\# Measuring the angles between each groups}
-\CommentTok{\#\# (note that we set the metric as.covar, more on that in the \#covar section below)}
-\NormalTok{groups\_angles \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ my\_covar,}
- \DataTypeTok{metric =} \KeywordTok{as.covar}\NormalTok{(projections.between),}
- \DataTypeTok{between.groups =}\NormalTok{ comparisons\_list,}
- \DataTypeTok{measure =} \StringTok{"degree"}\NormalTok{)}
-\CommentTok{\#\# And here are the angles in degrees:}
-\KeywordTok{summary}\NormalTok{(groups\_angles)}
+\DocumentationTok{\#\# Measuring the angles between each groups}
+\DocumentationTok{\#\# (note that we set the metric as.covar, more on that in the \#covar section below)}
+\NormalTok{groups\_angles }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\AttributeTok{data =}\NormalTok{ my\_covar,}
+ \AttributeTok{metric =} \FunctionTok{as.covar}\NormalTok{(projections.between),}
+ \AttributeTok{between.groups =}\NormalTok{ comparisons\_list,}
+ \AttributeTok{measure =} \StringTok{"degree"}\NormalTok{)}
+\DocumentationTok{\#\# And here are the angles in degrees:}
+\FunctionTok{summary}\NormalTok{(groups\_angles)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
-## 1 gulls:phylogeny 159 359 8.25 2.101 6.25 14.98 41.8
-## 2 plovers:phylogeny 98 359 33.75 5.700 16.33 75.50 131.5
-## 3 sandpipers:phylogeny 102 359 10.79 3.876 8.10 16.59 95.9
+## 1 gulls:phylogeny 159 359 9.39 2.480 5.95 16.67 43.2
+## 2 plovers:phylogeny 98 359 20.42 4.500 12.36 51.31 129.8
+## 3 sandpipers:phylogeny 102 359 10.82 1.777 7.60 13.89 43.0
\end{verbatim}
The second metric, \texttt{disalignment} rejects the centroid of a group (\texttt{matrix}) onto the major axis of another one (\texttt{matrix2}).
@@ -3055,20 +2859,20 @@ \subsubsection{Between group metrics}\label{betweengroupmetricslist}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the disalignement of each group}
-\NormalTok{groups\_alignement \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ my\_covar,}
- \DataTypeTok{metric =} \KeywordTok{as.covar}\NormalTok{(disalignment),}
- \DataTypeTok{between.groups =}\NormalTok{ comparisons\_list)}
-\CommentTok{\#\# And here are the groups alignment (0 = aligned)}
-\KeywordTok{summary}\NormalTok{(groups\_alignement)}
+\DocumentationTok{\#\# Measuring the disalignement of each group}
+\NormalTok{groups\_alignement }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\AttributeTok{data =}\NormalTok{ my\_covar,}
+ \AttributeTok{metric =} \FunctionTok{as.covar}\NormalTok{(disalignment),}
+ \AttributeTok{between.groups =}\NormalTok{ comparisons\_list)}
+\DocumentationTok{\#\# And here are the groups alignment (0 = aligned)}
+\FunctionTok{summary}\NormalTok{(groups\_alignement)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5%
-## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.015
+## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.021
## 2 plovers:phylogeny 98 359 0.001 0.000 0.001 0.001 0.006
-## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.003 0.009
+## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.005 0.018
\end{verbatim}
\hypertarget{which-disparity-metric-to-choose}{%
@@ -3078,7 +2882,7 @@ \subsection{Which disparity metric to choose?}\label{which-disparity-metric-to-c
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{best.metric \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{() }\KeywordTok{return}\NormalTok{(}\DecValTok{42}\NormalTok{)}
+\NormalTok{best.metric }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{() }\FunctionTok{return}\NormalTok{(}\DecValTok{42}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -3098,12 +2902,12 @@ \subsubsection{\texorpdfstring{\texttt{test.metric}}{test.metric}}\label{test-me
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating a 2D uniform space}
-\NormalTok{example\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{300}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)}
+\DocumentationTok{\#\# Creating a 2D uniform space}
+\NormalTok{example\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{300}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)}
-\CommentTok{\#\# Testing the product of ranges metric on the example space}
-\NormalTok{example\_test \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(example\_space, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(prod, ranges),}
- \DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{)) }
+\DocumentationTok{\#\# Testing the product of ranges metric on the example space}
+\NormalTok{example\_test }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(example\_space, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(prod, ranges),}
+ \AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{)) }
\end{Highlighting}
\end{Shaded}
@@ -3117,7 +2921,7 @@ \subsubsection{\texorpdfstring{\texttt{test.metric}}{test.metric}}\label{test-me
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The results as a dispRity object}
+\DocumentationTok{\#\# The results as a dispRity object}
\NormalTok{example\_test}
\end{Highlighting}
\end{Shaded}
@@ -3132,30 +2936,30 @@ \subsubsection{\texorpdfstring{\texttt{test.metric}}{test.metric}}\label{test-me
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising these results}
-\KeywordTok{summary}\NormalTok{(example\_test)}
+\DocumentationTok{\#\# Summarising these results}
+\FunctionTok{summary}\NormalTok{(example\_test)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope
-## random 0.84 0.88 0.94 0.95 0.96 0.98 0.97 0.98 0.96 0.98 1.450100e-03
-## size.increase 0.10 0.21 0.31 0.45 0.54 0.70 0.78 0.94 0.96 0.98 1.054925e-02
-## size.hollowness 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 1.453782e-05
+## random 0.94 0.97 0.94 0.97 0.98 0.98 0.99 0.99 0.99 0.99 6.389477e-04
+## size.increase 0.11 0.21 0.38 0.54 0.68 0.79 0.87 0.93 0.98 0.99 1.040938e-02
+## size.hollowness 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1.880225e-05
## p_value R^2(adj)
-## random 2.439179e-06 0.5377136
-## size.increase 4.450564e-25 0.9783976
-## size.hollowness 1.925262e-05 0.4664502
+## random 5.891773e-06 0.5084747
+## size.increase 4.331947e-19 0.9422289
+## size.hollowness 3.073793e-03 0.2467532
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Or visualising them}
-\KeywordTok{plot}\NormalTok{(example\_test)}
+\DocumentationTok{\#\# Or visualising them}
+\FunctionTok{plot}\NormalTok{(example\_test)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-77-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-78-1.pdf}
\hypertarget{summarising-disprity-data-plots}{%
\section{Summarising dispRity data (plots)}\label{summarising-disprity-data-plots}}
@@ -3170,42 +2974,42 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Example data from previous sections}
-\NormalTok{crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat50,}
- \DataTypeTok{group =} \KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree,}
- \DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{))}
-\CommentTok{\#\# Bootstrapping and rarefying these groups}
-\NormalTok{boot\_crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(crown\_stem, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{,}
- \DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)}
-\CommentTok{\#\# Calculate disparity}
-\NormalTok{disparity\_crown\_stem \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_crown\_stem,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))}
-
-\CommentTok{\#\# Creating time slice subsets}
-\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,}
- \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,}
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
-\CommentTok{\#\# Bootstrapping the time slice subsets}
-\NormalTok{boot\_time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(time\_slices, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{)}
-\CommentTok{\#\# Calculate disparity}
-\NormalTok{disparity\_time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_time\_slices,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))}
-
-\CommentTok{\#\# Creating time bin subsets}
-\NormalTok{time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,}
- \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree, }
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,}
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages,}
- \DataTypeTok{inc.nodes =} \OtherTok{TRUE}\NormalTok{)}
-\CommentTok{\#\# Bootstrapping the time bin subsets}
-\NormalTok{boot\_time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(time\_bins, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{)}
-\CommentTok{\#\# Calculate disparity}
-\NormalTok{disparity\_time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_time\_bins,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances))}
+\DocumentationTok{\#\# Example data from previous sections}
+\NormalTok{crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat50,}
+ \AttributeTok{group =} \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree,}
+ \AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{))}
+\DocumentationTok{\#\# Bootstrapping and rarefying these groups}
+\NormalTok{boot\_crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(crown\_stem, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{,}
+ \AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Calculate disparity}
+\NormalTok{disparity\_crown\_stem }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_crown\_stem,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))}
+
+\DocumentationTok{\#\# Creating time slice subsets}
+\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,}
+ \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,}
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+\DocumentationTok{\#\# Bootstrapping the time slice subsets}
+\NormalTok{boot\_time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(time\_slices, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{)}
+\DocumentationTok{\#\# Calculate disparity}
+\NormalTok{disparity\_time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_time\_slices,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))}
+
+\DocumentationTok{\#\# Creating time bin subsets}
+\NormalTok{time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,}
+ \AttributeTok{tree =}\NormalTok{ BeckLee\_tree, }
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,}
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{40}\NormalTok{, }\DecValTok{0}\NormalTok{),}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages,}
+ \AttributeTok{inc.nodes =} \ConstantTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Bootstrapping the time bin subsets}
+\NormalTok{boot\_time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(time\_bins, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{)}
+\DocumentationTok{\#\# Calculate disparity}
+\NormalTok{disparity\_time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_time\_bins,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances))}
\end{Highlighting}
\end{Shaded}
@@ -3213,17 +3017,17 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Default summary}
-\KeywordTok{summary}\NormalTok{(disparity\_time\_slices)}
+\DocumentationTok{\#\# Default summary}
+\FunctionTok{summary}\NormalTok{(disparity\_time\_slices)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 3.258 2.675 1.264 2.436 2.948 3.085
-## 2 80 19 3.491 3.315 3.128 3.266 3.362 3.453
-## 3 40 15 3.677 3.453 3.157 3.349 3.547 3.681
-## 4 0 10 4.092 3.726 3.293 3.578 3.828 3.950
+## 1 120 5 3.126 2.556 1.446 2.365 2.799 2.975
+## 2 80 19 3.351 3.188 3.019 3.137 3.235 3.291
+## 3 40 15 3.538 3.346 3.052 3.226 3.402 3.538
+## 4 0 10 3.934 3.601 3.219 3.446 3.681 3.819
\end{verbatim}
Information about the number of elements in each subset and the observed (i.e.~non-bootstrapped) disparity are also calculated.
@@ -3231,18 +3035,18 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(disparity\_crown\_stem))}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(disparity\_crown\_stem))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 crown 30 2.526 2.441 2.367 2.420 2.466 2.487
-## 2 crown 29 NA 2.449 2.354 2.428 2.468 2.490
-## 3 crown 28 NA 2.441 2.385 2.422 2.457 2.485
-## 4 crown 27 NA 2.442 2.363 2.411 2.465 2.490
-## 5 crown 26 NA 2.438 2.350 2.416 2.458 2.494
-## 6 crown 25 NA 2.447 2.359 2.423 2.471 2.496
+## 1 crown 30 2.526 2.444 2.374 2.420 2.466 2.490
+## 2 crown 29 NA 2.454 2.387 2.427 2.470 2.490
+## 3 crown 28 NA 2.443 2.387 2.423 2.462 2.489
+## 4 crown 27 NA 2.440 2.366 2.417 2.468 2.493
+## 5 crown 26 NA 2.442 2.357 2.408 2.459 2.492
+## 6 crown 25 NA 2.445 2.344 2.425 2.469 2.490
\end{verbatim}
The summary functions can also take various options such as:
@@ -3263,23 +3067,23 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Same as above but using the 88th quantile and the standard deviation as the summary }
-\KeywordTok{summary}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{quantiles =} \DecValTok{88}\NormalTok{, }\DataTypeTok{cent.tend =}\NormalTok{ sd)}
+\DocumentationTok{\#\# Same as above but using the 88th quantile and the standard deviation as the summary }
+\FunctionTok{summary}\NormalTok{(disparity\_time\_slices, }\AttributeTok{quantiles =} \DecValTok{88}\NormalTok{, }\AttributeTok{cent.tend =}\NormalTok{ sd)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.sd 6% 94%
-## 1 120 5 3.258 0.426 1.864 3.075
-## 2 80 19 3.491 0.084 3.156 3.435
-## 3 40 15 3.677 0.149 3.231 3.650
-## 4 0 10 4.092 0.195 3.335 3.904
+## 1 120 5 3.126 0.366 2.043 2.947
+## 2 80 19 3.351 0.072 3.048 3.277
+## 3 40 15 3.538 0.133 3.095 3.525
+## 4 0 10 3.934 0.167 3.292 3.776
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Printing the details of the object and digits the values to the 5th decimal place}
-\KeywordTok{summary}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{recall =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{digits =} \DecValTok{5}\NormalTok{)}
+\DocumentationTok{\#\# Printing the details of the object and digits the values to the 5th decimal place}
+\FunctionTok{summary}\NormalTok{(disparity\_time\_slices, }\AttributeTok{recall =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{digits =} \DecValTok{5}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -3287,16 +3091,16 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp
## ---- dispRity object ----
## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
## 120, 80, 40, 0.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: c(sum, variances).
\end{verbatim}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 3.25815 2.67517 1.26366 2.43637 2.94780 3.08485
-## 2 80 19 3.49145 3.31487 3.12837 3.26601 3.36182 3.45336
-## 3 40 15 3.67702 3.45329 3.15729 3.34867 3.54670 3.68134
-## 4 0 10 4.09234 3.72554 3.29285 3.57797 3.82814 3.95046
+## 1 120 5 3.12580 2.55631 1.44593 2.36454 2.79905 2.97520
+## 2 80 19 3.35072 3.18751 3.01906 3.13720 3.23534 3.29113
+## 3 40 15 3.53811 3.34647 3.05242 3.22616 3.40199 3.53793
+## 4 0 10 3.93353 3.60071 3.21947 3.44555 3.68095 3.81856
\end{verbatim}
Note that the summary table is a \texttt{data.frame}, hence it is as easy to modify as any dataframe using \texttt{dplyr}.
@@ -3304,10 +3108,10 @@ \subsection{\texorpdfstring{Summarising \texttt{dispRity} data}{Summarising disp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the xtable package}
-\KeywordTok{require}\NormalTok{(xtable)}
-\CommentTok{\#\# Converting the table in LaTeX}
-\KeywordTok{xtable}\NormalTok{(}\KeywordTok{summary}\NormalTok{(disparity\_time\_slices))}
+\DocumentationTok{\#\# Loading the xtable package}
+\FunctionTok{require}\NormalTok{(xtable)}
+\DocumentationTok{\#\# Converting the table in LaTeX}
+\FunctionTok{xtable}\NormalTok{(}\FunctionTok{summary}\NormalTok{(disparity\_time\_slices))}
\end{Highlighting}
\end{Shaded}
@@ -3338,29 +3142,29 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical parameters}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical parameters}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting continuous disparity results}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting continuous disparity results}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{)}
-\CommentTok{\#\# Plotting discrete disparity results}
-\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{type =} \StringTok{"box"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting discrete disparity results}
+\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{type =} \StringTok{"box"}\NormalTok{)}
-\CommentTok{\#\# As above but using lines for the rarefaction level of 20 elements only}
-\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{type =} \StringTok{"line"}\NormalTok{, }\DataTypeTok{rarefaction =} \DecValTok{20}\NormalTok{)}
+\DocumentationTok{\#\# As above but using lines for the rarefaction level of 20 elements only}
+\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{type =} \StringTok{"line"}\NormalTok{, }\AttributeTok{rarefaction =} \DecValTok{20}\NormalTok{)}
-\CommentTok{\#\# As above but using polygons while also displaying the number of elements}
-\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{type =} \StringTok{"polygon"}\NormalTok{, }\DataTypeTok{elements =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# As above but using polygons while also displaying the number of elements}
+\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{type =} \StringTok{"polygon"}\NormalTok{, }\AttributeTok{elements =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-83-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-84-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Resetting graphical parameters}
-\KeywordTok{par}\NormalTok{(op)}
+\DocumentationTok{\#\# Resetting graphical parameters}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -3368,28 +3172,28 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the results with some classic options from plot}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{),}
- \DataTypeTok{ylab =} \KeywordTok{c}\NormalTok{(}\StringTok{"Some measurement"}\NormalTok{), }\DataTypeTok{xlab =} \StringTok{"Some other measurement"}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Many options..."}\NormalTok{, }\DataTypeTok{ylim =} \KeywordTok{c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{), }\DataTypeTok{xlim =} \KeywordTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{, }\DecValTok{0}\NormalTok{))}
+\DocumentationTok{\#\# Plotting the results with some classic options from plot}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{),}
+ \AttributeTok{ylab =} \FunctionTok{c}\NormalTok{(}\StringTok{"Some measurement"}\NormalTok{), }\AttributeTok{xlab =} \StringTok{"Some other measurement"}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Many options..."}\NormalTok{, }\AttributeTok{ylim =} \FunctionTok{c}\NormalTok{(}\DecValTok{10}\NormalTok{, }\DecValTok{0}\NormalTok{), }\AttributeTok{xlim =} \FunctionTok{c}\NormalTok{(}\DecValTok{4}\NormalTok{, }\DecValTok{0}\NormalTok{))}
-\CommentTok{\#\# Adding a legend}
-\KeywordTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\DataTypeTok{legend =} \KeywordTok{c}\NormalTok{(}\StringTok{"Central tendency"}\NormalTok{,}
+\DocumentationTok{\#\# Adding a legend}
+\FunctionTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\AttributeTok{legend =} \FunctionTok{c}\NormalTok{(}\StringTok{"Central tendency"}\NormalTok{,}
\StringTok{"Confidence interval 1"}\NormalTok{,}
\StringTok{"Confidence interval 2"}\NormalTok{),}
- \DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{), }\DataTypeTok{pch =} \DecValTok{19}\NormalTok{)}
+ \AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"blue"}\NormalTok{, }\StringTok{"orange"}\NormalTok{, }\StringTok{"green"}\NormalTok{), }\AttributeTok{pch =} \DecValTok{19}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-84-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-85-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Resetting graphical parameters}
-\KeywordTok{par}\NormalTok{(op)}
+\DocumentationTok{\#\# Resetting graphical parameters}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -3397,27 +3201,27 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the results with some plot.dispRity arguments}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_slices,}
- \DataTypeTok{quantiles =} \KeywordTok{c}\NormalTok{(}\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{10}\NormalTok{, }\DataTypeTok{to =} \DecValTok{100}\NormalTok{, }\DataTypeTok{by =} \DecValTok{10}\NormalTok{)),}
- \DataTypeTok{cent.tend =}\NormalTok{ sd, }\DataTypeTok{type =} \StringTok{"c"}\NormalTok{, }\DataTypeTok{elements =} \OtherTok{TRUE}\NormalTok{,}
- \DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"black"}\NormalTok{, }\KeywordTok{rainbow}\NormalTok{(}\DecValTok{10}\NormalTok{)),}
- \DataTypeTok{ylab =} \KeywordTok{c}\NormalTok{(}\StringTok{"Disparity"}\NormalTok{, }\StringTok{"Diversity"}\NormalTok{),}
- \DataTypeTok{xlab =} \StringTok{"Time (in in units from past to present)"}\NormalTok{,}
- \DataTypeTok{observed =} \OtherTok{TRUE}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Many more options..."}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the results with some plot.dispRity arguments}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_slices,}
+ \AttributeTok{quantiles =} \FunctionTok{c}\NormalTok{(}\FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{10}\NormalTok{, }\AttributeTok{to =} \DecValTok{100}\NormalTok{, }\AttributeTok{by =} \DecValTok{10}\NormalTok{)),}
+ \AttributeTok{cent.tend =}\NormalTok{ sd, }\AttributeTok{type =} \StringTok{"c"}\NormalTok{, }\AttributeTok{elements =} \ConstantTok{TRUE}\NormalTok{,}
+ \AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"black"}\NormalTok{, }\FunctionTok{rainbow}\NormalTok{(}\DecValTok{10}\NormalTok{)),}
+ \AttributeTok{ylab =} \FunctionTok{c}\NormalTok{(}\StringTok{"Disparity"}\NormalTok{, }\StringTok{"Diversity"}\NormalTok{),}
+ \AttributeTok{xlab =} \StringTok{"Time (in in units from past to present)"}\NormalTok{,}
+ \AttributeTok{observed =} \ConstantTok{TRUE}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Many more options..."}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-85-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-86-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Resetting graphical parameters}
-\KeywordTok{par}\NormalTok{(op)}
+\DocumentationTok{\#\# Resetting graphical parameters}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -3429,23 +3233,23 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the continuous disparity with a fixed y axis}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{ylim =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{))}
-\CommentTok{\#\# Adding the discrete data}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_bins, }\DataTypeTok{type =} \StringTok{"line"}\NormalTok{, }\DataTypeTok{ylim =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{),}
- \DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{add =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the continuous disparity with a fixed y axis}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{ylim =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{))}
+\DocumentationTok{\#\# Adding the discrete data}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_bins, }\AttributeTok{type =} \StringTok{"line"}\NormalTok{, }\AttributeTok{ylim =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{, }\DecValTok{9}\NormalTok{),}
+ \AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{add =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-86-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-87-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Resetting graphical parameters}
-\KeywordTok{par}\NormalTok{(op)}
+\DocumentationTok{\#\# Resetting graphical parameters}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -3453,20 +3257,20 @@ \subsection{\texorpdfstring{Plotting \texttt{dispRity} data}{Plotting dispRity d
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the rarefaction curves}
-\KeywordTok{plot}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{rarefaction =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the rarefaction curves}
+\FunctionTok{plot}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{rarefaction =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-87-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-88-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Resetting graphical parameters}
-\KeywordTok{par}\NormalTok{(op)}
+\DocumentationTok{\#\# Resetting graphical parameters}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -3482,17 +3286,17 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Making the different subsets}
-\NormalTok{cust\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(BeckLee\_mat99,}
- \KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree,}
- \DataTypeTok{inc.nodes =} \OtherTok{TRUE}\NormalTok{))}
-\NormalTok{time\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(BeckLee\_mat99,}
- \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{5}\NormalTok{)}
+\DocumentationTok{\#\# Making the different subsets}
+\NormalTok{cust\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(BeckLee\_mat99,}
+ \FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree,}
+ \AttributeTok{inc.nodes =} \ConstantTok{TRUE}\NormalTok{))}
+\NormalTok{time\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(BeckLee\_mat99,}
+ \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{5}\NormalTok{)}
-\CommentTok{\#\# Note that no disparity has been calculated here:}
-\KeywordTok{is.null}\NormalTok{(cust\_subsets}\OperatorTok{$}\NormalTok{disparity)}
+\DocumentationTok{\#\# Note that no disparity has been calculated here:}
+\FunctionTok{is.null}\NormalTok{(cust\_subsets}\SpecialCharTok{$}\NormalTok{disparity)}
\end{Highlighting}
\end{Shaded}
@@ -3502,7 +3306,7 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{is.null}\NormalTok{(time\_subsets}\OperatorTok{$}\NormalTok{disparity)}
+\FunctionTok{is.null}\NormalTok{(time\_subsets}\SpecialCharTok{$}\NormalTok{disparity)}
\end{Highlighting}
\end{Shaded}
@@ -3512,17 +3316,17 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# But we can still plot both spaces by using the default plot functions}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\CommentTok{\#\# Default plotting}
-\KeywordTok{plot}\NormalTok{(cust\_subsets)}
-\CommentTok{\#\# Plotting with more arguments}
-\KeywordTok{plot}\NormalTok{(time\_subsets, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{dimensions =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)),}
- \DataTypeTok{main =} \StringTok{"Some }\CharTok{\textbackslash{}"}\StringTok{low}\CharTok{\textbackslash{}"}\StringTok{ dimensions"}\NormalTok{)}
+\DocumentationTok{\#\# But we can still plot both spaces by using the default plot functions}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# Default plotting}
+\FunctionTok{plot}\NormalTok{(cust\_subsets)}
+\DocumentationTok{\#\# Plotting with more arguments}
+\FunctionTok{plot}\NormalTok{(time\_subsets, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{dimensions =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)),}
+ \AttributeTok{main =} \StringTok{"Some }\SpecialCharTok{\textbackslash{}"}\StringTok{low}\SpecialCharTok{\textbackslash{}"}\StringTok{ dimensions"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-88-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-89-1.pdf}
\begin{quote}
DISCLAIMER: This functionality can be handy for exploring the data (e.g.~to visually check whether the subset attribution worked) but it might be misleading on how the data is \emph{actually} distributed in the multidimensional space!
@@ -3534,16 +3338,16 @@ \subsection{\texorpdfstring{\texttt{type\ =\ preview}}{type = preview}}\label{ty
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))}
-\CommentTok{\#\# Default plotting}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{main =} \StringTok{"Disparity through time"}\NormalTok{)}
-\CommentTok{\#\# Plotting with more arguments}
-\KeywordTok{plot}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Two first dimensions of the trait space"}\NormalTok{)}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{))}
+\DocumentationTok{\#\# Default plotting}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{main =} \StringTok{"Disparity through time"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting with more arguments}
+\FunctionTok{plot}\NormalTok{(disparity\_time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Two first dimensions of the trait space"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-89-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-90-1.pdf}
\hypertarget{graphical-options-with-...}{%
\subsection{\texorpdfstring{Graphical options with \texttt{...}}{Graphical options with ...}}\label{graphical-options-with-...}}
@@ -3558,39 +3362,39 @@ \subsection{\texorpdfstring{Graphical options with \texttt{...}}{Graphical optio
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading some demo data:}
-\CommentTok{\#\# An ordinated matrix with node and tip labels}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat99)}
-\CommentTok{\#\# The corresponding tree with tip and node labels}
-\KeywordTok{data}\NormalTok{(BeckLee\_tree)}
-\CommentTok{\#\# A list of tips ages for the fossil data}
-\KeywordTok{data}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Loading some demo data:}
+\DocumentationTok{\#\# An ordinated matrix with node and tip labels}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat99)}
+\DocumentationTok{\#\# The corresponding tree with tip and node labels}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree)}
+\DocumentationTok{\#\# A list of tips ages for the fossil data}
+\FunctionTok{data}\NormalTok{(BeckLee\_ages)}
-\CommentTok{\#\# Time slicing through the tree using the equal split algorithm}
-\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,}
- \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"acctran"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{15}\NormalTok{)}
+\DocumentationTok{\#\# Time slicing through the tree using the equal split algorithm}
+\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,}
+ \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"acctran"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{15}\NormalTok{)}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\CommentTok{\#\# The preview plot with the tree using only defaults}
-\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{))}
-\CommentTok{\#\# The same plot but by applying general options}
-\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{),}
- \DataTypeTok{col =} \StringTok{"blue"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"General options"}\NormalTok{)}
-\CommentTok{\#\# The same plot but by applying the colour only to the lines}
-\CommentTok{\#\# and change of shape only to the points}
-\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{),}
- \DataTypeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\DataTypeTok{points.pch =} \DecValTok{15}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Specific options"}\NormalTok{)}
-\CommentTok{\#\# And now without the legend}
-\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{, }\DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{),}
- \DataTypeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\DataTypeTok{points.pch =} \DecValTok{15}\NormalTok{, }\DataTypeTok{legend =} \OtherTok{FALSE}\NormalTok{)}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# The preview plot with the tree using only defaults}
+\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# The same plot but by applying general options}
+\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{),}
+ \AttributeTok{col =} \StringTok{"blue"}\NormalTok{, }\AttributeTok{main =} \StringTok{"General options"}\NormalTok{)}
+\DocumentationTok{\#\# The same plot but by applying the colour only to the lines}
+\DocumentationTok{\#\# and change of shape only to the points}
+\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{),}
+ \AttributeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\AttributeTok{points.pch =} \DecValTok{15}\NormalTok{, }\AttributeTok{main =} \StringTok{"Specific options"}\NormalTok{)}
+\DocumentationTok{\#\# And now without the legend}
+\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{, }\AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{),}
+ \AttributeTok{lines.col =} \StringTok{"blue"}\NormalTok{, }\AttributeTok{points.pch =} \DecValTok{15}\NormalTok{, }\AttributeTok{legend =} \ConstantTok{FALSE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-90-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-91-1.pdf}
\hypertarget{testing-disparity-hypotheses}{%
\section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}}
@@ -3628,33 +3432,33 @@ \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# T{-}test to test for a difference in disparity between crown and stem mammals}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{test =}\NormalTok{ t.test)}
+\DocumentationTok{\#\# T{-}test to test for a difference in disparity between crown and stem mammals}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{test =}\NormalTok{ t.test)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [[1]]
## statistic: t
-## crown : stem 57.38116
+## crown : stem 54.10423
##
## [[2]]
## parameter: df
-## crown : stem 184.8496
+## crown : stem 177.9857
##
## [[3]]
## p.value
-## crown : stem 9.763665e-120
+## crown : stem 1.928983e-112
##
## [[4]]
## stderr
-## crown : stem 0.005417012
+## crown : stem 0.005649615
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Performing the same test but with the detailed t.test output}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\DataTypeTok{test =}\NormalTok{ t.test, }\DataTypeTok{details =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Performing the same test but with the detailed t.test output}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_crown\_stem, }\AttributeTok{test =}\NormalTok{ t.test, }\AttributeTok{details =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -3665,51 +3469,51 @@ \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}}
## Welch Two Sample t-test
##
## data: dots[[1L]][[1L]] and dots[[2L]][[1L]]
-## t = 57.381, df = 184.85, p-value < 2.2e-16
+## t = 54.104, df = 177.99, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
-## 0.3001473 0.3215215
+## 0.2945193 0.3168170
## sample estimates:
## mean of x mean of y
-## 2.440611 2.129776
+## 2.440968 2.135299
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Wilcoxon test applied to time sliced disparity with sequential comparisons,}
-\CommentTok{\#\# with Bonferroni correction}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_time\_slices, }\DataTypeTok{test =}\NormalTok{ wilcox.test,}
- \DataTypeTok{comparisons =} \StringTok{"sequential"}\NormalTok{, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
+\DocumentationTok{\#\# Wilcoxon test applied to time sliced disparity with sequential comparisons,}
+\DocumentationTok{\#\# with Bonferroni correction}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_time\_slices, }\AttributeTok{test =}\NormalTok{ wilcox.test,}
+ \AttributeTok{comparisons =} \StringTok{"sequential"}\NormalTok{, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [[1]]
## statistic: W
-## 120 : 80 42
-## 80 : 40 2065
-## 40 : 0 1485
+## 120 : 80 40
+## 80 : 40 1812
+## 40 : 0 1463
##
## [[2]]
## p.value
-## 120 : 80 2.682431e-33
-## 80 : 40 2.247885e-12
-## 40 : 0 2.671335e-17
+## 120 : 80 2.534081e-33
+## 80 : 40 2.037470e-14
+## 40 : 0 1.671038e-17
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the overlap between distributions in the time bins (using the}
-\CommentTok{\#\# implemented Bhattacharyya Coefficient function {-} see ?bhatt.coeff)}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_time\_bins, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff)}
+\DocumentationTok{\#\# Measuring the overlap between distributions in the time bins (using the}
+\DocumentationTok{\#\# implemented Bhattacharyya Coefficient function {-} see ?bhatt.coeff)}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_time\_bins, }\AttributeTok{test =}\NormalTok{ bhatt.coeff)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## bhatt.coeff
-## 120 - 80 : 80 - 40 0.00000000
-## 120 - 80 : 40 - 0 0.02236068
-## 80 - 40 : 40 - 0 0.42018008
+## 120 - 80 : 80 - 40 0.000000
+## 120 - 80 : 40 - 0 0.000000
+## 80 - 40 : 40 - 0 0.450877
\end{verbatim}
Because of the modular design of the package, tests can always be made by the user (the same way disparity metrics can be user made).
@@ -3719,7 +3523,7 @@ \section{Testing disparity hypotheses}\label{testing-disparity-hypotheses}}
\hypertarget{adonis}{%
\subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}}\label{adonis}}
-One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices \texttt{vegan::adonis}.
+One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices \texttt{vegan::adonis2}.
This can be done on \texttt{dispRity} objects using the \texttt{adonis.dispRity} wrapper function.
Basically, this function takes the exact same arguments as \texttt{adonis} and a \texttt{dispRity} object for data and performs a PERMANOVA based on the distance matrix of the multidimensional space (unless the multidimensional space was already defined as a distance matrix).
The \texttt{adonis.dispRity} function uses the information from the \texttt{dispRity} object to generate default formulas:
@@ -3727,50 +3531,50 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}
\begin{itemize}
\tightlist
\item
- If the object contains customised subsets, it applies the default formula \texttt{matrix\ \textasciitilde{}\ group} testing the effect of \texttt{group} as a predictor on \texttt{matrix} (called from the \texttt{dispRity} object as \texttt{data\$matrix} see \protect\hyperlink{The-dispRity-object-content}{\texttt{dispRitu} object details})
+ If the object contains customised subsets, it applies the default formula \texttt{matrix\ \textasciitilde{}\ group} testing the effect of \texttt{group} as a predictor on \texttt{matrix} (called from the \texttt{dispRity} object as \texttt{data\$matrix} see \protect\hyperlink{The-dispRity-object-content}{\texttt{dispRity} object details})
\item
If the object contains time subsets, it applies the default formula \texttt{matrix\ \textasciitilde{}\ time} testing the effect of \texttt{time} as a predictor (were the different levels of \texttt{time} are the different time slices/bins)
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# Generating a random character matrix}
-\NormalTok{character\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(}\KeywordTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{50}\NormalTok{,}
- \DataTypeTok{rates =} \KeywordTok{c}\NormalTok{(rnorm, }\DecValTok{1}\NormalTok{, }\DecValTok{0}\NormalTok{))}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Generating a random character matrix}
+\NormalTok{character\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(}\FunctionTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{50}\NormalTok{,}
+ \AttributeTok{rates =} \FunctionTok{c}\NormalTok{(rnorm, }\DecValTok{1}\NormalTok{, }\DecValTok{0}\NormalTok{))}
-\CommentTok{\#\# Calculating the distance matrix}
-\NormalTok{distance\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{as.matrix}\NormalTok{(}\KeywordTok{dist}\NormalTok{(character\_matrix))}
+\DocumentationTok{\#\# Calculating the distance matrix}
+\NormalTok{distance\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(character\_matrix))}
-\CommentTok{\#\# Creating two groups}
-\NormalTok{random\_groups \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"group1"}\NormalTok{ =}\StringTok{ }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{, }\StringTok{"group2"}\NormalTok{ =}\StringTok{ }\DecValTok{11}\OperatorTok{:}\DecValTok{20}\NormalTok{)}
+\DocumentationTok{\#\# Creating two groups}
+\NormalTok{random\_groups }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"group1"} \OtherTok{=} \DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\StringTok{"group2"} \OtherTok{=} \DecValTok{11}\SpecialCharTok{:}\DecValTok{20}\NormalTok{)}
-\CommentTok{\#\# Generating a dispRity object}
-\NormalTok{random\_disparity \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(distance\_matrix, random\_groups)}
+\DocumentationTok{\#\# Generating a dispRity object}
+\NormalTok{random\_disparity }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(distance\_matrix, random\_groups)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Warning: custom.subsets is applied on what seems to be a distance matrix.
## The resulting matrices won't be distance matrices anymore!
+## You can use dist.data = TRUE, if you want to keep the data as a distance matrix.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Running a default NPMANOVA}
-\KeywordTok{adonis.dispRity}\NormalTok{(random\_disparity)}
+\DocumentationTok{\#\# Running a default NPMANOVA}
+\FunctionTok{adonis.dispRity}\NormalTok{(random\_disparity)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = matrix ~ group, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## group 1 14.2 0.06443 1.2396 0.166
+## Model 1 14.2 0.06443 1.2396 0.166
## Residual 18 206.2 0.93557
## Total 19 220.4 1.00000
\end{verbatim}
@@ -3780,41 +3584,40 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating two groups with two states each}
-\NormalTok{groups \textless{}{-}}\StringTok{ }\KeywordTok{as.data.frame}\NormalTok{(}\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{data =} \KeywordTok{c}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{10}\NormalTok{),}
- \KeywordTok{rep}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{10}\NormalTok{),}
- \KeywordTok{rep}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{), }\DecValTok{10}\NormalTok{)),}
- \DataTypeTok{nrow =} \DecValTok{20}\NormalTok{, }\DataTypeTok{ncol =} \DecValTok{2}\NormalTok{,}
- \DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{20}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"g1"}\NormalTok{, }\StringTok{"g2"}\NormalTok{))))}
+\DocumentationTok{\#\# Creating two groups with two states each}
+\NormalTok{groups }\OtherTok{\textless{}{-}} \FunctionTok{as.data.frame}\NormalTok{(}\FunctionTok{matrix}\NormalTok{(}\AttributeTok{data =} \FunctionTok{c}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{10}\NormalTok{),}
+ \FunctionTok{rep}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{10}\NormalTok{),}
+ \FunctionTok{rep}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{), }\DecValTok{10}\NormalTok{)),}
+ \AttributeTok{nrow =} \DecValTok{20}\NormalTok{, }\AttributeTok{ncol =} \DecValTok{2}\NormalTok{,}
+ \AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{20}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"g1"}\NormalTok{, }\StringTok{"g2"}\NormalTok{))))}
-\CommentTok{\#\# Creating the dispRity object}
-\NormalTok{multi\_groups \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(distance\_matrix, groups)}
+\DocumentationTok{\#\# Creating the dispRity object}
+\NormalTok{multi\_groups }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(distance\_matrix, groups)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Warning: custom.subsets is applied on what seems to be a distance matrix.
## The resulting matrices won't be distance matrices anymore!
+## You can use dist.data = TRUE, if you want to keep the data as a distance matrix.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Running the NPMANOVA}
-\KeywordTok{adonis.dispRity}\NormalTok{(multi\_groups, matrix }\OperatorTok{\textasciitilde{}}\StringTok{ }\NormalTok{g1 }\OperatorTok{+}\StringTok{ }\NormalTok{g2)}
+\DocumentationTok{\#\# Running the NPMANOVA}
+\FunctionTok{adonis.dispRity}\NormalTok{(multi\_groups, matrix }\SpecialCharTok{\textasciitilde{}}\NormalTok{ g1 }\SpecialCharTok{+}\NormalTok{ g2)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = matrix ~ g1 + g2, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## g1 1 11.0 0.04991 0.9359 0.549
-## g2 1 9.6 0.04356 0.8168 0.766
+## Model 2 20.6 0.09347 0.8764 0.746
## Residual 17 199.8 0.90653
## Total 19 220.4 1.00000
\end{verbatim}
@@ -3824,15 +3627,15 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating time series}
-\NormalTok{time\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{,}
- \DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{,}
- \DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{85}\NormalTok{, }\DecValTok{65}\NormalTok{, }\DecValTok{0}\NormalTok{),}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+\DocumentationTok{\#\# Creating time series}
+\NormalTok{time\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(BeckLee\_mat50, BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{,}
+ \AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{,}
+ \AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{85}\NormalTok{, }\DecValTok{65}\NormalTok{, }\DecValTok{0}\NormalTok{),}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
-\CommentTok{\#\# Running the NPMANOVA with time as a predictor}
-\KeywordTok{adonis.dispRity}\NormalTok{(time\_subsets)}
+\DocumentationTok{\#\# Running the NPMANOVA with time as a predictor}
+\FunctionTok{adonis.dispRity}\NormalTok{(time\_subsets)}
\end{Highlighting}
\end{Shaded}
@@ -3844,13 +3647,12 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}
\begin{verbatim}
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = dist(matrix) ~ time, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## time 2 9.593 0.07769 1.9796 0.001 ***
+## Model 2 9.593 0.07769 1.9796 0.001 ***
## Residual 47 113.884 0.92231
## Total 49 123.477 1.00000
## ---
@@ -3864,8 +3666,8 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Running the NPMANOVA with each time bin as a predictor}
-\KeywordTok{adonis.dispRity}\NormalTok{(time\_subsets, matrix }\OperatorTok{\textasciitilde{}}\StringTok{ }\NormalTok{chrono.subsets)}
+\DocumentationTok{\#\# Running the NPMANOVA with each time bin as a predictor}
+\FunctionTok{adonis.dispRity}\NormalTok{(time\_subsets, matrix }\SpecialCharTok{\textasciitilde{}}\NormalTok{ chrono.subsets)}
\end{Highlighting}
\end{Shaded}
@@ -3877,14 +3679,12 @@ \subsection{\texorpdfstring{NPMANOVA in \texttt{dispRity}}{NPMANOVA in dispRity}
\begin{verbatim}
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = dist(matrix) ~ chrono.subsets, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## t100to85 1 3.714 0.03008 1.5329 0.006 **
-## t85to65 1 5.879 0.04761 2.4262 0.001 ***
+## Model 2 9.593 0.07769 1.9796 0.001 ***
## Residual 47 113.884 0.92231
## Total 49 123.477 1.00000
## ---
@@ -3900,7 +3700,7 @@ \subsection{\texorpdfstring{\texttt{geiger::dtt} model fitting in \texttt{dispRi
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{require}\NormalTok{(geiger)}
+\FunctionTok{require}\NormalTok{(geiger)}
\end{Highlighting}
\end{Shaded}
@@ -3910,13 +3710,13 @@ \subsection{\texorpdfstring{\texttt{geiger::dtt} model fitting in \texttt{dispRi
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{geiger\_data \textless{}{-}}\StringTok{ }\KeywordTok{get}\NormalTok{(}\KeywordTok{data}\NormalTok{(geospiza))}
+\NormalTok{geiger\_data }\OtherTok{\textless{}{-}} \FunctionTok{get}\NormalTok{(}\FunctionTok{data}\NormalTok{(geospiza))}
-\CommentTok{\#\# Calculate the disparity of the dataset using the sum of variance}
-\NormalTok{dispRity\_dtt \textless{}{-}}\StringTok{ }\KeywordTok{dtt.dispRity}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ geiger\_data}\OperatorTok{$}\NormalTok{dat,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances),}
- \DataTypeTok{tree =}\NormalTok{ geiger\_data}\OperatorTok{$}\NormalTok{phy,}
- \DataTypeTok{nsim =} \DecValTok{100}\NormalTok{)}
+\DocumentationTok{\#\# Calculate the disparity of the dataset using the sum of variance}
+\NormalTok{dispRity\_dtt }\OtherTok{\textless{}{-}} \FunctionTok{dtt.dispRity}\NormalTok{(}\AttributeTok{data =}\NormalTok{ geiger\_data}\SpecialCharTok{$}\NormalTok{dat,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances),}
+ \AttributeTok{tree =}\NormalTok{ geiger\_data}\SpecialCharTok{$}\NormalTok{phy,}
+ \AttributeTok{nsim =} \DecValTok{100}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -3927,12 +3727,12 @@ \subsection{\texorpdfstring{\texttt{geiger::dtt} model fitting in \texttt{dispRi
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(dispRity\_dtt)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(dispRity\_dtt)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-96-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-97-1.pdf}
Note that, like in the original \texttt{dtt} function, it is possible to change the evolutionary model (see \texttt{?geiger::sim.char} documentation).
@@ -3945,13 +3745,13 @@ \subsection{\texorpdfstring{null morphospace testing with \texttt{null.test}}{nu
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)}
-\CommentTok{\#\# A "normal" multidimensional space with 50 dimensions and 10 elements}
-\NormalTok{normal\_space \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{1000}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{50}\NormalTok{)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)}
+\DocumentationTok{\#\# A "normal" multidimensional space with 50 dimensions and 10 elements}
+\NormalTok{normal\_space }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{1000}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{50}\NormalTok{)}
-\CommentTok{\#\# Calculating the disparity as the average pairwise distances}
-\NormalTok{obs\_disparity \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(normal\_space,}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, pairwise.dist))}
+\DocumentationTok{\#\# Calculating the disparity as the average pairwise distances}
+\NormalTok{obs\_disparity }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(normal\_space,}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, pairwise.dist))}
\end{Highlighting}
\end{Shaded}
@@ -3962,9 +3762,9 @@ \subsection{\texorpdfstring{null morphospace testing with \texttt{null.test}}{nu
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing against 100 randomly generated normal spaces}
-\NormalTok{(results \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(obs\_disparity, }\DataTypeTok{replicates =} \DecValTok{100}\NormalTok{,}
- \DataTypeTok{null.distrib =}\NormalTok{ rnorm))}
+\DocumentationTok{\#\# Testing against 100 randomly generated normal spaces}
+\NormalTok{(results }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(obs\_disparity, }\AttributeTok{replicates =} \DecValTok{100}\NormalTok{,}
+ \AttributeTok{null.distrib =}\NormalTok{ rnorm))}
\end{Highlighting}
\end{Shaded}
@@ -3989,12 +3789,12 @@ \subsection{\texorpdfstring{null morphospace testing with \texttt{null.test}}{nu
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(results, }\DataTypeTok{main =} \StringTok{"Is this space normal?"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(results, }\AttributeTok{main =} \StringTok{"Is this space normal?"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-98-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-99-1.pdf}
For more details on generating spaces see the \protect\hyperlink{Simulating-multidimensional-spaces}{\texttt{space.maker}} function tutorial.
@@ -4022,16 +3822,16 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading premade disparity data}
-\KeywordTok{data}\NormalTok{(BeckLee\_disparity)}
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity, }\DataTypeTok{model =} \StringTok{"Stasis"}\NormalTok{)}
+\DocumentationTok{\#\# Loading premade disparity data}
+\FunctionTok{data}\NormalTok{(BeckLee\_disparity)}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity, }\AttributeTok{model =} \StringTok{"Stasis"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
+## Running Stasis model...Done. Log-likelihood = -15.562
\end{verbatim}
We can see the standard output from \texttt{model.test}.
@@ -4045,30 +3845,30 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time\_pooled \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \StringTok{"Stasis"}\NormalTok{,}
- \DataTypeTok{pool.variance =} \OtherTok{TRUE}\NormalTok{)}
+\NormalTok{disp\_time\_pooled }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \StringTok{"Stasis"}\NormalTok{,}
+ \AttributeTok{pool.variance =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## Running Stasis model...Done. Log-likelihood = -16.884
+## Running Stasis model...Done. Log-likelihood = -13.682
\end{verbatim}
However, unless you have good reason to choose otherwise it is recommended to use the default of \texttt{pool.variance\ =\ NULL}:
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \StringTok{"Stasis"}\NormalTok{,}
- \DataTypeTok{pool.variance =} \OtherTok{NULL}\NormalTok{)}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \StringTok{"Stasis"}\NormalTok{,}
+ \AttributeTok{pool.variance =} \ConstantTok{NULL}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
+## Running Stasis model...Done. Log-likelihood = -15.562
\end{verbatim}
\begin{Shaded}
@@ -4082,13 +3882,13 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
## Call: model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL)
##
## aicc delta_aicc weight_aicc
-## Stasis 41.48967 0 1
+## Stasis 35.22653 0 1
##
## Use x$full.details for displaying the models details
## or summary(x) for summarising them.
\end{verbatim}
-The remaining output gives us the log-likelihood of the Stasis model of -18.7 (you may notice this change when we pooled variances above).
+The remaining output gives us the log-likelihood of the Stasis model of -15.6 (you may notice this change when we pooled variances above).
The output also gives us the small sample Akaike Information Criterion (AICc), the delta AICc (the distance from the best fitting model), and the AICc weights (\textasciitilde the relative support of this model compared to all models, scaled to one).
These are all metrics of relative fit, so when we test a single model they are not useful.
@@ -4096,17 +3896,17 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(disp\_time)}
+\FunctionTok{summary}\NormalTok{(disp\_time)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param theta.1 omega
-## Stasis 41.5 0 1 -18.7 2 3.6 0.1
+## Stasis 35.2 0 1 -15.6 2 3.5 0.1
\end{verbatim}
So we again see the AICc, delta AICc, AICc weight, and the log-likelihood we saw previously.
-We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.6).
+We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.5).
The \texttt{model.test} function is designed to test relative model fit, so we need to test more than one model to make relative comparisons.
So let's compare to the fit of the Stasis model to another model with two parameters: the Brownian motion.
@@ -4115,16 +3915,16 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
\end{verbatim}
\begin{Shaded}
@@ -4138,28 +3938,28 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
## Call: model.test(data = BeckLee_disparity, model = c("Stasis", "BM"))
##
## aicc delta_aicc weight_aicc
-## Stasis 41.48967 335.9656 1.111708e-73
-## BM -294.47595 0.0000 1.000000e+00
+## Stasis 35.22653 334.3978 2.434618e-73
+## BM -299.17132 0.0000 1.000000e+00
##
## Use x$full.details for displaying the models details
## or summary(x) for summarising them.
\end{verbatim}
Et voilà! Here we can see by the log-likelihood, AICc, delta AICc, and AICc weight Brownian motion has a much better relative fit to these data than the Stasis model.
-Brownian motion has a relative AICc fit336 units better than Stasis, and has a AICc weight of 1.
+Brownian motion has a relative AICc fit334.4 units better than Stasis, and has a AICc weight of 1.
We can also all the information about the relative fit of models alongside the maximum likelihood estimates of model parameters using the summary function
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(disp\_time)}
+\FunctionTok{summary}\NormalTok{(disp\_time)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Stasis 41 336 0 -18.7 2 3.629 0.074 NA
-## BM -294 0 1 149.3 2 NA NA 3.267
+## Stasis 35 334.4 0 -15.6 2 3.486 0.07 NA
+## BM -299 0.0 1 151.6 2 NA NA 3.132
## sigma squared
## Stasis NA
## BM 0.001
@@ -4171,7 +3971,7 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{plot}\NormalTok{(disp\_time)}
+\FunctionTok{plot}\NormalTok{(disp\_time)}
\end{Highlighting}
\end{Shaded}
@@ -4190,47 +3990,47 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 152.119
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 154.512
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(disp\_time)}
+\FunctionTok{summary}\NormalTok{(disp\_time)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
-## BM -294 3.6 0.112 149.3 2 NA NA 3.267
-## OU -296 2.1 0.227 152.1 4 NA NA 3.254
-## Trend -298 0.0 0.661 152.1 3 NA NA 3.255
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
+## BM -299 3.6 0.108 151.6 2 NA NA 3.132
+## OU -301 2.1 0.229 154.5 4 NA NA 3.118
+## Trend -303 0.0 0.664 154.5 3 NA NA 3.119
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
## sigma squared alpha optima.1 trend eb
## Stasis NA NA NA NA NA
## BM 0.001 NA NA NA NA
-## OU 0.001 0.001 12.35 NA NA
+## OU 0.001 0.001 10.18 NA NA
## Trend 0.001 NA NA 0.007 NA
-## EB 0.000 NA NA NA -0.032
+## EB 0.000 NA NA NA -0.034
\end{verbatim}
These models indicate support for a Trend model, and we can plot the relative support of all model AICc weights.
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{plot}\NormalTok{(disp\_time)}
+\FunctionTok{plot}\NormalTok{(disp\_time)}
\end{Highlighting}
\end{Shaded}
@@ -4252,15 +4052,15 @@ \subsubsection{\texorpdfstring{\texttt{model.test}}{model.test}}\label{model.tes
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(disp\_time)[}\StringTok{"Trend"}\NormalTok{,]}
+\FunctionTok{summary}\NormalTok{(disp\_time)[}\StringTok{"Trend"}\NormalTok{,]}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param
-## -298.000 0.000 0.661 152.100 3.000
+## -303.000 0.000 0.664 154.500 3.000
## theta.1 omega ancestral state sigma squared alpha
-## NA NA 3.255 0.001 NA
+## NA NA 3.119 0.001 NA
## optima.1 trend eb
## NA 0.007 NA
\end{verbatim}
@@ -4281,20 +4081,20 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}}
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),}
- \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{)}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),}
+ \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 152.119
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 154.512
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
\end{verbatim}
\begin{figure}
@@ -4314,22 +4114,22 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Trend -298 0.0 0.661 152.1 3 NA NA 3.255
-## OU -296 2.1 0.227 152.1 4 NA NA 3.254
-## BM -294 3.6 0.112 149.3 2 NA NA 3.267
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
+## Trend -303 0.0 0.664 154.5 3 NA NA 3.119
+## OU -301 2.1 0.229 154.5 4 NA NA 3.118
+## BM -299 3.6 0.108 151.6 2 NA NA 3.132
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
## sigma squared alpha optima.1 trend eb median p value lower p value
-## Trend 0.001 NA NA 0.007 NA 0.978021978 0.9760240
-## OU 0.001 0.001 12.35 NA NA 0.978021978 0.9770230
-## BM 0.001 NA NA NA NA 0.143856144 0.1368631
-## EB 0.000 NA NA NA -0.032 0.000999001 0.0000000
+## Trend 0.001 NA NA 0.007 NA 0.986013986 0.9850150
+## OU 0.001 0.001 10.18 NA NA 0.979020979 0.9770230
+## BM 0.001 NA NA NA NA 0.107892108 0.0969031
+## EB 0.000 NA NA NA -0.034 0.000999001 0.0000000
## Stasis NA NA NA NA NA 1.000000000 0.9990010
## upper p value
-## Trend 0.9780220
-## OU 0.9780220
-## BM 0.1878122
-## EB 0.1368631
+## Trend 0.9860140
+## OU 0.9800200
+## BM 0.1388611
+## EB 0.1378621
## Stasis 1.0000000
\end{verbatim}
@@ -4337,26 +4137,26 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}}
There is no significant differences between the empirical data and simulated data, except for the Early Burst model.
Trend is the best-fitting model but the plot suggests the OU model also follows a trend-like pattern.
-This is because the optima for the OU model (12.35) is different to the ancestral state (3.254) and outside the observed value.
+This is because the optima for the OU model (10.18) is different to the ancestral state (3.118) and outside the observed value.
This is potentially unrealistic, and one way to alleviate this issue is to set the optima of the OU model to equal the ancestral estimate - this is the normal practice for OU models in comparative phylogenetics.
To set the optima to the ancestral value we change the argument \texttt{fixed.optima\ =\ TRUE}:
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),}
- \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{),}
+ \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 149.289
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 151.637
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
\end{verbatim}
\begin{figure}
@@ -4376,21 +4176,21 @@ \subsubsection{\texorpdfstring{\texttt{model.test.wrapper}}{model.test.wrapper}}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Trend -298 0.0 0.814 152.1 3 NA NA 3.255
-## BM -294 3.6 0.138 149.3 2 NA NA 3.267
-## OU -292 5.7 0.048 149.3 3 NA NA 3.267
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
+## Trend -303 0.0 0.821 154.5 3 NA NA 3.119
+## BM -299 3.6 0.133 151.6 2 NA NA 3.132
+## OU -297 5.7 0.046 151.6 3 NA NA 3.132
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
## sigma squared alpha trend eb median p value lower p value
-## Trend 0.001 NA 0.007 NA 0.984015984 0.9820180
-## BM 0.001 NA NA NA 0.256743257 0.2487512
-## OU 0.001 0 NA NA 0.293706294 0.2917083
-## EB 0.000 NA NA -0.032 0.000999001 0.0000000
+## Trend 0.001 NA 0.007 NA 0.989010989 0.9880120
+## BM 0.001 NA NA NA 0.224775225 0.2117882
+## OU 0.001 0 NA NA 0.264735265 0.2637363
+## EB 0.000 NA NA -0.034 0.000999001 0.0000000
## Stasis NA NA NA NA 0.999000999 0.9980020
## upper p value
-## Trend 0.9840160
-## BM 0.2797203
-## OU 0.3166833
+## Trend 0.9890110
+## BM 0.2507493
+## OU 0.2967033
## EB 0.1378621
## Stasis 0.9990010
\end{verbatim}
@@ -4413,22 +4213,22 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),}
- \DataTypeTok{time.split =} \DecValTok{66}\NormalTok{,}
- \DataTypeTok{pool.variance =} \OtherTok{NULL}\NormalTok{,}
- \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{,}
- \DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),}
+ \AttributeTok{time.split =} \DecValTok{66}\NormalTok{,}
+ \AttributeTok{pool.variance =} \ConstantTok{NULL}\NormalTok{,}
+ \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{,}
+ \AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running BM model...Done. Log-likelihood = 149.289
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running OU model...Done. Log-likelihood = 149.289
-## Running multi.OU model...Done. Log-likelihood = 151.958
+## Running BM model...Done. Log-likelihood = 151.637
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running OU model...Done. Log-likelihood = 151.637
+## Running multi.OU model...Done. Log-likelihood = 154.492
\end{verbatim}
\begin{figure}
@@ -4448,20 +4248,20 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param ancestral state
-## Trend -298 0.000 0.657 152.1 3 3.255
-## multi.OU -296 2.456 0.193 152.0 4 3.253
-## BM -294 3.550 0.111 149.3 2 3.267
-## OU -292 5.654 0.039 149.3 3 3.267
+## Trend -303 0.000 0.642 154.5 3 3.119
+## multi.OU -301 2.170 0.217 154.5 4 3.117
+## BM -299 3.639 0.104 151.6 2 3.132
+## OU -297 5.742 0.036 151.6 3 3.132
## sigma squared trend alpha optima.2 median p value lower p value
## Trend 0.001 0.007 NA NA 0.9870130 0.9860140
-## multi.OU 0.001 NA 0.006 4.686 0.9570430 0.9560440
-## BM 0.001 NA NA NA 0.1868132 0.1808192
-## OU 0.001 NA 0.000 NA 0.2727273 0.2707293
+## multi.OU 0.001 NA 0.003 5.582 0.9620380 0.9610390
+## BM 0.001 NA NA NA 0.1848152 0.1838162
+## OU 0.001 NA 0.000 NA 0.2787213 0.2757243
## upper p value
## Trend 0.9870130
-## multi.OU 0.9590410
-## BM 0.2207792
-## OU 0.3016983
+## multi.OU 0.9620380
+## BM 0.2217782
+## OU 0.3046953
\end{verbatim}
The multi-OU model shows an increase an optima at the Cretaceous-Palaeogene boundary, indicating a shift in disparity.
@@ -4472,11 +4272,11 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# An example of a time split model in which all potential splits are tested}
-\CommentTok{\#\# }\AlertTok{WARNING}\CommentTok{: this will take between 20 minutes and half and hour to run!}
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),}
- \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# An example of a time split model in which all potential splits are tested}
+\DocumentationTok{\#\# }\AlertTok{WARNING}\DocumentationTok{: this will take between 20 minutes and half and hour to run!}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"multi.OU"}\NormalTok{),}
+ \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -4489,28 +4289,28 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The models to test}
-\NormalTok{my\_models \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Stasis"}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{),}
- \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))}
+\DocumentationTok{\#\# The models to test}
+\NormalTok{my\_models }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"OU"}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\StringTok{"Stasis"}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{),}
+ \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{))}
-\CommentTok{\#\# Testing the models}
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test.wrapper}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =}\NormalTok{ my\_models, }\DataTypeTok{time.split =} \DecValTok{66}\NormalTok{,}
- \DataTypeTok{show.p =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{fixed.optima =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Testing the models}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test.wrapper}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =}\NormalTok{ my\_models, }\AttributeTok{time.split =} \DecValTok{66}\NormalTok{,}
+ \AttributeTok{show.p =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{fixed.optima =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running BM:OU model...Done. Log-likelihood = 144.102
-## Running Stasis:OU model...Done. Log-likelihood = 125.066
-## Running BM:Stasis model...Done. Log-likelihood = 69.265
-## Running OU:Trend model...Done. Log-likelihood = 147.839
-## Running Stasis:BM model...Done. Log-likelihood = 125.066
+## Running BM:OU model...Done. Log-likelihood = 146.472
+## Running Stasis:OU model...Done. Log-likelihood = 127.707
+## Running BM:Stasis model...Done. Log-likelihood = 72.456
+## Running OU:Trend model...Done. Log-likelihood = 150.208
+## Running Stasis:BM model...Done. Log-likelihood = 127.707
\end{verbatim}
\begin{figure}
@@ -4530,22 +4330,22 @@ \subsection{Multiple modes of evolution (time shifts)}\label{multiple-modes-of-e
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param ancestral state
-## OU:Trend -287 0.0 0.977 147.8 4 3.352
-## BM:OU -280 7.5 0.023 144.1 4 3.350
-## Stasis:BM -244 43.4 0.000 125.1 3 NA
-## Stasis:OU -240 47.7 0.000 125.1 5 NA
-## BM:Stasis -130 157.1 0.000 69.3 4 3.268
+## OU:Trend -292 0.0 0.977 150.2 4 3.218
+## BM:OU -285 7.5 0.023 146.5 4 3.216
+## Stasis:BM -249 42.9 0.000 127.7 3 NA
+## Stasis:OU -245 47.2 0.000 127.7 5 NA
+## BM:Stasis -137 155.5 0.000 72.5 4 3.132
## sigma squared alpha optima.1 theta.1 omega trend median p value
-## OU:Trend 0.001 0.041 NA NA NA 0.011 0.2987013
-## BM:OU 0.001 0.000 4.092 NA NA NA 0.4925075
-## Stasis:BM 0.002 NA NA 3.390 0.004 NA 0.9970030
-## Stasis:OU 0.002 0.000 4.092 3.390 0.004 NA 1.0000000
-## BM:Stasis 0.000 NA NA 3.806 0.058 NA 1.0000000
+## OU:Trend 0.001 0.042 NA NA NA 0.011 0.3066933
+## BM:OU 0.001 0.000 3.934 NA NA NA 0.4985015
+## Stasis:BM 0.002 NA NA 3.25 0.004 NA 0.9960040
+## Stasis:OU 0.002 0.000 3.934 3.25 0.004 NA 0.9990010
+## BM:Stasis 0.000 NA NA 3.66 0.053 NA 1.0000000
## lower p value upper p value
-## OU:Trend 0.2947053 0.3536464
-## BM:OU 0.4875125 0.5134865
-## Stasis:BM 0.9960040 0.9970030
-## Stasis:OU 0.9990010 1.0000000
+## OU:Trend 0.3026973 0.3626374
+## BM:OU 0.4945055 0.5184815
+## Stasis:BM 0.9950050 0.9960040
+## Stasis:OU 0.9980020 1.0000000
## BM:Stasis 0.9990010 1.0000000
\end{verbatim}
@@ -4568,11 +4368,11 @@ \subsection{\texorpdfstring{\texttt{model.test.sim}}{model.test.sim}}\label{mode
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A simple BM model}
-\NormalTok{model\_simulation \textless{}{-}}\StringTok{ }\KeywordTok{model.test.sim}\NormalTok{(}\DataTypeTok{sim =} \DecValTok{1000}\NormalTok{, }\DataTypeTok{model =} \StringTok{"BM"}\NormalTok{,}
- \DataTypeTok{time.span =} \DecValTok{50}\NormalTok{, }\DataTypeTok{variance =} \FloatTok{0.1}\NormalTok{,}
- \DataTypeTok{sample.size =} \DecValTok{100}\NormalTok{,}
- \DataTypeTok{parameters =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{ancestral.state =} \DecValTok{0}\NormalTok{))}
+\DocumentationTok{\#\# A simple BM model}
+\NormalTok{model\_simulation }\OtherTok{\textless{}{-}} \FunctionTok{model.test.sim}\NormalTok{(}\AttributeTok{sim =} \DecValTok{1000}\NormalTok{, }\AttributeTok{model =} \StringTok{"BM"}\NormalTok{,}
+ \AttributeTok{time.span =} \DecValTok{50}\NormalTok{, }\AttributeTok{variance =} \FloatTok{0.1}\NormalTok{,}
+ \AttributeTok{sample.size =} \DecValTok{100}\NormalTok{,}
+ \AttributeTok{parameters =} \FunctionTok{list}\NormalTok{(}\AttributeTok{ancestral.state =} \DecValTok{0}\NormalTok{))}
\NormalTok{model\_simulation}
\end{Highlighting}
\end{Shaded}
@@ -4591,8 +4391,8 @@ \subsection{\texorpdfstring{\texttt{model.test.sim}}{model.test.sim}}\label{mode
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Displaying the 5 first rows of the summary}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(model\_simulation))}
+\DocumentationTok{\#\# Displaying the 5 first rows of the summary}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(model\_simulation))}
\end{Highlighting}
\end{Shaded}
@@ -4608,8 +4408,8 @@ \subsection{\texorpdfstring{\texttt{model.test.sim}}{model.test.sim}}\label{mode
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the simulations}
-\KeywordTok{plot}\NormalTok{(model\_simulation)}
+\DocumentationTok{\#\# Plotting the simulations}
+\FunctionTok{plot}\NormalTok{(model\_simulation)}
\end{Highlighting}
\end{Shaded}
@@ -4632,50 +4432,50 @@ \subsubsection{Simulating tested models}\label{simulating-tested-models}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Fitting multiple models on the data set}
-\NormalTok{disp\_time \textless{}{-}}\StringTok{ }\KeywordTok{model.test}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_disparity,}
- \DataTypeTok{model =} \KeywordTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))}
+\DocumentationTok{\#\# Fitting multiple models on the data set}
+\NormalTok{disp\_time }\OtherTok{\textless{}{-}} \FunctionTok{model.test}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_disparity,}
+ \AttributeTok{model =} \FunctionTok{c}\NormalTok{(}\StringTok{"Stasis"}\NormalTok{, }\StringTok{"BM"}\NormalTok{, }\StringTok{"OU"}\NormalTok{, }\StringTok{"Trend"}\NormalTok{, }\StringTok{"EB"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Evidence of equal variance (Bartlett's test of equal variances p = 0).
## Variance is not pooled.
-## Running Stasis model...Done. Log-likelihood = -18.694
-## Running BM model...Done. Log-likelihood = 149.289
-## Running OU model...Done. Log-likelihood = 152.119
-## Running Trend model...Done. Log-likelihood = 152.116
-## Running EB model...Done. Log-likelihood = 126.268
+## Running Stasis model...Done. Log-likelihood = -15.562
+## Running BM model...Done. Log-likelihood = 151.637
+## Running OU model...Done. Log-likelihood = 154.512
+## Running Trend model...Done. Log-likelihood = 154.508
+## Running EB model...Done. Log-likelihood = 128.008
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(disp\_time)}
+\FunctionTok{summary}\NormalTok{(disp\_time)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state
-## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA
-## BM -294 3.6 0.112 149.3 2 NA NA 3.267
-## OU -296 2.1 0.227 152.1 4 NA NA 3.254
-## Trend -298 0.0 0.661 152.1 3 NA NA 3.255
-## EB -246 51.7 0.000 126.3 3 NA NA 4.092
+## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA
+## BM -299 3.6 0.108 151.6 2 NA NA 3.132
+## OU -301 2.1 0.229 154.5 4 NA NA 3.118
+## Trend -303 0.0 0.664 154.5 3 NA NA 3.119
+## EB -250 53.0 0.000 128.0 3 NA NA 3.934
## sigma squared alpha optima.1 trend eb
## Stasis NA NA NA NA NA
## BM 0.001 NA NA NA NA
-## OU 0.001 0.001 12.35 NA NA
+## OU 0.001 0.001 10.18 NA NA
## Trend 0.001 NA NA 0.007 NA
-## EB 0.000 NA NA NA -0.032
+## EB 0.000 NA NA NA -0.034
\end{verbatim}
As seen before, the Trend model fitted this dataset the best.
-To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with \texttt{model.test} (here the ancestral state being 3.255, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to \texttt{model.test.sim}:
+To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with \texttt{model.test} (here the ancestral state being 3.119, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to \texttt{model.test.sim}:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Simulating 1000 Trend model with the observed parameters}
-\NormalTok{sim\_trend \textless{}{-}}\StringTok{ }\KeywordTok{model.test.sim}\NormalTok{(}\DataTypeTok{sim =} \DecValTok{1000}\NormalTok{, }\DataTypeTok{model =}\NormalTok{ disp\_time)}
+\DocumentationTok{\#\# Simulating 1000 Trend model with the observed parameters}
+\NormalTok{sim\_trend }\OtherTok{\textless{}{-}} \FunctionTok{model.test.sim}\NormalTok{(}\AttributeTok{sim =} \DecValTok{1000}\NormalTok{, }\AttributeTok{model =}\NormalTok{ disp\_time)}
\NormalTok{sim\_trend}
\end{Highlighting}
\end{Shaded}
@@ -4686,20 +4486,20 @@ \subsubsection{Simulating tested models}\label{simulating-tested-models}}
##
## Model simulated (1000 times):
## aicc log.lik param ancestral state sigma squared trend
-## Trend -298 152.1 3 3.255 0.001 0.007
+## Trend -303 154.5 3 3.119 0.001 0.007
##
## Rank envelope test:
-## p-value of the global test: 0.99001 (ties method: erl)
-## p-interval : (0.989011, 0.99001)
+## p-value of the global test: 0.992008 (ties method: erl)
+## p-interval : (0.991009, 0.992008)
\end{verbatim}
By default, the model simulated is the one with the lowest AICc (\texttt{model.rank\ =\ 1}) but it is possible to choose any ranked model, for example, the OU (second one):
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Simulating 1000 OU model with the observed parameters}
-\NormalTok{sim\_OU \textless{}{-}}\StringTok{ }\KeywordTok{model.test.sim}\NormalTok{(}\DataTypeTok{sim =} \DecValTok{1000}\NormalTok{, }\DataTypeTok{model =}\NormalTok{ disp\_time,}
- \DataTypeTok{model.rank =} \DecValTok{2}\NormalTok{)}
+\DocumentationTok{\#\# Simulating 1000 OU model with the observed parameters}
+\NormalTok{sim\_OU }\OtherTok{\textless{}{-}} \FunctionTok{model.test.sim}\NormalTok{(}\AttributeTok{sim =} \DecValTok{1000}\NormalTok{, }\AttributeTok{model =}\NormalTok{ disp\_time,}
+ \AttributeTok{model.rank =} \DecValTok{2}\NormalTok{)}
\NormalTok{sim\_OU}
\end{Highlighting}
\end{Shaded}
@@ -4710,55 +4510,55 @@ \subsubsection{Simulating tested models}\label{simulating-tested-models}}
##
## Model simulated (1000 times):
## aicc log.lik param ancestral state sigma squared alpha optima.1
-## OU -296 152.1 4 3.254 0.001 0.001 12.35
+## OU -301 154.5 4 3.118 0.001 0.001 10.18
##
## Rank envelope test:
-## p-value of the global test: 0.992008 (ties method: erl)
-## p-interval : (0.99001, 0.992008)
+## p-value of the global test: 0.991009 (ties method: erl)
+## p-interval : (0.989011, 0.991009)
\end{verbatim}
And as the example above, the simulated data can be plotted or summarised:
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(sim\_trend))}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(sim\_trend))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n var median 2.5% 25% 75% 97.5%
-## 1 120 5 0.01723152 3.255121 3.135057 3.219150 3.293407 3.375118
-## 2 119 5 0.03555816 3.265538 3.093355 3.200493 3.323520 3.440795
-## 3 118 6 0.03833089 3.269497 3.090438 3.212015 3.329629 3.443074
-## 4 117 7 0.03264826 3.279180 3.112205 3.224810 3.336801 3.447997
-## 5 116 7 0.03264826 3.284500 3.114788 3.223247 3.347970 3.463631
-## 6 115 7 0.03264826 3.293918 3.101298 3.231659 3.354321 3.474645
+## 1 120 5 0.01791717 3.119216 2.996786 3.082536 3.158256 3.241577
+## 2 119 5 0.03522253 3.129400 2.958681 3.064908 3.186889 3.303168
+## 3 118 6 0.03783622 3.133125 2.957150 3.076447 3.192556 3.304469
+## 4 117 7 0.03214472 3.143511 2.978352 3.089036 3.199075 3.307842
+## 5 116 7 0.03214472 3.147732 2.981253 3.087695 3.210136 3.321990
+## 6 115 7 0.03214472 3.157588 2.969189 3.094733 3.216221 3.335341
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(sim\_OU))}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(sim\_OU))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n var median 2.5% 25% 75% 97.5%
-## 1 120 5 0.01723152 3.253367 3.141471 3.212180 3.293760 3.371622
-## 2 119 5 0.03555816 3.263167 3.083477 3.197442 3.324438 3.440447
-## 3 118 6 0.03833089 3.262952 3.101351 3.203860 3.332595 3.440163
-## 4 117 7 0.03264826 3.272569 3.104476 3.214511 3.330587 3.442792
-## 5 116 7 0.03264826 3.280423 3.100220 3.219765 3.342726 3.475877
-## 6 115 7 0.03264826 3.287359 3.094699 3.222523 3.355278 3.477518
+## 1 120 5 0.01791717 3.116975 3.002874 3.074977 3.158164 3.237559
+## 2 119 5 0.03522253 3.126662 2.948491 3.061492 3.187414 3.302442
+## 3 118 6 0.03783622 3.126408 2.966988 3.068517 3.195251 3.301177
+## 4 117 7 0.03214472 3.136145 2.970973 3.079345 3.192427 3.301722
+## 5 116 7 0.03214472 3.144302 2.967779 3.083789 3.205035 3.336560
+## 6 115 7 0.03214472 3.151057 2.961801 3.086444 3.216077 3.336897
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The trend model with some graphical options}
-\KeywordTok{plot}\NormalTok{(sim\_trend, }\DataTypeTok{xlab =} \StringTok{"Time (Mya)"}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{"sum of variances"}\NormalTok{,}
- \DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"\#F65205"}\NormalTok{, }\StringTok{"\#F38336"}\NormalTok{, }\StringTok{"\#F7B27E"}\NormalTok{))}
+\DocumentationTok{\#\# The trend model with some graphical options}
+\FunctionTok{plot}\NormalTok{(sim\_trend, }\AttributeTok{xlab =} \StringTok{"Time (Mya)"}\NormalTok{, }\AttributeTok{ylab =} \StringTok{"sum of variances"}\NormalTok{,}
+ \AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"\#F65205"}\NormalTok{, }\StringTok{"\#F38336"}\NormalTok{, }\StringTok{"\#F7B27E"}\NormalTok{))}
-\CommentTok{\#\# Adding the observed disparity through time}
-\KeywordTok{plot}\NormalTok{(BeckLee\_disparity, }\DataTypeTok{add =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"\#3E9CBA"}\NormalTok{, }\StringTok{"\#98D4CF90"}\NormalTok{, }\StringTok{"\#BFE4E390"}\NormalTok{))}
+\DocumentationTok{\#\# Adding the observed disparity through time}
+\FunctionTok{plot}\NormalTok{(BeckLee\_disparity, }\AttributeTok{add =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"\#3E9CBA"}\NormalTok{, }\StringTok{"\#98D4CF90"}\NormalTok{, }\StringTok{"\#BFE4E390"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -4784,9 +4584,9 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity as a whole distribution}
-\NormalTok{disparity\_centroids \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(boot\_time\_slices, }
- \DataTypeTok{metric =}\NormalTok{ centroids)}
+\DocumentationTok{\#\# Measuring disparity as a whole distribution}
+\NormalTok{disparity\_centroids }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(boot\_time\_slices, }
+ \AttributeTok{metric =}\NormalTok{ centroids)}
\end{Highlighting}
\end{Shaded}
@@ -4794,9 +4594,9 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring median disparity in each time slice}
-\NormalTok{disparity\_centroids\_median \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(disparity\_centroids,}
- \DataTypeTok{metric =}\NormalTok{ median)}
+\DocumentationTok{\#\# Measuring median disparity in each time slice}
+\NormalTok{disparity\_centroids\_median }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(disparity\_centroids,}
+ \AttributeTok{metric =}\NormalTok{ median)}
\end{Highlighting}
\end{Shaded}
@@ -4804,33 +4604,33 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising both disparity measurements:}
-\CommentTok{\#\# The distributions:}
-\KeywordTok{summary}\NormalTok{(disparity\_centroids)}
+\DocumentationTok{\#\# Summarising both disparity measurements:}
+\DocumentationTok{\#\# The distributions:}
+\FunctionTok{summary}\NormalTok{(disparity\_centroids)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs.median bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 1.605 1.376 0.503 1.247 1.695 1.895
-## 2 80 19 1.834 1.774 1.514 1.691 1.853 1.968
-## 3 40 15 1.804 1.789 1.468 1.684 1.889 2.095
-## 4 0 10 1.911 1.809 1.337 1.721 1.968 2.099
+## 1 120 5 1.569 1.338 0.834 1.230 1.650 1.894
+## 2 80 19 1.796 1.739 1.498 1.652 1.812 1.928
+## 3 40 15 1.767 1.764 1.427 1.654 1.859 2.052
+## 4 0 10 1.873 1.779 1.361 1.685 1.934 2.058
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The summary of the distributions (as median)}
-\KeywordTok{summary}\NormalTok{(disparity\_centroids\_median)}
+\DocumentationTok{\#\# The summary of the distributions (as median)}
+\FunctionTok{summary}\NormalTok{(disparity\_centroids\_median)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 120 5 1.605 1.395 0.503 0.994 1.625 1.686
-## 2 80 19 1.834 1.774 1.682 1.749 1.799 1.823
-## 3 40 15 1.804 1.790 1.579 1.750 1.830 1.875
-## 4 0 10 1.911 1.812 1.659 1.784 1.859 1.930
+## 1 120 5 1.569 1.351 0.648 1.282 1.596 1.641
+## 2 80 19 1.796 1.739 1.655 1.721 1.756 1.787
+## 3 40 15 1.767 1.757 1.623 1.721 1.793 1.837
+## 4 0 10 1.873 1.781 1.564 1.756 1.834 1.900
\end{verbatim}
We can see that the summary message for the distribution is slightly different than before.
@@ -4841,22 +4641,22 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical parameters}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{, }\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# Graphical parameters}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{, }\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{))}
-\CommentTok{\#\# Plotting both disparity measurements}
-\KeywordTok{plot}\NormalTok{(disparity\_centroids,}
- \DataTypeTok{ylab =} \StringTok{"Distribution of all the distances"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(disparity\_centroids\_median,}
- \DataTypeTok{ylab =} \StringTok{"Distribution of the medians of all the distances"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting both disparity measurements}
+\FunctionTok{plot}\NormalTok{(disparity\_centroids,}
+ \AttributeTok{ylab =} \StringTok{"Distribution of all the distances"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(disparity\_centroids\_median,}
+ \AttributeTok{ylab =} \StringTok{"Distribution of the medians of all the distances"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-116-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-117-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(op)}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -4864,19 +4664,19 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Probability of overlap in the distribution of medians}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_centroids\_median, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff)}
+\DocumentationTok{\#\# Probability of overlap in the distribution of medians}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_centroids\_median, }\AttributeTok{test =}\NormalTok{ bhatt.coeff)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## bhatt.coeff
-## 120 : 80 0.09486833
-## 120 : 40 0.18256185
-## 120 : 0 0.18800657
-## 80 : 40 0.80759884
-## 80 : 0 0.71503765
-## 40 : 0 0.84542569
+## 120 : 80 0.08831761
+## 120 : 40 0.10583005
+## 120 : 0 0.15297059
+## 80 : 40 0.83840952
+## 80 : 0 0.63913150
+## 40 : 0 0.78405839
\end{verbatim}
In this case, we are looking at the probability of overlap of the distribution of median distances from centroids among each pair of time slices.
@@ -4888,19 +4688,19 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Probability of overlap for the full distributions}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_centroids, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff)}
+\DocumentationTok{\#\# Probability of overlap for the full distributions}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_centroids, }\AttributeTok{test =}\NormalTok{ bhatt.coeff)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## bhatt.coeff
-## 120 : 80 0.6088450
-## 120 : 40 0.6380217
-## 120 : 0 0.6340849
-## 80 : 40 0.9325982
-## 80 : 0 0.8614280
-## 40 : 0 0.9464329
+## 120 : 80 0.6163631
+## 120 : 40 0.6351473
+## 120 : 0 0.6315225
+## 80 : 40 0.9416508
+## 80 : 0 0.8551990
+## 40 : 0 0.9568684
\end{verbatim}
These results show the actual overlap among all the measured distances from centroids concatenated across all the bootstraps.
@@ -4911,20 +4711,20 @@ \section{Disparity as a distribution}\label{disparity-distribution}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Boostrapped probability of overlap for the full distributions}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_centroids, }\DataTypeTok{test =}\NormalTok{ bhatt.coeff,}
- \DataTypeTok{concatenate =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Boostrapped probability of overlap for the full distributions}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_centroids, }\AttributeTok{test =}\NormalTok{ bhatt.coeff,}
+ \AttributeTok{concatenate =} \ConstantTok{FALSE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## bhatt.coeff 2.5% 25% 75% 97.5%
-## 120 : 80 0.2641856 0.0000000 0.1450953 0.3964076 0.5468831
-## 120 : 40 0.2705336 0.0000000 0.1632993 0.3987346 0.6282038
-## 120 : 0 0.2841992 0.0000000 0.2000000 0.4000000 0.7083356
-## 80 : 40 0.6024121 0.3280389 0.4800810 0.7480791 0.8902989
-## 80 : 0 0.4495822 0.1450953 0.3292496 0.5715531 0.7332155
-## 40 : 0 0.5569422 0.2000000 0.4543681 0.6843217 0.8786504
+## bhatt.coeff 2.5% 25% 75% 97.5%
+## 120 : 80 0.2671081 0.00000000 0.1450953 0.3964076 0.6084459
+## 120 : 40 0.2864771 0.00000000 0.1632993 0.4238587 0.6444474
+## 120 : 0 0.2864716 0.00000000 0.2000000 0.4000000 0.5837006
+## 80 : 40 0.6187295 0.24391229 0.5284793 0.7440196 0.8961621
+## 80 : 0 0.4790692 0.04873397 0.3754429 0.5946595 0.7797225
+## 40 : 0 0.5513580 0.19542869 0.4207790 0.6870177 0.9066824
\end{verbatim}
These results show the median overlap among pairs of distributions in the first column (\texttt{bhatt.coeff}) and then the distribution of these overlaps among each pair of bootstraps.
@@ -4944,9 +4744,9 @@ \section{Disparity from other matrices}\label{other-matrices}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Making the eurodist data set into a matrix (rather than "dist" object)}
-\NormalTok{eurodist \textless{}{-}}\StringTok{ }\KeywordTok{as.matrix}\NormalTok{(eurodist)}
-\NormalTok{eurodist[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{]}
+\DocumentationTok{\#\# Making the eurodist data set into a matrix (rather than "dist" object)}
+\NormalTok{eurodist }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(eurodist)}
+\NormalTok{eurodist[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
@@ -4961,34 +4761,35 @@ \section{Disparity from other matrices}\label{other-matrices}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The two groups of cities}
-\NormalTok{Northern \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Brussels"}\NormalTok{, }\StringTok{"Calais"}\NormalTok{, }\StringTok{"Cherbourg"}\NormalTok{, }\StringTok{"Cologne"}\NormalTok{, }\StringTok{"Copenhagen"}\NormalTok{,}
+\DocumentationTok{\#\# The two groups of cities}
+\NormalTok{Northern }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"Brussels"}\NormalTok{, }\StringTok{"Calais"}\NormalTok{, }\StringTok{"Cherbourg"}\NormalTok{, }\StringTok{"Cologne"}\NormalTok{, }\StringTok{"Copenhagen"}\NormalTok{,}
\StringTok{"Hamburg"}\NormalTok{, }\StringTok{"Hook of Holland"}\NormalTok{, }\StringTok{"Paris"}\NormalTok{, }\StringTok{"Stockholm"}\NormalTok{)}
-\NormalTok{Southern \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Athens"}\NormalTok{, }\StringTok{"Barcelona"}\NormalTok{, }\StringTok{"Geneva"}\NormalTok{, }\StringTok{"Gibraltar"}\NormalTok{, }\StringTok{"Lisbon"}\NormalTok{, }\StringTok{"Lyons"}\NormalTok{,}
+\NormalTok{Southern }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"Athens"}\NormalTok{, }\StringTok{"Barcelona"}\NormalTok{, }\StringTok{"Geneva"}\NormalTok{, }\StringTok{"Gibraltar"}\NormalTok{, }\StringTok{"Lisbon"}\NormalTok{, }\StringTok{"Lyons"}\NormalTok{,}
\StringTok{"Madrid"}\NormalTok{, }\StringTok{"Marseilles"}\NormalTok{, }\StringTok{"Milan"}\NormalTok{, }\StringTok{"Munich"}\NormalTok{, }\StringTok{"Rome"}\NormalTok{, }\StringTok{"Vienna"}\NormalTok{)}
-\CommentTok{\#\# Creating the subset dispRity object}
-\NormalTok{eurodist\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(eurodist, }\DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}\StringTok{"Northern"}\NormalTok{ =}\StringTok{ }\NormalTok{Northern,}
- \StringTok{"Southern"}\NormalTok{ =}\StringTok{ }\NormalTok{Southern))}
+\DocumentationTok{\#\# Creating the subset dispRity object}
+\NormalTok{eurodist\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(eurodist, }\AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\StringTok{"Northern"} \OtherTok{=}\NormalTok{ Northern,}
+ \StringTok{"Southern"} \OtherTok{=}\NormalTok{ Southern))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Warning: custom.subsets is applied on what seems to be a distance matrix.
## The resulting matrices won't be distance matrices anymore!
+## You can use dist.data = TRUE, if you want to keep the data as a distance matrix.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Bootstrapping and rarefying to 9 elements (the number of Northern cities)}
-\NormalTok{eurodist\_bs \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(eurodist\_subsets, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{)}
+\DocumentationTok{\#\# Bootstrapping and rarefying to 9 elements (the number of Northern cities)}
+\NormalTok{eurodist\_bs }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(eurodist\_subsets, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{)}
-\CommentTok{\#\# Measuring disparity as the median distance from group\textquotesingle{}s centroid}
-\NormalTok{euro\_disp \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(eurodist\_bs, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids))}
+\DocumentationTok{\#\# Measuring disparity as the median distance from group\textquotesingle{}s centroid}
+\NormalTok{euro\_disp }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(eurodist\_bs, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids))}
-\CommentTok{\#\# Testing the differences using a simple wilcox.test}
-\NormalTok{euro\_diff \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test)}
-\NormalTok{euro\_diff\_rar \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{)}
+\DocumentationTok{\#\# Testing the differences using a simple wilcox.test}
+\NormalTok{euro\_diff }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test)}
+\NormalTok{euro\_diff\_rar }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -4996,17 +4797,17 @@ \section{Disparity from other matrices}\label{other-matrices}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Ordinating the eurodist matrix (with 11 dimensions)}
-\NormalTok{euro\_ord \textless{}{-}}\StringTok{ }\KeywordTok{cmdscale}\NormalTok{(eurodist, }\DataTypeTok{k =} \DecValTok{11}\NormalTok{)}
+\DocumentationTok{\#\# Ordinating the eurodist matrix (with 11 dimensions)}
+\NormalTok{euro\_ord }\OtherTok{\textless{}{-}} \FunctionTok{cmdscale}\NormalTok{(eurodist, }\AttributeTok{k =} \DecValTok{11}\NormalTok{)}
-\CommentTok{\#\# Calculating disparity on the bootstrapped and rarefied subset data}
-\NormalTok{euro\_ord\_disp \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(}\KeywordTok{custom.subsets}\NormalTok{(euro\_ord, }\DataTypeTok{group =}
- \KeywordTok{list}\NormalTok{(}\StringTok{"Northern"}\NormalTok{ =}\StringTok{ }\NormalTok{Northern, }\StringTok{"Southern"}\NormalTok{ =}\StringTok{ }\NormalTok{Southern)), }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{),}
- \DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids))}
+\DocumentationTok{\#\# Calculating disparity on the bootstrapped and rarefied subset data}
+\NormalTok{euro\_ord\_disp }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(}\FunctionTok{custom.subsets}\NormalTok{(euro\_ord, }\AttributeTok{group =}
+ \FunctionTok{list}\NormalTok{(}\StringTok{"Northern"} \OtherTok{=}\NormalTok{ Northern, }\StringTok{"Southern"} \OtherTok{=}\NormalTok{ Southern)), }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{),}
+ \AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids))}
-\CommentTok{\#\# Testing the differences using a simple wilcox.test}
-\NormalTok{euro\_ord\_diff \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test)}
-\NormalTok{euro\_ord\_diff\_rar \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{)}
+\DocumentationTok{\#\# Testing the differences using a simple wilcox.test}
+\NormalTok{euro\_ord\_diff }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test)}
+\NormalTok{euro\_ord\_diff\_rar }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(euro\_ord\_disp, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -5014,29 +4815,29 @@ \section{Disparity from other matrices}\label{other-matrices}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the differences}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the normal disparity}
-\KeywordTok{plot}\NormalTok{(euro\_disp, }\DataTypeTok{main =} \StringTok{"Distance differences"}\NormalTok{)}
-\CommentTok{\#\# Adding the p{-}value}
-\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{)))}
-\CommentTok{\#\# Plotting the rarefied disparity}
-\KeywordTok{plot}\NormalTok{(euro\_disp, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Distance differences (rarefied)"}\NormalTok{)}
-\CommentTok{\#\# Adding the p{-}value}
-\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{)))}
+\DocumentationTok{\#\# Plotting the differences}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the normal disparity}
+\FunctionTok{plot}\NormalTok{(euro\_disp, }\AttributeTok{main =} \StringTok{"Distance differences"}\NormalTok{)}
+\DocumentationTok{\#\# Adding the p{-}value}
+\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{)))}
+\DocumentationTok{\#\# Plotting the rarefied disparity}
+\FunctionTok{plot}\NormalTok{(euro\_disp, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\AttributeTok{main =} \StringTok{"Distance differences (rarefied)"}\NormalTok{)}
+\DocumentationTok{\#\# Adding the p{-}value}
+\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{4000}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{)))}
-\CommentTok{\#\# Plotting the ordinated disparity}
-\KeywordTok{plot}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{main =} \StringTok{"Ordinated differences"}\NormalTok{)}
-\CommentTok{\#\# Adding the p{-}value}
-\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_ord\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{) ))}
-\CommentTok{\#\# Plotting the rarefied disparity}
-\KeywordTok{plot}\NormalTok{(euro\_ord\_disp, }\DataTypeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Ordinated differences (rarefied)"}\NormalTok{)}
-\CommentTok{\#\# Adding the p{-}value}
-\KeywordTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\KeywordTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\KeywordTok{round}\NormalTok{(euro\_ord\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{5}\NormalTok{) ))}
+\DocumentationTok{\#\# Plotting the ordinated disparity}
+\FunctionTok{plot}\NormalTok{(euro\_ord\_disp, }\AttributeTok{main =} \StringTok{"Ordinated differences"}\NormalTok{)}
+\DocumentationTok{\#\# Adding the p{-}value}
+\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_ord\_diff[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{) ))}
+\DocumentationTok{\#\# Plotting the rarefied disparity}
+\FunctionTok{plot}\NormalTok{(euro\_ord\_disp, }\AttributeTok{rarefaction =} \DecValTok{9}\NormalTok{, }\AttributeTok{main =} \StringTok{"Ordinated differences (rarefied)"}\NormalTok{)}
+\DocumentationTok{\#\# Adding the p{-}value}
+\FunctionTok{text}\NormalTok{(}\FloatTok{1.5}\NormalTok{, }\DecValTok{1400}\NormalTok{, }\FunctionTok{paste0}\NormalTok{(}\StringTok{"p="}\NormalTok{,}\FunctionTok{round}\NormalTok{(euro\_ord\_diff\_rar[[}\DecValTok{2}\NormalTok{]][[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{5}\NormalTok{) ))}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-122-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-123-1.pdf}
As expected, the results are pretty similar in pattern but different in terms of scale.
The median centroids distance is expressed in km in the ``Distance differences'' plots and in Euclidean units of variation in the ``Ordinated differences'' plots.
@@ -5049,11 +4850,11 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...)}
-\NormalTok{matrix\_list \textless{}{-}}\StringTok{ }\KeywordTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{40}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(}\KeywordTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{))),}
- \DataTypeTok{simplify =} \OtherTok{FALSE}\NormalTok{)}
-\KeywordTok{class}\NormalTok{(matrix\_list) }\CommentTok{\# This is a list of matrices}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...)}
+\NormalTok{matrix\_list }\OtherTok{\textless{}{-}} \FunctionTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{40}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{4}\NormalTok{, }\AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(}\StringTok{"t"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{))),}
+ \AttributeTok{simplify =} \ConstantTok{FALSE}\NormalTok{)}
+\FunctionTok{class}\NormalTok{(matrix\_list) }\CommentTok{\# This is a list of matrices}
\end{Highlighting}
\end{Shaded}
@@ -5063,8 +4864,8 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring some disparity metric on one of the matrices}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(matrix\_list[[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\DocumentationTok{\#\# Measuring some disparity metric on one of the matrices}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(matrix\_list[[}\DecValTok{1}\NormalTok{]], }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5075,8 +4876,8 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the same disparity metric on the three matrices}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(matrix\_list, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\DocumentationTok{\#\# Measuring the same disparity metric on the three matrices}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(matrix\_list, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5094,23 +4895,23 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# Matches the trees and the matrices}
-\CommentTok{\#\# A bunch of trees}
-\NormalTok{make.tree \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(n, }\DataTypeTok{fun =}\NormalTok{ rtree) \{}
- \CommentTok{\#\# Make the tree}
-\NormalTok{ tree \textless{}{-}}\StringTok{ }\KeywordTok{fun}\NormalTok{(n)}
-\NormalTok{ tree \textless{}{-}}\StringTok{ }\KeywordTok{chronos}\NormalTok{(tree, }\DataTypeTok{quiet =} \OtherTok{TRUE}\NormalTok{,}
- \DataTypeTok{calibration =} \KeywordTok{makeChronosCalib}\NormalTok{(tree, }\DataTypeTok{age.min =} \DecValTok{10}\NormalTok{, }\DataTypeTok{age.max =} \DecValTok{10}\NormalTok{))}
- \KeywordTok{class}\NormalTok{(tree) \textless{}{-}}\StringTok{ "phylo"}
- \CommentTok{\#\# Add the node labels}
-\NormalTok{ tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\KeywordTok{Nnode}\NormalTok{(tree))}
- \CommentTok{\#\# Add the root time}
-\NormalTok{ tree}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{ages)}
- \KeywordTok{return}\NormalTok{(tree)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Matches the trees and the matrices}
+\DocumentationTok{\#\# A bunch of trees}
+\NormalTok{make.tree }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(n, }\AttributeTok{fun =}\NormalTok{ rtree) \{}
+ \DocumentationTok{\#\# Make the tree}
+\NormalTok{ tree }\OtherTok{\textless{}{-}} \FunctionTok{fun}\NormalTok{(n)}
+\NormalTok{ tree }\OtherTok{\textless{}{-}} \FunctionTok{chronos}\NormalTok{(tree, }\AttributeTok{quiet =} \ConstantTok{TRUE}\NormalTok{,}
+ \AttributeTok{calibration =} \FunctionTok{makeChronosCalib}\NormalTok{(tree, }\AttributeTok{age.min =} \DecValTok{10}\NormalTok{, }\AttributeTok{age.max =} \DecValTok{10}\NormalTok{))}
+ \FunctionTok{class}\NormalTok{(tree) }\OtherTok{\textless{}{-}} \StringTok{"phylo"}
+ \DocumentationTok{\#\# Add the node labels}
+\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Nnode}\NormalTok{(tree))}
+ \DocumentationTok{\#\# Add the root time}
+\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{ages)}
+ \FunctionTok{return}\NormalTok{(tree)}
\NormalTok{\}}
-\NormalTok{trees \textless{}{-}}\StringTok{ }\KeywordTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\KeywordTok{make.tree}\NormalTok{(}\DecValTok{10}\NormalTok{), }\DataTypeTok{simplify =} \OtherTok{FALSE}\NormalTok{)}
-\KeywordTok{class}\NormalTok{(trees) \textless{}{-}}\StringTok{ "multiPhylo"}
+\NormalTok{trees }\OtherTok{\textless{}{-}} \FunctionTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\FunctionTok{make.tree}\NormalTok{(}\DecValTok{10}\NormalTok{), }\AttributeTok{simplify =} \ConstantTok{FALSE}\NormalTok{)}
+\FunctionTok{class}\NormalTok{(trees) }\OtherTok{\textless{}{-}} \StringTok{"multiPhylo"}
\NormalTok{trees}
\end{Highlighting}
\end{Shaded}
@@ -5123,20 +4924,20 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A function for running the ancestral states estimations}
-\NormalTok{do.ace \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree, matrix) \{}
- \CommentTok{\#\# Run one ace}
-\NormalTok{ fun.ace \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(character, tree) \{}
-\NormalTok{ results \textless{}{-}}\StringTok{ }\KeywordTok{ace}\NormalTok{(character, }\DataTypeTok{phy =}\NormalTok{ tree)}\OperatorTok{$}\NormalTok{ace}
- \KeywordTok{names}\NormalTok{(results) \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\KeywordTok{Nnode}\NormalTok{(tree))}
- \KeywordTok{return}\NormalTok{(results)}
+\DocumentationTok{\#\# A function for running the ancestral states estimations}
+\NormalTok{do.ace }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree, matrix) \{}
+ \DocumentationTok{\#\# Run one ace}
+\NormalTok{ fun.ace }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(character, tree) \{}
+\NormalTok{ results }\OtherTok{\textless{}{-}} \FunctionTok{ace}\NormalTok{(character, }\AttributeTok{phy =}\NormalTok{ tree)}\SpecialCharTok{$}\NormalTok{ace}
+ \FunctionTok{names}\NormalTok{(results) }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Nnode}\NormalTok{(tree))}
+ \FunctionTok{return}\NormalTok{(results)}
\NormalTok{ \}}
- \CommentTok{\#\# Run all ace}
- \KeywordTok{return}\NormalTok{(}\KeywordTok{rbind}\NormalTok{(matrix, }\KeywordTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, fun.ace, }\DataTypeTok{tree =}\NormalTok{ tree)))}
+ \DocumentationTok{\#\# Run all ace}
+ \FunctionTok{return}\NormalTok{(}\FunctionTok{rbind}\NormalTok{(matrix, }\FunctionTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, fun.ace, }\AttributeTok{tree =}\NormalTok{ tree)))}
\NormalTok{\}}
-\CommentTok{\#\# All matrices}
-\NormalTok{matrices \textless{}{-}}\StringTok{ }\KeywordTok{mapply}\NormalTok{(do.ace, trees, matrix\_list, }\DataTypeTok{SIMPLIFY =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# All matrices}
+\NormalTok{matrices }\OtherTok{\textless{}{-}} \FunctionTok{mapply}\NormalTok{(do.ace, trees, matrix\_list, }\AttributeTok{SIMPLIFY =} \ConstantTok{FALSE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -5146,16 +4947,16 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Making three "proximity" time slices across one tree}
-\NormalTok{one\_tree \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees[[}\DecValTok{1}\NormalTok{]],}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{, }\DataTypeTok{time =} \DecValTok{3}\NormalTok{)}
-\CommentTok{\#\# Making three "proximity" time slices across the three trees}
-\NormalTok{three\_tree \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{, }\DataTypeTok{time =} \DecValTok{3}\NormalTok{)}
-\CommentTok{\#\# Measuring disparity as the sum of variances and summarising it}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(one\_tree, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\DocumentationTok{\#\# Making three "proximity" time slices across one tree}
+\NormalTok{one\_tree }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees[[}\DecValTok{1}\NormalTok{]],}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{, }\AttributeTok{time =} \DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Making three "proximity" time slices across the three trees}
+\NormalTok{three\_tree }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices[[}\DecValTok{1}\NormalTok{]], trees,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{, }\AttributeTok{time =} \DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Measuring disparity as the sum of variances and summarising it}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(one\_tree, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5168,7 +4969,7 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(three\_tree, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(three\_tree, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5183,19 +4984,19 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))}
-\NormalTok{slices \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\FloatTok{7.9}\NormalTok{, }\FloatTok{3.95}\NormalTok{, }\DecValTok{0}\NormalTok{)}
-\NormalTok{fun.plot \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree) \{}
- \KeywordTok{plot}\NormalTok{(tree)}
- \KeywordTok{nodelabels}\NormalTok{(tree}\OperatorTok{$}\NormalTok{node.label, }\DataTypeTok{cex =} \FloatTok{0.8}\NormalTok{)}
- \KeywordTok{axisPhylo}\NormalTok{()}
- \KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ tree}\OperatorTok{$}\NormalTok{root.time }\OperatorTok{{-}}\StringTok{ }\NormalTok{slices)}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))}
+\NormalTok{slices }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\FloatTok{7.9}\NormalTok{, }\FloatTok{3.95}\NormalTok{, }\DecValTok{0}\NormalTok{)}
+\NormalTok{fun.plot }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree) \{}
+ \FunctionTok{plot}\NormalTok{(tree)}
+ \FunctionTok{nodelabels}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{node.label, }\AttributeTok{cex =} \FloatTok{0.8}\NormalTok{)}
+ \FunctionTok{axisPhylo}\NormalTok{()}
+ \FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{root.time }\SpecialCharTok{{-}}\NormalTok{ slices)}
\NormalTok{\}}
-\NormalTok{silent \textless{}{-}}\StringTok{ }\KeywordTok{lapply}\NormalTok{(trees, fun.plot)}
+\NormalTok{silent }\OtherTok{\textless{}{-}} \FunctionTok{lapply}\NormalTok{(trees, fun.plot)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-127-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-128-1.pdf}
Note that in this example, the nodes are actually even different in each tree! The node \texttt{n4} for example, is not direct descendent of \texttt{t4} and \texttt{t6} in all trees!
To fix that, it is possible to input a list of trees and a list of matrices that correspond to each tree in \texttt{chrono.subsets} by using the \texttt{bind.data\ =\ TRUE} option.
@@ -5203,21 +5004,21 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Making three "proximity" time slices across three trees and three bound matrices}
-\NormalTok{bound\_data \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices, trees,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{3}\NormalTok{,}
- \DataTypeTok{bind.data =} \OtherTok{TRUE}\NormalTok{)}
-\CommentTok{\#\# Making three "proximity" time slices across three trees and three matrices}
-\NormalTok{unbound\_data \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(matrices, trees,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"proximity"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{3}\NormalTok{,}
- \DataTypeTok{bind.data =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Making three "proximity" time slices across three trees and three bound matrices}
+\NormalTok{bound\_data }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices, trees,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{3}\NormalTok{,}
+ \AttributeTok{bind.data =} \ConstantTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Making three "proximity" time slices across three trees and three matrices}
+\NormalTok{unbound\_data }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(matrices, trees,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"proximity"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{3}\NormalTok{,}
+ \AttributeTok{bind.data =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# Measuring disparity as the sum of variances and summarising it}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(bound\_data, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\DocumentationTok{\#\# Measuring disparity as the sum of variances and summarising it}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(bound\_data, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5230,7 +5031,7 @@ \section{Disparity from multiple matrices (and multiple trees!)}\label{multi.inp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(unbound\_data, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, variances)))}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(unbound\_data, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5265,34 +5066,34 @@ \section{\texorpdfstring{Disparity with trees: \emph{dispRitree!}}{Disparity wit
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading some demo data:}
-\CommentTok{\#\# An ordinated matrix with node and tip labels}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat99)}
-\CommentTok{\#\# The corresponding tree with tip and node labels}
-\KeywordTok{data}\NormalTok{(BeckLee\_tree)}
-\CommentTok{\#\# A list of tips ages for the fossil data}
-\KeywordTok{data}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Loading some demo data:}
+\DocumentationTok{\#\# An ordinated matrix with node and tip labels}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat99)}
+\DocumentationTok{\#\# The corresponding tree with tip and node labels}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree)}
+\DocumentationTok{\#\# A list of tips ages for the fossil data}
+\FunctionTok{data}\NormalTok{(BeckLee\_ages)}
-\CommentTok{\#\# Time slicing through the tree using the equal split algorithm}
-\NormalTok{time\_slices \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99,}
- \DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages,}
- \DataTypeTok{method =} \StringTok{"continuous"}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"acctran"}\NormalTok{,}
- \DataTypeTok{time =} \DecValTok{15}\NormalTok{)}
+\DocumentationTok{\#\# Time slicing through the tree using the equal split algorithm}
+\NormalTok{time\_slices }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99,}
+ \AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages,}
+ \AttributeTok{method =} \StringTok{"continuous"}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"acctran"}\NormalTok{,}
+ \AttributeTok{time =} \DecValTok{15}\NormalTok{)}
-\CommentTok{\#\# We can visualise the resulting trait space with the phylogeny}
-\CommentTok{\#\# (using the specific argument as follows)}
-\KeywordTok{plot}\NormalTok{(time\_slices, }\DataTypeTok{type =} \StringTok{"preview"}\NormalTok{,}
- \DataTypeTok{specific.args =} \KeywordTok{list}\NormalTok{(}\DataTypeTok{tree =} \OtherTok{TRUE}\NormalTok{))}
+\DocumentationTok{\#\# We can visualise the resulting trait space with the phylogeny}
+\DocumentationTok{\#\# (using the specific argument as follows)}
+\FunctionTok{plot}\NormalTok{(time\_slices, }\AttributeTok{type =} \StringTok{"preview"}\NormalTok{,}
+ \AttributeTok{specific.args =} \FunctionTok{list}\NormalTok{(}\AttributeTok{tree =} \ConstantTok{TRUE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-129-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-130-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Note that some nodes are never selected thus explaining the branches not reaching them.}
+\DocumentationTok{\#\# Note that some nodes are never selected thus explaining the branches not reaching them.}
\end{Highlighting}
\end{Shaded}
@@ -5300,10 +5101,10 @@ \section{\texorpdfstring{Disparity with trees: \emph{dispRitree!}}{Disparity wit
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the sum of the edge length per slice}
-\NormalTok{sum\_edge\_length \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(time\_slices), }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, edge.length.tree))}
-\CommentTok{\#\# Summarising and plotting}
-\KeywordTok{summary}\NormalTok{(sum\_edge\_length)}
+\DocumentationTok{\#\# Measuring the sum of the edge length per slice}
+\NormalTok{sum\_edge\_length }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(time\_slices), }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, edge.length.tree))}
+\DocumentationTok{\#\# Summarising and plotting}
+\FunctionTok{summary}\NormalTok{(sum\_edge\_length)}
\end{Highlighting}
\end{Shaded}
@@ -5328,11 +5129,11 @@ \section{\texorpdfstring{Disparity with trees: \emph{dispRitree!}}{Disparity wit
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{plot}\NormalTok{(sum\_edge\_length)}
+\FunctionTok{plot}\NormalTok{(sum\_edge\_length)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-130-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-131-1.pdf}
Of course this can be done with multiple trees and be combined with an approach using multiple matrices (see \protect\hyperlink{multi.input}{here})!
@@ -5347,6 +5148,7 @@ \section{Disparity of variance-covariance matrices (covar)}\label{covar}}
You can then analyse this data using a glmm with something like \texttt{my\_data\ \textasciitilde{}\ observations\ +\ phylogeny\ +\ redisduals}.
For more info on these models \href{https://en.wikipedia.org/wiki/Generalized_linear_mixed_model}{start here}.
For more details on running these models, I suggest using the \texttt{MCMCglmm} package (\citet{MCMCglmm}) from \citet{hadfield2010} (but see also \citet{mulTree}).
+For an example use of this code, see \citet{guillerme2023innovation}.
\hypertarget{creating-a-disprity-object-with-a-covar-component}{%
\subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\$covar} component}{Creating a dispRity object with a \$covar component}}\label{creating-a-disprity-object-with-a-covar-component}}
@@ -5355,8 +5157,8 @@ \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the charadriiformes data}
-\KeywordTok{data}\NormalTok{(charadriiformes)}
+\DocumentationTok{\#\# Loading the charadriiformes data}
+\FunctionTok{data}\NormalTok{(charadriiformes)}
\end{Highlighting}
\end{Shaded}
@@ -5366,14 +5168,14 @@ \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The term names}
-\NormalTok{model\_terms \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{posteriors)[}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{]}
-\CommentTok{\#\# Note that we\textquotesingle{}re ignoring the 5th term of the model that\textquotesingle{}s just the normal residuals}
+\DocumentationTok{\#\# The term names}
+\NormalTok{model\_terms }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors)[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{]}
+\DocumentationTok{\#\# Note that we\textquotesingle{}re ignoring the 5th term of the model that\textquotesingle{}s just the normal residuals}
-\CommentTok{\#\# The dispRity object}
-\KeywordTok{MCMCglmm.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{data,}
- \DataTypeTok{posteriors =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{posteriors,}
- \DataTypeTok{group =}\NormalTok{ model\_terms)}
+\DocumentationTok{\#\# The dispRity object}
+\FunctionTok{MCMCglmm.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data,}
+ \AttributeTok{posteriors =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors,}
+ \AttributeTok{group =}\NormalTok{ model\_terms)}
\end{Highlighting}
\end{Shaded}
@@ -5389,13 +5191,13 @@ \subsection{\texorpdfstring{Creating a \texttt{dispRity} object with a \texttt{\
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A fancier dispRity object}
-\NormalTok{my\_covar \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{data,}
- \DataTypeTok{posteriors =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{posteriors,}
- \DataTypeTok{group =}\NormalTok{ model\_terms,}
- \DataTypeTok{tree =}\NormalTok{ charadriiformes}\OperatorTok{$}\NormalTok{tree,}
- \DataTypeTok{rename.groups =} \KeywordTok{c}\NormalTok{(}\KeywordTok{levels}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{data}\OperatorTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))}
-\CommentTok{\#\# Note that the group names is contained in the clade column of the charadriiformes dataset as factors}
+\DocumentationTok{\#\# A fancier dispRity object}
+\NormalTok{my\_covar }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data,}
+ \AttributeTok{posteriors =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors,}
+ \AttributeTok{group =}\NormalTok{ model\_terms,}
+ \AttributeTok{tree =}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{tree,}
+ \AttributeTok{rename.groups =} \FunctionTok{c}\NormalTok{(}\FunctionTok{levels}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{data}\SpecialCharTok{$}\NormalTok{clade), }\StringTok{"phylogeny"}\NormalTok{))}
+\DocumentationTok{\#\# Note that the group names is contained in the clade column of the charadriiformes dataset as factors}
\end{Highlighting}
\end{Shaded}
@@ -5408,22 +5210,22 @@ \subsection{Visualising covar objects}\label{visualising-covar-objects}}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\CommentTok{\#\# The traitspace}
-\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Trait space"}\NormalTok{)}
-\CommentTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses}
-\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Mean VCV ellipses"}\NormalTok{,}
- \DataTypeTok{points =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{ellipses =}\NormalTok{ mean) }
-\CommentTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses}
-\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Mean major axes"}\NormalTok{,}
- \DataTypeTok{points =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{major.axes =}\NormalTok{ mean)}
-\CommentTok{\#\# A bit of everything}
-\KeywordTok{covar.plot}\NormalTok{(my\_covar, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Ten random VCV matrices"}\NormalTok{,}
- \DataTypeTok{points =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{major.axes =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{points.cex =} \DecValTok{1}\OperatorTok{/}\DecValTok{3}\NormalTok{, }\DataTypeTok{n =} \DecValTok{10}\NormalTok{, }\DataTypeTok{ellipses =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{legend =} \OtherTok{TRUE}\NormalTok{)}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# The traitspace}
+\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Trait space"}\NormalTok{)}
+\DocumentationTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses}
+\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Mean VCV ellipses"}\NormalTok{,}
+ \AttributeTok{points =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{ellipses =}\NormalTok{ mean) }
+\DocumentationTok{\#\# The traitspace\textquotesingle{}s variance{-}covariance mean ellipses}
+\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Mean major axes"}\NormalTok{,}
+ \AttributeTok{points =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{major.axes =}\NormalTok{ mean)}
+\DocumentationTok{\#\# A bit of everything}
+\FunctionTok{covar.plot}\NormalTok{(my\_covar, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"grey"}\NormalTok{), }\AttributeTok{main =} \StringTok{"Ten random VCV matrices"}\NormalTok{,}
+ \AttributeTok{points =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{major.axes =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{points.cex =} \DecValTok{1}\SpecialCharTok{/}\DecValTok{3}\NormalTok{, }\AttributeTok{n =} \DecValTok{10}\NormalTok{, }\AttributeTok{ellipses =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{legend =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-134-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-135-1.pdf}
\hypertarget{disparity-analyses-with-a-covar-component}{%
\subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component}{Disparity analyses with a \$covar component}}\label{disparity-analyses-with-a-covar-component}}
@@ -5433,7 +5235,7 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(my\_covar, }\DataTypeTok{metric =}\NormalTok{ variances))}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(my\_covar, }\AttributeTok{metric =}\NormalTok{ variances))}
\end{Highlighting}
\end{Shaded}
@@ -5452,8 +5254,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The first variance covariance matrix for the "gulls" group}
-\NormalTok{my\_covar}\OperatorTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]}
+\DocumentationTok{\#\# The first variance covariance matrix for the "gulls" group}
+\NormalTok{my\_covar}\SpecialCharTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]}
\end{Highlighting}
\end{Shaded}
@@ -5472,8 +5274,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Using the variances function on a VCV matrix}
-\KeywordTok{variances}\NormalTok{(my\_covar}\OperatorTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]}\OperatorTok{$}\NormalTok{VCV)}
+\DocumentationTok{\#\# Using the variances function on a VCV matrix}
+\FunctionTok{variances}\NormalTok{(my\_covar}\SpecialCharTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{VCV)}
\end{Highlighting}
\end{Shaded}
@@ -5483,8 +5285,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The same but using it as a covar metric}
-\KeywordTok{as.covar}\NormalTok{(variances)(my\_covar}\OperatorTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]])}
+\DocumentationTok{\#\# The same but using it as a covar metric}
+\FunctionTok{as.covar}\NormalTok{(variances)(my\_covar}\SpecialCharTok{$}\NormalTok{covar[[}\StringTok{"gulls"}\NormalTok{]][[}\DecValTok{1}\NormalTok{]])}
\end{Highlighting}
\end{Shaded}
@@ -5494,8 +5296,8 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The same but applied to the dispRity function}
-\KeywordTok{summary}\NormalTok{(}\KeywordTok{dispRity}\NormalTok{(my\_covar, }\DataTypeTok{metric =} \KeywordTok{as.covar}\NormalTok{(variances)))}
+\DocumentationTok{\#\# The same but applied to the dispRity function}
+\FunctionTok{summary}\NormalTok{(}\FunctionTok{dispRity}\NormalTok{(my\_covar, }\AttributeTok{metric =} \FunctionTok{as.covar}\NormalTok{(variances)))}
\end{Highlighting}
\end{Shaded}
@@ -5507,6 +5309,176 @@ \subsection{\texorpdfstring{Disparity analyses with a \texttt{\$covar} component
## 4 phylogeny 359 0.000 0 0 0.006 0.020
\end{verbatim}
+\hypertarget{disparity-and-distances}{%
+\section{Disparity and distances}\label{disparity-and-distances}}
+
+There are two ways to use distances in \texttt{dispRity}, either with your input data being directly a distance matrix or with your disparity metric involving some kind of distance calculations.
+
+\hypertarget{disparity-data-is-a-distance}{%
+\subsection{Disparity data is a distance}\label{disparity-data-is-a-distance}}
+
+If your disparity data is a distance matrix, you can use the option \texttt{dist.data\ =\ TRUE} in \texttt{dispRity} to make sure that all the operations done on your data take into account the fact that your disparity data has distance properties.
+For example, if you bootstrap the data, this will automatically bootstrap both rows AND columns (i.e.~so that the bootstrapped matrices are still distances).
+This also improves speed on some calculations if you use \protect\hyperlink{disparity-metrics}{disparity metrics} directly implemented in the package by avoiding recalculating distances (the full list can be seen in \texttt{?dispRity.metric} - they are usually the metrics with \texttt{dist} in their name).
+
+\hypertarget{subsets}{%
+\subsubsection{Subsets}\label{subsets}}
+
+By default, the \texttt{dispRity} package does not treat any matrix as a distance matrix.
+It will however try to guess whether your input data is a distance matrix or not.
+This means that if you input a distance matrix, you might get a warning letting you know the input matrix might not be treated correctly (e.g.~when bootstrapping or subsetting).
+For the functions \texttt{dispRity}, \texttt{custom.subsets} and \texttt{chrono.subsets} you can simply toggle the option \texttt{dist.data\ =\ TRUE} to make sure you treat your input data as a distance matrix throughout your analysis.
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Creating a distance matrix}
+\NormalTok{distance\_data }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(BeckLee\_mat50))}
+
+\DocumentationTok{\#\# Measuring the diagonal of the distance matrix}
+\FunctionTok{dispRity}\NormalTok{(distance\_data, }\AttributeTok{metric =}\NormalTok{ diag, }\AttributeTok{dist.data =} \ConstantTok{TRUE}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## ---- dispRity object ----
+## 50 elements in one matrix with 50 dimensions.
+## Disparity was calculated as: diag.
+\end{verbatim}
+
+If you use a pipeline of any of these functions, you only need to specify it once and the data will be treated as a distance matrix throughout.
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Creating a distance matrix}
+\NormalTok{distance\_data }\OtherTok{\textless{}{-}} \FunctionTok{as.matrix}\NormalTok{(}\FunctionTok{dist}\NormalTok{(BeckLee\_mat50))}
+
+\DocumentationTok{\#\# Creating two subsets specifying that the data is a distance matrix}
+\NormalTok{subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(distance\_data, }\AttributeTok{group =} \FunctionTok{list}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{), }\FunctionTok{c}\NormalTok{(}\DecValTok{6}\SpecialCharTok{:}\DecValTok{10}\NormalTok{)), }\AttributeTok{dist.data =} \ConstantTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Measuring disparity treating the data as distance matrices}
+\FunctionTok{dispRity}\NormalTok{(subsets, }\AttributeTok{metric =}\NormalTok{ diag)}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## ---- dispRity object ----
+## 2 customised subsets for 50 elements in one matrix with 50 dimensions:
+## 1, 2.
+## Disparity was calculated as: diag.
+\end{verbatim}
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Measuring disparity treating the data as a normal matrix (toggling the option to FALSE)}
+\FunctionTok{dispRity}\NormalTok{(subsets, }\AttributeTok{metric =}\NormalTok{ diag, }\AttributeTok{dist.data =} \ConstantTok{FALSE}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## Warning in dispRity(subsets, metric = diag, dist.data = FALSE): data.dist is
+## set to FALSE (the data will not be treated as a distance matrix) even though
+## subsets contains distance treated data.
+\end{verbatim}
+
+\begin{verbatim}
+## ---- dispRity object ----
+## 2 customised subsets for 50 elements in one matrix with 50 dimensions:
+## 1, 2.
+## Disparity was calculated as: diag.
+\end{verbatim}
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Note that a warning appears but the function still runs}
+\end{Highlighting}
+\end{Shaded}
+
+\hypertarget{bootstrapping}{%
+\subsubsection{Bootstrapping}\label{bootstrapping}}
+
+The function \texttt{boot.matrix} also can deal with distance matrices by bootstrapping both rows and columns in a linked way (e.g.~if a bootstrap pseudo-replicate draws the values 1, 2, and 5, it will select both columns 1, 2, and 5 and rows 1, 2, and 5 - keeping the distance structure of the data).
+You can do that by using the \texttt{boot.by\ =\ "dist"} function that will bootstrap the data in a distance matrix fashion:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Measuring the diagonal of a bootstrapped matrix}
+\FunctionTok{boot.matrix}\NormalTok{(distance\_data, }\AttributeTok{boot.by =} \StringTok{"dist"}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## ---- dispRity object ----
+## 50 elements in one matrix with 50 dimensions.
+## Rows and columns were bootstrapped 100 times (method:"full").
+\end{verbatim}
+
+Similarly to the \texttt{dispRity}, \texttt{custom.subsets} and \texttt{chrono.subsets} function above, the option to treat the input data as a distance matrix is recorded and recycled so there is no need to specify it each time.
+
+\hypertarget{disparity-metric-is-a-distance}{%
+\subsection{Disparity metric is a distance}\label{disparity-metric-is-a-distance}}
+
+On the other hand if your data is not a distance matrix but you are using a metric that uses some kind of distance calculations, you can use the option \texttt{dist.helper} to greatly speed up calculations.
+\texttt{dist.helper} can be either a pre-calculated distance matrix (or a list of distance matrices) or, better yet, a function to calculate distance matrices, like \texttt{stats::dist} or \texttt{vegan::vegdist}.
+This option directly stores the distance matrix separately in the RAM and allows the disparity metric to directly access it at every disparity calculation iteration, making it much faster.
+Note that if you provide a function for \texttt{dist.helper}, you can also provide any un-ambiguous optional argument to that function, for example \texttt{method\ =\ "euclidean"}.
+
+If you use a disparity metric implemented in \texttt{dispRity}, the \texttt{dist.helper} option is correctly loaded onto the RAM regardless of the argument you provide (a matrix, a list of matrix or any function to calculate a distance matrix).
+On the other hand, if you use your own function for the disparity metric, make sure that \texttt{dist.helper} exactly matches the internal distance calculation function.
+For example if you use the already implemented \texttt{pairwise.dist} metric all the following options will be using \texttt{dist.helper} optimally:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Using the dist function from stats (specifying it comes from stats)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ stats}\SpecialCharTok{::}\NormalTok{dist)}
+
+\DocumentationTok{\#\# Using the dist function from vegdist function (without specifying its origin)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ vegdist)}
+
+\DocumentationTok{\#\# Using some pre{-}calculated distance with a generic function}
+\NormalTok{my\_distance\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{dist}\NormalTok{(my\_distance\_data)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ my\_distance\_matrix)}
+
+\DocumentationTok{\#\# Using some pre{-}calculated distance with a user function defined elsewhere}
+\NormalTok{my\_distance\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{my.personalised.function}\NormalTok{(my\_distance\_data)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ pairwise.dist, }\AttributeTok{dist.helper =}\NormalTok{ my\_distance\_matrix)}
+\end{Highlighting}
+\end{Shaded}
+
+However, if you use a homemade metric for calculating distances like this:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# a personalised distance function}
+\NormalTok{my.sum.of.dist }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) \{}
+ \FunctionTok{return}\NormalTok{(}\FunctionTok{sum}\NormalTok{(}\FunctionTok{dist}\NormalTok{(matrix)))}
+\NormalTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+The \texttt{dist.helper} will only work if you specify the function using the same syntax as in the user function:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# The following uses the helper correctly (as in saves a lot of calculation time)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =}\NormalTok{ dist)}
+
+\DocumentationTok{\#\# These ones however, work but don\textquotesingle{}t use the dist.helper (don\textquotesingle{}t save time)}
+\DocumentationTok{\#\# The dist.helper is not a function}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =} \FunctionTok{dist}\NormalTok{(my\_data))}
+\DocumentationTok{\#\# The dist.helper is not the correct function (should be dist)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =}\NormalTok{ vegdist)}
+\DocumentationTok{\#\# The dist.helper is not the correct function (should be just dist)}
+\FunctionTok{dispRity}\NormalTok{(my\_data, }\AttributeTok{metric =}\NormalTok{ my.sum.of.dist, }\AttributeTok{dist.helper =}\NormalTok{ stats}\SpecialCharTok{::}\NormalTok{dist)}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{Shaded}
+\begin{Highlighting}[]
+ \FunctionTok{expect\_equal}\NormalTok{(}\FunctionTok{summary}\NormalTok{(test)}\SpecialCharTok{$}\NormalTok{obs.median, }\DecValTok{0}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
+--\textgreater{}
+
\hypertarget{making-stuff-up}{%
\chapter{Making stuff up!}\label{making-stuff-up}}
@@ -5526,18 +5498,18 @@ \section{Simulating discrete morphological data}\label{simulating-discrete-morph
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{3}\NormalTok{)}
-\CommentTok{\#\# Simulating a starting tree with 15 taxa as a random coalescent tree}
-\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Simulating a starting tree with 15 taxa as a random coalescent tree}
+\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)}
-\CommentTok{\#\# Generating a matrix with 100 characters (85\% binary and 15\% three state) and}
-\CommentTok{\#\# an equal rates model with a gamma rate distribution (0.5, 1) with no }
-\CommentTok{\#\# invariant characters.}
-\NormalTok{my\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(}\DataTypeTok{tree =}\NormalTok{ my\_tree, }\DataTypeTok{characters =} \DecValTok{100}\NormalTok{, }\DataTypeTok{states =} \KeywordTok{c}\NormalTok{(}\FloatTok{0.85}\NormalTok{,}
- \FloatTok{0.15}\NormalTok{), }\DataTypeTok{rates =} \KeywordTok{c}\NormalTok{(rgamma, }\FloatTok{0.5}\NormalTok{, }\DecValTok{1}\NormalTok{), }\DataTypeTok{invariant =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Generating a matrix with 100 characters (85\% binary and 15\% three state) and}
+\DocumentationTok{\#\# an equal rates model with a gamma rate distribution (0.5, 1) with no }
+\DocumentationTok{\#\# invariant characters.}
+\NormalTok{my\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(}\AttributeTok{tree =}\NormalTok{ my\_tree, }\AttributeTok{characters =} \DecValTok{100}\NormalTok{, }\AttributeTok{states =} \FunctionTok{c}\NormalTok{(}\FloatTok{0.85}\NormalTok{,}
+ \FloatTok{0.15}\NormalTok{), }\AttributeTok{rates =} \FunctionTok{c}\NormalTok{(rgamma, }\FloatTok{0.5}\NormalTok{, }\DecValTok{1}\NormalTok{), }\AttributeTok{invariant =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# The first few lines of the matrix}
-\NormalTok{my\_matrix[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]}
+\DocumentationTok{\#\# The first few lines of the matrix}
+\NormalTok{my\_matrix[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
@@ -5552,8 +5524,8 @@ \section{Simulating discrete morphological data}\label{simulating-discrete-morph
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Checking the matrix properties with a quick Maximum Parsimony tree search}
-\KeywordTok{check.morpho}\NormalTok{(my\_matrix, my\_tree)}
+\DocumentationTok{\#\# Checking the matrix properties with a quick Maximum Parsimony tree search}
+\FunctionTok{check.morpho}\NormalTok{(my\_matrix, my\_tree)}
\end{Highlighting}
\end{Shaded}
@@ -5650,13 +5622,13 @@ \subsubsection{Adding inapplicable characters}\label{adding-inapplicable-charact
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Generating 5 "character" NAs and 10 "clade" NAs}
-\NormalTok{my\_matrix\_NA \textless{}{-}}\StringTok{ }\KeywordTok{apply.NA}\NormalTok{(my\_matrix, }\DataTypeTok{tree =}\NormalTok{ my\_tree,}
- \DataTypeTok{NAs =} \KeywordTok{c}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\StringTok{"character"}\NormalTok{, }\DecValTok{5}\NormalTok{),}
- \KeywordTok{rep}\NormalTok{(}\StringTok{"clade"}\NormalTok{, }\DecValTok{10}\NormalTok{)))}
+\DocumentationTok{\#\# Generating 5 "character" NAs and 10 "clade" NAs}
+\NormalTok{my\_matrix\_NA }\OtherTok{\textless{}{-}} \FunctionTok{apply.NA}\NormalTok{(my\_matrix, }\AttributeTok{tree =}\NormalTok{ my\_tree,}
+ \AttributeTok{NAs =} \FunctionTok{c}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\StringTok{"character"}\NormalTok{, }\DecValTok{5}\NormalTok{),}
+ \FunctionTok{rep}\NormalTok{(}\StringTok{"clade"}\NormalTok{, }\DecValTok{10}\NormalTok{)))}
-\CommentTok{\#\# The first few lines of the resulting matrix}
-\NormalTok{my\_matrix\_NA[}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{90}\OperatorTok{:}\DecValTok{100}\NormalTok{]}
+\DocumentationTok{\#\# The first few lines of the resulting matrix}
+\NormalTok{my\_matrix\_NA[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{90}\SpecialCharTok{:}\DecValTok{100}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
@@ -5682,16 +5654,16 @@ \subsection{Parameters for a realistic(ish) matrix}\label{parameters-for-a-reali
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{0}\NormalTok{)}
-\CommentTok{\#\# tree}
-\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)}
-\CommentTok{\#\# matrix}
-\NormalTok{morpho\_mat \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(my\_tree,}
- \DataTypeTok{characters =} \DecValTok{100}\NormalTok{,}
- \DataTypeTok{model =} \StringTok{"ER"}\NormalTok{,}
- \DataTypeTok{rates =} \KeywordTok{c}\NormalTok{(rgamma, }\DataTypeTok{rate =} \DecValTok{100}\NormalTok{, }\DataTypeTok{shape =} \DecValTok{5}\NormalTok{),}
- \DataTypeTok{invariant =} \OtherTok{FALSE}\NormalTok{)}
-\KeywordTok{check.morpho}\NormalTok{(morpho\_mat, my\_tree)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{0}\NormalTok{)}
+\DocumentationTok{\#\# tree}
+\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{)}
+\DocumentationTok{\#\# matrix}
+\NormalTok{morpho\_mat }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(my\_tree,}
+ \AttributeTok{characters =} \DecValTok{100}\NormalTok{,}
+ \AttributeTok{model =} \StringTok{"ER"}\NormalTok{,}
+ \AttributeTok{rates =} \FunctionTok{c}\NormalTok{(rgamma, }\AttributeTok{rate =} \DecValTok{100}\NormalTok{, }\AttributeTok{shape =} \DecValTok{5}\NormalTok{),}
+ \AttributeTok{invariant =} \ConstantTok{FALSE}\NormalTok{)}
+\FunctionTok{check.morpho}\NormalTok{(morpho\_mat, my\_tree)}
\end{Highlighting}
\end{Shaded}
@@ -5723,14 +5695,14 @@ \section{Simulating multidimensional spaces}\label{simulating-multidimensional-s
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# A square space}
-\NormalTok{square\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)}
+\DocumentationTok{\#\# A square space}
+\NormalTok{square\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{100}\NormalTok{, }\DecValTok{2}\NormalTok{, runif)}
-\CommentTok{\#\# The resulting 2D matrix}
-\KeywordTok{head}\NormalTok{(square\_space)}
+\DocumentationTok{\#\# The resulting 2D matrix}
+\FunctionTok{head}\NormalTok{(square\_space)}
\end{Highlighting}
\end{Shaded}
@@ -5746,25 +5718,25 @@ \section{Simulating multidimensional spaces}\label{simulating-multidimensional-s
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Visualising the space}
-\KeywordTok{plot}\NormalTok{(square\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Uniform 2D space"}\NormalTok{)}
+\DocumentationTok{\#\# Visualising the space}
+\FunctionTok{plot}\NormalTok{(square\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Uniform 2D space"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-141-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-149-1.pdf}
Of course, more complex spaces can be created by changing the distributions, their arguments or adding a correlation matrix or a cumulative variance vector:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A plane space: uniform with one dimensions equal to 0}
-\NormalTok{plane\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\KeywordTok{c}\NormalTok{(runif, runif, runif),}
- \DataTypeTok{arguments =} \KeywordTok{list}\NormalTok{(}\KeywordTok{list}\NormalTok{(}\DataTypeTok{min =} \DecValTok{0}\NormalTok{, }\DataTypeTok{max =} \DecValTok{0}\NormalTok{),}
- \OtherTok{NULL}\NormalTok{, }\OtherTok{NULL}\NormalTok{))}
+\DocumentationTok{\#\# A plane space: uniform with one dimensions equal to 0}
+\NormalTok{plane\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\FunctionTok{c}\NormalTok{(runif, runif, runif),}
+ \AttributeTok{arguments =} \FunctionTok{list}\NormalTok{(}\FunctionTok{list}\NormalTok{(}\AttributeTok{min =} \DecValTok{0}\NormalTok{, }\AttributeTok{max =} \DecValTok{0}\NormalTok{),}
+ \ConstantTok{NULL}\NormalTok{, }\ConstantTok{NULL}\NormalTok{))}
-\CommentTok{\#\# Correlation matrix for a 3D space}
-\NormalTok{(cor\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{cbind}\NormalTok{(}\DecValTok{1}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\DecValTok{1}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\DecValTok{1}\NormalTok{), }\DataTypeTok{nrow =} \DecValTok{3}\NormalTok{))}
+\DocumentationTok{\#\# Correlation matrix for a 3D space}
+\NormalTok{(cor\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{cbind}\NormalTok{(}\DecValTok{1}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.8}\NormalTok{, }\DecValTok{1}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.7}\NormalTok{, }\DecValTok{1}\NormalTok{), }\AttributeTok{nrow =} \DecValTok{3}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -5777,13 +5749,13 @@ \section{Simulating multidimensional spaces}\label{simulating-multidimensional-s
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# An ellipsoid space (normal space with correlation)}
-\NormalTok{ellipse\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, rnorm,}
- \DataTypeTok{cor.matrix =}\NormalTok{ cor\_matrix)}
+\DocumentationTok{\#\# An ellipsoid space (normal space with correlation)}
+\NormalTok{ellipse\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, rnorm,}
+ \AttributeTok{cor.matrix =}\NormalTok{ cor\_matrix)}
-\CommentTok{\#\# A cylindrical space with decreasing axes variance}
-\NormalTok{cylindrical\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\KeywordTok{c}\NormalTok{(rnorm, rnorm, runif),}
- \DataTypeTok{scree =} \KeywordTok{c}\NormalTok{(}\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.1}\NormalTok{))}
+\DocumentationTok{\#\# A cylindrical space with decreasing axes variance}
+\NormalTok{cylindrical\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{2500}\NormalTok{, }\DecValTok{3}\NormalTok{, }\FunctionTok{c}\NormalTok{(rnorm, rnorm, runif),}
+ \AttributeTok{scree =} \FunctionTok{c}\NormalTok{(}\FloatTok{0.7}\NormalTok{, }\FloatTok{0.2}\NormalTok{, }\FloatTok{0.1}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -5798,25 +5770,25 @@ \subsection{Personalised dimensions distributions}\label{personalised-dimensions
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Generating coordinates for a normal circle with a upper boundary of 1}
-\NormalTok{circle \textless{}{-}}\StringTok{ }\KeywordTok{random.circle}\NormalTok{(}\DecValTok{1000}\NormalTok{, rnorm, }\DataTypeTok{inner =} \DecValTok{0}\NormalTok{, }\DataTypeTok{outer =} \DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Generating coordinates for a normal circle with a upper boundary of 1}
+\NormalTok{circle }\OtherTok{\textless{}{-}} \FunctionTok{random.circle}\NormalTok{(}\DecValTok{1000}\NormalTok{, rnorm, }\AttributeTok{inner =} \DecValTok{0}\NormalTok{, }\AttributeTok{outer =} \DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# Plotting the circle}
-\KeywordTok{plot}\NormalTok{(circle, }\DataTypeTok{xlab =} \StringTok{"x"}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{"y"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"A normal circle"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the circle}
+\FunctionTok{plot}\NormalTok{(circle, }\AttributeTok{xlab =} \StringTok{"x"}\NormalTok{, }\AttributeTok{ylab =} \StringTok{"y"}\NormalTok{, }\AttributeTok{main =} \StringTok{"A normal circle"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-143-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-151-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating doughnut space (a spherical space with a hole)}
-\NormalTok{doughnut\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{5000}\NormalTok{, }\DecValTok{3}\NormalTok{, }\KeywordTok{c}\NormalTok{(rnorm, random.circle),}
- \DataTypeTok{arguments =} \KeywordTok{list}\NormalTok{(}\KeywordTok{list}\NormalTok{(}\DataTypeTok{mean =} \DecValTok{0}\NormalTok{),}
- \KeywordTok{list}\NormalTok{(runif, }\DataTypeTok{inner =} \FloatTok{0.5}\NormalTok{, }\DataTypeTok{outer =} \DecValTok{1}\NormalTok{)))}
+\DocumentationTok{\#\# Creating doughnut space (a spherical space with a hole)}
+\NormalTok{doughnut\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{5000}\NormalTok{, }\DecValTok{3}\NormalTok{, }\FunctionTok{c}\NormalTok{(rnorm, random.circle),}
+ \AttributeTok{arguments =} \FunctionTok{list}\NormalTok{(}\FunctionTok{list}\NormalTok{(}\AttributeTok{mean =} \DecValTok{0}\NormalTok{),}
+ \FunctionTok{list}\NormalTok{(runif, }\AttributeTok{inner =} \FloatTok{0.5}\NormalTok{, }\AttributeTok{outer =} \DecValTok{1}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -5827,10 +5799,10 @@ \subsection{Visualising the space}\label{visualising-the-space}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =}\NormalTok{ (}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Visualising 3D spaces}
-\KeywordTok{require}\NormalTok{(scatterplot3d)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =}\NormalTok{ (}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Visualising 3D spaces}
+\FunctionTok{require}\NormalTok{(scatterplot3d)}
\end{Highlighting}
\end{Shaded}
@@ -5840,30 +5812,30 @@ \subsection{Visualising the space}\label{visualising-the-space}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The plane space}
-\KeywordTok{scatterplot3d}\NormalTok{(plane\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{zlab =} \StringTok{""}\NormalTok{,}
- \DataTypeTok{xlim =} \KeywordTok{c}\NormalTok{(}\OperatorTok{{-}}\FloatTok{0.5}\NormalTok{, }\FloatTok{0.5}\NormalTok{), }\DataTypeTok{main =} \StringTok{"Plane space"}\NormalTok{)}
+\DocumentationTok{\#\# The plane space}
+\FunctionTok{scatterplot3d}\NormalTok{(plane\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{zlab =} \StringTok{""}\NormalTok{,}
+ \AttributeTok{xlim =} \FunctionTok{c}\NormalTok{(}\SpecialCharTok{{-}}\FloatTok{0.5}\NormalTok{, }\FloatTok{0.5}\NormalTok{), }\AttributeTok{main =} \StringTok{"Plane space"}\NormalTok{)}
-\CommentTok{\#\# The ellipsoid space}
-\KeywordTok{scatterplot3d}\NormalTok{(ellipse\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{zlab =} \StringTok{""}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Normal ellipsoid space"}\NormalTok{)}
+\DocumentationTok{\#\# The ellipsoid space}
+\FunctionTok{scatterplot3d}\NormalTok{(ellipse\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{zlab =} \StringTok{""}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Normal ellipsoid space"}\NormalTok{)}
-\CommentTok{\#\# A cylindrical space with a decreasing variance per axis}
-\KeywordTok{scatterplot3d}\NormalTok{(cylindrical\_space, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{, }\DataTypeTok{zlab =} \StringTok{""}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Normal cylindrical space"}\NormalTok{)}
-\CommentTok{\#\# Axes have different orders of magnitude}
+\DocumentationTok{\#\# A cylindrical space with a decreasing variance per axis}
+\FunctionTok{scatterplot3d}\NormalTok{(cylindrical\_space, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{, }\AttributeTok{zlab =} \StringTok{""}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Normal cylindrical space"}\NormalTok{)}
+\DocumentationTok{\#\# Axes have different orders of magnitude}
-\CommentTok{\#\# Plotting the doughnut space}
-\KeywordTok{scatterplot3d}\NormalTok{(doughnut\_space[,}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{)], }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{""}\NormalTok{,}
- \DataTypeTok{zlab =} \StringTok{""}\NormalTok{, }\DataTypeTok{main =} \StringTok{"Doughnut space"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the doughnut space}
+\FunctionTok{scatterplot3d}\NormalTok{(doughnut\_space[,}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{,}\DecValTok{3}\NormalTok{)], }\AttributeTok{pch =} \DecValTok{20}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{, }\AttributeTok{ylab =} \StringTok{""}\NormalTok{,}
+ \AttributeTok{zlab =} \StringTok{""}\NormalTok{, }\AttributeTok{main =} \StringTok{"Doughnut space"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-144-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-152-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(op)}
+\FunctionTok{par}\NormalTok{(op)}
\end{Highlighting}
\end{Shaded}
@@ -5875,41 +5847,41 @@ \subsection{Generating realistic spaces}\label{generating-realistic-spaces}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the data}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat50)}
+\DocumentationTok{\#\# Loading the data}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat50)}
-\CommentTok{\#\# Number of dimensions}
-\NormalTok{obs\_dim \textless{}{-}}\StringTok{ }\KeywordTok{ncol}\NormalTok{(BeckLee\_mat50)}
+\DocumentationTok{\#\# Number of dimensions}
+\NormalTok{obs\_dim }\OtherTok{\textless{}{-}} \FunctionTok{ncol}\NormalTok{(BeckLee\_mat50)}
-\CommentTok{\#\# Observed correlation between the dimensions}
-\NormalTok{obs\_correlations \textless{}{-}}\StringTok{ }\KeywordTok{cor}\NormalTok{(BeckLee\_mat50)}
+\DocumentationTok{\#\# Observed correlation between the dimensions}
+\NormalTok{obs\_correlations }\OtherTok{\textless{}{-}} \FunctionTok{cor}\NormalTok{(BeckLee\_mat50)}
-\CommentTok{\#\# Observed mean and standard deviation per axis}
-\NormalTok{obs\_mu\_sd\_axis \textless{}{-}}\StringTok{ }\KeywordTok{mapply}\NormalTok{(}\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{list}\NormalTok{(}\StringTok{"mean"}\NormalTok{ =}\StringTok{ }\NormalTok{x, }\StringTok{"sd"}\NormalTok{ =}\StringTok{ }\NormalTok{y),}
- \KeywordTok{as.list}\NormalTok{(}\KeywordTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, mean)),}
- \KeywordTok{as.list}\NormalTok{(}\KeywordTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, sd)), }\DataTypeTok{SIMPLIFY =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Observed mean and standard deviation per axis}
+\NormalTok{obs\_mu\_sd\_axis }\OtherTok{\textless{}{-}} \FunctionTok{mapply}\NormalTok{(}\ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{list}\NormalTok{(}\StringTok{"mean"} \OtherTok{=}\NormalTok{ x, }\StringTok{"sd"} \OtherTok{=}\NormalTok{ y),}
+ \FunctionTok{as.list}\NormalTok{(}\FunctionTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, mean)),}
+ \FunctionTok{as.list}\NormalTok{(}\FunctionTok{apply}\NormalTok{(BeckLee\_mat50, }\DecValTok{2}\NormalTok{, sd)), }\AttributeTok{SIMPLIFY =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# Observed overall mean and standard deviation}
-\NormalTok{obs\_mu\_sd\_glob \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"mean"}\NormalTok{ =}\StringTok{ }\KeywordTok{mean}\NormalTok{(BeckLee\_mat50), }\StringTok{"sd"}\NormalTok{ =}\StringTok{ }\KeywordTok{sd}\NormalTok{(BeckLee\_mat50))}
+\DocumentationTok{\#\# Observed overall mean and standard deviation}
+\NormalTok{obs\_mu\_sd\_glob }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"mean"} \OtherTok{=} \FunctionTok{mean}\NormalTok{(BeckLee\_mat50), }\StringTok{"sd"} \OtherTok{=} \FunctionTok{sd}\NormalTok{(BeckLee\_mat50))}
-\CommentTok{\#\# Scaled observed variance per axis (scree plot)}
-\NormalTok{obs\_scree \textless{}{-}}\StringTok{ }\KeywordTok{variances}\NormalTok{(BeckLee\_mat50)}\OperatorTok{/}\KeywordTok{sum}\NormalTok{(}\KeywordTok{variances}\NormalTok{(BeckLee\_mat50))}
+\DocumentationTok{\#\# Scaled observed variance per axis (scree plot)}
+\NormalTok{obs\_scree }\OtherTok{\textless{}{-}} \FunctionTok{variances}\NormalTok{(BeckLee\_mat50)}\SpecialCharTok{/}\FunctionTok{sum}\NormalTok{(}\FunctionTok{variances}\NormalTok{(BeckLee\_mat50))}
-\CommentTok{\#\# Generating our simulated space}
-\NormalTok{simulated\_space \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DecValTok{1000}\NormalTok{, }\DataTypeTok{dimensions =}\NormalTok{ obs\_dim, }
- \DataTypeTok{distribution =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(rnorm), obs\_dim),}
- \DataTypeTok{arguments =}\NormalTok{ obs\_mu\_sd\_axis,}
- \DataTypeTok{cor.matrix =}\NormalTok{ obs\_correlations)}
+\DocumentationTok{\#\# Generating our simulated space}
+\NormalTok{simulated\_space }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\DecValTok{1000}\NormalTok{, }\AttributeTok{dimensions =}\NormalTok{ obs\_dim, }
+ \AttributeTok{distribution =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(rnorm), obs\_dim),}
+ \AttributeTok{arguments =}\NormalTok{ obs\_mu\_sd\_axis,}
+ \AttributeTok{cor.matrix =}\NormalTok{ obs\_correlations)}
-\CommentTok{\#\# Visualising the fit of our data in the space (in the two first dimensions)}
-\KeywordTok{plot}\NormalTok{(simulated\_space[,}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{], }\DataTypeTok{xlab =} \StringTok{"PC1"}\NormalTok{, }\DataTypeTok{ylab =} \StringTok{"PC2"}\NormalTok{)}
-\KeywordTok{points}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{], }\DataTypeTok{col =} \StringTok{"red"}\NormalTok{, }\DataTypeTok{pch =} \DecValTok{20}\NormalTok{)}
-\KeywordTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\DataTypeTok{legend =} \KeywordTok{c}\NormalTok{(}\StringTok{"observed"}\NormalTok{, }\StringTok{"simulated"}\NormalTok{),}
- \DataTypeTok{pch =} \KeywordTok{c}\NormalTok{(}\DecValTok{20}\NormalTok{,}\DecValTok{21}\NormalTok{), }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"red"}\NormalTok{, }\StringTok{"black"}\NormalTok{))}
+\DocumentationTok{\#\# Visualising the fit of our data in the space (in the two first dimensions)}
+\FunctionTok{plot}\NormalTok{(simulated\_space[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{], }\AttributeTok{xlab =} \StringTok{"PC1"}\NormalTok{, }\AttributeTok{ylab =} \StringTok{"PC2"}\NormalTok{)}
+\FunctionTok{points}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{], }\AttributeTok{col =} \StringTok{"red"}\NormalTok{, }\AttributeTok{pch =} \DecValTok{20}\NormalTok{)}
+\FunctionTok{legend}\NormalTok{(}\StringTok{"topleft"}\NormalTok{, }\AttributeTok{legend =} \FunctionTok{c}\NormalTok{(}\StringTok{"observed"}\NormalTok{, }\StringTok{"simulated"}\NormalTok{),}
+ \AttributeTok{pch =} \FunctionTok{c}\NormalTok{(}\DecValTok{20}\NormalTok{,}\DecValTok{21}\NormalTok{), }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"red"}\NormalTok{, }\StringTok{"black"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-145-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-153-1.pdf}
It is now possible to simulate a space using these observed arguments to test several hypothesis:
@@ -5923,36 +5895,36 @@ \subsection{Generating realistic spaces}\label{generating-realistic-spaces}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring disparity as the sum of variance}
-\NormalTok{observed\_disp \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(BeckLee\_mat50, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids))}
+\DocumentationTok{\#\# Measuring disparity as the sum of variance}
+\NormalTok{observed\_disp }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(BeckLee\_mat50, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids))}
-\CommentTok{\#\# Is the space uniform?}
-\NormalTok{test\_unif \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =}\NormalTok{ runif)}
+\DocumentationTok{\#\# Is the space uniform?}
+\NormalTok{test\_unif }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =}\NormalTok{ runif)}
-\CommentTok{\#\# Is the space normal with a mean of 0 and a sd of 1?}
-\NormalTok{test\_norm1 \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =}\NormalTok{ rnorm)}
+\DocumentationTok{\#\# Is the space normal with a mean of 0 and a sd of 1?}
+\NormalTok{test\_norm1 }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =}\NormalTok{ rnorm)}
-\CommentTok{\#\# Is the space normal with the observed mean and sd and cumulative variance}
-\NormalTok{test\_norm2 \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(rnorm), obs\_dim),}
- \DataTypeTok{null.args =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(obs\_mu\_sd\_glob), obs\_dim),}
- \DataTypeTok{null.scree =}\NormalTok{ obs\_scree)}
+\DocumentationTok{\#\# Is the space normal with the observed mean and sd and cumulative variance}
+\NormalTok{test\_norm2 }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(rnorm), obs\_dim),}
+ \AttributeTok{null.args =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(obs\_mu\_sd\_glob), obs\_dim),}
+ \AttributeTok{null.scree =}\NormalTok{ obs\_scree)}
-\CommentTok{\#\# Is the space multiple normal with multiple means and sds and a correlation?}
-\NormalTok{test\_norm3 \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(observed\_disp, }\DataTypeTok{null.distrib =} \KeywordTok{rep}\NormalTok{(}\KeywordTok{list}\NormalTok{(rnorm), obs\_dim),}
- \DataTypeTok{null.args =}\NormalTok{ obs\_mu\_sd\_axis, }\DataTypeTok{null.cor =}\NormalTok{ obs\_correlations)}
+\DocumentationTok{\#\# Is the space multiple normal with multiple means and sds and a correlation?}
+\NormalTok{test\_norm3 }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(observed\_disp, }\AttributeTok{null.distrib =} \FunctionTok{rep}\NormalTok{(}\FunctionTok{list}\NormalTok{(rnorm), obs\_dim),}
+ \AttributeTok{null.args =}\NormalTok{ obs\_mu\_sd\_axis, }\AttributeTok{null.cor =}\NormalTok{ obs\_correlations)}
-\CommentTok{\#\# Graphical options}
-\NormalTok{op \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =}\NormalTok{ (}\KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(test\_unif, }\DataTypeTok{main =} \StringTok{"Uniform (0,1)"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(test\_norm1, }\DataTypeTok{main =} \StringTok{"Normal (0,1)"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(test\_norm2, }\DataTypeTok{main =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"Normal ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{1}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{3}\NormalTok{),}
- \StringTok{","}\NormalTok{, }\KeywordTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{2}\NormalTok{]], }\DataTypeTok{digit =} \DecValTok{3}\NormalTok{), }\StringTok{")"}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(test\_norm3, }\DataTypeTok{main =} \StringTok{"Normal (variable + correlation)"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\NormalTok{op }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =}\NormalTok{ (}\FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{, }\DecValTok{2}\NormalTok{)), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(test\_unif, }\AttributeTok{main =} \StringTok{"Uniform (0,1)"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(test\_norm1, }\AttributeTok{main =} \StringTok{"Normal (0,1)"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(test\_norm2, }\AttributeTok{main =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"Normal ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{1}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{3}\NormalTok{),}
+ \StringTok{","}\NormalTok{, }\FunctionTok{round}\NormalTok{(obs\_mu\_sd\_glob[[}\DecValTok{2}\NormalTok{]], }\AttributeTok{digit =} \DecValTok{3}\NormalTok{), }\StringTok{")"}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(test\_norm3, }\AttributeTok{main =} \StringTok{"Normal (variable + correlation)"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-146-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-154-1.pdf}
If we measure disparity as the median distance from the morphospace centroid, we can explain the distribution of the data as normal with the variable observed mean and standard deviation and with a correlation between the dimensions.
@@ -5980,9 +5952,9 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A random binary matrix}
-\NormalTok{matrix\_binary \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{sample}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{), }\DecValTok{12}\NormalTok{, }\DataTypeTok{replace =} \OtherTok{TRUE}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{4}\NormalTok{,}
- \DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(letters[}\DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{], LETTERS[}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{]))}
+\DocumentationTok{\#\# A random binary matrix}
+\NormalTok{matrix\_binary }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{0}\NormalTok{,}\DecValTok{1}\NormalTok{), }\DecValTok{12}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{4}\NormalTok{,}
+ \AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(letters[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{], LETTERS[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{]))}
\end{Highlighting}
\end{Shaded}
@@ -5990,8 +5962,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The hamming distance between characters}
-\NormalTok{(differences \textless{}{-}}\StringTok{ }\KeywordTok{char.diff}\NormalTok{(matrix\_binary))}
+\DocumentationTok{\#\# The hamming distance between characters}
+\NormalTok{(differences }\OtherTok{\textless{}{-}} \FunctionTok{char.diff}\NormalTok{(matrix\_binary))}
\end{Highlighting}
\end{Shaded}
@@ -6010,12 +5982,12 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Visualising the matrix}
-\KeywordTok{plot}\NormalTok{(differences)}
+\DocumentationTok{\#\# Visualising the matrix}
+\FunctionTok{plot}\NormalTok{(differences)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-149-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-157-1.pdf}
You can check all the numerous plotting options in the \texttt{?plot.char.diff} manual (it won't be developed here).
@@ -6023,8 +5995,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Euclidean distance between rows}
-\KeywordTok{char.diff}\NormalTok{(matrix\_binary, }\DataTypeTok{by.col =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{method =} \StringTok{"euclidean"}\NormalTok{)}
+\DocumentationTok{\#\# Euclidean distance between rows}
+\FunctionTok{char.diff}\NormalTok{(matrix\_binary, }\AttributeTok{by.col =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{method =} \StringTok{"euclidean"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -6042,9 +6014,9 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A random character matrix}
-\NormalTok{(matrix\_character \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{sample}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\StringTok{"0"}\NormalTok{,}\StringTok{"1"}\NormalTok{,}\StringTok{"2"}\NormalTok{), }\DecValTok{30}\NormalTok{, }\DataTypeTok{replace =} \OtherTok{TRUE}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{5}\NormalTok{,}
- \DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(letters[}\DecValTok{1}\OperatorTok{:}\DecValTok{6}\NormalTok{], LETTERS[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])))}
+\DocumentationTok{\#\# A random character matrix}
+\NormalTok{(matrix\_character }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\StringTok{"0"}\NormalTok{,}\StringTok{"1"}\NormalTok{,}\StringTok{"2"}\NormalTok{), }\DecValTok{30}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{5}\NormalTok{,}
+ \AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(letters[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{6}\NormalTok{], LETTERS[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])))}
\end{Highlighting}
\end{Shaded}
@@ -6060,8 +6032,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The hamming difference between columns}
-\KeywordTok{char.diff}\NormalTok{(matrix\_character)}
+\DocumentationTok{\#\# The hamming difference between columns}
+\FunctionTok{char.diff}\NormalTok{(matrix\_character)}
\end{Highlighting}
\end{Shaded}
@@ -6080,13 +6052,13 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Adding uncertain characters}
-\NormalTok{matrix\_character[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] \textless{}{-}}\StringTok{ "0/1"}
+\DocumentationTok{\#\# Adding uncertain characters}
+\NormalTok{matrix\_character[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"0/1"}
-\CommentTok{\#\# Adding missing data}
-\NormalTok{matrix\_character[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{5}\NormalTok{)] \textless{}{-}}\StringTok{ "?"}
+\DocumentationTok{\#\# Adding missing data}
+\NormalTok{matrix\_character[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{5}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"?"}
-\CommentTok{\#\# This is what it looks like now}
+\DocumentationTok{\#\# This is what it looks like now}
\NormalTok{matrix\_character}
\end{Highlighting}
\end{Shaded}
@@ -6103,8 +6075,8 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The hamming difference between columns including the special characters}
-\KeywordTok{char.diff}\NormalTok{(matrix\_character)}
+\DocumentationTok{\#\# The hamming difference between columns including the special characters}
+\FunctionTok{char.diff}\NormalTok{(matrix\_character)}
\end{Highlighting}
\end{Shaded}
@@ -6126,12 +6098,12 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Specifying some special behaviours}
-\NormalTok{my\_special\_behaviours \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\DataTypeTok{missing =} \ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(y),}
- \DataTypeTok{uncertainty =} \ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(}\KeywordTok{as.integer}\NormalTok{(}\DecValTok{0}\NormalTok{)))}
+\DocumentationTok{\#\# Specifying some special behaviours}
+\NormalTok{my\_special\_behaviours }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\AttributeTok{missing =} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(y),}
+ \AttributeTok{uncertainty =} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(}\FunctionTok{as.integer}\NormalTok{(}\DecValTok{0}\NormalTok{)))}
-\CommentTok{\#\# Passing these special behaviours to the char.diff function}
-\KeywordTok{char.diff}\NormalTok{(matrix\_character, }\DataTypeTok{special.behaviour =}\NormalTok{ my\_special\_behaviours)}
+\DocumentationTok{\#\# Passing these special behaviours to the char.diff function}
+\FunctionTok{char.diff}\NormalTok{(matrix\_character, }\AttributeTok{special.behaviour =}\NormalTok{ my\_special\_behaviours)}
\end{Highlighting}
\end{Shaded}
@@ -6150,13 +6122,13 @@ \section{\texorpdfstring{\texttt{char.diff}}{char.diff}}\label{char.diff}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Adding weird tokens to the matrix}
-\NormalTok{matrix\_character[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] \textless{}{-}}\StringTok{ "\%"}
+\DocumentationTok{\#\# Adding weird tokens to the matrix}
+\NormalTok{matrix\_character[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{30}\NormalTok{, }\DecValTok{8}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"\%"}
-\CommentTok{\#\# Specify the new token and the new behaviour}
-\KeywordTok{char.diff}\NormalTok{(matrix\_character, }\DataTypeTok{special.tokens =} \KeywordTok{c}\NormalTok{(}\DataTypeTok{weird\_one =} \StringTok{"\%"}\NormalTok{),}
- \DataTypeTok{special.behaviours =} \KeywordTok{list}\NormalTok{(}
- \DataTypeTok{weird\_one =} \ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(}\KeywordTok{as.integer}\NormalTok{(}\DecValTok{42}\NormalTok{)))}
+\DocumentationTok{\#\# Specify the new token and the new behaviour}
+\FunctionTok{char.diff}\NormalTok{(matrix\_character, }\AttributeTok{special.tokens =} \FunctionTok{c}\NormalTok{(}\AttributeTok{weird\_one =} \StringTok{"\%"}\NormalTok{),}
+ \AttributeTok{special.behaviours =} \FunctionTok{list}\NormalTok{(}
+ \AttributeTok{weird\_one =} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(}\FunctionTok{as.integer}\NormalTok{(}\DecValTok{42}\NormalTok{)))}
\NormalTok{ )}
\end{Highlighting}
\end{Shaded}
@@ -6182,14 +6154,14 @@ \section{\texorpdfstring{\texttt{clean.data}}{clean.data}}\label{clean.data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Generating a trees with labels from a to e}
-\NormalTok{dummy\_tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\DataTypeTok{tip.label =}\NormalTok{ LETTERS[}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])}
+\DocumentationTok{\#\# Generating a trees with labels from a to e}
+\NormalTok{dummy\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\AttributeTok{tip.label =}\NormalTok{ LETTERS[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])}
-\CommentTok{\#\# Generating a matrix with rows from b to f}
-\NormalTok{dummy\_data \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DataTypeTok{dimnames =} \KeywordTok{list}\NormalTok{(LETTERS[}\DecValTok{2}\OperatorTok{:}\DecValTok{6}\NormalTok{], }\KeywordTok{c}\NormalTok{(}\StringTok{"var1"}\NormalTok{, }\StringTok{"var2"}\NormalTok{)))}
+\DocumentationTok{\#\# Generating a matrix with rows from b to f}
+\NormalTok{dummy\_data }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\DecValTok{1}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\AttributeTok{dimnames =} \FunctionTok{list}\NormalTok{(LETTERS[}\DecValTok{2}\SpecialCharTok{:}\DecValTok{6}\NormalTok{], }\FunctionTok{c}\NormalTok{(}\StringTok{"var1"}\NormalTok{, }\StringTok{"var2"}\NormalTok{)))}
-\CommentTok{\#\#Cleaning the trees and the data}
-\NormalTok{(cleaned \textless{}{-}}\StringTok{ }\KeywordTok{clean.data}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ dummy\_data, }\DataTypeTok{tree =}\NormalTok{ dummy\_tree))}
+\DocumentationTok{\#\#Cleaning the trees and the data}
+\NormalTok{(cleaned }\OtherTok{\textless{}{-}} \FunctionTok{clean.data}\NormalTok{(}\AttributeTok{data =}\NormalTok{ dummy\_data, }\AttributeTok{tree =}\NormalTok{ dummy\_tree))}
\end{Highlighting}
\end{Shaded}
@@ -6224,9 +6196,9 @@ \section{\texorpdfstring{\texttt{crown.stem}}{crown.stem}}\label{crown.stem}}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{data}\NormalTok{(BeckLee\_tree)}
-\CommentTok{\#\# Diving both crow and stem species}
-\NormalTok{(}\KeywordTok{crown.stem}\NormalTok{(BeckLee\_tree, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{))}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree)}
+\DocumentationTok{\#\# Diving both crow and stem species}
+\NormalTok{(}\FunctionTok{crown.stem}\NormalTok{(BeckLee\_tree, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -6262,7 +6234,7 @@ \section{\texorpdfstring{\texttt{get.bin.ages}}{get.bin.ages}}\label{get.bin.age
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{get.bin.ages}\NormalTok{(BeckLee\_tree)}
+\FunctionTok{get.bin.ages}\NormalTok{(BeckLee\_tree)}
\end{Highlighting}
\end{Shaded}
@@ -6289,17 +6261,17 @@ \section{\texorpdfstring{\texttt{match.tip.edge}}{match.tip.edge}}\label{match.t
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the charadriiformes data}
-\KeywordTok{data}\NormalTok{(charadriiformes) }
-\CommentTok{\#\# Extracting the tree}
-\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\NormalTok{charadriiformes}\OperatorTok{$}\NormalTok{tree}
-\CommentTok{\#\# Extracting the data column that contains the clade assignments}
-\NormalTok{my\_data \textless{}{-}}\StringTok{ }\NormalTok{charadriiformes}\OperatorTok{$}\NormalTok{data[, }\StringTok{"clade"}\NormalTok{]}
-\CommentTok{\#\# Changing the levels names (the clade names) to colours}
-\KeywordTok{levels}\NormalTok{(my\_data) \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{)}
-\NormalTok{my\_data \textless{}{-}}\StringTok{ }\KeywordTok{as.character}\NormalTok{(my\_data)}
-\CommentTok{\#\# Matching the data rownames to the tip order in the tree}
-\NormalTok{my\_data \textless{}{-}}\StringTok{ }\NormalTok{my\_data[}\KeywordTok{match}\NormalTok{(}\KeywordTok{ladderize}\NormalTok{(my\_tree)}\OperatorTok{$}\NormalTok{tip.label, }\KeywordTok{rownames}\NormalTok{(charadriiformes}\OperatorTok{$}\NormalTok{data))]}
+\DocumentationTok{\#\# Loading the charadriiformes data}
+\FunctionTok{data}\NormalTok{(charadriiformes) }
+\DocumentationTok{\#\# Extracting the tree}
+\NormalTok{my\_tree }\OtherTok{\textless{}{-}}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{tree}
+\DocumentationTok{\#\# Extracting the data column that contains the clade assignments}
+\NormalTok{my\_data }\OtherTok{\textless{}{-}}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{data[, }\StringTok{"clade"}\NormalTok{]}
+\DocumentationTok{\#\# Changing the levels names (the clade names) to colours}
+\FunctionTok{levels}\NormalTok{(my\_data) }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{, }\StringTok{"darkgreen"}\NormalTok{)}
+\NormalTok{my\_data }\OtherTok{\textless{}{-}} \FunctionTok{as.character}\NormalTok{(my\_data)}
+\DocumentationTok{\#\# Matching the data rownames to the tip order in the tree}
+\NormalTok{my\_data }\OtherTok{\textless{}{-}}\NormalTok{ my\_data[}\FunctionTok{match}\NormalTok{(}\FunctionTok{ladderize}\NormalTok{(my\_tree)}\SpecialCharTok{$}\NormalTok{tip.label, }\FunctionTok{rownames}\NormalTok{(charadriiformes}\SpecialCharTok{$}\NormalTok{data))]}
\end{Highlighting}
\end{Shaded}
@@ -6309,31 +6281,31 @@ \section{\texorpdfstring{\texttt{match.tip.edge}}{match.tip.edge}}\label{match.t
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Matching the tip colours (labels) to their descending edges in the tree}
-\CommentTok{\#\# (and making the non{-}match edges grey)}
-\NormalTok{clade\_edges \textless{}{-}}\StringTok{ }\KeywordTok{match.tip.edge}\NormalTok{(my\_data, my\_tree, }\DataTypeTok{replace.na =} \StringTok{"grey"}\NormalTok{)}
+\DocumentationTok{\#\# Matching the tip colours (labels) to their descending edges in the tree}
+\DocumentationTok{\#\# (and making the non{-}match edges grey)}
+\NormalTok{clade\_edges }\OtherTok{\textless{}{-}} \FunctionTok{match.tip.edge}\NormalTok{(my\_data, my\_tree, }\AttributeTok{replace.na =} \StringTok{"grey"}\NormalTok{)}
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(}\KeywordTok{ladderize}\NormalTok{(my\_tree), }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{edge.color =}\NormalTok{ clade\_edges)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(}\FunctionTok{ladderize}\NormalTok{(my\_tree), }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{edge.color =}\NormalTok{ clade\_edges)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-159-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-167-1.pdf}
But you can also use this option to only select some specific edges and modify them (for example making them all equal to one):
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Adding a fixed edge length to the green clade}
-\NormalTok{my\_tree\_modif \textless{}{-}}\StringTok{ }\NormalTok{my\_tree}
-\NormalTok{green\_clade \textless{}{-}}\StringTok{ }\KeywordTok{which}\NormalTok{(clade\_edges }\OperatorTok{==}\StringTok{ "darkgreen"}\NormalTok{)}
-\NormalTok{my\_tree\_modif}\OperatorTok{$}\NormalTok{edge.length[green\_clade] \textless{}{-}}\StringTok{ }\DecValTok{1}
-\KeywordTok{plot}\NormalTok{(}\KeywordTok{ladderize}\NormalTok{(my\_tree\_modif), }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{,}
- \DataTypeTok{edge.color =}\NormalTok{ clade\_edges)}
+\DocumentationTok{\#\# Adding a fixed edge length to the green clade}
+\NormalTok{my\_tree\_modif }\OtherTok{\textless{}{-}}\NormalTok{ my\_tree}
+\NormalTok{green\_clade }\OtherTok{\textless{}{-}} \FunctionTok{which}\NormalTok{(clade\_edges }\SpecialCharTok{==} \StringTok{"darkgreen"}\NormalTok{)}
+\NormalTok{my\_tree\_modif}\SpecialCharTok{$}\NormalTok{edge.length[green\_clade] }\OtherTok{\textless{}{-}} \DecValTok{1}
+\FunctionTok{plot}\NormalTok{(}\FunctionTok{ladderize}\NormalTok{(my\_tree\_modif), }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{,}
+ \AttributeTok{edge.color =}\NormalTok{ clade\_edges)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-160-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-168-1.pdf}
\hypertarget{MCMCglmm-utilities}{%
\section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label{MCMCglmm-utilities}}
@@ -6344,12 +6316,12 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the charadriiformes data that contains a MCMCglmm object}
-\KeywordTok{data}\NormalTok{(charadriiformes)}
-\NormalTok{my\_MCMCglmm \textless{}{-}}\StringTok{ }\NormalTok{charadriiformes}\OperatorTok{$}\NormalTok{posteriors}
+\DocumentationTok{\#\# Loading the charadriiformes data that contains a MCMCglmm object}
+\FunctionTok{data}\NormalTok{(charadriiformes)}
+\NormalTok{my\_MCMCglmm }\OtherTok{\textless{}{-}}\NormalTok{ charadriiformes}\SpecialCharTok{$}\NormalTok{posteriors}
-\CommentTok{\#\# Which traits where used in this model?}
-\KeywordTok{MCMCglmm.traits}\NormalTok{(my\_MCMCglmm)}
+\DocumentationTok{\#\# Which traits where used in this model?}
+\FunctionTok{MCMCglmm.traits}\NormalTok{(my\_MCMCglmm)}
\end{Highlighting}
\end{Shaded}
@@ -6359,8 +6331,8 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Which levels where used for the model\textquotesingle{}s random terms and/or residuals?}
-\KeywordTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm)}
+\DocumentationTok{\#\# Which levels where used for the model\textquotesingle{}s random terms and/or residuals?}
+\FunctionTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm)}
\end{Highlighting}
\end{Shaded}
@@ -6373,9 +6345,9 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The level names are converted for clarity but you can get them unconverted}
-\CommentTok{\#\# (i.e. as they appear in the model)}
-\KeywordTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm, }\DataTypeTok{convert =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# The level names are converted for clarity but you can get them unconverted}
+\DocumentationTok{\#\# (i.e. as they appear in the model)}
+\FunctionTok{MCMCglmm.levels}\NormalTok{(my\_MCMCglmm, }\AttributeTok{convert =} \ConstantTok{FALSE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -6390,8 +6362,8 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Sampling 2 random posteriors samples IDs}
-\NormalTok{(random\_samples \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.sample}\NormalTok{(my\_MCMCglmm, }\DataTypeTok{n =} \DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# Sampling 2 random posteriors samples IDs}
+\NormalTok{(random\_samples }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.sample}\NormalTok{(my\_MCMCglmm, }\AttributeTok{n =} \DecValTok{2}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -6401,17 +6373,17 @@ \section{\texorpdfstring{\texttt{MCMCglmm} utilities}{MCMCglmm utilities}}\label
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Extracting these two random samples}
-\NormalTok{my\_covars \textless{}{-}}\StringTok{ }\KeywordTok{MCMCglmm.covars}\NormalTok{(my\_MCMCglmm, }\DataTypeTok{sample =}\NormalTok{ random\_samples)}
+\DocumentationTok{\#\# Extracting these two random samples}
+\NormalTok{my\_covars }\OtherTok{\textless{}{-}} \FunctionTok{MCMCglmm.covars}\NormalTok{(my\_MCMCglmm, }\AttributeTok{sample =}\NormalTok{ random\_samples)}
-\CommentTok{\#\# Plotting the variance for each term in the model}
-\KeywordTok{boxplot}\NormalTok{(}\KeywordTok{MCMCglmm.variance}\NormalTok{(my\_MCMCglmm), }\DataTypeTok{horizontal =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{las =} \DecValTok{1}\NormalTok{,}
- \DataTypeTok{xlab =} \StringTok{"Relative variance"}\NormalTok{,}
- \DataTypeTok{main =} \StringTok{"Variance explained by each term"}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the variance for each term in the model}
+\FunctionTok{boxplot}\NormalTok{(}\FunctionTok{MCMCglmm.variance}\NormalTok{(my\_MCMCglmm), }\AttributeTok{horizontal =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{las =} \DecValTok{1}\NormalTok{,}
+ \AttributeTok{xlab =} \StringTok{"Relative variance"}\NormalTok{,}
+ \AttributeTok{main =} \StringTok{"Variance explained by each term"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-161-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-169-1.pdf}
See more in the \protect\hyperlink{covar}{\texttt{\$covar} section} on what to do with these \texttt{"MCMCglmm"} objects.
@@ -6423,16 +6395,16 @@ \section{\texorpdfstring{\texttt{pair.plot}}{pair.plot}}\label{pair.plot}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Random data}
-\NormalTok{data \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\DataTypeTok{data =} \KeywordTok{runif}\NormalTok{(}\DecValTok{42}\NormalTok{), }\DataTypeTok{ncol =} \DecValTok{2}\NormalTok{)}
+\DocumentationTok{\#\# Random data}
+\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\AttributeTok{data =} \FunctionTok{runif}\NormalTok{(}\DecValTok{42}\NormalTok{), }\AttributeTok{ncol =} \DecValTok{2}\NormalTok{)}
-\CommentTok{\#\# Plotting the first column as a pairwise comparisons}
-\KeywordTok{pair.plot}\NormalTok{(data, }\DataTypeTok{what =} \DecValTok{1}\NormalTok{, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\DataTypeTok{legend =} \OtherTok{TRUE}\NormalTok{,}
- \DataTypeTok{diag =} \DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the first column as a pairwise comparisons}
+\FunctionTok{pair.plot}\NormalTok{(data, }\AttributeTok{what =} \DecValTok{1}\NormalTok{, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\AttributeTok{legend =} \ConstantTok{TRUE}\NormalTok{,}
+ \AttributeTok{diag =} \DecValTok{1}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-162-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-170-1.pdf}
Here blue squares are ones that have a high value and orange ones the ones that have low values.
Note that the values plotted correspond the first column of the data as designated by \texttt{what\ =\ 1}.
@@ -6441,35 +6413,35 @@ \section{\texorpdfstring{\texttt{pair.plot}}{pair.plot}}\label{pair.plot}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The same plot as before without the diagonal being}
-\CommentTok{\#\# the maximal observed value}
-\KeywordTok{pair.plot}\NormalTok{(data, }\DataTypeTok{what =} \DecValTok{1}\NormalTok{, }\DataTypeTok{col =} \KeywordTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\DataTypeTok{legend =} \OtherTok{TRUE}\NormalTok{,}
- \DataTypeTok{diag =} \StringTok{"max"}\NormalTok{)}
-\CommentTok{\#\# Highlighting with an asterisk which squares have a value}
-\CommentTok{\#\# below 0.2}
-\KeywordTok{pair.plot}\NormalTok{(data, }\DataTypeTok{what =} \DecValTok{1}\NormalTok{, }\DataTypeTok{binary =} \FloatTok{0.2}\NormalTok{, }\DataTypeTok{add =} \StringTok{"*"}\NormalTok{, }\DataTypeTok{cex =} \DecValTok{2}\NormalTok{)}
+\DocumentationTok{\#\# The same plot as before without the diagonal being}
+\DocumentationTok{\#\# the maximal observed value}
+\FunctionTok{pair.plot}\NormalTok{(data, }\AttributeTok{what =} \DecValTok{1}\NormalTok{, }\AttributeTok{col =} \FunctionTok{c}\NormalTok{(}\StringTok{"orange"}\NormalTok{, }\StringTok{"blue"}\NormalTok{), }\AttributeTok{legend =} \ConstantTok{TRUE}\NormalTok{,}
+ \AttributeTok{diag =} \StringTok{"max"}\NormalTok{)}
+\DocumentationTok{\#\# Highlighting with an asterisk which squares have a value}
+\DocumentationTok{\#\# below 0.2}
+\FunctionTok{pair.plot}\NormalTok{(data, }\AttributeTok{what =} \DecValTok{1}\NormalTok{, }\AttributeTok{binary =} \FloatTok{0.2}\NormalTok{, }\AttributeTok{add =} \StringTok{"*"}\NormalTok{, }\AttributeTok{cex =} \DecValTok{2}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-163-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-171-1.pdf}
This function can also be used as a binary display when running a series of pairwise t-tests.
For example, the following script runs a wilcoxon test between the time-slices from the \texttt{disparity} example dataset and displays in black which pairs of slices have a p-value below 0.05:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading disparity data}
-\KeywordTok{data}\NormalTok{(disparity)}
+\DocumentationTok{\#\# Loading disparity data}
+\FunctionTok{data}\NormalTok{(disparity)}
-\CommentTok{\#\# Testing the pairwise difference between slices}
-\NormalTok{tests \textless{}{-}}\StringTok{ }\KeywordTok{test.dispRity}\NormalTok{(disparity, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
+\DocumentationTok{\#\# Testing the pairwise difference between slices}
+\NormalTok{tests }\OtherTok{\textless{}{-}} \FunctionTok{test.dispRity}\NormalTok{(disparity, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
-\CommentTok{\#\# Plotting the significance}
-\KeywordTok{pair.plot}\NormalTok{(}\KeywordTok{as.data.frame}\NormalTok{(tests), }\DataTypeTok{what =} \StringTok{"p.value"}\NormalTok{, }\DataTypeTok{binary =} \FloatTok{0.05}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the significance}
+\FunctionTok{pair.plot}\NormalTok{(}\FunctionTok{as.data.frame}\NormalTok{(tests), }\AttributeTok{what =} \StringTok{"p.value"}\NormalTok{, }\AttributeTok{binary =} \FloatTok{0.05}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-164-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-172-1.pdf}
\hypertarget{reduce.matrix}{%
\section{\texorpdfstring{\texttt{reduce.matrix}}{reduce.matrix}}\label{reduce.matrix}}
@@ -6481,28 +6453,28 @@ \section{\texorpdfstring{\texttt{reduce.matrix}}{reduce.matrix}}\label{reduce.ma
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# A 10*5 matrix}
-\NormalTok{na\_matrix \textless{}{-}}\StringTok{ }\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{50}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{)}
-\CommentTok{\#\# Making sure some rows don\textquotesingle{}t overlap}
-\NormalTok{na\_matrix[}\DecValTok{1}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{2}\NormalTok{] \textless{}{-}}\StringTok{ }\OtherTok{NA}
-\NormalTok{na\_matrix[}\DecValTok{2}\NormalTok{, }\DecValTok{3}\OperatorTok{:}\DecValTok{5}\NormalTok{] \textless{}{-}}\StringTok{ }\OtherTok{NA}
-\CommentTok{\#\# Adding 50\% NAs}
-\NormalTok{na\_matrix[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\DecValTok{50}\NormalTok{, }\DecValTok{25}\NormalTok{)] \textless{}{-}}\StringTok{ }\OtherTok{NA}
-\CommentTok{\#\# Illustrating the gappy matrix}
-\KeywordTok{image}\NormalTok{(}\KeywordTok{t}\NormalTok{(na\_matrix), }\DataTypeTok{col =} \StringTok{"black"}\NormalTok{)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# A 10*5 matrix}
+\NormalTok{na\_matrix }\OtherTok{\textless{}{-}} \FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{50}\NormalTok{), }\DecValTok{10}\NormalTok{, }\DecValTok{5}\NormalTok{)}
+\DocumentationTok{\#\# Making sure some rows don\textquotesingle{}t overlap}
+\NormalTok{na\_matrix[}\DecValTok{1}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{] }\OtherTok{\textless{}{-}} \ConstantTok{NA}
+\NormalTok{na\_matrix[}\DecValTok{2}\NormalTok{, }\DecValTok{3}\SpecialCharTok{:}\DecValTok{5}\NormalTok{] }\OtherTok{\textless{}{-}} \ConstantTok{NA}
+\DocumentationTok{\#\# Adding 50\% NAs}
+\NormalTok{na\_matrix[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{50}\NormalTok{, }\DecValTok{25}\NormalTok{)] }\OtherTok{\textless{}{-}} \ConstantTok{NA}
+\DocumentationTok{\#\# Illustrating the gappy matrix}
+\FunctionTok{image}\NormalTok{(}\FunctionTok{t}\NormalTok{(na\_matrix), }\AttributeTok{col =} \StringTok{"black"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-165-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-173-1.pdf}
We can use the \texttt{reduce.matrix} to double check whether any rows cannot be compared.
The functions needs as an input the type of distance that will be used, say a \texttt{"gower"} distance:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Reducing the matrix by row}
-\NormalTok{(reduction \textless{}{-}}\StringTok{ }\KeywordTok{reduce.matrix}\NormalTok{(na\_matrix, }\DataTypeTok{distance =} \StringTok{"gower"}\NormalTok{))}
+\DocumentationTok{\#\# Reducing the matrix by row}
+\NormalTok{(reduction }\OtherTok{\textless{}{-}} \FunctionTok{reduce.matrix}\NormalTok{(na\_matrix, }\AttributeTok{distance =} \StringTok{"gower"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -6518,12 +6490,12 @@ \section{\texorpdfstring{\texttt{reduce.matrix}}{reduce.matrix}}\label{reduce.ma
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{image}\NormalTok{(}\KeywordTok{t}\NormalTok{(na\_matrix[}\OperatorTok{{-}}\KeywordTok{as.numeric}\NormalTok{(reduction}\OperatorTok{$}\NormalTok{rows.to.remove), ]),}
- \DataTypeTok{col =} \StringTok{"black"}\NormalTok{)}
+\FunctionTok{image}\NormalTok{(}\FunctionTok{t}\NormalTok{(na\_matrix[}\SpecialCharTok{{-}}\FunctionTok{as.numeric}\NormalTok{(reduction}\SpecialCharTok{$}\NormalTok{rows.to.remove), ]),}
+ \AttributeTok{col =} \StringTok{"black"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-167-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-175-1.pdf}
\hypertarget{select.axes}{%
\section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
@@ -6535,11 +6507,11 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The USArrest example in R}
-\NormalTok{ordination \textless{}{-}}\StringTok{ }\KeywordTok{princomp}\NormalTok{(USArrests, }\DataTypeTok{cor =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# The USArrest example in R}
+\NormalTok{ordination }\OtherTok{\textless{}{-}} \FunctionTok{princomp}\NormalTok{(USArrests, }\AttributeTok{cor =} \ConstantTok{TRUE}\NormalTok{)}
-\CommentTok{\#\# The loading of each variable}
-\KeywordTok{loadings}\NormalTok{(ordination)}
+\DocumentationTok{\#\# The loading of each variable}
+\FunctionTok{loadings}\NormalTok{(ordination)}
\end{Highlighting}
\end{Shaded}
@@ -6560,11 +6532,11 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Or the same operation but manually}
-\NormalTok{variances \textless{}{-}}\StringTok{ }\KeywordTok{apply}\NormalTok{(ordination}\OperatorTok{$}\NormalTok{scores, }\DecValTok{2}\NormalTok{, var)}
-\NormalTok{scaled\_variances \textless{}{-}}\StringTok{ }\NormalTok{variances}\OperatorTok{/}\KeywordTok{sum}\NormalTok{(variances)}
-\NormalTok{sumed\_variances \textless{}{-}}\StringTok{ }\KeywordTok{cumsum}\NormalTok{(scaled\_variances)}
-\KeywordTok{round}\NormalTok{(}\KeywordTok{rbind}\NormalTok{(variances, scaled\_variances, sumed\_variances), }\DecValTok{3}\NormalTok{)}
+\DocumentationTok{\#\# Or the same operation but manually}
+\NormalTok{variances }\OtherTok{\textless{}{-}} \FunctionTok{apply}\NormalTok{(ordination}\SpecialCharTok{$}\NormalTok{scores, }\DecValTok{2}\NormalTok{, var)}
+\NormalTok{scaled\_variances }\OtherTok{\textless{}{-}}\NormalTok{ variances}\SpecialCharTok{/}\FunctionTok{sum}\NormalTok{(variances)}
+\NormalTok{sumed\_variances }\OtherTok{\textless{}{-}} \FunctionTok{cumsum}\NormalTok{(scaled\_variances)}
+\FunctionTok{round}\NormalTok{(}\FunctionTok{rbind}\NormalTok{(variances, scaled\_variances, sumed\_variances), }\DecValTok{3}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -6580,8 +6552,8 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Same operation automatised}
-\NormalTok{(selected \textless{}{-}}\StringTok{ }\KeywordTok{select.axes}\NormalTok{(ordination))}
+\DocumentationTok{\#\# Same operation automatised}
+\NormalTok{(selected }\OtherTok{\textless{}{-}} \FunctionTok{select.axes}\NormalTok{(ordination))}
\end{Highlighting}
\end{Shaded}
@@ -6594,8 +6566,8 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising this info}
-\KeywordTok{summary}\NormalTok{(selected)}
+\DocumentationTok{\#\# Summarising this info}
+\FunctionTok{summary}\NormalTok{(selected)}
\end{Highlighting}
\end{Shaded}
@@ -6608,18 +6580,18 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting it}
-\KeywordTok{plot}\NormalTok{(selected)}
+\DocumentationTok{\#\# Plotting it}
+\FunctionTok{plot}\NormalTok{(selected)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-170-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-178-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Extracting the dimensions}
-\CommentTok{\#\# (for the dispRity function for example)}
-\NormalTok{selected}\OperatorTok{$}\NormalTok{dimensions}
+\DocumentationTok{\#\# Extracting the dimensions}
+\DocumentationTok{\#\# (for the dispRity function for example)}
+\NormalTok{selected}\SpecialCharTok{$}\NormalTok{dimensions}
\end{Highlighting}
\end{Shaded}
@@ -6637,22 +6609,22 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating some groups of stats}
-\NormalTok{states\_groups \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(}\StringTok{"Group1"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Mississippi"}\NormalTok{,}\StringTok{"North Carolina"}\NormalTok{,}
+\DocumentationTok{\#\# Creating some groups of stats}
+\NormalTok{states\_groups }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}\StringTok{"Group1"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Mississippi"}\NormalTok{,}\StringTok{"North Carolina"}\NormalTok{,}
\StringTok{"South Carolina"}\NormalTok{, }\StringTok{"Georgia"}\NormalTok{, }\StringTok{"Alabama"}\NormalTok{,}
\StringTok{"Alaska"}\NormalTok{, }\StringTok{"Tennessee"}\NormalTok{, }\StringTok{"Louisiana"}\NormalTok{),}
- \StringTok{"Group2"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Florida"}\NormalTok{, }\StringTok{"New Mexico"}\NormalTok{, }\StringTok{"Michigan"}\NormalTok{,}
+ \StringTok{"Group2"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Florida"}\NormalTok{, }\StringTok{"New Mexico"}\NormalTok{, }\StringTok{"Michigan"}\NormalTok{,}
\StringTok{"Indiana"}\NormalTok{, }\StringTok{"Virginia"}\NormalTok{, }\StringTok{"Wyoming"}\NormalTok{, }\StringTok{"Montana"}\NormalTok{,}
\StringTok{"Maine"}\NormalTok{, }\StringTok{"Idaho"}\NormalTok{, }\StringTok{"New Hampshire"}\NormalTok{, }\StringTok{"Iowa"}\NormalTok{),}
- \StringTok{"Group3"}\NormalTok{ =}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"Rhode Island"}\NormalTok{, }\StringTok{"New Jersey"}\NormalTok{, }\StringTok{"Hawaii"}\NormalTok{, }\StringTok{"Massachusetts"}\NormalTok{))}
-\CommentTok{\#\# Running the same analyses but per groups}
-\NormalTok{selected \textless{}{-}}\StringTok{ }\KeywordTok{select.axes}\NormalTok{(ordination, }\DataTypeTok{group =}\NormalTok{ states\_groups, }\DataTypeTok{threshold =} \FloatTok{0.9}\NormalTok{)}
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{plot}\NormalTok{(selected)}
+ \StringTok{"Group3"} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"Rhode Island"}\NormalTok{, }\StringTok{"New Jersey"}\NormalTok{, }\StringTok{"Hawaii"}\NormalTok{, }\StringTok{"Massachusetts"}\NormalTok{))}
+\DocumentationTok{\#\# Running the same analyses but per groups}
+\NormalTok{selected }\OtherTok{\textless{}{-}} \FunctionTok{select.axes}\NormalTok{(ordination, }\AttributeTok{group =}\NormalTok{ states\_groups, }\AttributeTok{threshold =} \FloatTok{0.9}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{plot}\NormalTok{(selected)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-171-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-179-1.pdf}
As you can see here, the whole space requires the three first axes to explain at least 90\% of the variance (in fact, 95\% as seen before).
However, different groups have a different story!
@@ -6663,10 +6635,10 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the dispRity package demo data}
-\KeywordTok{data}\NormalTok{(demo\_data)}
-\CommentTok{\#\# A dispRity object with two groups}
-\NormalTok{demo\_data}\OperatorTok{$}\NormalTok{hopkins}
+\DocumentationTok{\#\# Loading the dispRity package demo data}
+\FunctionTok{data}\NormalTok{(demo\_data)}
+\DocumentationTok{\#\# A dispRity object with two groups}
+\NormalTok{demo\_data}\SpecialCharTok{$}\NormalTok{hopkins}
\end{Highlighting}
\end{Shaded}
@@ -6678,18 +6650,18 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Selecting axes on a dispRity object}
-\NormalTok{selected \textless{}{-}}\StringTok{ }\KeywordTok{select.axes}\NormalTok{(demo\_data}\OperatorTok{$}\NormalTok{hopkins)}
-\KeywordTok{plot}\NormalTok{(selected)}
+\DocumentationTok{\#\# Selecting axes on a dispRity object}
+\NormalTok{selected }\OtherTok{\textless{}{-}} \FunctionTok{select.axes}\NormalTok{(demo\_data}\SpecialCharTok{$}\NormalTok{hopkins)}
+\FunctionTok{plot}\NormalTok{(selected)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-172-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-180-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Displaying which axes are necessary for which group}
-\NormalTok{selected}\OperatorTok{$}\NormalTok{dim.list}
+\DocumentationTok{\#\# Displaying which axes are necessary for which group}
+\NormalTok{selected}\SpecialCharTok{$}\NormalTok{dim.list}
\end{Highlighting}
\end{Shaded}
@@ -6706,11 +6678,63 @@ \section{\texorpdfstring{\texttt{select.axes}}{select.axes}}\label{select.axes}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Note how the whole space needs only 16 axes}
-\CommentTok{\#\# but both groups need 22 and 23 axes}
+\DocumentationTok{\#\# Note how the whole space needs only 16 axes}
+\DocumentationTok{\#\# but both groups need 22 and 23 axes}
\end{Highlighting}
\end{Shaded}
+\hypertarget{set.root.time}{%
+\section{\texorpdfstring{\texttt{set.root.time}}{set.root.time}}\label{set.root.time}}
+
+This function can be used to easily add a \texttt{\$root.time} element to \texttt{"phylo"} or \texttt{"multiPhylo"} objects.
+This \texttt{\$root.time} element is used by \texttt{dispRity} and several packages (e.g.~\texttt{Claddis} and \texttt{paleotree}) to scale the branch length units of a tree allowing them to be usually expressed in million of years (Mya).
+
+For example, on a standard random tree, no \texttt{\$root.time} exist so the edge lengths are not expressed in any specific unit:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# A random tree with no root.time}
+\NormalTok{my\_tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)}
+\NormalTok{my\_tree}\SpecialCharTok{$}\NormalTok{root.time }\CommentTok{\# is NULL}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{verbatim}
+## NULL
+\end{verbatim}
+
+You can add a root time by either manually setting it:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Adding an arbitrary root time}
+\NormalTok{my\_tree\_arbitrary }\OtherTok{\textless{}{-}}\NormalTok{ my\_tree}
+\DocumentationTok{\#\# Setting the age of the root to 42}
+\NormalTok{my\_tree\_arbitrary}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \DecValTok{42}
+\end{Highlighting}
+\end{Shaded}
+
+Or by calculating it automatically from the cumulated branch length information (making the youngest tip age 0 and the oldest the total age/depth of the tree)
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Calculating the root time from the present}
+\NormalTok{my\_tree\_aged }\OtherTok{\textless{}{-}}\NormalTok{ my\_tree }
+\NormalTok{my\_tree\_aged }\OtherTok{\textless{}{-}} \FunctionTok{set.root.time}\NormalTok{(my\_tree)}
+\end{Highlighting}
+\end{Shaded}
+
+If you want the youngest tip to not be of age 0, you can define an arbitrary age for it and recalculate the age of the root from there using the \texttt{present} argument (say the youngest tip is 42 Mya old):
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Caculating the root time from 42 Mya }
+\NormalTok{my\_tree\_age }\OtherTok{\textless{}{-}} \FunctionTok{set.root.time}\NormalTok{(my\_tree, }\AttributeTok{present =} \DecValTok{42}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
+This function also works with a distribution of trees (\texttt{"multiPhylo"}).
+
\hypertarget{slice.tree}{%
\section{\texorpdfstring{\texttt{slice.tree}}{slice.tree}}\label{slice.tree}}
@@ -6722,27 +6746,27 @@ \section{\texorpdfstring{\texttt{slice.tree}}{slice.tree}}\label{slice.tree}}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# Generate a random ultrametric tree}
-\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{20}\NormalTok{)}
-\CommentTok{\#\# Add some node labels}
-\NormalTok{tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\NormalTok{letters[}\DecValTok{1}\OperatorTok{:}\DecValTok{19}\NormalTok{]}
-\CommentTok{\#\# Add its root time}
-\NormalTok{tree}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{ages)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Generate a random ultrametric tree}
+\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{20}\NormalTok{)}
+\DocumentationTok{\#\# Add some node labels}
+\NormalTok{tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}}\NormalTok{ letters[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{19}\NormalTok{]}
+\DocumentationTok{\#\# Add its root time}
+\NormalTok{tree}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{ages)}
-\CommentTok{\#\# Slicing the tree at age 0.75}
-\NormalTok{tree\_}\DecValTok{75}\NormalTok{ \textless{}{-}}\StringTok{ }\KeywordTok{slice.tree}\NormalTok{(tree, }\DataTypeTok{age =} \FloatTok{0.75}\NormalTok{, }\StringTok{"acctran"}\NormalTok{)}
+\DocumentationTok{\#\# Slicing the tree at age 0.75}
+\NormalTok{tree\_75 }\OtherTok{\textless{}{-}} \FunctionTok{slice.tree}\NormalTok{(tree, }\AttributeTok{age =} \FloatTok{0.75}\NormalTok{, }\StringTok{"acctran"}\NormalTok{)}
-\CommentTok{\#\# Showing both trees}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{)}
-\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{(tree}\OperatorTok{$}\NormalTok{node.label, }\DataTypeTok{cex =} \FloatTok{0.8}\NormalTok{)}
-\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ (}\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{ages) }\OperatorTok{{-}}\StringTok{ }\FloatTok{0.75}\NormalTok{), }\DataTypeTok{col =} \StringTok{"red"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(tree\_}\DecValTok{75}\NormalTok{, }\DataTypeTok{main =} \StringTok{"sliced tree"}\NormalTok{)}
+\DocumentationTok{\#\# Showing both trees}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{)}
+\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{node.label, }\AttributeTok{cex =} \FloatTok{0.8}\NormalTok{)}
+\FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ (}\FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{ages) }\SpecialCharTok{{-}} \FloatTok{0.75}\NormalTok{), }\AttributeTok{col =} \StringTok{"red"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(tree\_75, }\AttributeTok{main =} \StringTok{"sliced tree"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-173-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-185-1.pdf}
\hypertarget{slide.nodes-and-remove.zero.brlen}{%
\section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{slide.nodes and remove.zero.brlen}}\label{slide.nodes-and-remove.zero.brlen}}
@@ -6757,23 +6781,23 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
-\CommentTok{\#\# Generating simple coalescent tree}
-\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{5}\NormalTok{)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
+\DocumentationTok{\#\# Generating simple coalescent tree}
+\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{5}\NormalTok{)}
-\CommentTok{\#\# Sliding node 8 up and down}
-\NormalTok{tree\_slide\_up \textless{}{-}}\StringTok{ }\KeywordTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\DataTypeTok{slide =} \FloatTok{0.075}\NormalTok{)}
-\NormalTok{tree\_slide\_down \textless{}{-}}\StringTok{ }\KeywordTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\DataTypeTok{slide =} \FloatTok{{-}0.075}\NormalTok{)}
+\DocumentationTok{\#\# Sliding node 8 up and down}
+\NormalTok{tree\_slide\_up }\OtherTok{\textless{}{-}} \FunctionTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\AttributeTok{slide =} \FloatTok{0.075}\NormalTok{)}
+\NormalTok{tree\_slide\_down }\OtherTok{\textless{}{-}} \FunctionTok{slide.nodes}\NormalTok{(}\DecValTok{8}\NormalTok{, tree, }\AttributeTok{slide =} \SpecialCharTok{{-}}\FloatTok{0.075}\NormalTok{)}
-\CommentTok{\#\# Display the results}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{) ; }\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{()}
-\KeywordTok{plot}\NormalTok{(tree\_slide\_up, }\DataTypeTok{main =} \StringTok{"slide up!"}\NormalTok{) ; }\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{()}
-\KeywordTok{plot}\NormalTok{(tree\_slide\_down, }\DataTypeTok{main =} \StringTok{"slide down!"}\NormalTok{) ; }\KeywordTok{axisPhylo}\NormalTok{() ; }\KeywordTok{nodelabels}\NormalTok{()}
+\DocumentationTok{\#\# Display the results}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{) ; }\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{()}
+\FunctionTok{plot}\NormalTok{(tree\_slide\_up, }\AttributeTok{main =} \StringTok{"slide up!"}\NormalTok{) ; }\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{()}
+\FunctionTok{plot}\NormalTok{(tree\_slide\_down, }\AttributeTok{main =} \StringTok{"slide down!"}\NormalTok{) ; }\FunctionTok{axisPhylo}\NormalTok{() ; }\FunctionTok{nodelabels}\NormalTok{()}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-174-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-186-1.pdf}
The \texttt{remove.zero.brlen} is a ``clever'' wrapping function that uses the \texttt{slide.nodes} function to stochastically remove zero branch lengths across a whole tree.
This function will slide nodes up or down in successive postorder traversals (i.e.~going down the tree clade by clade) in order to minimise the number of nodes to slide while making sure there are no silly negative branch lengths produced!
@@ -6781,21 +6805,21 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
-\CommentTok{\#\# Generating a tree}
-\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
+\DocumentationTok{\#\# Generating a tree}
+\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{20}\NormalTok{)}
-\CommentTok{\#\# Adding some zero branch lengths (5)}
-\NormalTok{tree}\OperatorTok{$}\NormalTok{edge.length[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{Nedge}\NormalTok{(tree), }\DecValTok{5}\NormalTok{)] \textless{}{-}}\StringTok{ }\DecValTok{0}
+\DocumentationTok{\#\# Adding some zero branch lengths (5)}
+\NormalTok{tree}\SpecialCharTok{$}\NormalTok{edge.length[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Nedge}\NormalTok{(tree), }\DecValTok{5}\NormalTok{)] }\OtherTok{\textless{}{-}} \DecValTok{0}
-\CommentTok{\#\# And now removing these zero branch lengths!}
-\NormalTok{tree\_no\_zero \textless{}{-}}\StringTok{ }\KeywordTok{remove.zero.brlen}\NormalTok{(tree)}
+\DocumentationTok{\#\# And now removing these zero branch lengths!}
+\NormalTok{tree\_no\_zero }\OtherTok{\textless{}{-}} \FunctionTok{remove.zero.brlen}\NormalTok{(tree)}
-\CommentTok{\#\# Exaggerating the removal (to make it visible)}
-\NormalTok{tree\_exaggerated \textless{}{-}}\StringTok{ }\KeywordTok{remove.zero.brlen}\NormalTok{(tree, }\DataTypeTok{slide =} \DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Exaggerating the removal (to make it visible)}
+\NormalTok{tree\_exaggerated }\OtherTok{\textless{}{-}} \FunctionTok{remove.zero.brlen}\NormalTok{(tree, }\AttributeTok{slide =} \DecValTok{1}\NormalTok{)}
-\CommentTok{\#\# Check the differences}
-\KeywordTok{any}\NormalTok{(tree}\OperatorTok{$}\NormalTok{edge.length }\OperatorTok{==}\StringTok{ }\DecValTok{0}\NormalTok{)}
+\DocumentationTok{\#\# Check the differences}
+\FunctionTok{any}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{edge.length }\SpecialCharTok{==} \DecValTok{0}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -6805,7 +6829,7 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{any}\NormalTok{(tree\_no\_zero}\OperatorTok{$}\NormalTok{edge.length }\OperatorTok{==}\StringTok{ }\DecValTok{0}\NormalTok{)}
+\FunctionTok{any}\NormalTok{(tree\_no\_zero}\SpecialCharTok{$}\NormalTok{edge.length }\SpecialCharTok{==} \DecValTok{0}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -6815,7 +6839,7 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{any}\NormalTok{(tree\_exaggerated}\OperatorTok{$}\NormalTok{edge.length }\OperatorTok{==}\StringTok{ }\DecValTok{0}\NormalTok{)}
+\FunctionTok{any}\NormalTok{(tree\_exaggerated}\SpecialCharTok{$}\NormalTok{edge.length }\SpecialCharTok{==} \DecValTok{0}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -6825,15 +6849,15 @@ \section{\texorpdfstring{\texttt{slide.nodes} and \texttt{remove.zero.brlen}}{sl
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Display the results}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(tree, }\DataTypeTok{main =} \StringTok{"with zero edges"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(tree\_no\_zero, }\DataTypeTok{main =} \StringTok{"without zero edges!"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(tree\_exaggerated, }\DataTypeTok{main =} \StringTok{"with longer edges"}\NormalTok{)}
+\DocumentationTok{\#\# Display the results}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{3}\NormalTok{,}\DecValTok{1}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(tree, }\AttributeTok{main =} \StringTok{"with zero edges"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(tree\_no\_zero, }\AttributeTok{main =} \StringTok{"without zero edges!"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(tree\_exaggerated, }\AttributeTok{main =} \StringTok{"with longer edges"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-175-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-187-1.pdf}
\hypertarget{tree.age}{%
\section{\texorpdfstring{\texttt{tree.age}}{tree.age}}\label{tree.age}}
@@ -6842,104 +6866,104 @@ \section{\texorpdfstring{\texttt{tree.age}}{tree.age}}\label{tree.age}}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
-\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)}
-\CommentTok{\#\# The tree age from a 10 tip tree}
-\KeywordTok{tree.age}\NormalTok{(tree)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# The tree age from a 10 tip tree}
+\FunctionTok{tree.age}\NormalTok{(tree)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## ages elements
-## 1 0.707 t7
-## 2 0.142 t2
-## 3 0.000 t3
-## 4 1.467 t8
-## 5 1.366 t1
-## 6 1.895 t5
-## 7 1.536 t6
-## 8 1.456 t9
-## 9 0.815 t10
-## 10 2.343 t4
-## 11 3.011 11
-## 12 2.631 12
-## 13 1.854 13
-## 14 0.919 14
-## 15 0.267 15
-## 16 2.618 16
-## 17 2.235 17
-## 18 2.136 18
-## 19 1.642 19
+## ages elements
+## 1 0.7068 t7
+## 2 0.1417 t2
+## 3 0.0000 t3
+## 4 1.4675 t8
+## 5 1.3656 t1
+## 6 1.8949 t5
+## 7 1.5360 t6
+## 8 1.4558 t9
+## 9 0.8147 t10
+## 10 2.3426 t4
+## 11 3.0111 11
+## 12 2.6310 12
+## 13 1.8536 13
+## 14 0.9189 14
+## 15 0.2672 15
+## 16 2.6177 16
+## 17 2.2353 17
+## 18 2.1356 18
+## 19 1.6420 19
\end{verbatim}
It also allows to set the age of the root of the tree:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The ages starting from {-}100 units}
-\KeywordTok{tree.age}\NormalTok{(tree, }\DataTypeTok{age =} \DecValTok{100}\NormalTok{)}
+\DocumentationTok{\#\# The ages starting from {-}100 units}
+\FunctionTok{tree.age}\NormalTok{(tree, }\AttributeTok{age =} \DecValTok{100}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## ages elements
-## 1 23.472 t7
-## 2 4.705 t2
-## 3 0.000 t3
-## 4 48.736 t8
-## 5 45.352 t1
-## 6 62.931 t5
-## 7 51.012 t6
-## 8 48.349 t9
-## 9 27.055 t10
-## 10 77.800 t4
-## 11 100.000 11
-## 12 87.379 12
-## 13 61.559 13
-## 14 30.517 14
-## 15 8.875 15
-## 16 86.934 16
-## 17 74.235 17
-## 18 70.924 18
-## 19 54.533 19
+## ages elements
+## 1 23.4717 t7
+## 2 4.7048 t2
+## 3 0.0000 t3
+## 4 48.7362 t8
+## 5 45.3517 t1
+## 6 62.9315 t5
+## 7 51.0119 t6
+## 8 48.3486 t9
+## 9 27.0554 t10
+## 10 77.7998 t4
+## 11 100.0000 11
+## 12 87.3788 12
+## 13 61.5593 13
+## 14 30.5171 14
+## 15 8.8746 15
+## 16 86.9341 16
+## 17 74.2347 17
+## 18 70.9239 18
+## 19 54.5330 19
\end{verbatim}
Usually tree age is calculated from the present to the past (e.g.~in million years ago) but it is possible to reverse it using the \texttt{order\ =\ present} option:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The ages in terms of tip/node height}
-\KeywordTok{tree.age}\NormalTok{(tree, }\DataTypeTok{order =} \StringTok{"present"}\NormalTok{)}
+\DocumentationTok{\#\# The ages in terms of tip/node height}
+\FunctionTok{tree.age}\NormalTok{(tree, }\AttributeTok{order =} \StringTok{"present"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## ages elements
-## 1 2.304 t7
-## 2 2.869 t2
-## 3 3.011 t3
-## 4 1.544 t8
-## 5 1.646 t1
-## 6 1.116 t5
-## 7 1.475 t6
-## 8 1.555 t9
-## 9 2.196 t10
-## 10 0.668 t4
-## 11 0.000 11
-## 12 0.380 12
-## 13 1.157 13
-## 14 2.092 14
-## 15 2.744 15
-## 16 0.393 16
-## 17 0.776 17
-## 18 0.876 18
-## 19 1.369 19
+## ages elements
+## 1 2.3043 t7
+## 2 2.8694 t2
+## 3 3.0111 t3
+## 4 1.5436 t8
+## 5 1.6455 t1
+## 6 1.1162 t5
+## 7 1.4751 t6
+## 8 1.5553 t9
+## 9 2.1964 t10
+## 10 0.6685 t4
+## 11 0.0000 11
+## 12 0.3800 12
+## 13 1.1575 13
+## 14 2.0922 14
+## 15 2.7439 15
+## 16 0.3934 16
+## 17 0.7758 17
+## 18 0.8755 18
+## 19 1.3690 19
\end{verbatim}
\hypertarget{multi.ace}{%
\section{\texorpdfstring{\texttt{multi.ace}}{multi.ace}}\label{multi.ace}}
-This function allows to run the \texttt{ape::ace} function (ancestral characters estimations) on multiple trees.
+This function allows to run ancestral characters estimations on multiple trees.
In it's most basic structure (e.g.~using all default arguments) this function is using a mix of \texttt{ape::ace} and \texttt{castor::asr\_mk\_model} depending on the data and the situation and is generally faster than both functions when applied to a list of trees.
However, this function provides also some more complex and modular functionalities, especially appropriate when using discrete morphological character data.
@@ -6953,19 +6977,19 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
-\CommentTok{\#\# A random tree with 10 tips}
-\NormalTok{tree \textless{}{-}}\StringTok{ }\KeywordTok{rcoal}\NormalTok{(}\DecValTok{10}\NormalTok{)}
-\CommentTok{\#\# Setting up the parameters}
-\NormalTok{my\_rates =}\StringTok{ }\KeywordTok{c}\NormalTok{(rgamma, }\DataTypeTok{rate =} \DecValTok{10}\NormalTok{, }\DataTypeTok{shape =} \DecValTok{5}\NormalTok{)}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{42}\NormalTok{)}
+\DocumentationTok{\#\# A random tree with 10 tips}
+\NormalTok{tree }\OtherTok{\textless{}{-}} \FunctionTok{rcoal}\NormalTok{(}\DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Setting up the parameters}
+\NormalTok{my\_rates }\OtherTok{=} \FunctionTok{c}\NormalTok{(rgamma, }\AttributeTok{rate =} \DecValTok{10}\NormalTok{, }\AttributeTok{shape =} \DecValTok{5}\NormalTok{)}
-\CommentTok{\#\# Generating a bunch of trees}
-\NormalTok{multiple\_trees \textless{}{-}}\StringTok{ }\KeywordTok{rmtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Generating a bunch of trees}
+\NormalTok{multiple\_trees }\OtherTok{\textless{}{-}} \FunctionTok{rmtree}\NormalTok{(}\DecValTok{5}\NormalTok{, }\DecValTok{10}\NormalTok{)}
-\CommentTok{\#\# A random Mk matrix (10*50)}
-\NormalTok{matrix\_simple \textless{}{-}}\StringTok{ }\KeywordTok{sim.morpho}\NormalTok{(tree, }\DataTypeTok{characters =} \DecValTok{50}\NormalTok{, }\DataTypeTok{model =} \StringTok{"ER"}\NormalTok{, }\DataTypeTok{rates =}\NormalTok{ my\_rates,}
- \DataTypeTok{invariant =} \OtherTok{FALSE}\NormalTok{)}
-\NormalTok{matrix\_simple[}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]}
+\DocumentationTok{\#\# A random Mk matrix (10*50)}
+\NormalTok{matrix\_simple }\OtherTok{\textless{}{-}} \FunctionTok{sim.morpho}\NormalTok{(tree, }\AttributeTok{characters =} \DecValTok{50}\NormalTok{, }\AttributeTok{model =} \StringTok{"ER"}\NormalTok{, }\AttributeTok{rates =}\NormalTok{ my\_rates,}
+ \AttributeTok{invariant =} \ConstantTok{FALSE}\NormalTok{)}
+\NormalTok{matrix\_simple[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
@@ -6989,15 +7013,15 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Modify the matrix to contain missing and special data}
-\NormalTok{matrix\_complex \textless{}{-}}\StringTok{ }\NormalTok{matrix\_simple}
-\CommentTok{\#\# Adding 50 random "{-}" tokens}
-\NormalTok{matrix\_complex[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] \textless{}{-}}\StringTok{ "{-}"}
-\CommentTok{\#\# Adding 50 random "?" tokens}
-\NormalTok{matrix\_complex[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] \textless{}{-}}\StringTok{ "?"}
-\CommentTok{\#\# Adding 50 random "0\%2" tokens}
-\NormalTok{matrix\_complex[}\KeywordTok{sample}\NormalTok{(}\DecValTok{1}\OperatorTok{:}\KeywordTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] \textless{}{-}}\StringTok{ "0\%2"}
-\NormalTok{matrix\_complex[}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{,}\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]}
+\DocumentationTok{\#\# Modify the matrix to contain missing and special data}
+\NormalTok{matrix\_complex }\OtherTok{\textless{}{-}}\NormalTok{ matrix\_simple}
+\DocumentationTok{\#\# Adding 50 random "{-}" tokens}
+\NormalTok{matrix\_complex[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"{-}"}
+\DocumentationTok{\#\# Adding 50 random "?" tokens}
+\NormalTok{matrix\_complex[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"?"}
+\DocumentationTok{\#\# Adding 50 random "0\%2" tokens}
+\NormalTok{matrix\_complex[}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{length}\NormalTok{(matrix\_complex), }\DecValTok{50}\NormalTok{)] }\OtherTok{\textless{}{-}} \StringTok{"0\%2"}
+\NormalTok{matrix\_complex[}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
@@ -7026,12 +7050,12 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The specific token for the missing cases (note the "\textbackslash{}\textbackslash{}" for protecting the value)}
-\NormalTok{special.tokens \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"missing"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{)}
+\DocumentationTok{\#\# The specific token for the missing cases (note the "\textbackslash{}\textbackslash{}" for protecting the value)}
+\NormalTok{special.tokens }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"missing"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{)}
-\CommentTok{\#\# The behaviour for the missing cases (?)}
-\NormalTok{special.behaviour \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(missing \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x, y) }\KeywordTok{return}\NormalTok{(y))}
-\CommentTok{\#\# Where x is the input value (here "?") and y is all the possible normal values for the character}
+\DocumentationTok{\#\# The behaviour for the missing cases (?)}
+\NormalTok{special.behaviour }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(missing }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x, y) }\FunctionTok{return}\NormalTok{(y))}
+\DocumentationTok{\#\# Where x is the input value (here "?") and y is all the possible normal values for the character}
\end{Highlighting}
\end{Shaded}
@@ -7041,12 +7065,12 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Set a list of extra special tokens}
-\NormalTok{my\_spec\_tokens \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"weirdtoken"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\%"}\NormalTok{)}
+\DocumentationTok{\#\# Set a list of extra special tokens}
+\NormalTok{my\_spec\_tokens }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"weirdtoken"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{\%"}\NormalTok{)}
-\CommentTok{\#\# Weird tokens are considered as state 0 and 3}
-\NormalTok{my\_spec\_behaviours \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{()}
-\NormalTok{my\_spec\_behaviours}\OperatorTok{$}\NormalTok{weirdtoken \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{return}\NormalTok{(}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# Weird tokens are considered as state 0 and 3}
+\NormalTok{my\_spec\_behaviours }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{()}
+\NormalTok{my\_spec\_behaviours}\SpecialCharTok{$}\NormalTok{weirdtoken }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{return}\NormalTok{(}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -7054,14 +7078,14 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The token for missing values:}
-\NormalTok{default\_tokens \textless{}{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\StringTok{"missing"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{,}
-\CommentTok{\#\# The token for inapplicable values: }
- \StringTok{"inapplicable"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{{-}"}\NormalTok{,}
-\CommentTok{\#\# The token for polymorphisms:}
- \StringTok{"polymorphism"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{,}
-\CommentTok{\#\# The token for uncertainties:}
- \StringTok{"uncertanity"}\NormalTok{ =}\StringTok{ "}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{/"}\NormalTok{)}
+\DocumentationTok{\#\# The token for missing values:}
+\NormalTok{default\_tokens }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"missing"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{?"}\NormalTok{,}
+\DocumentationTok{\#\# The token for inapplicable values: }
+ \StringTok{"inapplicable"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{{-}"}\NormalTok{,}
+\DocumentationTok{\#\# The token for polymorphisms:}
+ \StringTok{"polymorphism"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{,}
+\DocumentationTok{\#\# The token for uncertainties:}
+ \StringTok{"uncertanity"} \OtherTok{=} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{/"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -7069,14 +7093,14 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Treating missing data as all data values}
-\NormalTok{default\_behaviour \textless{}{-}}\StringTok{ }\KeywordTok{list}\NormalTok{(missing \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) y,}
-\CommentTok{\#\# Treating inapplicable data as all data values (like missing) }
-\NormalTok{ inapplicable \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x, y) y,}
-\CommentTok{\#\# Treating polymorphisms as all values present:}
-\NormalTok{ polymorphism \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{strsplit}\NormalTok{(x, }\DataTypeTok{split =} \StringTok{"}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]],}
-\CommentTok{\#\# Treating uncertainties as all values present (like polymorphisms):}
-\NormalTok{ uncertanity \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(x,y) }\KeywordTok{strsplit}\NormalTok{(x, }\DataTypeTok{split =} \StringTok{"}\CharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]])}
+\DocumentationTok{\#\# Treating missing data as all data values}
+\NormalTok{default\_behaviour }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(missing }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) y,}
+\DocumentationTok{\#\# Treating inapplicable data as all data values (like missing) }
+\NormalTok{ inapplicable }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x, y) y,}
+\DocumentationTok{\#\# Treating polymorphisms as all values present:}
+\NormalTok{ polymorphism }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{strsplit}\NormalTok{(x, }\AttributeTok{split =} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{\&"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]],}
+\DocumentationTok{\#\# Treating uncertainties as all values present (like polymorphisms):}
+\NormalTok{ uncertanity }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,y) }\FunctionTok{strsplit}\NormalTok{(x, }\AttributeTok{split =} \StringTok{"}\SpecialCharTok{\textbackslash{}\textbackslash{}}\StringTok{/"}\NormalTok{)[[}\DecValTok{1}\NormalTok{]])}
\end{Highlighting}
\end{Shaded}
@@ -7084,11 +7108,11 @@ \subsection{Using different character tokens in different situations}\label{usin
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Running ancestral states}
-\NormalTok{ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,}
- \DataTypeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,}
- \DataTypeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,}
- \DataTypeTok{verbose =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Running ancestral states}
+\NormalTok{ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,}
+ \AttributeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,}
+ \AttributeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,}
+ \AttributeTok{verbose =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -7097,93 +7121,34 @@ \subsection{Using different character tokens in different situations}\label{usin
\end{verbatim}
\begin{verbatim}
-## Warning: The characters 39 are invariant (using the current special behaviours
-## for special characters) and are simply duplicated for each node.
+## Warning: The character 39 is invariant (using the current special behaviours
+## for special characters) and is simply duplicated for each node.
\end{verbatim}
\begin{verbatim}
## ..Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
-
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
-
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
-
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
-
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
-
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
-
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
-
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
-
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
-
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
-
-\begin{verbatim}
-## Done.
+## Running ancestral states estimations:.....................................................................................................................................................................................................................................................Done.
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# This outputs a list of ancestral parts of the matrices for each tree}
-\CommentTok{\#\# For example, here\textquotesingle{}s the first one:}
-\NormalTok{ancestral\_states[[}\DecValTok{1}\NormalTok{]][}\DecValTok{1}\OperatorTok{:}\DecValTok{9}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\DecValTok{10}\NormalTok{]}
+\DocumentationTok{\#\# This outputs a list of ancestral parts of the matrices for each tree}
+\DocumentationTok{\#\# For example, here\textquotesingle{}s the first one:}
+\NormalTok{ancestral\_states[[}\DecValTok{1}\NormalTok{]][}\DecValTok{1}\SpecialCharTok{:}\DecValTok{9}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\DecValTok{10}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
-## [1,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
-## [2,] "1" "1" "1" "1" "0/1" "0/1/2" "0/1" "0" "0" "1"
-## [3,] "1" "1" "1" "1" "0/1" "0/1/2" "0" "0" "0" "1"
-## [4,] "1" "1" "1" "1" "0" "0/1/2" "1" "1" "0" "1"
-## [5,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
-## [6,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
-## [7,] "0" "0/1" "0/1" "0" "1" "1" "1" "0" "0" "0/1"
-## [8,] "0" "0" "0" "0" "1" "0/1/2" "0" "0" "1" "0"
-## [9,] "0" "0" "0" "0" "1" "1" "0" "0" "1" "0"
+## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
+## n1 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
+## n2 "1" "1" "1" "1" "0/1" "0/1/2" "0/1" "0" "0" "1"
+## n3 "1" "1" "1" "1" "0/1" "0/1/2" "0" "0" "0" "1"
+## n4 "1" "1" "1" "1" "0" "0/1/2" "1" "1" "0" "1"
+## n5 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
+## n6 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
+## n7 "0" "0/1" "0/1" "0" "1" "1" "1" "0" "0" "0/1"
+## n8 "0" "0" "0" "0" "1" "0/1/2" "0" "0" "1" "0"
+## n9 "0" "0" "0" "0" "1" "1" "0" "0" "1" "0"
\end{verbatim}
Note that there are many different options that are not covered here.
@@ -7192,20 +7157,20 @@ \subsection{Using different character tokens in different situations}\label{usin
\hypertarget{feeding-the-results-to-char.diff-to-get-distance-matrices}{%
\subsection{\texorpdfstring{Feeding the results to \texttt{char.diff} to get distance matrices}{Feeding the results to char.diff to get distance matrices}}\label{feeding-the-results-to-char.diff-to-get-distance-matrices}}
-Finally, after running your ancestral states estimations, it is not uncommon to then use these resulting data to calculate the distances between taxa and then ordinate the results to measure disparity.
+After running your ancestral states estimations, it is not uncommon to then use these resulting data to calculate the distances between taxa and then ordinate the results to measure disparity.
You can do that using the \texttt{char.diff} function \protect\hyperlink{char.diff}{described above} but instead of measuring the distances between characters (columns) you can measure the distances between species (rows).
You might notice that this function uses the same modular token and behaviour descriptions.
That makes sense because they're using the same core C functions implemented in dispRity that greatly speed up distance calculations.
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Running ancestral states}
-\CommentTok{\#\# and outputing a list of combined matrices (tips and nodes)}
-\NormalTok{ancestral\_states \textless{}{-}}\StringTok{ }\KeywordTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,}
- \DataTypeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,}
- \DataTypeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,}
- \DataTypeTok{output =} \StringTok{"combined.matrix"}\NormalTok{,}
- \DataTypeTok{verbose =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Running ancestral states}
+\DocumentationTok{\#\# and outputing a list of combined matrices (tips and nodes)}
+\NormalTok{ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(matrix\_complex, multiple\_trees,}
+ \AttributeTok{special.tokens =}\NormalTok{ my\_spec\_tokens,}
+ \AttributeTok{special.behaviours =}\NormalTok{ my\_spec\_behaviours,}
+ \AttributeTok{output =} \StringTok{"combined.matrix"}\NormalTok{,}
+ \AttributeTok{verbose =} \ConstantTok{TRUE}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -7214,84 +7179,170 @@ \subsection{\texorpdfstring{Feeding the results to \texttt{char.diff} to get dis
\end{verbatim}
\begin{verbatim}
-## Warning: The characters 39 are invariant (using the current special behaviours
-## for special characters) and are simply duplicated for each node.
+## Warning: The character 39 is invariant (using the current special behaviours
+## for special characters) and is simply duplicated for each node.
\end{verbatim}
\begin{verbatim}
## ..Done.
-## Running ancestral states estimations:
-## .................................................
+## Running ancestral states estimations:.....................................................................................................................................................................................................................................................Done.
\end{verbatim}
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
+We can then feed these matrices directly to \texttt{char.diff}, say for calculating the ``MORD'' distance:
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Measuring the distances between rows using the MORD distance}
+\NormalTok{distances }\OtherTok{\textless{}{-}} \FunctionTok{lapply}\NormalTok{(ancestral\_states, char.diff, }\AttributeTok{method =} \StringTok{"mord"}\NormalTok{, }\AttributeTok{by.col =} \ConstantTok{FALSE}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
+And we now have a list of distances matrices with ancestral states estimated!
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
+\hypertarget{running-ancestral-states-estimations-for-continuous-characters}{%
+\subsection{Running ancestral states estimations for continuous characters}\label{running-ancestral-states-estimations-for-continuous-characters}}
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
+You can also run \texttt{multi.ace} on continuous characters.
+The function detects any continuous characters as being of class \texttt{"numeric"} and runs them using the \texttt{ape::ace} function.
-\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
-\end{verbatim}
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{1}\NormalTok{)}
+\DocumentationTok{\#\# Creating three coalescent trees}
+\NormalTok{my\_trees }\OtherTok{\textless{}{-}} \FunctionTok{replicate}\NormalTok{(}\DecValTok{3}\NormalTok{, }\FunctionTok{rcoal}\NormalTok{(}\DecValTok{15}\NormalTok{), }\AttributeTok{simplify =} \ConstantTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Adding node labels}
+\NormalTok{my\_trees }\OtherTok{\textless{}{-}} \FunctionTok{lapply}\NormalTok{(my\_trees, makeNodeLabel)}
+\DocumentationTok{\#\# Making into a multiPhylo object}
+\FunctionTok{class}\NormalTok{(my\_trees) }\OtherTok{\textless{}{-}} \StringTok{"multiPhylo"}
-\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-\end{verbatim}
+\DocumentationTok{\#\# Creating a matrix of continuous characters}
+\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\AttributeTok{elements =} \DecValTok{15}\NormalTok{, }\AttributeTok{dimensions =} \DecValTok{5}\NormalTok{, }\AttributeTok{distribution =}\NormalTok{ rnorm,}
+ \AttributeTok{elements.name =}\NormalTok{ my\_trees[[}\DecValTok{1}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{tip.label)}
+\end{Highlighting}
+\end{Shaded}
+
+With such data and trees you can easily run the \texttt{multi.ace} estimations.
+By default, the estimations use the default arguments from \texttt{ape::ace}, knowingly a Brownian Motion (\texttt{model\ =\ "BM"}) with the REML method (\texttt{method\ =\ "REML"}; this method ``first estimates the ancestral value at the root (aka, the phylogenetic mean), then the variance of the Brownian motion process is estimated by optimizing the residual log-likelihood'' - from \texttt{?ape::ace}).
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Running multi.ace on continuous data}
+\NormalTok{my\_ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(data, my\_trees)}
+\end{Highlighting}
+\end{Shaded}
\begin{verbatim}
-## Done.
-## Running ancestral states estimations:
-## .................................................
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
\end{verbatim}
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# We end up with three matrices of node states estimates}
+\FunctionTok{str}\NormalTok{(my\_ancestral\_states)}
+\end{Highlighting}
+\end{Shaded}
+
\begin{verbatim}
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
+## List of 3
+## $ : num [1:14, 1:5] -0.191 -0.155 -0.227 -0.17 0.138 ...
+## ..- attr(*, "dimnames")=List of 2
+## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ...
+## .. ..$ : NULL
+## $ : num [1:14, 1:5] -0.385 -0.552 -0.445 -0.435 -0.478 ...
+## ..- attr(*, "dimnames")=List of 2
+## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ...
+## .. ..$ : NULL
+## $ : num [1:14, 1:5] -0.3866 -0.2232 -0.0592 -0.7246 -0.2253 ...
+## ..- attr(*, "dimnames")=List of 2
+## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ...
+## .. ..$ : NULL
\end{verbatim}
+This results in three matrices with ancestral states for the nodes.
+When using continuous characters, however, you can output the results directly as a \texttt{dispRity} object that allows visualisation and other normal dispRity pipeline:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# Running multi.ace on continuous data}
+\NormalTok{my\_ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(data, my\_trees, }\AttributeTok{output =} \StringTok{"dispRity"}\NormalTok{)}
+\end{Highlighting}
+\end{Shaded}
+
\begin{verbatim}
-## Done.
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
\end{verbatim}
-We can then feed these matrices directly to \texttt{char.diff}, say for calculating the ``MORD'' distance:
+\begin{Shaded}
+\begin{Highlighting}[]
+\DocumentationTok{\#\# We end up with three matrices of node states estimates}
+\FunctionTok{plot}\NormalTok{(my\_ancestral\_states)}
+\end{Highlighting}
+\end{Shaded}
+
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-202-1.pdf}
+
+You can also mix continuous and discrete characters together.
+By default the \texttt{multi.ace} detects which character is of which type and applies the correct estimations based on that.
+However you can always specify models or other details character per characters.
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the distances between rows using the MORD distance}
-\NormalTok{distances \textless{}{-}}\StringTok{ }\KeywordTok{lapply}\NormalTok{(ancestral\_states, char.diff, }\DataTypeTok{method =} \StringTok{"mord"}\NormalTok{, }\DataTypeTok{by.col =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Adding two discrete characters}
+\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{as.data.frame}\NormalTok{(data)}
+\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{cbind}\NormalTok{(data, }\StringTok{"new\_char"} \OtherTok{=} \FunctionTok{as.character}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{, }\DecValTok{15}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{)))}
+\NormalTok{data }\OtherTok{\textless{}{-}} \FunctionTok{cbind}\NormalTok{(data, }\StringTok{"new\_char2"} \OtherTok{=} \FunctionTok{as.character}\NormalTok{(}\FunctionTok{sample}\NormalTok{(}\DecValTok{1}\SpecialCharTok{:}\DecValTok{2}\NormalTok{, }\DecValTok{15}\NormalTok{, }\AttributeTok{replace =} \ConstantTok{TRUE}\NormalTok{)))}
+
+\DocumentationTok{\#\# Setting up different models for each characters}
+\DocumentationTok{\#\# BM for all 5 continuous characters}
+\DocumentationTok{\#\# and ER and ARD for the two discrete ones}
+\NormalTok{my\_models }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\StringTok{"BM"}\NormalTok{, }\DecValTok{5}\NormalTok{), }\StringTok{"ER"}\NormalTok{, }\StringTok{"ARD"}\NormalTok{)}
+
+\DocumentationTok{\#\# Running the estimation with the specified models}
+\NormalTok{my\_ancestral\_states }\OtherTok{\textless{}{-}} \FunctionTok{multi.ace}\NormalTok{(data, my\_trees, }\AttributeTok{models =}\NormalTok{ my\_models)}
\end{Highlighting}
\end{Shaded}
-And we now have a list of distances matrices with ancestral states estimated!
+\begin{verbatim}
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+\end{verbatim}
+
+Of course all the options discussed in the first part above also can apply here!
\hypertarget{the-guts-of-the-disprity-package}{%
\chapter{\texorpdfstring{The guts of the \texttt{dispRity} package}{The guts of the dispRity package}}\label{the-guts-of-the-disprity-package}}
@@ -7310,11 +7361,11 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading the example data}
-\KeywordTok{data}\NormalTok{(disparity)}
+\DocumentationTok{\#\# Loading the example data}
+\FunctionTok{data}\NormalTok{(disparity)}
-\CommentTok{\#\# What is the class of the median\_centroids object?}
-\KeywordTok{class}\NormalTok{(disparity)}
+\DocumentationTok{\#\# What is the class of the median\_centroids object?}
+\FunctionTok{class}\NormalTok{(disparity)}
\end{Highlighting}
\end{Shaded}
@@ -7324,8 +7375,8 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# What does the object contain?}
-\KeywordTok{names}\NormalTok{(disparity)}
+\DocumentationTok{\#\# What does the object contain?}
+\FunctionTok{names}\NormalTok{(disparity)}
\end{Highlighting}
\end{Shaded}
@@ -7335,7 +7386,7 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising it using the S3 method print.dispRity}
+\DocumentationTok{\#\# Summarising it using the S3 method print.dispRity}
\NormalTok{disparity}
\end{Highlighting}
\end{Shaded}
@@ -7344,7 +7395,7 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di
## ---- dispRity object ----
## 7 continuous (acctran) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
## 90, 80, 70, 60, 50 ...
-## Data was bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements.
+## Rows were bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements.
## Disparity was calculated as: c(median, centroids).
\end{verbatim}
@@ -7352,9 +7403,9 @@ \section{\texorpdfstring{Manipulating \texttt{dispRity} objects}{Manipulating di
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Display the full object}
-\KeywordTok{print}\NormalTok{(disparity, }\DataTypeTok{all =} \OtherTok{TRUE}\NormalTok{)}
-\CommentTok{\#\# This is more nearly \textasciitilde{} 5000 lines on my 13 inch laptop screen!}
+\DocumentationTok{\#\# Display the full object}
+\FunctionTok{print}\NormalTok{(disparity, }\AttributeTok{all =} \ConstantTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# This is more nearly \textasciitilde{} 5000 lines on my 13 inch laptop screen!}
\end{Highlighting}
\end{Shaded}
@@ -7375,8 +7426,8 @@ \subsubsection{\texorpdfstring{\texttt{make.dispRity}}{make.dispRity}}\label{mak
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating an empty dispRity object}
-\KeywordTok{make.dispRity}\NormalTok{()}
+\DocumentationTok{\#\# Creating an empty dispRity object}
+\FunctionTok{make.dispRity}\NormalTok{()}
\end{Highlighting}
\end{Shaded}
@@ -7386,8 +7437,8 @@ \subsubsection{\texorpdfstring{\texttt{make.dispRity}}{make.dispRity}}\label{mak
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating an "empty" dispRity object with a matrix}
-\NormalTok{(disparity\_obj \textless{}{-}}\StringTok{ }\KeywordTok{make.dispRity}\NormalTok{(}\KeywordTok{matrix}\NormalTok{(}\KeywordTok{rnorm}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{5}\NormalTok{, }\DecValTok{4}\NormalTok{)))}
+\DocumentationTok{\#\# Creating an "empty" dispRity object with a matrix}
+\NormalTok{(disparity\_obj }\OtherTok{\textless{}{-}} \FunctionTok{make.dispRity}\NormalTok{(}\FunctionTok{matrix}\NormalTok{(}\FunctionTok{rnorm}\NormalTok{(}\DecValTok{20}\NormalTok{), }\DecValTok{5}\NormalTok{, }\DecValTok{4}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -7403,8 +7454,8 @@ \subsubsection{\texorpdfstring{\texttt{fill.dispRity}}{fill.dispRity}}\label{fil
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The dispRity object\textquotesingle{}s call is indeed empty}
-\NormalTok{disparity\_obj}\OperatorTok{$}\NormalTok{call}
+\DocumentationTok{\#\# The dispRity object\textquotesingle{}s call is indeed empty}
+\NormalTok{disparity\_obj}\SpecialCharTok{$}\NormalTok{call}
\end{Highlighting}
\end{Shaded}
@@ -7414,8 +7465,8 @@ \subsubsection{\texorpdfstring{\texttt{fill.dispRity}}{fill.dispRity}}\label{fil
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Filling an empty disparity object (that needs to contain at least a matrix)}
-\NormalTok{(disparity\_obj \textless{}{-}}\StringTok{ }\KeywordTok{fill.dispRity}\NormalTok{(disparity\_obj))}
+\DocumentationTok{\#\# Filling an empty disparity object (that needs to contain at least a matrix)}
+\NormalTok{(disparity\_obj }\OtherTok{\textless{}{-}} \FunctionTok{fill.dispRity}\NormalTok{(disparity\_obj))}
\end{Highlighting}
\end{Shaded}
@@ -7431,8 +7482,8 @@ \subsubsection{\texorpdfstring{\texttt{fill.dispRity}}{fill.dispRity}}\label{fil
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The dipRity object has now the correct minimal attributes}
-\NormalTok{disparity\_obj}\OperatorTok{$}\NormalTok{call}
+\DocumentationTok{\#\# The dipRity object has now the correct minimal attributes}
+\NormalTok{disparity\_obj}\SpecialCharTok{$}\NormalTok{call}
\end{Highlighting}
\end{Shaded}
@@ -7449,13 +7500,13 @@ \subsubsection{\texorpdfstring{\texttt{get.matrix}}{get.matrix}}\label{get.matri
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Extracting the matrix containing the coordinates of the elements at time 50}
-\KeywordTok{str}\NormalTok{(}\KeywordTok{get.matrix}\NormalTok{(disparity, }\StringTok{"50"}\NormalTok{))}
+\DocumentationTok{\#\# Extracting the matrix containing the coordinates of the elements at time 50}
+\FunctionTok{str}\NormalTok{(}\FunctionTok{get.matrix}\NormalTok{(disparity, }\StringTok{"50"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## num [1:18, 1:97] -0.1036 0.4318 0.3371 0.0501 0.685 ...
+## num [1:18, 1:97] -0.1 0.427 0.333 0.054 0.674 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:18] "Leptictis" "Dasypodidae" "n24" "Potamogalinae" ...
## ..$ : NULL
@@ -7463,14 +7514,14 @@ \subsubsection{\texorpdfstring{\texttt{get.matrix}}{get.matrix}}\label{get.matri
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level}
-\CommentTok{\#\# (15 elements) from the second group (80 Mya)}
-\KeywordTok{str}\NormalTok{(}\KeywordTok{get.matrix}\NormalTok{(disparity, }\DataTypeTok{subsets =} \DecValTok{1}\NormalTok{, }\DataTypeTok{bootstrap =} \DecValTok{3}\NormalTok{, }\DataTypeTok{rarefaction =} \DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level}
+\DocumentationTok{\#\# (15 elements) from the second group (80 Mya)}
+\FunctionTok{str}\NormalTok{(}\FunctionTok{get.matrix}\NormalTok{(disparity, }\AttributeTok{subsets =} \DecValTok{1}\NormalTok{, }\AttributeTok{bootstrap =} \DecValTok{3}\NormalTok{, }\AttributeTok{rarefaction =} \DecValTok{2}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## num [1:15, 1:97] -0.12948 -0.57973 0.00361 0.27123 0.27123 ...
+## num [1:15, 1:97] -0.134942 -0.571937 0.000589 0.266188 0.266188 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:15] "n15" "Maelestes" "n20" "n34" ...
## ..$ : NULL
@@ -7483,8 +7534,8 @@ \subsubsection{\texorpdfstring{\texttt{n.subsets}}{n.subsets}}\label{n.subsets}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# How many subsets are in this object?}
-\KeywordTok{n.subsets}\NormalTok{(disparity)}
+\DocumentationTok{\#\# How many subsets are in this object?}
+\FunctionTok{n.subsets}\NormalTok{(disparity)}
\end{Highlighting}
\end{Shaded}
@@ -7499,8 +7550,8 @@ \subsubsection{\texorpdfstring{\texttt{name.subsets}}{name.subsets}}\label{name.
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# What are they called?}
-\KeywordTok{name.subsets}\NormalTok{(disparity)}
+\DocumentationTok{\#\# What are they called?}
+\FunctionTok{name.subsets}\NormalTok{(disparity)}
\end{Highlighting}
\end{Shaded}
@@ -7515,8 +7566,8 @@ \subsubsection{\texorpdfstring{\texttt{size.subsets}}{size.subsets}}\label{size.
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# How many elements are there in each subset?}
-\KeywordTok{size.subsets}\NormalTok{(disparity)}
+\DocumentationTok{\#\# How many elements are there in each subset?}
+\FunctionTok{size.subsets}\NormalTok{(disparity)}
\end{Highlighting}
\end{Shaded}
@@ -7532,11 +7583,11 @@ \subsubsection{\texorpdfstring{\texttt{get.subsets}}{get.subsets}}\label{get.sub
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Extracting all the data for the crown mammals}
-\NormalTok{(crown\_mammals \textless{}{-}}\StringTok{ }\KeywordTok{get.subsets}\NormalTok{(disp\_crown\_stemBS, }\StringTok{"Group.crown"}\NormalTok{))}
+\DocumentationTok{\#\# Extracting all the data for the crown mammals}
+\NormalTok{(crown\_mammals }\OtherTok{\textless{}{-}} \FunctionTok{get.subsets}\NormalTok{(disp\_crown\_stemBS, }\StringTok{"Group.crown"}\NormalTok{))}
-\CommentTok{\#\# The object keeps the properties of the parent object but is composed of only one subsets}
-\KeywordTok{length}\NormalTok{(crown\_mammals}\OperatorTok{$}\NormalTok{subsets)}
+\DocumentationTok{\#\# The object keeps the properties of the parent object but is composed of only one subsets}
+\FunctionTok{length}\NormalTok{(crown\_mammals}\SpecialCharTok{$}\NormalTok{subsets)}
\end{Highlighting}
\end{Shaded}
@@ -7547,8 +7598,8 @@ \subsubsection{\texorpdfstring{\texttt{combine.subsets}}{combine.subsets}}\label
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Combine the two first subsets in the dispRity data example}
-\KeywordTok{combine.subsets}\NormalTok{(disparity, }\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\DocumentationTok{\#\# Combine the two first subsets in the dispRity data example}
+\FunctionTok{combine.subsets}\NormalTok{(disparity, }\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
@@ -7561,12 +7612,12 @@ \subsubsection{\texorpdfstring{\texttt{get.disparity}}{get.disparity}}\label{get
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Extracting the observed disparity (default)}
-\KeywordTok{get.disparity}\NormalTok{(disparity)}
+\DocumentationTok{\#\# Extracting the observed disparity (default)}
+\FunctionTok{get.disparity}\NormalTok{(disparity)}
-\CommentTok{\#\# Extracting the disparity from the bootstrapped values from the}
-\CommentTok{\#\# 10th rarefaction level from the second subsets (80 Mya)}
-\KeywordTok{get.disparity}\NormalTok{(disparity, }\DataTypeTok{observed =} \OtherTok{FALSE}\NormalTok{, }\DataTypeTok{subsets =} \DecValTok{2}\NormalTok{, }\DataTypeTok{rarefaction =} \DecValTok{10}\NormalTok{)}
+\DocumentationTok{\#\# Extracting the disparity from the bootstrapped values from the}
+\DocumentationTok{\#\# 10th rarefaction level from the second subsets (80 Mya)}
+\FunctionTok{get.disparity}\NormalTok{(disparity, }\AttributeTok{observed =} \ConstantTok{FALSE}\NormalTok{, }\AttributeTok{subsets =} \DecValTok{2}\NormalTok{, }\AttributeTok{rarefaction =} \DecValTok{10}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -7577,17 +7628,17 @@ \subsubsection{\texorpdfstring{\texttt{scale.dispRity}}{scale.dispRity}}\label{s
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Getting the disparity values of the time subsets}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(disparity))}
+\DocumentationTok{\#\# Getting the disparity values of the time subsets}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(disparity))}
-\CommentTok{\#\# Scaling the same disparity values}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{scale.dispRity}\NormalTok{(disparity, }\DataTypeTok{scale =} \OtherTok{TRUE}\NormalTok{)))}
+\DocumentationTok{\#\# Scaling the same disparity values}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{scale.dispRity}\NormalTok{(disparity, }\AttributeTok{scale =} \ConstantTok{TRUE}\NormalTok{)))}
-\CommentTok{\#\# Scaling and centering:}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{scale.dispRity}\NormalTok{(disparity, }\DataTypeTok{scale =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{center =} \OtherTok{TRUE}\NormalTok{)))}
+\DocumentationTok{\#\# Scaling and centering:}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{scale.dispRity}\NormalTok{(disparity, }\AttributeTok{scale =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{center =} \ConstantTok{TRUE}\NormalTok{)))}
-\CommentTok{\#\# Rescaling the value by dividing by a maximum value}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{scale.dispRity}\NormalTok{(disparity, }\DataTypeTok{max =} \DecValTok{10}\NormalTok{)))}
+\DocumentationTok{\#\# Rescaling the value by dividing by a maximum value}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{scale.dispRity}\NormalTok{(disparity, }\AttributeTok{max =} \DecValTok{10}\NormalTok{)))}
\end{Highlighting}
\end{Shaded}
@@ -7598,11 +7649,11 @@ \subsubsection{\texorpdfstring{\texttt{sort.dispRity}}{sort.dispRity}}\label{sor
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Sorting the disparity subsets in inverse alphabetic order}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{sort}\NormalTok{(disparity, }\DataTypeTok{decreasing =} \OtherTok{TRUE}\NormalTok{)))}
+\DocumentationTok{\#\# Sorting the disparity subsets in inverse alphabetic order}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{sort}\NormalTok{(disparity, }\AttributeTok{decreasing =} \ConstantTok{TRUE}\NormalTok{)))}
-\CommentTok{\#\# Customised sorting}
-\KeywordTok{head}\NormalTok{(}\KeywordTok{summary}\NormalTok{(}\KeywordTok{sort}\NormalTok{(disparity, }\DataTypeTok{sort =} \KeywordTok{c}\NormalTok{(}\DecValTok{7}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{6}\NormalTok{))))}
+\DocumentationTok{\#\# Customised sorting}
+\FunctionTok{head}\NormalTok{(}\FunctionTok{summary}\NormalTok{(}\FunctionTok{sort}\NormalTok{(disparity, }\AttributeTok{sort =} \FunctionTok{c}\NormalTok{(}\DecValTok{7}\NormalTok{, }\DecValTok{1}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{6}\NormalTok{))))}
\end{Highlighting}
\end{Shaded}
@@ -7613,14 +7664,14 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Getting the tree component of a dispRity object}
-\KeywordTok{get.tree}\NormalTok{(disparity)}
+\DocumentationTok{\#\# Getting the tree component of a dispRity object}
+\FunctionTok{get.tree}\NormalTok{(disparity)}
-\CommentTok{\#\# Removing the tree}
-\KeywordTok{remove.tree}\NormalTok{(disparity)}
+\DocumentationTok{\#\# Removing the tree}
+\FunctionTok{remove.tree}\NormalTok{(disparity)}
-\CommentTok{\#\# Adding a tree}
-\KeywordTok{add.tree}\NormalTok{(disparity, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree)}
+\DocumentationTok{\#\# Adding a tree}
+\FunctionTok{add.tree}\NormalTok{(disparity, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree)}
\end{Highlighting}
\end{Shaded}
@@ -7630,36 +7681,36 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Load the Beck \& Lee 2014 data}
-\KeywordTok{data}\NormalTok{(BeckLee\_tree) ; }\KeywordTok{data}\NormalTok{(BeckLee\_mat99) ; }\KeywordTok{data}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Load the Beck \& Lee 2014 data}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree) ; }\FunctionTok{data}\NormalTok{(BeckLee\_mat99) ; }\FunctionTok{data}\NormalTok{(BeckLee\_ages)}
-\CommentTok{\#\# Time binning (discrete method)}
-\CommentTok{\#\# Generate two discrete time bins from 120 to 40 Ma every 20 Ma}
-\NormalTok{time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ BeckLee\_mat99, }\DataTypeTok{tree =}\NormalTok{ BeckLee\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{, }\DataTypeTok{time =} \KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{),}
- \DataTypeTok{inc.nodes =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
+\DocumentationTok{\#\# Time binning (discrete method)}
+\DocumentationTok{\#\# Generate two discrete time bins from 120 to 40 Ma every 20 Ma}
+\NormalTok{time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ BeckLee\_mat99, }\AttributeTok{tree =}\NormalTok{ BeckLee\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{, }\AttributeTok{time =} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{),}
+ \AttributeTok{inc.nodes =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{FADLAD =}\NormalTok{ BeckLee\_ages)}
-\CommentTok{\#\# Getting the subtrees all the way to the root}
-\NormalTok{root\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{get.tree}\NormalTok{(time\_bins, }\DataTypeTok{subsets =} \OtherTok{TRUE}\NormalTok{)}
+\DocumentationTok{\#\# Getting the subtrees all the way to the root}
+\NormalTok{root\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{get.tree}\NormalTok{(time\_bins, }\AttributeTok{subsets =} \ConstantTok{TRUE}\NormalTok{)}
-\CommentTok{\#\# Plotting the bin contents}
-\NormalTok{old\_par \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{, }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)}
-\KeywordTok{axisPhylo}\NormalTok{()}
-\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ BeckLee\_tree}\OperatorTok{$}\NormalTok{root.time }\OperatorTok{{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))}
-\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{) \{}
- \KeywordTok{plot}\NormalTok{(root\_subsets[[i]], }\DataTypeTok{main =} \KeywordTok{names}\NormalTok{(root\_subsets)[i],}
- \DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)}
- \KeywordTok{axisPhylo}\NormalTok{()}
+\DocumentationTok{\#\# Plotting the bin contents}
+\NormalTok{old\_par }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{, }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)}
+\FunctionTok{axisPhylo}\NormalTok{()}
+\FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ BeckLee\_tree}\SpecialCharTok{$}\NormalTok{root.time }\SpecialCharTok{{-}} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))}
+\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{) \{}
+ \FunctionTok{plot}\NormalTok{(root\_subsets[[i]], }\AttributeTok{main =} \FunctionTok{names}\NormalTok{(root\_subsets)[i],}
+ \AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)}
+ \FunctionTok{axisPhylo}\NormalTok{()}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-202-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-218-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(old\_par)}
+\FunctionTok{par}\NormalTok{(old\_par)}
\end{Highlighting}
\end{Shaded}
@@ -7667,27 +7718,27 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Getting the subtrees all the way to the root}
-\NormalTok{bin\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{get.tree}\NormalTok{(time\_bins, }\DataTypeTok{subsets =} \OtherTok{TRUE}\NormalTok{, }\DataTypeTok{to.root =} \OtherTok{FALSE}\NormalTok{)}
+\DocumentationTok{\#\# Getting the subtrees all the way to the root}
+\NormalTok{bin\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{get.tree}\NormalTok{(time\_bins, }\AttributeTok{subsets =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{to.root =} \ConstantTok{FALSE}\NormalTok{)}
-\CommentTok{\#\# Plotting the bin contents}
-\NormalTok{old\_par \textless{}{-}}\StringTok{ }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{main =} \StringTok{"original tree"}\NormalTok{, }\DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)}
-\KeywordTok{axisPhylo}\NormalTok{()}
-\KeywordTok{abline}\NormalTok{(}\DataTypeTok{v =}\NormalTok{ BeckLee\_tree}\OperatorTok{$}\NormalTok{root.time }\OperatorTok{{-}}\StringTok{ }\KeywordTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))}
-\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\OperatorTok{:}\DecValTok{3}\NormalTok{) \{}
- \KeywordTok{plot}\NormalTok{(bin\_subsets[[i]], }\DataTypeTok{main =} \KeywordTok{names}\NormalTok{(bin\_subsets)[i],}
- \DataTypeTok{show.tip.label =} \OtherTok{FALSE}\NormalTok{)}
- \KeywordTok{axisPhylo}\NormalTok{()}
+\DocumentationTok{\#\# Plotting the bin contents}
+\NormalTok{old\_par }\OtherTok{\textless{}{-}} \FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{main =} \StringTok{"original tree"}\NormalTok{, }\AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)}
+\FunctionTok{axisPhylo}\NormalTok{()}
+\FunctionTok{abline}\NormalTok{(}\AttributeTok{v =}\NormalTok{ BeckLee\_tree}\SpecialCharTok{$}\NormalTok{root.time }\SpecialCharTok{{-}} \FunctionTok{c}\NormalTok{(}\DecValTok{120}\NormalTok{, }\DecValTok{100}\NormalTok{, }\DecValTok{80}\NormalTok{, }\DecValTok{60}\NormalTok{))}
+\ControlFlowTok{for}\NormalTok{(i }\ControlFlowTok{in} \DecValTok{1}\SpecialCharTok{:}\DecValTok{3}\NormalTok{) \{}
+ \FunctionTok{plot}\NormalTok{(bin\_subsets[[i]], }\AttributeTok{main =} \FunctionTok{names}\NormalTok{(bin\_subsets)[i],}
+ \AttributeTok{show.tip.label =} \ConstantTok{FALSE}\NormalTok{)}
+ \FunctionTok{axisPhylo}\NormalTok{()}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-203-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-219-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{par}\NormalTok{(old\_par)}
+\FunctionTok{par}\NormalTok{(old\_par)}
\end{Highlighting}
\end{Shaded}
@@ -7695,20 +7746,20 @@ \subsubsection{\texorpdfstring{\texttt{get.tree} \texttt{add.tree} and \texttt{r
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# How many cumulated phylogenetic diversity in each bin?}
-\KeywordTok{lapply}\NormalTok{(bin\_subsets, }\ControlFlowTok{function}\NormalTok{(tree) }\KeywordTok{sum}\NormalTok{(tree}\OperatorTok{$}\NormalTok{edge.length))}
+\DocumentationTok{\#\# How many cumulated phylogenetic diversity in each bin?}
+\FunctionTok{lapply}\NormalTok{(bin\_subsets, }\ControlFlowTok{function}\NormalTok{(tree) }\FunctionTok{sum}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{edge.length))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## $`120 - 100`
-## [1] 189.2799
+## [1] 189.2829
##
## $`100 - 80`
-## [1] 341.7199
+## [1] 341.7223
##
## $`80 - 60`
-## [1] 426.7493
+## [1] 426.7486
\end{verbatim}
\hypertarget{disprity-object}{%
@@ -7771,8 +7822,8 @@ \subsection{\texorpdfstring{\texttt{\$call}}{\$call}}\label{call}}
\texttt{\$call\$disparity}: this is a \texttt{list} containing one element, \texttt{\$metric}, that is a \texttt{list} containing the different functions passed to the \texttt{metric} argument in \texttt{dispRity}. These are \texttt{call} elements and get modified each time the \texttt{dispRity} function is used (the first element is the first metric(s), the second, the second metric(s), etc.).
\end{itemize}
-\hypertarget{subsets}{%
-\subsection{\texorpdfstring{\texttt{\$subsets}}{\$subsets}}\label{subsets}}
+\hypertarget{subsets-1}{%
+\subsection{\texorpdfstring{\texttt{\$subsets}}{\$subsets}}\label{subsets-1}}
This element contain the eventual subsets of the multidimensional space.
It is a \texttt{list} of subset names.
@@ -7864,7 +7915,7 @@ \section{Data}\label{data}}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{data}\NormalTok{(iris)}
+\FunctionTok{data}\NormalTok{(iris)}
\end{Highlighting}
\end{Shaded}
@@ -7872,10 +7923,10 @@ \section{Data}\label{data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Separating the species}
-\NormalTok{species \textless{}{-}}\StringTok{ }\NormalTok{iris[,}\DecValTok{5}\NormalTok{]}
-\CommentTok{\#\# Which species?}
-\KeywordTok{unique}\NormalTok{(species)}
+\DocumentationTok{\#\# Separating the species}
+\NormalTok{species }\OtherTok{\textless{}{-}}\NormalTok{ iris[,}\DecValTok{5}\NormalTok{]}
+\DocumentationTok{\#\# Which species?}
+\FunctionTok{unique}\NormalTok{(species)}
\end{Highlighting}
\end{Shaded}
@@ -7886,9 +7937,9 @@ \section{Data}\label{data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Separating the petal/sepal length}
-\NormalTok{measurements \textless{}{-}}\StringTok{ }\NormalTok{iris[,}\DecValTok{1}\OperatorTok{:}\DecValTok{4}\NormalTok{]}
-\KeywordTok{head}\NormalTok{(measurements)}
+\DocumentationTok{\#\# Separating the petal/sepal length}
+\NormalTok{measurements }\OtherTok{\textless{}{-}}\NormalTok{ iris[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{4}\NormalTok{]}
+\FunctionTok{head}\NormalTok{(measurements)}
\end{Highlighting}
\end{Shaded}
@@ -7906,14 +7957,14 @@ \section{Data}\label{data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Ordinating the data}
-\NormalTok{ordination \textless{}{-}}\StringTok{ }\KeywordTok{prcomp}\NormalTok{(measurements)}
+\DocumentationTok{\#\# Ordinating the data}
+\NormalTok{ordination }\OtherTok{\textless{}{-}} \FunctionTok{prcomp}\NormalTok{(measurements)}
-\CommentTok{\#\# The petal{-}space}
-\NormalTok{petal\_space \textless{}{-}}\StringTok{ }\NormalTok{ordination}\OperatorTok{$}\NormalTok{x}
+\DocumentationTok{\#\# The petal{-}space}
+\NormalTok{petal\_space }\OtherTok{\textless{}{-}}\NormalTok{ ordination}\SpecialCharTok{$}\NormalTok{x}
-\CommentTok{\#\# Adding the elements names to the petal{-}space (the individuals IDs)}
-\KeywordTok{rownames}\NormalTok{(petal\_space) \textless{}{-}}\StringTok{ }\DecValTok{1}\OperatorTok{:}\KeywordTok{nrow}\NormalTok{(petal\_space)}
+\DocumentationTok{\#\# Adding the elements names to the petal{-}space (the individuals IDs)}
+\FunctionTok{rownames}\NormalTok{(petal\_space) }\OtherTok{\textless{}{-}} \DecValTok{1}\SpecialCharTok{:}\FunctionTok{nrow}\NormalTok{(petal\_space)}
\end{Highlighting}
\end{Shaded}
@@ -7924,21 +7975,21 @@ \section{Classic analysis}\label{classic-analysis}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Measuring the variance on each axis}
-\NormalTok{axis\_variances \textless{}{-}}\StringTok{ }\KeywordTok{apply}\NormalTok{(petal\_space, }\DecValTok{2}\NormalTok{, var)}
-\NormalTok{axis\_variances \textless{}{-}}\StringTok{ }\NormalTok{axis\_variances}\OperatorTok{/}\KeywordTok{sum}\NormalTok{(axis\_variances)}
+\DocumentationTok{\#\# Measuring the variance on each axis}
+\NormalTok{axis\_variances }\OtherTok{\textless{}{-}} \FunctionTok{apply}\NormalTok{(petal\_space, }\DecValTok{2}\NormalTok{, var)}
+\NormalTok{axis\_variances }\OtherTok{\textless{}{-}}\NormalTok{ axis\_variances}\SpecialCharTok{/}\FunctionTok{sum}\NormalTok{(axis\_variances)}
-\CommentTok{\#\# Graphical option}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical option}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# A classic 2D ordination plot}
-\KeywordTok{plot}\NormalTok{(petal\_space[, }\DecValTok{1}\NormalTok{], petal\_space[, }\DecValTok{2}\NormalTok{], }\DataTypeTok{col =}\NormalTok{ species,}
- \DataTypeTok{xlab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 1 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{1}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),}
- \DataTypeTok{ylab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 2 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{2}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))}
+\DocumentationTok{\#\# A classic 2D ordination plot}
+\FunctionTok{plot}\NormalTok{(petal\_space[, }\DecValTok{1}\NormalTok{], petal\_space[, }\DecValTok{2}\NormalTok{], }\AttributeTok{col =}\NormalTok{ species,}
+ \AttributeTok{xlab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 1 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{1}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),}
+ \AttributeTok{ylab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 2 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{2}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-208-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-224-1.pdf}
This shows the distribution of the different species in the petal-space along the two first axis of variation.
This is a pretty standard way to visualise the multidimensional space and further analysis might be necessary to test wether the groups are different such as a linear discriminant analysis (LDA).
@@ -7947,14 +7998,14 @@ \section{Classic analysis}\label{classic-analysis}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the two second axis of the petal{-}space}
-\KeywordTok{plot}\NormalTok{(petal\_space[, }\DecValTok{3}\NormalTok{], petal\_space[, }\DecValTok{4}\NormalTok{], }\DataTypeTok{col =}\NormalTok{ species,}
- \DataTypeTok{xlab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 3 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{3}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),}
- \DataTypeTok{ylab =} \KeywordTok{paste0}\NormalTok{(}\StringTok{"PC 4 ("}\NormalTok{, }\KeywordTok{round}\NormalTok{(axis\_variances[}\DecValTok{4}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))}
+\DocumentationTok{\#\# Plotting the two second axis of the petal{-}space}
+\FunctionTok{plot}\NormalTok{(petal\_space[, }\DecValTok{3}\NormalTok{], petal\_space[, }\DecValTok{4}\NormalTok{], }\AttributeTok{col =}\NormalTok{ species,}
+ \AttributeTok{xlab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 3 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{3}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{),}
+ \AttributeTok{ylab =} \FunctionTok{paste0}\NormalTok{(}\StringTok{"PC 4 ("}\NormalTok{, }\FunctionTok{round}\NormalTok{(axis\_variances[}\DecValTok{4}\NormalTok{], }\DecValTok{2}\NormalTok{), }\StringTok{")"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-209-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-225-1.pdf}
Additionally, these two represented dimensions do not represent a biological reality \emph{per se}; i.e.~the values on the first dimension do not represent a continuous trait (e.g.~petal length), instead they just represent the ordinations of correlations between the data and some factors.
@@ -7968,13 +8019,13 @@ \section{\texorpdfstring{A multidimensional approach with \texttt{dispRity}}{A m
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating the table that contain the elements and their attributes}
-\NormalTok{petal\_subsets \textless{}{-}}\StringTok{ }\KeywordTok{custom.subsets}\NormalTok{(petal\_space, }\DataTypeTok{group =} \KeywordTok{list}\NormalTok{(}
- \StringTok{"setosa"}\NormalTok{ =}\StringTok{ }\KeywordTok{which}\NormalTok{(species }\OperatorTok{==}\StringTok{ "setosa"}\NormalTok{),}
- \StringTok{"versicolor"}\NormalTok{ =}\StringTok{ }\KeywordTok{which}\NormalTok{(species }\OperatorTok{==}\StringTok{ "versicolor"}\NormalTok{),}
- \StringTok{"virginica"}\NormalTok{ =}\StringTok{ }\KeywordTok{which}\NormalTok{(species }\OperatorTok{==}\StringTok{ "virginica"}\NormalTok{)))}
+\DocumentationTok{\#\# Creating the table that contain the elements and their attributes}
+\NormalTok{petal\_subsets }\OtherTok{\textless{}{-}} \FunctionTok{custom.subsets}\NormalTok{(petal\_space, }\AttributeTok{group =} \FunctionTok{list}\NormalTok{(}
+ \StringTok{"setosa"} \OtherTok{=} \FunctionTok{which}\NormalTok{(species }\SpecialCharTok{==} \StringTok{"setosa"}\NormalTok{),}
+ \StringTok{"versicolor"} \OtherTok{=} \FunctionTok{which}\NormalTok{(species }\SpecialCharTok{==} \StringTok{"versicolor"}\NormalTok{),}
+ \StringTok{"virginica"} \OtherTok{=} \FunctionTok{which}\NormalTok{(species }\SpecialCharTok{==} \StringTok{"virginica"}\NormalTok{)))}
-\CommentTok{\#\# Visualising the dispRity object content}
+\DocumentationTok{\#\# Visualising the dispRity object content}
\NormalTok{petal\_subsets}
\end{Highlighting}
\end{Shaded}
@@ -7995,8 +8046,8 @@ \subsection{Bootstrapping the data}\label{bootstrapping-the-data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Bootstrapping the data}
-\NormalTok{(petal\_bootstrapped \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(petal\_subsets))}
+\DocumentationTok{\#\# Bootstrapping the data}
+\NormalTok{(petal\_bootstrapped }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(petal\_subsets))}
\end{Highlighting}
\end{Shaded}
@@ -8004,7 +8055,7 @@ \subsection{Bootstrapping the data}\label{bootstrapping-the-data}}
## ---- dispRity object ----
## 3 customised subsets for 150 elements in one matrix with 4 dimensions:
## setosa, versicolor, virginica.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
\end{verbatim}
\hypertarget{calculating-disparity}{%
@@ -8020,9 +8071,9 @@ \subsection{Calculating disparity}\label{calculating-disparity}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity as the median distance between each elements and}
-\CommentTok{\#\# the centroid of the petal{-}space}
-\NormalTok{(petal\_disparity \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(petal\_bootstrapped, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(median, centroids)))}
+\DocumentationTok{\#\# Calculating disparity as the median distance between each elements and}
+\DocumentationTok{\#\# the centroid of the petal{-}space}
+\NormalTok{(petal\_disparity }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(petal\_bootstrapped, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(median, centroids)))}
\end{Highlighting}
\end{Shaded}
@@ -8030,7 +8081,7 @@ \subsection{Calculating disparity}\label{calculating-disparity}}
## ---- dispRity object ----
## 3 customised subsets for 150 elements in one matrix with 4 dimensions:
## setosa, versicolor, virginica.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: c(median, centroids).
\end{verbatim}
@@ -8044,31 +8095,31 @@ \subsection{Summarising the results (plot)}\label{summarising-the-results-plot}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Displaying the summary of the calculated disparity}
-\KeywordTok{summary}\NormalTok{(petal\_disparity)}
+\DocumentationTok{\#\# Displaying the summary of the calculated disparity}
+\FunctionTok{summary}\NormalTok{(petal\_disparity)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 setosa 50 0.421 0.432 0.370 0.408 0.454 0.501
-## 2 versicolor 50 0.693 0.656 0.511 0.619 0.697 0.770
-## 3 virginica 50 0.785 0.747 0.580 0.674 0.806 0.936
+## 1 setosa 50 0.421 0.432 0.363 0.409 0.456 0.502
+## 2 versicolor 50 0.693 0.662 0.563 0.618 0.702 0.781
+## 3 virginica 50 0.785 0.719 0.548 0.652 0.786 0.902
\end{verbatim}
We can also plot the results in a similar way:
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
-\CommentTok{\#\# Plotting the disparity in the petal\_space}
-\KeywordTok{plot}\NormalTok{(petal\_disparity)}
+\DocumentationTok{\#\# Plotting the disparity in the petal\_space}
+\FunctionTok{plot}\NormalTok{(petal\_disparity)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-214-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-230-1.pdf}
Now contrary to simply plotting the two first axis of the PCA where we saw that the species have a different position in the two first petal-space, we can now also see that they occupy this space clearly differently!
@@ -8079,8 +8130,8 @@ \subsection{Testing hypothesis}\label{testing-hypothesis}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Running a PERMANOVA}
-\KeywordTok{test.dispRity}\NormalTok{(petal\_disparity, }\DataTypeTok{test =}\NormalTok{ adonis.dispRity)}
+\DocumentationTok{\#\# Running a PERMANOVA}
+\FunctionTok{test.dispRity}\NormalTok{(petal\_disparity, }\AttributeTok{test =}\NormalTok{ adonis.dispRity)}
\end{Highlighting}
\end{Shaded}
@@ -8097,13 +8148,12 @@ \subsection{Testing hypothesis}\label{testing-hypothesis}}
\begin{verbatim}
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = dist(matrix) ~ group, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## group 2 592.07 0.86894 487.33 0.001 ***
+## Model 2 592.07 0.86894 487.33 0.001 ***
## Residual 147 89.30 0.13106
## Total 149 681.37 1.00000
## ---
@@ -8112,35 +8162,35 @@ \subsection{Testing hypothesis}\label{testing-hypothesis}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Post{-}hoc testing of the differences between species (corrected for multiple tests)}
-\KeywordTok{test.dispRity}\NormalTok{(petal\_disparity, }\DataTypeTok{test =}\NormalTok{ t.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
+\DocumentationTok{\#\# Post{-}hoc testing of the differences between species (corrected for multiple tests)}
+\FunctionTok{test.dispRity}\NormalTok{(petal\_disparity, }\AttributeTok{test =}\NormalTok{ t.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [[1]]
## statistic: t
-## setosa : versicolor -29.998366
-## setosa : virginica -30.465933
-## versicolor : virginica -7.498179
+## setosa : versicolor -33.37334
+## setosa : virginica -28.36656
+## versicolor : virginica -5.24564
##
## [[2]]
## parameter: df
-## setosa : versicolor 149.8429
-## setosa : virginica 124.4227
-## versicolor : virginica 175.4758
+## setosa : versicolor 166.2319
+## setosa : virginica 127.7601
+## versicolor : virginica 164.6248
##
## [[3]]
## p.value
-## setosa : versicolor 9.579095e-65
-## setosa : virginica 4.625567e-59
-## versicolor : virginica 9.247421e-12
+## setosa : versicolor 4.126944e-75
+## setosa : virginica 1.637347e-56
+## versicolor : virginica 1.420552e-06
##
## [[4]]
## stderr
-## setosa : versicolor 0.007378905
-## setosa : virginica 0.010103449
-## versicolor : virginica 0.011530255
+## setosa : versicolor 0.006875869
+## setosa : virginica 0.010145340
+## versicolor : virginica 0.011117360
\end{verbatim}
We can now see that there is a significant difference in petal-space occupancy between all species of iris.
@@ -8153,25 +8203,25 @@ \subsubsection{Setting up a multidimensional null-hypothesis}\label{setting-up-a
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing against a uniform distribution}
-\NormalTok{disparity\_uniform \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(petal\_disparity, }\DataTypeTok{replicates =} \DecValTok{200}\NormalTok{,}
- \DataTypeTok{null.distrib =}\NormalTok{ runif, }\DataTypeTok{scale =} \OtherTok{FALSE}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(disparity\_uniform)}
+\DocumentationTok{\#\# Testing against a uniform distribution}
+\NormalTok{disparity\_uniform }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(petal\_disparity, }\AttributeTok{replicates =} \DecValTok{200}\NormalTok{,}
+ \AttributeTok{null.distrib =}\NormalTok{ runif, }\AttributeTok{scale =} \ConstantTok{FALSE}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(disparity\_uniform)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-216-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-232-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing against a normal distribution}
-\NormalTok{disparity\_normal \textless{}{-}}\StringTok{ }\KeywordTok{null.test}\NormalTok{(petal\_disparity, }\DataTypeTok{replicates =} \DecValTok{200}\NormalTok{,}
- \DataTypeTok{null.distrib =}\NormalTok{ rnorm, }\DataTypeTok{scale =} \OtherTok{TRUE}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(disparity\_normal)}
+\DocumentationTok{\#\# Testing against a normal distribution}
+\NormalTok{disparity\_normal }\OtherTok{\textless{}{-}} \FunctionTok{null.test}\NormalTok{(petal\_disparity, }\AttributeTok{replicates =} \DecValTok{200}\NormalTok{,}
+ \AttributeTok{null.distrib =}\NormalTok{ rnorm, }\AttributeTok{scale =} \ConstantTok{TRUE}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(disparity\_normal)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-217-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-233-1.pdf}
In both cases we can see that our petal-space is not entirely normal or uniform.
This is expected because of the simplicity of these parameters.
@@ -8196,32 +8246,32 @@ \subsection{The morphospace}\label{the-morphospace}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading demo and the package data}
-\KeywordTok{library}\NormalTok{(dispRity)}
+\DocumentationTok{\#\# Loading demo and the package data}
+\FunctionTok{library}\NormalTok{(dispRity)}
-\CommentTok{\#\# Setting the random seed for repeatability}
-\KeywordTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)}
+\DocumentationTok{\#\# Setting the random seed for repeatability}
+\FunctionTok{set.seed}\NormalTok{(}\DecValTok{123}\NormalTok{)}
-\CommentTok{\#\# Loading the ordinated matrix/morphospace:}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat50)}
-\KeywordTok{data}\NormalTok{(BeckLee\_mat99)}
-\KeywordTok{head}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\OperatorTok{:}\DecValTok{5}\NormalTok{])}
+\DocumentationTok{\#\# Loading the ordinated matrix/morphospace:}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat50)}
+\FunctionTok{data}\NormalTok{(BeckLee\_mat99)}
+\FunctionTok{head}\NormalTok{(BeckLee\_mat50[,}\DecValTok{1}\SpecialCharTok{:}\DecValTok{5}\NormalTok{])}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
-## [,1] [,2] [,3] [,4] [,5]
-## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039
-## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479
-## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646
-## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626
-## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914
-## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351
+## [,1] [,2] [,3] [,4] [,5]
+## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039
+## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479
+## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646
+## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626
+## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914
+## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{dim}\NormalTok{(BeckLee\_mat50)}
+\FunctionTok{dim}\NormalTok{(BeckLee\_mat50)}
\end{Highlighting}
\end{Shaded}
@@ -8231,11 +8281,11 @@ \subsection{The morphospace}\label{the-morphospace}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The morphospace contains 50 taxa and has 48 dimensions (or axes)}
+\DocumentationTok{\#\# The morphospace contains 50 taxa and has 48 dimensions (or axes)}
-\CommentTok{\#\# Showing a list of first and last occurrences data for some fossils}
-\KeywordTok{data}\NormalTok{(BeckLee\_ages)}
-\KeywordTok{head}\NormalTok{(BeckLee\_ages)}
+\DocumentationTok{\#\# Showing a list of first and last occurrences data for some fossils}
+\FunctionTok{data}\NormalTok{(BeckLee\_ages)}
+\FunctionTok{head}\NormalTok{(BeckLee\_ages)}
\end{Highlighting}
\end{Shaded}
@@ -8251,14 +8301,14 @@ \subsection{The morphospace}\label{the-morphospace}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting a phylogeny}
-\KeywordTok{data}\NormalTok{(BeckLee\_tree)}
-\KeywordTok{plot}\NormalTok{(BeckLee\_tree, }\DataTypeTok{cex =} \FloatTok{0.7}\NormalTok{)}
-\KeywordTok{axisPhylo}\NormalTok{(}\DataTypeTok{root =} \DecValTok{140}\NormalTok{)}
+\DocumentationTok{\#\# Plotting a phylogeny}
+\FunctionTok{data}\NormalTok{(BeckLee\_tree)}
+\FunctionTok{plot}\NormalTok{(BeckLee\_tree, }\AttributeTok{cex =} \FloatTok{0.7}\NormalTok{)}
+\FunctionTok{axisPhylo}\NormalTok{(}\AttributeTok{root =} \DecValTok{140}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-218-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-234-1.pdf}
\begin{quote}
You can have an even nicer looking tree if you use the \texttt{strap} package!
@@ -8266,12 +8316,12 @@ \subsection{The morphospace}\label{the-morphospace}}
\begin{Shaded}
\begin{Highlighting}[]
-\ControlFlowTok{if}\NormalTok{(}\OperatorTok{!}\KeywordTok{require}\NormalTok{(strap)) }\KeywordTok{install.packages}\NormalTok{(}\StringTok{"strap"}\NormalTok{)}
-\NormalTok{strap}\OperatorTok{::}\KeywordTok{geoscalePhylo}\NormalTok{(BeckLee\_tree, }\DataTypeTok{cex.tip =} \FloatTok{0.7}\NormalTok{, }\DataTypeTok{cex.ts =} \FloatTok{0.6}\NormalTok{)}
+\ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{require}\NormalTok{(strap)) }\FunctionTok{install.packages}\NormalTok{(}\StringTok{"strap"}\NormalTok{)}
+\NormalTok{strap}\SpecialCharTok{::}\FunctionTok{geoscalePhylo}\NormalTok{(BeckLee\_tree, }\AttributeTok{cex.tip =} \FloatTok{0.7}\NormalTok{, }\AttributeTok{cex.ts =} \FloatTok{0.6}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-219-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-235-1.pdf}
\hypertarget{setting-up-your-own-data}{%
\subsection{Setting up your own data}\label{setting-up-your-own-data}}
@@ -8312,39 +8362,39 @@ \subsection{Setting up your own data}\label{setting-up-your-own-data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Functions to get simulate a PCO looking like matrix from a tree}
-\NormalTok{i.need.a.matrix \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree) \{}
-\NormalTok{ matrix \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DataTypeTok{elements =} \KeywordTok{Ntip}\NormalTok{(tree), }\DataTypeTok{dimensions =} \KeywordTok{Ntip}\NormalTok{(tree), }\DataTypeTok{distribution =}\NormalTok{ rnorm,}
- \DataTypeTok{scree =} \KeywordTok{rev}\NormalTok{(}\KeywordTok{cumsum}\NormalTok{(}\KeywordTok{rep}\NormalTok{(}\DecValTok{1}\OperatorTok{/}\KeywordTok{Ntip}\NormalTok{(tree), }\KeywordTok{Ntip}\NormalTok{(tree)))))}
- \KeywordTok{rownames}\NormalTok{(matrix) \textless{}{-}}\StringTok{ }\NormalTok{tree}\OperatorTok{$}\NormalTok{tip.label}
- \KeywordTok{return}\NormalTok{(matrix)}
+\DocumentationTok{\#\# Functions to get simulate a PCO looking like matrix from a tree}
+\NormalTok{i.need.a.matrix }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree) \{}
+\NormalTok{ matrix }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\AttributeTok{elements =} \FunctionTok{Ntip}\NormalTok{(tree), }\AttributeTok{dimensions =} \FunctionTok{Ntip}\NormalTok{(tree), }\AttributeTok{distribution =}\NormalTok{ rnorm,}
+ \AttributeTok{scree =} \FunctionTok{rev}\NormalTok{(}\FunctionTok{cumsum}\NormalTok{(}\FunctionTok{rep}\NormalTok{(}\DecValTok{1}\SpecialCharTok{/}\FunctionTok{Ntip}\NormalTok{(tree), }\FunctionTok{Ntip}\NormalTok{(tree)))))}
+ \FunctionTok{rownames}\NormalTok{(matrix) }\OtherTok{\textless{}{-}}\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{tip.label}
+ \FunctionTok{return}\NormalTok{(matrix)}
\NormalTok{\}}
-\CommentTok{\#\# Function to simulate a tree}
-\NormalTok{i.need.a.tree \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix) \{}
-\NormalTok{ tree \textless{}{-}}\StringTok{ }\KeywordTok{rtree}\NormalTok{(}\KeywordTok{nrow}\NormalTok{(matrix))}
-\NormalTok{ tree}\OperatorTok{$}\NormalTok{root.time \textless{}{-}}\StringTok{ }\KeywordTok{max}\NormalTok{(}\KeywordTok{tree.age}\NormalTok{(tree)}\OperatorTok{$}\NormalTok{age)}
-\NormalTok{ tree}\OperatorTok{$}\NormalTok{tip.label \textless{}{-}}\StringTok{ }\KeywordTok{rownames}\NormalTok{(matrix)}
-\NormalTok{ tree}\OperatorTok{$}\NormalTok{node.label \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\NormalTok{(}\KeywordTok{nrow}\NormalTok{(matrix)}\OperatorTok{{-}}\DecValTok{1}\NormalTok{))}
- \KeywordTok{return}\NormalTok{(tree)}
+\DocumentationTok{\#\# Function to simulate a tree}
+\NormalTok{i.need.a.tree }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) \{}
+\NormalTok{ tree }\OtherTok{\textless{}{-}} \FunctionTok{rtree}\NormalTok{(}\FunctionTok{nrow}\NormalTok{(matrix))}
+\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{root.time }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(}\FunctionTok{tree.age}\NormalTok{(tree)}\SpecialCharTok{$}\NormalTok{age)}
+\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{tip.label }\OtherTok{\textless{}{-}} \FunctionTok{rownames}\NormalTok{(matrix)}
+\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{node.label }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\NormalTok{(}\FunctionTok{nrow}\NormalTok{(matrix)}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{))}
+ \FunctionTok{return}\NormalTok{(tree)}
\NormalTok{\}}
-\CommentTok{\#\# Function to simulate some "node" data}
-\NormalTok{i.need.node.data \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix, tree) \{}
-\NormalTok{ matrix\_node \textless{}{-}}\StringTok{ }\KeywordTok{space.maker}\NormalTok{(}\DataTypeTok{elements =} \KeywordTok{Nnode}\NormalTok{(tree), }\DataTypeTok{dimensions =} \KeywordTok{ncol}\NormalTok{(matrix),}
- \DataTypeTok{distribution =}\NormalTok{ rnorm, }\DataTypeTok{scree =} \KeywordTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, var))}
- \ControlFlowTok{if}\NormalTok{(}\OperatorTok{!}\KeywordTok{is.null}\NormalTok{(tree}\OperatorTok{$}\NormalTok{node.label)) \{}
- \KeywordTok{rownames}\NormalTok{(matrix\_node) \textless{}{-}}\StringTok{ }\NormalTok{tree}\OperatorTok{$}\NormalTok{node.label}
+\DocumentationTok{\#\# Function to simulate some "node" data}
+\NormalTok{i.need.node.data }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix, tree) \{}
+\NormalTok{ matrix\_node }\OtherTok{\textless{}{-}} \FunctionTok{space.maker}\NormalTok{(}\AttributeTok{elements =} \FunctionTok{Nnode}\NormalTok{(tree), }\AttributeTok{dimensions =} \FunctionTok{ncol}\NormalTok{(matrix),}
+ \AttributeTok{distribution =}\NormalTok{ rnorm, }\AttributeTok{scree =} \FunctionTok{apply}\NormalTok{(matrix, }\DecValTok{2}\NormalTok{, var))}
+ \ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{is.null}\NormalTok{(tree}\SpecialCharTok{$}\NormalTok{node.label)) \{}
+ \FunctionTok{rownames}\NormalTok{(matrix\_node) }\OtherTok{\textless{}{-}}\NormalTok{ tree}\SpecialCharTok{$}\NormalTok{node.label}
\NormalTok{ \} }\ControlFlowTok{else}\NormalTok{ \{}
- \KeywordTok{rownames}\NormalTok{(matrix\_node) \textless{}{-}}\StringTok{ }\KeywordTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\OperatorTok{:}\NormalTok{(}\KeywordTok{nrow}\NormalTok{(matrix)}\OperatorTok{{-}}\DecValTok{1}\NormalTok{))}
+ \FunctionTok{rownames}\NormalTok{(matrix\_node) }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"n"}\NormalTok{, }\DecValTok{1}\SpecialCharTok{:}\NormalTok{(}\FunctionTok{nrow}\NormalTok{(matrix)}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{))}
\NormalTok{ \}}
- \KeywordTok{return}\NormalTok{(}\KeywordTok{rbind}\NormalTok{(matrix, matrix\_node))}
+ \FunctionTok{return}\NormalTok{(}\FunctionTok{rbind}\NormalTok{(matrix, matrix\_node))}
\NormalTok{\}}
-\CommentTok{\#\# Function to simulate some "FADLAD" data}
-\NormalTok{i.need.FADLAD \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(tree) \{}
-\NormalTok{ tree\_ages \textless{}{-}}\StringTok{ }\KeywordTok{tree.age}\NormalTok{(tree)[}\DecValTok{1}\OperatorTok{:}\KeywordTok{Ntip}\NormalTok{(tree),]}
- \KeywordTok{return}\NormalTok{(}\KeywordTok{data.frame}\NormalTok{(}\DataTypeTok{FAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\DataTypeTok{LAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\DataTypeTok{row.names =}\NormalTok{ tree\_ages[,}\DecValTok{2}\NormalTok{]))}
+\DocumentationTok{\#\# Function to simulate some "FADLAD" data}
+\NormalTok{i.need.FADLAD }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(tree) \{}
+\NormalTok{ tree\_ages }\OtherTok{\textless{}{-}} \FunctionTok{tree.age}\NormalTok{(tree)[}\DecValTok{1}\SpecialCharTok{:}\FunctionTok{Ntip}\NormalTok{(tree),]}
+ \FunctionTok{return}\NormalTok{(}\FunctionTok{data.frame}\NormalTok{(}\AttributeTok{FAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\AttributeTok{LAD =}\NormalTok{ tree\_ages[,}\DecValTok{1}\NormalTok{], }\AttributeTok{row.names =}\NormalTok{ tree\_ages[,}\DecValTok{2}\NormalTok{]))}
\NormalTok{\}}
\end{Highlighting}
\end{Shaded}
@@ -8353,9 +8403,9 @@ \subsection{Setting up your own data}\label{setting-up-your-own-data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Aaaaah I don\textquotesingle{}t have FADLAD data!}
-\NormalTok{my\_FADLAD \textless{}{-}}\StringTok{ }\KeywordTok{i.need.FADLAD}\NormalTok{(tree)}
-\CommentTok{\#\# Sorted.}
+\DocumentationTok{\#\# Aaaaah I don\textquotesingle{}t have FADLAD data!}
+\NormalTok{my\_FADLAD }\OtherTok{\textless{}{-}} \FunctionTok{i.need.FADLAD}\NormalTok{(tree)}
+\DocumentationTok{\#\# Sorted.}
\end{Highlighting}
\end{Shaded}
@@ -8363,17 +8413,17 @@ \subsection{Setting up your own data}\label{setting-up-your-own-data}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# A matrix with tip data}
-\NormalTok{my\_matrix \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_mat50}
+\DocumentationTok{\#\# A matrix with tip data}
+\NormalTok{my\_matrix }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_mat50}
-\CommentTok{\#\# A phylogenetic tree }
-\NormalTok{my\_tree \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_tree}
+\DocumentationTok{\#\# A phylogenetic tree }
+\NormalTok{my\_tree }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_tree}
-\CommentTok{\#\# A matrix with tip and node data}
-\NormalTok{my\_tip\_node\_matrix \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_mat99}
+\DocumentationTok{\#\# A matrix with tip and node data}
+\NormalTok{my\_tip\_node\_matrix }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_mat99}
-\CommentTok{\#\# A table of first and last occurrences data (FADLAD)}
-\NormalTok{my\_fadlad \textless{}{-}}\StringTok{ }\NormalTok{BeckLee\_ages}
+\DocumentationTok{\#\# A table of first and last occurrences data (FADLAD)}
+\NormalTok{my\_fadlad }\OtherTok{\textless{}{-}}\NormalTok{ BeckLee\_ages}
\end{Highlighting}
\end{Shaded}
@@ -8392,13 +8442,13 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Creating the vector of time bins ages}
-\NormalTok{time\_bins \textless{}{-}}\StringTok{ }\KeywordTok{rev}\NormalTok{(}\KeywordTok{seq}\NormalTok{(}\DataTypeTok{from =} \DecValTok{0}\NormalTok{, }\DataTypeTok{to =} \DecValTok{100}\NormalTok{, }\DataTypeTok{by =} \DecValTok{20}\NormalTok{))}
+\DocumentationTok{\#\# Creating the vector of time bins ages}
+\NormalTok{time\_bins }\OtherTok{\textless{}{-}} \FunctionTok{rev}\NormalTok{(}\FunctionTok{seq}\NormalTok{(}\AttributeTok{from =} \DecValTok{0}\NormalTok{, }\AttributeTok{to =} \DecValTok{100}\NormalTok{, }\AttributeTok{by =} \DecValTok{20}\NormalTok{))}
-\CommentTok{\#\# Splitting the morphospace using the chrono.subsets function}
-\NormalTok{binned\_morphospace \textless{}{-}}\StringTok{ }\KeywordTok{chrono.subsets}\NormalTok{(}\DataTypeTok{data =}\NormalTok{ my\_matrix, }\DataTypeTok{tree =}\NormalTok{ my\_tree,}
- \DataTypeTok{method =} \StringTok{"discrete"}\NormalTok{, }\DataTypeTok{time =}\NormalTok{ time\_bins, }\DataTypeTok{inc.nodes =} \OtherTok{FALSE}\NormalTok{,}
- \DataTypeTok{FADLAD =}\NormalTok{ my\_fadlad)}
+\DocumentationTok{\#\# Splitting the morphospace using the chrono.subsets function}
+\NormalTok{binned\_morphospace }\OtherTok{\textless{}{-}} \FunctionTok{chrono.subsets}\NormalTok{(}\AttributeTok{data =}\NormalTok{ my\_matrix, }\AttributeTok{tree =}\NormalTok{ my\_tree,}
+ \AttributeTok{method =} \StringTok{"discrete"}\NormalTok{, }\AttributeTok{time =}\NormalTok{ time\_bins, }\AttributeTok{inc.nodes =} \ConstantTok{FALSE}\NormalTok{,}
+ \AttributeTok{FADLAD =}\NormalTok{ my\_fadlad)}
\end{Highlighting}
\end{Shaded}
@@ -8408,8 +8458,8 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Printing the class of the object}
-\KeywordTok{class}\NormalTok{(binned\_morphospace)}
+\DocumentationTok{\#\# Printing the class of the object}
+\FunctionTok{class}\NormalTok{(binned\_morphospace)}
\end{Highlighting}
\end{Shaded}
@@ -8419,8 +8469,8 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Printing the content of the object}
-\KeywordTok{str}\NormalTok{(binned\_morphospace)}
+\DocumentationTok{\#\# Printing the content of the object}
+\FunctionTok{str}\NormalTok{(binned\_morphospace)}
\end{Highlighting}
\end{Shaded}
@@ -8461,7 +8511,7 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{names}\NormalTok{(binned\_morphospace)}
+\FunctionTok{names}\NormalTok{(binned\_morphospace)}
\end{Highlighting}
\end{Shaded}
@@ -8471,7 +8521,7 @@ \subsection{Splitting the morphospace through time}\label{splitting-the-morphosp
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Printing the object as a dispRity class}
+\DocumentationTok{\#\# Printing the object as a dispRity class}
\NormalTok{binned\_morphospace}
\end{Highlighting}
\end{Shaded}
@@ -8495,12 +8545,12 @@ \subsection{Bootstrapping the data}\label{bootstrapping-the-data-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Getting the minimum number of rows (i.e. taxa) in the time subsets}
-\NormalTok{minimum\_size \textless{}{-}}\StringTok{ }\KeywordTok{min}\NormalTok{(}\KeywordTok{size.subsets}\NormalTok{(binned\_morphospace))}
+\DocumentationTok{\#\# Getting the minimum number of rows (i.e. taxa) in the time subsets}
+\NormalTok{minimum\_size }\OtherTok{\textless{}{-}} \FunctionTok{min}\NormalTok{(}\FunctionTok{size.subsets}\NormalTok{(binned\_morphospace))}
-\CommentTok{\#\# Bootstrapping each time subset 100 times and rarefying them }
-\NormalTok{rare\_bin\_morphospace \textless{}{-}}\StringTok{ }\KeywordTok{boot.matrix}\NormalTok{(binned\_morphospace, }\DataTypeTok{bootstraps =} \DecValTok{100}\NormalTok{,}
- \DataTypeTok{rarefaction =}\NormalTok{ minimum\_size)}
+\DocumentationTok{\#\# Bootstrapping each time subset 100 times and rarefying them }
+\NormalTok{rare\_bin\_morphospace }\OtherTok{\textless{}{-}} \FunctionTok{boot.matrix}\NormalTok{(binned\_morphospace, }\AttributeTok{bootstraps =} \DecValTok{100}\NormalTok{,}
+ \AttributeTok{rarefaction =}\NormalTok{ minimum\_size)}
\end{Highlighting}
\end{Shaded}
@@ -8528,29 +8578,29 @@ \subsection{Calculating disparity}\label{calculating-disparity-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\NormalTok{my\_test \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(my\_matrix, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, dispRity}\OperatorTok{::}\NormalTok{variances), }\DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))}
-\KeywordTok{summary}\NormalTok{(my\_test)}
+\NormalTok{my\_test }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(my\_matrix, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, dispRity}\SpecialCharTok{::}\NormalTok{variances), }\AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))}
+\FunctionTok{summary}\NormalTok{(my\_test)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope
-## random 2.41 2.51 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0006434981
-## size.increase 2.23 2.19 2.25 2.33 2.31 2.35 2.43 2.44 2.48 2.52 0.0036071419
-## size.hollowness 2.40 2.56 2.56 2.60 2.63 2.64 2.60 2.58 2.55 2.52 0.0006032204
+## random 2.53 2.50 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0003234646
+## size.increase 2.23 2.17 2.25 2.26 2.31 2.35 2.39 2.47 2.50 2.52 0.0037712409
+## size.hollowness 2.40 2.50 2.59 2.65 2.63 2.62 2.60 2.57 2.55 2.52 0.0008954035
## p_value R^2(adj)
-## random 3.046683e-02 0.12638784
-## size.increase 4.009847e-16 0.90601561
-## size.hollowness 1.324664e-01 0.04783366
+## random 9.689431e-02 0.06301936
+## size.increase 1.016309e-17 0.93443767
+## size.hollowness 6.630162e-02 0.08377594
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{plot}\NormalTok{(my\_test)}
+\FunctionTok{plot}\NormalTok{(my\_test)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-226-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-242-1.pdf}
We see that changes in the inner size (see \citet{moms} for more details) is actually picked up by the sum of variances but not random changes or outer changes. Which is a good thing!
@@ -8562,8 +8612,8 @@ \subsection{Calculating disparity}\label{calculating-disparity-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Calculating disparity for the bootstrapped and rarefied data}
-\NormalTok{disparity \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(rare\_bin\_morphospace , }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(sum, dispRity}\OperatorTok{::}\NormalTok{variances))}
+\DocumentationTok{\#\# Calculating disparity for the bootstrapped and rarefied data}
+\NormalTok{disparity }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(rare\_bin\_morphospace , }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(sum, dispRity}\SpecialCharTok{::}\NormalTok{variances))}
\end{Highlighting}
\end{Shaded}
@@ -8572,8 +8622,8 @@ \subsection{Calculating disparity}\label{calculating-disparity-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising the disparity results}
-\KeywordTok{summary}\NormalTok{(disparity)}
+\DocumentationTok{\#\# Summarising the disparity results}
+\FunctionTok{summary}\NormalTok{(disparity)}
\end{Highlighting}
\end{Shaded}
@@ -8602,8 +8652,8 @@ \subsection{Plotting the results}\label{plotting-the-results}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Graphical options}
-\KeywordTok{quartz}\NormalTok{(}\DataTypeTok{width =} \DecValTok{10}\NormalTok{, }\DataTypeTok{height =} \DecValTok{5}\NormalTok{) ; }\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =}\NormalTok{ (}\KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)), }\DataTypeTok{bty =} \StringTok{"n"}\NormalTok{)}
+\DocumentationTok{\#\# Graphical options}
+\FunctionTok{quartz}\NormalTok{(}\AttributeTok{width =} \DecValTok{10}\NormalTok{, }\AttributeTok{height =} \DecValTok{5}\NormalTok{) ; }\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =}\NormalTok{ (}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{)), }\AttributeTok{bty =} \StringTok{"n"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -8614,14 +8664,14 @@ \subsection{Plotting the results}\label{plotting-the-results}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the bootstrapped and rarefied results}
-\KeywordTok{plot}\NormalTok{(disparity, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"bootstrapped results"}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(disparity, }\DataTypeTok{type =} \StringTok{"continuous"}\NormalTok{, }\DataTypeTok{main =} \StringTok{"rarefied results"}\NormalTok{,}
- \DataTypeTok{rarefaction =}\NormalTok{ minimum\_size)}
+\DocumentationTok{\#\# Plotting the bootstrapped and rarefied results}
+\FunctionTok{plot}\NormalTok{(disparity, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{main =} \StringTok{"bootstrapped results"}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(disparity, }\AttributeTok{type =} \StringTok{"continuous"}\NormalTok{, }\AttributeTok{main =} \StringTok{"rarefied results"}\NormalTok{,}
+ \AttributeTok{rarefaction =}\NormalTok{ minimum\_size)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-229-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-245-1.pdf}
Nice. The curves look pretty similar.
@@ -8640,9 +8690,9 @@ \subsection{Testing differences}\label{testing-differences}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing the differences between bins in the bootstrapped dataset.}
-\KeywordTok{test.dispRity}\NormalTok{(disparity, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{comparison =} \StringTok{"sequential"}\NormalTok{,}
- \DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
+\DocumentationTok{\#\# Testing the differences between bins in the bootstrapped dataset.}
+\FunctionTok{test.dispRity}\NormalTok{(disparity, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{comparison =} \StringTok{"sequential"}\NormalTok{,}
+ \AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
@@ -8664,9 +8714,9 @@ \subsection{Testing differences}\label{testing-differences}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing the differences between bins in the rarefied dataset.}
-\KeywordTok{test.dispRity}\NormalTok{(disparity, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{comparison =} \StringTok{"sequential"}\NormalTok{,}
- \DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{, }\DataTypeTok{rarefaction =}\NormalTok{ minimum\_size)}
+\DocumentationTok{\#\# Testing the differences between bins in the rarefied dataset.}
+\FunctionTok{test.dispRity}\NormalTok{(disparity, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{comparison =} \StringTok{"sequential"}\NormalTok{,}
+ \AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{, }\AttributeTok{rarefaction =}\NormalTok{ minimum\_size)}
\end{Highlighting}
\end{Shaded}
@@ -8723,14 +8773,14 @@ \section{Before starting}\label{before-starting-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Loading geomorph}
-\KeywordTok{library}\NormalTok{(geomorph)}
+\DocumentationTok{\#\# Loading geomorph}
+\FunctionTok{library}\NormalTok{(geomorph)}
-\CommentTok{\#\# Loading the plethodon dataset}
-\KeywordTok{data}\NormalTok{(plethodon)}
+\DocumentationTok{\#\# Loading the plethodon dataset}
+\FunctionTok{data}\NormalTok{(plethodon)}
-\CommentTok{\#\# Running a simple Procrustes superimposition}
-\NormalTok{gpa\_plethodon \textless{}{-}}\StringTok{ }\KeywordTok{gpagen}\NormalTok{(plethodon}\OperatorTok{$}\NormalTok{land)}
+\DocumentationTok{\#\# Running a simple Procrustes superimposition}
+\NormalTok{gpa\_plethodon }\OtherTok{\textless{}{-}} \FunctionTok{gpagen}\NormalTok{(plethodon}\SpecialCharTok{$}\NormalTok{land)}
\end{Highlighting}
\end{Shaded}
@@ -8744,10 +8794,10 @@ \section{Before starting}\label{before-starting-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Making a geomorph data frame object with the species and sites attributes}
-\NormalTok{gdf\_plethodon \textless{}{-}}\StringTok{ }\KeywordTok{geomorph.data.frame}\NormalTok{(gpa\_plethodon,}
- \DataTypeTok{species =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{species,}
- \DataTypeTok{site =}\NormalTok{ plethodon}\OperatorTok{$}\NormalTok{site)}
+\DocumentationTok{\#\# Making a geomorph data frame object with the species and sites attributes}
+\NormalTok{gdf\_plethodon }\OtherTok{\textless{}{-}} \FunctionTok{geomorph.data.frame}\NormalTok{(gpa\_plethodon,}
+ \AttributeTok{species =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{species,}
+ \AttributeTok{site =}\NormalTok{ plethodon}\SpecialCharTok{$}\NormalTok{site)}
\end{Highlighting}
\end{Shaded}
@@ -8755,8 +8805,8 @@ \section{Before starting}\label{before-starting-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# You can replace the gdf\_plethodon by your own geomorph data frame!}
-\NormalTok{my\_geomorph\_data \textless{}{-}}\StringTok{ }\NormalTok{gdf\_plethodon}
+\DocumentationTok{\#\# You can replace the gdf\_plethodon by your own geomorph data frame!}
+\NormalTok{my\_geomorph\_data }\OtherTok{\textless{}{-}}\NormalTok{ gdf\_plethodon}
\end{Highlighting}
\end{Shaded}
@@ -8777,8 +8827,8 @@ \subsection{The morphospace}\label{the-morphospace-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The morphospace}
-\NormalTok{morphospace \textless{}{-}}\StringTok{ }\KeywordTok{geomorph.ordination}\NormalTok{(gdf\_plethodon)}
+\DocumentationTok{\#\# The morphospace}
+\NormalTok{morphospace }\OtherTok{\textless{}{-}} \FunctionTok{geomorph.ordination}\NormalTok{(gdf\_plethodon)}
\end{Highlighting}
\end{Shaded}
@@ -8786,7 +8836,7 @@ \subsection{The morphospace}\label{the-morphospace-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The dispRity object}
+\DocumentationTok{\#\# The dispRity object}
\NormalTok{morphospace}
\end{Highlighting}
\end{Shaded}
@@ -8799,16 +8849,16 @@ \subsection{The morphospace}\label{the-morphospace-1}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the morphospace}
-\KeywordTok{plot}\NormalTok{(morphospace)}
+\DocumentationTok{\#\# Plotting the morphospace}
+\FunctionTok{plot}\NormalTok{(morphospace)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-234-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-250-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap!}
+\DocumentationTok{\#\# Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap!}
\end{Highlighting}
\end{Shaded}
@@ -8824,25 +8874,25 @@ \section{Calculating disparity}\label{calculating-disparity-2}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Defining a the procrustes variance metric}
-\CommentTok{\#\# (as in geomorph::morphol.disparity)}
-\NormalTok{proc.var \textless{}{-}}\StringTok{ }\ControlFlowTok{function}\NormalTok{(matrix) \{}\KeywordTok{sum}\NormalTok{(matrix}\OperatorTok{\^{}}\DecValTok{2}\NormalTok{)}\OperatorTok{/}\KeywordTok{nrow}\NormalTok{(matrix)\}}
+\DocumentationTok{\#\# Defining a the procrustes variance metric}
+\DocumentationTok{\#\# (as in geomorph::morphol.disparity)}
+\NormalTok{proc.var }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(matrix) \{}\FunctionTok{sum}\NormalTok{(matrix}\SpecialCharTok{\^{}}\DecValTok{2}\NormalTok{)}\SpecialCharTok{/}\FunctionTok{nrow}\NormalTok{(matrix)\}}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# The size metric}
-\NormalTok{test\_size \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(morphospace, }\DataTypeTok{metric =}\NormalTok{ proc.var,}
- \DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(test\_size)}
-\KeywordTok{summary}\NormalTok{(test\_size)}
+\DocumentationTok{\#\# The size metric}
+\NormalTok{test\_size }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(morphospace, }\AttributeTok{metric =}\NormalTok{ proc.var,}
+ \AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"size"}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(test\_size)}
+\FunctionTok{summary}\NormalTok{(test\_size)}
-\CommentTok{\#\# The position metric}
-\NormalTok{test\_position \textless{}{-}}\StringTok{ }\KeywordTok{test.metric}\NormalTok{(morphospace, }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, displacements),}
- \DataTypeTok{shifts =} \KeywordTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"position"}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(test\_position)}
-\KeywordTok{summary}\NormalTok{(test\_position)}
+\DocumentationTok{\#\# The position metric}
+\NormalTok{test\_position }\OtherTok{\textless{}{-}} \FunctionTok{test.metric}\NormalTok{(morphospace, }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, displacements),}
+ \AttributeTok{shifts =} \FunctionTok{c}\NormalTok{(}\StringTok{"random"}\NormalTok{, }\StringTok{"position"}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(test\_position)}
+\FunctionTok{summary}\NormalTok{(test\_position)}
\end{Highlighting}
\end{Shaded}
@@ -8857,9 +8907,9 @@ \section{Calculating disparity}\label{calculating-disparity-2}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Bootstrapped disparity}
-\NormalTok{disparity\_size \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(morphospace), }\DataTypeTok{metric =}\NormalTok{ proc.var)}
-\NormalTok{disparity\_position \textless{}{-}}\StringTok{ }\KeywordTok{dispRity}\NormalTok{(}\KeywordTok{boot.matrix}\NormalTok{(morphospace), }\DataTypeTok{metric =} \KeywordTok{c}\NormalTok{(mean, displacements))}
+\DocumentationTok{\#\# Bootstrapped disparity}
+\NormalTok{disparity\_size }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(morphospace), }\AttributeTok{metric =}\NormalTok{ proc.var)}
+\NormalTok{disparity\_position }\OtherTok{\textless{}{-}} \FunctionTok{dispRity}\NormalTok{(}\FunctionTok{boot.matrix}\NormalTok{(morphospace), }\AttributeTok{metric =} \FunctionTok{c}\NormalTok{(mean, displacements))}
\end{Highlighting}
\end{Shaded}
@@ -8873,25 +8923,25 @@ \section{Analyse the results}\label{analyse-the-results}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Plotting the results}
-\KeywordTok{par}\NormalTok{(}\DataTypeTok{mfrow =} \KeywordTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
-\KeywordTok{plot}\NormalTok{(disparity\_size, }\DataTypeTok{main =} \StringTok{"group sizes"}\NormalTok{, }\DataTypeTok{las =} \DecValTok{2}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{)}
-\KeywordTok{plot}\NormalTok{(disparity\_position, }\DataTypeTok{main =} \StringTok{"group positions"}\NormalTok{, }\DataTypeTok{las =} \DecValTok{2}\NormalTok{, }\DataTypeTok{xlab =} \StringTok{""}\NormalTok{)}
+\DocumentationTok{\#\# Plotting the results}
+\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow =} \FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
+\FunctionTok{plot}\NormalTok{(disparity\_size, }\AttributeTok{main =} \StringTok{"group sizes"}\NormalTok{, }\AttributeTok{las =} \DecValTok{2}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{)}
+\FunctionTok{plot}\NormalTok{(disparity\_position, }\AttributeTok{main =} \StringTok{"group positions"}\NormalTok{, }\AttributeTok{las =} \DecValTok{2}\NormalTok{, }\AttributeTok{xlab =} \StringTok{""}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
-\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-238-1.pdf}
+\includegraphics{dispRity_manual_files/figure-latex/unnamed-chunk-254-1.pdf}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Summarising the results}
-\KeywordTok{summary}\NormalTok{(disparity\_size)}
+\DocumentationTok{\#\# Summarising the results}
+\FunctionTok{summary}\NormalTok{(disparity\_size)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.006
+## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.005
## 2 species.Teyah 20 0.005 0.005 0.004 0.005 0.005 0.006
## 3 site.Allo 20 0.004 0.004 0.003 0.003 0.004 0.004
## 4 site.Symp 20 0.006 0.006 0.006 0.006 0.006 0.007
@@ -8899,16 +8949,16 @@ \section{Analyse the results}\label{analyse-the-results}}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{summary}\NormalTok{(disparity\_position)}
+\FunctionTok{summary}\NormalTok{(disparity\_position)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 species.Jord 20 1.096 1.122 1.067 1.101 1.171 1.380
-## 2 species.Teyah 20 1.070 1.105 1.033 1.065 1.143 1.345
-## 3 site.Allo 20 1.377 1.407 1.315 1.381 1.448 1.530
-## 4 site.Symp 20 1.168 1.221 1.148 1.187 1.269 1.458
+## 1 species.Jord 20 1.096 1.122 1.069 1.104 1.168 1.404
+## 2 species.Teyah 20 1.070 1.095 1.029 1.070 1.146 1.320
+## 3 site.Allo 20 1.377 1.415 1.311 1.369 1.464 1.526
+## 4 site.Symp 20 1.168 1.220 1.158 1.190 1.270 1.498
\end{verbatim}
Just from looking at the data, we can guess that there is not much difference in terms of morphospace occupancy and position for the species but there is on for the sites (allopatric or sympatric).
@@ -8916,55 +8966,55 @@ \section{Analyse the results}\label{analyse-the-results}}
\begin{Shaded}
\begin{Highlighting}[]
-\CommentTok{\#\# Testing the differences}
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_size, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
+\DocumentationTok{\#\# Testing the differences}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_size, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [[1]]
## statistic: W
-## species.Jord : species.Teyah 3803
-## species.Jord : site.Allo 9922
-## species.Jord : site.Symp 14
-## species.Teyah : site.Allo 9927
-## species.Teyah : site.Symp 238
+## species.Jord : species.Teyah 3842
+## species.Jord : site.Allo 9919
+## species.Jord : site.Symp 7
+## species.Teyah : site.Allo 9939
+## species.Teyah : site.Symp 155
## site.Allo : site.Symp 0
##
## [[2]]
## p.value
-## species.Jord : species.Teyah 2.076623e-02
-## species.Jord : site.Allo 1.572891e-32
-## species.Jord : site.Symp 2.339811e-33
-## species.Teyah : site.Allo 1.356528e-32
-## species.Teyah : site.Symp 1.657077e-30
+## species.Jord : species.Teyah 2.808435e-02
+## species.Jord : site.Allo 1.718817e-32
+## species.Jord : site.Symp 1.896841e-33
+## species.Teyah : site.Allo 9.504256e-33
+## species.Teyah : site.Symp 1.507734e-31
## site.Allo : site.Symp 1.537286e-33
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
-\KeywordTok{test.dispRity}\NormalTok{(disparity\_position, }\DataTypeTok{test =}\NormalTok{ wilcox.test, }\DataTypeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
+\FunctionTok{test.dispRity}\NormalTok{(disparity\_position, }\AttributeTok{test =}\NormalTok{ wilcox.test, }\AttributeTok{correction =} \StringTok{"bonferroni"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [[1]]
## statistic: W
-## species.Jord : species.Teyah 6536
-## species.Jord : site.Allo 204
-## species.Jord : site.Symp 1473
-## species.Teyah : site.Allo 103
-## species.Teyah : site.Symp 1042
-## site.Allo : site.Symp 9288
+## species.Jord : species.Teyah 6639
+## species.Jord : site.Allo 262
+## species.Jord : site.Symp 1386
+## species.Teyah : site.Allo 91
+## species.Teyah : site.Symp 981
+## site.Allo : site.Symp 9373
##
## [[2]]
## p.value
-## species.Jord : species.Teyah 1.053318e-03
-## species.Jord : site.Allo 6.238014e-31
-## species.Jord : site.Symp 4.137900e-17
-## species.Teyah : site.Allo 3.289139e-32
-## species.Teyah : site.Symp 2.433117e-21
-## site.Allo : site.Symp 6.679158e-25
+## species.Jord : species.Teyah 3.744848e-04
+## species.Jord : site.Allo 3.288928e-30
+## species.Jord : site.Symp 6.326430e-18
+## species.Teyah : site.Allo 2.309399e-32
+## species.Teyah : site.Symp 5.609280e-22
+## site.Allo : site.Symp 7.278818e-26
\end{verbatim}
So by applying the tests we see a difference in terms of position between each groups and differences in size between groups but between the species.
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot1-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot1-1.png
index 5025d60f..8cd88ec2 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot1-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot1-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot2-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot2-1.png
index d716d67f..822bcb60 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot2-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot2-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot3-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot3-1.png
index 5997c799..c396a54c 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot3-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot3-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot4-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot4-1.png
index 3c04653f..5fa63b88 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot4-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot4-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot5-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot5-1.png
index 2e70f767..20014f72 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot5-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot5-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot6-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot6-1.png
index dba4b00a..4a5ce825 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot6-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot6-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot7-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot7-1.png
index 4cd29e7b..b782ba13 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot7-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot7-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot8-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot8-1.png
index 56e484be..72d5b077 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/plot8-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/plot8-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-129-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-129-1.png
deleted file mode 100644
index 3009d0d3..00000000
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-129-1.png and /dev/null differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-13-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-13-1.png
index 3f1b1792..1e560699 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-13-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-13-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-130-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-130-1.png
new file mode 100644
index 00000000..2436a56a
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-130-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-144-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-144-1.png
deleted file mode 100644
index 27f94d6c..00000000
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-144-1.png and /dev/null differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-145-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-145-1.png
new file mode 100644
index 00000000..a0237460
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-145-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-149-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-149-1.png
new file mode 100644
index 00000000..99c8c03c
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-149-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-16-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-16-1.png
index e691817d..70b9ce04 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-16-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-16-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-167-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-167-1.png
new file mode 100644
index 00000000..f6c28d53
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-167-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-170-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-170-1.png
index 08030140..cd1be204 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-170-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-170-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-171-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-171-1.png
new file mode 100644
index 00000000..ba822620
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-171-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-172-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-172-1.png
new file mode 100644
index 00000000..f0bb7169
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-172-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-178-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-178-1.png
new file mode 100644
index 00000000..2ebae1c3
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-178-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-179-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-179-1.png
new file mode 100644
index 00000000..315bac5a
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-179-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-18-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-18-1.png
index 16ed8349..2565abcb 100644
Binary files a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-18-1.png and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-18-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-224-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-224-1.png
new file mode 100644
index 00000000..6c383c8e
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-224-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-225-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-225-1.png
new file mode 100644
index 00000000..829da642
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-225-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-234-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-234-1.png
new file mode 100644
index 00000000..9c4fd5f2
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-234-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-242-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-242-1.png
new file mode 100644
index 00000000..3b08393b
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-242-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-84-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-84-1.png
new file mode 100644
index 00000000..c7d613c8
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-84-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-85-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-85-1.png
new file mode 100644
index 00000000..2b0de228
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-85-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-86-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-86-1.png
new file mode 100644
index 00000000..2527e688
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-86-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-87-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-87-1.png
new file mode 100644
index 00000000..d6098a0a
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-87-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-88-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-88-1.png
new file mode 100644
index 00000000..91454157
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-88-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-89-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-89-1.png
new file mode 100644
index 00000000..00b57fab
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-89-1.png differ
diff --git a/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-90-1.png b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-90-1.png
new file mode 100644
index 00000000..44983f58
Binary files /dev/null and b/inst/gitbook/_book/dispRity_manual_files/figure-html/unnamed-chunk-90-1.png differ
diff --git a/inst/gitbook/_book/disprity-ecology-demo.html b/inst/gitbook/_book/disprity-ecology-demo.html
index fecb274d..15012175 100644
--- a/inst/gitbook/_book/disprity-ecology-demo.html
+++ b/inst/gitbook/_book/disprity-ecology-demo.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -364,17 +397,17 @@ 8 dispRity ecology demo
8.1 Data
For this example, we will use the famous iris
inbuilt data set
-data(iris)
+
This data contains petal and sepal length for 150 individual plants sorted into three species.
-## Separating the species
- iris[,5]
- species <-## Which species?
-unique(species)
+
## [1] setosa versicolor virginica
## Levels: setosa versicolor virginica
-## Separating the petal/sepal length
- iris[,1:4]
- measurements <-head(measurements)
+
## Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1 5.1 3.5 1.4 0.2
## 2 4.9 3.0 1.4 0.2
@@ -383,39 +416,39 @@ 8.1 Data## Ordinating the data
- prcomp(measurements)
- ordination <-
-## The petal-space
- ordination$x
- petal_space <-
-## Adding the elements names to the petal-space (the individuals IDs)
-rownames(petal_space) <- 1:nrow(petal_space)
+
8.2 Classic analysis
A classical way to represent this ordinated data would be to use two dimensional plots to look at how the different species are distributed in the petal-space.
-## Measuring the variance on each axis
- apply(petal_space, 2, var)
- axis_variances <- axis_variances/sum(axis_variances)
- axis_variances <-
-## Graphical option
-par(bty = "n")
-
-## A classic 2D ordination plot
-plot(petal_space[, 1], petal_space[, 2], col = species,
-xlab = paste0("PC 1 (", round(axis_variances[1], 2), ")"),
- ylab = paste0("PC 2 (", round(axis_variances[2], 2), ")"))
-
+## Measuring the variance on each axis
+axis_variances <- apply(petal_space, 2, var)
+axis_variances <- axis_variances/sum(axis_variances)
+
+## Graphical option
+par(bty = "n")
+
+## A classic 2D ordination plot
+plot(petal_space[, 1], petal_space[, 2], col = species,
+ xlab = paste0("PC 1 (", round(axis_variances[1], 2), ")"),
+ ylab = paste0("PC 2 (", round(axis_variances[2], 2), ")"))
+
This shows the distribution of the different species in the petal-space along the two first axis of variation.
This is a pretty standard way to visualise the multidimensional space and further analysis might be necessary to test wether the groups are different such as a linear discriminant analysis (LDA).
However, in this case we are ignoring the two other dimensions of the ordination!
If we look at the two other axis we see a totally different result:
-## Plotting the two second axis of the petal-space
-plot(petal_space[, 3], petal_space[, 4], col = species,
-xlab = paste0("PC 3 (", round(axis_variances[3], 2), ")"),
- ylab = paste0("PC 4 (", round(axis_variances[4], 2), ")"))
-
+## Plotting the two second axis of the petal-space
+plot(petal_space[, 3], petal_space[, 4], col = species,
+ xlab = paste0("PC 3 (", round(axis_variances[3], 2), ")"),
+ ylab = paste0("PC 4 (", round(axis_variances[4], 2), ")"))
+
Additionally, these two represented dimensions do not represent a biological reality per se; i.e. the values on the first dimension do not represent a continuous trait (e.g. petal length), instead they just represent the ordinations of correlations between the data and some factors.
Therefore, we might want to approach this problem without getting stuck in only two dimensions and consider the whole dataset as a n-dimensional object.
@@ -423,14 +456,14 @@ 8.2 Classic analysis8.3 A multidimensional approach with dispRity
The first step is to create different subsets that represent subsets of the ordinated space (i.e. sub-regions within the n-dimensional object).
Each of these subsets will contain only the individuals of a specific species.
-## Creating the table that contain the elements and their attributes
- custom.subsets(petal_space, group = list(
- petal_subsets <-"setosa" = which(species == "setosa"),
- "versicolor" = which(species == "versicolor"),
- "virginica" = which(species == "virginica")))
-
-## Visualising the dispRity object content
- petal_subsets
+## Creating the table that contain the elements and their attributes
+petal_subsets <- custom.subsets(petal_space, group = list(
+ "setosa" = which(species == "setosa"),
+ "versicolor" = which(species == "versicolor"),
+ "virginica" = which(species == "virginica")))
+
+## Visualising the dispRity object content
+petal_subsets
## ---- dispRity object ----
## 3 customised subsets for 150 elements in one matrix:
## setosa, versicolor, virginica.
@@ -439,12 +472,12 @@ 8.3 A multidimensional approach w
8.3.1 Bootstrapping the data
We can the bootstrap the subsets to be able test the robustness of the measured disparity to outliers.
We can do that using the default options of boot.matrix
(more about that here):
-## Bootstrapping the data
- boot.matrix(petal_subsets)) (petal_bootstrapped <-
+
## ---- dispRity object ----
## 3 customised subsets for 150 elements in one matrix with 4 dimensions:
## setosa, versicolor, virginica.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
8.3.2 Calculating disparity
@@ -454,13 +487,13 @@ 8.3.2 Calculating disparitydispRity function by feeding them to the metric
argument.
Here we are going to feed the functions stats::median
and dispRity::centroids
which calculates distances between elements and their centroid.
-## Calculating disparity as the median distance between each elements and
-## the centroid of the petal-space
- dispRity(petal_bootstrapped, metric = c(median, centroids))) (petal_disparity <-
+## Calculating disparity as the median distance between each elements and
+## the centroid of the petal-space
+(petal_disparity <- dispRity(petal_bootstrapped, metric = c(median, centroids)))
## ---- dispRity object ----
## 3 customised subsets for 150 elements in one matrix with 4 dimensions:
## setosa, versicolor, virginica.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: c(median, centroids).
@@ -468,83 +501,82 @@ 8.3.3 Summarising the results (pl
Similarly to the custom.subsets
and boot.matrix
function, dispRity
displays a dispRity
object.
But we are definitely more interested in actually look at the calculated values.
First we can summarise the data in a table by simply using summary
:
-## Displaying the summary of the calculated disparity
-summary(petal_disparity)
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 setosa 50 0.421 0.432 0.370 0.408 0.454 0.501
-## 2 versicolor 50 0.693 0.656 0.511 0.619 0.697 0.770
-## 3 virginica 50 0.785 0.747 0.580 0.674 0.806 0.936
+## 1 setosa 50 0.421 0.432 0.363 0.409 0.456 0.502
+## 2 versicolor 50 0.693 0.662 0.563 0.618 0.702 0.781
+## 3 virginica 50 0.785 0.719 0.548 0.652 0.786 0.902
We can also plot the results in a similar way:
-## Graphical options
-par(bty = "n")
-
-## Plotting the disparity in the petal_space
-plot(petal_disparity)
-
+## Graphical options
+par(bty = "n")
+
+## Plotting the disparity in the petal_space
+plot(petal_disparity)
+
Now contrary to simply plotting the two first axis of the PCA where we saw that the species have a different position in the two first petal-space, we can now also see that they occupy this space clearly differently!
8.3.4 Testing hypothesis
Finally we can test our hypothesis that we guessed from the disparity plot (that some groups occupy different volume of the petal-space) by using the test.dispRity
option.
-## Running a PERMANOVA
-test.dispRity(petal_disparity, test = adonis.dispRity)
+
## Warning in test.dispRity(petal_disparity, test = adonis.dispRity): adonis.dispRity test will be applied to the data matrix, not to the calculated disparity.
## See ?adonis.dispRity for more details.
## Warning in adonis.dispRity(data, ...): The input data for adonis.dispRity was not a distance matrix.
## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])).
## Make sure that this is the desired methodological approach!
## Permutation test for adonis under reduced model
-## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 999
##
## vegan::adonis2(formula = dist(matrix) ~ group, method = "euclidean")
## Df SumOfSqs R2 F Pr(>F)
-## group 2 592.07 0.86894 487.33 0.001 ***
+## Model 2 592.07 0.86894 487.33 0.001 ***
## Residual 147 89.30 0.13106
## Total 149 681.37 1.00000
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
-## Post-hoc testing of the differences between species (corrected for multiple tests)
-test.dispRity(petal_disparity, test = t.test, correction = "bonferroni")
+## Post-hoc testing of the differences between species (corrected for multiple tests)
+test.dispRity(petal_disparity, test = t.test, correction = "bonferroni")
## [[1]]
## statistic: t
-## setosa : versicolor -29.998366
-## setosa : virginica -30.465933
-## versicolor : virginica -7.498179
+## setosa : versicolor -33.37334
+## setosa : virginica -28.36656
+## versicolor : virginica -5.24564
##
## [[2]]
## parameter: df
-## setosa : versicolor 149.8429
-## setosa : virginica 124.4227
-## versicolor : virginica 175.4758
+## setosa : versicolor 166.2319
+## setosa : virginica 127.7601
+## versicolor : virginica 164.6248
##
## [[3]]
## p.value
-## setosa : versicolor 9.579095e-65
-## setosa : virginica 4.625567e-59
-## versicolor : virginica 9.247421e-12
+## setosa : versicolor 4.126944e-75
+## setosa : virginica 1.637347e-56
+## versicolor : virginica 1.420552e-06
##
## [[4]]
## stderr
-## setosa : versicolor 0.007378905
-## setosa : virginica 0.010103449
-## versicolor : virginica 0.011530255
+## setosa : versicolor 0.006875869
+## setosa : virginica 0.010145340
+## versicolor : virginica 0.011117360
We can now see that there is a significant difference in petal-space occupancy between all species of iris.
8.3.4.1 Setting up a multidimensional null-hypothesis
One other series of test can be done on the shape of the petal-space.
-Using a MCMC permutation test we can simulate a petal-space with specific properties and see if our observed petal-space matches these properties (similarly to Dı́az et al. (2016)):
-## Testing against a uniform distribution
- null.test(petal_disparity, replicates = 200,
- disparity_uniform <-null.distrib = runif, scale = FALSE)
- plot(disparity_uniform)
-
-## Testing against a normal distribution
- null.test(petal_disparity, replicates = 200,
- disparity_normal <-null.distrib = rnorm, scale = TRUE)
- plot(disparity_normal)
-
+Using a MCMC permutation test we can simulate a petal-space with specific properties and see if our observed petal-space matches these properties (similarly to Dı́az et al. (2016)):
+## Testing against a uniform distribution
+disparity_uniform <- null.test(petal_disparity, replicates = 200,
+ null.distrib = runif, scale = FALSE)
+plot(disparity_uniform)
+
+## Testing against a normal distribution
+disparity_normal <- null.test(petal_disparity, replicates = 200,
+ null.distrib = rnorm, scale = TRUE)
+plot(disparity_normal)
+
In both cases we can see that our petal-space is not entirely normal or uniform.
This is expected because of the simplicity of these parameters.
@@ -553,9 +585,9 @@ 8.3.4.1 Setting up a multidimensi
References
-
-
-Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
+
+
+Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
diff --git a/inst/gitbook/_book/disprity-r-package-manual.html b/inst/gitbook/_book/disprity-r-package-manual.html
index 7d26eb58..1f8efb05 100644
--- a/inst/gitbook/_book/disprity-r-package-manual.html
+++ b/inst/gitbook/_book/disprity-r-package-manual.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
diff --git a/inst/gitbook/_book/getting-started-with-disprity.html b/inst/gitbook/_book/getting-started-with-disprity.html
index bd38ab61..50de5205 100644
--- a/inst/gitbook/_book/getting-started-with-disprity.html
+++ b/inst/gitbook/_book/getting-started-with-disprity.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
-
- 7 The guts of the
dispRity
package
@@ -293,7 +326,7 @@
@@ -379,17 +412,17 @@ 3.2 Ordinated matrices3.2.1 Ordination matrices from geomorph
You can also easily use data from geomorph
using the geomorph.ordination
function.
This function simply takes Procrustes aligned data and performs an ordination:
-require(geomorph)
-
-## Loading the plethodon dataset
-data(plethodon)
-
-## Performing a Procrustes transform on the landmarks
- gpagen(plethodon$land, PrinAxes = FALSE,
- procrustes <-print.progress = FALSE)
-
-## Ordinating this data
-geomorph.ordination(procrustes)[1:5,1:5]
+require(geomorph)
+
+## Loading the plethodon dataset
+data(plethodon)
+
+## Performing a Procrustes transform on the landmarks
+procrustes <- gpagen(plethodon$land, PrinAxes = FALSE,
+ print.progress = FALSE)
+
+## Ordinating this data
+geomorph.ordination(procrustes)[1:5,1:5]
## PC1 PC2 PC3 PC4 PC5
## [1,] -0.0369930887 0.05118246 -0.0016971586 -0.003128881 -0.010935739
## [2,] -0.0007493689 0.05942083 0.0001371682 -0.002768621 -0.008117767
@@ -399,12 +432,12 @@ 3.2.1 Ordination matrices from Options for the ordination (from ?prcomp
) can be directly passed to this function to perform customised ordinations.
Additionally you can give the function a geomorph.data.frame
object.
If the latter contains sorting information (i.e. factors), they can be directly used to make a customised dispRity
object customised dispRity
object!
-## Using a geomorph.data.frame
- geomorph.data.frame(procrustes,
- geomorph_df <-species = plethodon$species, site = plethodon$site)
-
-## Ordinating this data and making a dispRity object
-geomorph.ordination(geomorph_df)
+## Using a geomorph.data.frame
+geomorph_df <- geomorph.data.frame(procrustes,
+ species = plethodon$species, site = plethodon$site)
+
+## Ordinating this data and making a dispRity object
+geomorph.ordination(geomorph_df)
## ---- dispRity object ----
## 4 customised subsets for 40 elements in one matrix:
## species.Jord, species.Teyah, site.Allo, site.Symp.
@@ -414,10 +447,10 @@ 3.2.1 Ordination matrices from 3.2.2 Ordination matrices from Claddis
dispRity
package can also easily take data from the Claddis
package using the Claddis.ordination
function.
For this, simply input a matrix in the Claddis
format to the function and it will automatically calculate and ordinate the distances among taxa:
-require(Claddis)
-
-## Ordinating the example data from Claddis
-Claddis.ordination(michaux_1989)
+
## [,1] [,2] [,3]
## Ancilla 0.000000e+00 4.154578e-01 0.2534942
## Turrancilla -5.106645e-01 -1.304614e-16 -0.2534942
@@ -434,8 +467,8 @@ 3.2.3 Other kinds of ordination m
- Multivariate matrices (principal components analysis; PCA)
-## A multivariate matrix
-head(USArrests)
+
## Murder Assault UrbanPop Rape
## Alabama 13.2 236 58 21.2
## Alaska 10.0 263 48 44.5
@@ -443,12 +476,12 @@ 3.2.3 Other kinds of ordination m
## Arkansas 8.8 190 50 19.5
## California 9.0 276 91 40.6
## Colorado 7.9 204 78 38.7
-## Ordinating the matrix using `prcomp`
- prcomp(USArrests)
- ordination <-
-## Selecting the ordinated matrix
- ordination$x
- ordinated_matrix <-head(ordinated_matrix)
+## Ordinating the matrix using `prcomp`
+ordination <- prcomp(USArrests)
+
+## Selecting the ordinated matrix
+ordinated_matrix <- ordination$x
+head(ordinated_matrix)
## PC1 PC2 PC3 PC4
## Alabama 64.80216 -11.448007 -2.4949328 -2.4079009
## Alaska 92.82745 -17.982943 20.1265749 4.0940470
@@ -460,14 +493,14 @@ 3.2.3 Other kinds of ordination m
- Distance matrices (classical multidimensional scaling; MDS)
-## A matrix of distances between cities
-str(eurodist)
+
## 'dist' num [1:210] 3313 2963 3175 3339 2762 ...
## - attr(*, "Size")= num 21
## - attr(*, "Labels")= chr [1:21] "Athens" "Barcelona" "Brussels" "Calais" ...
-## Ordinating the matrix using cmdscale() with k = 5 dimensions
- cmdscale(eurodist, k = 5)
- ordinated_matrix <-head(ordinated_matrix)
+## Ordinating the matrix using cmdscale() with k = 5 dimensions
+ordinated_matrix <- cmdscale(eurodist, k = 5)
+head(ordinated_matrix)
## [,1] [,2] [,3] [,4] [,5]
## Athens 2290.27468 1798.8029 53.79314 -103.82696 -156.95511
## Barcelona -825.38279 546.8115 -113.85842 84.58583 291.44076
@@ -497,31 +530,31 @@ 3.3 Performing a simple dispRity
Note that any of these default arguments can be changed within the disparity.through.time
or disparity.per.group
functions.
3.3.1 Example data
-To illustrate these functions, we will use data from Beck and Lee (2014).
+
To illustrate these functions, we will use data from Beck and Lee (2014).
This dataset contains an ordinated matrix of 50 discrete characters from mammals (BeckLee_mat50
), another matrix of the same 50 mammals and the estimated discrete data characters of their descendants (thus 50 + 49 rows, BeckLee_mat99
), a dataframe containing the ages of each taxon in the dataset (BeckLee_ages
) and finally a phylogenetic tree with the relationships among the 50 mammals (BeckLee_tree
).
-## Loading the ordinated matrices
-data(BeckLee_mat50)
-data(BeckLee_mat99)
-
-## The first five taxa and dimensions of the 50 taxa matrix
-head(BeckLee_mat50[, 1:5])
-## [,1] [,2] [,3] [,4] [,5]
-## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039
-## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479
-## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646
-## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626
-## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914
-## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351
-## The first five taxa and dimensions of the 99 taxa + ancestors matrix
-c(1, 2, 98, 99), 1:5] BeckLee_mat99[
-## [,1] [,2] [,3] [,4] [,5]
-## Cimolestes -0.6794737 0.15658591 0.04918307 0.22509831 -0.38139436
-## Maelestes -0.5797289 0.04223105 -0.20329542 -0.15453876 -0.06993258
-## n48 0.2614394 0.01712426 0.21997583 -0.05383777 0.07919679
-## n49 0.3881123 0.13771446 0.11966941 0.01856597 -0.15263921
-## Loading a list of first and last occurrence dates for the fossils
-data(BeckLee_ages)
-head(BeckLee_ages)
+## Loading the ordinated matrices
+data(BeckLee_mat50)
+data(BeckLee_mat99)
+
+## The first five taxa and dimensions of the 50 taxa matrix
+head(BeckLee_mat50[, 1:5])
+## [,1] [,2] [,3] [,4] [,5]
+## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039
+## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479
+## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646
+## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626
+## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914
+## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351
+## The first five taxa and dimensions of the 99 taxa + ancestors matrix
+BeckLee_mat99[c(1, 2, 98, 99), 1:5]
+## [,1] [,2] [,3] [,4] [,5]
+## Cimolestes -0.6662114 0.152778203 0.04859246 -0.34158286 0.26817202
+## Maelestes -0.5719365 0.051636855 -0.19877079 -0.08318416 -0.14166592
+## n48 0.2511551 -0.002014967 0.22408002 0.06857018 -0.05660113
+## n49 0.3860798 0.131742956 0.12604056 -0.14738050 0.05095751
+## Loading a list of first and last occurrence dates for the fossils
+data(BeckLee_ages)
+head(BeckLee_ages)
## FAD LAD
## Adapis 37.2 36.8
## Asioryctes 83.6 72.1
@@ -529,11 +562,11 @@ 3.3.1 Example data## Loading and plotting the phylogeny
-data(BeckLee_tree)
-plot(BeckLee_tree, cex = 0.8)
-axisPhylo(root = 140)
-nodelabels(cex = 0.5)
+
Of course you can use your own data as detailed in the previous section.
@@ -550,34 +583,34 @@ 3.3.2 Disparity through timeYour favourite disparity metric (here the sum of variances)
Using the Beck and Lee (2014) data described above:
-## Measuring disparity through time
- dispRity.through.time(BeckLee_mat50, BeckLee_tree,
- disparity_data <-metric = c(sum, variances),
- time = 3)
+## Measuring disparity through time
+disparity_data <- dispRity.through.time(BeckLee_mat50, BeckLee_tree,
+ metric = c(sum, variances),
+ time = 3)
This generates a dispRity
object (see here for technical details).
When displayed, these dispRity
objects provide us with information on the operations done to the matrix:
-## Print the disparity_data object
- disparity_data
+
## ---- dispRity object ----
## 3 discrete time subsets for 50 elements in one matrix with 48 dimensions with 1 phylogenetic tree
## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: metric.
We asked for three subsets (evenly spread across the age of the tree), the data was bootstrapped 100 times (default) and the metric used was the sum of variances.
We can now summarise or plot the disparity_data
object, or perform statistical tests on it (e.g. a simple lm
):
-## Summarising disparity through time
-summary(disparity_data)
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
## 1 133.51 - 89.01 5 2.123 1.775 1.017 1.496 1.942 2.123
## 2 89.01 - 44.5 29 2.456 2.384 2.295 2.350 2.404 2.427
## 3 44.5 - 0 16 2.528 2.363 2.213 2.325 2.406 2.466
-## Plotting the results
-plot(disparity_data, type = "continuous")
+
-## Testing for an difference among the time bins
- test.dispRity(disparity_data, test = lm,
- disp_lm <-comparisons = "all")
- summary(disp_lm)
+## Testing for an difference among the time bins
+disp_lm <- test.dispRity(disparity_data, test = lm,
+ comparisons = "all")
+summary(disp_lm)
##
## Call:
## test(formula = data ~ subsets, data = data)
@@ -610,32 +643,32 @@ 3.3.3 Disparity among groupsA list of group members: this list should be a list of numeric vectors or names corresponding to the row names in the matrix. For example list("A" = c(1,2), "B" = c(3,4))
will create a group A containing elements 1 and 2 from the matrix and a group B containing elements 3 and 4. Note that elements can be present in multiple groups at once.
Your favourite disparity metric (here the sum of variances)
-Using the Beck and Lee (2014) data described above:
-## Creating the two groups (crown versus stem) as a list
- crown.stem(BeckLee_tree, inc.nodes = FALSE)
- mammal_groups <-
-## Measuring disparity for each group
- dispRity.per.group(BeckLee_mat50,
- disparity_data <-group = mammal_groups,
- metric = c(sum, variances))
+Using the Beck and Lee (2014) data described above:
+## Creating the two groups (crown versus stem) as a list
+mammal_groups <- crown.stem(BeckLee_tree, inc.nodes = FALSE)
+
+## Measuring disparity for each group
+disparity_data <- dispRity.per.group(BeckLee_mat50,
+ group = mammal_groups,
+ metric = c(sum, variances))
We can display the disparity of both groups by simply looking at the output variable (disparity_data
) and then summarising the disparity_data
object and plotting it, and/or by performing a statistical test to compare disparity across the groups (here a Wilcoxon test).
-## Print the disparity_data object
- disparity_data
+
## ---- dispRity object ----
## 2 customised subsets for 50 elements in one matrix with 48 dimensions:
## crown, stem.
-## Data was bootstrapped 100 times (method:"full").
+## Rows were bootstrapped 100 times (method:"full").
## Disparity was calculated as: metric.
-## Summarising disparity in the different groups
-summary(disparity_data)
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
## 1 crown 30 2.526 2.446 2.380 2.429 2.467 2.498
## 2 stem 20 2.244 2.134 2.025 2.105 2.164 2.208
-## Plotting the results
-plot(disparity_data)
+
-## Testing for a difference between the groups
-test.dispRity(disparity_data, test = wilcox.test, details = TRUE)
+## Testing for a difference between the groups
+test.dispRity(disparity_data, test = wilcox.test, details = TRUE)
## $`crown : stem`
## $`crown : stem`[[1]]
##
@@ -649,9 +682,9 @@ 3.3.3 Disparity among groups
References
-
-
-Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
+
+
+Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
diff --git a/inst/gitbook/_book/glossary.html b/inst/gitbook/_book/glossary.html
index f68a6bbd..7cbf9f12 100644
--- a/inst/gitbook/_book/glossary.html
+++ b/inst/gitbook/_book/glossary.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
diff --git a/inst/gitbook/_book/index.html b/inst/gitbook/_book/index.html
index 31614f86..a7f5035b 100644
--- a/inst/gitbook/_book/index.html
+++ b/inst/gitbook/_book/index.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -361,7 +394,7 @@
dispRity R package manual
-2023-12-06
+2024-11-12
1 dispRity
@@ -386,13 +419,13 @@ 1.1.1 Modular?
1.2 Installing and running the package
You can install this package easily, directly from the CRAN:
-install.packages("dispRity")
+
Alternatively, for the most up to data version and some functionalities not compatible with the CRAN, you can use the package through GitHub using devtool
(see to CRAN or not to CRAN? for more details):
-## Checking if devtools is already installed
-if(!require(devtools)) install.packages("devtools")
-
-## Installing the latest released version directly from GitHub
-install_github("TGuillerme/dispRity", ref = "release")
+## Checking if devtools is already installed
+if(!require(devtools)) install.packages("devtools")
+
+## Installing the latest released version directly from GitHub
+install_github("TGuillerme/dispRity", ref = "release")
Note this uses the release
branch (1.7).
For the piping-hot (but potentially unstable) version, you can change the argument ref = release
to ref = master
.
dispRity
depends mainly on the ape
package and uses functions from several other packages (ade4
, geometry
, grDevices
, hypervolume
, paleotree
, snow
, Claddis
, geomorph
and RCurl
).
@@ -426,8 +459,8 @@ 1.4 dispRity
is alwa
> mean(c(1,2,3))
[1] 2
Or, more formally:
-::expect_equal(object = mean(c(1,2,3)),
- testthatexpected = 2)
+
You can always access what is actually tested in the test/testthat
sub-folder.
For example here is how the core function dispRity
is tested (through > 500 tests!).
All these tests are run every time a change is made to the package and you can always see for yourself how much a single function is covered (i.e. what percentage of the function is actually covered by at least one test).
diff --git a/inst/gitbook/_book/libs/CanvasMatrix4-1.2.1/CanvasMatrix.src.js b/inst/gitbook/_book/libs/CanvasMatrix4-1.3.12/CanvasMatrix.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/CanvasMatrix4-1.2.1/CanvasMatrix.src.js
rename to inst/gitbook/_book/libs/CanvasMatrix4-1.3.12/CanvasMatrix.src.js
diff --git a/inst/gitbook/_book/libs/accessible-code-block-0.0.1/empty-anchor.js b/inst/gitbook/_book/libs/accessible-code-block-0.0.1/empty-anchor.js
deleted file mode 100644
index ca349fd6..00000000
--- a/inst/gitbook/_book/libs/accessible-code-block-0.0.1/empty-anchor.js
+++ /dev/null
@@ -1,15 +0,0 @@
-// Hide empty tag within highlighted CodeBlock for screen reader accessibility (see https://github.com/jgm/pandoc/issues/6352#issuecomment-626106786) -->
-// v0.0.1
-// Written by JooYoung Seo (jooyoung@psu.edu) and Atsushi Yasumoto on June 1st, 2020.
-
-document.addEventListener('DOMContentLoaded', function() {
- const codeList = document.getElementsByClassName("sourceCode");
- for (var i = 0; i < codeList.length; i++) {
- var linkList = codeList[i].getElementsByTagName('a');
- for (var j = 0; j < linkList.length; j++) {
- if (linkList[j].innerHTML === "") {
- linkList[j].setAttribute('aria-hidden', 'true');
- }
- }
- }
-});
diff --git a/inst/gitbook/_book/libs/htmlwidgets-1.6.2/htmlwidgets.js b/inst/gitbook/_book/libs/htmlwidgets-1.6.4/htmlwidgets.js
similarity index 100%
rename from inst/gitbook/_book/libs/htmlwidgets-1.6.2/htmlwidgets.js
rename to inst/gitbook/_book/libs/htmlwidgets-1.6.4/htmlwidgets.js
diff --git a/inst/gitbook/_book/libs/rglWebGL-binding-1.2.1/rglWebGL.js b/inst/gitbook/_book/libs/rglWebGL-binding-1.3.12/rglWebGL.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglWebGL-binding-1.2.1/rglWebGL.js
rename to inst/gitbook/_book/libs/rglWebGL-binding-1.3.12/rglWebGL.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/animation.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/animation.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/animation.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/animation.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/axes.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/axes.src.js
similarity index 99%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/axes.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/axes.src.js
index 485fa13c..8fc17e89 100644
--- a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/axes.src.js
+++ b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/axes.src.js
@@ -123,8 +123,8 @@
result[dim].push(i*delta/range);
break;
case "pretty":
- locations = this.R_pretty(limits[0], limits[1], 5,
- 2, // min_n
+ locations = this.R_pretty(limits[0], limits[1], obj.axes.nticks[dim],
+ 3, // min_n
0.75, // shrink_sml
[1.5, 2.75], // high_u_fact
0, // eps_correction
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/buffer.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/buffer.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/buffer.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/buffer.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/controls.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/controls.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/controls.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/controls.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/draw.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/draw.src.js
similarity index 99%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/draw.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/draw.src.js
index 90ce52e4..11b098a3 100644
--- a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/draw.src.js
+++ b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/draw.src.js
@@ -954,9 +954,12 @@
this.setnormMatrix2();
this.setprmvMatrix();
- for (i=0; i < obj.objects.length; i++)
+ j = iOrig % obj.shapefirst.length;
+ var first = obj.shapefirst[j];
+
+ for (i=0; i < obj.shapelens[j]; i++)
if (this.opaquePass)
- result = result.concat(this.drawObjId(obj.objects[i], subscene.id, context.concat(j)));
+ result = result.concat(this.drawObjId(obj.objects[first + i], subscene.id, context.concat(j)));
else
this.drawObjId(obj.objects[i], subscene.id, context);
}
@@ -1164,14 +1167,17 @@
savepr = this.prMatrix;
saveinvpr = this.invPrMatrix;
savemv = this.mvMatrix;
+ savenorm = this.normMatrix;
this.prMatrix = new CanvasMatrix4();
this.invPrMatrix = new CanvasMatrix4();
this.mvMatrix = new CanvasMatrix4();
+ this.normMatrix = new CanvasMatrix4();
for (i=0; i < obj.quad.length; i++)
result = result.concat(this.drawObjId(obj.quad[i], subsceneid));
this.prMatrix = savepr;
this.invPrMatrix = saveinvpr;
this.mvMatrix = savemv;
+ this.normMatrix = savenorm;
} else if (obj.sphere) {
subscene = this.getObj(subsceneid);
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/init.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/init.src.js
similarity index 98%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/init.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/init.src.js
index 4266ca5a..3e4c4487 100644
--- a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/init.src.js
+++ b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/init.src.js
@@ -639,7 +639,8 @@
var stride = 3, nc, cofs, nofs, radofs, oofs, tofs, vnew, fnew,
nextofs = -1, pointofs = -1, alias, colors, key, selection,
- filter, adj, offset, attr, last, options;
+ filter, adj, offset, attr, last, options,
+ len, current;
obj.alias = undefined;
@@ -856,12 +857,31 @@
obj.objects = rglwidgetClass.flatten([].concat(obj.ids));
fl.is_lit = false;
obj.adj = rglwidgetClass.flatten(obj.adj);
+
if (typeof obj.pos !== "undefined") {
obj.pos = rglwidgetClass.flatten(obj.pos);
obj.offset = obj.adj[0];
} else
obj.offset = 0;
+ var shapenum = rglwidgetClass.flatten(obj.shapenum);
+ obj.shapelens = [];
+ obj.shapefirst = [];
+ obj.shapefirst.push(0);
+ len = 0;
+ current = 0;
+ for (i = 0; i < shapenum.length; i++) {
+ if (shapenum[i] === shapenum[current]) {
+ len++;
+ } else {
+ obj.shapelens.push(len);
+ len = 1;
+ current = i;
+ obj.shapefirst.push(i);
+ }
+ }
+ obj.shapelens.push(len);
+
for (i=0; i < obj.objects.length; i++)
this.initObjId(obj.objects[i]);
}
@@ -1223,10 +1243,12 @@
newcanvas.setAttribute("aria-labelledby",
labelid);
- if (typeof this.scene.altText !== "undefined")
+ if (typeof this.scene.altText !== "undefined") {
// We're in Shiny, so alter the label
- document.getElementById(labelid).innerHTML = this.scene.altText;
-
+ var label = document.getElementById(labelid);
+ if (label)
+ label.innerHTML = this.scene.altText;
+ }
newcanvas.addEventListener("webglcontextrestored",
this.onContextRestored, false);
newcanvas.addEventListener("webglcontextlost",
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/mouse.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/mouse.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/mouse.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/mouse.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/pieces.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/pieces.src.js
similarity index 71%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/pieces.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/pieces.src.js
index 2ac8c91d..c6a57245 100644
--- a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/pieces.src.js
+++ b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/pieces.src.js
@@ -20,7 +20,8 @@
var n = obj.centers.length,
depth,
result = new Array(n),
- z, w, i;
+ z, w, i,
+ meandepth = 0;
context = context.slice();
for(i=0; i 0) {
- diff = c1.pop() - c2.pop();
- }
- if (diff === 0)
- diff = j.objid - i.objid;
- if (diff === 0)
- diff = j.subid - i.subid;
+ var fastTransparency = this.scene.fastTransparency,
+ compare = function(i,j) {
+ var c1, c2,
+ diff = fastTransparency ? j.meandepth - i.meandepth : j.depth - i.depth;
+
+ // Check for different object depths
+ if (diff !== 0.0)
+ return diff;
+
+ // At this point we are either on the same object or
+ // two different objects that are at the same mean
+ // depth. Context changes are expensive so arbitrarily
+ // split the two objects.
+
+ // Check for different objects
+ diff = j.objid - i.objid;
+ if (diff !== 0)
+ return diff;
+
+ // Check for different nested objects
+ c1 = j.context.slice();
+ c2 = i.context.slice();
+ diff = c1.length - c2.length;
+ while (diff === 0 && c1.length > 0) {
+ diff = c1.pop() - c2.pop();
}
+ if (diff !== 0)
+ return diff;
+
+ // Both pieces are in the same object, so
+ // check for different piece depths
+ // If fastTransparency is not set, this is redundant,
+ // but a test would probably be slower.
+
+ diff = j.depth - i.depth;
+
return diff;
+
}, result = [];
if (pieces.length)
result = pieces.sort(compare);
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/pretty.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/pretty.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/pretty.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/pretty.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/projection.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/projection.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/projection.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/projection.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/rgl.css b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/rgl.css
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/rgl.css
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/rgl.css
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/rglClass.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/rglClass.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/rglClass.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/rglClass.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/rglTimer.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/rglTimer.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/rglTimer.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/rglTimer.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/selection.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/selection.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/selection.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/selection.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/shaders.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/shaders.src.js
similarity index 100%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/shaders.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/shaders.src.js
diff --git a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/shadersrc.src.js b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/shadersrc.src.js
similarity index 95%
rename from inst/gitbook/_book/libs/rglwidgetClass-1.2.1/shadersrc.src.js
rename to inst/gitbook/_book/libs/rglwidgetClass-1.3.12/shadersrc.src.js
index 5dc11e94..ccf93d4b 100644
--- a/inst/gitbook/_book/libs/rglwidgetClass-1.2.1/shadersrc.src.js
+++ b/inst/gitbook/_book/libs/rglwidgetClass-1.3.12/shadersrc.src.js
@@ -102,7 +102,7 @@ return "#line 2 1\n"+
"#endif // IS_TWOSIDED\n"+
" \n"+
"#ifdef NEEDS_VNORMAL\n"+
-" vNormal = vec4(normalize(vNormal.xyz/vNormal.w), 1);\n"+
+" vNormal = vec4(normalize(vNormal.xyz), 1);\n"+
"#endif\n"+
" \n"+
"#if defined(HAS_TEXTURE) || defined(IS_TEXT)\n"+
@@ -259,11 +259,19 @@ return "#line 2 2\n"+
"#endif\n"+
" \n"+
"#if NLIGHTS > 0\n"+
+" // Simulate two-sided lighting\n"+
+" if (n.z < 0.0)\n"+
+" n = -n;\n"+
" for (int i=0;i
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
-
- 7 The guts of the
dispRity
package
@@ -293,7 +326,7 @@
@@ -370,26 +403,26 @@ 5.1 Simulating discrete morpholog
In brief, the function sim.morpho
takes a phylogenetic tree, the number of required characters, the evolutionary model, and a function from which to draw the rates.
The package also contains a function for quickly checking the matrix’s phylogenetic signal (as defined in systematics not phylogenetic comparative methods) using parsimony.
The methods are described in details below
-set.seed(3)
-## Simulating a starting tree with 15 taxa as a random coalescent tree
- rcoal(15)
- my_tree <-
-## Generating a matrix with 100 characters (85% binary and 15% three state) and
-## an equal rates model with a gamma rate distribution (0.5, 1) with no
-## invariant characters.
- sim.morpho(tree = my_tree, characters = 100, states = c(0.85,
- my_matrix <-0.15), rates = c(rgamma, 0.5, 1), invariant = FALSE)
-
-## The first few lines of the matrix
-1:5, 1:10] my_matrix[
+set.seed(3)
+## Simulating a starting tree with 15 taxa as a random coalescent tree
+my_tree <- rcoal(15)
+
+## Generating a matrix with 100 characters (85% binary and 15% three state) and
+## an equal rates model with a gamma rate distribution (0.5, 1) with no
+## invariant characters.
+my_matrix <- sim.morpho(tree = my_tree, characters = 100, states = c(0.85,
+ 0.15), rates = c(rgamma, 0.5, 1), invariant = FALSE)
+
+## The first few lines of the matrix
+my_matrix[1:5, 1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## t10 "1" "0" "1" "0" "1" "0" "0" "1" "0" "0"
## t1 "0" "0" "1" "0" "0" "0" "0" "1" "0" "0"
## t9 "0" "0" "1" "0" "0" "0" "0" "1" "0" "0"
## t14 "1" "0" "1" "0" "0" "0" "0" "1" "0" "0"
## t13 "1" "0" "1" "0" "0" "0" "0" "1" "0" "0"
-## Checking the matrix properties with a quick Maximum Parsimony tree search
-check.morpho(my_matrix, my_tree)
+## Checking the matrix properties with a quick Maximum Parsimony tree search
+check.morpho(my_matrix, my_tree)
##
## Maximum parsimony 144.0000000
## Consistency index 0.7430556
@@ -399,10 +432,10 @@ 5.1 Simulating discrete morpholog
Nearly too good to be true…
5.1.1 A more detailed description
-The protocol implemented here to generate discrete morphological matrices is based on the ones developed in (Guillerme and Cooper 2016; O’Reilly et al. 2016; Puttick et al. 2017; E. et al., n.d.).
+The protocol implemented here to generate discrete morphological matrices is based on the ones developed in (Thomas Guillerme and Cooper 2016; O’Reilly et al. 2016; Puttick et al. 2017; E. et al., n.d.).
- The first
tree
argument will be the tree on which to “evolve” the characters and therefore requires branch length.
-You can generate quick and easy random Yule trees using ape::rtree(number_of_taxa)
but I would advise to use more realistic trees for more realistic simulations based on more realistic models (really realistic then) using the function tree.bd
from the diversitree
package (FitzJohn 2012).
+You can generate quick and easy random Yule trees using ape::rtree(number_of_taxa)
but I would advise to use more realistic trees for more realistic simulations based on more realistic models (really realistic then) using the function tree.bd
from the diversitree
package (FitzJohn 2012).
- The second argument,
character
is the number of characters. Pretty straight forward.
- The third,
states
is the proportion of characters states above two (yes, the minimum number of states is two). This argument intakes the proportion of n-states characters, for example states = c(0.5,0.3,0.2)
will generate 50% of binary-state characters, 30% of three-state characters and 20% of four-state characters. There is no limit in the number of state characters proportion as long as the total makes up 100%.
- The forth,
model
is the evolutionary model for generating the character(s). More about this below.
@@ -414,8 +447,8 @@ 5.1.1.1 Available evolutionary mo
There are currently three evolutionary models implemented in sim.morpho
but more will come in the future.
Note also that they allow fine tuning parameters making them pretty plastic!
-"ER"
: this model allows any number of character states and is based on the Mk model (Lewis 2001). It assumes a unique overall evolutionary rate equal substitution rate between character states. This model is based on the ape::rTraitDisc
function.
-"HKY"
: this is binary state character model based on the molecular HKY model (Hasegawa, Kishino, and Yano 1985). It uses the four molecular states (A,C,G,T) with a unique overall evolutionary rate and a biased substitution rate towards transitions (A <-> G or C <-> T) against transvertions (A <-> C and G <-> T). After evolving the nucleotide, this model transforms them into binary states by converting the purines (A and G) into state 0 and the pyrimidines (C and T) into state 1. This method is based on the phyclust::seq.gen.HKY
function and was first proposed by O’Reilly et al. (2016).
+"ER"
: this model allows any number of character states and is based on the Mk model (Lewis 2001). It assumes a unique overall evolutionary rate equal substitution rate between character states. This model is based on the ape::rTraitDisc
function.
+"HKY"
: this is binary state character model based on the molecular HKY model (Hasegawa, Kishino, and Yano 1985). It uses the four molecular states (A,C,G,T) with a unique overall evolutionary rate and a biased substitution rate towards transitions (A <-> G or C <-> T) against transvertions (A <-> C and G <-> T). After evolving the nucleotide, this model transforms them into binary states by converting the purines (A and G) into state 0 and the pyrimidines (C and T) into state 1. This method is based on the phyclust::seq.gen.HKY
function and was first proposed by O’Reilly et al. (2016).
"MIXED"
: this model uses a random (uniform) mix between both the "ER"
and the "HKY"
models.
The models can take the following parameters:
@@ -435,7 +468,7 @@
5.1.1.2 Checking the results5.1.1.3 Adding inapplicable characters
Once a matrix is generated, it is possible to apply inapplicable characters to it for increasing realism!
Inapplicable characters are commonly designated as NA
or simply -
.
-They differ from missing characters ?
in their nature by being inapplicable rather than unknown(see Brazeau, Guillerme, and Smith 2018 for more details).
+They differ from missing characters ?
in their nature by being inapplicable rather than unknown(see Brazeau, Guillerme, and Smith 2018 for more details).
For example, considering a binary character defined as “colour of the tail” with the following states “blue” and “red”; on a taxa with no tail, the character should be coded as inapplicable (“-
”) since the state of the character “colour of tail” is known: it’s neither “blue” or “red”, it’s just not there!
It contrasts with coding it as missing (“?
” - also called as ambiguous) where the state is unknown, for example, the taxon of interest is a fossil where the tail has no colour preserved or is not present at all due to bad conservation!
This type of characters can be added to the simulated matrices using the apply.NA
function/
@@ -450,13 +483,13 @@
5.1.1.3 Adding inapplicable chara
This simulates the inapplicability induced by evolutionary biology (e.g. the lose of a feature in a clade).
To apply these sources of inapplicability, simply repeat the number of inapplicable sources for the desired number of characters with inapplicable data.
-## Generating 5 "character" NAs and 10 "clade" NAs
- apply.NA(my_matrix, tree = my_tree,
- my_matrix_NA <-NAs = c(rep("character", 5),
- rep("clade", 10)))
-
-## The first few lines of the resulting matrix
-1:10, 90:100] my_matrix_NA[
+## Generating 5 "character" NAs and 10 "clade" NAs
+my_matrix_NA <- apply.NA(my_matrix, tree = my_tree,
+ NAs = c(rep("character", 5),
+ rep("clade", 10)))
+
+## The first few lines of the resulting matrix
+my_matrix_NA[1:10, 90:100]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
## t10 "-" "1" "1" "2" "1" "0" "0" "0" "1" "0" "0"
## t1 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0"
@@ -474,16 +507,16 @@ 5.1.1.3 Adding inapplicable chara
5.1.2 Parameters for a realistic(ish) matrix
There are many parameters that can create a “realistic” matrix (i.e. not too different from the input tree with a consistency and retention index close to what is seen in the literature) but because of the randomness of the matrix generation not all parameters combination end up creating “good” matrices.
The following parameters however, seem to generate fairly “realist” matrices with a starting coalescent tree, equal rates model with 0.85 binary characters and 0.15 three state characters, a gamma distribution with a shape parameter (\(\alpha\)) of 5 and no scaling (\(\beta\) = 1) with a rate of 100.
-set.seed(0)
-## tree
- rcoal(15)
- my_tree <-## matrix
- sim.morpho(my_tree,
- morpho_mat <-characters = 100,
- model = "ER",
- rates = c(rgamma, rate = 100, shape = 5),
- invariant = FALSE)
- check.morpho(morpho_mat, my_tree)
+set.seed(0)
+## tree
+my_tree <- rcoal(15)
+## matrix
+morpho_mat <- sim.morpho(my_tree,
+ characters = 100,
+ model = "ER",
+ rates = c(rgamma, rate = 100, shape = 5),
+ invariant = FALSE)
+check.morpho(morpho_mat, my_tree)
##
## Maximum parsimony 103.0000000
## Consistency index 0.9708738
@@ -498,7 +531,7 @@ 5.2 Simulating multidimensional s
Another way to simulate data is to directly simulate an ordinated space with the space.maker
function.
This function allows users to simulate multidimensional spaces with a certain number of properties.
For example, it is possible to design a multidimensional space with a specific distribution on each axis, a correlation between the axes and a specific cumulative variance per axis.
-This can be useful for creating ordinated spaces for null hypothesis, for example if you’re using the function null.test
(Dı́az et al. 2016).
+This can be useful for creating ordinated spaces for null hypothesis, for example if you’re using the function null.test
(Dı́az et al. 2016).
This function takes as arguments the number of elements (data points - elements
argument) and dimensions (dimensions
argument) to create the space and the distribution functions to be used for each axis.
The distributions are passed through the distribution
argument as… modular functions!
You can either pass a single distribution function for all the axes (for example distribution = runif
for all the axis being uniform) or a specific distribution function for each specific axis (for example distribution = c(runif, rnorm, rgamma))
for the first axis being uniform, the second normal and the third gamma).
@@ -506,14 +539,14 @@
5.2 Simulating multidimensional s
Specific optional arguments for each of these distributions can be passed as a list via the arguments
argument.
Furthermore, it is possible to add a correlation matrix to add a correlation between the axis via the cor.matrix
argument or even a vector of proportion of variance to be bear by each axis via the scree
argument to simulate realistic ordinated spaces.
Here is a simple two dimensional example:
-## Graphical options
- par(bty = "n")
- op <-
-## A square space
- space.maker(100, 2, runif)
- square_space <-
-## The resulting 2D matrix
-head(square_space)
+## Graphical options
+op <- par(bty = "n")
+
+## A square space
+square_space <- space.maker(100, 2, runif)
+
+## The resulting 2D matrix
+head(square_space)
## [,1] [,2]
## [1,] 0.2878797 0.82110157
## [2,] 0.5989886 0.72890558
@@ -521,29 +554,29 @@ 5.2 Simulating multidimensional s
## [4,] 0.3663870 0.75545936
## [5,] 0.2122375 0.98768804
## [6,] 0.9612441 0.07285561
-## Visualising the space
-plot(square_space, pch = 20, xlab = "", ylab = "",
-main = "Uniform 2D space")
-
+## Visualising the space
+plot(square_space, pch = 20, xlab = "", ylab = "",
+ main = "Uniform 2D space")
+
Of course, more complex spaces can be created by changing the distributions, their arguments or adding a correlation matrix or a cumulative variance vector:
-## A plane space: uniform with one dimensions equal to 0
- space.maker(2500, 3, c(runif, runif, runif),
- plane_space <-arguments = list(list(min = 0, max = 0),
- NULL, NULL))
-
-## Correlation matrix for a 3D space
- matrix(cbind(1, 0.8, 0.2, 0.8, 1, 0.7, 0.2, 0.7, 1), nrow = 3)) (cor_matrix <-
+## A plane space: uniform with one dimensions equal to 0
+plane_space <- space.maker(2500, 3, c(runif, runif, runif),
+ arguments = list(list(min = 0, max = 0),
+ NULL, NULL))
+
+## Correlation matrix for a 3D space
+(cor_matrix <- matrix(cbind(1, 0.8, 0.2, 0.8, 1, 0.7, 0.2, 0.7, 1), nrow = 3))
## [,1] [,2] [,3]
## [1,] 1.0 0.8 0.2
## [2,] 0.8 1.0 0.7
## [3,] 0.2 0.7 1.0
-## An ellipsoid space (normal space with correlation)
- space.maker(2500, 3, rnorm,
- ellipse_space <-cor.matrix = cor_matrix)
-
-## A cylindrical space with decreasing axes variance
- space.maker(2500, 3, c(rnorm, rnorm, runif),
- cylindrical_space <-scree = c(0.7, 0.2, 0.1))
+## An ellipsoid space (normal space with correlation)
+ellipse_space <- space.maker(2500, 3, rnorm,
+ cor.matrix = cor_matrix)
+
+## A cylindrical space with decreasing axes variance
+cylindrical_space <- space.maker(2500, 3, c(rnorm, rnorm, runif),
+ scree = c(0.7, 0.2, 0.1))
5.2.1 Personalised dimensions distributions
Following the modular architecture of the package, it is of course possible to pass home made distribution functions to the distribution
argument.
@@ -551,148 +584,148 @@
5.2.1 Personalised dimensions dis
This function allows to create circles based on basic trigonometry allowing to axis to covary to produce circle coordinates.
By default, this function generates two sets of coordinates with a distribution
argument and a minimum and maximum boundary (inner
and outer
respectively) to create nice sharp edges to the circle.
The maximum boundary is equivalent to the radius of the circle (it removes coordinates beyond the circle radius) and the minimum is equivalent to the radius of a smaller circle with no data (it removes coordinates below this inner circle radius).
-## Graphical options
- par(bty = "n")
- op <-
-## Generating coordinates for a normal circle with a upper boundary of 1
- random.circle(1000, rnorm, inner = 0, outer = 1)
- circle <-
-## Plotting the circle
-plot(circle, xlab = "x", ylab = "y", main = "A normal circle")
-
-## Creating doughnut space (a spherical space with a hole)
- space.maker(5000, 3, c(rnorm, random.circle),
- doughnut_space <-arguments = list(list(mean = 0),
- list(runif, inner = 0.5, outer = 1)))
+
+
+
5.2.2 Visualising the space
I suggest using the excellent scatterplot3d
package to play around and visualise the simulated spaces:
-## Graphical options
- par(mfrow = (c(2, 2)), bty = "n")
- op <-## Visualising 3D spaces
-require(scatterplot3d)
+## Graphical options
+op <- par(mfrow = (c(2, 2)), bty = "n")
+## Visualising 3D spaces
+require(scatterplot3d)
## Loading required package: scatterplot3d
-## The plane space
-scatterplot3d(plane_space, pch = 20, xlab = "", ylab = "", zlab = "",
-xlim = c(-0.5, 0.5), main = "Plane space")
-
-## The ellipsoid space
-scatterplot3d(ellipse_space, pch = 20, xlab = "", ylab = "", zlab = "",
-main = "Normal ellipsoid space")
-
-## A cylindrical space with a decreasing variance per axis
-scatterplot3d(cylindrical_space, pch = 20, xlab = "", ylab = "", zlab = "",
-main = "Normal cylindrical space")
- ## Axes have different orders of magnitude
-
-## Plotting the doughnut space
-scatterplot3d(doughnut_space[,c(2,1,3)], pch = 20, xlab = "", ylab = "",
-zlab = "", main = "Doughnut space")
-
-par(op)
+## The plane space
+scatterplot3d(plane_space, pch = 20, xlab = "", ylab = "", zlab = "",
+ xlim = c(-0.5, 0.5), main = "Plane space")
+
+## The ellipsoid space
+scatterplot3d(ellipse_space, pch = 20, xlab = "", ylab = "", zlab = "",
+ main = "Normal ellipsoid space")
+
+## A cylindrical space with a decreasing variance per axis
+scatterplot3d(cylindrical_space, pch = 20, xlab = "", ylab = "", zlab = "",
+ main = "Normal cylindrical space")
+## Axes have different orders of magnitude
+
+## Plotting the doughnut space
+scatterplot3d(doughnut_space[,c(2,1,3)], pch = 20, xlab = "", ylab = "",
+ zlab = "", main = "Doughnut space")
+
+
5.2.3 Generating realistic spaces
It is possible to generate “realistic” spaces by simply extracting the parameters of an existing space and scaling it up to the simulated space.
For example, we can extract the parameters of the BeckLee_mat50
ordinated space and simulate a similar space.
-## Loading the data
-data(BeckLee_mat50)
-
-## Number of dimensions
- ncol(BeckLee_mat50)
- obs_dim <-
-## Observed correlation between the dimensions
- cor(BeckLee_mat50)
- obs_correlations <-
-## Observed mean and standard deviation per axis
- mapply(function(x,y) list("mean" = x, "sd" = y),
- obs_mu_sd_axis <-as.list(apply(BeckLee_mat50, 2, mean)),
- as.list(apply(BeckLee_mat50, 2, sd)), SIMPLIFY = FALSE)
-
-## Observed overall mean and standard deviation
- list("mean" = mean(BeckLee_mat50), "sd" = sd(BeckLee_mat50))
- obs_mu_sd_glob <-
-## Scaled observed variance per axis (scree plot)
- variances(BeckLee_mat50)/sum(variances(BeckLee_mat50))
- obs_scree <-
-## Generating our simulated space
- space.maker(1000, dimensions = obs_dim,
- simulated_space <-distribution = rep(list(rnorm), obs_dim),
- arguments = obs_mu_sd_axis,
- cor.matrix = obs_correlations)
-
-## Visualising the fit of our data in the space (in the two first dimensions)
-plot(simulated_space[,1:2], xlab = "PC1", ylab = "PC2")
-points(BeckLee_mat50[,1:2], col = "red", pch = 20)
-legend("topleft", legend = c("observed", "simulated"),
-pch = c(20,21), col = c("red", "black"))
-
+## Loading the data
+data(BeckLee_mat50)
+
+## Number of dimensions
+obs_dim <- ncol(BeckLee_mat50)
+
+## Observed correlation between the dimensions
+obs_correlations <- cor(BeckLee_mat50)
+
+## Observed mean and standard deviation per axis
+obs_mu_sd_axis <- mapply(function(x,y) list("mean" = x, "sd" = y),
+ as.list(apply(BeckLee_mat50, 2, mean)),
+ as.list(apply(BeckLee_mat50, 2, sd)), SIMPLIFY = FALSE)
+
+## Observed overall mean and standard deviation
+obs_mu_sd_glob <- list("mean" = mean(BeckLee_mat50), "sd" = sd(BeckLee_mat50))
+
+## Scaled observed variance per axis (scree plot)
+obs_scree <- variances(BeckLee_mat50)/sum(variances(BeckLee_mat50))
+
+## Generating our simulated space
+simulated_space <- space.maker(1000, dimensions = obs_dim,
+ distribution = rep(list(rnorm), obs_dim),
+ arguments = obs_mu_sd_axis,
+ cor.matrix = obs_correlations)
+
+## Visualising the fit of our data in the space (in the two first dimensions)
+plot(simulated_space[,1:2], xlab = "PC1", ylab = "PC2")
+points(BeckLee_mat50[,1:2], col = "red", pch = 20)
+legend("topleft", legend = c("observed", "simulated"),
+ pch = c(20,21), col = c("red", "black"))
+
It is now possible to simulate a space using these observed arguments to test several hypothesis:
- Is the space uniform or normal?
- If the space is normal, is the mean and variance global or specific for each axis?
-## Measuring disparity as the sum of variance
- dispRity(BeckLee_mat50, metric = c(median, centroids))
- observed_disp <-
-## Is the space uniform?
- null.test(observed_disp, null.distrib = runif)
- test_unif <-
-## Is the space normal with a mean of 0 and a sd of 1?
- null.test(observed_disp, null.distrib = rnorm)
- test_norm1 <-
-## Is the space normal with the observed mean and sd and cumulative variance
- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim),
- test_norm2 <-null.args = rep(list(obs_mu_sd_glob), obs_dim),
- null.scree = obs_scree)
-
-## Is the space multiple normal with multiple means and sds and a correlation?
- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim),
- test_norm3 <-null.args = obs_mu_sd_axis, null.cor = obs_correlations)
-
-## Graphical options
- par(mfrow = (c(2, 2)), bty = "n")
- op <-## Plotting the results
-plot(test_unif, main = "Uniform (0,1)")
-plot(test_norm1, main = "Normal (0,1)")
-plot(test_norm2, main = paste0("Normal (", round(obs_mu_sd_glob[[1]], digit = 3),
-",", round(obs_mu_sd_glob[[2]], digit = 3), ")"))
- plot(test_norm3, main = "Normal (variable + correlation)")
-
+## Measuring disparity as the sum of variance
+observed_disp <- dispRity(BeckLee_mat50, metric = c(median, centroids))
+
+## Is the space uniform?
+test_unif <- null.test(observed_disp, null.distrib = runif)
+
+## Is the space normal with a mean of 0 and a sd of 1?
+test_norm1 <- null.test(observed_disp, null.distrib = rnorm)
+
+## Is the space normal with the observed mean and sd and cumulative variance
+test_norm2 <- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim),
+ null.args = rep(list(obs_mu_sd_glob), obs_dim),
+ null.scree = obs_scree)
+
+## Is the space multiple normal with multiple means and sds and a correlation?
+test_norm3 <- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim),
+ null.args = obs_mu_sd_axis, null.cor = obs_correlations)
+
+## Graphical options
+op <- par(mfrow = (c(2, 2)), bty = "n")
+## Plotting the results
+plot(test_unif, main = "Uniform (0,1)")
+plot(test_norm1, main = "Normal (0,1)")
+plot(test_norm2, main = paste0("Normal (", round(obs_mu_sd_glob[[1]], digit = 3),
+ ",", round(obs_mu_sd_glob[[2]], digit = 3), ")"))
+plot(test_norm3, main = "Normal (variable + correlation)")
+
If we measure disparity as the median distance from the morphospace centroid, we can explain the distribution of the data as normal with the variable observed mean and standard deviation and with a correlation between the dimensions.
References
-
-
-Brazeau, Martin D, Thomas Guillerme, and Martin R Smith. 2018. “An algorithm for Morphological Phylogenetic Analysis with Inapplicable Data.” Systematic Biology 68 (4): 619–31. https://doi.org/10.1093/sysbio/syy083.
+
+
+Brazeau, Martin D, Thomas Guillerme, and Martin R Smith. 2018. “An algorithm for Morphological Phylogenetic Analysis with Inapplicable Data.” Systematic Biology 68 (4): 619–31. https://doi.org/10.1093/sysbio/syy083.
-
-Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
+
+Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
-
-E., O’Reilly Joseph, Puttick Mark N., Pisani Davide, and Donoghue Philip C. J. n.d. “Probabilistic Methods Surpass Parsimony When Assessing Clade Support in Phylogenetic Analyses of Discrete Morphological Data.” Palaeontology 61 (1): 105–18. https://doi.org/10.1111/pala.12330.
+
+E., O’Reilly Joseph, Puttick Mark N., Pisani Davide, and Donoghue Philip C. J. n.d. “Probabilistic Methods Surpass Parsimony When Assessing Clade Support in Phylogenetic Analyses of Discrete Morphological Data.” Palaeontology 61 (1): 105–18. https://doi.org/10.1111/pala.12330.
-
-FitzJohn, Richard G. 2012. “Diversitree: Comparative Phylogenetic Analyses of Diversification in R.” Methods in Ecology and Evolution 3 (6): 1084–92. https://doi.org/10.1111/j.2041-210X.2012.00234.x.
+
+FitzJohn, Richard G. 2012. “Diversitree: Comparative Phylogenetic Analyses of Diversification in R.” Methods in Ecology and Evolution 3 (6): 1084–92. https://doi.org/10.1111/j.2041-210X.2012.00234.x.
-
-Guillerme, Thomas, and Natalie Cooper. 2016. “Effects of Missing Data on Topological Inference Using a Total Evidence Approach.” Molecular Phylogenetics and Evolution 94, Part A: 146–58. https://doi.org/http://dx.doi.org/10.1016/j.ympev.2015.08.023.
+
+Guillerme, Thomas, and Natalie Cooper. 2016. “Effects of Missing Data on Topological Inference Using a Total Evidence Approach.” Molecular Phylogenetics and Evolution 94, Part A: 146–58. https://doi.org/http://dx.doi.org/10.1016/j.ympev.2015.08.023.
-
-Hasegawa, M., H. Kishino, and T. A. Yano. 1985. “Dating of the Human Ape Splitting by a Molecular Clock of Mitochondrial-DNA.” Journal of Molecular Evolution 22 (2): 160–74.
+
+Hasegawa, M., H. Kishino, and T. A. Yano. 1985. “Dating of the Human Ape Splitting by a Molecular Clock of Mitochondrial-DNA.” Journal of Molecular Evolution 22 (2): 160–74.
-
-Lewis, P. 2001. “A Likelihood Approach to Estimating Phylogeny from Discrete Morphological Character Data.” Systematic Biology 50 (6): 913–25. https://doi.org/10.1080/106351501753462876.
+
+Lewis, P. 2001. “A Likelihood Approach to Estimating Phylogeny from Discrete Morphological Character Data.” Systematic Biology 50 (6): 913–25. https://doi.org/10.1080/106351501753462876.
-
-O’Reilly, Joseph E., Mark N. Puttick, Luke Parry, Alastair R. Tanner, James E. Tarver, James Fleming, Davide Pisani, and Philip C. J. Donoghue. 2016. “Bayesian Methods Outperform Parsimony but at the Expense of Precision in the Estimation of Phylogeny from Discrete Morphological Data.” Biology Letters 12 (4). https://doi.org/10.1098/rsbl.2016.0081.
+
+O’Reilly, Joseph E., Mark N. Puttick, Luke Parry, Alastair R. Tanner, James E. Tarver, James Fleming, Davide Pisani, and Philip C. J. Donoghue. 2016. “Bayesian Methods Outperform Parsimony but at the Expense of Precision in the Estimation of Phylogeny from Discrete Morphological Data.” Biology Letters 12 (4). https://doi.org/10.1098/rsbl.2016.0081.
-
-Puttick, Mark N, Joseph E O’Reilly, Alastair R Tanner, James F Fleming, James Clark, Lucy Holloway, Jesus Lozano-Fernandez, et al. 2017. “Uncertain-Tree: Discriminating Among Competing Approaches to the Phylogenetic Analysis of Phenotype Data.” Proceedings of the Royal Society B 284 (1846): 20162290. http://dx.doi.org/10.1098/rspb.2016.2290.
+
+Puttick, Mark N, Joseph E O’Reilly, Alastair R Tanner, James F Fleming, James Clark, Lucy Holloway, Jesus Lozano-Fernandez, et al. 2017. “Uncertain-Tree: Discriminating Among Competing Approaches to the Phylogenetic Analysis of Phenotype Data.” Proceedings of the Royal Society B 284 (1846): 20162290. http://dx.doi.org/10.1098/rspb.2016.2290.
diff --git a/inst/gitbook/_book/morphometric-geometric-demo-a-between-group-analysis.html b/inst/gitbook/_book/morphometric-geometric-demo-a-between-group-analysis.html
index 9da0eeee..4b6af402 100644
--- a/inst/gitbook/_book/morphometric-geometric-demo-a-between-group-analysis.html
+++ b/inst/gitbook/_book/morphometric-geometric-demo-a-between-group-analysis.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -366,34 +399,26 @@ 10 Morphometric geometric demo: a
10.1 Before starting
Here we are going to use the geomorph
plethodon
dataset that is a set of 12 2D landmark coordinates for 40 specimens from two species of salamanders.
This section will really quickly cover how to make a Procrustes sumperimposition analysis and create a geomorph
data.frame to have data ready for the dispRity
package.
-## Loading geomorph
-library(geomorph)
-
-## Loading the plethodon dataset
-data(plethodon)
-
-## Running a simple Procrustes superimposition
- gpagen(plethodon$land) gpa_plethodon <-
+## Loading geomorph
+library(geomorph)
+
+## Loading the plethodon dataset
+data(plethodon)
+
+## Running a simple Procrustes superimposition
+gpa_plethodon <- gpagen(plethodon$land)
##
## Performing GPA
-##
- |
- | | 0%
- |
- |================== | 25%
- |
- |=================================== | 50%
- |
- |======================================================================| 100%
+## | | | 0% | |================== | 25% | |=================================== | 50% | |======================================================================| 100%
##
## Making projections... Finished!
-## Making a geomorph data frame object with the species and sites attributes
- geomorph.data.frame(gpa_plethodon,
- gdf_plethodon <-species = plethodon$species,
- site = plethodon$site)
+## Making a geomorph data frame object with the species and sites attributes
+gdf_plethodon <- geomorph.data.frame(gpa_plethodon,
+ species = plethodon$species,
+ site = plethodon$site)
You can of course use your very own landmark coordinates dataset (though you will have to do some modifications in the scripts that will come below - they will be easy though!).
-## You can replace the gdf_plethodon by your own geomorph data frame!
- gdf_plethodon my_geomorph_data <-
+## You can replace the gdf_plethodon by your own geomorph data frame!
+my_geomorph_data <- gdf_plethodon
10.1.1 The morphospace
The first step of every disparity analysis is to define your morphospace.
@@ -404,18 +429,18 @@ 10.1.1 The morphospace## The morphospace
- geomorph.ordination(gdf_plethodon) morphospace <-
+
This automatically generates a dispRity
object with the information of each groups. You can find more information about dispRity
objects here but basically it summarises the content of your object without spamming your R console and is associated with many utility functions like summary
or plot
. For example here you can quickly visualise the two first dimensions of your space using the plot
function:
-## The dispRity object
- morphospace
+
## ---- dispRity object ----
## 4 customised subsets for 40 elements in one matrix:
## species.Jord, species.Teyah, site.Allo, site.Symp.
-## Plotting the morphospace
-plot(morphospace)
-
-## Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap!
+
+
+
The dispRity
package function comes with a lot of documentation of examples so don’t hesitate to type plot.dispRity
to check more plotting options.
@@ -423,101 +448,101 @@ 10.1.1 The morphospace10.2 Calculating disparity
Now that we have our morphospace, we can think about what we want to measure.
Two aspects of disparity that would be interesting for our question (is there a difference in disparity between the different species of salamanders and between the different sites?) would be the differences in size in the morphospace (do both groups occupy the same amount of morphospace) and position in the morphospace (do the do groups occupy the same position in the morphospace?).
-To choose which metric would cover best these two aspects, please check the Thomas Guillerme, Puttick, et al. (2020) paper and associated app. Here we are going to use the procrustes variance (geomorph::morphol.disparity
) for measuring the size of the trait space and the average displacements (Thomas Guillerme, Puttick, et al. 2020) for the position in the trait space.
-## Defining a the procrustes variance metric
-## (as in geomorph::morphol.disparity)
- function(matrix) {sum(matrix^2)/nrow(matrix)} proc.var <-
-## The size metric
- test.metric(morphospace, metric = proc.var,
- test_size <-shifts = c("random", "size"))
- plot(test_size)
-summary(test_size)
-
-## The position metric
- test.metric(morphospace, metric = c(mean, displacements),
- test_position <-shifts = c("random", "position"))
- plot(test_position)
-summary(test_position)
+To choose which metric would cover best these two aspects, please check the Thomas Guillerme, Puttick, et al. (2020) paper and associated app. Here we are going to use the procrustes variance (geomorph::morphol.disparity
) for measuring the size of the trait space and the average displacements (Thomas Guillerme, Puttick, et al. 2020) for the position in the trait space.
+## Defining a the procrustes variance metric
+## (as in geomorph::morphol.disparity)
+proc.var <- function(matrix) {sum(matrix^2)/nrow(matrix)}
+## The size metric
+test_size <- test.metric(morphospace, metric = proc.var,
+ shifts = c("random", "size"))
+plot(test_size)
+summary(test_size)
+
+## The position metric
+test_position <- test.metric(morphospace, metric = c(mean, displacements),
+ shifts = c("random", "position"))
+plot(test_position)
+summary(test_position)
You can see here for more details on the test.metric
function but basically these graphs are showing that there is a relation between changes in size and in position for each metric.
Note that there are some caveats here but the selection of the metric is just for the sake of the example!
Note also the format of defining the disparity metrics here using metric = c(mean, displacements)
or metric = proc.var
. This is a core bit of the dispRity
package were you can define your own metric as a function or a set of functions. You can find more info about this in the dispRity
metric section but in brief, the dispRity
package considers metrics by their “dimensions” level which corresponds to what they output. For example, the function mean
is a dimension level 1 function because no matter the input it outputs a single value (the mean), displacements
on the other hand is a dimension level 2 function because it will output the ratio between the distance from the centroid and from the centre of the trait space for each row in a matrix (an example of a dimensions level 3 would be the function var
that outputs a matrix).
The dispRity
package always automatically sorts the dimensions levels: it will always run dimensions level 3 > dimensions level 2 > and dimensions level 1. In this case both c(mean, displacements)
and c(mean, displacements)
will result in actually running mean(displacements(matrix))
.
Alternatively you can define your metric prior to the disparity analysis like we did for the proc.var
function.
Anyways, we can measure disparity using these two metrics on all the groups as follows:
-## Bootstrapped disparity
- dispRity(boot.matrix(morphospace), metric = proc.var)
- disparity_size <- dispRity(boot.matrix(morphospace), metric = c(mean, displacements)) disparity_position <-
+## Bootstrapped disparity
+disparity_size <- dispRity(boot.matrix(morphospace), metric = proc.var)
+disparity_position <- dispRity(boot.matrix(morphospace), metric = c(mean, displacements))
Note that here we use the boot.matrix
function for quickly bootstrapping the matrix.
This is not an essential step in this kind of analysis but it allows to “reduce” the effect of outliers and create a distribution of disparity measures (rather than single point estimates).
10.3 Analyse the results
We can visualise the results using the plot
function on the resulting disparity objects (or summarising them using summary
):
-## Plotting the results
-par(mfrow = c(1,2))
-plot(disparity_size, main = "group sizes", las = 2, xlab = "")
-plot(disparity_position, main = "group positions", las = 2, xlab = "")
-
-## Summarising the results
-summary(disparity_size)
+## Plotting the results
+par(mfrow = c(1,2))
+plot(disparity_size, main = "group sizes", las = 2, xlab = "")
+plot(disparity_position, main = "group positions", las = 2, xlab = "")
+
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.006
+## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.005
## 2 species.Teyah 20 0.005 0.005 0.004 0.005 0.005 0.006
## 3 site.Allo 20 0.004 0.004 0.003 0.003 0.004 0.004
## 4 site.Symp 20 0.006 0.006 0.006 0.006 0.006 0.007
-summary(disparity_position)
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
-## 1 species.Jord 20 1.096 1.122 1.067 1.101 1.171 1.380
-## 2 species.Teyah 20 1.070 1.105 1.033 1.065 1.143 1.345
-## 3 site.Allo 20 1.377 1.407 1.315 1.381 1.448 1.530
-## 4 site.Symp 20 1.168 1.221 1.148 1.187 1.269 1.458
+## 1 species.Jord 20 1.096 1.122 1.069 1.104 1.168 1.404
+## 2 species.Teyah 20 1.070 1.095 1.029 1.070 1.146 1.320
+## 3 site.Allo 20 1.377 1.415 1.311 1.369 1.464 1.526
+## 4 site.Symp 20 1.168 1.220 1.158 1.190 1.270 1.498
Just from looking at the data, we can guess that there is not much difference in terms of morphospace occupancy and position for the species but there is on for the sites (allopatric or sympatric).
We can test it using a simple non-parametric mean difference test (e.g. wilcox.test
) using the dispRity
package.
-## Testing the differences
-test.dispRity(disparity_size, test = wilcox.test, correction = "bonferroni")
+## Testing the differences
+test.dispRity(disparity_size, test = wilcox.test, correction = "bonferroni")
## [[1]]
## statistic: W
-## species.Jord : species.Teyah 3803
-## species.Jord : site.Allo 9922
-## species.Jord : site.Symp 14
-## species.Teyah : site.Allo 9927
-## species.Teyah : site.Symp 238
+## species.Jord : species.Teyah 3842
+## species.Jord : site.Allo 9919
+## species.Jord : site.Symp 7
+## species.Teyah : site.Allo 9939
+## species.Teyah : site.Symp 155
## site.Allo : site.Symp 0
##
## [[2]]
## p.value
-## species.Jord : species.Teyah 2.076623e-02
-## species.Jord : site.Allo 1.572891e-32
-## species.Jord : site.Symp 2.339811e-33
-## species.Teyah : site.Allo 1.356528e-32
-## species.Teyah : site.Symp 1.657077e-30
+## species.Jord : species.Teyah 2.808435e-02
+## species.Jord : site.Allo 1.718817e-32
+## species.Jord : site.Symp 1.896841e-33
+## species.Teyah : site.Allo 9.504256e-33
+## species.Teyah : site.Symp 1.507734e-31
## site.Allo : site.Symp 1.537286e-33
-test.dispRity(disparity_position, test = wilcox.test, correction = "bonferroni")
+
## [[1]]
## statistic: W
-## species.Jord : species.Teyah 6536
-## species.Jord : site.Allo 204
-## species.Jord : site.Symp 1473
-## species.Teyah : site.Allo 103
-## species.Teyah : site.Symp 1042
-## site.Allo : site.Symp 9288
+## species.Jord : species.Teyah 6639
+## species.Jord : site.Allo 262
+## species.Jord : site.Symp 1386
+## species.Teyah : site.Allo 91
+## species.Teyah : site.Symp 981
+## site.Allo : site.Symp 9373
##
## [[2]]
## p.value
-## species.Jord : species.Teyah 1.053318e-03
-## species.Jord : site.Allo 6.238014e-31
-## species.Jord : site.Symp 4.137900e-17
-## species.Teyah : site.Allo 3.289139e-32
-## species.Teyah : site.Symp 2.433117e-21
-## site.Allo : site.Symp 6.679158e-25
+## species.Jord : species.Teyah 3.744848e-04
+## species.Jord : site.Allo 3.288928e-30
+## species.Jord : site.Symp 6.326430e-18
+## species.Teyah : site.Allo 2.309399e-32
+## species.Teyah : site.Symp 5.609280e-22
+## site.Allo : site.Symp 7.278818e-26
So by applying the tests we see a difference in terms of position between each groups and differences in size between groups but between the species.
References
-
-
-Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
+
+
+Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
diff --git a/inst/gitbook/_book/other-functionalities.html b/inst/gitbook/_book/other-functionalities.html
index 57d9eddd..a10f0ac1 100644
--- a/inst/gitbook/_book/other-functionalities.html
+++ b/inst/gitbook/_book/other-functionalities.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -374,12 +407,12 @@ 6.1 char.diff
0 becomes 1
, 1
becomes 2
, 2
becomes 4
, 3
becomes 8
, etc…
Specifically it can handle any rules specific to special tokens (i.e. symbols) for discrete morphological characters. For example, should you treat missing values "?"
as NA
(ignoring them) or as any possible character state (e.g. c("0", "1")
?)? And how to treat characters with a ampersand ("&"
)? char.diff
can answer to all these questions!
Let’s start by a basic binary matrix 4*3 with random integer
:
-## A random binary matrix
- matrix(sample(c(0,1), 12, replace = TRUE), ncol = 4,
- matrix_binary <-dimnames = list(letters[1:3], LETTERS[1:4]))
+## A random binary matrix
+matrix_binary <- matrix(sample(c(0,1), 12, replace = TRUE), ncol = 4,
+ dimnames = list(letters[1:3], LETTERS[1:4]))
By default, char.diff
measures the hamming distance between characters:
-## The hamming distance between characters
- char.diff(matrix_binary)) (differences <-
+
## A B C D
## A 0 0 1 1
## B 0 0 1 1
@@ -389,13 +422,13 @@ 6.1 char.diff
Note that the results is just a pairwise distance (dissimilarity) matrix with some special dual class matrix
and char.diff
.
This means it can easily be plotted via the disparity package:
-## Visualising the matrix
-plot(differences)
-
+
+
You can check all the numerous plotting options in the ?plot.char.diff
manual (it won’t be developed here).
The char.diff
function has much more options however (see all of them in the ?char.diff
manual) for example to measure different differences (via method
) or making the comparison work per row (for a distance matrix between the rows):
-## Euclidean distance between rows
-char.diff(matrix_binary, by.col = FALSE, method = "euclidean")
+
## a b c
## a 0.000000 1.414214 1.414214
## b 1.414214 0.000000 0.000000
@@ -404,9 +437,9 @@ 6.1 char.diff
We can however make it more interesting by playing with the different rules to play with different tokens.
First let’s create a matrix with morphological characters as numeric character
s:
-## A random character matrix
- matrix(sample(c("0","1","2"), 30, replace = TRUE), ncol = 5,
- (matrix_character <-dimnames = list(letters[1:6], LETTERS[1:5])))
+## A random character matrix
+(matrix_character <- matrix(sample(c("0","1","2"), 30, replace = TRUE), ncol = 5,
+ dimnames = list(letters[1:6], LETTERS[1:5])))
## A B C D E
## a "1" "1" "1" "1" "0"
## b "0" "2" "0" "2" "0"
@@ -414,8 +447,8 @@ 6.1 char.diff
-## The hamming difference between columns
-char.diff(matrix_character)
+
## A B C D E
## A 0.0 0.6 0.6 0.6 0.8
## B 0.6 0.0 0.4 0.4 0.8
@@ -425,14 +458,14 @@ 6.1 char.diff
Here the characters are automatically converted into bitwise integers to be compared efficiently. We can now add some more special tokens like "?"
or "0/1"
for uncertainties between state "0"
and "1"
but not "2"
:
-## Adding uncertain characters
-sample(1:30, 8)] <- "0/1"
- matrix_character[
-## Adding missing data
-sample(1:30, 5)] <- "?"
- matrix_character[
-## This is what it looks like now
- matrix_character
+## Adding uncertain characters
+matrix_character[sample(1:30, 8)] <- "0/1"
+
+## Adding missing data
+matrix_character[sample(1:30, 5)] <- "?"
+
+## This is what it looks like now
+matrix_character
## A B C D E
## a "?" "?" "1" "1" "0"
## b "0" "0/1" "0/1" "0/1" "0"
@@ -440,8 +473,8 @@ 6.1 char.diff
-## The hamming difference between columns including the special characters
-char.diff(matrix_character)
+## The hamming difference between columns including the special characters
+char.diff(matrix_character)
## A B C D E
## A 0.0000000 0.6666667 1.00 0.50 0.6666667
## B 0.6666667 0.0000000 1.00 1.00 0.7500000
@@ -454,12 +487,12 @@ 6.1 char.diff
special.tokens
and special.behaviours
.
The special.tokens
are missing = "?"
, inapplicable = "-"
, uncertainty = "\"
and polymorphism = "&"
meaning we don’t have to modify them for now.
However, say we want to change the behaviour for "?"
and treat them as all possible characters and treat "/"
as only the character "0"
(as an integer) we can specify them giving a behaviour function:
-## Specifying some special behaviours
- list(missing = function(x,y) return(y),
- my_special_behaviours <-uncertainty = function(x,y) return(as.integer(0)))
-
-## Passing these special behaviours to the char.diff function
-char.diff(matrix_character, special.behaviour = my_special_behaviours)
+## Specifying some special behaviours
+my_special_behaviours <- list(missing = function(x,y) return(y),
+ uncertainty = function(x,y) return(as.integer(0)))
+
+## Passing these special behaviours to the char.diff function
+char.diff(matrix_character, special.behaviour = my_special_behaviours)
## A B C D E
## A 0.0 0.6 0.6 0.6 0.6
## B 0.6 0.0 0.8 0.8 0.8
@@ -469,14 +502,14 @@ 6.1 char.diff
The results are quiet different as before! Note that you can also specify some really specific behaviours for any type of special token.
-## Adding weird tokens to the matrix
-sample(1:30, 8)] <- "%"
- matrix_character[
-## Specify the new token and the new behaviour
-char.diff(matrix_character, special.tokens = c(weird_one = "%"),
-special.behaviours = list(
- weird_one = function(x,y) return(as.integer(42)))
- )
+## Adding weird tokens to the matrix
+matrix_character[sample(1:30, 8)] <- "%"
+
+## Specify the new token and the new behaviour
+char.diff(matrix_character, special.tokens = c(weird_one = "%"),
+ special.behaviours = list(
+ weird_one = function(x,y) return(as.integer(42)))
+ )
## A B C D E
## A 0 1 1 0 NaN
## B 1 0 1 1 NaN
@@ -491,14 +524,14 @@ 6.1 char.diff
6.2 clean.data
This is a rather useful function that allows matching a matrix
or a data.frame
to a tree (phylo
) or a distribution of trees (multiPhylo
).
This function outputs the cleaned data and trees (if cleaning was needed) and a list of dropped rows and tips.
-## Generating a trees with labels from a to e
- rtree(5, tip.label = LETTERS[1:5])
- dummy_tree <-
-## Generating a matrix with rows from b to f
- matrix(1, 5, 2, dimnames = list(LETTERS[2:6], c("var1", "var2")))
- dummy_data <-
-##Cleaning the trees and the data
- clean.data(data = dummy_data, tree = dummy_tree)) (cleaned <-
+## Generating a trees with labels from a to e
+dummy_tree <- rtree(5, tip.label = LETTERS[1:5])
+
+## Generating a matrix with rows from b to f
+dummy_data <- matrix(1, 5, 2, dimnames = list(LETTERS[2:6], c("var1", "var2")))
+
+##Cleaning the trees and the data
+(cleaned <- clean.data(data = dummy_data, tree = dummy_tree))
## $tree
##
## Phylogenetic tree with 4 tips and 3 internal nodes.
@@ -524,9 +557,9 @@ 6.2 clean.data
6.3 crown.stem
This function quiet handily separates tips from a phylogeny between crown members (the living taxa and their descendants) and their stem members (the fossil taxa without any living relatives).
-data(BeckLee_tree)
-## Diving both crow and stem species
-crown.stem(BeckLee_tree, inc.nodes = FALSE)) (
+data(BeckLee_tree)
+## Diving both crow and stem species
+(crown.stem(BeckLee_tree, inc.nodes = FALSE))
## $crown
## [1] "Dasypodidae" "Bradypus" "Myrmecophagidae" "Todralestes"
## [5] "Potamogalinae" "Dilambdogale" "Widanelfarasia" "Rhynchocyon"
@@ -552,7 +585,7 @@ 6.3 crown.stem
6.4 get.bin.ages
This function is similar than the crown.stem
one as it is based on a tree but this one outputs the stratigraphic bins ages that the tree is covering.
This can be useful to generate precise bin ages for the chrono.subsets
function:
-get.bin.ages(BeckLee_tree)
+
## [1] 132.9000 129.4000 125.0000 113.0000 100.5000 93.9000 89.8000 86.3000
## [9] 83.6000 72.1000 66.0000 61.6000 59.2000 56.0000 47.8000 41.2000
## [17] 37.8000 33.9000 28.1000 23.0300 20.4400 15.9700 13.8200 11.6300
@@ -568,139 +601,139 @@ 6.5 match.tip.edge
For example, with the charadriiformes
dataset, you can plot the tree with the branches coloured by clade.
To work properly, the function requires the characteristics of the tip labels (e.g. the clade colour) to match the order of the tips in the tree:
-## Loading the charadriiformes data
-data(charadriiformes)
-## Extracting the tree
- charadriiformes$tree
- my_tree <-## Extracting the data column that contains the clade assignments
- charadriiformes$data[, "clade"]
- my_data <-## Changing the levels names (the clade names) to colours
-levels(my_data) <- c("orange", "blue", "darkgreen")
- as.character(my_data)
- my_data <-## Matching the data rownames to the tip order in the tree
- my_data[match(ladderize(my_tree)$tip.label, rownames(charadriiformes$data))] my_data <-
+## Loading the charadriiformes data
+data(charadriiformes)
+## Extracting the tree
+my_tree <- charadriiformes$tree
+## Extracting the data column that contains the clade assignments
+my_data <- charadriiformes$data[, "clade"]
+## Changing the levels names (the clade names) to colours
+levels(my_data) <- c("orange", "blue", "darkgreen")
+my_data <- as.character(my_data)
+## Matching the data rownames to the tip order in the tree
+my_data <- my_data[match(ladderize(my_tree)$tip.label, rownames(charadriiformes$data))]
We can then match this tip data to their common descending edges.
We will also colour the edges that is not descendant directly from a common coloured tip in grey using "replace.na = "grey"
.
Note that these edges are usually the edges at the root of the tree that are the descendant edges from multiple clades.
-## Matching the tip colours (labels) to their descending edges in the tree
-## (and making the non-match edges grey)
- match.tip.edge(my_data, my_tree, replace.na = "grey")
- clade_edges <-
-## Plotting the results
-plot(ladderize(my_tree), show.tip.label = FALSE, edge.color = clade_edges)
-
+## Matching the tip colours (labels) to their descending edges in the tree
+## (and making the non-match edges grey)
+clade_edges <- match.tip.edge(my_data, my_tree, replace.na = "grey")
+
+## Plotting the results
+plot(ladderize(my_tree), show.tip.label = FALSE, edge.color = clade_edges)
+
But you can also use this option to only select some specific edges and modify them (for example making them all equal to one):
-## Adding a fixed edge length to the green clade
- my_tree
- my_tree_modif <- which(clade_edges == "darkgreen")
- green_clade <-$edge.length[green_clade] <- 1
- my_tree_modifplot(ladderize(my_tree_modif), show.tip.label = FALSE,
-edge.color = clade_edges)
-
+
+
6.6 MCMCglmm
utilities
Since version 1.7
, the dispRity
package contains several utility functions for manipulating "MCMCglmm"
(that is, objects returned by the function MCMCglmm::MCMCglmm
).
These objects are a modification of the mcmc
object (from the package coda
) and can be sometimes cumbersome to manipulate because of the huge amount of data in it.
You can use the functions MCMCglmm.traits
for extracting the number of traits, MCMCglmm.levels
for extracting the level names, MCMCglmm.sample
for sampling posterior IDs and MCMCglmm.covars
for extracting variance-covariance matrices. You can also quickly calculate the variance (or relative variance) for each terms in the model using MCMCglmm.variance
(the variance is calculated as the sum of the diagonal of each variance-covariance matrix for each term).
-## Loading the charadriiformes data that contains a MCMCglmm object
-data(charadriiformes)
- charadriiformes$posteriors
- my_MCMCglmm <-
-## Which traits where used in this model?
-MCMCglmm.traits(my_MCMCglmm)
+## Loading the charadriiformes data that contains a MCMCglmm object
+data(charadriiformes)
+my_MCMCglmm <- charadriiformes$posteriors
+
+## Which traits where used in this model?
+MCMCglmm.traits(my_MCMCglmm)
## [1] "PC1" "PC2" "PC3"
-## Which levels where used for the model's random terms and/or residuals?
-MCMCglmm.levels(my_MCMCglmm)
+## Which levels where used for the model's random terms and/or residuals?
+MCMCglmm.levels(my_MCMCglmm)
## random random random random
## "animal:clade_1" "animal:clade_2" "animal:clade_3" "animal"
## residual
## "units"
-## The level names are converted for clarity but you can get them unconverted
-## (i.e. as they appear in the model)
-MCMCglmm.levels(my_MCMCglmm, convert = FALSE)
+## The level names are converted for clarity but you can get them unconverted
+## (i.e. as they appear in the model)
+MCMCglmm.levels(my_MCMCglmm, convert = FALSE)
## random random
## "us(at.level(clade, 1):trait):animal" "us(at.level(clade, 2):trait):animal"
## random random
## "us(at.level(clade, 3):trait):animal" "us(trait):animal"
## residual
## "us(trait):units"
-## Sampling 2 random posteriors samples IDs
- MCMCglmm.sample(my_MCMCglmm, n = 2)) (random_samples <-
+## Sampling 2 random posteriors samples IDs
+(random_samples <- MCMCglmm.sample(my_MCMCglmm, n = 2))
## [1] 749 901
-## Extracting these two random samples
- MCMCglmm.covars(my_MCMCglmm, sample = random_samples)
- my_covars <-
-## Plotting the variance for each term in the model
-boxplot(MCMCglmm.variance(my_MCMCglmm), horizontal = TRUE, las = 1,
-xlab = "Relative variance",
- main = "Variance explained by each term")
-
+## Extracting these two random samples
+my_covars <- MCMCglmm.covars(my_MCMCglmm, sample = random_samples)
+
+## Plotting the variance for each term in the model
+boxplot(MCMCglmm.variance(my_MCMCglmm), horizontal = TRUE, las = 1,
+ xlab = "Relative variance",
+ main = "Variance explained by each term")
+
See more in the $covar
section on what to do with these "MCMCglmm"
objects.
6.7 pair.plot
This utility function allows to plot a matrix image of pairwise comparisons.
This can be useful when getting pairwise comparisons and if you’d like to see at a glance which pairs of comparisons have high or low values.
-## Random data
- matrix(data = runif(42), ncol = 2)
- data <-
-## Plotting the first column as a pairwise comparisons
-pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE,
-diag = 1)
-
+## Random data
+data <- matrix(data = runif(42), ncol = 2)
+
+## Plotting the first column as a pairwise comparisons
+pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE,
+ diag = 1)
+
Here blue squares are ones that have a high value and orange ones the ones that have low values.
Note that the values plotted correspond the first column of the data as designated by what = 1
.
It is also possible to add some tokens or symbols to quickly highlight to specific cells, for example which elements in the data are below a certain value:
-## The same plot as before without the diagonal being
-## the maximal observed value
-pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE,
-diag = "max")
- ## Highlighting with an asterisk which squares have a value
-## below 0.2
-pair.plot(data, what = 1, binary = 0.2, add = "*", cex = 2)
-
+## The same plot as before without the diagonal being
+## the maximal observed value
+pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE,
+ diag = "max")
+## Highlighting with an asterisk which squares have a value
+## below 0.2
+pair.plot(data, what = 1, binary = 0.2, add = "*", cex = 2)
+
This function can also be used as a binary display when running a series of pairwise t-tests.
For example, the following script runs a wilcoxon test between the time-slices from the disparity
example dataset and displays in black which pairs of slices have a p-value below 0.05:
-## Loading disparity data
-data(disparity)
-
-## Testing the pairwise difference between slices
- test.dispRity(disparity, test = wilcox.test, correction = "bonferroni")
- tests <-
-## Plotting the significance
-pair.plot(as.data.frame(tests), what = "p.value", binary = 0.05)
-
+
+
6.8 reduce.matrix
This function allows to reduce columns or rows of a matrix to make sure that there is enough overlap for further analysis.
This is particularly useful if you are going to use distance matrices since it uses the vegan::vegdist
function to test whether distances can be calculated or not.
For example, if we have a patchy matrix like so (where the black squares represent available data):
-set.seed(1)
-## A 10*5 matrix
- matrix(rnorm(50), 10, 5)
- na_matrix <-## Making sure some rows don't overlap
-1, 1:2] <- NA
- na_matrix[2, 3:5] <- NA
- na_matrix[## Adding 50% NAs
-sample(1:50, 25)] <- NA
- na_matrix[## Illustrating the gappy matrix
-image(t(na_matrix), col = "black")
-
+set.seed(1)
+## A 10*5 matrix
+na_matrix <- matrix(rnorm(50), 10, 5)
+## Making sure some rows don't overlap
+na_matrix[1, 1:2] <- NA
+na_matrix[2, 3:5] <- NA
+## Adding 50% NAs
+na_matrix[sample(1:50, 25)] <- NA
+## Illustrating the gappy matrix
+image(t(na_matrix), col = "black")
+
We can use the reduce.matrix
to double check whether any rows cannot be compared.
The functions needs as an input the type of distance that will be used, say a "gower"
distance:
-## Reducing the matrix by row
- reduce.matrix(na_matrix, distance = "gower")) (reduction <-
+
## $rows.to.remove
## [1] "9" "1"
##
## $cols.to.remove
## NULL
We can not remove the rows 1 and 9 and see if that improved the overlap:
-image(t(na_matrix[-as.numeric(reduction$rows.to.remove), ]),
-col = "black")
-
+
+
6.9 select.axes
@@ -708,11 +741,11 @@ 6.9 select.axes
-## The USArrest example in R
- princomp(USArrests, cor = TRUE)
- ordination <-
-## The loading of each variable
-loadings(ordination)
+## The USArrest example in R
+ordination <- princomp(USArrests, cor = TRUE)
+
+## The loading of each variable
+loadings(ordination)
##
## Loadings:
## Comp.1 Comp.2 Comp.3 Comp.4
@@ -725,34 +758,34 @@ 6.9 select.axes
-## Or the same operation but manually
- apply(ordination$scores, 2, var)
- variances <- variances/sum(variances)
- scaled_variances <- cumsum(scaled_variances)
- sumed_variances <-round(rbind(variances, scaled_variances, sumed_variances), 3)
+## Or the same operation but manually
+variances <- apply(ordination$scores, 2, var)
+scaled_variances <- variances/sum(variances)
+sumed_variances <- cumsum(scaled_variances)
+round(rbind(variances, scaled_variances, sumed_variances), 3)
## Comp.1 Comp.2 Comp.3 Comp.4
## variances 2.531 1.010 0.364 0.177
## scaled_variances 0.620 0.247 0.089 0.043
## sumed_variances 0.620 0.868 0.957 1.000
In this example, you can see that the three first axes are required to have at least 0.95 of the variance.
You can do that automatically in dispRity
using the select.axes
function.
-## Same operation automatised
- select.axes(ordination)) (selected <-
+
## The first 3 dimensions are needed to express at least 95% of the variance in the whole trait space.
## You can use x$dimensions to select them or use plot(x) and summary(x) to summarise them.
This function does basically what the script above does and allows the results to be plotted or summarised into a table.
-## Summarising this info
-summary(selected)
+
## Comp.1.var Comp.1.sum Comp.2.var Comp.2.sum Comp.3.var Comp.3.sum
## whole_space 0.62 0.62 0.247 0.868 0.089 0.957
## Comp.4.var Comp.4.sum
## whole_space 0.043 1
-## Plotting it
-plot(selected)
-
-## Extracting the dimensions
-## (for the dispRity function for example)
-$dimensions selected
+
+
+
## [1] 1 2 3
However, it might be interesting to not only consider the variance within the whole trait space but also among groups of specific interest.
E.g. if the 95% of the variance is concentrated in the two first axes for the whole trait space, that does not automatically mean that it is the case for each subset in this space. Some subset might require more than the two first axes to express 95% of their variance!
@@ -760,37 +793,37 @@
6.9 select.axes
Note that you can always change the threshold value (default is 0.95). Here for example we set it to 0.9 (we arbitrarily decide that explain 90% of the variance is enough).
-## Creating some groups of stats
- list("Group1" = c("Mississippi","North Carolina",
- states_groups <-"South Carolina", "Georgia", "Alabama",
- "Alaska", "Tennessee", "Louisiana"),
- "Group2" = c("Florida", "New Mexico", "Michigan",
- "Indiana", "Virginia", "Wyoming", "Montana",
- "Maine", "Idaho", "New Hampshire", "Iowa"),
- "Group3" = c("Rhode Island", "New Jersey", "Hawaii", "Massachusetts"))
- ## Running the same analyses but per groups
- select.axes(ordination, group = states_groups, threshold = 0.9)
- selected <-## Plotting the results
-plot(selected)
-
+## Creating some groups of stats
+states_groups <- list("Group1" = c("Mississippi","North Carolina",
+ "South Carolina", "Georgia", "Alabama",
+ "Alaska", "Tennessee", "Louisiana"),
+ "Group2" = c("Florida", "New Mexico", "Michigan",
+ "Indiana", "Virginia", "Wyoming", "Montana",
+ "Maine", "Idaho", "New Hampshire", "Iowa"),
+ "Group3" = c("Rhode Island", "New Jersey", "Hawaii", "Massachusetts"))
+## Running the same analyses but per groups
+selected <- select.axes(ordination, group = states_groups, threshold = 0.9)
+## Plotting the results
+plot(selected)
+
As you can see here, the whole space requires the three first axes to explain at least 90% of the variance (in fact, 95% as seen before).
However, different groups have a different story!
The Group 1 and 3 requires 4 dimensions whereas Group 2 requires only 1 dimensions (note how for Group 3, there is actually nearly no variance explained on the second axes)!
Using this method, you can safely use the four axes returned by the function (selected$dimensions
) so that every group has at least 90% of their variance explained in the trait space.
If you’ve used the function if you’ve already done some grouping in your disparity analyses (e.g. using the function custom.subsets
or chrono.subsets
), you can use the generated dispRity
to automatise this analyses:
-## Loading the dispRity package demo data
-data(demo_data)
-## A dispRity object with two groups
-$hopkins demo_data
+## Loading the dispRity package demo data
+data(demo_data)
+## A dispRity object with two groups
+demo_data$hopkins
## ---- dispRity object ----
## 2 customised subsets for 46 elements in one matrix:
## adult, juvenile.
-## Selecting axes on a dispRity object
- select.axes(demo_data$hopkins)
- selected <-plot(selected)
-
-## Displaying which axes are necessary for which group
-$dim.list selected
+
+
+
## $adult
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
##
@@ -799,184 +832,207 @@ 6.9 select.axes
-## Note how the whole space needs only 16 axes
-## but both groups need 22 and 23 axes
+
+
+
+6.10 set.root.time
+This function can be used to easily add a $root.time
element to "phylo"
or "multiPhylo"
objects.
+This $root.time
element is used by dispRity
and several packages (e.g. Claddis
and paleotree
) to scale the branch length units of a tree allowing them to be usually expressed in million of years (Mya).
+For example, on a standard random tree, no $root.time
exist so the edge lengths are not expressed in any specific unit:
+
+## NULL
+You can add a root time by either manually setting it:
+## Adding an arbitrary root time
+my_tree_arbitrary <- my_tree
+## Setting the age of the root to 42
+my_tree_arbitrary$root.time <- 42
+Or by calculating it automatically from the cumulated branch length information (making the youngest tip age 0 and the oldest the total age/depth of the tree)
+## Calculating the root time from the present
+my_tree_aged <- my_tree
+my_tree_aged <- set.root.time(my_tree)
+If you want the youngest tip to not be of age 0, you can define an arbitrary age for it and recalculate the age of the root from there using the present
argument (say the youngest tip is 42 Mya old):
+
+This function also works with a distribution of trees ("multiPhylo"
).
-
-6.10 slice.tree
+
+6.11 slice.tree
This function is a modification of the paleotree::timeSliceTree
function that allows to make slices through a phylogenetic tree.
Compared to the paleotree::timeSliceTree
, this function allows a model to decide which tip or node to use when slicing through a branch (whereas paleotree::timeSliceTree
always choose the first available tip alphabetically).
The models for choosing which tip or node are the same as the ones used in the chrono.subsets
and are described in chapter 03: specific tutorials.
The function works by using at least a tree, a slice age and a model:
-set.seed(1)
-## Generate a random ultrametric tree
- rcoal(20)
- tree <-## Add some node labels
-$node.label <- letters[1:19]
- tree## Add its root time
-$root.time <- max(tree.age(tree)$ages)
- tree
-## Slicing the tree at age 0.75
-75 <- slice.tree(tree, age = 0.75, "acctran")
- tree_
-## Showing both trees
-par(mfrow = c(1,2))
-plot(tree, main = "original tree")
-axisPhylo() ; nodelabels(tree$node.label, cex = 0.8)
-abline(v = (max(tree.age(tree)$ages) - 0.75), col = "red")
-plot(tree_75, main = "sliced tree")
-
+set.seed(1)
+## Generate a random ultrametric tree
+tree <- rcoal(20)
+## Add some node labels
+tree$node.label <- letters[1:19]
+## Add its root time
+tree$root.time <- max(tree.age(tree)$ages)
+
+## Slicing the tree at age 0.75
+tree_75 <- slice.tree(tree, age = 0.75, "acctran")
+
+## Showing both trees
+par(mfrow = c(1,2))
+plot(tree, main = "original tree")
+axisPhylo() ; nodelabels(tree$node.label, cex = 0.8)
+abline(v = (max(tree.age(tree)$ages) - 0.75), col = "red")
+plot(tree_75, main = "sliced tree")
+
-
-6.11 slide.nodes
and remove.zero.brlen
+
+6.12 slide.nodes
and remove.zero.brlen
This function allows to slide nodes along a tree!
In other words it allows to change the branch length leading to a node without modifying the overall tree shape.
This can be useful to add some value to 0 branch lengths for example.
The function works by taking a node (or a list of nodes), a tree and a sliding value.
The node will be moved “up” (towards the tips) for the given sliding value.
You can move the node “down” (towards the roots) using a negative value.
-set.seed(42)
-## Generating simple coalescent tree
- rcoal(5)
- tree <-
-## Sliding node 8 up and down
- slide.nodes(8, tree, slide = 0.075)
- tree_slide_up <- slide.nodes(8, tree, slide = -0.075)
- tree_slide_down <-
-## Display the results
-par(mfrow = c(3,1))
-plot(tree, main = "original tree") ; axisPhylo() ; nodelabels()
-plot(tree_slide_up, main = "slide up!") ; axisPhylo() ; nodelabels()
-plot(tree_slide_down, main = "slide down!") ; axisPhylo() ; nodelabels()
-
+set.seed(42)
+## Generating simple coalescent tree
+tree <- rcoal(5)
+
+## Sliding node 8 up and down
+tree_slide_up <- slide.nodes(8, tree, slide = 0.075)
+tree_slide_down <- slide.nodes(8, tree, slide = -0.075)
+
+## Display the results
+par(mfrow = c(3,1))
+plot(tree, main = "original tree") ; axisPhylo() ; nodelabels()
+plot(tree_slide_up, main = "slide up!") ; axisPhylo() ; nodelabels()
+plot(tree_slide_down, main = "slide down!") ; axisPhylo() ; nodelabels()
+
The remove.zero.brlen
is a “clever” wrapping function that uses the slide.nodes
function to stochastically remove zero branch lengths across a whole tree.
This function will slide nodes up or down in successive postorder traversals (i.e. going down the tree clade by clade) in order to minimise the number of nodes to slide while making sure there are no silly negative branch lengths produced!
By default it is trying to slide the nodes using 1% of the minimum branch length to avoid changing the topology too much.
-set.seed(42)
-## Generating a tree
- rtree(20)
- tree <-
-## Adding some zero branch lengths (5)
-$edge.length[sample(1:Nedge(tree), 5)] <- 0
- tree
-## And now removing these zero branch lengths!
- remove.zero.brlen(tree)
- tree_no_zero <-
-## Exaggerating the removal (to make it visible)
- remove.zero.brlen(tree, slide = 1)
- tree_exaggerated <-
-## Check the differences
-any(tree$edge.length == 0)
+set.seed(42)
+## Generating a tree
+tree <- rtree(20)
+
+## Adding some zero branch lengths (5)
+tree$edge.length[sample(1:Nedge(tree), 5)] <- 0
+
+## And now removing these zero branch lengths!
+tree_no_zero <- remove.zero.brlen(tree)
+
+## Exaggerating the removal (to make it visible)
+tree_exaggerated <- remove.zero.brlen(tree, slide = 1)
+
+## Check the differences
+any(tree$edge.length == 0)
## [1] TRUE
-any(tree_no_zero$edge.length == 0)
+
## [1] FALSE
-any(tree_exaggerated$edge.length == 0)
+
## [1] FALSE
-## Display the results
-par(mfrow = c(3,1))
-plot(tree, main = "with zero edges")
-plot(tree_no_zero, main = "without zero edges!")
-plot(tree_exaggerated, main = "with longer edges")
-
+
+
-
-6.12 tree.age
+
+6.13 tree.age
This function allows to quickly calculate the ages of each tips and nodes present in a tree.
-set.seed(1)
- rtree(10)
- tree <-## The tree age from a 10 tip tree
-tree.age(tree)
-## ages elements
-## 1 0.707 t7
-## 2 0.142 t2
-## 3 0.000 t3
-## 4 1.467 t8
-## 5 1.366 t1
-## 6 1.895 t5
-## 7 1.536 t6
-## 8 1.456 t9
-## 9 0.815 t10
-## 10 2.343 t4
-## 11 3.011 11
-## 12 2.631 12
-## 13 1.854 13
-## 14 0.919 14
-## 15 0.267 15
-## 16 2.618 16
-## 17 2.235 17
-## 18 2.136 18
-## 19 1.642 19
+
+## ages elements
+## 1 0.7068 t7
+## 2 0.1417 t2
+## 3 0.0000 t3
+## 4 1.4675 t8
+## 5 1.3656 t1
+## 6 1.8949 t5
+## 7 1.5360 t6
+## 8 1.4558 t9
+## 9 0.8147 t10
+## 10 2.3426 t4
+## 11 3.0111 11
+## 12 2.6310 12
+## 13 1.8536 13
+## 14 0.9189 14
+## 15 0.2672 15
+## 16 2.6177 16
+## 17 2.2353 17
+## 18 2.1356 18
+## 19 1.6420 19
It also allows to set the age of the root of the tree:
-## The ages starting from -100 units
-tree.age(tree, age = 100)
-## ages elements
-## 1 23.472 t7
-## 2 4.705 t2
-## 3 0.000 t3
-## 4 48.736 t8
-## 5 45.352 t1
-## 6 62.931 t5
-## 7 51.012 t6
-## 8 48.349 t9
-## 9 27.055 t10
-## 10 77.800 t4
-## 11 100.000 11
-## 12 87.379 12
-## 13 61.559 13
-## 14 30.517 14
-## 15 8.875 15
-## 16 86.934 16
-## 17 74.235 17
-## 18 70.924 18
-## 19 54.533 19
+
+## ages elements
+## 1 23.4717 t7
+## 2 4.7048 t2
+## 3 0.0000 t3
+## 4 48.7362 t8
+## 5 45.3517 t1
+## 6 62.9315 t5
+## 7 51.0119 t6
+## 8 48.3486 t9
+## 9 27.0554 t10
+## 10 77.7998 t4
+## 11 100.0000 11
+## 12 87.3788 12
+## 13 61.5593 13
+## 14 30.5171 14
+## 15 8.8746 15
+## 16 86.9341 16
+## 17 74.2347 17
+## 18 70.9239 18
+## 19 54.5330 19
Usually tree age is calculated from the present to the past (e.g. in million years ago) but it is possible to reverse it using the order = present
option:
-## The ages in terms of tip/node height
-tree.age(tree, order = "present")
-## ages elements
-## 1 2.304 t7
-## 2 2.869 t2
-## 3 3.011 t3
-## 4 1.544 t8
-## 5 1.646 t1
-## 6 1.116 t5
-## 7 1.475 t6
-## 8 1.555 t9
-## 9 2.196 t10
-## 10 0.668 t4
-## 11 0.000 11
-## 12 0.380 12
-## 13 1.157 13
-## 14 2.092 14
-## 15 2.744 15
-## 16 0.393 16
-## 17 0.776 17
-## 18 0.876 18
-## 19 1.369 19
+
+## ages elements
+## 1 2.3043 t7
+## 2 2.8694 t2
+## 3 3.0111 t3
+## 4 1.5436 t8
+## 5 1.6455 t1
+## 6 1.1162 t5
+## 7 1.4751 t6
+## 8 1.5553 t9
+## 9 2.1964 t10
+## 10 0.6685 t4
+## 11 0.0000 11
+## 12 0.3800 12
+## 13 1.1575 13
+## 14 2.0922 14
+## 15 2.7439 15
+## 16 0.3934 16
+## 17 0.7758 17
+## 18 0.8755 18
+## 19 1.3690 19
-
-6.13 multi.ace
-This function allows to run the ape::ace
function (ancestral characters estimations) on multiple trees.
+
+6.14 multi.ace
+This function allows to run ancestral characters estimations on multiple trees.
In it’s most basic structure (e.g. using all default arguments) this function is using a mix of ape::ace
and castor::asr_mk_model
depending on the data and the situation and is generally faster than both functions when applied to a list of trees.
However, this function provides also some more complex and modular functionalities, especially appropriate when using discrete morphological character data.
-
-6.13.1 Using different character tokens in different situations
+
+6.14.1 Using different character tokens in different situations
This data can be often coded in non-standard way with different character tokens having different meanings.
For example, in some datasets the token -
can mean “the trait is inapplicable” but this can be also coded by the more conventional NA
or can mean “this trait is missing” (often coded ?
).
This makes the meaning of specific tokens idiosyncratic to different matrices.
For example we can have the following discrete morphological matrix with all the data encoded:
-set.seed(42)
-## A random tree with 10 tips
- rcoal(10)
- tree <-## Setting up the parameters
- c(rgamma, rate = 10, shape = 5)
- my_rates =
-## Generating a bunch of trees
- rmtree(5, 10)
- multiple_trees <-
-## A random Mk matrix (10*50)
- sim.morpho(tree, characters = 50, model = "ER", rates = my_rates,
- matrix_simple <-invariant = FALSE)
- 1:10, 1:10] matrix_simple[
+set.seed(42)
+## A random tree with 10 tips
+tree <- rcoal(10)
+## Setting up the parameters
+my_rates = c(rgamma, rate = 10, shape = 5)
+
+## Generating a bunch of trees
+multiple_trees <- rmtree(5, 10)
+
+## A random Mk matrix (10*50)
+matrix_simple <- sim.morpho(tree, characters = 50, model = "ER", rates = my_rates,
+ invariant = FALSE)
+matrix_simple[1:10, 1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## t8 "1" "1" "1" "1" "0" "0" "0" "0" "0" "1"
## t3 "1" "1" "1" "1" "0" "0" "0" "0" "0" "1"
@@ -991,15 +1047,15 @@ 6.13.1 Using different character
But of course, as mentioned above, in practice, such matrices have more nuance and can including missing characters, ambiguous characters, multi-state characters, inapplicable characters, etc…
All these coded and defined by different authors using different tokens (or symbols).
Let’s give it a go and transform this simple data to something more messy:
-## Modify the matrix to contain missing and special data
- matrix_simple
- matrix_complex <-## Adding 50 random "-" tokens
-sample(1:length(matrix_complex), 50)] <- "-"
- matrix_complex[## Adding 50 random "?" tokens
-sample(1:length(matrix_complex), 50)] <- "?"
- matrix_complex[## Adding 50 random "0%2" tokens
-sample(1:length(matrix_complex), 50)] <- "0%2"
- matrix_complex[1:10,1:10] matrix_complex[
+## Modify the matrix to contain missing and special data
+matrix_complex <- matrix_simple
+## Adding 50 random "-" tokens
+matrix_complex[sample(1:length(matrix_complex), 50)] <- "-"
+## Adding 50 random "?" tokens
+matrix_complex[sample(1:length(matrix_complex), 50)] <- "?"
+## Adding 50 random "0%2" tokens
+matrix_complex[sample(1:length(matrix_complex), 50)] <- "0%2"
+matrix_complex[1:10,1:10]
## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
## t8 "1" "1" "1" "1" "?" "0" "0" "0" "0" "0%2"
## t3 "1" "-" "1" "1" "?" "0" "0" "0" "0" "1"
@@ -1019,146 +1075,185 @@ 6.13.1 Using different character
For example we might want to create a special case called "missing"
(i.e. the data is missing) that we want to denote using the token "?"
and we can specify the algorithm to treat this "missing"
cases ("?"
) as treating the character token value as “any possible values”.
This behaviour can be hard coded by providing a function with the name of the behaviour.
For example:
-## The specific token for the missing cases (note the "\\" for protecting the value)
- c("missing" = "\\?")
- special.tokens <-
-## The behaviour for the missing cases (?)
- list(missing <- function(x, y) return(y))
- special.behaviour <-## Where x is the input value (here "?") and y is all the possible normal values for the character
+## The specific token for the missing cases (note the "\\" for protecting the value)
+special.tokens <- c("missing" = "\\?")
+
+## The behaviour for the missing cases (?)
+special.behaviour <- list(missing <- function(x, y) return(y))
+## Where x is the input value (here "?") and y is all the possible normal values for the character
This example shows a very common case (and is actually used by default, more on that below) but this architecture allows for very modular combination of tokens and behaviours.
For example, in our code above we introduced the token "%"
which is very odd (to my knowledge) and might mean something very specific in our case.
Say we want to call this case "weirdtoken"
and mean that whenever this token is encountered in a character, it should be interpreted by the algorithm as the values 1 and 2, no matter what:
-## Set a list of extra special tokens
- c("weirdtoken" = "\\%")
- my_spec_tokens <-
-## Weird tokens are considered as state 0 and 3
- list()
- my_spec_behaviours <-$weirdtoken <- function(x,y) return(c(1,2)) my_spec_behaviours
+## Set a list of extra special tokens
+my_spec_tokens <- c("weirdtoken" = "\\%")
+
+## Weird tokens are considered as state 0 and 3
+my_spec_behaviours <- list()
+my_spec_behaviours$weirdtoken <- function(x,y) return(c(1,2))
If you don’t need/don’t have any of this specific tokens, don’t worry, most special but common tokens are handled by default as such:
-## The token for missing values:
- c("missing" = "\\?",
- default_tokens <-## The token for inapplicable values:
-"inapplicable" = "\\-",
- ## The token for polymorphisms:
-"polymorphism" = "\\&",
- ## The token for uncertainties:
-"uncertanity" = "\\/")
+## The token for missing values:
+default_tokens <- c("missing" = "\\?",
+## The token for inapplicable values:
+ "inapplicable" = "\\-",
+## The token for polymorphisms:
+ "polymorphism" = "\\&",
+## The token for uncertainties:
+ "uncertanity" = "\\/")
With the following associated default behaviours
-## Treating missing data as all data values
- list(missing <- function(x,y) y,
- default_behaviour <-## Treating inapplicable data as all data values (like missing)
- function(x, y) y,
- inapplicable <-## Treating polymorphisms as all values present:
- function(x,y) strsplit(x, split = "\\&")[[1]],
- polymorphism <-## Treating uncertainties as all values present (like polymorphisms):
- function(x,y) strsplit(x, split = "\\&")[[1]]) uncertanity <-
+## Treating missing data as all data values
+default_behaviour <- list(missing <- function(x,y) y,
+## Treating inapplicable data as all data values (like missing)
+ inapplicable <- function(x, y) y,
+## Treating polymorphisms as all values present:
+ polymorphism <- function(x,y) strsplit(x, split = "\\&")[[1]],
+## Treating uncertainties as all values present (like polymorphisms):
+ uncertanity <- function(x,y) strsplit(x, split = "\\/")[[1]])
We can then use these token description along with our complex matrix and our list of trees to run the ancestral states estimations as follows:
-## Running ancestral states
- multi.ace(matrix_complex, multiple_trees,
- ancestral_states <-special.tokens = my_spec_tokens,
- special.behaviours = my_spec_behaviours,
- verbose = TRUE)
+## Running ancestral states
+ancestral_states <- multi.ace(matrix_complex, multiple_trees,
+ special.tokens = my_spec_tokens,
+ special.behaviours = my_spec_behaviours,
+ verbose = TRUE)
## Preparing the data:...
-## Warning: The characters 39 are invariant (using the current special behaviours
-## for special characters) and are simply duplicated for each node.
+## Warning: The character 39 is invariant (using the current special behaviours
+## for special characters) and is simply duplicated for each node.
## ..Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## This outputs a list of ancestral parts of the matrices for each tree
-## For example, here's the first one:
-1]][1:9, 1:10] ancestral_states[[
-## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
-## [1,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
-## [2,] "1" "1" "1" "1" "0/1" "0/1/2" "0/1" "0" "0" "1"
-## [3,] "1" "1" "1" "1" "0/1" "0/1/2" "0" "0" "0" "1"
-## [4,] "1" "1" "1" "1" "0" "0/1/2" "1" "1" "0" "1"
-## [5,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
-## [6,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
-## [7,] "0" "0/1" "0/1" "0" "1" "1" "1" "0" "0" "0/1"
-## [8,] "0" "0" "0" "0" "1" "0/1/2" "0" "0" "1" "0"
-## [9,] "0" "0" "0" "0" "1" "1" "0" "0" "1" "0"
+## Running ancestral states estimations:.....................................................................................................................................................................................................................................................Done.
+## This outputs a list of ancestral parts of the matrices for each tree
+## For example, here's the first one:
+ancestral_states[[1]][1:9, 1:10]
+## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
+## n1 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
+## n2 "1" "1" "1" "1" "0/1" "0/1/2" "0/1" "0" "0" "1"
+## n3 "1" "1" "1" "1" "0/1" "0/1/2" "0" "0" "0" "1"
+## n4 "1" "1" "1" "1" "0" "0/1/2" "1" "1" "0" "1"
+## n5 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
+## n6 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1"
+## n7 "0" "0/1" "0/1" "0" "1" "1" "1" "0" "0" "0/1"
+## n8 "0" "0" "0" "0" "1" "0/1/2" "0" "0" "1" "0"
+## n9 "0" "0" "0" "0" "1" "1" "0" "0" "1" "0"
Note that there are many different options that are not covered here.
For example, you can use different models for each character via the models
argument, you can specify how to handle uncertainties via the threshold
argument, use a branch length modifier (brlen.multiplier
), specify the type of output, etc…
-
-6.13.2 Feeding the results to char.diff
to get distance matrices
-Finally, after running your ancestral states estimations, it is not uncommon to then use these resulting data to calculate the distances between taxa and then ordinate the results to measure disparity.
+
+6.14.2 Feeding the results to char.diff
to get distance matrices
+After running your ancestral states estimations, it is not uncommon to then use these resulting data to calculate the distances between taxa and then ordinate the results to measure disparity.
You can do that using the char.diff
function described above but instead of measuring the distances between characters (columns) you can measure the distances between species (rows).
You might notice that this function uses the same modular token and behaviour descriptions.
That makes sense because they’re using the same core C functions implemented in dispRity that greatly speed up distance calculations.
-## Running ancestral states
-## and outputing a list of combined matrices (tips and nodes)
- multi.ace(matrix_complex, multiple_trees,
- ancestral_states <-special.tokens = my_spec_tokens,
- special.behaviours = my_spec_behaviours,
- output = "combined.matrix",
- verbose = TRUE)
+## Running ancestral states
+## and outputing a list of combined matrices (tips and nodes)
+ancestral_states <- multi.ace(matrix_complex, multiple_trees,
+ special.tokens = my_spec_tokens,
+ special.behaviours = my_spec_behaviours,
+ output = "combined.matrix",
+ verbose = TRUE)
## Preparing the data:...
-## Warning: The characters 39 are invariant (using the current special behaviours
-## for special characters) and are simply duplicated for each node.
+## Warning: The character 39 is invariant (using the current special behaviours
+## for special characters) and is simply duplicated for each node.
## ..Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
-## Running ancestral states estimations:
-## .................................................
-## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs =
-## list(special.tokens = special.tokens), : longer argument not a multiple of
-## length of shorter
-## Done.
+## Running ancestral states estimations:.....................................................................................................................................................................................................................................................Done.
We can then feed these matrices directly to char.diff
, say for calculating the “MORD” distance:
-## Measuring the distances between rows using the MORD distance
- lapply(ancestral_states, char.diff, method = "mord", by.col = FALSE) distances <-
+## Measuring the distances between rows using the MORD distance
+distances <- lapply(ancestral_states, char.diff, method = "mord", by.col = FALSE)
And we now have a list of distances matrices with ancestral states estimated!
+
+
+6.14.3 Running ancestral states estimations for continuous characters
+You can also run multi.ace
on continuous characters.
+The function detects any continuous characters as being of class "numeric"
and runs them using the ape::ace
function.
+set.seed(1)
+## Creating three coalescent trees
+my_trees <- replicate(3, rcoal(15), simplify = FALSE)
+## Adding node labels
+my_trees <- lapply(my_trees, makeNodeLabel)
+## Making into a multiPhylo object
+class(my_trees) <- "multiPhylo"
+
+## Creating a matrix of continuous characters
+data <- space.maker(elements = 15, dimensions = 5, distribution = rnorm,
+ elements.name = my_trees[[1]]$tip.label)
+With such data and trees you can easily run the multi.ace
estimations.
+By default, the estimations use the default arguments from ape::ace
, knowingly a Brownian Motion (model = "BM"
) with the REML method (method = "REML"
; this method “first estimates the ancestral value at the root (aka, the phylogenetic mean), then the variance of the Brownian motion process is estimated by optimizing the residual log-likelihood” - from ?ape::ace
).
+
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+
+## List of 3
+## $ : num [1:14, 1:5] -0.191 -0.155 -0.227 -0.17 0.138 ...
+## ..- attr(*, "dimnames")=List of 2
+## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ...
+## .. ..$ : NULL
+## $ : num [1:14, 1:5] -0.385 -0.552 -0.445 -0.435 -0.478 ...
+## ..- attr(*, "dimnames")=List of 2
+## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ...
+## .. ..$ : NULL
+## $ : num [1:14, 1:5] -0.3866 -0.2232 -0.0592 -0.7246 -0.2253 ...
+## ..- attr(*, "dimnames")=List of 2
+## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ...
+## .. ..$ : NULL
+This results in three matrices with ancestral states for the nodes.
+When using continuous characters, however, you can output the results directly as a dispRity
object that allows visualisation and other normal dispRity pipeline:
+## Running multi.ace on continuous data
+my_ancestral_states <- multi.ace(data, my_trees, output = "dispRity")
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+
+
+You can also mix continuous and discrete characters together.
+By default the multi.ace
detects which character is of which type and applies the correct estimations based on that.
+However you can always specify models or other details character per characters.
+## Adding two discrete characters
+data <- as.data.frame(data)
+data <- cbind(data, "new_char" = as.character(sample(1:2, 15, replace = TRUE)))
+data <- cbind(data, "new_char2" = as.character(sample(1:2, 15, replace = TRUE)))
+
+## Setting up different models for each characters
+## BM for all 5 continuous characters
+## and ER and ARD for the two discrete ones
+my_models <- c(rep("BM", 5), "ER", "ARD")
+
+## Running the estimation with the specified models
+my_ancestral_states <- multi.ace(data, my_trees, models = my_models)
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+## Warning in sqrt(1/out$hessian): NaNs produced
+Of course all the options discussed in the first part above also can apply here!
diff --git a/inst/gitbook/_book/palaeobiology-demo-disparity-through-time-and-within-groups.html b/inst/gitbook/_book/palaeobiology-demo-disparity-through-time-and-within-groups.html
index 6e6a98a3..b752aeb1 100644
--- a/inst/gitbook/_book/palaeobiology-demo-disparity-through-time-and-within-groups.html
+++ b/inst/gitbook/_book/palaeobiology-demo-disparity-through-time-and-within-groups.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -361,39 +394,39 @@
9 Palaeobiology demo: disparity-through-time and within groups
This demo aims to give quick overview of the dispRity
package (v.1.7) for palaeobiology analyses of disparity, including disparity through time analyses.
-This demo showcases a typical disparity-through-time analysis: we are going to test whether the disparity changed through time in a subset of eutherian mammals from the last 100 million years using a dataset from Beck and Lee (2014).
+This demo showcases a typical disparity-through-time analysis: we are going to test whether the disparity changed through time in a subset of eutherian mammals from the last 100 million years using a dataset from Beck and Lee (2014).
9.1 Before starting
9.1.1 The morphospace
-In this example, we are going to use a subset of the data from Beck and Lee (2014).
+
In this example, we are going to use a subset of the data from Beck and Lee (2014).
See the example data description for more details.
Briefly, this dataset contains an ordinated matrix of the Gower distance between 50 mammals based (BeckLee_mat50
), another matrix of the same 50 mammals and the estimated discrete data characters of their descendants (thus 50 + 49 rows, BeckLee_mat99
), a dataframe containing the ages of each taxon in the dataset (BeckLee_ages
) and finally a phylogenetic tree with the relationships among the 50 mammals (BeckLee_tree
).
The ordinated matrix will represent our full morphospace, i.e. all the mammalian morphologies that ever existed through time (for this dataset).
-## Loading demo and the package data
-library(dispRity)
-
-## Setting the random seed for repeatability
-set.seed(123)
-
-## Loading the ordinated matrix/morphospace:
-data(BeckLee_mat50)
-data(BeckLee_mat99)
-head(BeckLee_mat50[,1:5])
-## [,1] [,2] [,3] [,4] [,5]
-## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039
-## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479
-## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646
-## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626
-## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914
-## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351
-dim(BeckLee_mat50)
+## Loading demo and the package data
+library(dispRity)
+
+## Setting the random seed for repeatability
+set.seed(123)
+
+## Loading the ordinated matrix/morphospace:
+data(BeckLee_mat50)
+data(BeckLee_mat99)
+head(BeckLee_mat50[,1:5])
+## [,1] [,2] [,3] [,4] [,5]
+## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039
+## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479
+## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646
+## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626
+## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914
+## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351
+
## [1] 50 48
-## The morphospace contains 50 taxa and has 48 dimensions (or axes)
-
-## Showing a list of first and last occurrences data for some fossils
-data(BeckLee_ages)
-head(BeckLee_ages)
+## The morphospace contains 50 taxa and has 48 dimensions (or axes)
+
+## Showing a list of first and last occurrences data for some fossils
+data(BeckLee_ages)
+head(BeckLee_ages)
## FAD LAD
## Adapis 37.2 36.8
## Asioryctes 83.6 72.1
@@ -401,17 +434,17 @@ 9.1.1 The morphospace## Plotting a phylogeny
-data(BeckLee_tree)
-plot(BeckLee_tree, cex = 0.7)
-axisPhylo(root = 140)
-
+
+
You can have an even nicer looking tree if you use the strap
package!
-if(!require(strap)) install.packages("strap")
-::geoscalePhylo(BeckLee_tree, cex.tip = 0.7, cex.ts = 0.6) strap
-
+
+
9.1.2 Setting up your own data
@@ -419,7 +452,7 @@ 9.1.2 Setting up your own data
What data can I use?
-You can use any type of morphospace in any dataset form ("matrix"
, "data.frame"
). Throughout this tutorial, you we assume you are using the (loose) morphospace definition from Thomas Guillerme, Cooper, et al. (2020): any matrix were columns are traits and rows are observations (in a distance matrix, columns are still trait, i.e. “distance to species A”, etc.).
+
You can use any type of morphospace in any dataset form ("matrix"
, "data.frame"
). Throughout this tutorial, you we assume you are using the (loose) morphospace definition from Thomas Guillerme, Cooper, et al. (2020): any matrix were columns are traits and rows are observations (in a distance matrix, columns are still trait, i.e. “distance to species A”, etc.).
We won’t cover it here but you can also use lists of matrices and list of trees.
How should I format my data for this tutorial?
@@ -436,56 +469,56 @@ 9.1.2 Setting up your own dataWARNING: the data generated by the functions i.need.a.matrix
, i.need.a.tree
, i.need.node.data
and i.need.FADLAD
are used to SIMULATE data for this tutorial. This is not to be used for publications or analysing real data!
If you need a data matrix, a phylogenetic tree or FADLAD data, (i.need.a.matrix
, i.need.a.tree
and i.need.FADLAD
), you will actually need to collect data from the literature or the field! If you need node data, you will need to use ancestral states estimations (e.g. using estimate_ancestral_states
from the Claddis
package).
-## Functions to get simulate a PCO looking like matrix from a tree
- function(tree) {
- i.need.a.matrix <- space.maker(elements = Ntip(tree), dimensions = Ntip(tree), distribution = rnorm,
- matrix <-scree = rev(cumsum(rep(1/Ntip(tree), Ntip(tree)))))
- rownames(matrix) <- tree$tip.label
- return(matrix)
-
- }
-## Function to simulate a tree
- function(matrix) {
- i.need.a.tree <- rtree(nrow(matrix))
- tree <-$root.time <- max(tree.age(tree)$age)
- tree$tip.label <- rownames(matrix)
- tree$node.label <- paste0("n", 1:(nrow(matrix)-1))
- treereturn(tree)
-
- }
-## Function to simulate some "node" data
- function(matrix, tree) {
- i.need.node.data <- space.maker(elements = Nnode(tree), dimensions = ncol(matrix),
- matrix_node <-distribution = rnorm, scree = apply(matrix, 2, var))
- if(!is.null(tree$node.label)) {
- rownames(matrix_node) <- tree$node.label
- else {
- } rownames(matrix_node) <- paste0("n", 1:(nrow(matrix)-1))
-
- }return(rbind(matrix, matrix_node))
-
- }
-## Function to simulate some "FADLAD" data
- function(tree) {
- i.need.FADLAD <- tree.age(tree)[1:Ntip(tree),]
- tree_ages <-return(data.frame(FAD = tree_ages[,1], LAD = tree_ages[,1], row.names = tree_ages[,2]))
- }
+## Functions to get simulate a PCO looking like matrix from a tree
+i.need.a.matrix <- function(tree) {
+ matrix <- space.maker(elements = Ntip(tree), dimensions = Ntip(tree), distribution = rnorm,
+ scree = rev(cumsum(rep(1/Ntip(tree), Ntip(tree)))))
+ rownames(matrix) <- tree$tip.label
+ return(matrix)
+}
+
+## Function to simulate a tree
+i.need.a.tree <- function(matrix) {
+ tree <- rtree(nrow(matrix))
+ tree$root.time <- max(tree.age(tree)$age)
+ tree$tip.label <- rownames(matrix)
+ tree$node.label <- paste0("n", 1:(nrow(matrix)-1))
+ return(tree)
+}
+
+## Function to simulate some "node" data
+i.need.node.data <- function(matrix, tree) {
+ matrix_node <- space.maker(elements = Nnode(tree), dimensions = ncol(matrix),
+ distribution = rnorm, scree = apply(matrix, 2, var))
+ if(!is.null(tree$node.label)) {
+ rownames(matrix_node) <- tree$node.label
+ } else {
+ rownames(matrix_node) <- paste0("n", 1:(nrow(matrix)-1))
+ }
+ return(rbind(matrix, matrix_node))
+}
+
+## Function to simulate some "FADLAD" data
+i.need.FADLAD <- function(tree) {
+ tree_ages <- tree.age(tree)[1:Ntip(tree),]
+ return(data.frame(FAD = tree_ages[,1], LAD = tree_ages[,1], row.names = tree_ages[,2]))
+}
You can use these functions for the generating the data you need. For example
-## Aaaaah I don't have FADLAD data!
- i.need.FADLAD(tree)
- my_FADLAD <-## Sorted.
+
In the end this is what your data should be named to facilitate the rest of this tutorial (fill in yours here):
-## A matrix with tip data
- BeckLee_mat50
- my_matrix <-
-## A phylogenetic tree
- BeckLee_tree
- my_tree <-
-## A matrix with tip and node data
- BeckLee_mat99
- my_tip_node_matrix <-
-## A table of first and last occurrences data (FADLAD)
- BeckLee_ages my_fadlad <-
+
@@ -497,21 +530,21 @@ 9.2.1 Splitting the morphospace t
The dispRity
package provides a chrono.subsets
function that allows users to split the morphospace into time slices (using method = continuous
) or into time bins (using method = discrete
).
In this example, we are going to split the morphospace into five equal time bins of 20 million years long from 100 million years ago to the present.
We will also provide to the function a table containing the first and last occurrences dates for some fossils to take into account that some fossils might occur in several of our different time bins.
-## Creating the vector of time bins ages
- rev(seq(from = 0, to = 100, by = 20))
- time_bins <-
-## Splitting the morphospace using the chrono.subsets function
- chrono.subsets(data = my_matrix, tree = my_tree,
- binned_morphospace <-method = "discrete", time = time_bins, inc.nodes = FALSE,
- FADLAD = my_fadlad)
+## Creating the vector of time bins ages
+time_bins <- rev(seq(from = 0, to = 100, by = 20))
+
+## Splitting the morphospace using the chrono.subsets function
+binned_morphospace <- chrono.subsets(data = my_matrix, tree = my_tree,
+ method = "discrete", time = time_bins, inc.nodes = FALSE,
+ FADLAD = my_fadlad)
The output object is a dispRity
object (see more about that here.
In brief, dispRity
objects are lists of different elements (i.e. disparity results, morphospace time subsets, morphospace attributes, etc.) that display only a summary of the object when calling the object to avoiding filling the R
console with superfluous output.
It also allows easy plotting/summarising/analysing for repeatability down the line but we will not go into this right now.
-## Printing the class of the object
-class(binned_morphospace)
+
## [1] "dispRity"
-## Printing the content of the object
-str(binned_morphospace)
+
## List of 4
## $ matrix :List of 1
## ..$ : num [1:50, 1:48] -0.561 -0.419 -0.834 -0.771 -0.832 ...
@@ -544,10 +577,10 @@ 9.2.1 Splitting the morphospace t
## ..$ 20 - 0 :List of 1
## .. ..$ elements: int [1:10, 1] 36 37 38 32 33 34 50 48 29 30
## - attr(*, "class")= chr "dispRity"
-names(binned_morphospace)
+
## [1] "matrix" "tree" "call" "subsets"
-## Printing the object as a dispRity class
- binned_morphospace
+
## ---- dispRity object ----
## 5 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree
## 100 - 80, 80 - 60, 60 - 40, 40 - 20, 20 - 0.
@@ -560,12 +593,12 @@ 9.2.2 Bootstrapping the dataOnce we obtain our different time subsets, we can bootstrap and rarefy them (i.e. pseudo-replicating the data).
The bootstrapping allows us to make each subset more robust to outliers and the rarefaction allows us to compare subsets with the same number of taxa to remove sampling biases (i.e. more taxa in one subset than the others).
The boot.matrix
function bootstraps the dispRity
object and the rarefaction
option within performs rarefaction.
-## Getting the minimum number of rows (i.e. taxa) in the time subsets
- min(size.subsets(binned_morphospace))
- minimum_size <-
-## Bootstrapping each time subset 100 times and rarefying them
- boot.matrix(binned_morphospace, bootstraps = 100,
- rare_bin_morphospace <-rarefaction = minimum_size)
+## Getting the minimum number of rows (i.e. taxa) in the time subsets
+minimum_size <- min(size.subsets(binned_morphospace))
+
+## Bootstrapping each time subset 100 times and rarefying them
+rare_bin_morphospace <- boot.matrix(binned_morphospace, bootstraps = 100,
+ rarefaction = minimum_size)
Note how information is adding up to the dispRity
object.
@@ -577,35 +610,35 @@ 9.2.3 Calculating disparitydispRity
metric section (or directly use moms
).
In this example, we are going to look at how the spread of the data in the morphospace through time.
For that we are going to use the sum of the variance from each dimension of the morphospace in the morphospace.
-We highly recommend using a metric that makes sense for your specific analysis and for your specific dataset and not just because everyone uses it (Thomas Guillerme, Puttick, et al. 2020, @Guillerme2020)!
+We highly recommend using a metric that makes sense for your specific analysis and for your specific dataset and not just because everyone uses it Thomas Guillerme, Cooper, et al. (2020)!
How can I be sure that the metric is the most appropriate for my morphospace and question?
This is not a straightforward question but you can use the test.metric
function to check your assumptions (more details here): basically what test.metric
does is modifying your morphospace using a null process of interest (e.g. changes in size) and checks whether your metric does indeed pick up that change.
For example here, let see if the sum of variances picks up changes in size but not random changes:
- test.metric(my_matrix, metric = c(sum, dispRity::variances), shifts = c("random", "size"))
- my_test <-summary(my_test)
+my_test <- test.metric(my_matrix, metric = c(sum, dispRity::variances), shifts = c("random", "size"))
+summary(my_test)
## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope
-## random 2.41 2.51 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0006434981
-## size.increase 2.23 2.19 2.25 2.33 2.31 2.35 2.43 2.44 2.48 2.52 0.0036071419
-## size.hollowness 2.40 2.56 2.56 2.60 2.63 2.64 2.60 2.58 2.55 2.52 0.0006032204
+## random 2.53 2.50 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0003234646
+## size.increase 2.23 2.17 2.25 2.26 2.31 2.35 2.39 2.47 2.50 2.52 0.0037712409
+## size.hollowness 2.40 2.50 2.59 2.65 2.63 2.62 2.60 2.57 2.55 2.52 0.0008954035
## p_value R^2(adj)
-## random 3.046683e-02 0.12638784
-## size.increase 4.009847e-16 0.90601561
-## size.hollowness 1.324664e-01 0.04783366
-plot(my_test)
-
-We see that changes in the inner size (see Thomas Guillerme, Puttick, et al. (2020) for more details) is actually picked up by the sum of variances but not random changes or outer changes. Which is a good thing!
+## random 9.689431e-02 0.06301936
+## size.increase 1.016309e-17 0.93443767
+## size.hollowness 6.630162e-02 0.08377594
+
+
+We see that changes in the inner size (see Thomas Guillerme, Puttick, et al. (2020) for more details) is actually picked up by the sum of variances but not random changes or outer changes. Which is a good thing!
As you’ve noted, the sum of variances is defined in test.metric
as c(sum, variances)
. This is a core bit of the dispRity
package were you can define your own metric as a function or a set of functions.
You can find more info about this in the dispRity
metric section but in brief, the dispRity
package considers metrics by their “dimensions” level which corresponds to what they output. For example, the function sum
is a dimension level 1 function because no matter the input it outputs a single value (the sum), variances
on the other hand is a dimension level 2 function because it will output the variance of each column in a matrix (an example of a dimensions level 3 would be the function var
that outputs a matrix).
The dispRity
package always automatically sorts the dimensions levels: it will always run dimensions level 3 > dimensions level 2 > and dimensions level 1. In this case both c(sum, variances)
and c(variances, sum)
will result in actually running sum(variances(matrix))
.
Anyways, let’s calculate the sum of variances on our bootstrapped and rarefied morphospaces:
-## Calculating disparity for the bootstrapped and rarefied data
- dispRity(rare_bin_morphospace , metric = c(sum, dispRity::variances)) disparity <-
+## Calculating disparity for the bootstrapped and rarefied data
+disparity <- dispRity(rare_bin_morphospace , metric = c(sum, dispRity::variances))
To display the actual calculated scores, we need to summarise the disparity object using the S3 method summary
that is applied to a dispRity
object (see ?summary.dispRity
for more details).
By the way, as for any R
package, you can refer to the help files for each individual function for more details.
-## Summarising the disparity results
-summary(disparity)
+
## subsets n obs bs.median 2.5% 25% 75% 97.5%
## 1 100 - 80 8 2.207 1.962 1.615 1.876 2.017 2.172
## 2 100 - 80 6 NA 1.923 1.477 1.768 2.065 2.222
@@ -624,15 +657,15 @@ 9.2.3 Calculating disparity9.2.4 Plotting the results
It is sometimes easier to visualise the results in a plot than in a table.
For that we can use the plot
S3 function to plot the dispRity
objects (see ?plot.dispRity
for more details).
-## Graphical options
-quartz(width = 10, height = 5) ; par(mfrow = (c(1,2)), bty = "n")
+
## Warning in quartz(width = 10, height = 5): Quartz device is not available on
## this platform
-## Plotting the bootstrapped and rarefied results
-plot(disparity, type = "continuous", main = "bootstrapped results")
-plot(disparity, type = "continuous", main = "rarefied results",
-rarefaction = minimum_size)
-
+## Plotting the bootstrapped and rarefied results
+plot(disparity, type = "continuous", main = "bootstrapped results")
+plot(disparity, type = "continuous", main = "rarefied results",
+ rarefaction = minimum_size)
+
Nice. The curves look pretty similar.
Same as for the summary.dispRity
function, check out the plot.dispRity
manual for the many, many options available.
@@ -645,9 +678,9 @@ 9.2.5 Testing differencesn is equal to the disparity in bin n+1, and whether this is in turn equal to the disparity in bin n+2, etc.
Because our data is temporally autocorrelated (i.e. what happens in bin n+1 depends on what happened in bin n) and pseudoreplicated (i.e. each bootstrap draw creates non-independent time subsets because they are all based on the same time subsets), we apply a non-parametric mean comparison: the wilcox.test
.
Also, we need to apply a p-value correction (e.g. Bonferroni correction) to correct for multiple testing (see ?p.adjust
for more details).
-## Testing the differences between bins in the bootstrapped dataset.
-test.dispRity(disparity, test = wilcox.test, comparison = "sequential",
-correction = "bonferroni")
+## Testing the differences between bins in the bootstrapped dataset.
+test.dispRity(disparity, test = wilcox.test, comparison = "sequential",
+ correction = "bonferroni")
## [[1]]
## statistic: W
## 100 - 80 : 80 - 60 730
@@ -661,9 +694,9 @@ 9.2.5 Testing differences
-## Testing the differences between bins in the rarefied dataset.
-test.dispRity(disparity, test = wilcox.test, comparison = "sequential",
-correction = "bonferroni", rarefaction = minimum_size)
+## Testing the differences between bins in the rarefied dataset.
+test.dispRity(disparity, test = wilcox.test, comparison = "sequential",
+ correction = "bonferroni", rarefaction = minimum_size)
## [[1]]
## statistic: W
## 100 - 80 : 80 - 60 1518
@@ -685,8 +718,8 @@ 9.2.5 Testing differences9.3 Some more advanced stuff
The previous section detailed some of the basic functionalities in the dispRity
package but of course, you can do some much more advanced analysis, here is just a list of some specific tutorials from this manual that you might be interested in:
-- Time slicing: an alternative method to look at disparity through time that allows you to specify evolutionary models (Guillerme and Cooper 2018).
-- Many more disparity metrics: there are many, many different things you might be interested to measure in your morphospace! This manual has some extended documentation on what to use (or check Thomas Guillerme, Puttick, et al. (2020)).
+- Time slicing: an alternative method to look at disparity through time that allows you to specify evolutionary models (T. Guillerme and Cooper 2018).
+- Many more disparity metrics: there are many, many different things you might be interested to measure in your morphospace! This manual has some extended documentation on what to use (or check Thomas Guillerme, Puttick, et al. (2020)).
- Many more ways to look at disparity: you can for example, use distributions rather than point estimates for your disparity metric (e.g. the variances rather than the sum of variances); or calculate disparity from non ordinated matrices or even from multiple matrices and trees.
- And finally there are much more advanced statistical tests you might be interested in using, such as the NPMANOVA, the “disparity-through-time test”, using a null model approach or some model fitting…
@@ -695,18 +728,18 @@ 9.3 Some more advanced stuff
References
-
-
-Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
+
+
+Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
-
-Guillerme, T., and N. Cooper. 2018. “Time for a Rethink: Time Sub-Sampling Methods in Disparity-Through-Time Analyses.” Palaeontology 61 (4): 481–93. https://doi.org/10.1111/pala.12364.
+
+Guillerme, T., and N. Cooper. 2018. “Time for a Rethink: Time Sub-Sampling Methods in Disparity-Through-Time Analyses.” Palaeontology 61 (4): 481–93. https://doi.org/10.1111/pala.12364.
-
-Guillerme, Thomas, Natalie Cooper, Stephen L. Brusatte, Katie E. Davis, Andrew L. Jackson, Sylvain Gerber, Anjali Goswami, et al. 2020. “Disparities in the Analysis of Morphological Disparity.” Biology Letters 16 (7): 20200199. https://doi.org/10.1098/rsbl.2020.0199.
+
+Guillerme, Thomas, Natalie Cooper, Stephen L. Brusatte, Katie E. Davis, Andrew L. Jackson, Sylvain Gerber, Anjali Goswami, et al. 2020. “Disparities in the Analysis of Morphological Disparity.” Biology Letters 16 (7): 20200199. https://doi.org/10.1098/rsbl.2020.0199.
-
-Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
+
+Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
diff --git a/inst/gitbook/_book/references-1.html b/inst/gitbook/_book/references-1.html
index a6b06355..1237e1be 100644
--- a/inst/gitbook/_book/references-1.html
+++ b/inst/gitbook/_book/references-1.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -361,75 +394,78 @@
12 References
-
-
-Aguilera, Antonio, and Ricardo Pérez-Aguila. 2004. “General N-Dimensional Rotations.” http://wscg.zcu.cz/wscg2004/Papers_2004_Short/N29.pdf.
+
+
+Aguilera, Antonio, and Ricardo Pérez-Aguila. 2004. “General n-Dimensional Rotations.” http://wscg.zcu.cz/wscg2004/Papers_2004_Short/N29.pdf.
+
+
+Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
-
-Beck, Robin M, and Michael S Lee. 2014. “Ancient Dates or Accelerated Rates? Morphological Clocks and the Antiquity of Placental Mammals.” Proceedings of the Royal Society B: Biological Sciences 281 (20141278): 1–10. https://doi.org/10.1098/rspb.2014.1278.
+
+Brazeau, Martin D, Thomas Guillerme, and Martin R Smith. 2018. “An algorithm for Morphological Phylogenetic Analysis with Inapplicable Data.” Systematic Biology 68 (4): 619–31. https://doi.org/10.1093/sysbio/syy083.
-
-Brazeau, Martin D, Thomas Guillerme, and Martin R Smith. 2018. “An algorithm for Morphological Phylogenetic Analysis with Inapplicable Data.” Systematic Biology 68 (4): 619–31. https://doi.org/10.1093/sysbio/syy083.
+
+Cooper, Natalie, Gavin H. Thomas, Chris Venditti, Andrew Meade, and Rob P. Freckleton. 2016. “A Cautionary Note on the Use of Ornstein Uhlenbeck Models in Macroevolutionary Studies.” Biological Journal of the Linnean Society 118 (1): 64–77. https://doi.org/10.1111/bij.12701.
-
-Cooper, Natalie, Gavin H. Thomas, Chris Venditti, Andrew Meade, and Rob P. Freckleton. 2016. “A Cautionary Note on the Use of Ornstein Uhlenbeck Models in Macroevolutionary Studies.” Biological Journal of the Linnean Society 118 (1): 64–77. https://doi.org/10.1111/bij.12701.
+
+Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
-
-Dı́az, Sandra, Jens Kattge, Johannes HC Cornelissen, Ian J Wright, Sandra Lavorel, Stéphane Dray, Björn Reu, et al. 2016. “The Global Spectrum of Plant Form and Function.” Nature 529 (7585): 167. http://dx.doi.org/10.1038/nature16489.
+
+E., O’Reilly Joseph, Puttick Mark N., Pisani Davide, and Donoghue Philip C. J. n.d. “Probabilistic Methods Surpass Parsimony When Assessing Clade Support in Phylogenetic Analyses of Discrete Morphological Data.” Palaeontology 61 (1): 105–18. https://doi.org/10.1111/pala.12330.
-
-E., O’Reilly Joseph, Puttick Mark N., Pisani Davide, and Donoghue Philip C. J. n.d. “Probabilistic Methods Surpass Parsimony When Assessing Clade Support in Phylogenetic Analyses of Discrete Morphological Data.” Palaeontology 61 (1): 105–18. https://doi.org/10.1111/pala.12330.
+
+Endler, John A, David A Westcott, Joah R Madden, and Tim Robson. 2005. “Animal Visual Systems and the Evolution of Color Patterns: Sensory Processing Illuminates Signal Evolution.” Evolution 59 (8): 1795–1818.
-
-Endler, John A, David A Westcott, Joah R Madden, and Tim Robson. 2005. “Animal Visual Systems and the Evolution of Color Patterns: Sensory Processing Illuminates Signal Evolution.” Evolution 59 (8): 1795–1818.
+
+FitzJohn, Richard G. 2012. “Diversitree: Comparative Phylogenetic Analyses of Diversification in R.” Methods in Ecology and Evolution 3 (6): 1084–92. https://doi.org/10.1111/j.2041-210X.2012.00234.x.
-
-FitzJohn, Richard G. 2012. “Diversitree: Comparative Phylogenetic Analyses of Diversification in R.” Methods in Ecology and Evolution 3 (6): 1084–92. https://doi.org/10.1111/j.2041-210X.2012.00234.x.
+
+Guillerme, T., and N. Cooper. 2018. “Time for a Rethink: Time Sub-Sampling Methods in Disparity-Through-Time Analyses.” Palaeontology 61 (4): 481–93. https://doi.org/10.1111/pala.12364.
-
-Guillerme, T., and N. Cooper. 2018. “Time for a Rethink: Time Sub-Sampling Methods in Disparity-Through-Time Analyses.” Palaeontology 61 (4): 481–93. https://doi.org/10.1111/pala.12364.
+
+Guillerme, Thomas, Jen A Bright, Christopher R Cooney, Emma C Hughes, Zoë K Varley, Natalie Cooper, Andrew P Beckerman, and Gavin H Thomas. 2023. “Innovation and Elaboration on the Avian Tree of Life.” Science Advances 9 (43): eadg1641.
-
-Guillerme, Thomas, and Natalie Cooper. 2016. “Effects of Missing Data on Topological Inference Using a Total Evidence Approach.” Molecular Phylogenetics and Evolution 94, Part A: 146–58. https://doi.org/http://dx.doi.org/10.1016/j.ympev.2015.08.023.
+
+Guillerme, Thomas, and Natalie Cooper. 2016. “Effects of Missing Data on Topological Inference Using a Total Evidence Approach.” Molecular Phylogenetics and Evolution 94, Part A: 146–58. https://doi.org/http://dx.doi.org/10.1016/j.ympev.2015.08.023.
-
-Guillerme, Thomas, Natalie Cooper, Stephen L. Brusatte, Katie E. Davis, Andrew L. Jackson, Sylvain Gerber, Anjali Goswami, et al. 2020. “Disparities in the Analysis of Morphological Disparity.” Biology Letters 16 (7): 20200199. https://doi.org/10.1098/rsbl.2020.0199.
+
+Guillerme, Thomas, Natalie Cooper, Stephen L. Brusatte, Katie E. Davis, Andrew L. Jackson, Sylvain Gerber, Anjali Goswami, et al. 2020. “Disparities in the Analysis of Morphological Disparity.” Biology Letters 16 (7): 20200199. https://doi.org/10.1098/rsbl.2020.0199.
-
-Guillerme, Thomas, and Kevin Healy. 2014. mulTree: a package for running MCMCglmm analysis on multiple trees. Zenodo. https://doi.org/10.5281/zenodo.12902.
+
+Guillerme, Thomas, and Kevin Healy. 2014. “mulTree: a package for running MCMCglmm analysis on multiple trees.” Zenodo. https://doi.org/10.5281/zenodo.12902.
-
-Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
+
+Guillerme, Thomas, Mark N Puttick, Ariel E Marcy, and Vera Weisbecker. 2020. “Shifting Spaces: Which Disparity or Dissimilarity Measurement Best Summarize Occupancy in Multidimensional Spaces?” Ecology and Evolution.
-
-Hadfield, Jarrod D. 2010a. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
+
+Hadfield, Jarrod D. 2010a. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
-
-———. 2010b. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
+
+———. 2010b. “MCMC Methods for Multi-Response Generalized Linear Mixed Models: The MCMCglmm R Package.” Journal of Statistical Software 33 (2): 1–22. https://www.jstatsoft.org/v33/i02/.
-
-Hasegawa, M., H. Kishino, and T. A. Yano. 1985. “Dating of the Human Ape Splitting by a Molecular Clock of Mitochondrial-DNA.” Journal of Molecular Evolution 22 (2): 160–74.
+
+Hasegawa, M., H. Kishino, and T. A. Yano. 1985. “Dating of the Human Ape Splitting by a Molecular Clock of Mitochondrial-DNA.” Journal of Molecular Evolution 22 (2): 160–74.
-
-Hunt, Gene. 2006. “Fitting and Comparing Models of Phyletic Evolution: Random Walks and Beyond.” Paleobiology 32 (4): 578–601. https://doi.org/10.1666/05070.1.
+
+Hunt, Gene. 2006. “Fitting and Comparing Models of Phyletic Evolution: Random Walks and Beyond.” Paleobiology 32 (4): 578–601. https://doi.org/10.1666/05070.1.
-
-———. 2012. “Measuring Rates of Phenotypic Evolution and the Inseparability of Tempo and Mode.” Paleobiology 38 (3): 351–73. https://doi.org/10.1666/11047.1.
+
+———. 2012. “Measuring Rates of Phenotypic Evolution and the Inseparability of Tempo and Mode.” Paleobiology 38 (3): 351–73. https://doi.org/10.1666/11047.1.
-
-Hunt, Gene, Melanie J Hopkins, and Scott Lidgard. 2015. “Simple Versus Complex Models of Trait Evolution and Stasis as a Response to Environmental Change.” Proceedings of the National Academy of Sciences, 201403662. https://doi.org/10.1073/pnas.1403662111.
+
+Hunt, Gene, Melanie J Hopkins, and Scott Lidgard. 2015. “Simple Versus Complex Models of Trait Evolution and Stasis as a Response to Environmental Change.” Proceedings of the National Academy of Sciences, 201403662. https://doi.org/10.1073/pnas.1403662111.
-
-Lewis, P. 2001. “A Likelihood Approach to Estimating Phylogeny from Discrete Morphological Character Data.” Systematic Biology 50 (6): 913–25. https://doi.org/10.1080/106351501753462876.
+
+Lewis, P. 2001. “A Likelihood Approach to Estimating Phylogeny from Discrete Morphological Character Data.” Systematic Biology 50 (6): 913–25. https://doi.org/10.1080/106351501753462876.
-
-Murrell, David J. 2018. “A Global Envelope Test to Detect Non-Random Bursts of Trait Evolution.” Methods in Ecology and Evolution 9 (7): 1739–48. https://doi.org/10.1111/2041-210X.13006.
+
+Murrell, David J. 2018. “A Global Envelope Test to Detect Non-Random Bursts of Trait Evolution.” Methods in Ecology and Evolution 9 (7): 1739–48. https://doi.org/10.1111/2041-210X.13006.
-
-O’Reilly, Joseph E., Mark N. Puttick, Luke Parry, Alastair R. Tanner, James E. Tarver, James Fleming, Davide Pisani, and Philip C. J. Donoghue. 2016. “Bayesian Methods Outperform Parsimony but at the Expense of Precision in the Estimation of Phylogeny from Discrete Morphological Data.” Biology Letters 12 (4). https://doi.org/10.1098/rsbl.2016.0081.
+
+O’Reilly, Joseph E., Mark N. Puttick, Luke Parry, Alastair R. Tanner, James E. Tarver, James Fleming, Davide Pisani, and Philip C. J. Donoghue. 2016. “Bayesian Methods Outperform Parsimony but at the Expense of Precision in the Estimation of Phylogeny from Discrete Morphological Data.” Biology Letters 12 (4). https://doi.org/10.1098/rsbl.2016.0081.
-
-Puttick, Mark N, Joseph E O’Reilly, Alastair R Tanner, James F Fleming, James Clark, Lucy Holloway, Jesus Lozano-Fernandez, et al. 2017. “Uncertain-Tree: Discriminating Among Competing Approaches to the Phylogenetic Analysis of Phenotype Data.” Proceedings of the Royal Society B 284 (1846): 20162290. http://dx.doi.org/10.1098/rspb.2016.2290.
+
+Puttick, Mark N, Joseph E O’Reilly, Alastair R Tanner, James F Fleming, James Clark, Lucy Holloway, Jesus Lozano-Fernandez, et al. 2017. “Uncertain-Tree: Discriminating Among Competing Approaches to the Phylogenetic Analysis of Phenotype Data.” Proceedings of the Royal Society B 284 (1846): 20162290. http://dx.doi.org/10.1098/rspb.2016.2290.
diff --git a/inst/gitbook/_book/references.html b/inst/gitbook/_book/references.html
index 059c785e..4bb6d2bd 100644
--- a/inst/gitbook/_book/references.html
+++ b/inst/gitbook/_book/references.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
+ - 6.10
set.root.time
+- 6.11
slice.tree
+- 6.12
slide.nodes
and remove.zero.brlen
+- 6.13
tree.age
+- 6.14
multi.ace
-- 6.13.1 Using different character tokens in different situations
-- 6.13.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.1 Using different character tokens in different situations
+- 6.14.2 Feeding the results to
char.diff
to get distance matrices
+- 6.14.3 Running ancestral states estimations for continuous characters
7 The guts of the dispRity
package
@@ -293,7 +326,7 @@
@@ -358,7 +391,7 @@
-
+
diff --git a/inst/gitbook/_book/search_index.json b/inst/gitbook/_book/search_index.json
index 4e6c08c4..63b104b3 100644
--- a/inst/gitbook/_book/search_index.json
+++ b/inst/gitbook/_book/search_index.json
@@ -1 +1 @@
-[["index.html", "dispRity R package manual 1 dispRity 1.1 What is dispRity? 1.2 Installing and running the package 1.3 Which version do I choose? 1.4 dispRity is always changing, how do I know it’s not broken? 1.5 Help 1.6 Citations", " dispRity R package manual Thomas Guillerme (guillert@tcd.ie) 2023-12-06 1 dispRity This is a package for measuring disparity (aka multidimensional space occupancy) in R. It allows users to summarise matrices as representations as multidimensional spaces into a single value or distribution describing a specific aspect of this multidimensional space (the disparity). Multidimensional spaces can be ordinated matrices from MDS, PCA, PCO, PCoA but the package is not restricted to any type of matrices! This manual is based on the version 1.7. 1.1 What is dispRity? This is a modular package for measuring disparity in R. It allows users to summarise ordinated matrices (e.g. MDS, PCA, PCO, PCoA) to perform some multidimensional analysis. Typically, these analysis are used in palaeobiology and evolutionary biology to study the changes in morphology through time. However, there are many more applications in ecology, evolution and beyond. 1.1.1 Modular? Because their exist a multitude of ways to measure disparity, each adapted to every specific question, this package uses an easy to modify modular architecture. In coding, each module is simply a function or a modification of a function that can be passed to the main functions of the package to tweak it to your proper needs! In practice, you will notice throughout this manual that some function can take other functions as arguments: the modular architecture of this package allows you to use any function for these arguments (with some restrictions explained for each specific cases). This will allow you to finely tune your multidimensional analysis to the needs of your specific question! 1.2 Installing and running the package You can install this package easily, directly from the CRAN: install.packages("dispRity") Alternatively, for the most up to data version and some functionalities not compatible with the CRAN, you can use the package through GitHub using devtool (see to CRAN or not to CRAN? for more details): ## Checking if devtools is already installed if(!require(devtools)) install.packages("devtools") ## Installing the latest released version directly from GitHub install_github("TGuillerme/dispRity", ref = "release") Note this uses the release branch (1.7). For the piping-hot (but potentially unstable) version, you can change the argument ref = release to ref = master. dispRity depends mainly on the ape package and uses functions from several other packages (ade4, geometry, grDevices, hypervolume, paleotree, snow, Claddis, geomorph and RCurl). 1.3 Which version do I choose? There are always three version of the package available: The CRAN one The GitHub release one The GitHub master one The differences between the CRAN one and the GitHub release or master ones is explained just above. For the the GitHub version, the differences are that the release one is more stable (i.e. more rarely modified) and the master one is more live one (i.e. bug fixes and new functionalities are added as they come). If you want the latest-latest version of the package I suggest using the GitHub master one, especially if you recently emailed me reporting a minor bug or wanting a new functionality! Note however that it can happen that the master version can sometimes be bugged (especially when there are major R and R packages updates), however, the status of the package state on both the release and the master version is constantly displayed on the README page of the package with the nice badges displaying these different (and constantly tested) information. 1.4 dispRity is always changing, how do I know it’s not broken? This is a really common a legitimate question in software development. Like R itself: dispRity is free software and comes with ABSOLUTELY NO WARRANTY. So you are using it at your own risk. HOWEVER, there are two points that can be used as objective-ish markers on why it’s OK to use dispRity. First, the package has been use in a number of peer reviewed publications (the majority of them independently) which could be taken as warranty. Second, I spend a lot of time and attention in making sure that every function in every version actually does what I think it is supposed to do. This is done through CI; continuous integration development, the CRAN check, and unit testing. The two first checks (CRAN and CI) ensure that the version you are using is not bugged (the CRAN check if you are using the CRAN version and the Travis CI if you are using a GitHub version). The third check, unit testing, is checking that every function is doing what it is supposed to do. For a real basic example, it is testing that the following expression should always return the same thing no matter what changes in the package. > mean(c(1,2,3)) [1] 2 Or, more formally: testthat::expect_equal(object = mean(c(1,2,3)), expected = 2) You can always access what is actually tested in the test/testthat sub-folder. For example here is how the core function dispRity is tested (through > 500 tests!). All these tests are run every time a change is made to the package and you can always see for yourself how much a single function is covered (i.e. what percentage of the function is actually covered by at least one test). You can always see the global coverage here or the specific coverage for each function here. Finally, this package is build on the shoulders of the whole open science philosophy so when bugs do occur and are caught by myself or the package users, they are quickly fixed and notified in the NEWS.md file. And all the changes to the package are public and annotated so there’s that too… 1.5 Help If you need help with the package, hopefully the following manual will be useful. However, parts of this package are still in development and some other parts are probably not covered. Thus if you have suggestions or comments on on what has already been developed or will be developed, please send me an email (guillert@tcd.ie) or if you are a GitHub user, directly create an issue on the GitHub page. 1.6 Citations To cite the package, this manual or some specific functionalities, you can use the following references: The package main paper: Guillerme T. dispRity: A modular R package for measuring disparity. Methods Ecol Evol. 2018;9:1755–1763. doi.org/10.1111/2041-210X.13022. The package manual (regularly updated!): Guillerme, T. & Cooper, N. (2018): dispRity manual. figshare. Preprint. 10.6084/m9.figshare.6187337.v1. The time-slicing method implemented in chrono.subsets (unfortunately not Open Access, but you can still get a free copy from here): Guillerme, T. and Cooper, N. (2018), Time for a rethink: time sub-sampling methods in disparity-through-time analyses. Palaeontology, 61: 481-493. doi:10.1111/pala.12364. Furthermore, don’t forget to cite R: R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/. Bonus: you can also cite ape since the dispRity package heavily relies on it: Paradis E. & Schliep K. 2019. ape 5.0: an environment for modern phylogenetics and evolutionary analyses in R. Bioinformatics 35: 526-528. 1.6.1 Why is it important to cite us? Aside from how science works (if you’re using a method from a specific paper, cite that specific paper to refer to that specific method), why is it important to also cite the package and the manual? All the people involve in making the dispRity package happened to do it enthusiastically, freely and most amazingly without asking anything in return! I created the package with this idea in mind and I am still sticking to it. However, academia (the institutions and people producing science around the globe) is unfortunately not optimal at many level (some might even say “broken”): high impact papers attract big grants that attract high impact papers and big grants again, all this along with livelihood, permanent position and job security. Unfortunately however, method development has a hard time to catch up with the current publish or perish system: constantly updating the dispRity package and this manual is hugely time consuming (but really fun!) and that is not even taking into account maintenance and helping users. Although I do truly believe that this time spent doing these things modestly help the scientific endeavour, it does not contribute to our paper list! Therefore, by citing the package and this manual, you help provide visibility to other workers and you might help them in their work! And you directly contribute in making this project fun for all the people involved and most of all, free, updated and independent from the publish and perish system! Thank you! "],["glossary.html", "2 Glossary 2.1 Glossary equivalences in palaeobiology and ecology", " 2 Glossary Multidimensional space (or just space). The mathematical multidimensional object that will be analysed with this package. In morphometrics, this is often referred to as the morphospace. However it may also be referred to as the cladisto-space for cladistic data or the eco-space for ecological data etc. In practice, this term designates a matrix where the columns represent the dimensions of the space (often – but not necessarily - > 3!) and the rows represent the elements within this space. Elements. The rows of the multidimensional space matrix. Elements can be taxa, field sites, countries etc. Dimensions. The columns of the multidimensional space matrix. The dimensions can be referred to as axes of variation, or principal components, for ordinated spaces obtained from a PCA for example. Subsets. Subsets of the multidimensional space. A subset (or subsets) contains the same number of dimensions as the space but may contain a smaller subset of elements. For example, if our space is composed of birds and mammals (the elements) and 50 principal components of variation (the dimensions), we can create two subsets containing just mammals or birds, but with the same 50 dimensions, to compare disparity in the two clades. Disparity. A metric expressing the similarities/dissimilarities of the elements within the space or a summarising the space dimensions. For example the pairwise distances between elements or the range of each dimensions. 2.1 Glossary equivalences in palaeobiology and ecology In this manual In dispRity E.g. in palaeobiology E.g. in ecology the multidimensional space a matrix object (\\(n\\times d\\)) a morphospace a function-space elements rows (\\(n\\)) taxa field experiments dimensions columns (\\(d\\)) morphological characters communities’ compositions subsets a matrix (\\(m \\times d\\), with \\(m \\leq n\\)) time series experimental treatments disparity a function sum of variances ellipsoid volume "],["getting-started-with-disprity.html", "3 Getting started with dispRity 3.1 What sort of data does dispRity work with? 3.2 Ordinated matrices 3.3 Performing a simple dispRity analysis", " 3 Getting started with dispRity 3.1 What sort of data does dispRity work with? Any matrix object in R. Disparity can be estimated from pretty much any matrix as long as rows represent the elements and columns the dimensions. These matrices can be observations, pairwise differences between elements, ordinations, etc… Since version 1.4 it is also possible to include a \"list\" containing matrices. These matrices need to have the same dimensions and rownames but can contain different values. This is especially useful for modelling uncertainty (see here for more details). 3.2 Ordinated matrices Classically, when a high number of variables is used, disparity is calculated from ordinated matrices. These can be any type of ordinations (PCO, PCA, PCoA, MDS, etc.) as long as elements are the rows (taxa, countries, field experiments) and the dimensions are the columns. However, note that this is not required from any of the functions in this package. You can also use distance matrices or any other matrix type that suits your question and your analysis! 3.2.1 Ordination matrices from geomorph You can also easily use data from geomorph using the geomorph.ordination function. This function simply takes Procrustes aligned data and performs an ordination: require(geomorph) ## Loading the plethodon dataset data(plethodon) ## Performing a Procrustes transform on the landmarks procrustes <- gpagen(plethodon$land, PrinAxes = FALSE, print.progress = FALSE) ## Ordinating this data geomorph.ordination(procrustes)[1:5,1:5] ## PC1 PC2 PC3 PC4 PC5 ## [1,] -0.0369930887 0.05118246 -0.0016971586 -0.003128881 -0.010935739 ## [2,] -0.0007493689 0.05942083 0.0001371682 -0.002768621 -0.008117767 ## [3,] 0.0056004751 0.07419599 -0.0052612189 -0.005034502 -0.002747104 ## [4,] -0.0134808326 0.06463958 -0.0458436274 -0.007887336 0.009817034 ## [5,] -0.0334696064 0.06863518 0.0136292227 0.007359383 0.022347215 Options for the ordination (from ?prcomp) can be directly passed to this function to perform customised ordinations. Additionally you can give the function a geomorph.data.frame object. If the latter contains sorting information (i.e. factors), they can be directly used to make a customised dispRity object customised dispRity object! ## Using a geomorph.data.frame geomorph_df <- geomorph.data.frame(procrustes, species = plethodon$species, site = plethodon$site) ## Ordinating this data and making a dispRity object geomorph.ordination(geomorph_df) ## ---- dispRity object ---- ## 4 customised subsets for 40 elements in one matrix: ## species.Jord, species.Teyah, site.Allo, site.Symp. More about these dispRity objects below! 3.2.2 Ordination matrices from Claddis dispRity package can also easily take data from the Claddis package using the Claddis.ordination function. For this, simply input a matrix in the Claddis format to the function and it will automatically calculate and ordinate the distances among taxa: require(Claddis) ## Ordinating the example data from Claddis Claddis.ordination(michaux_1989) ## [,1] [,2] [,3] ## Ancilla 0.000000e+00 4.154578e-01 0.2534942 ## Turrancilla -5.106645e-01 -1.304614e-16 -0.2534942 ## Ancillista 5.106645e-01 -1.630768e-17 -0.2534942 ## Amalda 1.603581e-16 -4.154578e-01 0.2534942 Note that several options are available, namely which type of distance should be computed. See more info in the function manual (?Claddis.ordination). Alternatively, it is of course also possible to manual calculate the ordination matrix using the functions Claddis::calculate_morphological_distances and stats::cmdscale. 3.2.3 Other kinds of ordination matrices If you are not using the packages mentioned above (Claddis and geomorph) you can easily make your own ordination matrices by using the following functions from the stats package. Here is how to do it for the following types of matrices: Multivariate matrices (principal components analysis; PCA) ## A multivariate matrix head(USArrests) ## Murder Assault UrbanPop Rape ## Alabama 13.2 236 58 21.2 ## Alaska 10.0 263 48 44.5 ## Arizona 8.1 294 80 31.0 ## Arkansas 8.8 190 50 19.5 ## California 9.0 276 91 40.6 ## Colorado 7.9 204 78 38.7 ## Ordinating the matrix using `prcomp` ordination <- prcomp(USArrests) ## Selecting the ordinated matrix ordinated_matrix <- ordination$x head(ordinated_matrix) ## PC1 PC2 PC3 PC4 ## Alabama 64.80216 -11.448007 -2.4949328 -2.4079009 ## Alaska 92.82745 -17.982943 20.1265749 4.0940470 ## Arizona 124.06822 8.830403 -1.6874484 4.3536852 ## Arkansas 18.34004 -16.703911 0.2101894 0.5209936 ## California 107.42295 22.520070 6.7458730 2.8118259 ## Colorado 34.97599 13.719584 12.2793628 1.7214637 This results in a ordinated matrix with US states as elements and four dimensions (PC 1 to 4). For an alternative method, see the ?princomp function. Distance matrices (classical multidimensional scaling; MDS) ## A matrix of distances between cities str(eurodist) ## 'dist' num [1:210] 3313 2963 3175 3339 2762 ... ## - attr(*, "Size")= num 21 ## - attr(*, "Labels")= chr [1:21] "Athens" "Barcelona" "Brussels" "Calais" ... ## Ordinating the matrix using cmdscale() with k = 5 dimensions ordinated_matrix <- cmdscale(eurodist, k = 5) head(ordinated_matrix) ## [,1] [,2] [,3] [,4] [,5] ## Athens 2290.27468 1798.8029 53.79314 -103.82696 -156.95511 ## Barcelona -825.38279 546.8115 -113.85842 84.58583 291.44076 ## Brussels 59.18334 -367.0814 177.55291 38.79751 -95.62045 ## Calais -82.84597 -429.9147 300.19274 106.35369 -180.44614 ## Cherbourg -352.49943 -290.9084 457.35294 111.44915 -417.49668 ## Cologne 293.68963 -405.3119 360.09323 -636.20238 159.39266 This results in a ordinated matrix with European cities as elements and five dimensions. Of course any other method for creating the ordination matrix is totally valid, you can also not use any ordination at all! The only requirements for the dispRity functions is that the input is a matrix with elements as rows and dimensions as columns. 3.3 Performing a simple dispRity analysis Two dispRity functions allow users to run an analysis pipeline simply by inputting an ordination matrix. These functions allow users to either calculate the disparity through time (dispRity.through.time) or the disparity of user-defined groups (dispRity.per.group). IMPORTANT Note that disparity.through.time and disparity.per.group are wrapper functions (i.e. they incorporate lots of other functions) that allow users to run a basic disparity-through-time, or disparity among groups, analysis without too much effort. As such they use a lot of default options. These are described in the help files for the functions that are used to make the wrapper functions, and not described in the help files for disparity.through.time and disparity.per.group. These defaults are good enough for data exploration, but for a proper analysis you should consider the best parameters for your question and data. For example, which metric should you use? How many bootstraps do you require? What model of evolution is most appropriate if you are time slicing? Should you rarefy the data? See chrono.subsets, custom.subsets, boot.matrix and dispRity.metric for more details of the defaults used in each of these functions. Note that any of these default arguments can be changed within the disparity.through.time or disparity.per.group functions. 3.3.1 Example data To illustrate these functions, we will use data from Beck and Lee (2014). This dataset contains an ordinated matrix of 50 discrete characters from mammals (BeckLee_mat50), another matrix of the same 50 mammals and the estimated discrete data characters of their descendants (thus 50 + 49 rows, BeckLee_mat99), a dataframe containing the ages of each taxon in the dataset (BeckLee_ages) and finally a phylogenetic tree with the relationships among the 50 mammals (BeckLee_tree). ## Loading the ordinated matrices data(BeckLee_mat50) data(BeckLee_mat99) ## The first five taxa and dimensions of the 50 taxa matrix head(BeckLee_mat50[, 1:5]) ## [,1] [,2] [,3] [,4] [,5] ## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039 ## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479 ## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646 ## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626 ## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914 ## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351 ## The first five taxa and dimensions of the 99 taxa + ancestors matrix BeckLee_mat99[c(1, 2, 98, 99), 1:5] ## [,1] [,2] [,3] [,4] [,5] ## Cimolestes -0.6794737 0.15658591 0.04918307 0.22509831 -0.38139436 ## Maelestes -0.5797289 0.04223105 -0.20329542 -0.15453876 -0.06993258 ## n48 0.2614394 0.01712426 0.21997583 -0.05383777 0.07919679 ## n49 0.3881123 0.13771446 0.11966941 0.01856597 -0.15263921 ## Loading a list of first and last occurrence dates for the fossils data(BeckLee_ages) head(BeckLee_ages) ## FAD LAD ## Adapis 37.2 36.8 ## Asioryctes 83.6 72.1 ## Leptictis 33.9 33.3 ## Miacis 49.0 46.7 ## Mimotona 61.6 59.2 ## Notharctus 50.2 47.0 ## Loading and plotting the phylogeny data(BeckLee_tree) plot(BeckLee_tree, cex = 0.8) axisPhylo(root = 140) nodelabels(cex = 0.5) Of course you can use your own data as detailed in the previous section. 3.3.2 Disparity through time The dispRity.through.time function calculates disparity through time, a common analysis in palaeontology. This function (and the following one) uses an analysis pipeline with a lot of default parameters to make the analysis as simple as possible. Of course all the defaults can be changed if required, more on this later. For a disparity through time analysis, you will need: An ordinated matrix (we covered that above) A phylogenetic tree: this must be a phylo object (from the ape package) and needs a root.time element. To give your tree a root time (i.e. an age for the root), you can simply do\\ my_tree$root.time <- my_age. The required number of time subsets (here time = 3) Your favourite disparity metric (here the sum of variances) Using the Beck and Lee (2014) data described above: ## Measuring disparity through time disparity_data <- dispRity.through.time(BeckLee_mat50, BeckLee_tree, metric = c(sum, variances), time = 3) This generates a dispRity object (see here for technical details). When displayed, these dispRity objects provide us with information on the operations done to the matrix: ## Print the disparity_data object disparity_data ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 48 dimensions with 1 phylogenetic tree ## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0. ## Data was bootstrapped 100 times (method:"full"). ## Disparity was calculated as: metric. We asked for three subsets (evenly spread across the age of the tree), the data was bootstrapped 100 times (default) and the metric used was the sum of variances. We can now summarise or plot the disparity_data object, or perform statistical tests on it (e.g. a simple lm): ## Summarising disparity through time summary(disparity_data) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 133.51 - 89.01 5 2.123 1.775 1.017 1.496 1.942 2.123 ## 2 89.01 - 44.5 29 2.456 2.384 2.295 2.350 2.404 2.427 ## 3 44.5 - 0 16 2.528 2.363 2.213 2.325 2.406 2.466 ## Plotting the results plot(disparity_data, type = "continuous") ## Testing for an difference among the time bins disp_lm <- test.dispRity(disparity_data, test = lm, comparisons = "all") summary(disp_lm) ## ## Call: ## test(formula = data ~ subsets, data = data) ## ## Residuals: ## Min 1Q Median 3Q Max ## -0.87430 -0.04100 0.01456 0.05318 0.41059 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 1.71217 0.01703 100.55 <2e-16 *** ## subsets44.5 - 0 0.64824 0.02408 26.92 <2e-16 *** ## subsets89.01 - 44.5 0.66298 0.02408 27.53 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 0.1703 on 297 degrees of freedom ## Multiple R-squared: 0.769, Adjusted R-squared: 0.7674 ## F-statistic: 494.3 on 2 and 297 DF, p-value: < 2.2e-16 Please refer to the specific tutorials for (much!) more information on the nuts and bolts of the package. You can also directly explore the specific function help files within R and navigate to related functions. 3.3.3 Disparity among groups The dispRity.per.group function is used if you are interested in looking at disparity among groups rather than through time. For example, you could ask if there is a difference in disparity between two groups? To perform such an analysis, you will need: An matrix with rows as elements and columns as dimensions (always!) A list of group members: this list should be a list of numeric vectors or names corresponding to the row names in the matrix. For example list(\"A\" = c(1,2), \"B\" = c(3,4)) will create a group A containing elements 1 and 2 from the matrix and a group B containing elements 3 and 4. Note that elements can be present in multiple groups at once. Your favourite disparity metric (here the sum of variances) Using the Beck and Lee (2014) data described above: ## Creating the two groups (crown versus stem) as a list mammal_groups <- crown.stem(BeckLee_tree, inc.nodes = FALSE) ## Measuring disparity for each group disparity_data <- dispRity.per.group(BeckLee_mat50, group = mammal_groups, metric = c(sum, variances)) We can display the disparity of both groups by simply looking at the output variable (disparity_data) and then summarising the disparity_data object and plotting it, and/or by performing a statistical test to compare disparity across the groups (here a Wilcoxon test). ## Print the disparity_data object disparity_data ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 48 dimensions: ## crown, stem. ## Data was bootstrapped 100 times (method:"full"). ## Disparity was calculated as: metric. ## Summarising disparity in the different groups summary(disparity_data) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 crown 30 2.526 2.446 2.380 2.429 2.467 2.498 ## 2 stem 20 2.244 2.134 2.025 2.105 2.164 2.208 ## Plotting the results plot(disparity_data) ## Testing for a difference between the groups test.dispRity(disparity_data, test = wilcox.test, details = TRUE) ## $`crown : stem` ## $`crown : stem`[[1]] ## ## Wilcoxon rank sum test with continuity correction ## ## data: dots[[1L]][[1L]] and dots[[2L]][[1L]] ## W = 10000, p-value < 2.2e-16 ## alternative hypothesis: true location shift is not equal to 0 References "],["details-of-specific-functions.html", "4 Details of specific functions 4.1 Time slicing 4.2 Customised subsets 4.3 Bootstraps and rarefactions 4.4 Disparity metrics 4.5 Summarising dispRity data (plots) 4.6 Testing disparity hypotheses 4.7 Fitting modes of evolution to disparity data 4.8 Disparity as a distribution 4.9 Disparity from other matrices 4.10 Disparity from multiple matrices (and multiple trees!) 4.11 Disparity with trees: dispRitree! 4.12 Disparity of variance-covariance matrices (covar)", " 4 Details of specific functions The following section contains information specific to some functions. If any of your questions are not covered in these sections, please refer to the function help files in R, send me an email (guillert@tcd.ie), or raise an issue on GitHub. The several tutorials below describe specific functionalities of certain functions; please always refer to the function help files for the full function documentation! Before each section, make sure you loaded the Beck and Lee (2014) data (see example data for more details). ## Loading the data data(BeckLee_mat50) data(BeckLee_mat99) data(BeckLee_tree) data(BeckLee_ages) 4.1 Time slicing The function chrono.subsets allows users to divide the matrix into different time subsets or slices given a dated phylogeny that contains all the elements (i.e. taxa) from the matrix. Each subset generated by this function will then contain all the elements present at a specific point in time or during a specific period in time. Two types of time subsets can be performed by using the method option: Discrete time subsets (or time-binning) using method = discrete Continuous time subsets (or time-slicing) using method = continuous For the time-slicing method details see Guillerme and Cooper (2018). For both methods, the function takes the time argument which can be a vector of numeric values for: Defining the boundaries of the time bins (when method = discrete) Defining the time slices (when method = continuous) Otherwise, the time argument can be set as a single numeric value for automatically generating a given number of equidistant time-bins/slices. Additionally, it is also possible to input a dataframe containing the first and last occurrence data (FAD/LAD) for taxa that span over a longer time than the given tips/nodes age, so taxa can appear in more than one time bin/slice. 4.1.1 Time-binning Here is an example for the time binning method (method = discrete): ## Generating three time bins containing the taxa present every 40 Ma chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree, method = "discrete", time = c(120, 80, 40, 0)) ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 120 - 80, 80 - 40, 40 - 0. Note that we can also generate equivalent results by just telling the function that we want three time-bins as follow: ## Automatically generate three equal length bins: chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree, method = "discrete", time = 3) ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0. In this example, the taxa were split inside each time-bin according to their age. However, the taxa here are considered as single points in time. It is totally possible that some taxa could have had longer longevity and that they exist in multiple time bins. In this case, it is possible to include them in more than one bin by providing a table of first and last occurrence dates (FAD/LAD). This table should have the taxa names as row names and two columns for respectively the first and last occurrence age: ## Displaying the table of first and last occurrence dates ## for each taxa head(BeckLee_ages) ## FAD LAD ## Adapis 37.2 36.8 ## Asioryctes 83.6 72.1 ## Leptictis 33.9 33.3 ## Miacis 49.0 46.7 ## Mimotona 61.6 59.2 ## Notharctus 50.2 47.0 ## Generating time bins including taxa that might span between them chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree, method = "discrete", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 120 - 80, 80 - 40, 40 - 0. When using this method, the oldest boundary of the first bin (or the first slice, see below) is automatically generated as the root age plus 1% of the tree length, as long as at least three elements/taxa are present at that point in time. The algorithm adds an extra 1% tree length until reaching the required minimum of three elements. It is also possible to include nodes in each bin by using inc.nodes = TRUE and providing a matrix that contains the ordinated distance among tips and nodes. If you want to generate time subsets based on stratigraphy, the package proposes a useful functions to do it for you: get.bin.ages (check out the function’s manual in R)! 4.1.2 Time-slicing For the time-slicing method (method = continuous), the idea is fairly similar. This option, however, requires a matrix that contains the ordinated distance among taxa and nodes and an extra argument describing the assumed evolutionary model (via the model argument). This model argument is used when the time slice occurs along a branch of the tree rather than on a tip or a node, meaning that a decision must be made about what the value for the branch should be. The model can be one of the following: Punctuated models acctran where the data chosen along the branch is always the one of the descendant deltran where the data chosen along the branch is always the one of the ancestor random where the data chosen along the branch is randomly chosen between the descendant or the ancestor proximity where the data chosen along the branch is either the descendant or the ancestor depending on branch length Gradual models equal.split where the data chosen along the branch is both the descendant and the ancestor with an even probability gradual.split where the data chosen along the branch is both the descendant and the ancestor with a probability depending on branch length Note that the four first models are a proxy for punctuated evolution: the selected data is always either the one of the descendant or the ancestor. In other words, changes along the branches always occur at either ends of it. The two last models are a proxy for gradual evolution: the data from both the descendant and the ancestor is used with an associate probability. These later models perform better when bootstrapped, effectively approximating the “intermediate” state between and the ancestor and the descendants. More details about the differences between these methods can be found in Guillerme and Cooper (2018). ## Generating four time slices every 40 million years ## under a model of proximity evolution chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 1 phylogenetic tree ## 120, 80, 40, 0. ## Generating four time slices automatically chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = 4, FADLAD = BeckLee_ages) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 1 phylogenetic tree ## 133.51, 89.01, 44.5, 0. 4.2 Customised subsets Another way of separating elements into different categories is to use customised subsets as briefly explained above. This function simply takes the list of elements to put in each group (whether they are the actual element names or their position in the matrix). ## Creating the two groups (crown and stems) mammal_groups <- crown.stem(BeckLee_tree, inc.nodes = FALSE) ## Separating the dataset into two different groups custom.subsets(BeckLee_mat50, group = mammal_groups) ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix: ## crown, stem. Like in this example, you can use the utility function crown.stem that allows to automatically separate the crown and stems taxa given a phylogenetic tree. Also, elements can easily be assigned to different groups if necessary! ## Creating the three groups as a list weird_groups <- list("even" = seq(from = 1, to = 49, by = 2), "odd" = seq(from = 2, to = 50, by = 2), "all" = c(1:50)) The custom.subsets function can also take a phylogeny (as a phylo object) as an argument to create groups as clades: ## Creating groups as clades custom.subsets(BeckLee_mat50, group = BeckLee_tree) This automatically creates 49 (the number of nodes) groups containing between two and 50 (the number of tips) elements. 4.3 Bootstraps and rarefactions One important step in analysing ordinated matrices is to pseudo-replicate the data to see how robust the results are, and how sensitive they are to outliers in the dataset. This can be achieved using the function boot.matrix to bootstrap and/or rarefy the data. The default options will bootstrap the matrix 100 times without rarefaction using the “full” bootstrap method (see below): ## Default bootstrapping boot.matrix(data = BeckLee_mat50) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Data was bootstrapped 100 times (method:"full"). The number of bootstrap replicates can be defined using the bootstraps option. The method can be modified by controlling which bootstrap algorithm to use through the boot.type argument. Currently two algorithms are implemented: \"full\" where the bootstrapping is entirely stochastic (n elements are replaced by any m elements drawn from the data) \"single\" where only one random element is replaced by one other random element for each pseudo-replicate \"null\" where every element is resampled across the whole matrix (not just the subsets). I.e. for each subset of n elements, this algorithm resamples n elements across ALL subsets (not just the current one). If only one subset (or none) is used, this does the same as the \"full\" algorithm. ## Bootstrapping with the single bootstrap method boot.matrix(BeckLee_mat50, boot.type = "single") ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Data was bootstrapped 100 times (method:"single"). This function also allows users to rarefy the data using the rarefaction argument. Rarefaction allows users to limit the number of elements to be drawn at each bootstrap replication. This is useful if, for example, one is interested in looking at the effect of reducing the number of elements on the results of an analysis. This can be achieved by using the rarefaction option that draws only n-x at each bootstrap replicate (where x is the number of elements not sampled). The default argument is FALSE but it can be set to TRUE to fully rarefy the data (i.e. remove x elements for the number of pseudo-replicates, where x varies from the maximum number of elements present in each subset to a minimum of three elements). It can also be set to one or more numeric values to only rarefy to the corresponding number of elements. ## Bootstrapping with the full rarefaction boot.matrix(BeckLee_mat50, bootstraps = 20, rarefaction = TRUE) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Data was bootstrapped 20 times (method:"full") and fully rarefied. ## Or with a set number of rarefaction levels boot.matrix(BeckLee_mat50, bootstraps = 20, rarefaction = c(6:8, 3)) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Data was bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements. Note that using the rarefaction argument also bootstraps the data. In these examples, the function bootstraps the data (without rarefaction) AND also bootstraps the data with the different rarefaction levels. One other argument is dimensions that specifies how many dimensions from the matrix should be used for further analysis. When missing, all dimensions from the ordinated matrix are used. ## Using the first 50% of the dimensions boot.matrix(BeckLee_mat50, dimensions = 0.5) ## ---- dispRity object ---- ## 50 elements in one matrix with 24 dimensions. ## Data was bootstrapped 100 times (method:"full"). ## Using the first 10 dimensions boot.matrix(BeckLee_mat50, dimensions = 10) ## ---- dispRity object ---- ## 50 elements in one matrix with 1 dimensions. ## Data was bootstrapped 100 times (method:"full"). It is also possible to specify the sampling probability in the bootstrap for each elements. This can be useful for weighting analysis for example (i.e. giving more importance to specific elements). These probabilities can be passed to the prob argument individually with a vector with the elements names or with a matrix with the rownames as elements names. The elements with no specified probability will be assigned a probability of 1 (or 1/maximum weight if the argument is weights rather than probabilities). ## Attributing a weight of 0 to Cimolestes and 10 to Maelestes boot.matrix(BeckLee_mat50, prob = c("Cimolestes" = 0, "Maelestes" = 10)) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Data was bootstrapped 100 times (method:"full"). Of course, one could directly supply the subsets generated above (using chrono.subsets or custom.subsets) to this function. ## Creating subsets of crown and stem mammals crown_stem <- custom.subsets(BeckLee_mat50, group = crown.stem(BeckLee_tree, inc.nodes = FALSE)) ## Bootstrapping and rarefying these groups boot.matrix(crown_stem, bootstraps = 200, rarefaction = TRUE) ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 48 dimensions: ## crown, stem. ## Data was bootstrapped 200 times (method:"full") and fully rarefied. ## Creating time slice subsets time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## Bootstrapping the time slice subsets boot.matrix(time_slices, bootstraps = 100) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 120, 80, 40, 0. ## Data was bootstrapped 100 times (method:"full"). 4.4 Disparity metrics There are many ways of measuring disparity! In brief, disparity is a summary metric that will represent an aspect of an ordinated space (e.g. a MDS, PCA, PCO, PCoA). For example, one can look at ellipsoid hyper-volume of the ordinated space (Donohue et al. 2013), the sum and the product of the ranges and variances (Wills et al. 1994) or the median position of the elements relative to their centroid (Wills et al. 1994). Of course, there are many more examples of metrics one can use for describing some aspect of the ordinated space, with some performing better than other ones at particular descriptive tasks, and some being more generalist. Check out this paper on selecting the best metric for your specific question in Ecology and Evolution. You can also use the moms shiny app to test which metric captures which aspect of traitspace occupancy regarding your specific space and your specific question. Regardless, and because of this great diversity of metrics, the package dispRity does not have one way to measure disparity but rather proposes to facilitate users in defining their own disparity metric that will best suit their particular analysis. In fact, the core function of the package, dispRity, allows the user to define any metric with the metric argument. However the metric argument has to follow certain rules: It must be composed from one to three function objects; The function(s) must take as a first argument a matrix or a vector; The function(s) must be of one of the three dimension-levels described below; At least one of the functions must be of dimension-level 1 or 2 (see below). 4.4.1 The function dimension-levels The metric function dimension-levels determine the “dimensionality of decomposition” of the input matrix. In other words, each dimension-level designates the dimensions of the output, i.e. either three (a matrix); two (a vector); or one (a single numeric value) dimension. Illustration of the different dimension-levels of functions with an input matrix 4.4.1.1 Dimension-level 1 functions A dimension-level 1 function will decompose a matrix or a vector into a single value: ## Creating a dummy matrix dummy_matrix <- matrix(rnorm(12), 4, 3) ## Example of dimension-level 1 functions mean(dummy_matrix) ## [1] 0.1012674 median(dummy_matrix) ## [1] 0.3345108 Any summary metric such as mean or median are good examples of dimension-level 1 functions as they reduce the matrix to a single dimension (i.e. one value). 4.4.1.2 Dimension-level 2 functions A dimension-level 2 function will decompose a matrix into a vector. ## Defining the function as the product of rows prod.rows <- function(matrix) apply(matrix, 1, prod) ## A dimension-level 2 metric prod.rows(dummy_matrix) ## [1] 0.72217818 2.48612354 -0.08986575 0.58266449 Several dimension-level 2 functions are implemented in dispRity (see ?dispRity.metric) such as the variances or ranges functions that calculate the variance or the range of each dimension of the ordinated matrix respectively. 4.4.1.3 Dimension-level 3 functions Finally a dimension-level 3 function will transform the matrix into another matrix. Note that the dimension of the output matrix doesn’t need to match the the input matrix: ## A dimension-level 3 metric var(dummy_matrix) ## [,1] [,2] [,3] ## [1,] 1.8570383 0.7417569 -0.5131686 ## [2,] 0.7417569 1.3194330 -1.5344429 ## [3,] -0.5131686 -1.5344429 2.8070556 ## A dimension-level 3 metric with a forced matrix output as.matrix(dist(dummy_matrix)) ## 1 2 3 4 ## 1 0.000000 4.794738 3.382990 3.297110 ## 2 4.794738 0.000000 2.400321 3.993864 ## 3 3.382990 2.400321 0.000000 2.187412 ## 4 3.297110 3.993864 2.187412 0.000000 4.4.2 Between groups metrics One specific category of metrics in the dispRity package is the between groups metrics. As the name suggest, these metrics can be used to calculate the disparity between groups rather than within the groups. These metrics follow the same classifications as the “normal” (within group) metrics with dimension-level 1, 2 and 3 between groups metrics. However, at the difference of the “normal” metrics, their input arguments must be matrix and matrix2 (and of course any other additional arguments). For example, this metric measures the difference in mean between two matrices: ## A simple example mean.difference <- function(matrix, matrix2) { mean(matrix) - mean(matrix2) } You can find the list of implemented between groups metric here or design them yourself for your specific needs (potentially using make.metric for help). The function works by simply using the two available matrices, with no restriction in terms of dimensions (although you’d probably want both matrices to have the same number of dimensions) ## A second matrix dummy_matrix2 <- matrix(runif(12), 4, 3) ## The difference between groups mean.difference(dummy_matrix, dummy_matrix2) ## [1] -0.3194556 Beyond this super simple example, it might probably be interesting to use this metric on dispRity objects, especially the ones from custom.subsets and chrono.subsets. In fact, the dispRity function allows to apply the between groups metric directly to the dispRity objects using the between.groups = TRUE option. For example: ## Combining both matrices big_matrix <- rbind(dummy_matrix, dummy_matrix2) rownames(big_matrix) <- 1:8 ## Making a dispRity object with both groups grouped_matrix <- custom.subsets(big_matrix, group = c(list(1:4), list(1:4))) ## Calculating the mean difference between groups (mean_differences <- dispRity(grouped_matrix, metric = mean.difference, between.groups = TRUE)) ## ---- dispRity object ---- ## 2 customised subsets for 8 elements in one matrix with 3 dimensions: ## 1, 2. ## Disparity was calculated as: mean.difference between groups. ## Summarising the object summary(mean_differences) ## subsets n_1 n_2 obs ## 1 1:2 4 4 0 ## Note how the summary table now indicates ## the number of elements for each group For dispRity objects generated by custom.subsets, the dispRity function will by default apply the metric on the groups in a pairwise fashion. For example, if the object contains multiple groups, all groups will be compared to each other: ## A dispRity object with multiple groups grouped_matrix <- custom.subsets(big_matrix, group = c("A" = list(1:4), "B" = list(1:4), "C" = list(2:6), "D" = list(1:8))) ## Measuring disparity between all groups summary(dispRity(grouped_matrix, metric = mean.difference, between.groups = TRUE)) ## subsets n_1 n_2 obs ## 1 A:B 4 4 0.000 ## 2 A:C 4 5 -0.172 ## 3 A:D 4 8 -0.160 ## 4 B:C 4 5 -0.172 ## 5 B:D 4 8 -0.160 ## 6 C:D 5 8 0.012 For dispRity objects generated by chrono.subsets (not shown here), the dispRity function will by default apply the metric on the groups in a serial way (group 1 vs. group 2, group 2 vs. group 3, group 3 vs. group 4, etc…). However, in both cases (for objects from custom.subsets or chrono.subsets) it is possible to manually specific the list of pairs of comparisons through their ID numbers: ## Measuring disparity between specific groups summary(dispRity(grouped_matrix, metric = mean.difference, between.groups = list(c(1,3), c(3,1), c(4,1)))) ## subsets n_1 n_2 obs ## 1 A:C 4 5 -0.172 ## 2 C:A 5 4 0.172 ## 3 D:A 8 4 0.160 Note that in any case, the order of the comparison can matter. In our example, it is obvious that mean(matrix) - mean(matrix2) is not the same as mean(matrix2) - mean(matrix). 4.4.3 make.metric Of course, functions can be more complex and involve multiple operations such as the centroids function (see ?dispRity.metric) that calculates the Euclidean distance between each element and the centroid of the ordinated space. The make.metric function implemented in dispRity is designed to help test and find the dimension-level of the functions. This function tests: If your function can deal with a matrix or a vector as an input; Your function’s dimension-level according to its output (dimension-level 1, 2 or 3, see above); Whether the function can be implemented in the dispRity function (the function is fed into a lapply loop). For example, let’s see if the functions described above are the right dimension-levels: ## Which dimension-level is the mean function? ## And can it be used in dispRity? make.metric(mean) ## mean outputs a single value. ## mean is detected as being a dimension-level 1 function. ## Which dimension-level is the prod.rows function? ## And can it be used in dispRity? make.metric(prod.rows) ## prod.rows outputs a matrix object. ## prod.rows is detected as being a dimension-level 2 function. ## Which dimension-level is the var function? ## And can it be used in dispRity? make.metric(var) ## var outputs a matrix object. ## var is detected as being a dimension-level 3 function. ## Additional dimension-level 2 and/or 1 function(s) will be needed. A non verbose version of the function is also available. This can be done using the option silent = TRUE and will simply output the dimension-level of the metric. ## Testing whether mean is dimension-level 1 if(make.metric(mean, silent = TRUE)$type != "level1") { message("The metric is not dimension-level 1.") } ## Testing whether var is dimension-level 1 if(make.metric(var, silent = TRUE)$type != "level1") { message("The metric is not dimension-level 1.") } ## The metric is not dimension-level 1. 4.4.4 Metrics in the dispRity function Using this metric structure, we can easily use any disparity metric in the dispRity function as follows: ## Measuring disparity as the standard deviation ## of all the values of the ## ordinated matrix (dimension-level 1 function). summary(dispRity(BeckLee_mat50, metric = sd)) ## subsets n obs ## 1 1 50 0.227 ## Measuring disparity as the standard deviation ## of the variance of each axis of ## the ordinated matrix (dimension-level 1 and 2 functions). summary(dispRity(BeckLee_mat50, metric = c(sd, variances))) ## subsets n obs ## 1 1 50 0.032 ## Measuring disparity as the standard deviation ## of the variance of each axis of ## the variance covariance matrix (dimension-level 1, 2 and 3 functions). summary(dispRity(BeckLee_mat50, metric = c(sd, variances, var)), round = 10) ## subsets n obs ## 1 1 50 0 Note that the order of each function in the metric argument does not matter, the dispRity function will automatically detect the function dimension-levels (using make.metric) and apply them to the data in decreasing order (dimension-level 3 > 2 > 1). ## Disparity as the standard deviation of the variance of each axis of the ## variance covariance matrix: disparity1 <- summary(dispRity(BeckLee_mat50, metric = c(sd, variances, var)), round = 10) ## Same as above but using a different function order for the metric argument disparity2 <- summary(dispRity(BeckLee_mat50, metric = c(variances, sd, var)), round = 10) ## Both ways output the same disparity values: disparity1 == disparity2 ## subsets n obs ## [1,] TRUE TRUE TRUE In these examples, we considered disparity to be a single value. For example, in the previous example, we defined disparity as the standard deviation of the variances of each column of the variance/covariance matrix (metric = c(variances, sd, var)). It is, however, possible to calculate disparity as a distribution. 4.4.5 Metrics implemented in dispRity Several disparity metrics are implemented in the dispRity package. The detailed list can be found in ?dispRity.metric along with some description of each metric. Level Name Description Source 2 ancestral.dist The distance between an element and its ancestor dispRity 2 angles The angle of main variation of each dimensions dispRity 2 centroids1 The distance between each element and the centroid of the ordinated space dispRity 1 convhull.surface The surface of the convex hull formed by all the elements geometry::convhulln$area 1 convhull.volume The volume of the convex hull formed by all the elements geometry::convhulln$vol 2 deviations The minimal distance between each element and a hyperplane dispRity 1 diagonal The longest distance in the ordinated space (like the diagonal in two dimensions) dispRity 1 disalignment The rejection of the centroid of a matrix from the major axis of another (typically an \"as.covar\" metric) dispRity 2 displacements The ratio between the distance from a reference and the distance from the centroid dispRity 1 edge.length.tree The edge lengths of the elements on a tree ape 1 ellipsoid.volume1 The volume of the ellipsoid of the space Donohue et al. (2013) 1 func.div The functional divergence (the ratio of deviation from the centroid) dispRity (similar to FD::dbFD$FDiv but without abundance) 1 func.eve The functional evenness (the minimal spanning tree distances evenness) dispRity (similar to FD::dbFD$FEve but without abundance) 1 group.dist The distance between two groups dispRity 1 mode.val The modal value dispRity 1 n.ball.volume The hyper-spherical (n-ball) volume dispRity 2 neighbours The distance to specific neighbours (e.g. the nearest neighbours - by default) dispRity 2 pairwise.dist The pairwise distances between elements vegan::vegist 2 point.dist The distance between one group and the point of another group dispRity 2 projections The distance on (projection) or from (rejection) an arbitrary vector dispRity 1 projections.between projections metric applied between groups dispRity 2 projections.tree The projections metric but where the vector can be based on a tree dispRity 2 quantiles The nth quantile range per axis dispRity 2 radius The radius of each dimensions dispRity 2 ranges The range of each dimension dispRity 1 roundness The integral of the ranked scaled eigenvalues of a variance-covariance matrix dispRity 2 span.tree.length The minimal spanning tree length vegan::spantree 2 variances The variance of each dimension dispRity 1: Note that by default, the centroid is the centroid of the elements. It can, however, be fixed to a different value by using the centroid argument centroids(space, centroid = rep(0, ncol(space))), for example the origin of the ordinated space. 2: This function uses an estimation of the eigenvalue that only works for MDS or PCoA ordinations (not PCA). You can find more informations on the vast variety of metrics that you can use in your analysis in this paper. 4.4.6 Equations and implementations Some of the functions described below are implemented in the dispRity package and do not require any other packages to calculate (see implementation here). \\[\\begin{equation} ancestral.dist = \\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Ancestor_{n})^2}} \\end{equation}\\] \\[\\begin{equation} centroids = \\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Centroid_{d})^2}} \\end{equation}\\] \\[\\begin{equation} diagonal = \\sqrt{\\sum_{i=1}^{d}|max(d_i) - min(k_i)|} \\end{equation}\\] \\[\\begin{equation} deviations = \\frac{|Ax + By + ... + Nm + Intercept|}{\\sqrt{A^2 + B^2 + ... + N^2}} \\end{equation}\\] \\[\\begin{equation} displacements = \\frac{\\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Reference_{d})^2}}}{\\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Centroid_{k})^2}}} \\end{equation}\\] \\[\\begin{equation} ellipsoid.volume = \\frac{\\pi^{d/2}}{\\Gamma(\\frac{d}{2}+1)}\\displaystyle\\prod_{i=1}^{d} (\\lambda_{i}^{0.5}) \\end{equation}\\] \\[\\begin{equation} n.ball.volume = \\frac{\\pi^{d/2}}{\\Gamma(\\frac{d}{2}+1)}\\displaystyle\\prod_{i=1}^{d} R \\end{equation}\\] \\[\\begin{equation} projection_{on} = \\| \\overrightarrow{i} \\cdot \\overrightarrow{b} \\| \\end{equation}\\] \\[\\begin{equation} projection_{from} = \\| \\overrightarrow{i} - \\overrightarrow{i} \\cdot \\overrightarrow{b} \\| \\end{equation}\\] \\[\\begin{equation} radius = |\\frac{\\sum_{i=1}^{n}d_i}{n} - f(\\mathbf{v}d)| \\end{equation}\\] \\[\\begin{equation} ranges = |max(d_i) - min(d_i)| \\end{equation}\\] \\[\\begin{equation} roundness = \\int_{i = 1}^{n}{\\frac{\\lambda_{i}}{\\text{max}(\\lambda)}} \\end{equation}\\] \\[\\begin{equation} variances = \\sigma^{2}{d_i} \\end{equation}\\] \\[\\begin{equation} span.tree.length = \\mathrm{branch\\ length} \\end{equation}\\] Where d is the number of dimensions, n the number of elements, \\(\\Gamma\\) is the Gamma distribution, \\(\\lambda_i\\) is the eigenvalue of each dimensions, \\(\\sigma^{2}\\) is their variance and \\(Centroid_{k}\\) is their mean, \\(Ancestor_{n}\\) is the coordinates of the ancestor of element \\(n\\), \\(f(\\mathbf{v}k)\\) is function to select one value from the vector \\(\\mathbf{v}\\) of the dimension \\(k\\) (e.g. it’s maximum, minimum, mean, etc.), R is the radius of the sphere or the product of the radii of each dimensions (\\(\\displaystyle\\prod_{i=1}^{k}R_{i}\\) - for a hyper-ellipsoid), \\(Reference_{k}\\) is an arbitrary point’s coordinates (usually 0), \\(\\overrightarrow{b}\\) is the vector defined by ((point1, point2)), and \\(\\overrightarrow{i}\\) is the vector defined by ((point1, i) where i is any row of the matrix). 4.4.7 Using the different disparity metrics Here is a brief demonstration of the main metrics implemented in dispRity. First, we will create a dummy/simulated ordinated space using the space.maker utility function (more about that here: ## Creating a 10*5 normal space set.seed(1) dummy_space <- space.maker(10, 5, rnorm) rownames(dummy_space) <- 1:10 We will use this simulated space to demonstrate the different metrics. 4.4.7.1 Volumes and surface metrics The functions ellipsoid.volume, convhull.surface, convhull.volume and n.ball.volume all measure the surface or the volume of the ordinated space occupied: Because there is only one subset (i.e. one matrix) in the dispRity object, the operations below are the equivalent of metric(dummy_space) (with rounding). ## Calculating the ellipsoid volume summary(dispRity(dummy_space, metric = ellipsoid.volume)) ## subsets n obs ## 1 1 10 1.061 WARNING: in such dummy space, this gives the estimation of the ellipsoid volume, not the real ellipsoid volume! See the cautionary note in ?ellipsoid.volume. ## Calculating the convex hull surface summary(dispRity(dummy_space, metric = convhull.surface)) ## subsets n obs ## 1 1 10 11.91 ## Calculating the convex hull volume summary(dispRity(dummy_space, metric = convhull.volume)) ## subsets n obs ## 1 1 10 1.031 ## Calculating the convex hull volume summary(dispRity(dummy_space, metric = n.ball.volume)) ## subsets n obs ## 1 1 10 4.43 The convex hull based functions are a call to the geometry::convhulln function with the \"FA\" option (computes total area and volume). Also note that they are really sensitive to the size of the dataset. Cautionary note: measuring volumes in a high number of dimensions can be strongly affected by the curse of dimensionality that often results in near 0 disparity values. I strongly recommend reading this really intuitive explanation from Toph Tucker. 4.4.7.2 Ranges, variances, quantiles, radius, pairwise distance, neighbours, modal value and diagonal The functions ranges, variances radius, pairwise.dist, mode.val and diagonal all measure properties of the ordinated space based on its dimensional properties (they are also less affected by the “curse of dimensionality”): ranges, variances quantiles and radius work on the same principle and measure the range/variance/radius of each dimension: ## Calculating the ranges of each dimension in the ordinated space ranges(dummy_space) ## [1] 2.430909 3.726481 2.908329 2.735739 1.588603 ## Calculating disparity as the distribution of these ranges summary(dispRity(dummy_space, metric = ranges)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 2.736 1.673 2.431 2.908 3.645 ## Calculating disparity as the sum and the product of these ranges summary(dispRity(dummy_space, metric = c(sum, ranges))) ## subsets n obs ## 1 1 10 13.39 summary(dispRity(dummy_space, metric = c(prod, ranges))) ## subsets n obs ## 1 1 10 114.5 ## Calculating the variances of each dimension in the ## ordinated space variances(dummy_space) ## [1] 0.6093144 1.1438620 0.9131859 0.6537768 0.3549372 ## Calculating disparity as the distribution of these variances summary(dispRity(dummy_space, metric = variances)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.654 0.38 0.609 0.913 1.121 ## Calculating disparity as the sum and ## the product of these variances summary(dispRity(dummy_space, metric = c(sum, variances))) ## subsets n obs ## 1 1 10 3.675 summary(dispRity(dummy_space, metric = c(prod, variances))) ## subsets n obs ## 1 1 10 0.148 ## Calculating the quantiles of each dimension ## in the ordinated space quantiles(dummy_space) ## [1] 2.234683 3.280911 2.760855 2.461077 1.559057 ## Calculating disparity as the distribution of these variances summary(dispRity(dummy_space, metric = quantiles)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 2.461 1.627 2.235 2.761 3.229 ## By default, the quantile calculated is the 95% ## (i.e. 95% of the data on each axis) ## this can be changed using the option quantile: summary(dispRity(dummy_space, metric = quantiles, quantile = 50)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.967 0.899 0.951 0.991 1.089 ## Calculating the radius of each dimension in the ordinated space radius(dummy_space) ## [1] 1.4630780 2.4635449 1.8556785 1.4977898 0.8416318 ## By default the radius is the maximum distance from the centre of ## the dimension. It can however be changed to any function: radius(dummy_space, type = min) ## [1] 0.05144054 0.14099827 0.02212226 0.17453525 0.23044528 radius(dummy_space, type = mean) ## [1] 0.6233501 0.7784888 0.7118713 0.6253263 0.5194332 ## Calculating disparity as the mean average radius summary(dispRity(dummy_space, metric = c(mean, radius), type = mean)) ## subsets n obs ## 1 1 10 0.652 The pairwise distances and the neighbours distances uses the function vegan::vegdist and can take the normal vegdist options: ## The average pairwise euclidean distance summary(dispRity(dummy_space, metric = c(mean, pairwise.dist))) ## subsets n obs ## 1 1 10 2.539 ## The distribution of the Manhattan distances summary(dispRity(dummy_space, metric = pairwise.dist, method = "manhattan")) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 4.427 2.566 3.335 5.672 9.63 ## The average nearest neighbour distances summary(dispRity(dummy_space, metric = neighbours)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.517 1.266 1.432 1.646 2.787 ## The average furthest neighbour manhattan distances summary(dispRity(dummy_space, metric = neighbours, which = max, method = "manhattan")) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 7.895 6.15 6.852 9.402 10.99 Note that this function is a direct call to vegan::vegdist(matrix, method = method, diag = FALSE, upper = FALSE, ...). The diagonal function measures the multidimensional diagonal of the whole space (i.e. in our case the longest Euclidean distance in our five dimensional space). The mode.val function measures the modal value of the matrix: ## Calculating the ordinated space's diagonal summary(dispRity(dummy_space, metric = diagonal)) ## subsets n obs ## 1 1 10 3.659 ## Calculating the modal value of the matrix summary(dispRity(dummy_space, metric = mode.val)) ## subsets n obs ## 1 1 10 -2.21 This metric is only a Euclidean diagonal (mathematically valid) if the dimensions within the space are all orthogonal! 4.4.7.3 Centroids, displacements and ancestral distances metrics The centroids metric allows users to measure the position of the different elements compared to a fixed point in the ordinated space. By default, this function measures the distance between each element and their centroid (centre point): ## The distribution of the distances between each element and their centroid summary(dispRity(dummy_space, metric = centroids)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.435 0.788 1.267 1.993 3.167 ## Disparity as the median value of these distances summary(dispRity(dummy_space, metric = c(median, centroids))) ## subsets n obs ## 1 1 10 1.435 It is however possible to fix the coordinates of the centroid to a specific point in the ordinated space, as long as it has the correct number of dimensions: ## The distance between each element and the origin ## of the ordinated space summary(dispRity(dummy_space, metric = centroids, centroid = 0)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.487 0.785 1.2 2.044 3.176 ## Disparity as the distance between each element ## and a specific point in space summary(dispRity(dummy_space, metric = centroids, centroid = c(0,1,2,3,4))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 5.489 4.293 5.032 6.155 6.957 If you have subsets in your dispRity object, you can also use the matrix.dispRity (see utilities) and colMeans to get the centre of a specific subgroup. For example ## Create a custom subsets object dummy_groups <- custom.subsets(dummy_space, group = list("group1" = 1:5, "group2" = 6:10)) summary(dispRity(dummy_groups, metric = centroids, centroid = colMeans(get.matrix(dummy_groups, "group1")))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 group1 5 2.011 0.902 1.389 2.284 3.320 ## 2 group2 5 1.362 0.760 1.296 1.505 1.985 The displacements distance is the ratio between the centroids distance and the centroids distance with centroid = 0. Note that it is possible to measure a ratio from another point than 0 using the reference argument. It gives indication of the relative displacement of elements in the multidimensional space: a score >1 signifies a displacement away from the reference. A score of >1 signifies a displacement towards the reference. ## The relative displacement of the group in space to the centre summary(dispRity(dummy_space, metric = displacements)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.014 0.841 0.925 1.1 1.205 ## The relative displacement of the group to an arbitrary point summary(dispRity(dummy_space, metric = displacements, reference = c(0,1,2,3,4))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 3.368 2.066 3.19 4.358 7.166 The ancestral.dist metric works on a similar principle as the centroids function but changes the centroid to be the coordinates of each element’s ancestor (if to.root = FALSE; default) or to the root of the tree (to.root = TRUE). Therefore this function needs a matrix that contains tips and nodes and a tree as additional argument. ## A generating a random tree with node labels my_tree <- makeNodeLabel(rtree(5), prefix = "n") ## Adding the tip and node names to the matrix dummy_space2 <- dummy_space[-1,] rownames(dummy_space2) <- c(my_tree$tip.label, my_tree$node.label) ## Calculating the distances from the ancestral nodes ancestral_dist <- dispRity(dummy_space2, metric = ancestral.dist, tree = my_tree) ## The ancestral distances distributions summary(ancestral_dist) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 9 1.729 0.286 1.653 1.843 3.981 ## Calculating disparity as the sum of the distances from all the ancestral nodes summary(dispRity(ancestral_dist, metric = sum)) ## subsets n obs ## 1 1 9 17.28 4.4.7.4 Minimal spanning tree length The span.tree.length uses the vegan::spantree function to heuristically calculate the minimum spanning tree (the shortest multidimensional tree connecting each elements) and calculates its length as the sum of every branch lengths. ## The length of the minimal spanning tree summary(dispRity(dummy_space, metric = c(sum, span.tree.length))) ## subsets n obs ## 1 1 10 15.4 Note that because the solution is heuristic, this metric can take a long time to compute for big matrices. 4.4.7.5 Functional divergence and evenness The func.div and func.eve functions are based on the FD::dpFD package. They are the equivalent to FD::dpFD(matrix)$FDiv and FD::dpFD(matrix)$FEve but a bit faster (since they don’t deal with abundance data). They are pretty straightforward to use: ## The ratio of deviation from the centroid summary(dispRity(dummy_space, metric = func.div)) ## subsets n obs ## 1 1 10 0.747 ## The minimal spanning tree distances evenness summary(dispRity(dummy_space, metric = func.eve)) ## subsets n obs ## 1 1 10 0.898 ## The minimal spanning tree manhanttan distances evenness summary(dispRity(dummy_space, metric = func.eve, method = "manhattan")) ## subsets n obs ## 1 1 10 0.913 4.4.7.6 Orientation: angles and deviations The angles performs a least square regression (via the lm function) and returns slope of the main axis of variation for each dimension. This slope can be converted into different units, \"slope\", \"degree\" (the default) and \"radian\". This can be changed through the unit argument. By default, the angle is measured from the slope 0 (the horizontal line in a 2D plot) but this can be changed through the base argument (using the defined unit): ## The distribution of each angles in degrees for each ## main axis in the matrix summary(dispRity(dummy_space, metric = angles)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 21.26 -39.8 3.723 39.47 56 ## The distribution of slopes deviating from the 1:1 slope: summary(dispRity(dummy_space, metric = angles, unit = "slope", base = 1)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.389 0.118 1.065 1.823 2.514 The deviations function is based on a similar algorithm as above but measures the deviation from the main axis (or hyperplane) of variation. In other words, it finds the least square line (for a 2D dataset), plane (for a 3D dataset) or hyperplane (for a >3D dataset) and measures the shortest distances between every points and the line/plane/hyperplane. By default, the hyperplane is fitted using the least square algorithm from stats::glm: ## The distribution of the deviation of each point ## from the least square hyperplane summary(dispRity(dummy_space, metric = deviations)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.274 0.02 0.236 0.453 0.776 It is also possible to specify the hyperplane equation through the hyperplane equation. The equation must contain the intercept first and then all the slopes and is interpreted as \\(intercept + Ax + By + ... + Nd = 0\\). For example, a 2 line defined as beta + intercept (e.g. \\(y = 2x + 1\\)) should be defined as hyperplane = c(1, 2, 1) (\\(2x - y + 1 = 0\\)). ## The distribution of the deviation of each point ## from a slope (with only the two first dimensions) summary(dispRity(dummy_space[, c(1:2)], metric = deviations, hyperplane = c(1, 2, -1))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.516 0.038 0.246 0.763 2.42 Since both the functions angles and deviations effectively run a lm or glm to estimate slopes or hyperplanes, it is possible to use the option significant = TRUE to only consider slopes or intercepts that have a slope significantly different than zero using an aov with a significant threshold of \\(p = 0.05\\). Note that depending on your dataset, using and aov could be completely inappropriate! In doubt, it’s probably better to enter your base (for angles) or your hyperplane (for deviations) manually so you’re sure you know what the function is measuring. 4.4.7.7 Projections and phylo projections: elaboration and exploration The projections metric calculates the geometric projection and corresponding rejection of all the rows in a matrix on an arbitrary vector (respectively the distance on and the distance from that vector). The function is based on Aguilera and Pérez-Aguila (2004)’s n-dimensional rotation algorithm to use linear algebra in mutidimensional spaces. The projection or rejection can be seen as respectively the elaboration and exploration scores on a trajectory (sensu Endler et al. (2005)). By default, the vector (e.g. a trajectory, an axis), on which the data is projected is the one going from the centre of the space (coordinates 0,0, …) and the centroid of the matrix. However, we advice you do define this axis to something more meaningful using the point1 and point2 options, to create the vector (the vector’s norm will be dist(point1, point2) and its direction will be from point1 towards point2). ## The elaboration on the axis defined by the first and ## second row in the dummy_space summary(dispRity(dummy_space, metric = projections, point1 = dummy_space[1,], point2 = dummy_space[2,])) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.998 0.118 0.651 1.238 1.885 ## The exploration on the same axis summary(dispRity(dummy_space, metric = projections, point1 = dummy_space[1,], point2 = dummy_space[2,], measure = "distance")) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.719 0 0.568 0.912 1.65 By default, the vector (point1, point2) is used as unit vector of the projections (i.e. the Euclidean distance between (point1, point2) is set to 1) meaning that a projection value (\"distance\" or \"position\") of X means X times the distance between point1 and point2. If you want use the unit vector of the input matrix or are using a space where Euclidean distances are non-sensical, you can remove this option using scale = FALSE: ## The elaboration on the same axis using the dummy_space's ## unit vector summary(dispRity(dummy_space, metric = projections, point1 = dummy_space[1,], point2 = dummy_space[2,], scale = FALSE)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 4.068 0.481 2.655 5.05 7.685 The projections.tree is the same as the projections metric but allows to determine the vector ((point1, point2)) using a tree rather than manually entering these points. The function intakes the exact same options as the projections function described above at the exception of point1 and point2. Instead it takes a the argument type that designates the type of vector to draw from the data based on a phylogenetic tree phy. The argument type can be a pair of any of the following inputs: \"root\": to automatically use the coordinates of the root of the tree (the first element in phy$node.label); \"ancestor\": to automatically use the coordinates of the elements’ (i.e. any row in the matrix) most recent ancestor; \"tips\": to automatically use the coordinates from the centroid of all tips; \"nodes\": to automatically use the coordinates from the centroid of all nodes; \"livings\": to automatically use the coordinates from the centroid of all “living” tips (i.e. the tips that are the furthest away from the root); \"fossils\": to automatically use the coordinates from the centroid of all “fossil” tips and nodes (i.e. not the “living” ones); any numeric values that can be interpreted as point1 and point2 in projections (e.g. 0, c(0, 1.2, 3/4), etc.); or a user defined function that with the inputs matrix and phy and row (the element’s ID, i.e. the row number in matrix). For example, if you want to measure the projection of each element in the matrix (tips and nodes) on the axis from the root of the tree to each element’s most recent ancestor, you can define the vector as type = c(\"root\", \"ancestor\"). ## Adding a extra row to dummy matrix (to match dummy_tree) tree_space <- rbind(dummy_space, root = rnorm(5)) ## Creating a random dummy tree (with labels matching the ones from tree_space) dummy_tree <- rtree(6) dummy_tree$tip.label <- rownames(tree_space)[1:6] dummy_tree$node.label <- rownames(tree_space)[rev(7:11)] ## Measuring the disparity as the projection of each element ## on its root-ancestor vector summary(dispRity(tree_space, metric = projections.tree, tree = dummy_tree, type = c("root", "ancestor"))) ## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to ## max; returning -Inf ## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to ## max; returning -Inf ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 11 NA 0.229 0.416 0.712 1.016 Of course you can also use any other options from the projections function: ## A user defined function that's returns the centroid of ## the first three nodes fun.root <- function(matrix, tree, row = NULL) { return(colMeans(matrix[tree$node.label[1:3], ])) } ## Measuring the unscaled rejection from the vector from the ## centroid of the three first nodes ## to the coordinates of the first tip summary(dispRity(tree_space, metric = projections.tree, tree = dummy_tree, measure = "distance", type = list(fun.root, tree_space[1, ]))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 11 0.606 0.064 0.462 0.733 0.999 4.4.7.8 Roundness The roundness coefficient (or metric) ranges between 0 and 1 and expresses the distribution of and ellipse’ major axis ranging from 1, a totally round ellipse (i.e. a circle) to 0 a totally flat ellipse (i.e. a line). A value of \\(0.5\\) represents a regular ellipse where each major axis is half the size of the previous major axis. A value \\(> 0.5\\) describes a pancake where the major axis distribution is convex (values close to 1 can be pictured in 3D as a cr`{e}pes with the first two axis being rather big - a circle - and the third axis being particularly thin; values closer to \\(0.5\\) can be pictured as flying saucers). Conversely, a value \\(< 0.5\\) describes a cigar where the major axis distribution is concave (values close to 0 can be pictured in 3D as a spaghetti with the first axis rather big and the two next ones being small; values closer to \\(0.5\\) can be pictured in 3D as a fat cigar). This is what it looks for example for three simulated variance-covariance matrices in 3D: 4.4.7.9 Between group metrics You can find detailed explanation on how between group metrics work here. 4.4.7.9.1 group.dist The group.dist metric allows to measure the distance between two groups in the multidimensional space. This function needs to intake several groups and use the option between.groups = TRUE in the dispRity function. It calculates the vector normal distance (euclidean) between two groups and returns 0 if that distance is negative. Note that it is possible to set up which quantiles to consider for calculating the distances between groups. For example, one might be interested in only considering the 95% CI for each group. This can be done through the option probs = c(0.025, 0.975) that is passed to the quantile function. It is also possible to use this function to measure the distance between the groups centroids by calculating the 50% quantile (probs = c(0.5)). ## Creating a dispRity object with two groups grouped_space <- custom.subsets(dummy_space, group = list(c(1:5), c(6:10))) ## Measuring the minimum distance between both groups summary(dispRity(grouped_space, metric = group.dist, between.groups = TRUE)) ## subsets n_1 n_2 obs ## 1 1:2 5 5 0 ## Measuring the centroid distance between both groups summary(dispRity(grouped_space, metric = group.dist, between.groups = TRUE, probs = 0.5)) ## subsets n_1 n_2 obs ## 1 1:2 5 5 0.708 ## Measuring the distance between both group's 75% CI summary(dispRity(grouped_space, metric = group.dist, between.groups = TRUE, probs = c(0.25, 0.75))) ## subsets n_1 n_2 obs ## 1 1:2 5 5 0.059 4.4.7.9.2 point.dist The metric measures the distance between the elements in one group (matrix) and a point calculated from a second group (matrix2). By default this point is the centroid but can be any point defined by a function passed to the point argument. For example, the centroid of matrix2 is the mean of each column of that matrix so point = colMeans (default). This function also takes the method argument like previous one described above to measure either the \"euclidean\" (default) or the \"manhattan\" distances: ## Measuring the distance between the elements of the first group ## and the centroid of the second group summary(dispRity(grouped_space, metric = point.dist, between.groups = TRUE)) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 1:2 5 5 2.182 1.304 1.592 2.191 3.355 ## Measuring the distance between the elements of the second group ## and the centroid of the first group summary(dispRity(grouped_space, metric = point.dist, between.groups = list(c(2,1)))) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 2:1 5 5 1.362 0.76 1.296 1.505 1.985 ## Measuring the distance between the elements of the first group ## a point defined as the standard deviation of each column ## in the second group sd.point <- function(matrix2) {apply(matrix2, 2, sd)} summary(dispRity(grouped_space, metric = point.dist, point = sd.point, method = "manhattan", between.groups = TRUE)) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 1:2 5 5 4.043 2.467 3.567 4.501 6.884 4.4.7.9.3 projections.between and disalignment These two metrics are typically based on variance-covariance matrices from a dispRity object that has a $covar component (see more about that here). Both are based on the projections metric and can take the same optional arguments (more info here). The examples and explanations below are based on the default arguments but it is possible (and easy!) to change them. We are going to use the charadriiformes example for both metrics (see more about that here). ## Loading the charadriiformes data data(charadriiformes) ## Creating the dispRity object (see the #covar section in the manual for more info) my_covar <- MCMCglmm.subsets(n = 50, data = charadriiformes$data, posteriors = charadriiformes$posteriors, group = MCMCglmm.levels(charadriiformes$posteriors)[1:4], tree = charadriiformes$tree, rename.groups = c(levels(charadriiformes$data$clade), "phylogeny")) The first metric, projections.between projects the major axis of one group (matrix) onto the major axis of another one (matrix2). For example we might want to know how some groups compare in terms of angle (orientation) to a base group: ## Creating the list of groups to compare comparisons_list <- list(c("gulls", "phylogeny"), c("plovers", "phylogeny"), c("sandpipers", "phylogeny")) ## Measuring the angles between each groups ## (note that we set the metric as.covar, more on that in the #covar section below) groups_angles <- dispRity(data = my_covar, metric = as.covar(projections.between), between.groups = comparisons_list, measure = "degree") ## And here are the angles in degrees: summary(groups_angles) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 gulls:phylogeny 159 359 8.25 2.101 6.25 14.98 41.8 ## 2 plovers:phylogeny 98 359 33.75 5.700 16.33 75.50 131.5 ## 3 sandpipers:phylogeny 102 359 10.79 3.876 8.10 16.59 95.9 The second metric, disalignment rejects the centroid of a group (matrix) onto the major axis of another one (matrix2). This allows to measure wether the center of a group is aligned with the major axis of another. A disalignement value of 0 means that the groups are aligned. A higher disalignment value means the groups are more and more disaligned. We can use the same set of comparisons as in the projections.between examples to measure which group is most aligned (less disaligned) with the phylogenetic major axis: ## Measuring the disalignement of each group groups_alignement <- dispRity(data = my_covar, metric = as.covar(disalignment), between.groups = comparisons_list) ## And here are the groups alignment (0 = aligned) summary(groups_alignement) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.015 ## 2 plovers:phylogeny 98 359 0.001 0.000 0.001 0.001 0.006 ## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.003 0.009 4.4.8 Which disparity metric to choose? The disparity metric that gives the most consistent results is the following one: best.metric <- function() return(42) Joke aside, this is a legitimate question that has no simple answer: it depends on the dataset and question at hand. Thoughts on which metric to choose can be find in Thomas Guillerme, Puttick, et al. (2020) and Thomas Guillerme, Cooper, et al. (2020) but again, will ultimately depend on the question and dataset. The question should help figuring out which type of metric is desired: for example, in the question “does the extinction released niches for mammals to evolve”, the metric in interest should probably pick up a change in size in the trait space (the release could result in some expansion of the mammalian morphospace); or if the question is “does group X compete with group Y”, maybe the metric of interested should pick up changes in position (group X can be displaced by group Y). In order to visualise what signal different disparity metrics are picking, you can use the moms that come with a detailed manual on how to use it. Alternatively, you can use the test.metric function: 4.4.8.1 test.metric This function allows to test whether a metric picks different changes in disparity. It intakes the space on which to test the metric, the disparity metric and the type of changes to apply gradually to the space. Basically this is a type of biased data rarefaction (or non-biased for \"random\") to see how the metric reacts to specific changes in trait space. ## Creating a 2D uniform space example_space <- space.maker(300, 2, runif) ## Testing the product of ranges metric on the example space example_test <- test.metric(example_space, metric = c(prod, ranges), shifts = c("random", "size")) By default, the test runs three replicates of space reduction as described in Thomas Guillerme, Puttick, et al. (2020) by gradually removing 10% of the data points following the different algorithms from Thomas Guillerme, Puttick, et al. (2020) (here the \"random\" reduction and the \"size\") reduction, resulting in a dispRity object that can be summarised or plotted. The number of replicates can be changed using the replicates option. Still by default, the function then runs a linear model on the simulated data to measure some potential trend in the changes in disparity. The model can be changed using the model option. Finally, the function runs 10 reductions by default from keeping 10% of the data (removing 90%) and way up to keeping 100% of the data (removing 0%). This can be changed using the steps option. A good disparity metric for your dataset will typically have no trend in the \"random\" reduction (the metric is ideally not affected by sample size) but should have a trend for the reduction of interest. ## The results as a dispRity object example_test ## Metric testing: ## The following metric was tested: c(prod, ranges). ## The test was run on the random, size shifts for 3 replicates using the following model: ## lm(disparity ~ reduction, data = data) ## Use summary(x) or plot(x) for more details. ## Summarising these results summary(example_test) ## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope ## random 0.84 0.88 0.94 0.95 0.96 0.98 0.97 0.98 0.96 0.98 1.450100e-03 ## size.increase 0.10 0.21 0.31 0.45 0.54 0.70 0.78 0.94 0.96 0.98 1.054925e-02 ## size.hollowness 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 0.98 1.453782e-05 ## p_value R^2(adj) ## random 2.439179e-06 0.5377136 ## size.increase 4.450564e-25 0.9783976 ## size.hollowness 1.925262e-05 0.4664502 ## Or visualising them plot(example_test) 4.5 Summarising dispRity data (plots) Because of its architecture, printing dispRity objects only summarises their content but does not print the disparity value measured or associated analysis (more about this here). To actually see what is in a dispRity object, one can either use the summary function for visualising the data in a table or plot to have a graphical representation of the results. 4.5.1 Summarising dispRity data This function is an S3 function (summary.dispRity) allowing users to summarise the content of dispRity objects that contain disparity calculations. ## Example data from previous sections crown_stem <- custom.subsets(BeckLee_mat50, group = crown.stem(BeckLee_tree, inc.nodes = FALSE)) ## Bootstrapping and rarefying these groups boot_crown_stem <- boot.matrix(crown_stem, bootstraps = 100, rarefaction = TRUE) ## Calculate disparity disparity_crown_stem <- dispRity(boot_crown_stem, metric = c(sum, variances)) ## Creating time slice subsets time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## Bootstrapping the time slice subsets boot_time_slices <- boot.matrix(time_slices, bootstraps = 100) ## Calculate disparity disparity_time_slices <- dispRity(boot_time_slices, metric = c(sum, variances)) ## Creating time bin subsets time_bins <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "discrete", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages, inc.nodes = TRUE) ## Bootstrapping the time bin subsets boot_time_bins <- boot.matrix(time_bins, bootstraps = 100) ## Calculate disparity disparity_time_bins <- dispRity(boot_time_bins, metric = c(sum, variances)) These objects are easy to summarise as follows: ## Default summary summary(disparity_time_slices) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 120 5 3.258 2.675 1.264 2.436 2.948 3.085 ## 2 80 19 3.491 3.315 3.128 3.266 3.362 3.453 ## 3 40 15 3.677 3.453 3.157 3.349 3.547 3.681 ## 4 0 10 4.092 3.726 3.293 3.578 3.828 3.950 Information about the number of elements in each subset and the observed (i.e. non-bootstrapped) disparity are also calculated. This is specifically handy when rarefying the data for example: head(summary(disparity_crown_stem)) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 crown 30 2.526 2.441 2.367 2.420 2.466 2.487 ## 2 crown 29 NA 2.449 2.354 2.428 2.468 2.490 ## 3 crown 28 NA 2.441 2.385 2.422 2.457 2.485 ## 4 crown 27 NA 2.442 2.363 2.411 2.465 2.490 ## 5 crown 26 NA 2.438 2.350 2.416 2.458 2.494 ## 6 crown 25 NA 2.447 2.359 2.423 2.471 2.496 The summary functions can also take various options such as: quantiles values for the confidence interval levels (by default, the 50 and 95 quantiles are calculated) cent.tend for the central tendency to use for summarising the results (default is median) digits option corresponding to the number of decimal places to print (default is 2) recall option for printing the call of the dispRity object as well (default is FALSE) These options can easily be changed from the defaults as follows: ## Same as above but using the 88th quantile and the standard deviation as the summary summary(disparity_time_slices, quantiles = 88, cent.tend = sd) ## subsets n obs bs.sd 6% 94% ## 1 120 5 3.258 0.426 1.864 3.075 ## 2 80 19 3.491 0.084 3.156 3.435 ## 3 40 15 3.677 0.149 3.231 3.650 ## 4 0 10 4.092 0.195 3.335 3.904 ## Printing the details of the object and digits the values to the 5th decimal place summary(disparity_time_slices, recall = TRUE, digits = 5) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 120, 80, 40, 0. ## Data was bootstrapped 100 times (method:"full"). ## Disparity was calculated as: c(sum, variances). ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 120 5 3.25815 2.67517 1.26366 2.43637 2.94780 3.08485 ## 2 80 19 3.49145 3.31487 3.12837 3.26601 3.36182 3.45336 ## 3 40 15 3.67702 3.45329 3.15729 3.34867 3.54670 3.68134 ## 4 0 10 4.09234 3.72554 3.29285 3.57797 3.82814 3.95046 Note that the summary table is a data.frame, hence it is as easy to modify as any dataframe using dplyr. You can also export it in csv format using write.csv or write_csv or even directly export into LaTeX format using the following; ## Loading the xtable package require(xtable) ## Converting the table in LaTeX xtable(summary(disparity_time_slices)) 4.5.2 Plotting dispRity data An alternative (and more fun!) way to display the calculated disparity is to plot the results using the S3 method plot.dispRity. This function takes the same options as summary.dispRity along with various graphical options described in the function help files (see ?plot.dispRity). The plots can be of five different types: preview for a 2d preview of the trait-space. continuous for displaying continuous disparity curves box, lines, and polygons to display discrete disparity results in respectively a boxplot, confidence interval lines, and confidence interval polygons. This argument can be left empty. In this case, the algorithm will automatically detect the type of subsets from the dispRity object and plot accordingly. It is also possible to display the number of elements in each subset (as a horizontal dotted line) using the option elements = TRUE. Additionally, when the data is rarefied, one can indicate which level of rarefaction to display (i.e. only display the results for a certain number of elements) by using the rarefaction argument. ## Graphical parameters op <- par(mfrow = c(2, 2), bty = "n") ## Plotting continuous disparity results plot(disparity_time_slices, type = "continuous") ## Plotting discrete disparity results plot(disparity_crown_stem, type = "box") ## As above but using lines for the rarefaction level of 20 elements only plot(disparity_crown_stem, type = "line", rarefaction = 20) ## As above but using polygons while also displaying the number of elements plot(disparity_crown_stem, type = "polygon", elements = TRUE) ## Resetting graphical parameters par(op) Since plot.dispRity uses the arguments from the generic plot method, it is of course possible to change pretty much everything using the regular plot arguments: ## Graphical options op <- par(bty = "n") ## Plotting the results with some classic options from plot plot(disparity_time_slices, col = c("blue", "orange", "green"), ylab = c("Some measurement"), xlab = "Some other measurement", main = "Many options...", ylim = c(10, 0), xlim = c(4, 0)) ## Adding a legend legend("topleft", legend = c("Central tendency", "Confidence interval 1", "Confidence interval 2"), col = c("blue", "orange", "green"), pch = 19) ## Resetting graphical parameters par(op) In addition to the classic plot arguments, the function can also take arguments that are specific to plot.dispRity like adding the number of elements or rarefaction level (as described above), and also changing the values of the quantiles to plot as well as the central tendency. ## Graphical options op <- par(bty = "n") ## Plotting the results with some plot.dispRity arguments plot(disparity_time_slices, quantiles = c(seq(from = 10, to = 100, by = 10)), cent.tend = sd, type = "c", elements = TRUE, col = c("black", rainbow(10)), ylab = c("Disparity", "Diversity"), xlab = "Time (in in units from past to present)", observed = TRUE, main = "Many more options...") ## Resetting graphical parameters par(op) Note that the argument observed = TRUE allows to plot the disparity values calculated from the non-bootstrapped data as crosses on the plot. For comparing results, it is also possible to add a plot to the existent plot by using add = TRUE: ## Graphical options op <- par(bty = "n") ## Plotting the continuous disparity with a fixed y axis plot(disparity_time_slices, ylim = c(3, 9)) ## Adding the discrete data plot(disparity_time_bins, type = "line", ylim = c(3, 9), xlab = "", ylab = "", add = TRUE) ## Resetting graphical parameters par(op) Finally, if your data has been fully rarefied, it is also possible to easily look at rarefaction curves by using the rarefaction = TRUE argument: ## Graphical options op <- par(bty = "n") ## Plotting the rarefaction curves plot(disparity_crown_stem, rarefaction = TRUE) ## Resetting graphical parameters par(op) 4.5.3 type = preview Note that all the options above are plotting disparity objects for which a disparity metric has been calculated. This makes totally sense for dispRity objects but sometimes it might be interesting to look at what the trait-space looks like before measuring the disparity. This can be done by plotting dispRity objects with no calculated disparity! For example, we might be interested in looking at how the distribution of elements change as a function of the distributions of different sub-settings. For example custom subsets vs. time subsets: ## Making the different subsets cust_subsets <- custom.subsets(BeckLee_mat99, crown.stem(BeckLee_tree, inc.nodes = TRUE)) time_subsets <- chrono.subsets(BeckLee_mat99, tree = BeckLee_tree, method = "discrete", time = 5) ## Note that no disparity has been calculated here: is.null(cust_subsets$disparity) ## [1] TRUE is.null(time_subsets$disparity) ## [1] TRUE ## But we can still plot both spaces by using the default plot functions par(mfrow = c(1,2)) ## Default plotting plot(cust_subsets) ## Plotting with more arguments plot(time_subsets, specific.args = list(dimensions = c(1,2)), main = "Some \\"low\\" dimensions") DISCLAIMER: This functionality can be handy for exploring the data (e.g. to visually check whether the subset attribution worked) but it might be misleading on how the data is actually distributed in the multidimensional space! Groups that don’t overlap on two set dimensions can totally overlap in all other dimensions! For dispRity objects that do contain disparity data, the default option is to plot your disparity data. However you can always force the preview option using the following: par(mfrow = c(2,1)) ## Default plotting plot(disparity_time_slices, main = "Disparity through time") ## Plotting with more arguments plot(disparity_time_slices, type = "preview", main = "Two first dimensions of the trait space") 4.5.4 Graphical options with ... As mentioned above all the plots using plot.dispRity you can use the ... options to add any type of graphical parameters recognised by plot. However, sometimes, plotting more advanced \"dispRity\" objects also calls other generic functions such as lines, points or legend. You can fine tune which specific function should be affected by ... by using the syntax <function>.<argument> where <function> is usually the function to plot a specific element in the plot (e.g. points) and the <argument> is the specific argument you want to change for that function. For example, in a plot containing several elements, including circles (plotted internally with points), you can decide to colour everything in blue using the normal col = \"blue\" option. But you can also decide to only colour the circles in blue using points.col = \"blue\"! Here is an example with multiple elements (lines and points) taken from the disparity with trees section below: ## Loading some demo data: ## An ordinated matrix with node and tip labels data(BeckLee_mat99) ## The corresponding tree with tip and node labels data(BeckLee_tree) ## A list of tips ages for the fossil data data(BeckLee_ages) ## Time slicing through the tree using the equal split algorithm time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, FADLAD = BeckLee_ages, method = "continuous", model = "acctran", time = 15) par(mfrow = c(2,2)) ## The preview plot with the tree using only defaults plot(time_slices, type = "preview", specific.args = list(tree = TRUE)) ## The same plot but by applying general options plot(time_slices, type = "preview", specific.args = list(tree = TRUE), col = "blue", main = "General options") ## The same plot but by applying the colour only to the lines ## and change of shape only to the points plot(time_slices, type = "preview", specific.args = list(tree = TRUE), lines.col = "blue", points.pch = 15, main = "Specific options") ## And now without the legend plot(time_slices, type = "preview", specific.args = list(tree = TRUE), lines.col = "blue", points.pch = 15, legend = FALSE) 4.6 Testing disparity hypotheses The dispRity package allows users to apply statistical tests to the calculated disparity to test various hypotheses. The function test.dispRity works in a similar way to the dispRity function: it takes a dispRity object, a test and a comparisons argument. The comparisons argument indicates the way the test should be applied to the data: pairwise (default): to compare each subset in a pairwise manner referential: to compare each subset to the first subset sequential: to compare each subset to the following subset all: to compare all the subsets together (like in analysis of variance) It is also possible to input a list of pairs of numeric values or characters matching the subset names to create personalised tests. Some other tests implemented in dispRity such as the dispRity::null.test have a specific way they are applied to the data and therefore ignore the comparisons argument. The test argument can be any statistical or non-statistical test to apply to the disparity object. It can be a common statistical test function (e.g. stats::t.test), a function implemented in dispRity (e.g. see ?null.test) or any function defined by the user. This function also allows users to correct for Type I error inflation (false positives) when using multiple comparisons via the correction argument. This argument can be empty (no correction applied) or can contain one of the corrections from the stats::p.adjust function (see ?p.adjust). Note that the test.dispRity algorithm deals with some classical test outputs (h.test, lm and numeric vector) and summarises the test output. It is, however, possible to get the full detailed output by using the options details = TRUE. Here we are using the variables generated in the section above: ## T-test to test for a difference in disparity between crown and stem mammals test.dispRity(disparity_crown_stem, test = t.test) ## [[1]] ## statistic: t ## crown : stem 57.38116 ## ## [[2]] ## parameter: df ## crown : stem 184.8496 ## ## [[3]] ## p.value ## crown : stem 9.763665e-120 ## ## [[4]] ## stderr ## crown : stem 0.005417012 ## Performing the same test but with the detailed t.test output test.dispRity(disparity_crown_stem, test = t.test, details = TRUE) ## $`crown : stem` ## $`crown : stem`[[1]] ## ## Welch Two Sample t-test ## ## data: dots[[1L]][[1L]] and dots[[2L]][[1L]] ## t = 57.381, df = 184.85, p-value < 2.2e-16 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## 0.3001473 0.3215215 ## sample estimates: ## mean of x mean of y ## 2.440611 2.129776 ## Wilcoxon test applied to time sliced disparity with sequential comparisons, ## with Bonferroni correction test.dispRity(disparity_time_slices, test = wilcox.test, comparisons = "sequential", correction = "bonferroni") ## [[1]] ## statistic: W ## 120 : 80 42 ## 80 : 40 2065 ## 40 : 0 1485 ## ## [[2]] ## p.value ## 120 : 80 2.682431e-33 ## 80 : 40 2.247885e-12 ## 40 : 0 2.671335e-17 ## Measuring the overlap between distributions in the time bins (using the ## implemented Bhattacharyya Coefficient function - see ?bhatt.coeff) test.dispRity(disparity_time_bins, test = bhatt.coeff) ## bhatt.coeff ## 120 - 80 : 80 - 40 0.00000000 ## 120 - 80 : 40 - 0 0.02236068 ## 80 - 40 : 40 - 0 0.42018008 Because of the modular design of the package, tests can always be made by the user (the same way disparity metrics can be user made). The only condition is that the test can be applied to at least two distributions. In practice, the test.dispRity function will pass the calculated disparity data (distributions) to the provided function in either pairs of distributions (if the comparisons argument is set to pairwise, referential or sequential) or a table containing all the distributions (comparisons = all; this should be in the same format as data passed to lm-type functions for example). 4.6.1 NPMANOVA in dispRity One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices vegan::adonis. This can be done on dispRity objects using the adonis.dispRity wrapper function. Basically, this function takes the exact same arguments as adonis and a dispRity object for data and performs a PERMANOVA based on the distance matrix of the multidimensional space (unless the multidimensional space was already defined as a distance matrix). The adonis.dispRity function uses the information from the dispRity object to generate default formulas: If the object contains customised subsets, it applies the default formula matrix ~ group testing the effect of group as a predictor on matrix (called from the dispRity object as data$matrix see dispRitu object details) If the object contains time subsets, it applies the default formula matrix ~ time testing the effect of time as a predictor (were the different levels of time are the different time slices/bins) set.seed(1) ## Generating a random character matrix character_matrix <- sim.morpho(rtree(20), 50, rates = c(rnorm, 1, 0)) ## Calculating the distance matrix distance_matrix <- as.matrix(dist(character_matrix)) ## Creating two groups random_groups <- list("group1" = 1:10, "group2" = 11:20) ## Generating a dispRity object random_disparity <- custom.subsets(distance_matrix, random_groups) ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! ## Running a default NPMANOVA adonis.dispRity(random_disparity) ## Permutation test for adonis under reduced model ## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = matrix ~ group, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## group 1 14.2 0.06443 1.2396 0.166 ## Residual 18 206.2 0.93557 ## Total 19 220.4 1.00000 Of course, it is possible to pass customised formulas if the disparity object contains more more groups. In that case the predictors must correspond to the names of the groups explained data must be set as matrix: ## Creating two groups with two states each groups <- as.data.frame(matrix(data = c(rep(1,10), rep(2,10), rep(c(1,2), 10)), nrow = 20, ncol = 2, dimnames = list(paste0("t", 1:20), c("g1", "g2")))) ## Creating the dispRity object multi_groups <- custom.subsets(distance_matrix, groups) ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! ## Running the NPMANOVA adonis.dispRity(multi_groups, matrix ~ g1 + g2) ## Permutation test for adonis under reduced model ## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = matrix ~ g1 + g2, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## g1 1 11.0 0.04991 0.9359 0.549 ## g2 1 9.6 0.04356 0.8168 0.766 ## Residual 17 199.8 0.90653 ## Total 19 220.4 1.00000 Finally, it is possible to use objects generated by chrono.subsets. In this case, adonis.dispRity will applied the matrix ~ time formula by default: ## Creating time series time_subsets <- chrono.subsets(BeckLee_mat50, BeckLee_tree, method = "discrete", inc.nodes = FALSE, time = c(100, 85, 65, 0), FADLAD = BeckLee_ages) ## Running the NPMANOVA with time as a predictor adonis.dispRity(time_subsets) ## Warning in adonis.dispRity(time_subsets): The input data for adonis.dispRity was not a distance matrix. ## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])). ## Make sure that this is the desired methodological approach! ## Permutation test for adonis under reduced model ## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ time, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## time 2 9.593 0.07769 1.9796 0.001 *** ## Residual 47 113.884 0.92231 ## Total 49 123.477 1.00000 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Note that the function warns you that the input data was transformed into a distance matrix. This is reflected in the Call part of the output (formula = dist(matrix) ~ time). To use each time subset as a separate predictor, you can use the matrix ~ chrono.subsets formula; this is equivalent to matrix ~ first_time_subset + second_time_subset + ...: ## Running the NPMANOVA with each time bin as a predictor adonis.dispRity(time_subsets, matrix ~ chrono.subsets) ## Warning in adonis.dispRity(time_subsets, matrix ~ chrono.subsets): The input data for adonis.dispRity was not a distance matrix. ## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])). ## Make sure that this is the desired methodological approach! ## Permutation test for adonis under reduced model ## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ chrono.subsets, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## t100to85 1 3.714 0.03008 1.5329 0.006 ** ## t85to65 1 5.879 0.04761 2.4262 0.001 *** ## Residual 47 113.884 0.92231 ## Total 49 123.477 1.00000 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 4.6.2 geiger::dtt model fitting in dispRity The dtt function from the geiger package is also often used to compare a trait’s disparity observed in living taxa to the disparity of a simulated trait based on a given phylogeny. The dispRity package proposes a wrapper function for geiger::dtt, dtt.dispRity that allows the use of any disparity metric. Unfortunately, this implementation is slower that geiger::dtt (so if you’re using the metrics implemented in geiger prefer the original version) and, as the original function, is limited to ultrametric trees (only living taxa!)… require(geiger) ## Loading required package: geiger geiger_data <- get(data(geospiza)) ## Calculate the disparity of the dataset using the sum of variance dispRity_dtt <- dtt.dispRity(data = geiger_data$dat, metric = c(sum, variances), tree = geiger_data$phy, nsim = 100) ## Warning in dtt.dispRity(data = geiger_data$dat, metric = c(sum, variances), : ## The following tip(s) was not present in the data: olivacea. ## Plotting the results plot(dispRity_dtt) Note that, like in the original dtt function, it is possible to change the evolutionary model (see ?geiger::sim.char documentation). 4.6.3 null morphospace testing with null.test This test is equivalent to the test performed in Dı́az et al. (2016). It compares the disparity measured in the observed space to the disparity measured in a set of simulated spaces. These simulated spaces can be built with based on the hypothesis assumptions: for example, we can test whether our space is normal. set.seed(123) ## A "normal" multidimensional space with 50 dimensions and 10 elements normal_space <- matrix(rnorm(1000), ncol = 50) ## Calculating the disparity as the average pairwise distances obs_disparity <- dispRity(normal_space, metric = c(mean, pairwise.dist)) ## Warning in check.data(data, match_call): Row names have been automatically ## added to data. ## Testing against 100 randomly generated normal spaces (results <- null.test(obs_disparity, replicates = 100, null.distrib = rnorm)) ## Monte-Carlo test ## Call: [1] "dispRity::null.test" ## ## Observation: 9.910536 ## ## Based on 100 replicates ## Simulated p-value: 0.8712871 ## Alternative hypothesis: two-sided ## ## Std.Obs Expectation Variance ## -0.18217227 9.95101000 0.04936221 Here the results show that disparity measured in our observed space is not significantly different than the one measured in a normal space. We can then propose that our observed space is normal! These results have an attributed dispRity and randtest class and can be plotted as randtest objects using the dispRity S3 plot method: ## Plotting the results plot(results, main = "Is this space normal?") For more details on generating spaces see the space.maker function tutorial. 4.7 Fitting modes of evolution to disparity data The code used for these models is based on those developed by Gene Hunt (Hunt 2006, 2012; Hunt, Hopkins, and Lidgard 2015). So we acknowledge and thank Gene Hunt for developing these models and writing the original R code that served as inspiration for these models. DISCLAIMER: this method of analysing disparity has not been published yet and has not been peer reviewed. Caution should be used in interpreting these results: it is unclear what “a disparity curve fitting a Brownian motion” actually means biologically. As Malcolm said in Jurassic Park: “although the examples within this chapter all work and produce solid tested results (from an algorithm point of view), that doesn’t mean you should use it” (or something along those lines). 4.7.1 Simple modes of disparity change through time 4.7.1.1 model.test Changes in disparity-through-time can follow a range of models, such as random walks, stasis, constrained evolution, trends, or an early burst model of evolution. We will start with by fitting the simplest modes of evolution to our data. For example we may have a null expectation of time-invariant change in disparity in which values fluctuate with a variance around the mean - this would be best describe by a Stasis model: ## Loading premade disparity data data(BeckLee_disparity) disp_time <- model.test(data = BeckLee_disparity, model = "Stasis") ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 We can see the standard output from model.test. The first output message tells us it has tested for equal variances in each sample. The model uses Bartlett’s test of equal variances to assess if variances are equal, so if p > 0.05 then variance is treated as the same for all samples, but if (p < 0.05) then each bin variance is unique. Here we have p < 0.05, so variance is not pooled between samples. By default model.test will use Bartlett’s test to assess for homogeneity of variances, and then use this to decide to pool variances or not. This is ignored if the argument pool.variance in model.test is changed from the default NULL to TRUE or FALSE. For example, to ignore Bartlett’s test and pool variances manually we would do the following: disp_time_pooled <- model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = TRUE) ## Running Stasis model...Done. Log-likelihood = -16.884 However, unless you have good reason to choose otherwise it is recommended to use the default of pool.variance = NULL: disp_time <- model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 disp_time ## Disparity evolution model fitting: ## Call: model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL) ## ## aicc delta_aicc weight_aicc ## Stasis 41.48967 0 1 ## ## Use x$full.details for displaying the models details ## or summary(x) for summarising them. The remaining output gives us the log-likelihood of the Stasis model of -18.7 (you may notice this change when we pooled variances above). The output also gives us the small sample Akaike Information Criterion (AICc), the delta AICc (the distance from the best fitting model), and the AICc weights (~the relative support of this model compared to all models, scaled to one). These are all metrics of relative fit, so when we test a single model they are not useful. By using the function summary in dispRity we can see the maximum likelihood estimates of the model parameters: summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ## Stasis 41.5 0 1 -18.7 2 3.6 0.1 So we again see the AICc, delta AICc, AICc weight, and the log-likelihood we saw previously. We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.6). The model.test function is designed to test relative model fit, so we need to test more than one model to make relative comparisons. So let’s compare to the fit of the Stasis model to another model with two parameters: the Brownian motion. Brownian motion assumes a constant mean that is equal to the ancestral estimate of the sequence, and the variance around this mean increases linearly with time. The easier way to compare these models is to simply add \"BM\" to the models vector argument: disp_time <- model.test(data = BeckLee_disparity, model = c("Stasis", "BM")) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 ## Running BM model...Done. Log-likelihood = 149.289 disp_time ## Disparity evolution model fitting: ## Call: model.test(data = BeckLee_disparity, model = c("Stasis", "BM")) ## ## aicc delta_aicc weight_aicc ## Stasis 41.48967 335.9656 1.111708e-73 ## BM -294.47595 0.0000 1.000000e+00 ## ## Use x$full.details for displaying the models details ## or summary(x) for summarising them. Et voilà! Here we can see by the log-likelihood, AICc, delta AICc, and AICc weight Brownian motion has a much better relative fit to these data than the Stasis model. Brownian motion has a relative AICc fit336 units better than Stasis, and has a AICc weight of 1. We can also all the information about the relative fit of models alongside the maximum likelihood estimates of model parameters using the summary function summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Stasis 41 336 0 -18.7 2 3.629 0.074 NA ## BM -294 0 1 149.3 2 NA NA 3.267 ## sigma squared ## Stasis NA ## BM 0.001 Not that because the parameters per models differ, the summary includes NA for inapplicable parameters per models (e.g. the theta and omega parameters from the Stasis models are inapplicable for a Brownian motion model). We can plot the relative fit of our models using the plot function plot(disp_time) Figure 4.1: relative fit (AICc weight) of Stasis and Brownian models of disparity through time Here we see and overwhelming support for the Brownian motion model. Alternatively, we could test all available models single modes: Stasis, Brownian motion, Ornstein-Uhlenbeck (evolution constrained to an optima), Trend (increasing or decreasing mean through time), and Early Burst (exponentially decreasing rate through time) disp_time <- model.test(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB")) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 ## Running BM model...Done. Log-likelihood = 149.289 ## Running OU model...Done. Log-likelihood = 152.119 ## Running Trend model...Done. Log-likelihood = 152.116 ## Running EB model...Done. Log-likelihood = 126.268 summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA ## BM -294 3.6 0.112 149.3 2 NA NA 3.267 ## OU -296 2.1 0.227 152.1 4 NA NA 3.254 ## Trend -298 0.0 0.661 152.1 3 NA NA 3.255 ## EB -246 51.7 0.000 126.3 3 NA NA 4.092 ## sigma squared alpha optima.1 trend eb ## Stasis NA NA NA NA NA ## BM 0.001 NA NA NA NA ## OU 0.001 0.001 12.35 NA NA ## Trend 0.001 NA NA 0.007 NA ## EB 0.000 NA NA NA -0.032 These models indicate support for a Trend model, and we can plot the relative support of all model AICc weights. plot(disp_time) Figure 4.2: relative fit (AICc weight) of various modes of evolution Note that although AIC values are indicator of model best fit, it is also important to look at the parameters themselves. For example OU can be really well supported but with an alpha parameter really close to 0, making it effectively a BM model (Cooper et al. 2016). Is this a trend of increasing or decreasing disparity through time? One way to find out is to look at the summary function for the Trend model: summary(disp_time)["Trend",] ## aicc delta_aicc weight_aicc log.lik param ## -298.000 0.000 0.661 152.100 3.000 ## theta.1 omega ancestral state sigma squared alpha ## NA NA 3.255 0.001 NA ## optima.1 trend eb ## NA 0.007 NA This show a positive trend (0.007) of increasing disparity through time. 4.7.2 Plot and run simulation tests in a single step 4.7.2.1 model.test.wrapper Patterns of evolution can be fit using model.test, but the model.test.wrapper fits the same models as model.test as well as running predictive tests and plots. The predictive tests use the maximum likelihood estimates of model parameters to simulate a number of datasets (default = 1000), and analyse whether this is significantly different to the empirical input data using the Rank Envelope test (Murrell 2018). Finally we can plot the empirical data, simulated data, and the Rank Envelope test p values. This can all be done using the function model.test.wrapper, and we will set the argument show.p = TRUE so p values from the Rank Envelope test are printed on the plot: disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB"), show.p = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 ## Running BM model...Done. Log-likelihood = 149.289 ## Running OU model...Done. Log-likelihood = 152.119 ## Running Trend model...Done. Log-likelihood = 152.116 ## Running EB model...Done. Log-likelihood = 126.268 Figure 4.3: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for Trend, OU, BM, EB, and Stasis models disp_time ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Trend -298 0.0 0.661 152.1 3 NA NA 3.255 ## OU -296 2.1 0.227 152.1 4 NA NA 3.254 ## BM -294 3.6 0.112 149.3 2 NA NA 3.267 ## EB -246 51.7 0.000 126.3 3 NA NA 4.092 ## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA ## sigma squared alpha optima.1 trend eb median p value lower p value ## Trend 0.001 NA NA 0.007 NA 0.978021978 0.9760240 ## OU 0.001 0.001 12.35 NA NA 0.978021978 0.9770230 ## BM 0.001 NA NA NA NA 0.143856144 0.1368631 ## EB 0.000 NA NA NA -0.032 0.000999001 0.0000000 ## Stasis NA NA NA NA NA 1.000000000 0.9990010 ## upper p value ## Trend 0.9780220 ## OU 0.9780220 ## BM 0.1878122 ## EB 0.1368631 ## Stasis 1.0000000 From this plot we can see the empirical estimates of disparity through time (pink) compared to the predictive data based upon the simulations using the estimated parameters from each model. There is no significant differences between the empirical data and simulated data, except for the Early Burst model. Trend is the best-fitting model but the plot suggests the OU model also follows a trend-like pattern. This is because the optima for the OU model (12.35) is different to the ancestral state (3.254) and outside the observed value. This is potentially unrealistic, and one way to alleviate this issue is to set the optima of the OU model to equal the ancestral estimate - this is the normal practice for OU models in comparative phylogenetics. To set the optima to the ancestral value we change the argument fixed.optima = TRUE: disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB"), show.p = TRUE, fixed.optima = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 ## Running BM model...Done. Log-likelihood = 149.289 ## Running OU model...Done. Log-likelihood = 149.289 ## Running Trend model...Done. Log-likelihood = 152.116 ## Running EB model...Done. Log-likelihood = 126.268 Figure 4.4: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for Trend, OU, BM, EB, and Stasis models with the optima of the OU model set to equal the ancestral value disp_time ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Trend -298 0.0 0.814 152.1 3 NA NA 3.255 ## BM -294 3.6 0.138 149.3 2 NA NA 3.267 ## OU -292 5.7 0.048 149.3 3 NA NA 3.267 ## EB -246 51.7 0.000 126.3 3 NA NA 4.092 ## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA ## sigma squared alpha trend eb median p value lower p value ## Trend 0.001 NA 0.007 NA 0.984015984 0.9820180 ## BM 0.001 NA NA NA 0.256743257 0.2487512 ## OU 0.001 0 NA NA 0.293706294 0.2917083 ## EB 0.000 NA NA -0.032 0.000999001 0.0000000 ## Stasis NA NA NA NA 0.999000999 0.9980020 ## upper p value ## Trend 0.9840160 ## BM 0.2797203 ## OU 0.3166833 ## EB 0.1378621 ## Stasis 0.9990010 The relative fit of the OU model is decreased by constraining the fit of the optima to equal the ancestral state value. In fact as the OU attraction parameter (alpha) is zero, the model is equal to a Brownian motion model but is penalised by having an extra parameter. Note that indeed, the plots of the BM model and the OU model look nearly identical. 4.7.3 Multiple modes of evolution (time shifts) As well as fitting a single model to a sequence of disparity values we can also allow for the mode of evolution to shift at a single or multiple points in time. The timing of a shift in mode can be based on an a prior expectation, such as a mass extinction event, or the model can test multiple points to allow to find time shift point with the highest likelihood. Models can be fit using model.test but it can be more convenient to use model.test.wrapper. Here we will compare the relative fit of Brownian motion, Trend, Ornstein-Uhlenbeck and a multi-mode Ornstein Uhlenbck model in which the optima changes at 66 million years ago, the Cretaceous-Palaeogene boundary. For example, we could be testing the hypothesis that the extinction of non-avian dinosaurs allowed mammals to go from scurrying in the undergrowth (low optima/low disparity) to dominating all habitats (high optima/high disparity). We will constrain the optima of OU model in the first time begin (i.e, pre-66 Mya) to equal the ancestral value: disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("BM", "Trend", "OU", "multi.OU"), time.split = 66, pool.variance = NULL, show.p = TRUE, fixed.optima = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running BM model...Done. Log-likelihood = 149.289 ## Running Trend model...Done. Log-likelihood = 152.116 ## Running OU model...Done. Log-likelihood = 149.289 ## Running multi.OU model...Done. Log-likelihood = 151.958 Figure 4.5: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for BM, Trend, OU, and multi OU models with a shift in optima allowed at 66 Ma disp_time ## aicc delta_aicc weight_aicc log.lik param ancestral state ## Trend -298 0.000 0.657 152.1 3 3.255 ## multi.OU -296 2.456 0.193 152.0 4 3.253 ## BM -294 3.550 0.111 149.3 2 3.267 ## OU -292 5.654 0.039 149.3 3 3.267 ## sigma squared trend alpha optima.2 median p value lower p value ## Trend 0.001 0.007 NA NA 0.9870130 0.9860140 ## multi.OU 0.001 NA 0.006 4.686 0.9570430 0.9560440 ## BM 0.001 NA NA NA 0.1868132 0.1808192 ## OU 0.001 NA 0.000 NA 0.2727273 0.2707293 ## upper p value ## Trend 0.9870130 ## multi.OU 0.9590410 ## BM 0.2207792 ## OU 0.3016983 The multi-OU model shows an increase an optima at the Cretaceous-Palaeogene boundary, indicating a shift in disparity. However, this model does not fit as well as a model in which there is an increasing trend through time. We can also fit a model in which the we specify a heterogeneous model but we do not give a time.split. In this instance the model will test all splits that have at least 10 time slices on either side of the split. That’s 102 potential time shifts in this example dataset so be warned, the following code will estimate 105 models! ## An example of a time split model in which all potential splits are tested ## WARNING: this will take between 20 minutes and half and hour to run! disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("BM", "Trend", "OU", "multi.OU"), show.p = TRUE, fixed.optima = TRUE) As well as specifying a multi-OU model we can run any combination of models. For example we could fit a model at the Cretaceous-Palaeogene boundary that goes from an OU to a BM model, a Trend to an OU model, a Stasis to a Trend model or any combination you want to use. The only model that can’t be used in combination is a multi-OU model. These can be introduced by changing the input for the models into a list, and supplying a vector with the two models. This is easier to see with an example: ## The models to test my_models <- list(c("BM", "OU"), c("Stasis", "OU"), c("BM", "Stasis"), c("OU", "Trend"), c("Stasis", "BM")) ## Testing the models disp_time <- model.test.wrapper(data = BeckLee_disparity, model = my_models, time.split = 66, show.p = TRUE, fixed.optima = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running BM:OU model...Done. Log-likelihood = 144.102 ## Running Stasis:OU model...Done. Log-likelihood = 125.066 ## Running BM:Stasis model...Done. Log-likelihood = 69.265 ## Running OU:Trend model...Done. Log-likelihood = 147.839 ## Running Stasis:BM model...Done. Log-likelihood = 125.066 Figure 4.6: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for a variety of models with a shift in optima allowed at 66 Ma disp_time ## aicc delta_aicc weight_aicc log.lik param ancestral state ## OU:Trend -287 0.0 0.977 147.8 4 3.352 ## BM:OU -280 7.5 0.023 144.1 4 3.350 ## Stasis:BM -244 43.4 0.000 125.1 3 NA ## Stasis:OU -240 47.7 0.000 125.1 5 NA ## BM:Stasis -130 157.1 0.000 69.3 4 3.268 ## sigma squared alpha optima.1 theta.1 omega trend median p value ## OU:Trend 0.001 0.041 NA NA NA 0.011 0.2987013 ## BM:OU 0.001 0.000 4.092 NA NA NA 0.4925075 ## Stasis:BM 0.002 NA NA 3.390 0.004 NA 0.9970030 ## Stasis:OU 0.002 0.000 4.092 3.390 0.004 NA 1.0000000 ## BM:Stasis 0.000 NA NA 3.806 0.058 NA 1.0000000 ## lower p value upper p value ## OU:Trend 0.2947053 0.3536464 ## BM:OU 0.4875125 0.5134865 ## Stasis:BM 0.9960040 0.9970030 ## Stasis:OU 0.9990010 1.0000000 ## BM:Stasis 0.9990010 1.0000000 4.7.4 model.test.sim Note that all the models above where run using the model.test.wrapper function that is a… wrapping function! In practice, this function runs two main functions from the dispRity package and then plots the results: model.test and model.test.sim The model.test.sim allows to simulate disparity evolution given a dispRity object input (as in model.test.wrapper) or given a model and its specification. For example, it is possible to simulate a simple Brownian motion model (or any of the other models or models combination described above): ## A simple BM model model_simulation <- model.test.sim(sim = 1000, model = "BM", time.span = 50, variance = 0.1, sample.size = 100, parameters = list(ancestral.state = 0)) model_simulation ## Disparity evolution model simulation: ## Call: model.test.sim(sim = 1000, model = "BM", time.span = 50, variance = 0.1, sample.size = 100, parameters = list(ancestral.state = 0)) ## ## Model simulated (1000 times): ## [1] "BM" This will simulate 1000 Brownian motions for 50 units of time with 100 sampled elements, a variance of 0.1 and an ancestral state of 0. We can also pass multiple models in the same way we did it for model.test This model can then be summarised and plotted as most dispRity objects: ## Displaying the 5 first rows of the summary head(summary(model_simulation)) ## subsets n var median 2.5% 25% 75% 97.5% ## 1 50 100 0.1 -0.06195918 -1.963569 -0.7361336 0.5556715 1.806730 ## 2 49 100 0.1 -0.09905061 -2.799025 -1.0670018 0.8836605 2.693583 ## 3 48 100 0.1 -0.06215828 -3.594213 -1.3070097 1.1349712 3.272569 ## 4 47 100 0.1 -0.10602238 -3.949521 -1.4363010 1.2234625 3.931000 ## 5 46 100 0.1 -0.09016928 -4.277897 -1.5791755 1.3889584 4.507491 ## 6 45 100 0.1 -0.13183180 -5.115647 -1.7791878 1.6270527 5.144023 ## Plotting the simulations plot(model_simulation) Figure 4.7: A simulated Brownian motion Note that these functions can take all the arguments that can be passed to plot, summary, plot.dispRity and summary.dispRity. 4.7.4.1 Simulating tested models Maybe more interestingly though, it is possible to pass the output of model.test directly to model.test.sim to simulate the models that fits the data the best and calculate the Rank Envelope test p value. Let’s see that using the simple example from the start: ## Fitting multiple models on the data set disp_time <- model.test(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB")) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -18.694 ## Running BM model...Done. Log-likelihood = 149.289 ## Running OU model...Done. Log-likelihood = 152.119 ## Running Trend model...Done. Log-likelihood = 152.116 ## Running EB model...Done. Log-likelihood = 126.268 summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Stasis 41 339.5 0.000 -18.7 2 3.629 0.074 NA ## BM -294 3.6 0.112 149.3 2 NA NA 3.267 ## OU -296 2.1 0.227 152.1 4 NA NA 3.254 ## Trend -298 0.0 0.661 152.1 3 NA NA 3.255 ## EB -246 51.7 0.000 126.3 3 NA NA 4.092 ## sigma squared alpha optima.1 trend eb ## Stasis NA NA NA NA NA ## BM 0.001 NA NA NA NA ## OU 0.001 0.001 12.35 NA NA ## Trend 0.001 NA NA 0.007 NA ## EB 0.000 NA NA NA -0.032 As seen before, the Trend model fitted this dataset the best. To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with model.test (here the ancestral state being 3.255, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to model.test.sim: ## Simulating 1000 Trend model with the observed parameters sim_trend <- model.test.sim(sim = 1000, model = disp_time) sim_trend ## Disparity evolution model simulation: ## Call: model.test.sim(sim = 1000, model = disp_time) ## ## Model simulated (1000 times): ## aicc log.lik param ancestral state sigma squared trend ## Trend -298 152.1 3 3.255 0.001 0.007 ## ## Rank envelope test: ## p-value of the global test: 0.99001 (ties method: erl) ## p-interval : (0.989011, 0.99001) By default, the model simulated is the one with the lowest AICc (model.rank = 1) but it is possible to choose any ranked model, for example, the OU (second one): ## Simulating 1000 OU model with the observed parameters sim_OU <- model.test.sim(sim = 1000, model = disp_time, model.rank = 2) sim_OU ## Disparity evolution model simulation: ## Call: model.test.sim(sim = 1000, model = disp_time, model.rank = 2) ## ## Model simulated (1000 times): ## aicc log.lik param ancestral state sigma squared alpha optima.1 ## OU -296 152.1 4 3.254 0.001 0.001 12.35 ## ## Rank envelope test: ## p-value of the global test: 0.992008 (ties method: erl) ## p-interval : (0.99001, 0.992008) And as the example above, the simulated data can be plotted or summarised: head(summary(sim_trend)) ## subsets n var median 2.5% 25% 75% 97.5% ## 1 120 5 0.01723152 3.255121 3.135057 3.219150 3.293407 3.375118 ## 2 119 5 0.03555816 3.265538 3.093355 3.200493 3.323520 3.440795 ## 3 118 6 0.03833089 3.269497 3.090438 3.212015 3.329629 3.443074 ## 4 117 7 0.03264826 3.279180 3.112205 3.224810 3.336801 3.447997 ## 5 116 7 0.03264826 3.284500 3.114788 3.223247 3.347970 3.463631 ## 6 115 7 0.03264826 3.293918 3.101298 3.231659 3.354321 3.474645 head(summary(sim_OU)) ## subsets n var median 2.5% 25% 75% 97.5% ## 1 120 5 0.01723152 3.253367 3.141471 3.212180 3.293760 3.371622 ## 2 119 5 0.03555816 3.263167 3.083477 3.197442 3.324438 3.440447 ## 3 118 6 0.03833089 3.262952 3.101351 3.203860 3.332595 3.440163 ## 4 117 7 0.03264826 3.272569 3.104476 3.214511 3.330587 3.442792 ## 5 116 7 0.03264826 3.280423 3.100220 3.219765 3.342726 3.475877 ## 6 115 7 0.03264826 3.287359 3.094699 3.222523 3.355278 3.477518 ## The trend model with some graphical options plot(sim_trend, xlab = "Time (Mya)", ylab = "sum of variances", col = c("#F65205", "#F38336", "#F7B27E")) ## Adding the observed disparity through time plot(BeckLee_disparity, add = TRUE, col = c("#3E9CBA", "#98D4CF90", "#BFE4E390")) Figure 4.8: The best fitted model (Trend) and the observed disparity through time 4.8 Disparity as a distribution Disparity is often regarded as a summary value of the position of the all elements in the ordinated space. For example, the sum of variances, the product of ranges or the median distance between the elements and their centroid will summarise disparity as a single value. This value can be pseudo-replicated (bootstrapped) to obtain a distribution of the summary metric with estimated error. However, another way to perform disparity analysis is to use the whole distribution rather than just a summary metric (e.g. the variances or the ranges). This is possible in the dispRity package by calculating disparity as a dimension-level 2 metric only! Let’s have a look using our previous example of bootstrapped time slices but by measuring the distances between each taxon and their centroid as disparity. ## Measuring disparity as a whole distribution disparity_centroids <- dispRity(boot_time_slices, metric = centroids) The resulting disparity object is of dimension-level 2, so it can easily be transformed into a dimension-level 1 object by, for example, measuring the median distance of all these distributions: ## Measuring median disparity in each time slice disparity_centroids_median <- dispRity(disparity_centroids, metric = median) And we can now compare the differences between these methods: ## Summarising both disparity measurements: ## The distributions: summary(disparity_centroids) ## subsets n obs.median bs.median 2.5% 25% 75% 97.5% ## 1 120 5 1.605 1.376 0.503 1.247 1.695 1.895 ## 2 80 19 1.834 1.774 1.514 1.691 1.853 1.968 ## 3 40 15 1.804 1.789 1.468 1.684 1.889 2.095 ## 4 0 10 1.911 1.809 1.337 1.721 1.968 2.099 ## The summary of the distributions (as median) summary(disparity_centroids_median) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 120 5 1.605 1.395 0.503 0.994 1.625 1.686 ## 2 80 19 1.834 1.774 1.682 1.749 1.799 1.823 ## 3 40 15 1.804 1.790 1.579 1.750 1.830 1.875 ## 4 0 10 1.911 1.812 1.659 1.784 1.859 1.930 We can see that the summary message for the distribution is slightly different than before. Here summary also displays the observed central tendency (i.e. the central tendency of the measured distributions). Note that, as expected, this central tendency is the same in both metrics! Another, maybe more intuitive way, to compare both approaches for measuring disparity is to plot the distributions: ## Graphical parameters op <- par(bty = "n", mfrow = c(1, 2)) ## Plotting both disparity measurements plot(disparity_centroids, ylab = "Distribution of all the distances") plot(disparity_centroids_median, ylab = "Distribution of the medians of all the distances") par(op) We can then test for differences in the resulting distributions using test.dispRity and the bhatt.coeff test as described above. ## Probability of overlap in the distribution of medians test.dispRity(disparity_centroids_median, test = bhatt.coeff) ## bhatt.coeff ## 120 : 80 0.09486833 ## 120 : 40 0.18256185 ## 120 : 0 0.18800657 ## 80 : 40 0.80759884 ## 80 : 0 0.71503765 ## 40 : 0 0.84542569 In this case, we are looking at the probability of overlap of the distribution of median distances from centroids among each pair of time slices. In other words, we are measuring whether the medians from each bootstrap pseudo-replicate for each time slice overlap. But of course, we might be interested in the actual distribution of the distances from the centroid rather than simply their central tendencies. This can be problematic depending on the research question asked since we are effectively comparing non-independent medians distributions (because of the pseudo-replication). One solution, therefore, is to look at the full distribution: ## Probability of overlap for the full distributions test.dispRity(disparity_centroids, test = bhatt.coeff) ## bhatt.coeff ## 120 : 80 0.6088450 ## 120 : 40 0.6380217 ## 120 : 0 0.6340849 ## 80 : 40 0.9325982 ## 80 : 0 0.8614280 ## 40 : 0 0.9464329 These results show the actual overlap among all the measured distances from centroids concatenated across all the bootstraps. For example, when comparing the slices 120 and 80, we are effectively comparing the 5 \\(\\times\\) 100 distances (the distances of the five elements in slice 120 bootstrapped 100 times) to the 19 \\(\\times\\) 100 distances from slice 80. However, this can also be problematic for some specific tests since the n \\(\\times\\) 100 distances are also pseudo-replicates and thus are still not independent. A second solution is to compare the distributions to each other for each replicate: ## Boostrapped probability of overlap for the full distributions test.dispRity(disparity_centroids, test = bhatt.coeff, concatenate = FALSE) ## bhatt.coeff 2.5% 25% 75% 97.5% ## 120 : 80 0.2641856 0.0000000 0.1450953 0.3964076 0.5468831 ## 120 : 40 0.2705336 0.0000000 0.1632993 0.3987346 0.6282038 ## 120 : 0 0.2841992 0.0000000 0.2000000 0.4000000 0.7083356 ## 80 : 40 0.6024121 0.3280389 0.4800810 0.7480791 0.8902989 ## 80 : 0 0.4495822 0.1450953 0.3292496 0.5715531 0.7332155 ## 40 : 0 0.5569422 0.2000000 0.4543681 0.6843217 0.8786504 These results show the median overlap among pairs of distributions in the first column (bhatt.coeff) and then the distribution of these overlaps among each pair of bootstraps. In other words, when two distributions are compared, they are now compared for each bootstrap pseudo-replicate, thus effectively creating a distribution of probabilities of overlap. For example, when comparing the slices 120 and 80, we have a mean probability of overlap of 0.28 and a probability between 0.18 and 0.43 in 50% of the pseudo-replicates. Note that the quantiles and central tendencies can be modified via the conc.quantiles option. 4.9 Disparity from other matrices In the example so far, disparity was measured from an ordinated multidimensional space (i.e. a PCO of the distances between taxa based on discrete morphological characters). This is a common approach in palaeobiology, morphometrics or ecology but ordinated matrices are not mandatory for the dispRity package! It is totally possible to perform the same analysis detailed above using other types of matrices as long as your elements are rows in your matrix. For example, we can use the data set eurodist, an R inbuilt dataset that contains the distances (in km) between European cities. We can check for example, if Northern European cities are closer to each other than Southern ones: ## Making the eurodist data set into a matrix (rather than "dist" object) eurodist <- as.matrix(eurodist) eurodist[1:5, 1:5] ## Athens Barcelona Brussels Calais Cherbourg ## Athens 0 3313 2963 3175 3339 ## Barcelona 3313 0 1318 1326 1294 ## Brussels 2963 1318 0 204 583 ## Calais 3175 1326 204 0 460 ## Cherbourg 3339 1294 583 460 0 ## The two groups of cities Northern <- c("Brussels", "Calais", "Cherbourg", "Cologne", "Copenhagen", "Hamburg", "Hook of Holland", "Paris", "Stockholm") Southern <- c("Athens", "Barcelona", "Geneva", "Gibraltar", "Lisbon", "Lyons", "Madrid", "Marseilles", "Milan", "Munich", "Rome", "Vienna") ## Creating the subset dispRity object eurodist_subsets <- custom.subsets(eurodist, group = list("Northern" = Northern, "Southern" = Southern)) ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! ## Bootstrapping and rarefying to 9 elements (the number of Northern cities) eurodist_bs <- boot.matrix(eurodist_subsets, rarefaction = 9) ## Measuring disparity as the median distance from group's centroid euro_disp <- dispRity(eurodist_bs, metric = c(median, centroids)) ## Testing the differences using a simple wilcox.test euro_diff <- test.dispRity(euro_disp, test = wilcox.test) euro_diff_rar <- test.dispRity(euro_disp, test = wilcox.test, rarefaction = 9) We can compare this approach to an ordination one: ## Ordinating the eurodist matrix (with 11 dimensions) euro_ord <- cmdscale(eurodist, k = 11) ## Calculating disparity on the bootstrapped and rarefied subset data euro_ord_disp <- dispRity(boot.matrix(custom.subsets(euro_ord, group = list("Northern" = Northern, "Southern" = Southern)), rarefaction = 9), metric = c(median, centroids)) ## Testing the differences using a simple wilcox.test euro_ord_diff <- test.dispRity(euro_ord_disp, test = wilcox.test) euro_ord_diff_rar <- test.dispRity(euro_ord_disp, test = wilcox.test, rarefaction = 9) And visualise the differences: ## Plotting the differences par(mfrow = c(2,2), bty = "n") ## Plotting the normal disparity plot(euro_disp, main = "Distance differences") ## Adding the p-value text(1.5, 4000, paste0("p=",round(euro_diff[[2]][[1]], digit = 5))) ## Plotting the rarefied disparity plot(euro_disp, rarefaction = 9, main = "Distance differences (rarefied)") ## Adding the p-value text(1.5, 4000, paste0("p=",round(euro_diff_rar[[2]][[1]], digit = 5))) ## Plotting the ordinated disparity plot(euro_ord_disp, main = "Ordinated differences") ## Adding the p-value text(1.5, 1400, paste0("p=",round(euro_ord_diff[[2]][[1]], digit = 5) )) ## Plotting the rarefied disparity plot(euro_ord_disp, rarefaction = 9, main = "Ordinated differences (rarefied)") ## Adding the p-value text(1.5, 1400, paste0("p=",round(euro_ord_diff_rar[[2]][[1]], digit = 5) )) As expected, the results are pretty similar in pattern but different in terms of scale. The median centroids distance is expressed in km in the “Distance differences” plots and in Euclidean units of variation in the “Ordinated differences” plots. 4.10 Disparity from multiple matrices (and multiple trees!) Since the version 1.4 of this package, it is possible to use multiple trees and multiple matrices in dispRity objects. To use multiple matrices, this is rather easy: just supply a list of matrices to any of the dispRity functions and, as long as they have the same size and the same rownames they will be handled as a distribution of matrices. set.seed(1) ## Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...) matrix_list <- replicate(3, matrix(rnorm(40), 10, 4, dimnames = list(paste0("t", 1:10))), simplify = FALSE) class(matrix_list) # This is a list of matrices ## [1] "list" ## Measuring some disparity metric on one of the matrices summary(dispRity(matrix_list[[1]], metric = c(sum, variances))) ## subsets n obs ## 1 1 10 3.32 ## Measuring the same disparity metric on the three matrices summary(dispRity(matrix_list, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 3.32 3.044 3.175 3.381 3.435 As you can see, when measuring the sum of variances on multiple matrices, we now have a distribution of sum of variances rather than a single observed value. Similarly as running disparity analysis using multiple matrices, you can run the chrono.subsets function using multiple trees. This can be useful if you want to use a tree posterior distribution rather than a single consensus tree. These trees can be passed to chrono.subsets as a \"multiPhylo\" object (with the same node and tip labels in each tree). First let’s define a function to generate multiple trees with the same labels and root ages: set.seed(1) ## Matches the trees and the matrices ## A bunch of trees make.tree <- function(n, fun = rtree) { ## Make the tree tree <- fun(n) tree <- chronos(tree, quiet = TRUE, calibration = makeChronosCalib(tree, age.min = 10, age.max = 10)) class(tree) <- "phylo" ## Add the node labels tree$node.label <- paste0("n", 1:Nnode(tree)) ## Add the root time tree$root.time <- max(tree.age(tree)$ages) return(tree) } trees <- replicate(3, make.tree(10), simplify = FALSE) class(trees) <- "multiPhylo" trees ## 3 phylogenetic trees We can now simulate some ancestral states for the matrices in the example above to have multiple matrices associated with the multiple trees. ## A function for running the ancestral states estimations do.ace <- function(tree, matrix) { ## Run one ace fun.ace <- function(character, tree) { results <- ace(character, phy = tree)$ace names(results) <- paste0("n", 1:Nnode(tree)) return(results) } ## Run all ace return(rbind(matrix, apply(matrix, 2, fun.ace, tree = tree))) } ## All matrices matrices <- mapply(do.ace, trees, matrix_list, SIMPLIFY = FALSE) Let’s first see an example of time-slicing with one matrix and multiple trees. This assumes that your tip values (observed) and node values (estimated) are fixed with no error on them. It also assumes that the nodes in the matrix always corresponds to the node in the trees (in other words, the tree topologies are fixed): ## Making three "proximity" time slices across one tree one_tree <- chrono.subsets(matrices[[1]], trees[[1]], method = "continuous", model = "proximity", time = 3) ## Making three "proximity" time slices across the three trees three_tree <- chrono.subsets(matrices[[1]], trees, method = "continuous", model = "proximity", time = 3) ## Measuring disparity as the sum of variances and summarising it summary(dispRity(one_tree, metric = c(sum, variances))) ## subsets n obs ## 1 8.3 3 0.079 ## 2 4.15 5 2.905 ## 3 0 10 3.320 summary(dispRity(three_tree, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 7.9 3 0.253 0.088 0.166 0.309 0.360 ## 2 3.95 5 0.257 0.133 0.192 1.581 2.773 ## 3 0 10 3.320 3.320 3.320 3.320 3.320 This results show the effect of considering a tree distribution: in the first case (one_tree) the time slice at 3.95 Mya has a sum of variances of 2.9 but this values goes down to 0.256 in the second case (three_tree) which is due to the differences in branch lengths distributions: par(mfrow = c(3,1)) slices <- c(7.9, 3.95, 0) fun.plot <- function(tree) { plot(tree) nodelabels(tree$node.label, cex = 0.8) axisPhylo() abline(v = tree$root.time - slices) } silent <- lapply(trees, fun.plot) Note that in this example, the nodes are actually even different in each tree! The node n4 for example, is not direct descendent of t4 and t6 in all trees! To fix that, it is possible to input a list of trees and a list of matrices that correspond to each tree in chrono.subsets by using the bind.data = TRUE option. In this case, the matrices need to all have the same row names and the trees all need the same labels as before: ## Making three "proximity" time slices across three trees and three bound matrices bound_data <- chrono.subsets(matrices, trees, method = "continuous", model = "proximity", time = 3, bind.data = TRUE) ## Making three "proximity" time slices across three trees and three matrices unbound_data <- chrono.subsets(matrices, trees, method = "continuous", model = "proximity", time = 3, bind.data = FALSE) ## Measuring disparity as the sum of variances and summarising it summary(dispRity(bound_data, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 7.9 3 0.079 0.076 0.077 0.273 0.447 ## 2 3.95 5 1.790 0.354 1.034 2.348 2.850 ## 3 0 10 3.320 3.044 3.175 3.381 3.435 summary(dispRity(unbound_data, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 7.9 3 0.79 0.48 0.63 0.83 0.85 ## 2 3.95 5 3.25 1.36 2.25 3.94 4.56 ## 3 0 10 9.79 9.79 9.79 9.79 9.79 Note here that the results are again rather different: with the bound data, the slices are done across the three trees and each of their corresponding matrix (resulting in three observation) which is more accurate than the previous results from three_trees above. With the unbound data, the slices are done across the three trees and applied to the three matrices (resulting in 9 observations). As we’ve seen before, this is incorrect in this case since the trees don’t have the same topology (so the nodes selected by a slice through the second tree are not equivalent to the nodes in the first matrix) but it can be useful if the topology is fixed to integrate both uncertainty in branch length (slicing through different trees) and uncertainty from, say, ancestral states estimations (applying the slices on different matrices). Note that since the version 1.8 the trees and the matrices don’t have to match allowing to run disparity analyses with variable matrices and trees. This can be useful when running ancestral states estimations from a tree distribution where not all trees have the same topology. 4.11 Disparity with trees: dispRitree! Since the package’s version 1.5.10, trees can be directly attached to dispRity objects. This allows any function in the package that has an input argument called “tree” to automatically intake the tree from the dispRity object. This is especially useful for disparity metrics that requires calculations based on a phylogenetic tree (e.g. ancestral.dist or projections.tree) and if phylogeny (or phylogenie*s*) are going to be an important part of your analyses. Trees are attached to dispRity object as soon as they are called in any function of the package (e.g. as an argument in chrono.subsets or in dispRity) and are stored in my_dispRity_object$tree. You can always manually attach, detach or modify the tree parts of a dispRity object using the utility functions get.tree (to access the trees), remove.tree (to remove it) and add.tree (to… add trees!). The only requirement for this to work is that the labels in the tree must match the ones in the data. If the tree has node labels, their node labels must also match the data. Similarly if the data has entries for node labels, they must be present in the tree. Here is a quick demo on how attaching trees to dispRity objects can work and make your life easy: for example here we will measure how the sum of branch length changes through time when time slicing through some demo data with a acctran split time slice model (see more info here). ## Loading some demo data: ## An ordinated matrix with node and tip labels data(BeckLee_mat99) ## The corresponding tree with tip and node labels data(BeckLee_tree) ## A list of tips ages for the fossil data data(BeckLee_ages) ## Time slicing through the tree using the equal split algorithm time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, FADLAD = BeckLee_ages, method = "continuous", model = "acctran", time = 15) ## We can visualise the resulting trait space with the phylogeny ## (using the specific argument as follows) plot(time_slices, type = "preview", specific.args = list(tree = TRUE)) ## Note that some nodes are never selected thus explaining the branches not reaching them. And we can then measure disparity as the sum of the edge length at each time slice on the bootstrapped data: ## Measuring the sum of the edge length per slice sum_edge_length <- dispRity(boot.matrix(time_slices), metric = c(sum, edge.length.tree)) ## Summarising and plotting summary(sum_edge_length) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 133.51 3 51 51 36 40 61 69 ## 2 123.97 6 163 166 141 158 172 188 ## 3 114.44 9 332 331 287 317 354 383 ## 4 104.9 12 558 565 489 540 587 620 ## 5 95.37 15 762 763 723 745 782 815 ## 6 85.83 20 1303 1305 1218 1271 1342 1415 ## 7 76.29 19 1565 1559 1408 1491 1620 1802 ## 8 66.76 23 2055 2040 1865 1965 2095 2262 ## 9 57.22 20 2029 2031 1842 1949 2091 2190 ## 10 47.68 16 1908 1892 1727 1840 1945 2057 ## 11 38.15 16 2017 2016 1910 1975 2081 2152 ## 12 28.61 10 1391 1391 1391 1391 1391 1391 ## 13 19.07 10 1391 1391 1391 1391 1391 1391 ## 14 9.54 10 1391 1391 1391 1391 1391 1391 ## 15 0 10 1391 1391 1391 1391 1391 1391 plot(sum_edge_length) Of course this can be done with multiple trees and be combined with an approach using multiple matrices (see here)! 4.12 Disparity of variance-covariance matrices (covar) Variance-covariance matrices are sometimes a useful way to summarise multidimensional data. In fact, you can express the variation in your multidimensional dataset directly in terms of how your trait covary rather than simply the positions of your elements in the trait space. Furthermore, variance-covariance matrices can be estimated from multidimensional in sometimes more useful ways that simply looking at the the data in your trait space. This can be done by describing your data as hierarchical models like generalised linear mixed effect models (glmm). For example, you might have a multidimensional dataset where your observations have a nested structure (e.g. they are part of the same phylogeny). You can then analyse this data using a glmm with something like my_data ~ observations + phylogeny + redisduals. For more info on these models start here. For more details on running these models, I suggest using the MCMCglmm package (Hadfield (2010a)) from Hadfield (2010b) (but see also Guillerme and Healy (2014)). 4.12.1 Creating a dispRity object with a $covar component Once you have a trait space and variance-covariance matrices output from the MCMCglmm model, you can use the function MCMCglmm.subsets to create a \"dispRity\" object that contains the classic \"dispRity\" data (the matrix, the subsets, etc…) but also a the new $covar element: ## Loading the charadriiformes data data(charadriiformes) Here we using precaculated variance-covariance matrices from the charadriiformes dataset that contains a set of posteriors from a MCMCglmm model. The model here was data ~ traits + clade specific phylogenetic effect + global phylogenetic effect + residuals. We can retrieve the model information using the MCMCglmm utilities tools, namely the MCMCglmm.levels function to directly extract the terms names as used in the model and then build our \"dispRity\" object with the correct data, the posteriors and the correct term names: ## The term names model_terms <- MCMCglmm.levels(charadriiformes$posteriors)[1:4] ## Note that we're ignoring the 5th term of the model that's just the normal residuals ## The dispRity object MCMCglmm.subsets(data = charadriiformes$data, posteriors = charadriiformes$posteriors, group = model_terms) ## ---- dispRity object ---- ## 4 covar subsets for 359 elements in one matrix with 3 dimensions: ## animal:clade_1, animal:clade_2, animal:clade_3, animal. ## Data is based on 1000 posterior samples. As you can see this creates a normal dispRity object with the information you are now familiar with. However, we can be more fancy and provide more understandable names for the groups and provide the underlying phylogenetic structure used: ## A fancier dispRity object my_covar <- MCMCglmm.subsets(data = charadriiformes$data, posteriors = charadriiformes$posteriors, group = model_terms, tree = charadriiformes$tree, rename.groups = c(levels(charadriiformes$data$clade), "phylogeny")) ## Note that the group names is contained in the clade column of the charadriiformes dataset as factors 4.12.2 Visualising covar objects One useful thing to do with these objects is then to visualise them in 2D. Here we can use the covar.plot function (that has many different options that just plot.dispRity for plotting covar objects) to plot the trait space, the 95% confidence interval ellipses of the variance-covariance matrices and the major axes from these ellipses. See the ?covar.plot help page for all the options available: par(mfrow = c(2,2)) ## The traitspace covar.plot(my_covar, col = c("orange", "darkgreen", "blue"), main = "Trait space") ## The traitspace's variance-covariance mean ellipses covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean VCV ellipses", points = FALSE, ellipses = mean) ## The traitspace's variance-covariance mean ellipses covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean major axes", points = FALSE, major.axes = mean) ## A bit of everything covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Ten random VCV matrices", points = TRUE, major.axes = TRUE, points.cex = 1/3, n = 10, ellipses = TRUE, legend = TRUE) 4.12.3 Disparity analyses with a $covar component You can then calculate disparity on the \"dispRity\" object like shown previously. For example, you can get the variances of the groups that where used in the model by using the normal dispRity function: summary(dispRity(my_covar, metric = variances)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 gulls 159 0.009 0.009 0.009 0.129 0.238 ## 2 plovers 98 0.008 0.003 0.005 0.173 0.321 ## 3 sandpipers 102 0.007 0.003 0.005 0.177 0.331 ## 4 phylogeny 359 0.023 0.007 0.015 0.166 0.294 However this is not applied on the variance-covariance matrices from the posteriors of the MCMCglmm. To do that, you need to modify the metric to be recognised as a “covar” metric using the as.covar function. This function transforms any disparity metric (or disparity metric style function) to be applied to the $covar part of a \"dispRity\" object. Basically this $covar part is a list containing, for each posterior sample $VCV, the variance-covariance matrix and $loc, it’s optional location in the traitspace. ## The first variance covariance matrix for the "gulls" group my_covar$covar[["gulls"]][[1]] ## $VCV ## [,1] [,2] [,3] ## [1,] 0.23258067 -2.180519e-02 -2.837630e-02 ## [2,] -0.02180519 3.137106e-02 -8.711996e-05 ## [3,] -0.02837630 -8.711996e-05 1.943929e-02 ## ## $loc ## [1] 0.0007118691 0.1338917465 -0.0145412698 And this is how as.covar modifies the disparity metric: ## Using the variances function on a VCV matrix variances(my_covar$covar[["gulls"]][[1]]$VCV) ## [1] 0.0221423147 0.0007148342 0.0005779815 ## The same but using it as a covar metric as.covar(variances)(my_covar$covar[["gulls"]][[1]]) ## [1] 0.0221423147 0.0007148342 0.0005779815 ## The same but applied to the dispRity function summary(dispRity(my_covar, metric = as.covar(variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 gulls 159 0.001 0 0 0.012 0.068 ## 2 plovers 98 0.000 0 0 0.000 0.002 ## 3 sandpipers 102 0.000 0 0 0.000 0.016 ## 4 phylogeny 359 0.000 0 0 0.006 0.020 References "],["making-stuff-up.html", "5 Making stuff up! 5.1 Simulating discrete morphological data 5.2 Simulating multidimensional spaces", " 5 Making stuff up! The dispRity package also offers some advanced data simulation features to allow to test hypothesis, explore ordinate-spaces or metrics properties or simply playing around with data! All the following functions are based on the same modular architecture of the package and therefore can be used with most of the functions of the package. 5.1 Simulating discrete morphological data The function sim.morpho allows to simulate discrete morphological data matrices (sometimes referred to as “cladistic” matrices). It allows to evolve multiple discrete characters on a given phylogenetic trees, given different models, rates, and states. It even allows to include “proper” inapplicable data to make datasets as messy as in real life! In brief, the function sim.morpho takes a phylogenetic tree, the number of required characters, the evolutionary model, and a function from which to draw the rates. The package also contains a function for quickly checking the matrix’s phylogenetic signal (as defined in systematics not phylogenetic comparative methods) using parsimony. The methods are described in details below set.seed(3) ## Simulating a starting tree with 15 taxa as a random coalescent tree my_tree <- rcoal(15) ## Generating a matrix with 100 characters (85% binary and 15% three state) and ## an equal rates model with a gamma rate distribution (0.5, 1) with no ## invariant characters. my_matrix <- sim.morpho(tree = my_tree, characters = 100, states = c(0.85, 0.15), rates = c(rgamma, 0.5, 1), invariant = FALSE) ## The first few lines of the matrix my_matrix[1:5, 1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## t10 "1" "0" "1" "0" "1" "0" "0" "1" "0" "0" ## t1 "0" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## t9 "0" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## t14 "1" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## t13 "1" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## Checking the matrix properties with a quick Maximum Parsimony tree search check.morpho(my_matrix, my_tree) ## ## Maximum parsimony 144.0000000 ## Consistency index 0.7430556 ## Retention index 0.9160998 ## Robinson-Foulds distance 2.0000000 Note that this example produces a tree with a great consistency index and an identical topology to the random coalescent tree! Nearly too good to be true… 5.1.1 A more detailed description The protocol implemented here to generate discrete morphological matrices is based on the ones developed in (Guillerme and Cooper 2016; O’Reilly et al. 2016; Puttick et al. 2017; E. et al., n.d.). The first tree argument will be the tree on which to “evolve” the characters and therefore requires branch length. You can generate quick and easy random Yule trees using ape::rtree(number_of_taxa) but I would advise to use more realistic trees for more realistic simulations based on more realistic models (really realistic then) using the function tree.bd from the diversitree package (FitzJohn 2012). The second argument, character is the number of characters. Pretty straight forward. The third, states is the proportion of characters states above two (yes, the minimum number of states is two). This argument intakes the proportion of n-states characters, for example states = c(0.5,0.3,0.2) will generate 50% of binary-state characters, 30% of three-state characters and 20% of four-state characters. There is no limit in the number of state characters proportion as long as the total makes up 100%. The forth, model is the evolutionary model for generating the character(s). More about this below. The fifth and sixth, rates and substitution are the model parameters described below as well. Finally, the two logical arguments, are self explanatory: invariant whether to allow invariant characters (i.e. characters that don’t change) and verbose whether to print the simulation progress on your console. 5.1.1.1 Available evolutionary models There are currently three evolutionary models implemented in sim.morpho but more will come in the future. Note also that they allow fine tuning parameters making them pretty plastic! \"ER\": this model allows any number of character states and is based on the Mk model (Lewis 2001). It assumes a unique overall evolutionary rate equal substitution rate between character states. This model is based on the ape::rTraitDisc function. \"HKY\": this is binary state character model based on the molecular HKY model (Hasegawa, Kishino, and Yano 1985). It uses the four molecular states (A,C,G,T) with a unique overall evolutionary rate and a biased substitution rate towards transitions (A <-> G or C <-> T) against transvertions (A <-> C and G <-> T). After evolving the nucleotide, this model transforms them into binary states by converting the purines (A and G) into state 0 and the pyrimidines (C and T) into state 1. This method is based on the phyclust::seq.gen.HKY function and was first proposed by O’Reilly et al. (2016). \"MIXED\": this model uses a random (uniform) mix between both the \"ER\" and the \"HKY\" models. The models can take the following parameters: (1) rates is the evolutionary rate (i.e. the rate of changes along a branch: the evolutionary speed) and (2) substitution is the frequency of changes between one state or another. For example if a character can have high probability of changing (the evolutionary rate) with, each time a change occurs a probability of changing from state X to state Y (the substitution rate). Note that in the \"ER\" model, the substitution rate is ignore because… by definition this (substitution) rate is equal! The parameters arguments rates and substitution takes a distributions from which to draw the parameters values for each character. For example, if you want an \"HKY\" model with an evolutionary rate (i.e. speed) drawn from a uniform distribution bounded between 0.001 and 0.005, you can define it as rates = c(runif, min = 0.001, max = 0.005), runif being the function for random draws from a uniform distribution and max and min being the distribution parameters. These distributions should always be passed in the format c(random_distribution_function, distribution_parameters) with the names of the distribution parameters arguments. 5.1.1.2 Checking the results An additional function, check.morpho runs a quick Maximum Parsimony tree search using the phangorn parsimony algorithm. It quickly calculates the parsimony score, the consistency and retention indices and, if a tree is provided (e.g. the tree used to generate the matrix) it calculates the Robinson-Foulds distance between the most parsimonious tree and the provided tree to determine how different they are. 5.1.1.3 Adding inapplicable characters Once a matrix is generated, it is possible to apply inapplicable characters to it for increasing realism! Inapplicable characters are commonly designated as NA or simply -. They differ from missing characters ? in their nature by being inapplicable rather than unknown(see Brazeau, Guillerme, and Smith 2018 for more details). For example, considering a binary character defined as “colour of the tail” with the following states “blue” and “red”; on a taxa with no tail, the character should be coded as inapplicable (“-”) since the state of the character “colour of tail” is known: it’s neither “blue” or “red”, it’s just not there! It contrasts with coding it as missing (“?” - also called as ambiguous) where the state is unknown, for example, the taxon of interest is a fossil where the tail has no colour preserved or is not present at all due to bad conservation! This type of characters can be added to the simulated matrices using the apply.NA function/ It takes, as arguments, the matrix, the source of inapplicability (NAs - more below), the tree used to generate the matrix and the two same invariant and verbose arguments as defined above. The NAs argument allows two types of sources of inapplicability: \"character\" where the inapplicability is due to the character (e.g. coding a character tail for species with no tail). In practice, the algorithm chooses a character X as the underlying character (e.g. “presence and absence of tail”), arbitrarily chooses one of the states as “absent” (e.g. 0 = absent) and changes in the next character Y any state next to character X state 0 into an inapplicable token (“-”). This simulates the inapplicability induced by coding the characters (i.e. not always biological). \"clade\" where the inapplicability is due to evolutionary history (e.g. a clade loosing its tail). In practice, the algorithm chooses a random clade in the tree and a random character Z and replaces the state of the taxa present in the clade by the inapplicable token (“-”). This simulates the inapplicability induced by evolutionary biology (e.g. the lose of a feature in a clade). To apply these sources of inapplicability, simply repeat the number of inapplicable sources for the desired number of characters with inapplicable data. ## Generating 5 "character" NAs and 10 "clade" NAs my_matrix_NA <- apply.NA(my_matrix, tree = my_tree, NAs = c(rep("character", 5), rep("clade", 10))) ## The first few lines of the resulting matrix my_matrix_NA[1:10, 90:100] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] ## t10 "-" "1" "1" "2" "1" "0" "0" "0" "1" "0" "0" ## t1 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t9 "-" "1" "1" "0" "1" "0" "0" "0" "-" "0" "0" ## t14 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t13 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t5 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t2 "1" "1" "0" "0" "1" "0" "0" "0" "0" "0" "0" ## t8 "2" "1" "0" "0" "1" "0" "0" "0" "0" "0" "0" ## t6 "-" "1" "1" "0" "0" "1" "1" "2" "0" "1" "1" ## t15 "-" "1" "1" "0" "0" "1" "1" "2" "0" "1" "1" 5.1.2 Parameters for a realistic(ish) matrix There are many parameters that can create a “realistic” matrix (i.e. not too different from the input tree with a consistency and retention index close to what is seen in the literature) but because of the randomness of the matrix generation not all parameters combination end up creating “good” matrices. The following parameters however, seem to generate fairly “realist” matrices with a starting coalescent tree, equal rates model with 0.85 binary characters and 0.15 three state characters, a gamma distribution with a shape parameter (\\(\\alpha\\)) of 5 and no scaling (\\(\\beta\\) = 1) with a rate of 100. set.seed(0) ## tree my_tree <- rcoal(15) ## matrix morpho_mat <- sim.morpho(my_tree, characters = 100, model = "ER", rates = c(rgamma, rate = 100, shape = 5), invariant = FALSE) check.morpho(morpho_mat, my_tree) ## ## Maximum parsimony 103.0000000 ## Consistency index 0.9708738 ## Retention index 0.9919571 ## Robinson-Foulds distance 4.0000000 5.2 Simulating multidimensional spaces Another way to simulate data is to directly simulate an ordinated space with the space.maker function. This function allows users to simulate multidimensional spaces with a certain number of properties. For example, it is possible to design a multidimensional space with a specific distribution on each axis, a correlation between the axes and a specific cumulative variance per axis. This can be useful for creating ordinated spaces for null hypothesis, for example if you’re using the function null.test (Dı́az et al. 2016). This function takes as arguments the number of elements (data points - elements argument) and dimensions (dimensions argument) to create the space and the distribution functions to be used for each axis. The distributions are passed through the distribution argument as… modular functions! You can either pass a single distribution function for all the axes (for example distribution = runif for all the axis being uniform) or a specific distribution function for each specific axis (for example distribution = c(runif, rnorm, rgamma)) for the first axis being uniform, the second normal and the third gamma). You can of course use your very own functions or use the ones implemented in dispRity for more complex ones (see below). Specific optional arguments for each of these distributions can be passed as a list via the arguments argument. Furthermore, it is possible to add a correlation matrix to add a correlation between the axis via the cor.matrix argument or even a vector of proportion of variance to be bear by each axis via the scree argument to simulate realistic ordinated spaces. Here is a simple two dimensional example: ## Graphical options op <- par(bty = "n") ## A square space square_space <- space.maker(100, 2, runif) ## The resulting 2D matrix head(square_space) ## [,1] [,2] ## [1,] 0.2878797 0.82110157 ## [2,] 0.5989886 0.72890558 ## [3,] 0.8401571 0.53042419 ## [4,] 0.3663870 0.75545936 ## [5,] 0.2122375 0.98768804 ## [6,] 0.9612441 0.07285561 ## Visualising the space plot(square_space, pch = 20, xlab = "", ylab = "", main = "Uniform 2D space") Of course, more complex spaces can be created by changing the distributions, their arguments or adding a correlation matrix or a cumulative variance vector: ## A plane space: uniform with one dimensions equal to 0 plane_space <- space.maker(2500, 3, c(runif, runif, runif), arguments = list(list(min = 0, max = 0), NULL, NULL)) ## Correlation matrix for a 3D space (cor_matrix <- matrix(cbind(1, 0.8, 0.2, 0.8, 1, 0.7, 0.2, 0.7, 1), nrow = 3)) ## [,1] [,2] [,3] ## [1,] 1.0 0.8 0.2 ## [2,] 0.8 1.0 0.7 ## [3,] 0.2 0.7 1.0 ## An ellipsoid space (normal space with correlation) ellipse_space <- space.maker(2500, 3, rnorm, cor.matrix = cor_matrix) ## A cylindrical space with decreasing axes variance cylindrical_space <- space.maker(2500, 3, c(rnorm, rnorm, runif), scree = c(0.7, 0.2, 0.1)) 5.2.1 Personalised dimensions distributions Following the modular architecture of the package, it is of course possible to pass home made distribution functions to the distribution argument. For example, the random.circle function is a personalised one implemented in dispRity. This function allows to create circles based on basic trigonometry allowing to axis to covary to produce circle coordinates. By default, this function generates two sets of coordinates with a distribution argument and a minimum and maximum boundary (inner and outer respectively) to create nice sharp edges to the circle. The maximum boundary is equivalent to the radius of the circle (it removes coordinates beyond the circle radius) and the minimum is equivalent to the radius of a smaller circle with no data (it removes coordinates below this inner circle radius). ## Graphical options op <- par(bty = "n") ## Generating coordinates for a normal circle with a upper boundary of 1 circle <- random.circle(1000, rnorm, inner = 0, outer = 1) ## Plotting the circle plot(circle, xlab = "x", ylab = "y", main = "A normal circle") ## Creating doughnut space (a spherical space with a hole) doughnut_space <- space.maker(5000, 3, c(rnorm, random.circle), arguments = list(list(mean = 0), list(runif, inner = 0.5, outer = 1))) 5.2.2 Visualising the space I suggest using the excellent scatterplot3d package to play around and visualise the simulated spaces: ## Graphical options op <- par(mfrow = (c(2, 2)), bty = "n") ## Visualising 3D spaces require(scatterplot3d) ## Loading required package: scatterplot3d ## The plane space scatterplot3d(plane_space, pch = 20, xlab = "", ylab = "", zlab = "", xlim = c(-0.5, 0.5), main = "Plane space") ## The ellipsoid space scatterplot3d(ellipse_space, pch = 20, xlab = "", ylab = "", zlab = "", main = "Normal ellipsoid space") ## A cylindrical space with a decreasing variance per axis scatterplot3d(cylindrical_space, pch = 20, xlab = "", ylab = "", zlab = "", main = "Normal cylindrical space") ## Axes have different orders of magnitude ## Plotting the doughnut space scatterplot3d(doughnut_space[,c(2,1,3)], pch = 20, xlab = "", ylab = "", zlab = "", main = "Doughnut space") par(op) 5.2.3 Generating realistic spaces It is possible to generate “realistic” spaces by simply extracting the parameters of an existing space and scaling it up to the simulated space. For example, we can extract the parameters of the BeckLee_mat50 ordinated space and simulate a similar space. ## Loading the data data(BeckLee_mat50) ## Number of dimensions obs_dim <- ncol(BeckLee_mat50) ## Observed correlation between the dimensions obs_correlations <- cor(BeckLee_mat50) ## Observed mean and standard deviation per axis obs_mu_sd_axis <- mapply(function(x,y) list("mean" = x, "sd" = y), as.list(apply(BeckLee_mat50, 2, mean)), as.list(apply(BeckLee_mat50, 2, sd)), SIMPLIFY = FALSE) ## Observed overall mean and standard deviation obs_mu_sd_glob <- list("mean" = mean(BeckLee_mat50), "sd" = sd(BeckLee_mat50)) ## Scaled observed variance per axis (scree plot) obs_scree <- variances(BeckLee_mat50)/sum(variances(BeckLee_mat50)) ## Generating our simulated space simulated_space <- space.maker(1000, dimensions = obs_dim, distribution = rep(list(rnorm), obs_dim), arguments = obs_mu_sd_axis, cor.matrix = obs_correlations) ## Visualising the fit of our data in the space (in the two first dimensions) plot(simulated_space[,1:2], xlab = "PC1", ylab = "PC2") points(BeckLee_mat50[,1:2], col = "red", pch = 20) legend("topleft", legend = c("observed", "simulated"), pch = c(20,21), col = c("red", "black")) It is now possible to simulate a space using these observed arguments to test several hypothesis: Is the space uniform or normal? If the space is normal, is the mean and variance global or specific for each axis? ## Measuring disparity as the sum of variance observed_disp <- dispRity(BeckLee_mat50, metric = c(median, centroids)) ## Is the space uniform? test_unif <- null.test(observed_disp, null.distrib = runif) ## Is the space normal with a mean of 0 and a sd of 1? test_norm1 <- null.test(observed_disp, null.distrib = rnorm) ## Is the space normal with the observed mean and sd and cumulative variance test_norm2 <- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim), null.args = rep(list(obs_mu_sd_glob), obs_dim), null.scree = obs_scree) ## Is the space multiple normal with multiple means and sds and a correlation? test_norm3 <- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim), null.args = obs_mu_sd_axis, null.cor = obs_correlations) ## Graphical options op <- par(mfrow = (c(2, 2)), bty = "n") ## Plotting the results plot(test_unif, main = "Uniform (0,1)") plot(test_norm1, main = "Normal (0,1)") plot(test_norm2, main = paste0("Normal (", round(obs_mu_sd_glob[[1]], digit = 3), ",", round(obs_mu_sd_glob[[2]], digit = 3), ")")) plot(test_norm3, main = "Normal (variable + correlation)") If we measure disparity as the median distance from the morphospace centroid, we can explain the distribution of the data as normal with the variable observed mean and standard deviation and with a correlation between the dimensions. References "],["other-functionalities.html", "6 Other functionalities 6.1 char.diff 6.2 clean.data 6.3 crown.stem 6.4 get.bin.ages 6.5 match.tip.edge 6.6 MCMCglmm utilities 6.7 pair.plot 6.8 reduce.matrix 6.9 select.axes 6.10 slice.tree 6.11 slide.nodes and remove.zero.brlen 6.12 tree.age 6.13 multi.ace", " 6 Other functionalities The dispRity package also contains several other functions that are not specific to multidimensional analysis but that are often used by dispRity internal functions. However, we decided to make these functions also available at a user level since they can be handy for certain specific operations! You’ll find a brief description of each of them (alphabetically) here: 6.1 char.diff This is yet another function for calculating distance matrices. There are many functions for calculating pairwise distance matrices in R (stats::dist, vegan::vegdist, cluster::daisy or Claddis::calculate_morphological_distances) but this one is the dispRity one. It is slightly different to the ones mentioned above (though not that dissimilar from Claddis::calculate_morphological_distances) in the fact that it focuses on comparing discrete morphological characters and tries to solve all the problems linked to these kind of matrices (especially dealing with special tokens). The function intakes a matrix with either numeric or integer (NA included) or matrices with character that are indeed integers (e.g.\"0\" and \"1\"). It then uses a bitwise operations architecture implemented in C that renders the function pretty fast and pretty modular. This bitwise operations translates the character states into binary values. This way, 0 becomes 1, 1 becomes 2, 2 becomes 4, 3 becomes 8, etc… Specifically it can handle any rules specific to special tokens (i.e. symbols) for discrete morphological characters. For example, should you treat missing values \"?\" as NA (ignoring them) or as any possible character state (e.g. c(\"0\", \"1\")?)? And how to treat characters with a ampersand (\"&\")? char.diff can answer to all these questions! Let’s start by a basic binary matrix 4*3 with random integer: ## A random binary matrix matrix_binary <- matrix(sample(c(0,1), 12, replace = TRUE), ncol = 4, dimnames = list(letters[1:3], LETTERS[1:4])) By default, char.diff measures the hamming distance between characters: ## The hamming distance between characters (differences <- char.diff(matrix_binary)) ## A B C D ## A 0 0 1 1 ## B 0 0 1 1 ## C 1 1 0 0 ## D 1 1 0 0 ## attr(,"class") ## [1] "matrix" "char.diff" Note that the results is just a pairwise distance (dissimilarity) matrix with some special dual class matrix and char.diff. This means it can easily be plotted via the disparity package: ## Visualising the matrix plot(differences) You can check all the numerous plotting options in the ?plot.char.diff manual (it won’t be developed here). The char.diff function has much more options however (see all of them in the ?char.diff manual) for example to measure different differences (via method) or making the comparison work per row (for a distance matrix between the rows): ## Euclidean distance between rows char.diff(matrix_binary, by.col = FALSE, method = "euclidean") ## a b c ## a 0.000000 1.414214 1.414214 ## b 1.414214 0.000000 0.000000 ## c 1.414214 0.000000 0.000000 ## attr(,"class") ## [1] "matrix" "char.diff" We can however make it more interesting by playing with the different rules to play with different tokens. First let’s create a matrix with morphological characters as numeric characters: ## A random character matrix (matrix_character <- matrix(sample(c("0","1","2"), 30, replace = TRUE), ncol = 5, dimnames = list(letters[1:6], LETTERS[1:5]))) ## A B C D E ## a "1" "1" "1" "1" "0" ## b "0" "2" "0" "2" "0" ## c "2" "2" "1" "2" "0" ## d "1" "2" "0" "0" "1" ## e "2" "2" "1" "1" "2" ## f "0" "2" "0" "2" "0" ## The hamming difference between columns char.diff(matrix_character) ## A B C D E ## A 0.0 0.6 0.6 0.6 0.8 ## B 0.6 0.0 0.4 0.4 0.8 ## C 0.6 0.4 0.0 0.4 0.6 ## D 0.6 0.4 0.4 0.0 1.0 ## E 0.8 0.8 0.6 1.0 0.0 ## attr(,"class") ## [1] "matrix" "char.diff" Here the characters are automatically converted into bitwise integers to be compared efficiently. We can now add some more special tokens like \"?\" or \"0/1\" for uncertainties between state \"0\" and \"1\" but not \"2\": ## Adding uncertain characters matrix_character[sample(1:30, 8)] <- "0/1" ## Adding missing data matrix_character[sample(1:30, 5)] <- "?" ## This is what it looks like now matrix_character ## A B C D E ## a "?" "?" "1" "1" "0" ## b "0" "0/1" "0/1" "0/1" "0" ## c "2" "2" "?" "0/1" "0" ## d "1" "2" "0" "0/1" "1" ## e "?" "2" "1" "1" "2" ## f "0" "2" "0" "?" "0/1" ## The hamming difference between columns including the special characters char.diff(matrix_character) ## A B C D E ## A 0.0000000 0.6666667 1.00 0.50 0.6666667 ## B 0.6666667 0.0000000 1.00 1.00 0.7500000 ## C 1.0000000 1.0000000 0.00 0.00 0.2500000 ## D 0.5000000 1.0000000 0.00 0.00 0.2500000 ## E 0.6666667 0.7500000 0.25 0.25 0.0000000 ## attr(,"class") ## [1] "matrix" "char.diff" Note here that it detected the default behaviours for the special tokens \"?\" and \"/\": \"?\" are treated as NA (not compared) and \"/\" are treated as both states (e.g. \"0/1\" is treated as \"0\" and as \"1\"). We can specify both the special tokens and the special behaviours to consider via special.tokens and special.behaviours. The special.tokens are missing = \"?\", inapplicable = \"-\", uncertainty = \"\\\" and polymorphism = \"&\" meaning we don’t have to modify them for now. However, say we want to change the behaviour for \"?\" and treat them as all possible characters and treat \"/\" as only the character \"0\" (as an integer) we can specify them giving a behaviour function: ## Specifying some special behaviours my_special_behaviours <- list(missing = function(x,y) return(y), uncertainty = function(x,y) return(as.integer(0))) ## Passing these special behaviours to the char.diff function char.diff(matrix_character, special.behaviour = my_special_behaviours) ## A B C D E ## A 0.0 0.6 0.6 0.6 0.6 ## B 0.6 0.0 0.8 0.8 0.8 ## C 0.6 0.8 0.0 0.4 0.6 ## D 0.6 0.8 0.4 0.0 1.0 ## E 0.6 0.8 0.6 1.0 0.0 ## attr(,"class") ## [1] "matrix" "char.diff" The results are quiet different as before! Note that you can also specify some really specific behaviours for any type of special token. ## Adding weird tokens to the matrix matrix_character[sample(1:30, 8)] <- "%" ## Specify the new token and the new behaviour char.diff(matrix_character, special.tokens = c(weird_one = "%"), special.behaviours = list( weird_one = function(x,y) return(as.integer(42))) ) ## A B C D E ## A 0 1 1 0 NaN ## B 1 0 1 1 NaN ## C 1 1 0 0 0 ## D 0 1 0 0 0 ## E NaN NaN 0 0 0 ## attr(,"class") ## [1] "matrix" "char.diff" Of course the results can be quiet surprising then… But that’s the essence of the modularity. You can see more options in the function manual ?char.diff! 6.2 clean.data This is a rather useful function that allows matching a matrix or a data.frame to a tree (phylo) or a distribution of trees (multiPhylo). This function outputs the cleaned data and trees (if cleaning was needed) and a list of dropped rows and tips. ## Generating a trees with labels from a to e dummy_tree <- rtree(5, tip.label = LETTERS[1:5]) ## Generating a matrix with rows from b to f dummy_data <- matrix(1, 5, 2, dimnames = list(LETTERS[2:6], c("var1", "var2"))) ##Cleaning the trees and the data (cleaned <- clean.data(data = dummy_data, tree = dummy_tree)) ## $tree ## ## Phylogenetic tree with 4 tips and 3 internal nodes. ## ## Tip labels: ## D, B, E, C ## ## Rooted; includes branch lengths. ## ## $data ## var1 var2 ## B 1 1 ## C 1 1 ## D 1 1 ## E 1 1 ## ## $dropped_tips ## [1] "A" ## ## $dropped_rows ## [1] "F" 6.3 crown.stem This function quiet handily separates tips from a phylogeny between crown members (the living taxa and their descendants) and their stem members (the fossil taxa without any living relatives). data(BeckLee_tree) ## Diving both crow and stem species (crown.stem(BeckLee_tree, inc.nodes = FALSE)) ## $crown ## [1] "Dasypodidae" "Bradypus" "Myrmecophagidae" "Todralestes" ## [5] "Potamogalinae" "Dilambdogale" "Widanelfarasia" "Rhynchocyon" ## [9] "Procavia" "Moeritherium" "Pezosiren" "Trichechus" ## [13] "Tribosphenomys" "Paramys" "Rhombomylus" "Gomphos" ## [17] "Mimotona" "Cynocephalus" "Purgatorius" "Plesiadapis" ## [21] "Notharctus" "Adapis" "Patriomanis" "Protictis" ## [25] "Vulpavus" "Miacis" "Icaronycteris" "Soricidae" ## [29] "Solenodon" "Eoryctes" ## ## $stem ## [1] "Daulestes" "Bulaklestes" "Uchkudukodon" ## [4] "Kennalestes" "Asioryctes" "Ukhaatherium" ## [7] "Cimolestes" "unnamed_cimolestid" "Maelestes" ## [10] "Batodon" "Kulbeckia" "Zhangolestes" ## [13] "unnamed_zalambdalestid" "Zalambdalestes" "Barunlestes" ## [16] "Gypsonictops" "Leptictis" "Oxyclaenus" ## [19] "Protungulatum" "Oxyprimus" Note that it is possible to include or exclude nodes from the output. To see a more applied example: this function is used in chapter 03: specific tutorials. 6.4 get.bin.ages This function is similar than the crown.stem one as it is based on a tree but this one outputs the stratigraphic bins ages that the tree is covering. This can be useful to generate precise bin ages for the chrono.subsets function: get.bin.ages(BeckLee_tree) ## [1] 132.9000 129.4000 125.0000 113.0000 100.5000 93.9000 89.8000 86.3000 ## [9] 83.6000 72.1000 66.0000 61.6000 59.2000 56.0000 47.8000 41.2000 ## [17] 37.8000 33.9000 28.1000 23.0300 20.4400 15.9700 13.8200 11.6300 ## [25] 7.2460 5.3330 3.6000 2.5800 1.8000 0.7810 0.1260 0.0117 ## [33] 0.0000 Note that this function outputs the stratigraphic age limits by default but this can be customisable by specifying the type of data (e.g. type = \"Eon\" for eons). The function also intakes several optional arguments such as whether to output the startm end, range or midpoint of the stratigraphy or the year of reference of the International Commission of Stratigraphy. To see a more applied example: this function is used in chapter 03: specific tutorials. 6.5 match.tip.edge This function matches a vector of discreet tip values with the edges connecting these tips in the \"phylo\" structure. This can be used to pull the branches of interest for some specific trait of some group of species or for colouring tree tips based on clades. For example, with the charadriiformes dataset, you can plot the tree with the branches coloured by clade. To work properly, the function requires the characteristics of the tip labels (e.g. the clade colour) to match the order of the tips in the tree: ## Loading the charadriiformes data data(charadriiformes) ## Extracting the tree my_tree <- charadriiformes$tree ## Extracting the data column that contains the clade assignments my_data <- charadriiformes$data[, "clade"] ## Changing the levels names (the clade names) to colours levels(my_data) <- c("orange", "blue", "darkgreen") my_data <- as.character(my_data) ## Matching the data rownames to the tip order in the tree my_data <- my_data[match(ladderize(my_tree)$tip.label, rownames(charadriiformes$data))] We can then match this tip data to their common descending edges. We will also colour the edges that is not descendant directly from a common coloured tip in grey using \"replace.na = \"grey\". Note that these edges are usually the edges at the root of the tree that are the descendant edges from multiple clades. ## Matching the tip colours (labels) to their descending edges in the tree ## (and making the non-match edges grey) clade_edges <- match.tip.edge(my_data, my_tree, replace.na = "grey") ## Plotting the results plot(ladderize(my_tree), show.tip.label = FALSE, edge.color = clade_edges) But you can also use this option to only select some specific edges and modify them (for example making them all equal to one): ## Adding a fixed edge length to the green clade my_tree_modif <- my_tree green_clade <- which(clade_edges == "darkgreen") my_tree_modif$edge.length[green_clade] <- 1 plot(ladderize(my_tree_modif), show.tip.label = FALSE, edge.color = clade_edges) 6.6 MCMCglmm utilities Since version 1.7, the dispRity package contains several utility functions for manipulating \"MCMCglmm\" (that is, objects returned by the function MCMCglmm::MCMCglmm). These objects are a modification of the mcmc object (from the package coda) and can be sometimes cumbersome to manipulate because of the huge amount of data in it. You can use the functions MCMCglmm.traits for extracting the number of traits, MCMCglmm.levels for extracting the level names, MCMCglmm.sample for sampling posterior IDs and MCMCglmm.covars for extracting variance-covariance matrices. You can also quickly calculate the variance (or relative variance) for each terms in the model using MCMCglmm.variance (the variance is calculated as the sum of the diagonal of each variance-covariance matrix for each term). ## Loading the charadriiformes data that contains a MCMCglmm object data(charadriiformes) my_MCMCglmm <- charadriiformes$posteriors ## Which traits where used in this model? MCMCglmm.traits(my_MCMCglmm) ## [1] "PC1" "PC2" "PC3" ## Which levels where used for the model's random terms and/or residuals? MCMCglmm.levels(my_MCMCglmm) ## random random random random ## "animal:clade_1" "animal:clade_2" "animal:clade_3" "animal" ## residual ## "units" ## The level names are converted for clarity but you can get them unconverted ## (i.e. as they appear in the model) MCMCglmm.levels(my_MCMCglmm, convert = FALSE) ## random random ## "us(at.level(clade, 1):trait):animal" "us(at.level(clade, 2):trait):animal" ## random random ## "us(at.level(clade, 3):trait):animal" "us(trait):animal" ## residual ## "us(trait):units" ## Sampling 2 random posteriors samples IDs (random_samples <- MCMCglmm.sample(my_MCMCglmm, n = 2)) ## [1] 749 901 ## Extracting these two random samples my_covars <- MCMCglmm.covars(my_MCMCglmm, sample = random_samples) ## Plotting the variance for each term in the model boxplot(MCMCglmm.variance(my_MCMCglmm), horizontal = TRUE, las = 1, xlab = "Relative variance", main = "Variance explained by each term") See more in the $covar section on what to do with these \"MCMCglmm\" objects. 6.7 pair.plot This utility function allows to plot a matrix image of pairwise comparisons. This can be useful when getting pairwise comparisons and if you’d like to see at a glance which pairs of comparisons have high or low values. ## Random data data <- matrix(data = runif(42), ncol = 2) ## Plotting the first column as a pairwise comparisons pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE, diag = 1) Here blue squares are ones that have a high value and orange ones the ones that have low values. Note that the values plotted correspond the first column of the data as designated by what = 1. It is also possible to add some tokens or symbols to quickly highlight to specific cells, for example which elements in the data are below a certain value: ## The same plot as before without the diagonal being ## the maximal observed value pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE, diag = "max") ## Highlighting with an asterisk which squares have a value ## below 0.2 pair.plot(data, what = 1, binary = 0.2, add = "*", cex = 2) This function can also be used as a binary display when running a series of pairwise t-tests. For example, the following script runs a wilcoxon test between the time-slices from the disparity example dataset and displays in black which pairs of slices have a p-value below 0.05: ## Loading disparity data data(disparity) ## Testing the pairwise difference between slices tests <- test.dispRity(disparity, test = wilcox.test, correction = "bonferroni") ## Plotting the significance pair.plot(as.data.frame(tests), what = "p.value", binary = 0.05) 6.8 reduce.matrix This function allows to reduce columns or rows of a matrix to make sure that there is enough overlap for further analysis. This is particularly useful if you are going to use distance matrices since it uses the vegan::vegdist function to test whether distances can be calculated or not. For example, if we have a patchy matrix like so (where the black squares represent available data): set.seed(1) ## A 10*5 matrix na_matrix <- matrix(rnorm(50), 10, 5) ## Making sure some rows don't overlap na_matrix[1, 1:2] <- NA na_matrix[2, 3:5] <- NA ## Adding 50% NAs na_matrix[sample(1:50, 25)] <- NA ## Illustrating the gappy matrix image(t(na_matrix), col = "black") We can use the reduce.matrix to double check whether any rows cannot be compared. The functions needs as an input the type of distance that will be used, say a \"gower\" distance: ## Reducing the matrix by row (reduction <- reduce.matrix(na_matrix, distance = "gower")) ## $rows.to.remove ## [1] "9" "1" ## ## $cols.to.remove ## NULL We can not remove the rows 1 and 9 and see if that improved the overlap: image(t(na_matrix[-as.numeric(reduction$rows.to.remove), ]), col = "black") 6.9 select.axes This function allows you to select which axes (or how many of them) are relevant in your trait space analyses. Usually, when the trait space is an ordination, workers select a certain number of axes to reduce the dimensionality of the dataset by removing axes that contain relatively little information. This is often done by selecting the axes from which the cumulative individual variance is lower than an arbitrary threshold. For example, all the axes that contain together 0.95 of the variance: ## The USArrest example in R ordination <- princomp(USArrests, cor = TRUE) ## The loading of each variable loadings(ordination) ## ## Loadings: ## Comp.1 Comp.2 Comp.3 Comp.4 ## Murder 0.536 0.418 0.341 0.649 ## Assault 0.583 0.188 0.268 -0.743 ## UrbanPop 0.278 -0.873 0.378 0.134 ## Rape 0.543 -0.167 -0.818 ## ## Comp.1 Comp.2 Comp.3 Comp.4 ## SS loadings 1.00 1.00 1.00 1.00 ## Proportion Var 0.25 0.25 0.25 0.25 ## Cumulative Var 0.25 0.50 0.75 1.00 ## Or the same operation but manually variances <- apply(ordination$scores, 2, var) scaled_variances <- variances/sum(variances) sumed_variances <- cumsum(scaled_variances) round(rbind(variances, scaled_variances, sumed_variances), 3) ## Comp.1 Comp.2 Comp.3 Comp.4 ## variances 2.531 1.010 0.364 0.177 ## scaled_variances 0.620 0.247 0.089 0.043 ## sumed_variances 0.620 0.868 0.957 1.000 In this example, you can see that the three first axes are required to have at least 0.95 of the variance. You can do that automatically in dispRity using the select.axes function. ## Same operation automatised (selected <- select.axes(ordination)) ## The first 3 dimensions are needed to express at least 95% of the variance in the whole trait space. ## You can use x$dimensions to select them or use plot(x) and summary(x) to summarise them. This function does basically what the script above does and allows the results to be plotted or summarised into a table. ## Summarising this info summary(selected) ## Comp.1.var Comp.1.sum Comp.2.var Comp.2.sum Comp.3.var Comp.3.sum ## whole_space 0.62 0.62 0.247 0.868 0.089 0.957 ## Comp.4.var Comp.4.sum ## whole_space 0.043 1 ## Plotting it plot(selected) ## Extracting the dimensions ## (for the dispRity function for example) selected$dimensions ## [1] 1 2 3 However, it might be interesting to not only consider the variance within the whole trait space but also among groups of specific interest. E.g. if the 95% of the variance is concentrated in the two first axes for the whole trait space, that does not automatically mean that it is the case for each subset in this space. Some subset might require more than the two first axes to express 95% of their variance! You can thus use the select.axes function to look at the results per group as well as through the whole trait space. Note that you can always change the threshold value (default is 0.95). Here for example we set it to 0.9 (we arbitrarily decide that explain 90% of the variance is enough). ## Creating some groups of stats states_groups <- list("Group1" = c("Mississippi","North Carolina", "South Carolina", "Georgia", "Alabama", "Alaska", "Tennessee", "Louisiana"), "Group2" = c("Florida", "New Mexico", "Michigan", "Indiana", "Virginia", "Wyoming", "Montana", "Maine", "Idaho", "New Hampshire", "Iowa"), "Group3" = c("Rhode Island", "New Jersey", "Hawaii", "Massachusetts")) ## Running the same analyses but per groups selected <- select.axes(ordination, group = states_groups, threshold = 0.9) ## Plotting the results plot(selected) As you can see here, the whole space requires the three first axes to explain at least 90% of the variance (in fact, 95% as seen before). However, different groups have a different story! The Group 1 and 3 requires 4 dimensions whereas Group 2 requires only 1 dimensions (note how for Group 3, there is actually nearly no variance explained on the second axes)! Using this method, you can safely use the four axes returned by the function (selected$dimensions) so that every group has at least 90% of their variance explained in the trait space. If you’ve used the function if you’ve already done some grouping in your disparity analyses (e.g. using the function custom.subsets or chrono.subsets), you can use the generated dispRity to automatise this analyses: ## Loading the dispRity package demo data data(demo_data) ## A dispRity object with two groups demo_data$hopkins ## ---- dispRity object ---- ## 2 customised subsets for 46 elements in one matrix: ## adult, juvenile. ## Selecting axes on a dispRity object selected <- select.axes(demo_data$hopkins) plot(selected) ## Displaying which axes are necessary for which group selected$dim.list ## $adult ## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ## ## $juvenile ## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ## ## $whole_space ## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ## Note how the whole space needs only 16 axes ## but both groups need 22 and 23 axes 6.10 slice.tree This function is a modification of the paleotree::timeSliceTree function that allows to make slices through a phylogenetic tree. Compared to the paleotree::timeSliceTree, this function allows a model to decide which tip or node to use when slicing through a branch (whereas paleotree::timeSliceTree always choose the first available tip alphabetically). The models for choosing which tip or node are the same as the ones used in the chrono.subsets and are described in chapter 03: specific tutorials. The function works by using at least a tree, a slice age and a model: set.seed(1) ## Generate a random ultrametric tree tree <- rcoal(20) ## Add some node labels tree$node.label <- letters[1:19] ## Add its root time tree$root.time <- max(tree.age(tree)$ages) ## Slicing the tree at age 0.75 tree_75 <- slice.tree(tree, age = 0.75, "acctran") ## Showing both trees par(mfrow = c(1,2)) plot(tree, main = "original tree") axisPhylo() ; nodelabels(tree$node.label, cex = 0.8) abline(v = (max(tree.age(tree)$ages) - 0.75), col = "red") plot(tree_75, main = "sliced tree") 6.11 slide.nodes and remove.zero.brlen This function allows to slide nodes along a tree! In other words it allows to change the branch length leading to a node without modifying the overall tree shape. This can be useful to add some value to 0 branch lengths for example. The function works by taking a node (or a list of nodes), a tree and a sliding value. The node will be moved “up” (towards the tips) for the given sliding value. You can move the node “down” (towards the roots) using a negative value. set.seed(42) ## Generating simple coalescent tree tree <- rcoal(5) ## Sliding node 8 up and down tree_slide_up <- slide.nodes(8, tree, slide = 0.075) tree_slide_down <- slide.nodes(8, tree, slide = -0.075) ## Display the results par(mfrow = c(3,1)) plot(tree, main = "original tree") ; axisPhylo() ; nodelabels() plot(tree_slide_up, main = "slide up!") ; axisPhylo() ; nodelabels() plot(tree_slide_down, main = "slide down!") ; axisPhylo() ; nodelabels() The remove.zero.brlen is a “clever” wrapping function that uses the slide.nodes function to stochastically remove zero branch lengths across a whole tree. This function will slide nodes up or down in successive postorder traversals (i.e. going down the tree clade by clade) in order to minimise the number of nodes to slide while making sure there are no silly negative branch lengths produced! By default it is trying to slide the nodes using 1% of the minimum branch length to avoid changing the topology too much. set.seed(42) ## Generating a tree tree <- rtree(20) ## Adding some zero branch lengths (5) tree$edge.length[sample(1:Nedge(tree), 5)] <- 0 ## And now removing these zero branch lengths! tree_no_zero <- remove.zero.brlen(tree) ## Exaggerating the removal (to make it visible) tree_exaggerated <- remove.zero.brlen(tree, slide = 1) ## Check the differences any(tree$edge.length == 0) ## [1] TRUE any(tree_no_zero$edge.length == 0) ## [1] FALSE any(tree_exaggerated$edge.length == 0) ## [1] FALSE ## Display the results par(mfrow = c(3,1)) plot(tree, main = "with zero edges") plot(tree_no_zero, main = "without zero edges!") plot(tree_exaggerated, main = "with longer edges") 6.12 tree.age This function allows to quickly calculate the ages of each tips and nodes present in a tree. set.seed(1) tree <- rtree(10) ## The tree age from a 10 tip tree tree.age(tree) ## ages elements ## 1 0.707 t7 ## 2 0.142 t2 ## 3 0.000 t3 ## 4 1.467 t8 ## 5 1.366 t1 ## 6 1.895 t5 ## 7 1.536 t6 ## 8 1.456 t9 ## 9 0.815 t10 ## 10 2.343 t4 ## 11 3.011 11 ## 12 2.631 12 ## 13 1.854 13 ## 14 0.919 14 ## 15 0.267 15 ## 16 2.618 16 ## 17 2.235 17 ## 18 2.136 18 ## 19 1.642 19 It also allows to set the age of the root of the tree: ## The ages starting from -100 units tree.age(tree, age = 100) ## ages elements ## 1 23.472 t7 ## 2 4.705 t2 ## 3 0.000 t3 ## 4 48.736 t8 ## 5 45.352 t1 ## 6 62.931 t5 ## 7 51.012 t6 ## 8 48.349 t9 ## 9 27.055 t10 ## 10 77.800 t4 ## 11 100.000 11 ## 12 87.379 12 ## 13 61.559 13 ## 14 30.517 14 ## 15 8.875 15 ## 16 86.934 16 ## 17 74.235 17 ## 18 70.924 18 ## 19 54.533 19 Usually tree age is calculated from the present to the past (e.g. in million years ago) but it is possible to reverse it using the order = present option: ## The ages in terms of tip/node height tree.age(tree, order = "present") ## ages elements ## 1 2.304 t7 ## 2 2.869 t2 ## 3 3.011 t3 ## 4 1.544 t8 ## 5 1.646 t1 ## 6 1.116 t5 ## 7 1.475 t6 ## 8 1.555 t9 ## 9 2.196 t10 ## 10 0.668 t4 ## 11 0.000 11 ## 12 0.380 12 ## 13 1.157 13 ## 14 2.092 14 ## 15 2.744 15 ## 16 0.393 16 ## 17 0.776 17 ## 18 0.876 18 ## 19 1.369 19 6.13 multi.ace This function allows to run the ape::ace function (ancestral characters estimations) on multiple trees. In it’s most basic structure (e.g. using all default arguments) this function is using a mix of ape::ace and castor::asr_mk_model depending on the data and the situation and is generally faster than both functions when applied to a list of trees. However, this function provides also some more complex and modular functionalities, especially appropriate when using discrete morphological character data. 6.13.1 Using different character tokens in different situations This data can be often coded in non-standard way with different character tokens having different meanings. For example, in some datasets the token - can mean “the trait is inapplicable” but this can be also coded by the more conventional NA or can mean “this trait is missing” (often coded ?). This makes the meaning of specific tokens idiosyncratic to different matrices. For example we can have the following discrete morphological matrix with all the data encoded: set.seed(42) ## A random tree with 10 tips tree <- rcoal(10) ## Setting up the parameters my_rates = c(rgamma, rate = 10, shape = 5) ## Generating a bunch of trees multiple_trees <- rmtree(5, 10) ## A random Mk matrix (10*50) matrix_simple <- sim.morpho(tree, characters = 50, model = "ER", rates = my_rates, invariant = FALSE) matrix_simple[1:10, 1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## t8 "1" "1" "1" "1" "0" "0" "0" "0" "0" "1" ## t3 "1" "1" "1" "1" "0" "0" "0" "0" "0" "1" ## t2 "1" "1" "1" "1" "0" "1" "1" "1" "0" "1" ## t1 "1" "1" "1" "1" "0" "0" "1" "1" "0" "1" ## t10 "1" "1" "1" "1" "0" "0" "1" "0" "1" "1" ## t9 "1" "1" "1" "1" "0" "0" "1" "0" "0" "1" ## t5 "0" "0" "0" "0" "1" "1" "1" "0" "0" "0" ## t6 "0" "0" "0" "0" "1" "1" "1" "0" "0" "0" ## t4 "0" "0" "0" "0" "1" "0" "0" "0" "1" "0" ## t7 "0" "0" "0" "0" "1" "0" "0" "0" "1" "0" But of course, as mentioned above, in practice, such matrices have more nuance and can including missing characters, ambiguous characters, multi-state characters, inapplicable characters, etc… All these coded and defined by different authors using different tokens (or symbols). Let’s give it a go and transform this simple data to something more messy: ## Modify the matrix to contain missing and special data matrix_complex <- matrix_simple ## Adding 50 random "-" tokens matrix_complex[sample(1:length(matrix_complex), 50)] <- "-" ## Adding 50 random "?" tokens matrix_complex[sample(1:length(matrix_complex), 50)] <- "?" ## Adding 50 random "0%2" tokens matrix_complex[sample(1:length(matrix_complex), 50)] <- "0%2" matrix_complex[1:10,1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## t8 "1" "1" "1" "1" "?" "0" "0" "0" "0" "0%2" ## t3 "1" "-" "1" "1" "?" "0" "0" "0" "0" "1" ## t2 "1" "1" "1" "0%2" "0" "0%2" "1" "1" "0" "1" ## t1 "1" "1" "1" "1" "0" "0" "1" "?" "0" "1" ## t10 "1" "0%2" "1" "1" "-" "?" "0%2" "0%2" "1" "1" ## t9 "1" "1" "?" "1" "0%2" "0" "1" "0" "0" "1" ## t5 "0" "-" "?" "0" "1" "1" "1" "0" "0" "-" ## t6 "0" "-" "0" "0" "1" "1" "-" "-" "?" "0" ## t4 "?" "0" "0" "0" "1" "0" "0" "0" "1" "0" ## t7 "0" "0" "0" "0%2" "1" "0" "0" "-" "1" "-" In multi.ace you can specify what all these tokens actually mean and how the code should interpret them. For example, - often means inapplicable data (i.e. the specimen does not have the coded feature, for example, the colour of the tail of a tailless bird); or ? that often means missing data (i.e. it is unknown if the specimen has a tail or not since only the head was available). And more than the differences in meaning between these characters, different people treat these characters differently even if they have the same meaning for the token. For example, one might want to treat - as meaning “we don’t know” (which will be treated by the algorithm as “any possible trait value”) or “we know, and it’s no possible” (which will be treated by the algorithm as NA). Because of this situation, multi.ace allows combining any special case marked with a special token to a special behaviour. For example we might want to create a special case called \"missing\" (i.e. the data is missing) that we want to denote using the token \"?\" and we can specify the algorithm to treat this \"missing\" cases (\"?\") as treating the character token value as “any possible values”. This behaviour can be hard coded by providing a function with the name of the behaviour. For example: ## The specific token for the missing cases (note the "\\\\" for protecting the value) special.tokens <- c("missing" = "\\\\?") ## The behaviour for the missing cases (?) special.behaviour <- list(missing <- function(x, y) return(y)) ## Where x is the input value (here "?") and y is all the possible normal values for the character This example shows a very common case (and is actually used by default, more on that below) but this architecture allows for very modular combination of tokens and behaviours. For example, in our code above we introduced the token \"%\" which is very odd (to my knowledge) and might mean something very specific in our case. Say we want to call this case \"weirdtoken\" and mean that whenever this token is encountered in a character, it should be interpreted by the algorithm as the values 1 and 2, no matter what: ## Set a list of extra special tokens my_spec_tokens <- c("weirdtoken" = "\\\\%") ## Weird tokens are considered as state 0 and 3 my_spec_behaviours <- list() my_spec_behaviours$weirdtoken <- function(x,y) return(c(1,2)) If you don’t need/don’t have any of this specific tokens, don’t worry, most special but common tokens are handled by default as such: ## The token for missing values: default_tokens <- c("missing" = "\\\\?", ## The token for inapplicable values: "inapplicable" = "\\\\-", ## The token for polymorphisms: "polymorphism" = "\\\\&", ## The token for uncertainties: "uncertanity" = "\\\\/") With the following associated default behaviours ## Treating missing data as all data values default_behaviour <- list(missing <- function(x,y) y, ## Treating inapplicable data as all data values (like missing) inapplicable <- function(x, y) y, ## Treating polymorphisms as all values present: polymorphism <- function(x,y) strsplit(x, split = "\\\\&")[[1]], ## Treating uncertainties as all values present (like polymorphisms): uncertanity <- function(x,y) strsplit(x, split = "\\\\&")[[1]]) We can then use these token description along with our complex matrix and our list of trees to run the ancestral states estimations as follows: ## Running ancestral states ancestral_states <- multi.ace(matrix_complex, multiple_trees, special.tokens = my_spec_tokens, special.behaviours = my_spec_behaviours, verbose = TRUE) ## Preparing the data:... ## Warning: The characters 39 are invariant (using the current special behaviours ## for special characters) and are simply duplicated for each node. ## ..Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## This outputs a list of ancestral parts of the matrices for each tree ## For example, here's the first one: ancestral_states[[1]][1:9, 1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## [1,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1" ## [2,] "1" "1" "1" "1" "0/1" "0/1/2" "0/1" "0" "0" "1" ## [3,] "1" "1" "1" "1" "0/1" "0/1/2" "0" "0" "0" "1" ## [4,] "1" "1" "1" "1" "0" "0/1/2" "1" "1" "0" "1" ## [5,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1" ## [6,] "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1" ## [7,] "0" "0/1" "0/1" "0" "1" "1" "1" "0" "0" "0/1" ## [8,] "0" "0" "0" "0" "1" "0/1/2" "0" "0" "1" "0" ## [9,] "0" "0" "0" "0" "1" "1" "0" "0" "1" "0" Note that there are many different options that are not covered here. For example, you can use different models for each character via the models argument, you can specify how to handle uncertainties via the threshold argument, use a branch length modifier (brlen.multiplier), specify the type of output, etc… 6.13.2 Feeding the results to char.diff to get distance matrices Finally, after running your ancestral states estimations, it is not uncommon to then use these resulting data to calculate the distances between taxa and then ordinate the results to measure disparity. You can do that using the char.diff function described above but instead of measuring the distances between characters (columns) you can measure the distances between species (rows). You might notice that this function uses the same modular token and behaviour descriptions. That makes sense because they’re using the same core C functions implemented in dispRity that greatly speed up distance calculations. ## Running ancestral states ## and outputing a list of combined matrices (tips and nodes) ancestral_states <- multi.ace(matrix_complex, multiple_trees, special.tokens = my_spec_tokens, special.behaviours = my_spec_behaviours, output = "combined.matrix", verbose = TRUE) ## Preparing the data:... ## Warning: The characters 39 are invariant (using the current special behaviours ## for special characters) and are simply duplicated for each node. ## ..Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. ## Running ancestral states estimations: ## ................................................. ## Warning in mapply(replace.NA, ancestral_states, characters_states, MoreArgs = ## list(special.tokens = special.tokens), : longer argument not a multiple of ## length of shorter ## Done. We can then feed these matrices directly to char.diff, say for calculating the “MORD” distance: ## Measuring the distances between rows using the MORD distance distances <- lapply(ancestral_states, char.diff, method = "mord", by.col = FALSE) And we now have a list of distances matrices with ancestral states estimated! "],["the-guts-of-the-disprity-package.html", "7 The guts of the dispRity package 7.1 Manipulating dispRity objects 7.2 dispRity utilities 7.3 The dispRity object content", " 7 The guts of the dispRity package 7.1 Manipulating dispRity objects Disparity analysis involves a lot of manipulation of many matrices (especially when bootstrapping) which can be impractical to visualise and will quickly overwhelm your R console. Even the simple Beck and Lee 2014 example above produces an object with > 72 lines of lists of lists of matrices! Therefore dispRity uses a specific class of object called a dispRity object. These objects allow users to use S3 method functions such as summary.dispRity, plot.dispRity and print.dispRity. dispRity also contains various utility functions that manipulate the dispRity object (e.g. sort.dispRity, extract.dispRity see the full list in the next section). These functions modify the dispRity object without having to delve into its complex structure! The full structure of a dispRity object is detailed here. ## Loading the example data data(disparity) ## What is the class of the median_centroids object? class(disparity) ## [1] "dispRity" ## What does the object contain? names(disparity) ## [1] "matrix" "tree" "call" "subsets" "disparity" ## Summarising it using the S3 method print.dispRity disparity ## ---- dispRity object ---- ## 7 continuous (acctran) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 90, 80, 70, 60, 50 ... ## Data was bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements. ## Disparity was calculated as: c(median, centroids). Note that it is always possible to recall the full object using the argument all = TRUE in print.dispRity: ## Display the full object print(disparity, all = TRUE) ## This is more nearly ~ 5000 lines on my 13 inch laptop screen! 7.2 dispRity utilities The package also provides some utility functions to facilitate multidimensional analysis. 7.2.1 dispRity object utilities The first set of utilities are functions for manipulating dispRity objects: 7.2.1.1 make.dispRity This function creates empty dispRity objects. ## Creating an empty dispRity object make.dispRity() ## Empty dispRity object. ## Creating an "empty" dispRity object with a matrix (disparity_obj <- make.dispRity(matrix(rnorm(20), 5, 4))) ## ---- dispRity object ---- ## Contains a matrix 5x4. 7.2.1.2 fill.dispRity This function initialises a dispRity object and generates its call properties. ## The dispRity object's call is indeed empty disparity_obj$call ## list() ## Filling an empty disparity object (that needs to contain at least a matrix) (disparity_obj <- fill.dispRity(disparity_obj)) ## Warning in check.data(data, match_call): Row names have been automatically ## added to data$matrix. ## ---- dispRity object ---- ## 5 elements in one matrix with 4 dimensions. ## The dipRity object has now the correct minimal attributes disparity_obj$call ## $dimensions ## [1] 1 2 3 4 7.2.1.3 get.matrix This function extracts a specific matrix from a disparity object. The matrix can be one of the bootstrapped matrices or/and a rarefied matrix. ## Extracting the matrix containing the coordinates of the elements at time 50 str(get.matrix(disparity, "50")) ## num [1:18, 1:97] -0.1036 0.4318 0.3371 0.0501 0.685 ... ## - attr(*, "dimnames")=List of 2 ## ..$ : chr [1:18] "Leptictis" "Dasypodidae" "n24" "Potamogalinae" ... ## ..$ : NULL ## Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level ## (15 elements) from the second group (80 Mya) str(get.matrix(disparity, subsets = 1, bootstrap = 3, rarefaction = 2)) ## num [1:15, 1:97] -0.12948 -0.57973 0.00361 0.27123 0.27123 ... ## - attr(*, "dimnames")=List of 2 ## ..$ : chr [1:15] "n15" "Maelestes" "n20" "n34" ... ## ..$ : NULL 7.2.1.4 n.subsets This function simply counts the number of subsets in a dispRity object. ## How many subsets are in this object? n.subsets(disparity) ## [1] 7 7.2.1.5 name.subsets This function gets you the names of the subsets in a dispRity object as a vector. ## What are they called? name.subsets(disparity) ## [1] "90" "80" "70" "60" "50" "40" "30" 7.2.1.6 size.subsets This function tells the number of elements in each subsets of a dispRity object. ## How many elements are there in each subset? size.subsets(disparity) ## 90 80 70 60 50 40 30 ## 18 22 23 21 18 15 10 7.2.1.7 get.subsets This function creates a dispRity object that contains only elements from one specific subsets. ## Extracting all the data for the crown mammals (crown_mammals <- get.subsets(disp_crown_stemBS, "Group.crown")) ## The object keeps the properties of the parent object but is composed of only one subsets length(crown_mammals$subsets) 7.2.1.8 combine.subsets This function allows to merge different subsets. ## Combine the two first subsets in the dispRity data example combine.subsets(disparity, c(1,2)) Note that the computed values (bootstrapped data + disparity metric) are not merge. 7.2.1.9 get.disparity This function extracts the calculated disparity values of a specific matrix. ## Extracting the observed disparity (default) get.disparity(disparity) ## Extracting the disparity from the bootstrapped values from the ## 10th rarefaction level from the second subsets (80 Mya) get.disparity(disparity, observed = FALSE, subsets = 2, rarefaction = 10) 7.2.1.10 scale.dispRity This is the modified S3 method for scale (scaling and/or centring) that can be applied to the disparity data of a dispRity object and can take optional arguments (for example the rescaling by dividing by a maximum value). ## Getting the disparity values of the time subsets head(summary(disparity)) ## Scaling the same disparity values head(summary(scale.dispRity(disparity, scale = TRUE))) ## Scaling and centering: head(summary(scale.dispRity(disparity, scale = TRUE, center = TRUE))) ## Rescaling the value by dividing by a maximum value head(summary(scale.dispRity(disparity, max = 10))) 7.2.1.11 sort.dispRity This is the S3 method of sort for sorting the subsets alphabetically (default) or following a specific pattern. ## Sorting the disparity subsets in inverse alphabetic order head(summary(sort(disparity, decreasing = TRUE))) ## Customised sorting head(summary(sort(disparity, sort = c(7, 1, 3, 4, 5, 2, 6)))) 7.2.1.12 get.tree add.tree and remove.tree These functions allow to manipulate the potential tree components of dispRity objects. ## Getting the tree component of a dispRity object get.tree(disparity) ## Removing the tree remove.tree(disparity) ## Adding a tree add.tree(disparity, tree = BeckLee_tree) Note that get.tree can also be used to extract trees from different subsets (custom or continuous/discrete subsets). For example, if we have three time bins like in the example below we have three time bins and we can extract the subtrees for these three time bins in different ways using the option subsets and to.root: ## Load the Beck & Lee 2014 data data(BeckLee_tree) ; data(BeckLee_mat99) ; data(BeckLee_ages) ## Time binning (discrete method) ## Generate two discrete time bins from 120 to 40 Ma every 20 Ma time_bins <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "discrete", time = c(120, 100, 80, 60), inc.nodes = TRUE, FADLAD = BeckLee_ages) ## Getting the subtrees all the way to the root root_subsets <- get.tree(time_bins, subsets = TRUE) ## Plotting the bin contents old_par <- par(mfrow = c(2,2)) plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE) axisPhylo() abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60)) for(i in 1:3) { plot(root_subsets[[i]], main = names(root_subsets)[i], show.tip.label = FALSE) axisPhylo() } par(old_par) But we can also extract the subtrees containing only branch lengths for the actual bins using to.root = FALSE: ## Getting the subtrees all the way to the root bin_subsets <- get.tree(time_bins, subsets = TRUE, to.root = FALSE) ## Plotting the bin contents old_par <- par(mfrow = c(2,2)) plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE) axisPhylo() abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60)) for(i in 1:3) { plot(bin_subsets[[i]], main = names(bin_subsets)[i], show.tip.label = FALSE) axisPhylo() } par(old_par) This can be useful for example for calculating the branch lengths in each bin: ## How many cumulated phylogenetic diversity in each bin? lapply(bin_subsets, function(tree) sum(tree$edge.length)) ## $`120 - 100` ## [1] 189.2799 ## ## $`100 - 80` ## [1] 341.7199 ## ## $`80 - 60` ## [1] 426.7493 7.3 The dispRity object content The functions above are utilities to easily and safely access different elements in the dispRity object. Alternatively, of course, each elements can be accessed manually. Here is an explanation on how it works. The dispRity object is a list of two to four elements, each of which are detailed below: $matrix: an object of class list that contains at least one object of class matrix: the full multidimensional space. $call: an object of class list containing information on the dispRity object content. $subsets: an object of class list containing the subsets of the multidimensional space. $disparity: an object of class list containing the disparity values. The dispRity object is loosely based on C structure objects. In fact, it is composed of one unique instance of a matrix (the multidimensional space) upon which the metric function is called via “pointers” to only a certain number of elements and/or dimensions of this matrix. This allows for: (1) faster and easily tractable execution time: the metric functions are called through apply family function and can be parallelised; and (2) a really low memory footprint: at any time, only one matrix (or list of matrices) is present in the R environment rather than multiple copies of it for each subset. 7.3.1 $matrix This is the multidimensional space, stored in the R environment as a list object containing one or more matrix objects. Each matrix requires row names but not column names (optional). By default, if the row names are missing, dispRity function will arbitrarily generate them in numeric order (i.e. rownames(matrix) <- 1:nrow(matrix)). This element of the dispRity object is never modified. 7.3.2 $call This element contains the information on the dispRity object content. It is a list that can contain the following: $call$subsets: a vector of character with information on the subsets type (either \"continuous\", \"discrete\" or \"custom\"), their eventual model (\"acctran\", \"deltran\", \"random\", \"proximity\", \"equal.split\", \"gradual.split\") and eventual information about the trees and matrices used through chrono.subsets. This element generated only once via chrono.subsets() and custom.subsets(). $call$dimensions: either a single numeric value indicating how many dimensions to use or a vector of numeric values indicating which specific dimensions to use. This element is by default the number of columns in $matrix but can be modified through boot.matrix() or dispRity(). $call$bootstrap: this is a list containing three elements: [[1]]: the number of bootstrap replicates (numeric) [[2]]: the bootstrap method (character) [[3]]: the rarefaction levels (numeric vector) $call$disparity: this is a list containing one element, $metric, that is a list containing the different functions passed to the metric argument in dispRity. These are call elements and get modified each time the dispRity function is used (the first element is the first metric(s), the second, the second metric(s), etc.). 7.3.3 $subsets This element contain the eventual subsets of the multidimensional space. It is a list of subset names. Each subset name is in turn a list of at least one element called elements which is in turn a matrix. This elements matrix is the raw (observed) elements in the subsets. The elements matrix is composed of numeric values in one column and n rows (the number of elements in the subset). Each of these values are a “pointer” (C inspired) to the element of the $matrix. For example, lets assume a dispRity object called disparity, composed of at least one subsets called sub1: disparity$subsets$sub1$elements [,1] [1,] 5 [2,] 4 [3,] 6 [4,] 7 The values in the matrix “point” to the elements in $matrix: here, the multidimensional space with only the 4th, 5th, 6th and 7th elements. The following elements in diparity$subsets$sub1 will correspond to the same “pointers” but drawn from the bootstrap replicates. The columns will correspond to different bootstrap replicates. For example: disparity$subsets$sub1[[2]] [,1] [,2] [,3] [,4] [1,] 57 43 70 4 [2,] 43 44 4 4 [3,] 42 84 44 1 [4,] 84 7 2 10 This signifies that we have four bootstrap pseudo-replicates pointing each time to four elements in $matrix. The next element ([[3]]) will be the same for the eventual first rarefaction level (i.e. the resulting bootstrap matrix will have m rows where m is the number of elements for this rarefaction level). The next element after that ([[4]]) will be the same for with an other rarefaction level and so forth… When a probabilistic model was used to select the elements (models that have the \"split\" suffix, e.g. chrono.subsets(..., model = \"gradual.split\")), the $elements is a matrix containing a pair of elements of the matrix and a probability for sampling the first element in that list: disparity$subsets$sub1$elements [,1] [,2] [,3] [1,] 73 36 0.01871893 [2,] 74 37 0.02555876 [3,] 33 38 0.85679821 In this example, you can read the table row by row as: “there is a probability of 0.018 for sampling element 73 and a probability of 0.82 (1-0.018) of sampling element 36”. 7.3.4 $disparity The $disparity element is identical to the $subsets element structure (a list of list(s) containing matrices) but the matrices don’t contain “pointers” to $matrix but the disparity result of the disparity metric applied to the “pointers”. For example, in our first example ($elements) from above, if the disparity metric is of dimensions level 1, we would have: disparity$disparity$sub1$elements [,1] [1,] 1.82 This is the observed disparity (1.82) for the subset called sub1. If the disparity metric is of dimension level 2 (say the function range that outputs two values), we would have: disparity$disparity$sub1$elements [,1] [1,] 0.82 [2,] 2.82 The following elements in the list follow the same logic as before: rows are disparity values (one row for a dimension level 1 metric, multiple for a dimensions level 2 metric) and columns are the bootstrap replicates (the bootstrap with all elements followed by the eventual rarefaction levels). For example for the bootstrap without rarefaction (second element of the list): disparity$disparity$sub1[[2]] [,1] [,2] [,3] [,4] [1,] 1.744668 1.777418 1.781624 1.739679 "],["disprity-ecology-demo.html", "8 dispRity ecology demo 8.1 Data 8.2 Classic analysis 8.3 A multidimensional approach with dispRity", " 8 dispRity ecology demo This is an example of typical disparity analysis that can be performed in ecology. 8.1 Data For this example, we will use the famous iris inbuilt data set data(iris) This data contains petal and sepal length for 150 individual plants sorted into three species. ## Separating the species species <- iris[,5] ## Which species? unique(species) ## [1] setosa versicolor virginica ## Levels: setosa versicolor virginica ## Separating the petal/sepal length measurements <- iris[,1:4] head(measurements) ## Sepal.Length Sepal.Width Petal.Length Petal.Width ## 1 5.1 3.5 1.4 0.2 ## 2 4.9 3.0 1.4 0.2 ## 3 4.7 3.2 1.3 0.2 ## 4 4.6 3.1 1.5 0.2 ## 5 5.0 3.6 1.4 0.2 ## 6 5.4 3.9 1.7 0.4 We can then ordinate the data using a PCA (prcomp function) thus defining our four dimensional space as the poetically named petal-space. ## Ordinating the data ordination <- prcomp(measurements) ## The petal-space petal_space <- ordination$x ## Adding the elements names to the petal-space (the individuals IDs) rownames(petal_space) <- 1:nrow(petal_space) 8.2 Classic analysis A classical way to represent this ordinated data would be to use two dimensional plots to look at how the different species are distributed in the petal-space. ## Measuring the variance on each axis axis_variances <- apply(petal_space, 2, var) axis_variances <- axis_variances/sum(axis_variances) ## Graphical option par(bty = "n") ## A classic 2D ordination plot plot(petal_space[, 1], petal_space[, 2], col = species, xlab = paste0("PC 1 (", round(axis_variances[1], 2), ")"), ylab = paste0("PC 2 (", round(axis_variances[2], 2), ")")) This shows the distribution of the different species in the petal-space along the two first axis of variation. This is a pretty standard way to visualise the multidimensional space and further analysis might be necessary to test wether the groups are different such as a linear discriminant analysis (LDA). However, in this case we are ignoring the two other dimensions of the ordination! If we look at the two other axis we see a totally different result: ## Plotting the two second axis of the petal-space plot(petal_space[, 3], petal_space[, 4], col = species, xlab = paste0("PC 3 (", round(axis_variances[3], 2), ")"), ylab = paste0("PC 4 (", round(axis_variances[4], 2), ")")) Additionally, these two represented dimensions do not represent a biological reality per se; i.e. the values on the first dimension do not represent a continuous trait (e.g. petal length), instead they just represent the ordinations of correlations between the data and some factors. Therefore, we might want to approach this problem without getting stuck in only two dimensions and consider the whole dataset as a n-dimensional object. 8.3 A multidimensional approach with dispRity The first step is to create different subsets that represent subsets of the ordinated space (i.e. sub-regions within the n-dimensional object). Each of these subsets will contain only the individuals of a specific species. ## Creating the table that contain the elements and their attributes petal_subsets <- custom.subsets(petal_space, group = list( "setosa" = which(species == "setosa"), "versicolor" = which(species == "versicolor"), "virginica" = which(species == "virginica"))) ## Visualising the dispRity object content petal_subsets ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix: ## setosa, versicolor, virginica. This created a dispRity object (more about that here) with three subsets corresponding to each subspecies. 8.3.1 Bootstrapping the data We can the bootstrap the subsets to be able test the robustness of the measured disparity to outliers. We can do that using the default options of boot.matrix (more about that here): ## Bootstrapping the data (petal_bootstrapped <- boot.matrix(petal_subsets)) ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix with 4 dimensions: ## setosa, versicolor, virginica. ## Data was bootstrapped 100 times (method:"full"). 8.3.2 Calculating disparity Disparity can be calculated in many ways, therefore the dispRity function allows users to define their own measure of disparity. For more details on measuring disparity, see the dispRity metrics section. In this example, we are going to define disparity as the median distance between the different individuals and the centroid of the ordinated space. High values of disparity will indicate a generally high spread of points from this centroid (i.e. on average, the individuals are far apart in the ordinated space). We can define the metrics easily in the dispRity function by feeding them to the metric argument. Here we are going to feed the functions stats::median and dispRity::centroids which calculates distances between elements and their centroid. ## Calculating disparity as the median distance between each elements and ## the centroid of the petal-space (petal_disparity <- dispRity(petal_bootstrapped, metric = c(median, centroids))) ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix with 4 dimensions: ## setosa, versicolor, virginica. ## Data was bootstrapped 100 times (method:"full"). ## Disparity was calculated as: c(median, centroids). 8.3.3 Summarising the results (plot) Similarly to the custom.subsets and boot.matrix function, dispRity displays a dispRity object. But we are definitely more interested in actually look at the calculated values. First we can summarise the data in a table by simply using summary: ## Displaying the summary of the calculated disparity summary(petal_disparity) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 setosa 50 0.421 0.432 0.370 0.408 0.454 0.501 ## 2 versicolor 50 0.693 0.656 0.511 0.619 0.697 0.770 ## 3 virginica 50 0.785 0.747 0.580 0.674 0.806 0.936 We can also plot the results in a similar way: ## Graphical options par(bty = "n") ## Plotting the disparity in the petal_space plot(petal_disparity) Now contrary to simply plotting the two first axis of the PCA where we saw that the species have a different position in the two first petal-space, we can now also see that they occupy this space clearly differently! 8.3.4 Testing hypothesis Finally we can test our hypothesis that we guessed from the disparity plot (that some groups occupy different volume of the petal-space) by using the test.dispRity option. ## Running a PERMANOVA test.dispRity(petal_disparity, test = adonis.dispRity) ## Warning in test.dispRity(petal_disparity, test = adonis.dispRity): adonis.dispRity test will be applied to the data matrix, not to the calculated disparity. ## See ?adonis.dispRity for more details. ## Warning in adonis.dispRity(data, ...): The input data for adonis.dispRity was not a distance matrix. ## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])). ## Make sure that this is the desired methodological approach! ## Permutation test for adonis under reduced model ## Terms added sequentially (first to last) ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ group, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## group 2 592.07 0.86894 487.33 0.001 *** ## Residual 147 89.30 0.13106 ## Total 149 681.37 1.00000 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## Post-hoc testing of the differences between species (corrected for multiple tests) test.dispRity(petal_disparity, test = t.test, correction = "bonferroni") ## [[1]] ## statistic: t ## setosa : versicolor -29.998366 ## setosa : virginica -30.465933 ## versicolor : virginica -7.498179 ## ## [[2]] ## parameter: df ## setosa : versicolor 149.8429 ## setosa : virginica 124.4227 ## versicolor : virginica 175.4758 ## ## [[3]] ## p.value ## setosa : versicolor 9.579095e-65 ## setosa : virginica 4.625567e-59 ## versicolor : virginica 9.247421e-12 ## ## [[4]] ## stderr ## setosa : versicolor 0.007378905 ## setosa : virginica 0.010103449 ## versicolor : virginica 0.011530255 We can now see that there is a significant difference in petal-space occupancy between all species of iris. 8.3.4.1 Setting up a multidimensional null-hypothesis One other series of test can be done on the shape of the petal-space. Using a MCMC permutation test we can simulate a petal-space with specific properties and see if our observed petal-space matches these properties (similarly to Dı́az et al. (2016)): ## Testing against a uniform distribution disparity_uniform <- null.test(petal_disparity, replicates = 200, null.distrib = runif, scale = FALSE) plot(disparity_uniform) ## Testing against a normal distribution disparity_normal <- null.test(petal_disparity, replicates = 200, null.distrib = rnorm, scale = TRUE) plot(disparity_normal) In both cases we can see that our petal-space is not entirely normal or uniform. This is expected because of the simplicity of these parameters. References "],["palaeobiology-demo-disparity-through-time-and-within-groups.html", "9 Palaeobiology demo: disparity-through-time and within groups 9.1 Before starting 9.2 A disparity-through-time analysis 9.3 Some more advanced stuff", " 9 Palaeobiology demo: disparity-through-time and within groups This demo aims to give quick overview of the dispRity package (v.1.7) for palaeobiology analyses of disparity, including disparity through time analyses. This demo showcases a typical disparity-through-time analysis: we are going to test whether the disparity changed through time in a subset of eutherian mammals from the last 100 million years using a dataset from Beck and Lee (2014). 9.1 Before starting 9.1.1 The morphospace In this example, we are going to use a subset of the data from Beck and Lee (2014). See the example data description for more details. Briefly, this dataset contains an ordinated matrix of the Gower distance between 50 mammals based (BeckLee_mat50), another matrix of the same 50 mammals and the estimated discrete data characters of their descendants (thus 50 + 49 rows, BeckLee_mat99), a dataframe containing the ages of each taxon in the dataset (BeckLee_ages) and finally a phylogenetic tree with the relationships among the 50 mammals (BeckLee_tree). The ordinated matrix will represent our full morphospace, i.e. all the mammalian morphologies that ever existed through time (for this dataset). ## Loading demo and the package data library(dispRity) ## Setting the random seed for repeatability set.seed(123) ## Loading the ordinated matrix/morphospace: data(BeckLee_mat50) data(BeckLee_mat99) head(BeckLee_mat50[,1:5]) ## [,1] [,2] [,3] [,4] [,5] ## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 -0.18825039 ## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 -0.28510479 ## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 -0.07132646 ## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 -0.39962626 ## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 -0.37385914 ## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 -0.34857351 dim(BeckLee_mat50) ## [1] 50 48 ## The morphospace contains 50 taxa and has 48 dimensions (or axes) ## Showing a list of first and last occurrences data for some fossils data(BeckLee_ages) head(BeckLee_ages) ## FAD LAD ## Adapis 37.2 36.8 ## Asioryctes 83.6 72.1 ## Leptictis 33.9 33.3 ## Miacis 49.0 46.7 ## Mimotona 61.6 59.2 ## Notharctus 50.2 47.0 ## Plotting a phylogeny data(BeckLee_tree) plot(BeckLee_tree, cex = 0.7) axisPhylo(root = 140) You can have an even nicer looking tree if you use the strap package! if(!require(strap)) install.packages("strap") strap::geoscalePhylo(BeckLee_tree, cex.tip = 0.7, cex.ts = 0.6) 9.1.2 Setting up your own data I greatly encourage you to follow along this tutorial with your very own data: it is more exciting and, ultimately, that’s probably your objective. What data can I use? You can use any type of morphospace in any dataset form (\"matrix\", \"data.frame\"). Throughout this tutorial, you we assume you are using the (loose) morphospace definition from Thomas Guillerme, Cooper, et al. (2020): any matrix were columns are traits and rows are observations (in a distance matrix, columns are still trait, i.e. “distance to species A”, etc.). We won’t cover it here but you can also use lists of matrices and list of trees. How should I format my data for this tutorial? To go through this tutorial you will need: A matrix with tip data A phylogenetic tree A matrix with tip and node data A table of first and last occurrences data (FADLAD) If you are missing any of these, fear not, here are a couple of functions to simulate the missing data, it will surely make your results look funky but it’ll let you go through the tutorial. WARNING: the data generated by the functions i.need.a.matrix, i.need.a.tree, i.need.node.data and i.need.FADLAD are used to SIMULATE data for this tutorial. This is not to be used for publications or analysing real data! If you need a data matrix, a phylogenetic tree or FADLAD data, (i.need.a.matrix, i.need.a.tree and i.need.FADLAD), you will actually need to collect data from the literature or the field! If you need node data, you will need to use ancestral states estimations (e.g. using estimate_ancestral_states from the Claddis package). ## Functions to get simulate a PCO looking like matrix from a tree i.need.a.matrix <- function(tree) { matrix <- space.maker(elements = Ntip(tree), dimensions = Ntip(tree), distribution = rnorm, scree = rev(cumsum(rep(1/Ntip(tree), Ntip(tree))))) rownames(matrix) <- tree$tip.label return(matrix) } ## Function to simulate a tree i.need.a.tree <- function(matrix) { tree <- rtree(nrow(matrix)) tree$root.time <- max(tree.age(tree)$age) tree$tip.label <- rownames(matrix) tree$node.label <- paste0("n", 1:(nrow(matrix)-1)) return(tree) } ## Function to simulate some "node" data i.need.node.data <- function(matrix, tree) { matrix_node <- space.maker(elements = Nnode(tree), dimensions = ncol(matrix), distribution = rnorm, scree = apply(matrix, 2, var)) if(!is.null(tree$node.label)) { rownames(matrix_node) <- tree$node.label } else { rownames(matrix_node) <- paste0("n", 1:(nrow(matrix)-1)) } return(rbind(matrix, matrix_node)) } ## Function to simulate some "FADLAD" data i.need.FADLAD <- function(tree) { tree_ages <- tree.age(tree)[1:Ntip(tree),] return(data.frame(FAD = tree_ages[,1], LAD = tree_ages[,1], row.names = tree_ages[,2])) } You can use these functions for the generating the data you need. For example ## Aaaaah I don't have FADLAD data! my_FADLAD <- i.need.FADLAD(tree) ## Sorted. In the end this is what your data should be named to facilitate the rest of this tutorial (fill in yours here): ## A matrix with tip data my_matrix <- BeckLee_mat50 ## A phylogenetic tree my_tree <- BeckLee_tree ## A matrix with tip and node data my_tip_node_matrix <- BeckLee_mat99 ## A table of first and last occurrences data (FADLAD) my_fadlad <- BeckLee_ages 9.2 A disparity-through-time analysis 9.2.1 Splitting the morphospace through time One of the crucial steps in disparity-through-time analysis is to split the full morphospace into smaller time subsets that contain the total number of morphologies at certain points in time (time-slicing) or during certain periods in time (time-binning). Basically, the full morphospace represents the total number of morphologies across all time and will be greater than any of the time subsets of the morphospace. The dispRity package provides a chrono.subsets function that allows users to split the morphospace into time slices (using method = continuous) or into time bins (using method = discrete). In this example, we are going to split the morphospace into five equal time bins of 20 million years long from 100 million years ago to the present. We will also provide to the function a table containing the first and last occurrences dates for some fossils to take into account that some fossils might occur in several of our different time bins. ## Creating the vector of time bins ages time_bins <- rev(seq(from = 0, to = 100, by = 20)) ## Splitting the morphospace using the chrono.subsets function binned_morphospace <- chrono.subsets(data = my_matrix, tree = my_tree, method = "discrete", time = time_bins, inc.nodes = FALSE, FADLAD = my_fadlad) The output object is a dispRity object (see more about that here. In brief, dispRity objects are lists of different elements (i.e. disparity results, morphospace time subsets, morphospace attributes, etc.) that display only a summary of the object when calling the object to avoiding filling the R console with superfluous output. It also allows easy plotting/summarising/analysing for repeatability down the line but we will not go into this right now. ## Printing the class of the object class(binned_morphospace) ## [1] "dispRity" ## Printing the content of the object str(binned_morphospace) ## List of 4 ## $ matrix :List of 1 ## ..$ : num [1:50, 1:48] -0.561 -0.419 -0.834 -0.771 -0.832 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:50] "Cimolestes" "Maelestes" "Batodon" "Bulaklestes" ... ## .. .. ..$ : NULL ## $ tree :Class "multiPhylo" ## List of 1 ## ..$ :List of 6 ## .. ..$ edge : int [1:98, 1:2] 51 52 52 53 53 51 54 55 56 56 ... ## .. ..$ edge.length: num [1:98] 24.5 24.6 12.7 11.8 11.8 ... ## .. ..$ Nnode : int 49 ## .. ..$ tip.label : chr [1:50] "Daulestes" "Bulaklestes" "Uchkudukodon" "Kennalestes" ... ## .. ..$ node.labels: chr [1:49] "n1" "n2" "n3" "n4" ... ## .. ..$ root.time : num 139 ## .. ..- attr(*, "class")= chr "phylo" ## .. ..- attr(*, "order")= chr "cladewise" ## $ call :List of 1 ## ..$ subsets: Named chr [1:4] "discrete" "1" "1" "FALSE" ## .. ..- attr(*, "names")= chr [1:4] "" "trees" "matrices" "bind" ## $ subsets:List of 5 ## ..$ 100 - 80:List of 1 ## .. ..$ elements: int [1:8, 1] 5 4 6 8 43 10 11 42 ## ..$ 80 - 60 :List of 1 ## .. ..$ elements: int [1:15, 1] 7 8 9 1 2 3 12 13 14 44 ... ## ..$ 60 - 40 :List of 1 ## .. ..$ elements: int [1:13, 1] 41 49 24 25 26 27 28 21 22 19 ... ## ..$ 40 - 20 :List of 1 ## .. ..$ elements: int [1:6, 1] 15 39 40 35 23 47 ## ..$ 20 - 0 :List of 1 ## .. ..$ elements: int [1:10, 1] 36 37 38 32 33 34 50 48 29 30 ## - attr(*, "class")= chr "dispRity" names(binned_morphospace) ## [1] "matrix" "tree" "call" "subsets" ## Printing the object as a dispRity class binned_morphospace ## ---- dispRity object ---- ## 5 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 100 - 80, 80 - 60, 60 - 40, 40 - 20, 20 - 0. These objects will gradually contain more information when completing the following steps in the disparity-through-time analysis. 9.2.2 Bootstrapping the data Once we obtain our different time subsets, we can bootstrap and rarefy them (i.e. pseudo-replicating the data). The bootstrapping allows us to make each subset more robust to outliers and the rarefaction allows us to compare subsets with the same number of taxa to remove sampling biases (i.e. more taxa in one subset than the others). The boot.matrix function bootstraps the dispRity object and the rarefaction option within performs rarefaction. ## Getting the minimum number of rows (i.e. taxa) in the time subsets minimum_size <- min(size.subsets(binned_morphospace)) ## Bootstrapping each time subset 100 times and rarefying them rare_bin_morphospace <- boot.matrix(binned_morphospace, bootstraps = 100, rarefaction = minimum_size) Note how information is adding up to the dispRity object. 9.2.3 Calculating disparity We can now calculate the disparity within each time subsets along with some confidence intervals generated by the pseudoreplication step above (bootstraps/rarefaction). Disparity can be calculated in many ways and this package allows users to come up with their own disparity metrics. For more details, please refer to the dispRity metric section (or directly use moms). In this example, we are going to look at how the spread of the data in the morphospace through time. For that we are going to use the sum of the variance from each dimension of the morphospace in the morphospace. We highly recommend using a metric that makes sense for your specific analysis and for your specific dataset and not just because everyone uses it (Thomas Guillerme, Puttick, et al. 2020, @Guillerme2020)! How can I be sure that the metric is the most appropriate for my morphospace and question? This is not a straightforward question but you can use the test.metric function to check your assumptions (more details here): basically what test.metric does is modifying your morphospace using a null process of interest (e.g. changes in size) and checks whether your metric does indeed pick up that change. For example here, let see if the sum of variances picks up changes in size but not random changes: my_test <- test.metric(my_matrix, metric = c(sum, dispRity::variances), shifts = c("random", "size")) summary(my_test) ## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope ## random 2.41 2.51 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0006434981 ## size.increase 2.23 2.19 2.25 2.33 2.31 2.35 2.43 2.44 2.48 2.52 0.0036071419 ## size.hollowness 2.40 2.56 2.56 2.60 2.63 2.64 2.60 2.58 2.55 2.52 0.0006032204 ## p_value R^2(adj) ## random 3.046683e-02 0.12638784 ## size.increase 4.009847e-16 0.90601561 ## size.hollowness 1.324664e-01 0.04783366 plot(my_test) We see that changes in the inner size (see Thomas Guillerme, Puttick, et al. (2020) for more details) is actually picked up by the sum of variances but not random changes or outer changes. Which is a good thing! As you’ve noted, the sum of variances is defined in test.metric as c(sum, variances). This is a core bit of the dispRity package were you can define your own metric as a function or a set of functions. You can find more info about this in the dispRity metric section but in brief, the dispRity package considers metrics by their “dimensions” level which corresponds to what they output. For example, the function sum is a dimension level 1 function because no matter the input it outputs a single value (the sum), variances on the other hand is a dimension level 2 function because it will output the variance of each column in a matrix (an example of a dimensions level 3 would be the function var that outputs a matrix). The dispRity package always automatically sorts the dimensions levels: it will always run dimensions level 3 > dimensions level 2 > and dimensions level 1. In this case both c(sum, variances) and c(variances, sum) will result in actually running sum(variances(matrix)). Anyways, let’s calculate the sum of variances on our bootstrapped and rarefied morphospaces: ## Calculating disparity for the bootstrapped and rarefied data disparity <- dispRity(rare_bin_morphospace , metric = c(sum, dispRity::variances)) To display the actual calculated scores, we need to summarise the disparity object using the S3 method summary that is applied to a dispRity object (see ?summary.dispRity for more details). By the way, as for any R package, you can refer to the help files for each individual function for more details. ## Summarising the disparity results summary(disparity) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 100 - 80 8 2.207 1.962 1.615 1.876 2.017 2.172 ## 2 100 - 80 6 NA 1.923 1.477 1.768 2.065 2.222 ## 3 80 - 60 15 2.315 2.167 1.979 2.111 2.227 2.308 ## 4 80 - 60 6 NA 2.167 1.831 2.055 2.300 2.460 ## 5 60 - 40 13 2.435 2.244 2.006 2.183 2.304 2.384 ## 6 60 - 40 6 NA 2.284 1.683 2.140 2.383 2.532 ## 7 40 - 20 6 2.604 2.206 1.628 2.026 2.388 2.604 ## 8 20 - 0 10 2.491 2.257 1.958 2.170 2.326 2.421 ## 9 20 - 0 6 NA 2.302 1.766 2.143 2.366 2.528 The summary.dispRity function comes with many options on which values to calculate (central tendency and quantiles) and on how many digits to display. Refer to the function’s manual for more details. 9.2.4 Plotting the results It is sometimes easier to visualise the results in a plot than in a table. For that we can use the plot S3 function to plot the dispRity objects (see ?plot.dispRity for more details). ## Graphical options quartz(width = 10, height = 5) ; par(mfrow = (c(1,2)), bty = "n") ## Warning in quartz(width = 10, height = 5): Quartz device is not available on ## this platform ## Plotting the bootstrapped and rarefied results plot(disparity, type = "continuous", main = "bootstrapped results") plot(disparity, type = "continuous", main = "rarefied results", rarefaction = minimum_size) Nice. The curves look pretty similar. Same as for the summary.dispRity function, check out the plot.dispRity manual for the many, many options available. 9.2.5 Testing differences Finally, to draw some valid conclusions from these results, we can apply some statistical tests. We can test, for example, if mammalian disparity changed significantly through time over the last 100 million years. To do so, we can compare the means of each time-bin in a sequential manner to see whether the disparity in bin n is equal to the disparity in bin n+1, and whether this is in turn equal to the disparity in bin n+2, etc. Because our data is temporally autocorrelated (i.e. what happens in bin n+1 depends on what happened in bin n) and pseudoreplicated (i.e. each bootstrap draw creates non-independent time subsets because they are all based on the same time subsets), we apply a non-parametric mean comparison: the wilcox.test. Also, we need to apply a p-value correction (e.g. Bonferroni correction) to correct for multiple testing (see ?p.adjust for more details). ## Testing the differences between bins in the bootstrapped dataset. test.dispRity(disparity, test = wilcox.test, comparison = "sequential", correction = "bonferroni") ## [[1]] ## statistic: W ## 100 - 80 : 80 - 60 730 ## 80 - 60 : 60 - 40 2752 ## 60 - 40 : 40 - 20 5461 ## 40 - 20 : 20 - 0 4506 ## ## [[2]] ## p.value ## 100 - 80 : 80 - 60 7.081171e-25 ## 80 - 60 : 60 - 40 1.593988e-07 ## 60 - 40 : 40 - 20 1.000000e+00 ## 40 - 20 : 20 - 0 9.115419e-01 ## Testing the differences between bins in the rarefied dataset. test.dispRity(disparity, test = wilcox.test, comparison = "sequential", correction = "bonferroni", rarefaction = minimum_size) ## [[1]] ## statistic: W ## 100 - 80 : 80 - 60 1518 ## 80 - 60 : 60 - 40 3722 ## 60 - 40 : 40 - 20 5676 ## 40 - 20 : 20 - 0 4160 ## ## [[2]] ## p.value ## 100 - 80 : 80 - 60 7.158946e-17 ## 80 - 60 : 60 - 40 7.199018e-03 ## 60 - 40 : 40 - 20 3.953427e-01 ## 40 - 20 : 20 - 0 1.609715e-01 Here our results show significant changes in disparity through time between all time bins (all p-values < 0.05). However, when looking at the rarefied results, there is no significant difference between the time bins in the Palaeogene (60-40 to 40-20 Mya), suggesting that the differences detected in the first test might just be due to the differences in number of taxa sampled (13 or 6 taxa) in each time bin. 9.3 Some more advanced stuff The previous section detailed some of the basic functionalities in the dispRity package but of course, you can do some much more advanced analysis, here is just a list of some specific tutorials from this manual that you might be interested in: Time slicing: an alternative method to look at disparity through time that allows you to specify evolutionary models (Guillerme and Cooper 2018). Many more disparity metrics: there are many, many different things you might be interested to measure in your morphospace! This manual has some extended documentation on what to use (or check Thomas Guillerme, Puttick, et al. (2020)). Many more ways to look at disparity: you can for example, use distributions rather than point estimates for your disparity metric (e.g. the variances rather than the sum of variances); or calculate disparity from non ordinated matrices or even from multiple matrices and trees. And finally there are much more advanced statistical tests you might be interested in using, such as the NPMANOVA, the “disparity-through-time test”, using a null model approach or some model fitting… You can even come up with your own ideas, implementations and modifications of the package: the dispRity package is a modular and collaborative package and I encourage you to contact me (guillert@tcd.e) for any ideas you have about adding new features to the package (whether you have them already implemented or not)! References "],["morphometric-geometric-demo-a-between-group-analysis.html", "10 Morphometric geometric demo: a between group analysis 10.1 Before starting 10.2 Calculating disparity 10.3 Analyse the results", " 10 Morphometric geometric demo: a between group analysis This demo aims to give quick overview of the dispRity package (v.1.7) for palaeobiology analyses of disparity, including disparity through time analyses. This demo showcases a typical between groups geometric morphometric analysis: we are going to test whether the disparity in two species of salamander (plethodons!) are different and in which ways they are different. 10.1 Before starting Here we are going to use the geomorph plethodon dataset that is a set of 12 2D landmark coordinates for 40 specimens from two species of salamanders. This section will really quickly cover how to make a Procrustes sumperimposition analysis and create a geomorph data.frame to have data ready for the dispRity package. ## Loading geomorph library(geomorph) ## Loading the plethodon dataset data(plethodon) ## Running a simple Procrustes superimposition gpa_plethodon <- gpagen(plethodon$land) ## ## Performing GPA ## | | | 0% | |================== | 25% | |=================================== | 50% | |======================================================================| 100% ## ## Making projections... Finished! ## Making a geomorph data frame object with the species and sites attributes gdf_plethodon <- geomorph.data.frame(gpa_plethodon, species = plethodon$species, site = plethodon$site) You can of course use your very own landmark coordinates dataset (though you will have to do some modifications in the scripts that will come below - they will be easy though!). ## You can replace the gdf_plethodon by your own geomorph data frame! my_geomorph_data <- gdf_plethodon 10.1.1 The morphospace The first step of every disparity analysis is to define your morphospace. Note that this is actually not true at all and kept as a erroneous sentence: the first step of your disparity analysis should be to define your question! Our question here will be: is there a difference in disparity between the different species of salamanders and between the different sites (allopatric and sympatric)? OK, now we can go to the second step of every disparity analysis: defining the morphospace. Here we will define it with the ordination of all possible Procrustes superimposed plethodon landmark coordinates. You can do this directly in dispRity using the geomorph.ordination function that can input a geomorph data frame: ## The morphospace morphospace <- geomorph.ordination(gdf_plethodon) This automatically generates a dispRity object with the information of each groups. You can find more information about dispRity objects here but basically it summarises the content of your object without spamming your R console and is associated with many utility functions like summary or plot. For example here you can quickly visualise the two first dimensions of your space using the plot function: ## The dispRity object morphospace ## ---- dispRity object ---- ## 4 customised subsets for 40 elements in one matrix: ## species.Jord, species.Teyah, site.Allo, site.Symp. ## Plotting the morphospace plot(morphospace) ## Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap! The dispRity package function comes with a lot of documentation of examples so don’t hesitate to type plot.dispRity to check more plotting options. 10.2 Calculating disparity Now that we have our morphospace, we can think about what we want to measure. Two aspects of disparity that would be interesting for our question (is there a difference in disparity between the different species of salamanders and between the different sites?) would be the differences in size in the morphospace (do both groups occupy the same amount of morphospace) and position in the morphospace (do the do groups occupy the same position in the morphospace?). To choose which metric would cover best these two aspects, please check the Thomas Guillerme, Puttick, et al. (2020) paper and associated app. Here we are going to use the procrustes variance (geomorph::morphol.disparity) for measuring the size of the trait space and the average displacements (Thomas Guillerme, Puttick, et al. 2020) for the position in the trait space. ## Defining a the procrustes variance metric ## (as in geomorph::morphol.disparity) proc.var <- function(matrix) {sum(matrix^2)/nrow(matrix)} ## The size metric test_size <- test.metric(morphospace, metric = proc.var, shifts = c("random", "size")) plot(test_size) summary(test_size) ## The position metric test_position <- test.metric(morphospace, metric = c(mean, displacements), shifts = c("random", "position")) plot(test_position) summary(test_position) You can see here for more details on the test.metric function but basically these graphs are showing that there is a relation between changes in size and in position for each metric. Note that there are some caveats here but the selection of the metric is just for the sake of the example! Note also the format of defining the disparity metrics here using metric = c(mean, displacements) or metric = proc.var. This is a core bit of the dispRity package were you can define your own metric as a function or a set of functions. You can find more info about this in the dispRity metric section but in brief, the dispRity package considers metrics by their “dimensions” level which corresponds to what they output. For example, the function mean is a dimension level 1 function because no matter the input it outputs a single value (the mean), displacements on the other hand is a dimension level 2 function because it will output the ratio between the distance from the centroid and from the centre of the trait space for each row in a matrix (an example of a dimensions level 3 would be the function var that outputs a matrix). The dispRity package always automatically sorts the dimensions levels: it will always run dimensions level 3 > dimensions level 2 > and dimensions level 1. In this case both c(mean, displacements) and c(mean, displacements) will result in actually running mean(displacements(matrix)). Alternatively you can define your metric prior to the disparity analysis like we did for the proc.var function. Anyways, we can measure disparity using these two metrics on all the groups as follows: ## Bootstrapped disparity disparity_size <- dispRity(boot.matrix(morphospace), metric = proc.var) disparity_position <- dispRity(boot.matrix(morphospace), metric = c(mean, displacements)) Note that here we use the boot.matrix function for quickly bootstrapping the matrix. This is not an essential step in this kind of analysis but it allows to “reduce” the effect of outliers and create a distribution of disparity measures (rather than single point estimates). 10.3 Analyse the results We can visualise the results using the plot function on the resulting disparity objects (or summarising them using summary): ## Plotting the results par(mfrow = c(1,2)) plot(disparity_size, main = "group sizes", las = 2, xlab = "") plot(disparity_position, main = "group positions", las = 2, xlab = "") ## Summarising the results summary(disparity_size) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.006 ## 2 species.Teyah 20 0.005 0.005 0.004 0.005 0.005 0.006 ## 3 site.Allo 20 0.004 0.004 0.003 0.003 0.004 0.004 ## 4 site.Symp 20 0.006 0.006 0.006 0.006 0.006 0.007 summary(disparity_position) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 species.Jord 20 1.096 1.122 1.067 1.101 1.171 1.380 ## 2 species.Teyah 20 1.070 1.105 1.033 1.065 1.143 1.345 ## 3 site.Allo 20 1.377 1.407 1.315 1.381 1.448 1.530 ## 4 site.Symp 20 1.168 1.221 1.148 1.187 1.269 1.458 Just from looking at the data, we can guess that there is not much difference in terms of morphospace occupancy and position for the species but there is on for the sites (allopatric or sympatric). We can test it using a simple non-parametric mean difference test (e.g. wilcox.test) using the dispRity package. ## Testing the differences test.dispRity(disparity_size, test = wilcox.test, correction = "bonferroni") ## [[1]] ## statistic: W ## species.Jord : species.Teyah 3803 ## species.Jord : site.Allo 9922 ## species.Jord : site.Symp 14 ## species.Teyah : site.Allo 9927 ## species.Teyah : site.Symp 238 ## site.Allo : site.Symp 0 ## ## [[2]] ## p.value ## species.Jord : species.Teyah 2.076623e-02 ## species.Jord : site.Allo 1.572891e-32 ## species.Jord : site.Symp 2.339811e-33 ## species.Teyah : site.Allo 1.356528e-32 ## species.Teyah : site.Symp 1.657077e-30 ## site.Allo : site.Symp 1.537286e-33 test.dispRity(disparity_position, test = wilcox.test, correction = "bonferroni") ## [[1]] ## statistic: W ## species.Jord : species.Teyah 6536 ## species.Jord : site.Allo 204 ## species.Jord : site.Symp 1473 ## species.Teyah : site.Allo 103 ## species.Teyah : site.Symp 1042 ## site.Allo : site.Symp 9288 ## ## [[2]] ## p.value ## species.Jord : species.Teyah 1.053318e-03 ## species.Jord : site.Allo 6.238014e-31 ## species.Jord : site.Symp 4.137900e-17 ## species.Teyah : site.Allo 3.289139e-32 ## species.Teyah : site.Symp 2.433117e-21 ## site.Allo : site.Symp 6.679158e-25 So by applying the tests we see a difference in terms of position between each groups and differences in size between groups but between the species. References "],["disprity-r-package-manual.html", "11 dispRity R package manual", " 11 dispRity R package manual "],["references.html", "References", " References "],["references-1.html", "12 References", " 12 References "],["404.html", "Page not found", " Page not found The page you requested cannot be found (perhaps it was moved or renamed). You may want to try searching to find the page's new location, or use the table of contents to find the page you are looking for. "]]
+[["index.html", "dispRity R package manual 1 dispRity 1.1 What is dispRity? 1.2 Installing and running the package 1.3 Which version do I choose? 1.4 dispRity is always changing, how do I know it’s not broken? 1.5 Help 1.6 Citations", " dispRity R package manual Thomas Guillerme (guillert@tcd.ie) 2024-11-12 1 dispRity This is a package for measuring disparity (aka multidimensional space occupancy) in R. It allows users to summarise matrices as representations as multidimensional spaces into a single value or distribution describing a specific aspect of this multidimensional space (the disparity). Multidimensional spaces can be ordinated matrices from MDS, PCA, PCO, PCoA but the package is not restricted to any type of matrices! This manual is based on the version 1.7. 1.1 What is dispRity? This is a modular package for measuring disparity in R. It allows users to summarise ordinated matrices (e.g. MDS, PCA, PCO, PCoA) to perform some multidimensional analysis. Typically, these analysis are used in palaeobiology and evolutionary biology to study the changes in morphology through time. However, there are many more applications in ecology, evolution and beyond. 1.1.1 Modular? Because their exist a multitude of ways to measure disparity, each adapted to every specific question, this package uses an easy to modify modular architecture. In coding, each module is simply a function or a modification of a function that can be passed to the main functions of the package to tweak it to your proper needs! In practice, you will notice throughout this manual that some function can take other functions as arguments: the modular architecture of this package allows you to use any function for these arguments (with some restrictions explained for each specific cases). This will allow you to finely tune your multidimensional analysis to the needs of your specific question! 1.2 Installing and running the package You can install this package easily, directly from the CRAN: install.packages("dispRity") Alternatively, for the most up to data version and some functionalities not compatible with the CRAN, you can use the package through GitHub using devtool (see to CRAN or not to CRAN? for more details): ## Checking if devtools is already installed if(!require(devtools)) install.packages("devtools") ## Installing the latest released version directly from GitHub install_github("TGuillerme/dispRity", ref = "release") Note this uses the release branch (1.7). For the piping-hot (but potentially unstable) version, you can change the argument ref = release to ref = master. dispRity depends mainly on the ape package and uses functions from several other packages (ade4, geometry, grDevices, hypervolume, paleotree, snow, Claddis, geomorph and RCurl). 1.3 Which version do I choose? There are always three version of the package available: The CRAN one The GitHub release one The GitHub master one The differences between the CRAN one and the GitHub release or master ones is explained just above. For the the GitHub version, the differences are that the release one is more stable (i.e. more rarely modified) and the master one is more live one (i.e. bug fixes and new functionalities are added as they come). If you want the latest-latest version of the package I suggest using the GitHub master one, especially if you recently emailed me reporting a minor bug or wanting a new functionality! Note however that it can happen that the master version can sometimes be bugged (especially when there are major R and R packages updates), however, the status of the package state on both the release and the master version is constantly displayed on the README page of the package with the nice badges displaying these different (and constantly tested) information. 1.4 dispRity is always changing, how do I know it’s not broken? This is a really common a legitimate question in software development. Like R itself: dispRity is free software and comes with ABSOLUTELY NO WARRANTY. So you are using it at your own risk. HOWEVER, there are two points that can be used as objective-ish markers on why it’s OK to use dispRity. First, the package has been use in a number of peer reviewed publications (the majority of them independently) which could be taken as warranty. Second, I spend a lot of time and attention in making sure that every function in every version actually does what I think it is supposed to do. This is done through CI; continuous integration development, the CRAN check, and unit testing. The two first checks (CRAN and CI) ensure that the version you are using is not bugged (the CRAN check if you are using the CRAN version and the Travis CI if you are using a GitHub version). The third check, unit testing, is checking that every function is doing what it is supposed to do. For a real basic example, it is testing that the following expression should always return the same thing no matter what changes in the package. > mean(c(1,2,3)) [1] 2 Or, more formally: testthat::expect_equal(object = mean(c(1,2,3)), expected = 2) You can always access what is actually tested in the test/testthat sub-folder. For example here is how the core function dispRity is tested (through > 500 tests!). All these tests are run every time a change is made to the package and you can always see for yourself how much a single function is covered (i.e. what percentage of the function is actually covered by at least one test). You can always see the global coverage here or the specific coverage for each function here. Finally, this package is build on the shoulders of the whole open science philosophy so when bugs do occur and are caught by myself or the package users, they are quickly fixed and notified in the NEWS.md file. And all the changes to the package are public and annotated so there’s that too… 1.5 Help If you need help with the package, hopefully the following manual will be useful. However, parts of this package are still in development and some other parts are probably not covered. Thus if you have suggestions or comments on on what has already been developed or will be developed, please send me an email (guillert@tcd.ie) or if you are a GitHub user, directly create an issue on the GitHub page. 1.6 Citations To cite the package, this manual or some specific functionalities, you can use the following references: The package main paper: Guillerme T. dispRity: A modular R package for measuring disparity. Methods Ecol Evol. 2018;9:1755–1763. doi.org/10.1111/2041-210X.13022. The package manual (regularly updated!): Guillerme, T. & Cooper, N. (2018): dispRity manual. figshare. Preprint. 10.6084/m9.figshare.6187337.v1. The time-slicing method implemented in chrono.subsets (unfortunately not Open Access, but you can still get a free copy from here): Guillerme, T. and Cooper, N. (2018), Time for a rethink: time sub-sampling methods in disparity-through-time analyses. Palaeontology, 61: 481-493. doi:10.1111/pala.12364. Furthermore, don’t forget to cite R: R Core Team (2020). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/. Bonus: you can also cite ape since the dispRity package heavily relies on it: Paradis E. & Schliep K. 2019. ape 5.0: an environment for modern phylogenetics and evolutionary analyses in R. Bioinformatics 35: 526-528. 1.6.1 Why is it important to cite us? Aside from how science works (if you’re using a method from a specific paper, cite that specific paper to refer to that specific method), why is it important to also cite the package and the manual? All the people involve in making the dispRity package happened to do it enthusiastically, freely and most amazingly without asking anything in return! I created the package with this idea in mind and I am still sticking to it. However, academia (the institutions and people producing science around the globe) is unfortunately not optimal at many level (some might even say “broken”): high impact papers attract big grants that attract high impact papers and big grants again, all this along with livelihood, permanent position and job security. Unfortunately however, method development has a hard time to catch up with the current publish or perish system: constantly updating the dispRity package and this manual is hugely time consuming (but really fun!) and that is not even taking into account maintenance and helping users. Although I do truly believe that this time spent doing these things modestly help the scientific endeavour, it does not contribute to our paper list! Therefore, by citing the package and this manual, you help provide visibility to other workers and you might help them in their work! And you directly contribute in making this project fun for all the people involved and most of all, free, updated and independent from the publish and perish system! Thank you! "],["glossary.html", "2 Glossary 2.1 Glossary equivalences in palaeobiology and ecology", " 2 Glossary Multidimensional space (or just space). The mathematical multidimensional object that will be analysed with this package. In morphometrics, this is often referred to as the morphospace. However it may also be referred to as the cladisto-space for cladistic data or the eco-space for ecological data etc. In practice, this term designates a matrix where the columns represent the dimensions of the space (often – but not necessarily - > 3!) and the rows represent the elements within this space. Elements. The rows of the multidimensional space matrix. Elements can be taxa, field sites, countries etc. Dimensions. The columns of the multidimensional space matrix. The dimensions can be referred to as axes of variation, or principal components, for ordinated spaces obtained from a PCA for example. Subsets. Subsets of the multidimensional space. A subset (or subsets) contains the same number of dimensions as the space but may contain a smaller subset of elements. For example, if our space is composed of birds and mammals (the elements) and 50 principal components of variation (the dimensions), we can create two subsets containing just mammals or birds, but with the same 50 dimensions, to compare disparity in the two clades. Disparity. A metric expressing the similarities/dissimilarities of the elements within the space or a summarising the space dimensions. For example the pairwise distances between elements or the range of each dimensions. 2.1 Glossary equivalences in palaeobiology and ecology In this manual In dispRity E.g. in palaeobiology E.g. in ecology the multidimensional space a matrix object (\\(n\\times d\\)) a morphospace a function-space elements rows (\\(n\\)) taxa field experiments dimensions columns (\\(d\\)) morphological characters communities’ compositions subsets a matrix (\\(m \\times d\\), with \\(m \\leq n\\)) time series experimental treatments disparity a function sum of variances ellipsoid volume "],["getting-started-with-disprity.html", "3 Getting started with dispRity 3.1 What sort of data does dispRity work with? 3.2 Ordinated matrices 3.3 Performing a simple dispRity analysis", " 3 Getting started with dispRity 3.1 What sort of data does dispRity work with? Any matrix object in R. Disparity can be estimated from pretty much any matrix as long as rows represent the elements and columns the dimensions. These matrices can be observations, pairwise differences between elements, ordinations, etc… Since version 1.4 it is also possible to include a \"list\" containing matrices. These matrices need to have the same dimensions and rownames but can contain different values. This is especially useful for modelling uncertainty (see here for more details). 3.2 Ordinated matrices Classically, when a high number of variables is used, disparity is calculated from ordinated matrices. These can be any type of ordinations (PCO, PCA, PCoA, MDS, etc.) as long as elements are the rows (taxa, countries, field experiments) and the dimensions are the columns. However, note that this is not required from any of the functions in this package. You can also use distance matrices or any other matrix type that suits your question and your analysis! 3.2.1 Ordination matrices from geomorph You can also easily use data from geomorph using the geomorph.ordination function. This function simply takes Procrustes aligned data and performs an ordination: require(geomorph) ## Loading the plethodon dataset data(plethodon) ## Performing a Procrustes transform on the landmarks procrustes <- gpagen(plethodon$land, PrinAxes = FALSE, print.progress = FALSE) ## Ordinating this data geomorph.ordination(procrustes)[1:5,1:5] ## PC1 PC2 PC3 PC4 PC5 ## [1,] -0.0369930887 0.05118246 -0.0016971586 -0.003128881 -0.010935739 ## [2,] -0.0007493689 0.05942083 0.0001371682 -0.002768621 -0.008117767 ## [3,] 0.0056004751 0.07419599 -0.0052612189 -0.005034502 -0.002747104 ## [4,] -0.0134808326 0.06463958 -0.0458436274 -0.007887336 0.009817034 ## [5,] -0.0334696064 0.06863518 0.0136292227 0.007359383 0.022347215 Options for the ordination (from ?prcomp) can be directly passed to this function to perform customised ordinations. Additionally you can give the function a geomorph.data.frame object. If the latter contains sorting information (i.e. factors), they can be directly used to make a customised dispRity object customised dispRity object! ## Using a geomorph.data.frame geomorph_df <- geomorph.data.frame(procrustes, species = plethodon$species, site = plethodon$site) ## Ordinating this data and making a dispRity object geomorph.ordination(geomorph_df) ## ---- dispRity object ---- ## 4 customised subsets for 40 elements in one matrix: ## species.Jord, species.Teyah, site.Allo, site.Symp. More about these dispRity objects below! 3.2.2 Ordination matrices from Claddis dispRity package can also easily take data from the Claddis package using the Claddis.ordination function. For this, simply input a matrix in the Claddis format to the function and it will automatically calculate and ordinate the distances among taxa: require(Claddis) ## Ordinating the example data from Claddis Claddis.ordination(michaux_1989) ## [,1] [,2] [,3] ## Ancilla 0.000000e+00 4.154578e-01 0.2534942 ## Turrancilla -5.106645e-01 -1.304614e-16 -0.2534942 ## Ancillista 5.106645e-01 -1.630768e-17 -0.2534942 ## Amalda 1.603581e-16 -4.154578e-01 0.2534942 Note that several options are available, namely which type of distance should be computed. See more info in the function manual (?Claddis.ordination). Alternatively, it is of course also possible to manual calculate the ordination matrix using the functions Claddis::calculate_morphological_distances and stats::cmdscale. 3.2.3 Other kinds of ordination matrices If you are not using the packages mentioned above (Claddis and geomorph) you can easily make your own ordination matrices by using the following functions from the stats package. Here is how to do it for the following types of matrices: Multivariate matrices (principal components analysis; PCA) ## A multivariate matrix head(USArrests) ## Murder Assault UrbanPop Rape ## Alabama 13.2 236 58 21.2 ## Alaska 10.0 263 48 44.5 ## Arizona 8.1 294 80 31.0 ## Arkansas 8.8 190 50 19.5 ## California 9.0 276 91 40.6 ## Colorado 7.9 204 78 38.7 ## Ordinating the matrix using `prcomp` ordination <- prcomp(USArrests) ## Selecting the ordinated matrix ordinated_matrix <- ordination$x head(ordinated_matrix) ## PC1 PC2 PC3 PC4 ## Alabama 64.80216 -11.448007 -2.4949328 -2.4079009 ## Alaska 92.82745 -17.982943 20.1265749 4.0940470 ## Arizona 124.06822 8.830403 -1.6874484 4.3536852 ## Arkansas 18.34004 -16.703911 0.2101894 0.5209936 ## California 107.42295 22.520070 6.7458730 2.8118259 ## Colorado 34.97599 13.719584 12.2793628 1.7214637 This results in a ordinated matrix with US states as elements and four dimensions (PC 1 to 4). For an alternative method, see the ?princomp function. Distance matrices (classical multidimensional scaling; MDS) ## A matrix of distances between cities str(eurodist) ## 'dist' num [1:210] 3313 2963 3175 3339 2762 ... ## - attr(*, "Size")= num 21 ## - attr(*, "Labels")= chr [1:21] "Athens" "Barcelona" "Brussels" "Calais" ... ## Ordinating the matrix using cmdscale() with k = 5 dimensions ordinated_matrix <- cmdscale(eurodist, k = 5) head(ordinated_matrix) ## [,1] [,2] [,3] [,4] [,5] ## Athens 2290.27468 1798.8029 53.79314 -103.82696 -156.95511 ## Barcelona -825.38279 546.8115 -113.85842 84.58583 291.44076 ## Brussels 59.18334 -367.0814 177.55291 38.79751 -95.62045 ## Calais -82.84597 -429.9147 300.19274 106.35369 -180.44614 ## Cherbourg -352.49943 -290.9084 457.35294 111.44915 -417.49668 ## Cologne 293.68963 -405.3119 360.09323 -636.20238 159.39266 This results in a ordinated matrix with European cities as elements and five dimensions. Of course any other method for creating the ordination matrix is totally valid, you can also not use any ordination at all! The only requirements for the dispRity functions is that the input is a matrix with elements as rows and dimensions as columns. 3.3 Performing a simple dispRity analysis Two dispRity functions allow users to run an analysis pipeline simply by inputting an ordination matrix. These functions allow users to either calculate the disparity through time (dispRity.through.time) or the disparity of user-defined groups (dispRity.per.group). IMPORTANT Note that disparity.through.time and disparity.per.group are wrapper functions (i.e. they incorporate lots of other functions) that allow users to run a basic disparity-through-time, or disparity among groups, analysis without too much effort. As such they use a lot of default options. These are described in the help files for the functions that are used to make the wrapper functions, and not described in the help files for disparity.through.time and disparity.per.group. These defaults are good enough for data exploration, but for a proper analysis you should consider the best parameters for your question and data. For example, which metric should you use? How many bootstraps do you require? What model of evolution is most appropriate if you are time slicing? Should you rarefy the data? See chrono.subsets, custom.subsets, boot.matrix and dispRity.metric for more details of the defaults used in each of these functions. Note that any of these default arguments can be changed within the disparity.through.time or disparity.per.group functions. 3.3.1 Example data To illustrate these functions, we will use data from Beck and Lee (2014). This dataset contains an ordinated matrix of 50 discrete characters from mammals (BeckLee_mat50), another matrix of the same 50 mammals and the estimated discrete data characters of their descendants (thus 50 + 49 rows, BeckLee_mat99), a dataframe containing the ages of each taxon in the dataset (BeckLee_ages) and finally a phylogenetic tree with the relationships among the 50 mammals (BeckLee_tree). ## Loading the ordinated matrices data(BeckLee_mat50) data(BeckLee_mat99) ## The first five taxa and dimensions of the 50 taxa matrix head(BeckLee_mat50[, 1:5]) ## [,1] [,2] [,3] [,4] [,5] ## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039 ## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479 ## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646 ## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626 ## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914 ## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351 ## The first five taxa and dimensions of the 99 taxa + ancestors matrix BeckLee_mat99[c(1, 2, 98, 99), 1:5] ## [,1] [,2] [,3] [,4] [,5] ## Cimolestes -0.6662114 0.152778203 0.04859246 -0.34158286 0.26817202 ## Maelestes -0.5719365 0.051636855 -0.19877079 -0.08318416 -0.14166592 ## n48 0.2511551 -0.002014967 0.22408002 0.06857018 -0.05660113 ## n49 0.3860798 0.131742956 0.12604056 -0.14738050 0.05095751 ## Loading a list of first and last occurrence dates for the fossils data(BeckLee_ages) head(BeckLee_ages) ## FAD LAD ## Adapis 37.2 36.8 ## Asioryctes 83.6 72.1 ## Leptictis 33.9 33.3 ## Miacis 49.0 46.7 ## Mimotona 61.6 59.2 ## Notharctus 50.2 47.0 ## Loading and plotting the phylogeny data(BeckLee_tree) plot(BeckLee_tree, cex = 0.8) axisPhylo(root = 140) nodelabels(cex = 0.5) Of course you can use your own data as detailed in the previous section. 3.3.2 Disparity through time The dispRity.through.time function calculates disparity through time, a common analysis in palaeontology. This function (and the following one) uses an analysis pipeline with a lot of default parameters to make the analysis as simple as possible. Of course all the defaults can be changed if required, more on this later. For a disparity through time analysis, you will need: An ordinated matrix (we covered that above) A phylogenetic tree: this must be a phylo object (from the ape package) and needs a root.time element. To give your tree a root time (i.e. an age for the root), you can simply do\\ my_tree$root.time <- my_age. The required number of time subsets (here time = 3) Your favourite disparity metric (here the sum of variances) Using the Beck and Lee (2014) data described above: ## Measuring disparity through time disparity_data <- dispRity.through.time(BeckLee_mat50, BeckLee_tree, metric = c(sum, variances), time = 3) This generates a dispRity object (see here for technical details). When displayed, these dispRity objects provide us with information on the operations done to the matrix: ## Print the disparity_data object disparity_data ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 48 dimensions with 1 phylogenetic tree ## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0. ## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: metric. We asked for three subsets (evenly spread across the age of the tree), the data was bootstrapped 100 times (default) and the metric used was the sum of variances. We can now summarise or plot the disparity_data object, or perform statistical tests on it (e.g. a simple lm): ## Summarising disparity through time summary(disparity_data) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 133.51 - 89.01 5 2.123 1.775 1.017 1.496 1.942 2.123 ## 2 89.01 - 44.5 29 2.456 2.384 2.295 2.350 2.404 2.427 ## 3 44.5 - 0 16 2.528 2.363 2.213 2.325 2.406 2.466 ## Plotting the results plot(disparity_data, type = "continuous") ## Testing for an difference among the time bins disp_lm <- test.dispRity(disparity_data, test = lm, comparisons = "all") summary(disp_lm) ## ## Call: ## test(formula = data ~ subsets, data = data) ## ## Residuals: ## Min 1Q Median 3Q Max ## -0.87430 -0.04100 0.01456 0.05318 0.41059 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 1.71217 0.01703 100.55 <2e-16 *** ## subsets44.5 - 0 0.64824 0.02408 26.92 <2e-16 *** ## subsets89.01 - 44.5 0.66298 0.02408 27.53 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 0.1703 on 297 degrees of freedom ## Multiple R-squared: 0.769, Adjusted R-squared: 0.7674 ## F-statistic: 494.3 on 2 and 297 DF, p-value: < 2.2e-16 Please refer to the specific tutorials for (much!) more information on the nuts and bolts of the package. You can also directly explore the specific function help files within R and navigate to related functions. 3.3.3 Disparity among groups The dispRity.per.group function is used if you are interested in looking at disparity among groups rather than through time. For example, you could ask if there is a difference in disparity between two groups? To perform such an analysis, you will need: An matrix with rows as elements and columns as dimensions (always!) A list of group members: this list should be a list of numeric vectors or names corresponding to the row names in the matrix. For example list(\"A\" = c(1,2), \"B\" = c(3,4)) will create a group A containing elements 1 and 2 from the matrix and a group B containing elements 3 and 4. Note that elements can be present in multiple groups at once. Your favourite disparity metric (here the sum of variances) Using the Beck and Lee (2014) data described above: ## Creating the two groups (crown versus stem) as a list mammal_groups <- crown.stem(BeckLee_tree, inc.nodes = FALSE) ## Measuring disparity for each group disparity_data <- dispRity.per.group(BeckLee_mat50, group = mammal_groups, metric = c(sum, variances)) We can display the disparity of both groups by simply looking at the output variable (disparity_data) and then summarising the disparity_data object and plotting it, and/or by performing a statistical test to compare disparity across the groups (here a Wilcoxon test). ## Print the disparity_data object disparity_data ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 48 dimensions: ## crown, stem. ## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: metric. ## Summarising disparity in the different groups summary(disparity_data) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 crown 30 2.526 2.446 2.380 2.429 2.467 2.498 ## 2 stem 20 2.244 2.134 2.025 2.105 2.164 2.208 ## Plotting the results plot(disparity_data) ## Testing for a difference between the groups test.dispRity(disparity_data, test = wilcox.test, details = TRUE) ## $`crown : stem` ## $`crown : stem`[[1]] ## ## Wilcoxon rank sum test with continuity correction ## ## data: dots[[1L]][[1L]] and dots[[2L]][[1L]] ## W = 10000, p-value < 2.2e-16 ## alternative hypothesis: true location shift is not equal to 0 References "],["details-of-specific-functions.html", "4 Details of specific functions 4.1 Time slicing 4.2 Customised subsets 4.3 Bootstraps and rarefactions 4.4 Disparity metrics 4.5 Summarising dispRity data (plots) 4.6 Testing disparity hypotheses 4.7 Fitting modes of evolution to disparity data 4.8 Disparity as a distribution 4.9 Disparity from other matrices 4.10 Disparity from multiple matrices (and multiple trees!) 4.11 Disparity with trees: dispRitree! 4.12 Disparity of variance-covariance matrices (covar) 4.13 Disparity and distances", " 4 Details of specific functions The following section contains information specific to some functions. If any of your questions are not covered in these sections, please refer to the function help files in R, send me an email (guillert@tcd.ie), or raise an issue on GitHub. The several tutorials below describe specific functionalities of certain functions; please always refer to the function help files for the full function documentation! Before each section, make sure you loaded the Beck and Lee (2014) data (see example data for more details). ## Loading the data data(BeckLee_mat50) data(BeckLee_mat99) data(BeckLee_tree) data(BeckLee_ages) 4.1 Time slicing The function chrono.subsets allows users to divide the matrix into different time subsets or slices given a dated phylogeny that contains all the elements (i.e. taxa) from the matrix. Each subset generated by this function will then contain all the elements present at a specific point in time or during a specific period in time. Two types of time subsets can be performed by using the method option: Discrete time subsets (or time-binning) using method = discrete Continuous time subsets (or time-slicing) using method = continuous For the time-slicing method details see T. Guillerme and Cooper (2018). For both methods, the function takes the time argument which can be a vector of numeric values for: Defining the boundaries of the time bins (when method = discrete) Defining the time slices (when method = continuous) Otherwise, the time argument can be set as a single numeric value for automatically generating a given number of equidistant time-bins/slices. Additionally, it is also possible to input a dataframe containing the first and last occurrence data (FAD/LAD) for taxa that span over a longer time than the given tips/nodes age, so taxa can appear in more than one time bin/slice. 4.1.1 Time-binning Here is an example for the time binning method (method = discrete): ## Generating three time bins containing the taxa present every 40 Ma chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree, method = "discrete", time = c(120, 80, 40, 0)) ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 120 - 80, 80 - 40, 40 - 0. Note that we can also generate equivalent results by just telling the function that we want three time-bins as follow: ## Automatically generate three equal length bins: chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree, method = "discrete", time = 3) ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 133.51 - 89.01, 89.01 - 44.5, 44.5 - 0. In this example, the taxa were split inside each time-bin according to their age. However, the taxa here are considered as single points in time. It is totally possible that some taxa could have had longer longevity and that they exist in multiple time bins. In this case, it is possible to include them in more than one bin by providing a table of first and last occurrence dates (FAD/LAD). This table should have the taxa names as row names and two columns for respectively the first and last occurrence age: ## Displaying the table of first and last occurrence dates ## for each taxa head(BeckLee_ages) ## FAD LAD ## Adapis 37.2 36.8 ## Asioryctes 83.6 72.1 ## Leptictis 33.9 33.3 ## Miacis 49.0 46.7 ## Mimotona 61.6 59.2 ## Notharctus 50.2 47.0 ## Generating time bins including taxa that might span between them chrono.subsets(data = BeckLee_mat50, tree = BeckLee_tree, method = "discrete", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## ---- dispRity object ---- ## 3 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 120 - 80, 80 - 40, 40 - 0. When using this method, the oldest boundary of the first bin (or the first slice, see below) is automatically generated as the root age plus 1% of the tree length, as long as at least three elements/taxa are present at that point in time. The algorithm adds an extra 1% tree length until reaching the required minimum of three elements. It is also possible to include nodes in each bin by using inc.nodes = TRUE and providing a matrix that contains the ordinated distance among tips and nodes. If you want to generate time subsets based on stratigraphy, the package proposes a useful functions to do it for you: get.bin.ages (check out the function’s manual in R)! 4.1.2 Time-slicing For the time-slicing method (method = continuous), the idea is fairly similar. This option, however, requires a matrix that contains the ordinated distance among taxa and nodes and an extra argument describing the assumed evolutionary model (via the model argument). This model argument is used when the time slice occurs along a branch of the tree rather than on a tip or a node, meaning that a decision must be made about what the value for the branch should be. The model can be one of the following: Punctuated models acctran where the data chosen along the branch is always the one of the descendant deltran where the data chosen along the branch is always the one of the ancestor random where the data chosen along the branch is randomly chosen between the descendant or the ancestor proximity where the data chosen along the branch is either the descendant or the ancestor depending on branch length Gradual models equal.split where the data chosen along the branch is both the descendant and the ancestor with an even probability gradual.split where the data chosen along the branch is both the descendant and the ancestor with a probability depending on branch length Note that the four first models are a proxy for punctuated evolution: the selected data is always either the one of the descendant or the ancestor. In other words, changes along the branches always occur at either ends of it. The two last models are a proxy for gradual evolution: the data from both the descendant and the ancestor is used with an associate probability. These later models perform better when bootstrapped, effectively approximating the “intermediate” state between and the ancestor and the descendants. More details about the differences between these methods can be found in T. Guillerme and Cooper (2018). ## Generating four time slices every 40 million years ## under a model of proximity evolution chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 1 phylogenetic tree ## 120, 80, 40, 0. ## Generating four time slices automatically chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = 4, FADLAD = BeckLee_ages) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 1 phylogenetic tree ## 133.51, 89.01, 44.5, 0. 4.2 Customised subsets Another way of separating elements into different categories is to use customised subsets as briefly explained above. This function simply takes the list of elements to put in each group (whether they are the actual element names or their position in the matrix). ## Creating the two groups (crown and stems) mammal_groups <- crown.stem(BeckLee_tree, inc.nodes = FALSE) ## Separating the dataset into two different groups custom.subsets(BeckLee_mat50, group = mammal_groups) ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix: ## crown, stem. Like in this example, you can use the utility function crown.stem that allows to automatically separate the crown and stems taxa given a phylogenetic tree. Also, elements can easily be assigned to different groups if necessary! ## Creating the three groups as a list weird_groups <- list("even" = seq(from = 1, to = 49, by = 2), "odd" = seq(from = 2, to = 50, by = 2), "all" = c(1:50)) The custom.subsets function can also take a phylogeny (as a phylo object) as an argument to create groups as clades: ## Creating groups as clades custom.subsets(BeckLee_mat50, group = BeckLee_tree) This automatically creates 49 (the number of nodes) groups containing between two and 50 (the number of tips) elements. 4.3 Bootstraps and rarefactions One important step in analysing ordinated matrices is to pseudo-replicate the data to see how robust the results are, and how sensitive they are to outliers in the dataset. This can be achieved using the function boot.matrix to bootstrap and/or rarefy the data. The default options will bootstrap the matrix 100 times without rarefaction using the “full” bootstrap method (see below): ## Default bootstrapping boot.matrix(data = BeckLee_mat50) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Rows were bootstrapped 100 times (method:"full"). The number of bootstrap replicates can be defined using the bootstraps option. The method can be modified by controlling which bootstrap algorithm to use through the boot.type argument. Currently two algorithms are implemented: \"full\" where the bootstrapping is entirely stochastic (n elements are replaced by any m elements drawn from the data) \"single\" where only one random element is replaced by one other random element for each pseudo-replicate \"null\" where every element is resampled across the whole matrix (not just the subsets). I.e. for each subset of n elements, this algorithm resamples n elements across ALL subsets (not just the current one). If only one subset (or none) is used, this does the same as the \"full\" algorithm. ## Bootstrapping with the single bootstrap method boot.matrix(BeckLee_mat50, boot.type = "single") ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Rows were bootstrapped 100 times (method:"single"). This function also allows users to rarefy the data using the rarefaction argument. Rarefaction allows users to limit the number of elements to be drawn at each bootstrap replication. This is useful if, for example, one is interested in looking at the effect of reducing the number of elements on the results of an analysis. This can be achieved by using the rarefaction option that draws only n-x at each bootstrap replicate (where x is the number of elements not sampled). The default argument is FALSE but it can be set to TRUE to fully rarefy the data (i.e. remove x elements for the number of pseudo-replicates, where x varies from the maximum number of elements present in each subset to a minimum of three elements). It can also be set to one or more numeric values to only rarefy to the corresponding number of elements. ## Bootstrapping with the full rarefaction boot.matrix(BeckLee_mat50, bootstraps = 20, rarefaction = TRUE) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Rows were bootstrapped 20 times (method:"full") and fully rarefied. ## Or with a set number of rarefaction levels boot.matrix(BeckLee_mat50, bootstraps = 20, rarefaction = c(6:8, 3)) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Rows were bootstrapped 20 times (method:"full") and rarefied to 6, 7, 8, 3 elements. Note that using the rarefaction argument also bootstraps the data. In these examples, the function bootstraps the data (without rarefaction) AND also bootstraps the data with the different rarefaction levels. ## Creating subsets of crown and stem mammals crown_stem <- custom.subsets(BeckLee_mat50, group = crown.stem(BeckLee_tree, inc.nodes = FALSE)) ## Bootstrapping and rarefying these groups boot.matrix(crown_stem, bootstraps = 200, rarefaction = TRUE) ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 48 dimensions: ## crown, stem. ## Rows were bootstrapped 200 times (method:"full") and fully rarefied. ## Creating time slice subsets time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## Bootstrapping the time slice subsets boot.matrix(time_slices, bootstraps = 100) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 120, 80, 40, 0. ## Rows were bootstrapped 100 times (method:"full"). 4.3.1 Bootstrapping with probabilities It is also possible to specify the sampling probability in the bootstrap for each elements. This can be useful for weighting analysis for example (i.e. giving more importance to specific elements). These probabilities can be passed to the prob argument individually with a vector with the elements names or with a matrix with the rownames as elements names. The elements with no specified probability will be assigned a probability of 1 (or 1/maximum weight if the argument is weights rather than probabilities). ## Attributing a weight of 0 to Cimolestes and 10 to Maelestes boot.matrix(BeckLee_mat50, prob = c("Cimolestes" = 0, "Maelestes" = 10)) ## ---- dispRity object ---- ## 50 elements in one matrix with 48 dimensions. ## Rows were bootstrapped 100 times (method:"full"). 4.3.2 Bootstrapping dimensions In some cases, you might also be interested in bootstrapping dimensions rather than observations. I.e. bootstrapping the columns of a matrix rather than the rows. It’s pretty easy! By default, boot.matrix uses the option boot.by = \"rows\" which you can toggle to boot.by = \"columns\" ## Bootstrapping the observations (default) set.seed(1) boot_obs <- boot.matrix(data = crown_stem, boot.by = "rows") ## Bootstrapping the columns rather than the rows set.seed(1) boot_dim <- boot.matrix(data = crown_stem, boot.by = "columns") In these two examples, the first one boot_obs bootstraps the rows as showed before (default behaviour). But the second one, boot_dim bootstraps the dimensions. That means that for each bootstrap sample, the value calculated is actually obtained by reshuffling the dimensions (columns) rather than the observations (rows). ## Measuring disparity and summarising summary(dispRity(boot_obs, metric = sum)) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 crown 30 -1.1 -2.04 -19.4 -7.56 3.621 14.64 ## 2 stem 20 1.1 1.52 -10.8 -1.99 6.712 13.97 summary(dispRity(boot_dim, metric = sum)) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 crown 30 -1.1 -2.04 -18.5 -8.84 5.440 19.80 ## 2 stem 20 1.1 1.31 -16.7 -2.99 6.338 14.99 Note here how the observed sum is the same (no bootstrapping) but the bootstrapping distributions are quiet different even though the same seed was used. 4.4 Disparity metrics There are many ways of measuring disparity! In brief, disparity is a summary metric that will represent an aspect of an ordinated space (e.g. a MDS, PCA, PCO, PCoA). For example, one can look at ellipsoid hyper-volume of the ordinated space (Donohue et al. 2013), the sum and the product of the ranges and variances (Wills et al. 1994) or the median position of the elements relative to their centroid (Wills et al. 1994). Of course, there are many more examples of metrics one can use for describing some aspect of the ordinated space, with some performing better than other ones at particular descriptive tasks, and some being more generalist. Check out this paper on selecting the best metric for your specific question in Ecology and Evolution. You can also use the moms shiny app to test which metric captures which aspect of traitspace occupancy regarding your specific space and your specific question. Regardless, and because of this great diversity of metrics, the package dispRity does not have one way to measure disparity but rather proposes to facilitate users in defining their own disparity metric that will best suit their particular analysis. In fact, the core function of the package, dispRity, allows the user to define any metric with the metric argument. However the metric argument has to follow certain rules: It must be composed from one to three function objects; The function(s) must take as a first argument a matrix or a vector; The function(s) must be of one of the three dimension-levels described below; At least one of the functions must be of dimension-level 1 or 2 (see below). 4.4.1 The function dimension-levels The metric function dimension-levels determine the “dimensionality of decomposition” of the input matrix. In other words, each dimension-level designates the dimensions of the output, i.e. either three (a matrix); two (a vector); or one (a single numeric value) dimension. Illustration of the different dimension-levels of functions with an input matrix 4.4.1.1 Dimension-level 1 functions A dimension-level 1 function will decompose a matrix or a vector into a single value: ## Creating a dummy matrix dummy_matrix <- matrix(rnorm(12), 4, 3) ## Example of dimension-level 1 functions mean(dummy_matrix) ## [1] -0.183358 median(dummy_matrix) ## [1] -0.3909538 Any summary metric such as mean or median are good examples of dimension-level 1 functions as they reduce the matrix to a single dimension (i.e. one value). 4.4.1.2 Dimension-level 2 functions A dimension-level 2 function will decompose a matrix into a vector. ## Defining the function as the product of rows prod.rows <- function(matrix) apply(matrix, 1, prod) ## A dimension-level 2 metric prod.rows(dummy_matrix) ## [1] 0.63727584 -0.09516528 -1.24477435 -0.10958022 Several dimension-level 2 functions are implemented in dispRity (see ?dispRity.metric) such as the variances or ranges functions that calculate the variance or the range of each dimension of the ordinated matrix respectively. 4.4.1.3 Dimension-level 3 functions Finally a dimension-level 3 function will transform the matrix into another matrix. Note that the dimension of the output matrix doesn’t need to match the the input matrix: ## A dimension-level 3 metric var(dummy_matrix) ## [,1] [,2] [,3] ## [1,] 0.6356714 -0.2017617 0.2095042 ## [2,] -0.2017617 1.3656124 1.0850900 ## [3,] 0.2095042 1.0850900 1.0879400 ## A dimension-level 3 metric with a forced matrix output as.matrix(dist(dummy_matrix)) ## 1 2 3 4 ## 1 0.000000 1.390687 2.156388 2.984951 ## 2 1.390687 0.000000 2.557670 1.602143 ## 3 2.156388 2.557670 0.000000 3.531033 ## 4 2.984951 1.602143 3.531033 0.000000 4.4.2 Between groups metrics One specific category of metrics in the dispRity package is the between groups metrics. As the name suggest, these metrics can be used to calculate the disparity between groups rather than within the groups. These metrics follow the same classifications as the “normal” (within group) metrics with dimension-level 1, 2 and 3 between groups metrics. However, at the difference of the “normal” metrics, their input arguments must be matrix and matrix2 (and of course any other additional arguments). For example, this metric measures the difference in mean between two matrices: ## A simple example mean.difference <- function(matrix, matrix2) { mean(matrix) - mean(matrix2) } You can find the list of implemented between groups metric here or design them yourself for your specific needs (potentially using make.metric for help). The function works by simply using the two available matrices, with no restriction in terms of dimensions (although you’d probably want both matrices to have the same number of dimensions) ## A second matrix dummy_matrix2 <- matrix(runif(12), 4, 3) ## The difference between groups mean.difference(dummy_matrix, dummy_matrix2) ## [1] -0.5620336 Beyond this super simple example, it might probably be interesting to use this metric on dispRity objects, especially the ones from custom.subsets and chrono.subsets. In fact, the dispRity function allows to apply the between groups metric directly to the dispRity objects using the between.groups = TRUE option. For example: ## Combining both matrices big_matrix <- rbind(dummy_matrix, dummy_matrix2) rownames(big_matrix) <- 1:8 ## Making a dispRity object with both groups grouped_matrix <- custom.subsets(big_matrix, group = c(list(1:4), list(1:4))) ## Calculating the mean difference between groups (mean_differences <- dispRity(grouped_matrix, metric = mean.difference, between.groups = TRUE)) ## ---- dispRity object ---- ## 2 customised subsets for 8 elements in one matrix with 3 dimensions: ## 1, 2. ## Disparity was calculated as: mean.difference between groups. ## Summarising the object summary(mean_differences) ## subsets n_1 n_2 obs ## 1 1:2 4 4 0 ## Note how the summary table now indicates ## the number of elements for each group For dispRity objects generated by custom.subsets, the dispRity function will by default apply the metric on the groups in a pairwise fashion. For example, if the object contains multiple groups, all groups will be compared to each other: ## A dispRity object with multiple groups grouped_matrix <- custom.subsets(big_matrix, group = c("A" = list(1:4), "B" = list(1:4), "C" = list(2:6), "D" = list(1:8))) ## Measuring disparity between all groups summary(dispRity(grouped_matrix, metric = mean.difference, between.groups = TRUE)) ## subsets n_1 n_2 obs ## 1 A:B 4 4 0.000 ## 2 A:C 4 5 -0.269 ## 3 A:D 4 8 -0.281 ## 4 B:C 4 5 -0.269 ## 5 B:D 4 8 -0.281 ## 6 C:D 5 8 -0.012 For dispRity objects generated by chrono.subsets (not shown here), the dispRity function will by default apply the metric on the groups in a serial way (group 1 vs. group 2, group 2 vs. group 3, group 3 vs. group 4, etc…). However, in both cases (for objects from custom.subsets or chrono.subsets) it is possible to manually specific the list of pairs of comparisons through their ID numbers: ## Measuring disparity between specific groups summary(dispRity(grouped_matrix, metric = mean.difference, between.groups = list(c(1,3), c(3,1), c(4,1)))) ## subsets n_1 n_2 obs ## 1 A:C 4 5 -0.269 ## 2 C:A 5 4 0.269 ## 3 D:A 8 4 0.281 Note that in any case, the order of the comparison can matter. In our example, it is obvious that mean(matrix) - mean(matrix2) is not the same as mean(matrix2) - mean(matrix). 4.4.3 make.metric Of course, functions can be more complex and involve multiple operations such as the centroids function (see ?dispRity.metric) that calculates the Euclidean distance between each element and the centroid of the ordinated space. The make.metric function implemented in dispRity is designed to help test and find the dimension-level of the functions. This function tests: If your function can deal with a matrix or a vector as an input; Your function’s dimension-level according to its output (dimension-level 1, 2 or 3, see above); Whether the function can be implemented in the dispRity function (the function is fed into a lapply loop). For example, let’s see if the functions described above are the right dimension-levels: ## Which dimension-level is the mean function? ## And can it be used in dispRity? make.metric(mean) ## mean outputs a single value. ## mean is detected as being a dimension-level 1 function. ## Which dimension-level is the prod.rows function? ## And can it be used in dispRity? make.metric(prod.rows) ## prod.rows outputs a matrix object. ## prod.rows is detected as being a dimension-level 2 function. ## Which dimension-level is the var function? ## And can it be used in dispRity? make.metric(var) ## var outputs a matrix object. ## var is detected as being a dimension-level 3 function. ## Additional dimension-level 2 and/or 1 function(s) will be needed. A non verbose version of the function is also available. This can be done using the option silent = TRUE and will simply output the dimension-level of the metric. ## Testing whether mean is dimension-level 1 if(make.metric(mean, silent = TRUE)$type != "level1") { message("The metric is not dimension-level 1.") } ## Testing whether var is dimension-level 1 if(make.metric(var, silent = TRUE)$type != "level1") { message("The metric is not dimension-level 1.") } ## The metric is not dimension-level 1. 4.4.4 Metrics in the dispRity function Using this metric structure, we can easily use any disparity metric in the dispRity function as follows: ## Measuring disparity as the standard deviation ## of all the values of the ## ordinated matrix (dimension-level 1 function). summary(dispRity(BeckLee_mat50, metric = sd)) ## subsets n obs ## 1 1 50 0.227 ## Measuring disparity as the standard deviation ## of the variance of each axis of ## the ordinated matrix (dimension-level 1 and 2 functions). summary(dispRity(BeckLee_mat50, metric = c(sd, variances))) ## subsets n obs ## 1 1 50 0.032 ## Measuring disparity as the standard deviation ## of the variance of each axis of ## the variance covariance matrix (dimension-level 1, 2 and 3 functions). summary(dispRity(BeckLee_mat50, metric = c(sd, variances, var)), round = 10) ## subsets n obs ## 1 1 50 0 Note that the order of each function in the metric argument does not matter, the dispRity function will automatically detect the function dimension-levels (using make.metric) and apply them to the data in decreasing order (dimension-level 3 > 2 > 1). ## Disparity as the standard deviation of the variance of each axis of the ## variance covariance matrix: disparity1 <- summary(dispRity(BeckLee_mat50, metric = c(sd, variances, var)), round = 10) ## Same as above but using a different function order for the metric argument disparity2 <- summary(dispRity(BeckLee_mat50, metric = c(variances, sd, var)), round = 10) ## Both ways output the same disparity values: disparity1 == disparity2 ## subsets n obs ## [1,] TRUE TRUE TRUE In these examples, we considered disparity to be a single value. For example, in the previous example, we defined disparity as the standard deviation of the variances of each column of the variance/covariance matrix (metric = c(variances, sd, var)). It is, however, possible to calculate disparity as a distribution. 4.4.5 Metrics implemented in dispRity Several disparity metrics are implemented in the dispRity package. The detailed list can be found in ?dispRity.metric along with some description of each metric. Level Name Description Source 2 ancestral.dist The distance between an element and its ancestor dispRity 2 angles The angle of main variation of each dimensions dispRity 2 centroids1 The distance between each element and the centroid of the ordinated space dispRity 1 convhull.surface The surface of the convex hull formed by all the elements geometry::convhulln$area 1 convhull.volume The volume of the convex hull formed by all the elements geometry::convhulln$vol 2 count.neighbours The number of neigbhours to each element in a specified radius dispRity 2 deviations The minimal distance between each element and a hyperplane dispRity 1 diagonal The longest distance in the ordinated space (like the diagonal in two dimensions) dispRity 1 disalignment The rejection of the centroid of a matrix from the major axis of another (typically an \"as.covar\" metric) dispRity 2 displacements The ratio between the distance from a reference and the distance from the centroid dispRity 1 edge.length.tree The edge lengths of the elements on a tree ape 1 ellipsoid.volume1 The volume of the ellipsoid of the space Donohue et al. (2013) 1 func.div The functional divergence (the ratio of deviation from the centroid) dispRity (similar to FD::dbFD$FDiv but without abundance) 1 func.eve The functional evenness (the minimal spanning tree distances evenness) dispRity (similar to FD::dbFD$FEve but without abundance) 1 group.dist The distance between two groups dispRity 1 mode.val The modal value dispRity 1 n.ball.volume The hyper-spherical (n-ball) volume dispRity 2 neighbours The distance to specific neighbours (e.g. the nearest neighbours - by default) dispRity 2 pairwise.dist The pairwise distances between elements vegan::vegist 2 point.dist The distance between one group and the point of another group dispRity 2 projections The distance on (projection) or from (rejection) an arbitrary vector dispRity 1 projections.between projections metric applied between groups dispRity 2 projections.tree The projections metric but where the vector can be based on a tree dispRity 2 quantiles The nth quantile range per axis dispRity 2 radius The radius of each dimensions dispRity 2 ranges The range of each dimension dispRity 1 roundness The integral of the ranked scaled eigenvalues of a variance-covariance matrix dispRity 2 span.tree.length The minimal spanning tree length vegan::spantree 2 variances The variance of each dimension dispRity 1: Note that by default, the centroid is the centroid of the elements. It can, however, be fixed to a different value by using the centroid argument centroids(space, centroid = rep(0, ncol(space))), for example the origin of the ordinated space. 2: This function uses an estimation of the eigenvalue that only works for MDS or PCoA ordinations (not PCA). You can find more informations on the vast variety of metrics that you can use in your analysis in this paper. 4.4.6 Equations and implementations Some of the functions described below are implemented in the dispRity package and do not require any other packages to calculate (see implementation here). \\[\\begin{equation} ancestral.dist = \\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Ancestor_{n})^2}} \\end{equation}\\] \\[\\begin{equation} centroids = \\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Centroid_{d})^2}} \\end{equation}\\] \\[\\begin{equation} diagonal = \\sqrt{\\sum_{i=1}^{d}|max(d_i) - min(k_i)|} \\end{equation}\\] \\[\\begin{equation} deviations = \\frac{|Ax + By + ... + Nm + Intercept|}{\\sqrt{A^2 + B^2 + ... + N^2}} \\end{equation}\\] \\[\\begin{equation} displacements = \\frac{\\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Reference_{d})^2}}}{\\sqrt{\\sum_{i=1}^{n}{({d}_{n}-Centroid_{k})^2}}} \\end{equation}\\] \\[\\begin{equation} ellipsoid.volume = \\frac{\\pi^{d/2}}{\\Gamma(\\frac{d}{2}+1)}\\displaystyle\\prod_{i=1}^{d} (\\lambda_{i}^{0.5}) \\end{equation}\\] \\[\\begin{equation} n.ball.volume = \\frac{\\pi^{d/2}}{\\Gamma(\\frac{d}{2}+1)}\\displaystyle\\prod_{i=1}^{d} R \\end{equation}\\] \\[\\begin{equation} projection_{on} = \\| \\overrightarrow{i} \\cdot \\overrightarrow{b} \\| \\end{equation}\\] \\[\\begin{equation} projection_{from} = \\| \\overrightarrow{i} - \\overrightarrow{i} \\cdot \\overrightarrow{b} \\| \\end{equation}\\] \\[\\begin{equation} radius = |\\frac{\\sum_{i=1}^{n}d_i}{n} - f(\\mathbf{v}d)| \\end{equation}\\] \\[\\begin{equation} ranges = |max(d_i) - min(d_i)| \\end{equation}\\] \\[\\begin{equation} roundness = \\int_{i = 1}^{n}{\\frac{\\lambda_{i}}{\\text{max}(\\lambda)}} \\end{equation}\\] \\[\\begin{equation} variances = \\sigma^{2}{d_i} \\end{equation}\\] \\[\\begin{equation} span.tree.length = \\mathrm{branch\\ length} \\end{equation}\\] Where d is the number of dimensions, n the number of elements, \\(\\Gamma\\) is the Gamma distribution, \\(\\lambda_i\\) is the eigenvalue of each dimensions, \\(\\sigma^{2}\\) is their variance and \\(Centroid_{k}\\) is their mean, \\(Ancestor_{n}\\) is the coordinates of the ancestor of element \\(n\\), \\(f(\\mathbf{v}k)\\) is function to select one value from the vector \\(\\mathbf{v}\\) of the dimension \\(k\\) (e.g. it’s maximum, minimum, mean, etc.), R is the radius of the sphere or the product of the radii of each dimensions (\\(\\displaystyle\\prod_{i=1}^{k}R_{i}\\) - for a hyper-ellipsoid), \\(Reference_{k}\\) is an arbitrary point’s coordinates (usually 0), \\(\\overrightarrow{b}\\) is the vector defined by ((point1, point2)), and \\(\\overrightarrow{i}\\) is the vector defined by ((point1, i) where i is any row of the matrix). 4.4.7 Using the different disparity metrics Here is a brief demonstration of the main metrics implemented in dispRity. First, we will create a dummy/simulated ordinated space using the space.maker utility function (more about that here: ## Creating a 10*5 normal space set.seed(1) dummy_space <- space.maker(10, 5, rnorm) rownames(dummy_space) <- 1:10 We will use this simulated space to demonstrate the different metrics. 4.4.7.1 Volumes and surface metrics The functions ellipsoid.volume, convhull.surface, convhull.volume and n.ball.volume all measure the surface or the volume of the ordinated space occupied: Because there is only one subset (i.e. one matrix) in the dispRity object, the operations below are the equivalent of metric(dummy_space) (with rounding). ## Calculating the ellipsoid volume summary(dispRity(dummy_space, metric = ellipsoid.volume)) ## subsets n obs ## 1 1 10 1.061 WARNING: in such dummy space, this gives the estimation of the ellipsoid volume, not the real ellipsoid volume! See the cautionary note in ?ellipsoid.volume. ## Calculating the convex hull surface summary(dispRity(dummy_space, metric = convhull.surface)) ## subsets n obs ## 1 1 10 11.91 ## Calculating the convex hull volume summary(dispRity(dummy_space, metric = convhull.volume)) ## subsets n obs ## 1 1 10 1.031 ## Calculating the convex hull volume summary(dispRity(dummy_space, metric = n.ball.volume)) ## subsets n obs ## 1 1 10 4.43 The convex hull based functions are a call to the geometry::convhulln function with the \"FA\" option (computes total area and volume). Also note that they are really sensitive to the size of the dataset. Cautionary note: measuring volumes in a high number of dimensions can be strongly affected by the curse of dimensionality that often results in near 0 disparity values. I strongly recommend reading this really intuitive explanation from Toph Tucker. 4.4.7.2 Ranges, variances, quantiles, radius, pairwise distance, neighbours (and counting them), modal value and diagonal The functions ranges, variances radius, pairwise.dist, mode.val and diagonal all measure properties of the ordinated space based on its dimensional properties (they are also less affected by the “curse of dimensionality”): ranges, variances quantiles and radius work on the same principle and measure the range/variance/radius of each dimension: ## Calculating the ranges of each dimension in the ordinated space ranges(dummy_space) ## [1] 2.430909 3.726481 2.908329 2.735739 1.588603 ## Calculating disparity as the distribution of these ranges summary(dispRity(dummy_space, metric = ranges)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 2.736 1.673 2.431 2.908 3.645 ## Calculating disparity as the sum and the product of these ranges summary(dispRity(dummy_space, metric = c(sum, ranges))) ## subsets n obs ## 1 1 10 13.39 summary(dispRity(dummy_space, metric = c(prod, ranges))) ## subsets n obs ## 1 1 10 114.5 ## Calculating the variances of each dimension in the ## ordinated space variances(dummy_space) ## [1] 0.6093144 1.1438620 0.9131859 0.6537768 0.3549372 ## Calculating disparity as the distribution of these variances summary(dispRity(dummy_space, metric = variances)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.654 0.38 0.609 0.913 1.121 ## Calculating disparity as the sum and ## the product of these variances summary(dispRity(dummy_space, metric = c(sum, variances))) ## subsets n obs ## 1 1 10 3.675 summary(dispRity(dummy_space, metric = c(prod, variances))) ## subsets n obs ## 1 1 10 0.148 ## Calculating the quantiles of each dimension ## in the ordinated space quantiles(dummy_space) ## [1] 2.234683 3.280911 2.760855 2.461077 1.559057 ## Calculating disparity as the distribution of these variances summary(dispRity(dummy_space, metric = quantiles)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 2.461 1.627 2.235 2.761 3.229 ## By default, the quantile calculated is the 95% ## (i.e. 95% of the data on each axis) ## this can be changed using the option quantile: summary(dispRity(dummy_space, metric = quantiles, quantile = 50)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.967 0.899 0.951 0.991 1.089 ## Calculating the radius of each dimension in the ordinated space radius(dummy_space) ## [1] 1.4630780 2.4635449 1.8556785 1.4977898 0.8416318 ## By default the radius is the maximum distance from the centre of ## the dimension. It can however be changed to any function: radius(dummy_space, type = min) ## [1] 0.05144054 0.14099827 0.02212226 0.17453525 0.23044528 radius(dummy_space, type = mean) ## [1] 0.6233501 0.7784888 0.7118713 0.6253263 0.5194332 ## Calculating disparity as the mean average radius summary(dispRity(dummy_space, metric = c(mean, radius), type = mean)) ## subsets n obs ## 1 1 10 0.652 The pairwise distances and the neighbours distances uses the function vegan::vegdist and can take the normal vegdist options: ## The average pairwise euclidean distance summary(dispRity(dummy_space, metric = c(mean, pairwise.dist))) ## subsets n obs ## 1 1 10 2.539 ## The distribution of the Manhattan distances summary(dispRity(dummy_space, metric = pairwise.dist, method = "manhattan")) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 4.427 2.566 3.335 5.672 9.63 ## The average nearest neighbour distances summary(dispRity(dummy_space, metric = neighbours)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.517 1.266 1.432 1.646 2.787 ## The average furthest neighbour manhattan distances summary(dispRity(dummy_space, metric = neighbours, which = max, method = "manhattan")) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 7.895 6.15 6.852 9.402 10.99 ## The overall number of neighbours per point summary(dispRity(dummy_space, metric = count.neighbours, relative = FALSE)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 6.5 0.675 4.25 7 7.775 ## The relative number of neigbhours ## two standard deviations of each element summary(dispRity(dummy_space, metric = count.neighbours, radius = function(x)(sd(x)*2), relative = TRUE)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.55 0.068 0.3 0.7 0.7 Note that this function is a direct call to vegan::vegdist(matrix, method = method, diag = FALSE, upper = FALSE, ...). The diagonal function measures the multidimensional diagonal of the whole space (i.e. in our case the longest Euclidean distance in our five dimensional space). The mode.val function measures the modal value of the matrix: ## Calculating the ordinated space's diagonal summary(dispRity(dummy_space, metric = diagonal)) ## subsets n obs ## 1 1 10 3.659 ## Calculating the modal value of the matrix summary(dispRity(dummy_space, metric = mode.val)) ## subsets n obs ## 1 1 10 -2.21 This metric is only a Euclidean diagonal (mathematically valid) if the dimensions within the space are all orthogonal! 4.4.7.3 Centroids, displacements and ancestral distances metrics The centroids metric allows users to measure the position of the different elements compared to a fixed point in the ordinated space. By default, this function measures the distance between each element and their centroid (centre point): ## The distribution of the distances between each element and their centroid summary(dispRity(dummy_space, metric = centroids)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.435 0.788 1.267 1.993 3.167 ## Disparity as the median value of these distances summary(dispRity(dummy_space, metric = c(median, centroids))) ## subsets n obs ## 1 1 10 1.435 It is however possible to fix the coordinates of the centroid to a specific point in the ordinated space, as long as it has the correct number of dimensions: ## The distance between each element and the origin ## of the ordinated space summary(dispRity(dummy_space, metric = centroids, centroid = 0)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.487 0.785 1.2 2.044 3.176 ## Disparity as the distance between each element ## and a specific point in space summary(dispRity(dummy_space, metric = centroids, centroid = c(0,1,2,3,4))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 5.489 4.293 5.032 6.155 6.957 If you have subsets in your dispRity object, you can also use the matrix.dispRity (see utilities) and colMeans to get the centre of a specific subgroup. For example ## Create a custom subsets object dummy_groups <- custom.subsets(dummy_space, group = list("group1" = 1:5, "group2" = 6:10)) summary(dispRity(dummy_groups, metric = centroids, centroid = colMeans(get.matrix(dummy_groups, "group1")))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 group1 5 2.011 0.902 1.389 2.284 3.320 ## 2 group2 5 1.362 0.760 1.296 1.505 1.985 The displacements distance is the ratio between the centroids distance and the centroids distance with centroid = 0. Note that it is possible to measure a ratio from another point than 0 using the reference argument. It gives indication of the relative displacement of elements in the multidimensional space: a score >1 signifies a displacement away from the reference. A score of >1 signifies a displacement towards the reference. ## The relative displacement of the group in space to the centre summary(dispRity(dummy_space, metric = displacements)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.014 0.841 0.925 1.1 1.205 ## The relative displacement of the group to an arbitrary point summary(dispRity(dummy_space, metric = displacements, reference = c(0,1,2,3,4))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 3.368 2.066 3.19 4.358 7.166 The ancestral.dist metric works on a similar principle as the centroids function but changes the centroid to be the coordinates of each element’s ancestor (if to.root = FALSE; default) or to the root of the tree (to.root = TRUE). Therefore this function needs a matrix that contains tips and nodes and a tree as additional argument. ## A generating a random tree with node labels my_tree <- makeNodeLabel(rtree(5), prefix = "n") ## Adding the tip and node names to the matrix dummy_space2 <- dummy_space[-1,] rownames(dummy_space2) <- c(my_tree$tip.label, my_tree$node.label) ## Calculating the distances from the ancestral nodes ancestral_dist <- dispRity(dummy_space2, metric = ancestral.dist, tree = my_tree) ## The ancestral distances distributions summary(ancestral_dist) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 9 2.193 0.343 1.729 2.595 3.585 ## Calculating disparity as the sum of the distances from all the ancestral nodes summary(dispRity(ancestral_dist, metric = sum)) ## subsets n obs ## 1 1 9 18.93 4.4.7.4 Minimal spanning tree length The span.tree.length uses the vegan::spantree function to heuristically calculate the minimum spanning tree (the shortest multidimensional tree connecting each elements) and calculates its length as the sum of every branch lengths. ## The length of the minimal spanning tree summary(dispRity(dummy_space, metric = c(sum, span.tree.length))) ## subsets n obs ## 1 1 10 15.4 Note that because the solution is heuristic, this metric can take a long time to compute for big matrices. 4.4.7.5 Functional divergence and evenness The func.div and func.eve functions are based on the FD::dpFD package. They are the equivalent to FD::dpFD(matrix)$FDiv and FD::dpFD(matrix)$FEve but a bit faster (since they don’t deal with abundance data). They are pretty straightforward to use: ## The ratio of deviation from the centroid summary(dispRity(dummy_space, metric = func.div)) ## subsets n obs ## 1 1 10 0.747 ## The minimal spanning tree distances evenness summary(dispRity(dummy_space, metric = func.eve)) ## subsets n obs ## 1 1 10 0.898 ## The minimal spanning tree manhanttan distances evenness summary(dispRity(dummy_space, metric = func.eve, method = "manhattan")) ## subsets n obs ## 1 1 10 0.913 4.4.7.6 Orientation: angles and deviations The angles performs a least square regression (via the lm function) and returns slope of the main axis of variation for each dimension. This slope can be converted into different units, \"slope\", \"degree\" (the default) and \"radian\". This can be changed through the unit argument. By default, the angle is measured from the slope 0 (the horizontal line in a 2D plot) but this can be changed through the base argument (using the defined unit): ## The distribution of each angles in degrees for each ## main axis in the matrix summary(dispRity(dummy_space, metric = angles)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 21.26 -39.8 3.723 39.47 56 ## The distribution of slopes deviating from the 1:1 slope: summary(dispRity(dummy_space, metric = angles, unit = "slope", base = 1)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 1.389 0.118 1.065 1.823 2.514 The deviations function is based on a similar algorithm as above but measures the deviation from the main axis (or hyperplane) of variation. In other words, it finds the least square line (for a 2D dataset), plane (for a 3D dataset) or hyperplane (for a >3D dataset) and measures the shortest distances between every points and the line/plane/hyperplane. By default, the hyperplane is fitted using the least square algorithm from stats::glm: ## The distribution of the deviation of each point ## from the least square hyperplane summary(dispRity(dummy_space, metric = deviations)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.274 0.02 0.236 0.453 0.776 It is also possible to specify the hyperplane equation through the hyperplane equation. The equation must contain the intercept first and then all the slopes and is interpreted as \\(intercept + Ax + By + ... + Nd = 0\\). For example, a 2 line defined as beta + intercept (e.g. \\(y = 2x + 1\\)) should be defined as hyperplane = c(1, 2, 1) (\\(2x - y + 1 = 0\\)). ## The distribution of the deviation of each point ## from a slope (with only the two first dimensions) summary(dispRity(dummy_space[, c(1:2)], metric = deviations, hyperplane = c(1, 2, -1))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.516 0.038 0.246 0.763 2.42 Since both the functions angles and deviations effectively run a lm or glm to estimate slopes or hyperplanes, it is possible to use the option significant = TRUE to only consider slopes or intercepts that have a slope significantly different than zero using an aov with a significant threshold of \\(p = 0.05\\). Note that depending on your dataset, using and aov could be completely inappropriate! In doubt, it’s probably better to enter your base (for angles) or your hyperplane (for deviations) manually so you’re sure you know what the function is measuring. 4.4.7.7 Projections and phylo projections: elaboration and exploration The projections metric calculates the geometric projection and corresponding rejection of all the rows in a matrix on an arbitrary vector (respectively the distance on and the distance from that vector). The function is based on Aguilera and Pérez-Aguila (2004)’s n-dimensional rotation algorithm to use linear algebra in mutidimensional spaces. The projection or rejection can be seen as respectively the elaboration and exploration scores on a trajectory (sensu Endler et al. (2005)). By default, the vector (e.g. a trajectory, an axis), on which the data is projected is the one going from the centre of the space (coordinates 0,0, …) and the centroid of the matrix. However, we advice you do define this axis to something more meaningful using the point1 and point2 options, to create the vector (the vector’s norm will be dist(point1, point2) and its direction will be from point1 towards point2). ## The elaboration on the axis defined by the first and ## second row in the dummy_space summary(dispRity(dummy_space, metric = projections, point1 = dummy_space[1,], point2 = dummy_space[2,])) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.998 0.118 0.651 1.238 1.885 ## The exploration on the same axis summary(dispRity(dummy_space, metric = projections, point1 = dummy_space[1,], point2 = dummy_space[2,], measure = "distance")) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 0.719 0 0.568 0.912 1.65 By default, the vector (point1, point2) is used as unit vector of the projections (i.e. the Euclidean distance between (point1, point2) is set to 1) meaning that a projection value (\"distance\" or \"position\") of X means X times the distance between point1 and point2. If you want use the unit vector of the input matrix or are using a space where Euclidean distances are non-sensical, you can remove this option using scale = FALSE: ## The elaboration on the same axis using the dummy_space's ## unit vector summary(dispRity(dummy_space, metric = projections, point1 = dummy_space[1,], point2 = dummy_space[2,], scale = FALSE)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 4.068 0.481 2.655 5.05 7.685 The projections.tree is the same as the projections metric but allows to determine the vector ((point1, point2)) using a tree rather than manually entering these points. The function intakes the exact same options as the projections function described above at the exception of point1 and point2. Instead it takes a the argument type that designates the type of vector to draw from the data based on a phylogenetic tree phy. The argument type can be a pair of any of the following inputs: \"root\": to automatically use the coordinates of the root of the tree (the first element in phy$node.label); \"ancestor\": to automatically use the coordinates of the elements’ (i.e. any row in the matrix) most recent ancestor; \"tips\": to automatically use the coordinates from the centroid of all tips; \"nodes\": to automatically use the coordinates from the centroid of all nodes; \"livings\": to automatically use the coordinates from the centroid of all “living” tips (i.e. the tips that are the furthest away from the root); \"fossils\": to automatically use the coordinates from the centroid of all “fossil” tips and nodes (i.e. not the “living” ones); any numeric values that can be interpreted as point1 and point2 in projections (e.g. 0, c(0, 1.2, 3/4), etc.); or a user defined function that with the inputs matrix and phy and row (the element’s ID, i.e. the row number in matrix). For example, if you want to measure the projection of each element in the matrix (tips and nodes) on the axis from the root of the tree to each element’s most recent ancestor, you can define the vector as type = c(\"root\", \"ancestor\"). ## Adding a extra row to dummy matrix (to match dummy_tree) tree_space <- rbind(dummy_space, root = rnorm(5)) ## Creating a random dummy tree (with labels matching the ones from tree_space) dummy_tree <- rtree(6) dummy_tree$tip.label <- rownames(tree_space)[1:6] dummy_tree$node.label <- rownames(tree_space)[rev(7:11)] ## Measuring the disparity as the projection of each element ## on its root-ancestor vector summary(dispRity(tree_space, metric = projections.tree, tree = dummy_tree, type = c("root", "ancestor"))) ## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to ## max; returning -Inf ## Warning in max(nchar(round(column)), na.rm = TRUE): no non-missing arguments to ## max; returning -Inf ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 11 NA -0.7 -0.196 0.908 1.774 Of course you can also use any other options from the projections function: ## A user defined function that's returns the centroid of ## the first three nodes fun.root <- function(matrix, tree, row = NULL) { return(colMeans(matrix[tree$node.label[1:3], ])) } ## Measuring the unscaled rejection from the vector from the ## centroid of the three first nodes ## to the coordinates of the first tip summary(dispRity(tree_space, metric = projections.tree, tree = dummy_tree, measure = "distance", type = list(fun.root, tree_space[1, ]))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 11 0.763 0.07 0.459 0.873 1.371 4.4.7.8 Roundness The roundness coefficient (or metric) ranges between 0 and 1 and expresses the distribution of and ellipse’ major axis ranging from 1, a totally round ellipse (i.e. a circle) to 0 a totally flat ellipse (i.e. a line). A value of \\(0.5\\) represents a regular ellipse where each major axis is half the size of the previous major axis. A value \\(> 0.5\\) describes a pancake where the major axis distribution is convex (values close to 1 can be pictured in 3D as a cr`{e}pes with the first two axis being rather big - a circle - and the third axis being particularly thin; values closer to \\(0.5\\) can be pictured as flying saucers). Conversely, a value \\(< 0.5\\) describes a cigar where the major axis distribution is concave (values close to 0 can be pictured in 3D as a spaghetti with the first axis rather big and the two next ones being small; values closer to \\(0.5\\) can be pictured in 3D as a fat cigar). This is what it looks for example for three simulated variance-covariance matrices in 3D: 4.4.7.9 Between group metrics You can find detailed explanation on how between group metrics work here. 4.4.7.9.1 group.dist The group.dist metric allows to measure the distance between two groups in the multidimensional space. This function needs to intake several groups and use the option between.groups = TRUE in the dispRity function. It calculates the vector normal distance (euclidean) between two groups and returns 0 if that distance is negative. Note that it is possible to set up which quantiles to consider for calculating the distances between groups. For example, one might be interested in only considering the 95% CI for each group. This can be done through the option probs = c(0.025, 0.975) that is passed to the quantile function. It is also possible to use this function to measure the distance between the groups centroids by calculating the 50% quantile (probs = c(0.5)). ## Creating a dispRity object with two groups grouped_space <- custom.subsets(dummy_space, group = list(c(1:5), c(6:10))) ## Measuring the minimum distance between both groups summary(dispRity(grouped_space, metric = group.dist, between.groups = TRUE)) ## subsets n_1 n_2 obs ## 1 1:2 5 5 0 ## Measuring the centroid distance between both groups summary(dispRity(grouped_space, metric = group.dist, between.groups = TRUE, probs = 0.5)) ## subsets n_1 n_2 obs ## 1 1:2 5 5 0.708 ## Measuring the distance between both group's 75% CI summary(dispRity(grouped_space, metric = group.dist, between.groups = TRUE, probs = c(0.25, 0.75))) ## subsets n_1 n_2 obs ## 1 1:2 5 5 0.059 4.4.7.9.2 point.dist The metric measures the distance between the elements in one group (matrix) and a point calculated from a second group (matrix2). By default this point is the centroid but can be any point defined by a function passed to the point argument. For example, the centroid of matrix2 is the mean of each column of that matrix so point = colMeans (default). This function also takes the method argument like previous one described above to measure either the \"euclidean\" (default) or the \"manhattan\" distances: ## Measuring the distance between the elements of the first group ## and the centroid of the second group summary(dispRity(grouped_space, metric = point.dist, between.groups = TRUE)) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 1:2 5 5 2.182 1.304 1.592 2.191 3.355 ## Measuring the distance between the elements of the second group ## and the centroid of the first group summary(dispRity(grouped_space, metric = point.dist, between.groups = list(c(2,1)))) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 2:1 5 5 1.362 0.76 1.296 1.505 1.985 ## Measuring the distance between the elements of the first group ## a point defined as the standard deviation of each column ## in the second group sd.point <- function(matrix2) {apply(matrix2, 2, sd)} summary(dispRity(grouped_space, metric = point.dist, point = sd.point, method = "manhattan", between.groups = TRUE)) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 1:2 5 5 4.043 2.467 3.567 4.501 6.884 4.4.7.9.3 projections.between and disalignment These two metrics are typically based on variance-covariance matrices from a dispRity object that has a $covar component (see more about that here). Both are based on the projections metric and can take the same optional arguments (more info here). The examples and explanations below are based on the default arguments but it is possible (and easy!) to change them. We are going to use the charadriiformes example for both metrics (see more about that here). ## Loading the charadriiformes data data(charadriiformes) ## Creating the dispRity object (see the #covar section in the manual for more info) my_covar <- MCMCglmm.subsets(n = 50, data = charadriiformes$data, posteriors = charadriiformes$posteriors, group = MCMCglmm.levels(charadriiformes$posteriors)[1:4], tree = charadriiformes$tree, rename.groups = c(levels(charadriiformes$data$clade), "phylogeny")) The first metric, projections.between projects the major axis of one group (matrix) onto the major axis of another one (matrix2). For example we might want to know how some groups compare in terms of angle (orientation) to a base group: ## Creating the list of groups to compare comparisons_list <- list(c("gulls", "phylogeny"), c("plovers", "phylogeny"), c("sandpipers", "phylogeny")) ## Measuring the angles between each groups ## (note that we set the metric as.covar, more on that in the #covar section below) groups_angles <- dispRity(data = my_covar, metric = as.covar(projections.between), between.groups = comparisons_list, measure = "degree") ## And here are the angles in degrees: summary(groups_angles) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 gulls:phylogeny 159 359 9.39 2.480 5.95 16.67 43.2 ## 2 plovers:phylogeny 98 359 20.42 4.500 12.36 51.31 129.8 ## 3 sandpipers:phylogeny 102 359 10.82 1.777 7.60 13.89 43.0 The second metric, disalignment rejects the centroid of a group (matrix) onto the major axis of another one (matrix2). This allows to measure wether the center of a group is aligned with the major axis of another. A disalignement value of 0 means that the groups are aligned. A higher disalignment value means the groups are more and more disaligned. We can use the same set of comparisons as in the projections.between examples to measure which group is most aligned (less disaligned) with the phylogenetic major axis: ## Measuring the disalignement of each group groups_alignement <- dispRity(data = my_covar, metric = as.covar(disalignment), between.groups = comparisons_list) ## And here are the groups alignment (0 = aligned) summary(groups_alignement) ## subsets n_1 n_2 obs.median 2.5% 25% 75% 97.5% ## 1 gulls:phylogeny 159 359 0.003 0.001 0.002 0.005 0.021 ## 2 plovers:phylogeny 98 359 0.001 0.000 0.001 0.001 0.006 ## 3 sandpipers:phylogeny 102 359 0.002 0.000 0.001 0.005 0.018 4.4.8 Which disparity metric to choose? The disparity metric that gives the most consistent results is the following one: best.metric <- function() return(42) Joke aside, this is a legitimate question that has no simple answer: it depends on the dataset and question at hand. Thoughts on which metric to choose can be find in Thomas Guillerme, Puttick, et al. (2020) and Thomas Guillerme, Cooper, et al. (2020) but again, will ultimately depend on the question and dataset. The question should help figuring out which type of metric is desired: for example, in the question “does the extinction released niches for mammals to evolve”, the metric in interest should probably pick up a change in size in the trait space (the release could result in some expansion of the mammalian morphospace); or if the question is “does group X compete with group Y”, maybe the metric of interested should pick up changes in position (group X can be displaced by group Y). In order to visualise what signal different disparity metrics are picking, you can use the moms that come with a detailed manual on how to use it. Alternatively, you can use the test.metric function: 4.4.8.1 test.metric This function allows to test whether a metric picks different changes in disparity. It intakes the space on which to test the metric, the disparity metric and the type of changes to apply gradually to the space. Basically this is a type of biased data rarefaction (or non-biased for \"random\") to see how the metric reacts to specific changes in trait space. ## Creating a 2D uniform space example_space <- space.maker(300, 2, runif) ## Testing the product of ranges metric on the example space example_test <- test.metric(example_space, metric = c(prod, ranges), shifts = c("random", "size")) By default, the test runs three replicates of space reduction as described in Thomas Guillerme, Puttick, et al. (2020) by gradually removing 10% of the data points following the different algorithms from Thomas Guillerme, Puttick, et al. (2020) (here the \"random\" reduction and the \"size\") reduction, resulting in a dispRity object that can be summarised or plotted. The number of replicates can be changed using the replicates option. Still by default, the function then runs a linear model on the simulated data to measure some potential trend in the changes in disparity. The model can be changed using the model option. Finally, the function runs 10 reductions by default from keeping 10% of the data (removing 90%) and way up to keeping 100% of the data (removing 0%). This can be changed using the steps option. A good disparity metric for your dataset will typically have no trend in the \"random\" reduction (the metric is ideally not affected by sample size) but should have a trend for the reduction of interest. ## The results as a dispRity object example_test ## Metric testing: ## The following metric was tested: c(prod, ranges). ## The test was run on the random, size shifts for 3 replicates using the following model: ## lm(disparity ~ reduction, data = data) ## Use summary(x) or plot(x) for more details. ## Summarising these results summary(example_test) ## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope ## random 0.94 0.97 0.94 0.97 0.98 0.98 0.99 0.99 0.99 0.99 6.389477e-04 ## size.increase 0.11 0.21 0.38 0.54 0.68 0.79 0.87 0.93 0.98 0.99 1.040938e-02 ## size.hollowness 0.98 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 0.99 1.880225e-05 ## p_value R^2(adj) ## random 5.891773e-06 0.5084747 ## size.increase 4.331947e-19 0.9422289 ## size.hollowness 3.073793e-03 0.2467532 ## Or visualising them plot(example_test) 4.5 Summarising dispRity data (plots) Because of its architecture, printing dispRity objects only summarises their content but does not print the disparity value measured or associated analysis (more about this here). To actually see what is in a dispRity object, one can either use the summary function for visualising the data in a table or plot to have a graphical representation of the results. 4.5.1 Summarising dispRity data This function is an S3 function (summary.dispRity) allowing users to summarise the content of dispRity objects that contain disparity calculations. ## Example data from previous sections crown_stem <- custom.subsets(BeckLee_mat50, group = crown.stem(BeckLee_tree, inc.nodes = FALSE)) ## Bootstrapping and rarefying these groups boot_crown_stem <- boot.matrix(crown_stem, bootstraps = 100, rarefaction = TRUE) ## Calculate disparity disparity_crown_stem <- dispRity(boot_crown_stem, metric = c(sum, variances)) ## Creating time slice subsets time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "continuous", model = "proximity", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages) ## Bootstrapping the time slice subsets boot_time_slices <- boot.matrix(time_slices, bootstraps = 100) ## Calculate disparity disparity_time_slices <- dispRity(boot_time_slices, metric = c(sum, variances)) ## Creating time bin subsets time_bins <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "discrete", time = c(120, 80, 40, 0), FADLAD = BeckLee_ages, inc.nodes = TRUE) ## Bootstrapping the time bin subsets boot_time_bins <- boot.matrix(time_bins, bootstraps = 100) ## Calculate disparity disparity_time_bins <- dispRity(boot_time_bins, metric = c(sum, variances)) These objects are easy to summarise as follows: ## Default summary summary(disparity_time_slices) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 120 5 3.126 2.556 1.446 2.365 2.799 2.975 ## 2 80 19 3.351 3.188 3.019 3.137 3.235 3.291 ## 3 40 15 3.538 3.346 3.052 3.226 3.402 3.538 ## 4 0 10 3.934 3.601 3.219 3.446 3.681 3.819 Information about the number of elements in each subset and the observed (i.e. non-bootstrapped) disparity are also calculated. This is specifically handy when rarefying the data for example: head(summary(disparity_crown_stem)) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 crown 30 2.526 2.444 2.374 2.420 2.466 2.490 ## 2 crown 29 NA 2.454 2.387 2.427 2.470 2.490 ## 3 crown 28 NA 2.443 2.387 2.423 2.462 2.489 ## 4 crown 27 NA 2.440 2.366 2.417 2.468 2.493 ## 5 crown 26 NA 2.442 2.357 2.408 2.459 2.492 ## 6 crown 25 NA 2.445 2.344 2.425 2.469 2.490 The summary functions can also take various options such as: quantiles values for the confidence interval levels (by default, the 50 and 95 quantiles are calculated) cent.tend for the central tendency to use for summarising the results (default is median) digits option corresponding to the number of decimal places to print (default is 2) recall option for printing the call of the dispRity object as well (default is FALSE) These options can easily be changed from the defaults as follows: ## Same as above but using the 88th quantile and the standard deviation as the summary summary(disparity_time_slices, quantiles = 88, cent.tend = sd) ## subsets n obs bs.sd 6% 94% ## 1 120 5 3.126 0.366 2.043 2.947 ## 2 80 19 3.351 0.072 3.048 3.277 ## 3 40 15 3.538 0.133 3.095 3.525 ## 4 0 10 3.934 0.167 3.292 3.776 ## Printing the details of the object and digits the values to the 5th decimal place summary(disparity_time_slices, recall = TRUE, digits = 5) ## ---- dispRity object ---- ## 4 continuous (proximity) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 120, 80, 40, 0. ## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: c(sum, variances). ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 120 5 3.12580 2.55631 1.44593 2.36454 2.79905 2.97520 ## 2 80 19 3.35072 3.18751 3.01906 3.13720 3.23534 3.29113 ## 3 40 15 3.53811 3.34647 3.05242 3.22616 3.40199 3.53793 ## 4 0 10 3.93353 3.60071 3.21947 3.44555 3.68095 3.81856 Note that the summary table is a data.frame, hence it is as easy to modify as any dataframe using dplyr. You can also export it in csv format using write.csv or write_csv or even directly export into LaTeX format using the following; ## Loading the xtable package require(xtable) ## Converting the table in LaTeX xtable(summary(disparity_time_slices)) 4.5.2 Plotting dispRity data An alternative (and more fun!) way to display the calculated disparity is to plot the results using the S3 method plot.dispRity. This function takes the same options as summary.dispRity along with various graphical options described in the function help files (see ?plot.dispRity). The plots can be of five different types: preview for a 2d preview of the trait-space. continuous for displaying continuous disparity curves box, lines, and polygons to display discrete disparity results in respectively a boxplot, confidence interval lines, and confidence interval polygons. This argument can be left empty. In this case, the algorithm will automatically detect the type of subsets from the dispRity object and plot accordingly. It is also possible to display the number of elements in each subset (as a horizontal dotted line) using the option elements = TRUE. Additionally, when the data is rarefied, one can indicate which level of rarefaction to display (i.e. only display the results for a certain number of elements) by using the rarefaction argument. ## Graphical parameters op <- par(mfrow = c(2, 2), bty = "n") ## Plotting continuous disparity results plot(disparity_time_slices, type = "continuous") ## Plotting discrete disparity results plot(disparity_crown_stem, type = "box") ## As above but using lines for the rarefaction level of 20 elements only plot(disparity_crown_stem, type = "line", rarefaction = 20) ## As above but using polygons while also displaying the number of elements plot(disparity_crown_stem, type = "polygon", elements = TRUE) ## Resetting graphical parameters par(op) Since plot.dispRity uses the arguments from the generic plot method, it is of course possible to change pretty much everything using the regular plot arguments: ## Graphical options op <- par(bty = "n") ## Plotting the results with some classic options from plot plot(disparity_time_slices, col = c("blue", "orange", "green"), ylab = c("Some measurement"), xlab = "Some other measurement", main = "Many options...", ylim = c(10, 0), xlim = c(4, 0)) ## Adding a legend legend("topleft", legend = c("Central tendency", "Confidence interval 1", "Confidence interval 2"), col = c("blue", "orange", "green"), pch = 19) ## Resetting graphical parameters par(op) In addition to the classic plot arguments, the function can also take arguments that are specific to plot.dispRity like adding the number of elements or rarefaction level (as described above), and also changing the values of the quantiles to plot as well as the central tendency. ## Graphical options op <- par(bty = "n") ## Plotting the results with some plot.dispRity arguments plot(disparity_time_slices, quantiles = c(seq(from = 10, to = 100, by = 10)), cent.tend = sd, type = "c", elements = TRUE, col = c("black", rainbow(10)), ylab = c("Disparity", "Diversity"), xlab = "Time (in in units from past to present)", observed = TRUE, main = "Many more options...") ## Resetting graphical parameters par(op) Note that the argument observed = TRUE allows to plot the disparity values calculated from the non-bootstrapped data as crosses on the plot. For comparing results, it is also possible to add a plot to the existent plot by using add = TRUE: ## Graphical options op <- par(bty = "n") ## Plotting the continuous disparity with a fixed y axis plot(disparity_time_slices, ylim = c(3, 9)) ## Adding the discrete data plot(disparity_time_bins, type = "line", ylim = c(3, 9), xlab = "", ylab = "", add = TRUE) ## Resetting graphical parameters par(op) Finally, if your data has been fully rarefied, it is also possible to easily look at rarefaction curves by using the rarefaction = TRUE argument: ## Graphical options op <- par(bty = "n") ## Plotting the rarefaction curves plot(disparity_crown_stem, rarefaction = TRUE) ## Resetting graphical parameters par(op) 4.5.3 type = preview Note that all the options above are plotting disparity objects for which a disparity metric has been calculated. This makes totally sense for dispRity objects but sometimes it might be interesting to look at what the trait-space looks like before measuring the disparity. This can be done by plotting dispRity objects with no calculated disparity! For example, we might be interested in looking at how the distribution of elements change as a function of the distributions of different sub-settings. For example custom subsets vs. time subsets: ## Making the different subsets cust_subsets <- custom.subsets(BeckLee_mat99, crown.stem(BeckLee_tree, inc.nodes = TRUE)) time_subsets <- chrono.subsets(BeckLee_mat99, tree = BeckLee_tree, method = "discrete", time = 5) ## Note that no disparity has been calculated here: is.null(cust_subsets$disparity) ## [1] TRUE is.null(time_subsets$disparity) ## [1] TRUE ## But we can still plot both spaces by using the default plot functions par(mfrow = c(1,2)) ## Default plotting plot(cust_subsets) ## Plotting with more arguments plot(time_subsets, specific.args = list(dimensions = c(1,2)), main = "Some \\"low\\" dimensions") DISCLAIMER: This functionality can be handy for exploring the data (e.g. to visually check whether the subset attribution worked) but it might be misleading on how the data is actually distributed in the multidimensional space! Groups that don’t overlap on two set dimensions can totally overlap in all other dimensions! For dispRity objects that do contain disparity data, the default option is to plot your disparity data. However you can always force the preview option using the following: par(mfrow = c(2,1)) ## Default plotting plot(disparity_time_slices, main = "Disparity through time") ## Plotting with more arguments plot(disparity_time_slices, type = "preview", main = "Two first dimensions of the trait space") 4.5.4 Graphical options with ... As mentioned above all the plots using plot.dispRity you can use the ... options to add any type of graphical parameters recognised by plot. However, sometimes, plotting more advanced \"dispRity\" objects also calls other generic functions such as lines, points or legend. You can fine tune which specific function should be affected by ... by using the syntax <function>.<argument> where <function> is usually the function to plot a specific element in the plot (e.g. points) and the <argument> is the specific argument you want to change for that function. For example, in a plot containing several elements, including circles (plotted internally with points), you can decide to colour everything in blue using the normal col = \"blue\" option. But you can also decide to only colour the circles in blue using points.col = \"blue\"! Here is an example with multiple elements (lines and points) taken from the disparity with trees section below: ## Loading some demo data: ## An ordinated matrix with node and tip labels data(BeckLee_mat99) ## The corresponding tree with tip and node labels data(BeckLee_tree) ## A list of tips ages for the fossil data data(BeckLee_ages) ## Time slicing through the tree using the equal split algorithm time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, FADLAD = BeckLee_ages, method = "continuous", model = "acctran", time = 15) par(mfrow = c(2,2)) ## The preview plot with the tree using only defaults plot(time_slices, type = "preview", specific.args = list(tree = TRUE)) ## The same plot but by applying general options plot(time_slices, type = "preview", specific.args = list(tree = TRUE), col = "blue", main = "General options") ## The same plot but by applying the colour only to the lines ## and change of shape only to the points plot(time_slices, type = "preview", specific.args = list(tree = TRUE), lines.col = "blue", points.pch = 15, main = "Specific options") ## And now without the legend plot(time_slices, type = "preview", specific.args = list(tree = TRUE), lines.col = "blue", points.pch = 15, legend = FALSE) 4.6 Testing disparity hypotheses The dispRity package allows users to apply statistical tests to the calculated disparity to test various hypotheses. The function test.dispRity works in a similar way to the dispRity function: it takes a dispRity object, a test and a comparisons argument. The comparisons argument indicates the way the test should be applied to the data: pairwise (default): to compare each subset in a pairwise manner referential: to compare each subset to the first subset sequential: to compare each subset to the following subset all: to compare all the subsets together (like in analysis of variance) It is also possible to input a list of pairs of numeric values or characters matching the subset names to create personalised tests. Some other tests implemented in dispRity such as the dispRity::null.test have a specific way they are applied to the data and therefore ignore the comparisons argument. The test argument can be any statistical or non-statistical test to apply to the disparity object. It can be a common statistical test function (e.g. stats::t.test), a function implemented in dispRity (e.g. see ?null.test) or any function defined by the user. This function also allows users to correct for Type I error inflation (false positives) when using multiple comparisons via the correction argument. This argument can be empty (no correction applied) or can contain one of the corrections from the stats::p.adjust function (see ?p.adjust). Note that the test.dispRity algorithm deals with some classical test outputs (h.test, lm and numeric vector) and summarises the test output. It is, however, possible to get the full detailed output by using the options details = TRUE. Here we are using the variables generated in the section above: ## T-test to test for a difference in disparity between crown and stem mammals test.dispRity(disparity_crown_stem, test = t.test) ## [[1]] ## statistic: t ## crown : stem 54.10423 ## ## [[2]] ## parameter: df ## crown : stem 177.9857 ## ## [[3]] ## p.value ## crown : stem 1.928983e-112 ## ## [[4]] ## stderr ## crown : stem 0.005649615 ## Performing the same test but with the detailed t.test output test.dispRity(disparity_crown_stem, test = t.test, details = TRUE) ## $`crown : stem` ## $`crown : stem`[[1]] ## ## Welch Two Sample t-test ## ## data: dots[[1L]][[1L]] and dots[[2L]][[1L]] ## t = 54.104, df = 177.99, p-value < 2.2e-16 ## alternative hypothesis: true difference in means is not equal to 0 ## 95 percent confidence interval: ## 0.2945193 0.3168170 ## sample estimates: ## mean of x mean of y ## 2.440968 2.135299 ## Wilcoxon test applied to time sliced disparity with sequential comparisons, ## with Bonferroni correction test.dispRity(disparity_time_slices, test = wilcox.test, comparisons = "sequential", correction = "bonferroni") ## [[1]] ## statistic: W ## 120 : 80 40 ## 80 : 40 1812 ## 40 : 0 1463 ## ## [[2]] ## p.value ## 120 : 80 2.534081e-33 ## 80 : 40 2.037470e-14 ## 40 : 0 1.671038e-17 ## Measuring the overlap between distributions in the time bins (using the ## implemented Bhattacharyya Coefficient function - see ?bhatt.coeff) test.dispRity(disparity_time_bins, test = bhatt.coeff) ## bhatt.coeff ## 120 - 80 : 80 - 40 0.000000 ## 120 - 80 : 40 - 0 0.000000 ## 80 - 40 : 40 - 0 0.450877 Because of the modular design of the package, tests can always be made by the user (the same way disparity metrics can be user made). The only condition is that the test can be applied to at least two distributions. In practice, the test.dispRity function will pass the calculated disparity data (distributions) to the provided function in either pairs of distributions (if the comparisons argument is set to pairwise, referential or sequential) or a table containing all the distributions (comparisons = all; this should be in the same format as data passed to lm-type functions for example). 4.6.1 NPMANOVA in dispRity One often useful test to apply to multidimensional data is the permutational multivariate analysis of variance based on distance matrices vegan::adonis2. This can be done on dispRity objects using the adonis.dispRity wrapper function. Basically, this function takes the exact same arguments as adonis and a dispRity object for data and performs a PERMANOVA based on the distance matrix of the multidimensional space (unless the multidimensional space was already defined as a distance matrix). The adonis.dispRity function uses the information from the dispRity object to generate default formulas: If the object contains customised subsets, it applies the default formula matrix ~ group testing the effect of group as a predictor on matrix (called from the dispRity object as data$matrix see dispRity object details) If the object contains time subsets, it applies the default formula matrix ~ time testing the effect of time as a predictor (were the different levels of time are the different time slices/bins) set.seed(1) ## Generating a random character matrix character_matrix <- sim.morpho(rtree(20), 50, rates = c(rnorm, 1, 0)) ## Calculating the distance matrix distance_matrix <- as.matrix(dist(character_matrix)) ## Creating two groups random_groups <- list("group1" = 1:10, "group2" = 11:20) ## Generating a dispRity object random_disparity <- custom.subsets(distance_matrix, random_groups) ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! ## You can use dist.data = TRUE, if you want to keep the data as a distance matrix. ## Running a default NPMANOVA adonis.dispRity(random_disparity) ## Permutation test for adonis under reduced model ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = matrix ~ group, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## Model 1 14.2 0.06443 1.2396 0.166 ## Residual 18 206.2 0.93557 ## Total 19 220.4 1.00000 Of course, it is possible to pass customised formulas if the disparity object contains more more groups. In that case the predictors must correspond to the names of the groups explained data must be set as matrix: ## Creating two groups with two states each groups <- as.data.frame(matrix(data = c(rep(1,10), rep(2,10), rep(c(1,2), 10)), nrow = 20, ncol = 2, dimnames = list(paste0("t", 1:20), c("g1", "g2")))) ## Creating the dispRity object multi_groups <- custom.subsets(distance_matrix, groups) ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! ## You can use dist.data = TRUE, if you want to keep the data as a distance matrix. ## Running the NPMANOVA adonis.dispRity(multi_groups, matrix ~ g1 + g2) ## Permutation test for adonis under reduced model ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = matrix ~ g1 + g2, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## Model 2 20.6 0.09347 0.8764 0.746 ## Residual 17 199.8 0.90653 ## Total 19 220.4 1.00000 Finally, it is possible to use objects generated by chrono.subsets. In this case, adonis.dispRity will applied the matrix ~ time formula by default: ## Creating time series time_subsets <- chrono.subsets(BeckLee_mat50, BeckLee_tree, method = "discrete", inc.nodes = FALSE, time = c(100, 85, 65, 0), FADLAD = BeckLee_ages) ## Running the NPMANOVA with time as a predictor adonis.dispRity(time_subsets) ## Warning in adonis.dispRity(time_subsets): The input data for adonis.dispRity was not a distance matrix. ## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])). ## Make sure that this is the desired methodological approach! ## Permutation test for adonis under reduced model ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ time, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## Model 2 9.593 0.07769 1.9796 0.001 *** ## Residual 47 113.884 0.92231 ## Total 49 123.477 1.00000 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Note that the function warns you that the input data was transformed into a distance matrix. This is reflected in the Call part of the output (formula = dist(matrix) ~ time). To use each time subset as a separate predictor, you can use the matrix ~ chrono.subsets formula; this is equivalent to matrix ~ first_time_subset + second_time_subset + ...: ## Running the NPMANOVA with each time bin as a predictor adonis.dispRity(time_subsets, matrix ~ chrono.subsets) ## Warning in adonis.dispRity(time_subsets, matrix ~ chrono.subsets): The input data for adonis.dispRity was not a distance matrix. ## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])). ## Make sure that this is the desired methodological approach! ## Permutation test for adonis under reduced model ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ chrono.subsets, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## Model 2 9.593 0.07769 1.9796 0.001 *** ## Residual 47 113.884 0.92231 ## Total 49 123.477 1.00000 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 4.6.2 geiger::dtt model fitting in dispRity The dtt function from the geiger package is also often used to compare a trait’s disparity observed in living taxa to the disparity of a simulated trait based on a given phylogeny. The dispRity package proposes a wrapper function for geiger::dtt, dtt.dispRity that allows the use of any disparity metric. Unfortunately, this implementation is slower that geiger::dtt (so if you’re using the metrics implemented in geiger prefer the original version) and, as the original function, is limited to ultrametric trees (only living taxa!)… require(geiger) ## Loading required package: geiger geiger_data <- get(data(geospiza)) ## Calculate the disparity of the dataset using the sum of variance dispRity_dtt <- dtt.dispRity(data = geiger_data$dat, metric = c(sum, variances), tree = geiger_data$phy, nsim = 100) ## Warning in dtt.dispRity(data = geiger_data$dat, metric = c(sum, variances), : ## The following tip(s) was not present in the data: olivacea. ## Plotting the results plot(dispRity_dtt) Note that, like in the original dtt function, it is possible to change the evolutionary model (see ?geiger::sim.char documentation). 4.6.3 null morphospace testing with null.test This test is equivalent to the test performed in Dı́az et al. (2016). It compares the disparity measured in the observed space to the disparity measured in a set of simulated spaces. These simulated spaces can be built with based on the hypothesis assumptions: for example, we can test whether our space is normal. set.seed(123) ## A "normal" multidimensional space with 50 dimensions and 10 elements normal_space <- matrix(rnorm(1000), ncol = 50) ## Calculating the disparity as the average pairwise distances obs_disparity <- dispRity(normal_space, metric = c(mean, pairwise.dist)) ## Warning in check.data(data, match_call): Row names have been automatically ## added to data. ## Testing against 100 randomly generated normal spaces (results <- null.test(obs_disparity, replicates = 100, null.distrib = rnorm)) ## Monte-Carlo test ## Call: [1] "dispRity::null.test" ## ## Observation: 9.910536 ## ## Based on 100 replicates ## Simulated p-value: 0.8712871 ## Alternative hypothesis: two-sided ## ## Std.Obs Expectation Variance ## -0.18217227 9.95101000 0.04936221 Here the results show that disparity measured in our observed space is not significantly different than the one measured in a normal space. We can then propose that our observed space is normal! These results have an attributed dispRity and randtest class and can be plotted as randtest objects using the dispRity S3 plot method: ## Plotting the results plot(results, main = "Is this space normal?") For more details on generating spaces see the space.maker function tutorial. 4.7 Fitting modes of evolution to disparity data The code used for these models is based on those developed by Gene Hunt (Hunt 2006, 2012; Hunt, Hopkins, and Lidgard 2015). So we acknowledge and thank Gene Hunt for developing these models and writing the original R code that served as inspiration for these models. DISCLAIMER: this method of analysing disparity has not been published yet and has not been peer reviewed. Caution should be used in interpreting these results: it is unclear what “a disparity curve fitting a Brownian motion” actually means biologically. As Malcolm said in Jurassic Park: “although the examples within this chapter all work and produce solid tested results (from an algorithm point of view), that doesn’t mean you should use it” (or something along those lines). 4.7.1 Simple modes of disparity change through time 4.7.1.1 model.test Changes in disparity-through-time can follow a range of models, such as random walks, stasis, constrained evolution, trends, or an early burst model of evolution. We will start with by fitting the simplest modes of evolution to our data. For example we may have a null expectation of time-invariant change in disparity in which values fluctuate with a variance around the mean - this would be best describe by a Stasis model: ## Loading premade disparity data data(BeckLee_disparity) disp_time <- model.test(data = BeckLee_disparity, model = "Stasis") ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 We can see the standard output from model.test. The first output message tells us it has tested for equal variances in each sample. The model uses Bartlett’s test of equal variances to assess if variances are equal, so if p > 0.05 then variance is treated as the same for all samples, but if (p < 0.05) then each bin variance is unique. Here we have p < 0.05, so variance is not pooled between samples. By default model.test will use Bartlett’s test to assess for homogeneity of variances, and then use this to decide to pool variances or not. This is ignored if the argument pool.variance in model.test is changed from the default NULL to TRUE or FALSE. For example, to ignore Bartlett’s test and pool variances manually we would do the following: disp_time_pooled <- model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = TRUE) ## Running Stasis model...Done. Log-likelihood = -13.682 However, unless you have good reason to choose otherwise it is recommended to use the default of pool.variance = NULL: disp_time <- model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 disp_time ## Disparity evolution model fitting: ## Call: model.test(data = BeckLee_disparity, model = "Stasis", pool.variance = NULL) ## ## aicc delta_aicc weight_aicc ## Stasis 35.22653 0 1 ## ## Use x$full.details for displaying the models details ## or summary(x) for summarising them. The remaining output gives us the log-likelihood of the Stasis model of -15.6 (you may notice this change when we pooled variances above). The output also gives us the small sample Akaike Information Criterion (AICc), the delta AICc (the distance from the best fitting model), and the AICc weights (~the relative support of this model compared to all models, scaled to one). These are all metrics of relative fit, so when we test a single model they are not useful. By using the function summary in dispRity we can see the maximum likelihood estimates of the model parameters: summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ## Stasis 35.2 0 1 -15.6 2 3.5 0.1 So we again see the AICc, delta AICc, AICc weight, and the log-likelihood we saw previously. We now also see the number of parameters from the model (2: theta and omega), and their estimates so the variance (omega = 0.1) and the mean (theta.1 = 3.5). The model.test function is designed to test relative model fit, so we need to test more than one model to make relative comparisons. So let’s compare to the fit of the Stasis model to another model with two parameters: the Brownian motion. Brownian motion assumes a constant mean that is equal to the ancestral estimate of the sequence, and the variance around this mean increases linearly with time. The easier way to compare these models is to simply add \"BM\" to the models vector argument: disp_time <- model.test(data = BeckLee_disparity, model = c("Stasis", "BM")) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 ## Running BM model...Done. Log-likelihood = 151.637 disp_time ## Disparity evolution model fitting: ## Call: model.test(data = BeckLee_disparity, model = c("Stasis", "BM")) ## ## aicc delta_aicc weight_aicc ## Stasis 35.22653 334.3978 2.434618e-73 ## BM -299.17132 0.0000 1.000000e+00 ## ## Use x$full.details for displaying the models details ## or summary(x) for summarising them. Et voilà! Here we can see by the log-likelihood, AICc, delta AICc, and AICc weight Brownian motion has a much better relative fit to these data than the Stasis model. Brownian motion has a relative AICc fit334.4 units better than Stasis, and has a AICc weight of 1. We can also all the information about the relative fit of models alongside the maximum likelihood estimates of model parameters using the summary function summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Stasis 35 334.4 0 -15.6 2 3.486 0.07 NA ## BM -299 0.0 1 151.6 2 NA NA 3.132 ## sigma squared ## Stasis NA ## BM 0.001 Not that because the parameters per models differ, the summary includes NA for inapplicable parameters per models (e.g. the theta and omega parameters from the Stasis models are inapplicable for a Brownian motion model). We can plot the relative fit of our models using the plot function plot(disp_time) Figure 4.1: relative fit (AICc weight) of Stasis and Brownian models of disparity through time Here we see and overwhelming support for the Brownian motion model. Alternatively, we could test all available models single modes: Stasis, Brownian motion, Ornstein-Uhlenbeck (evolution constrained to an optima), Trend (increasing or decreasing mean through time), and Early Burst (exponentially decreasing rate through time) disp_time <- model.test(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB")) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 ## Running BM model...Done. Log-likelihood = 151.637 ## Running OU model...Done. Log-likelihood = 154.512 ## Running Trend model...Done. Log-likelihood = 154.508 ## Running EB model...Done. Log-likelihood = 128.008 summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA ## BM -299 3.6 0.108 151.6 2 NA NA 3.132 ## OU -301 2.1 0.229 154.5 4 NA NA 3.118 ## Trend -303 0.0 0.664 154.5 3 NA NA 3.119 ## EB -250 53.0 0.000 128.0 3 NA NA 3.934 ## sigma squared alpha optima.1 trend eb ## Stasis NA NA NA NA NA ## BM 0.001 NA NA NA NA ## OU 0.001 0.001 10.18 NA NA ## Trend 0.001 NA NA 0.007 NA ## EB 0.000 NA NA NA -0.034 These models indicate support for a Trend model, and we can plot the relative support of all model AICc weights. plot(disp_time) Figure 4.2: relative fit (AICc weight) of various modes of evolution Note that although AIC values are indicator of model best fit, it is also important to look at the parameters themselves. For example OU can be really well supported but with an alpha parameter really close to 0, making it effectively a BM model (Cooper et al. 2016). Is this a trend of increasing or decreasing disparity through time? One way to find out is to look at the summary function for the Trend model: summary(disp_time)["Trend",] ## aicc delta_aicc weight_aicc log.lik param ## -303.000 0.000 0.664 154.500 3.000 ## theta.1 omega ancestral state sigma squared alpha ## NA NA 3.119 0.001 NA ## optima.1 trend eb ## NA 0.007 NA This show a positive trend (0.007) of increasing disparity through time. 4.7.2 Plot and run simulation tests in a single step 4.7.2.1 model.test.wrapper Patterns of evolution can be fit using model.test, but the model.test.wrapper fits the same models as model.test as well as running predictive tests and plots. The predictive tests use the maximum likelihood estimates of model parameters to simulate a number of datasets (default = 1000), and analyse whether this is significantly different to the empirical input data using the Rank Envelope test (Murrell 2018). Finally we can plot the empirical data, simulated data, and the Rank Envelope test p values. This can all be done using the function model.test.wrapper, and we will set the argument show.p = TRUE so p values from the Rank Envelope test are printed on the plot: disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB"), show.p = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 ## Running BM model...Done. Log-likelihood = 151.637 ## Running OU model...Done. Log-likelihood = 154.512 ## Running Trend model...Done. Log-likelihood = 154.508 ## Running EB model...Done. Log-likelihood = 128.008 Figure 4.3: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for Trend, OU, BM, EB, and Stasis models disp_time ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Trend -303 0.0 0.664 154.5 3 NA NA 3.119 ## OU -301 2.1 0.229 154.5 4 NA NA 3.118 ## BM -299 3.6 0.108 151.6 2 NA NA 3.132 ## EB -250 53.0 0.000 128.0 3 NA NA 3.934 ## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA ## sigma squared alpha optima.1 trend eb median p value lower p value ## Trend 0.001 NA NA 0.007 NA 0.986013986 0.9850150 ## OU 0.001 0.001 10.18 NA NA 0.979020979 0.9770230 ## BM 0.001 NA NA NA NA 0.107892108 0.0969031 ## EB 0.000 NA NA NA -0.034 0.000999001 0.0000000 ## Stasis NA NA NA NA NA 1.000000000 0.9990010 ## upper p value ## Trend 0.9860140 ## OU 0.9800200 ## BM 0.1388611 ## EB 0.1378621 ## Stasis 1.0000000 From this plot we can see the empirical estimates of disparity through time (pink) compared to the predictive data based upon the simulations using the estimated parameters from each model. There is no significant differences between the empirical data and simulated data, except for the Early Burst model. Trend is the best-fitting model but the plot suggests the OU model also follows a trend-like pattern. This is because the optima for the OU model (10.18) is different to the ancestral state (3.118) and outside the observed value. This is potentially unrealistic, and one way to alleviate this issue is to set the optima of the OU model to equal the ancestral estimate - this is the normal practice for OU models in comparative phylogenetics. To set the optima to the ancestral value we change the argument fixed.optima = TRUE: disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB"), show.p = TRUE, fixed.optima = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 ## Running BM model...Done. Log-likelihood = 151.637 ## Running OU model...Done. Log-likelihood = 151.637 ## Running Trend model...Done. Log-likelihood = 154.508 ## Running EB model...Done. Log-likelihood = 128.008 Figure 4.4: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for Trend, OU, BM, EB, and Stasis models with the optima of the OU model set to equal the ancestral value disp_time ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Trend -303 0.0 0.821 154.5 3 NA NA 3.119 ## BM -299 3.6 0.133 151.6 2 NA NA 3.132 ## OU -297 5.7 0.046 151.6 3 NA NA 3.132 ## EB -250 53.0 0.000 128.0 3 NA NA 3.934 ## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA ## sigma squared alpha trend eb median p value lower p value ## Trend 0.001 NA 0.007 NA 0.989010989 0.9880120 ## BM 0.001 NA NA NA 0.224775225 0.2117882 ## OU 0.001 0 NA NA 0.264735265 0.2637363 ## EB 0.000 NA NA -0.034 0.000999001 0.0000000 ## Stasis NA NA NA NA 0.999000999 0.9980020 ## upper p value ## Trend 0.9890110 ## BM 0.2507493 ## OU 0.2967033 ## EB 0.1378621 ## Stasis 0.9990010 The relative fit of the OU model is decreased by constraining the fit of the optima to equal the ancestral state value. In fact as the OU attraction parameter (alpha) is zero, the model is equal to a Brownian motion model but is penalised by having an extra parameter. Note that indeed, the plots of the BM model and the OU model look nearly identical. 4.7.3 Multiple modes of evolution (time shifts) As well as fitting a single model to a sequence of disparity values we can also allow for the mode of evolution to shift at a single or multiple points in time. The timing of a shift in mode can be based on an a prior expectation, such as a mass extinction event, or the model can test multiple points to allow to find time shift point with the highest likelihood. Models can be fit using model.test but it can be more convenient to use model.test.wrapper. Here we will compare the relative fit of Brownian motion, Trend, Ornstein-Uhlenbeck and a multi-mode Ornstein Uhlenbck model in which the optima changes at 66 million years ago, the Cretaceous-Palaeogene boundary. For example, we could be testing the hypothesis that the extinction of non-avian dinosaurs allowed mammals to go from scurrying in the undergrowth (low optima/low disparity) to dominating all habitats (high optima/high disparity). We will constrain the optima of OU model in the first time begin (i.e, pre-66 Mya) to equal the ancestral value: disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("BM", "Trend", "OU", "multi.OU"), time.split = 66, pool.variance = NULL, show.p = TRUE, fixed.optima = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running BM model...Done. Log-likelihood = 151.637 ## Running Trend model...Done. Log-likelihood = 154.508 ## Running OU model...Done. Log-likelihood = 151.637 ## Running multi.OU model...Done. Log-likelihood = 154.492 Figure 4.5: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for BM, Trend, OU, and multi OU models with a shift in optima allowed at 66 Ma disp_time ## aicc delta_aicc weight_aicc log.lik param ancestral state ## Trend -303 0.000 0.642 154.5 3 3.119 ## multi.OU -301 2.170 0.217 154.5 4 3.117 ## BM -299 3.639 0.104 151.6 2 3.132 ## OU -297 5.742 0.036 151.6 3 3.132 ## sigma squared trend alpha optima.2 median p value lower p value ## Trend 0.001 0.007 NA NA 0.9870130 0.9860140 ## multi.OU 0.001 NA 0.003 5.582 0.9620380 0.9610390 ## BM 0.001 NA NA NA 0.1848152 0.1838162 ## OU 0.001 NA 0.000 NA 0.2787213 0.2757243 ## upper p value ## Trend 0.9870130 ## multi.OU 0.9620380 ## BM 0.2217782 ## OU 0.3046953 The multi-OU model shows an increase an optima at the Cretaceous-Palaeogene boundary, indicating a shift in disparity. However, this model does not fit as well as a model in which there is an increasing trend through time. We can also fit a model in which the we specify a heterogeneous model but we do not give a time.split. In this instance the model will test all splits that have at least 10 time slices on either side of the split. That’s 102 potential time shifts in this example dataset so be warned, the following code will estimate 105 models! ## An example of a time split model in which all potential splits are tested ## WARNING: this will take between 20 minutes and half and hour to run! disp_time <- model.test.wrapper(data = BeckLee_disparity, model = c("BM", "Trend", "OU", "multi.OU"), show.p = TRUE, fixed.optima = TRUE) As well as specifying a multi-OU model we can run any combination of models. For example we could fit a model at the Cretaceous-Palaeogene boundary that goes from an OU to a BM model, a Trend to an OU model, a Stasis to a Trend model or any combination you want to use. The only model that can’t be used in combination is a multi-OU model. These can be introduced by changing the input for the models into a list, and supplying a vector with the two models. This is easier to see with an example: ## The models to test my_models <- list(c("BM", "OU"), c("Stasis", "OU"), c("BM", "Stasis"), c("OU", "Trend"), c("Stasis", "BM")) ## Testing the models disp_time <- model.test.wrapper(data = BeckLee_disparity, model = my_models, time.split = 66, show.p = TRUE, fixed.optima = TRUE) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running BM:OU model...Done. Log-likelihood = 146.472 ## Running Stasis:OU model...Done. Log-likelihood = 127.707 ## Running BM:Stasis model...Done. Log-likelihood = 72.456 ## Running OU:Trend model...Done. Log-likelihood = 150.208 ## Running Stasis:BM model...Done. Log-likelihood = 127.707 Figure 4.6: Empirical disparity through time (pink), simulate data based on estimated model parameters (grey), delta AICc, and range of p values from the Rank Envelope test for a variety of models with a shift in optima allowed at 66 Ma disp_time ## aicc delta_aicc weight_aicc log.lik param ancestral state ## OU:Trend -292 0.0 0.977 150.2 4 3.218 ## BM:OU -285 7.5 0.023 146.5 4 3.216 ## Stasis:BM -249 42.9 0.000 127.7 3 NA ## Stasis:OU -245 47.2 0.000 127.7 5 NA ## BM:Stasis -137 155.5 0.000 72.5 4 3.132 ## sigma squared alpha optima.1 theta.1 omega trend median p value ## OU:Trend 0.001 0.042 NA NA NA 0.011 0.3066933 ## BM:OU 0.001 0.000 3.934 NA NA NA 0.4985015 ## Stasis:BM 0.002 NA NA 3.25 0.004 NA 0.9960040 ## Stasis:OU 0.002 0.000 3.934 3.25 0.004 NA 0.9990010 ## BM:Stasis 0.000 NA NA 3.66 0.053 NA 1.0000000 ## lower p value upper p value ## OU:Trend 0.3026973 0.3626374 ## BM:OU 0.4945055 0.5184815 ## Stasis:BM 0.9950050 0.9960040 ## Stasis:OU 0.9980020 1.0000000 ## BM:Stasis 0.9990010 1.0000000 4.7.4 model.test.sim Note that all the models above where run using the model.test.wrapper function that is a… wrapping function! In practice, this function runs two main functions from the dispRity package and then plots the results: model.test and model.test.sim The model.test.sim allows to simulate disparity evolution given a dispRity object input (as in model.test.wrapper) or given a model and its specification. For example, it is possible to simulate a simple Brownian motion model (or any of the other models or models combination described above): ## A simple BM model model_simulation <- model.test.sim(sim = 1000, model = "BM", time.span = 50, variance = 0.1, sample.size = 100, parameters = list(ancestral.state = 0)) model_simulation ## Disparity evolution model simulation: ## Call: model.test.sim(sim = 1000, model = "BM", time.span = 50, variance = 0.1, sample.size = 100, parameters = list(ancestral.state = 0)) ## ## Model simulated (1000 times): ## [1] "BM" This will simulate 1000 Brownian motions for 50 units of time with 100 sampled elements, a variance of 0.1 and an ancestral state of 0. We can also pass multiple models in the same way we did it for model.test This model can then be summarised and plotted as most dispRity objects: ## Displaying the 5 first rows of the summary head(summary(model_simulation)) ## subsets n var median 2.5% 25% 75% 97.5% ## 1 50 100 0.1 -0.06195918 -1.963569 -0.7361336 0.5556715 1.806730 ## 2 49 100 0.1 -0.09905061 -2.799025 -1.0670018 0.8836605 2.693583 ## 3 48 100 0.1 -0.06215828 -3.594213 -1.3070097 1.1349712 3.272569 ## 4 47 100 0.1 -0.10602238 -3.949521 -1.4363010 1.2234625 3.931000 ## 5 46 100 0.1 -0.09016928 -4.277897 -1.5791755 1.3889584 4.507491 ## 6 45 100 0.1 -0.13183180 -5.115647 -1.7791878 1.6270527 5.144023 ## Plotting the simulations plot(model_simulation) Figure 4.7: A simulated Brownian motion Note that these functions can take all the arguments that can be passed to plot, summary, plot.dispRity and summary.dispRity. 4.7.4.1 Simulating tested models Maybe more interestingly though, it is possible to pass the output of model.test directly to model.test.sim to simulate the models that fits the data the best and calculate the Rank Envelope test p value. Let’s see that using the simple example from the start: ## Fitting multiple models on the data set disp_time <- model.test(data = BeckLee_disparity, model = c("Stasis", "BM", "OU", "Trend", "EB")) ## Evidence of equal variance (Bartlett's test of equal variances p = 0). ## Variance is not pooled. ## Running Stasis model...Done. Log-likelihood = -15.562 ## Running BM model...Done. Log-likelihood = 151.637 ## Running OU model...Done. Log-likelihood = 154.512 ## Running Trend model...Done. Log-likelihood = 154.508 ## Running EB model...Done. Log-likelihood = 128.008 summary(disp_time) ## aicc delta_aicc weight_aicc log.lik param theta.1 omega ancestral state ## Stasis 35 338.0 0.000 -15.6 2 3.486 0.07 NA ## BM -299 3.6 0.108 151.6 2 NA NA 3.132 ## OU -301 2.1 0.229 154.5 4 NA NA 3.118 ## Trend -303 0.0 0.664 154.5 3 NA NA 3.119 ## EB -250 53.0 0.000 128.0 3 NA NA 3.934 ## sigma squared alpha optima.1 trend eb ## Stasis NA NA NA NA NA ## BM 0.001 NA NA NA NA ## OU 0.001 0.001 10.18 NA NA ## Trend 0.001 NA NA 0.007 NA ## EB 0.000 NA NA NA -0.034 As seen before, the Trend model fitted this dataset the best. To simulate what 1000 Trend models would look like using the same parameters as the ones estimated with model.test (here the ancestral state being 3.119, the sigma squared being 0.001 and the trend of 0.007), we can simply pass this model to model.test.sim: ## Simulating 1000 Trend model with the observed parameters sim_trend <- model.test.sim(sim = 1000, model = disp_time) sim_trend ## Disparity evolution model simulation: ## Call: model.test.sim(sim = 1000, model = disp_time) ## ## Model simulated (1000 times): ## aicc log.lik param ancestral state sigma squared trend ## Trend -303 154.5 3 3.119 0.001 0.007 ## ## Rank envelope test: ## p-value of the global test: 0.992008 (ties method: erl) ## p-interval : (0.991009, 0.992008) By default, the model simulated is the one with the lowest AICc (model.rank = 1) but it is possible to choose any ranked model, for example, the OU (second one): ## Simulating 1000 OU model with the observed parameters sim_OU <- model.test.sim(sim = 1000, model = disp_time, model.rank = 2) sim_OU ## Disparity evolution model simulation: ## Call: model.test.sim(sim = 1000, model = disp_time, model.rank = 2) ## ## Model simulated (1000 times): ## aicc log.lik param ancestral state sigma squared alpha optima.1 ## OU -301 154.5 4 3.118 0.001 0.001 10.18 ## ## Rank envelope test: ## p-value of the global test: 0.991009 (ties method: erl) ## p-interval : (0.989011, 0.991009) And as the example above, the simulated data can be plotted or summarised: head(summary(sim_trend)) ## subsets n var median 2.5% 25% 75% 97.5% ## 1 120 5 0.01791717 3.119216 2.996786 3.082536 3.158256 3.241577 ## 2 119 5 0.03522253 3.129400 2.958681 3.064908 3.186889 3.303168 ## 3 118 6 0.03783622 3.133125 2.957150 3.076447 3.192556 3.304469 ## 4 117 7 0.03214472 3.143511 2.978352 3.089036 3.199075 3.307842 ## 5 116 7 0.03214472 3.147732 2.981253 3.087695 3.210136 3.321990 ## 6 115 7 0.03214472 3.157588 2.969189 3.094733 3.216221 3.335341 head(summary(sim_OU)) ## subsets n var median 2.5% 25% 75% 97.5% ## 1 120 5 0.01791717 3.116975 3.002874 3.074977 3.158164 3.237559 ## 2 119 5 0.03522253 3.126662 2.948491 3.061492 3.187414 3.302442 ## 3 118 6 0.03783622 3.126408 2.966988 3.068517 3.195251 3.301177 ## 4 117 7 0.03214472 3.136145 2.970973 3.079345 3.192427 3.301722 ## 5 116 7 0.03214472 3.144302 2.967779 3.083789 3.205035 3.336560 ## 6 115 7 0.03214472 3.151057 2.961801 3.086444 3.216077 3.336897 ## The trend model with some graphical options plot(sim_trend, xlab = "Time (Mya)", ylab = "sum of variances", col = c("#F65205", "#F38336", "#F7B27E")) ## Adding the observed disparity through time plot(BeckLee_disparity, add = TRUE, col = c("#3E9CBA", "#98D4CF90", "#BFE4E390")) Figure 4.8: The best fitted model (Trend) and the observed disparity through time 4.8 Disparity as a distribution Disparity is often regarded as a summary value of the position of the all elements in the ordinated space. For example, the sum of variances, the product of ranges or the median distance between the elements and their centroid will summarise disparity as a single value. This value can be pseudo-replicated (bootstrapped) to obtain a distribution of the summary metric with estimated error. However, another way to perform disparity analysis is to use the whole distribution rather than just a summary metric (e.g. the variances or the ranges). This is possible in the dispRity package by calculating disparity as a dimension-level 2 metric only! Let’s have a look using our previous example of bootstrapped time slices but by measuring the distances between each taxon and their centroid as disparity. ## Measuring disparity as a whole distribution disparity_centroids <- dispRity(boot_time_slices, metric = centroids) The resulting disparity object is of dimension-level 2, so it can easily be transformed into a dimension-level 1 object by, for example, measuring the median distance of all these distributions: ## Measuring median disparity in each time slice disparity_centroids_median <- dispRity(disparity_centroids, metric = median) And we can now compare the differences between these methods: ## Summarising both disparity measurements: ## The distributions: summary(disparity_centroids) ## subsets n obs.median bs.median 2.5% 25% 75% 97.5% ## 1 120 5 1.569 1.338 0.834 1.230 1.650 1.894 ## 2 80 19 1.796 1.739 1.498 1.652 1.812 1.928 ## 3 40 15 1.767 1.764 1.427 1.654 1.859 2.052 ## 4 0 10 1.873 1.779 1.361 1.685 1.934 2.058 ## The summary of the distributions (as median) summary(disparity_centroids_median) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 120 5 1.569 1.351 0.648 1.282 1.596 1.641 ## 2 80 19 1.796 1.739 1.655 1.721 1.756 1.787 ## 3 40 15 1.767 1.757 1.623 1.721 1.793 1.837 ## 4 0 10 1.873 1.781 1.564 1.756 1.834 1.900 We can see that the summary message for the distribution is slightly different than before. Here summary also displays the observed central tendency (i.e. the central tendency of the measured distributions). Note that, as expected, this central tendency is the same in both metrics! Another, maybe more intuitive way, to compare both approaches for measuring disparity is to plot the distributions: ## Graphical parameters op <- par(bty = "n", mfrow = c(1, 2)) ## Plotting both disparity measurements plot(disparity_centroids, ylab = "Distribution of all the distances") plot(disparity_centroids_median, ylab = "Distribution of the medians of all the distances") par(op) We can then test for differences in the resulting distributions using test.dispRity and the bhatt.coeff test as described above. ## Probability of overlap in the distribution of medians test.dispRity(disparity_centroids_median, test = bhatt.coeff) ## bhatt.coeff ## 120 : 80 0.08831761 ## 120 : 40 0.10583005 ## 120 : 0 0.15297059 ## 80 : 40 0.83840952 ## 80 : 0 0.63913150 ## 40 : 0 0.78405839 In this case, we are looking at the probability of overlap of the distribution of median distances from centroids among each pair of time slices. In other words, we are measuring whether the medians from each bootstrap pseudo-replicate for each time slice overlap. But of course, we might be interested in the actual distribution of the distances from the centroid rather than simply their central tendencies. This can be problematic depending on the research question asked since we are effectively comparing non-independent medians distributions (because of the pseudo-replication). One solution, therefore, is to look at the full distribution: ## Probability of overlap for the full distributions test.dispRity(disparity_centroids, test = bhatt.coeff) ## bhatt.coeff ## 120 : 80 0.6163631 ## 120 : 40 0.6351473 ## 120 : 0 0.6315225 ## 80 : 40 0.9416508 ## 80 : 0 0.8551990 ## 40 : 0 0.9568684 These results show the actual overlap among all the measured distances from centroids concatenated across all the bootstraps. For example, when comparing the slices 120 and 80, we are effectively comparing the 5 \\(\\times\\) 100 distances (the distances of the five elements in slice 120 bootstrapped 100 times) to the 19 \\(\\times\\) 100 distances from slice 80. However, this can also be problematic for some specific tests since the n \\(\\times\\) 100 distances are also pseudo-replicates and thus are still not independent. A second solution is to compare the distributions to each other for each replicate: ## Boostrapped probability of overlap for the full distributions test.dispRity(disparity_centroids, test = bhatt.coeff, concatenate = FALSE) ## bhatt.coeff 2.5% 25% 75% 97.5% ## 120 : 80 0.2671081 0.00000000 0.1450953 0.3964076 0.6084459 ## 120 : 40 0.2864771 0.00000000 0.1632993 0.4238587 0.6444474 ## 120 : 0 0.2864716 0.00000000 0.2000000 0.4000000 0.5837006 ## 80 : 40 0.6187295 0.24391229 0.5284793 0.7440196 0.8961621 ## 80 : 0 0.4790692 0.04873397 0.3754429 0.5946595 0.7797225 ## 40 : 0 0.5513580 0.19542869 0.4207790 0.6870177 0.9066824 These results show the median overlap among pairs of distributions in the first column (bhatt.coeff) and then the distribution of these overlaps among each pair of bootstraps. In other words, when two distributions are compared, they are now compared for each bootstrap pseudo-replicate, thus effectively creating a distribution of probabilities of overlap. For example, when comparing the slices 120 and 80, we have a mean probability of overlap of 0.28 and a probability between 0.18 and 0.43 in 50% of the pseudo-replicates. Note that the quantiles and central tendencies can be modified via the conc.quantiles option. 4.9 Disparity from other matrices In the example so far, disparity was measured from an ordinated multidimensional space (i.e. a PCO of the distances between taxa based on discrete morphological characters). This is a common approach in palaeobiology, morphometrics or ecology but ordinated matrices are not mandatory for the dispRity package! It is totally possible to perform the same analysis detailed above using other types of matrices as long as your elements are rows in your matrix. For example, we can use the data set eurodist, an R inbuilt dataset that contains the distances (in km) between European cities. We can check for example, if Northern European cities are closer to each other than Southern ones: ## Making the eurodist data set into a matrix (rather than "dist" object) eurodist <- as.matrix(eurodist) eurodist[1:5, 1:5] ## Athens Barcelona Brussels Calais Cherbourg ## Athens 0 3313 2963 3175 3339 ## Barcelona 3313 0 1318 1326 1294 ## Brussels 2963 1318 0 204 583 ## Calais 3175 1326 204 0 460 ## Cherbourg 3339 1294 583 460 0 ## The two groups of cities Northern <- c("Brussels", "Calais", "Cherbourg", "Cologne", "Copenhagen", "Hamburg", "Hook of Holland", "Paris", "Stockholm") Southern <- c("Athens", "Barcelona", "Geneva", "Gibraltar", "Lisbon", "Lyons", "Madrid", "Marseilles", "Milan", "Munich", "Rome", "Vienna") ## Creating the subset dispRity object eurodist_subsets <- custom.subsets(eurodist, group = list("Northern" = Northern, "Southern" = Southern)) ## Warning: custom.subsets is applied on what seems to be a distance matrix. ## The resulting matrices won't be distance matrices anymore! ## You can use dist.data = TRUE, if you want to keep the data as a distance matrix. ## Bootstrapping and rarefying to 9 elements (the number of Northern cities) eurodist_bs <- boot.matrix(eurodist_subsets, rarefaction = 9) ## Measuring disparity as the median distance from group's centroid euro_disp <- dispRity(eurodist_bs, metric = c(median, centroids)) ## Testing the differences using a simple wilcox.test euro_diff <- test.dispRity(euro_disp, test = wilcox.test) euro_diff_rar <- test.dispRity(euro_disp, test = wilcox.test, rarefaction = 9) We can compare this approach to an ordination one: ## Ordinating the eurodist matrix (with 11 dimensions) euro_ord <- cmdscale(eurodist, k = 11) ## Calculating disparity on the bootstrapped and rarefied subset data euro_ord_disp <- dispRity(boot.matrix(custom.subsets(euro_ord, group = list("Northern" = Northern, "Southern" = Southern)), rarefaction = 9), metric = c(median, centroids)) ## Testing the differences using a simple wilcox.test euro_ord_diff <- test.dispRity(euro_ord_disp, test = wilcox.test) euro_ord_diff_rar <- test.dispRity(euro_ord_disp, test = wilcox.test, rarefaction = 9) And visualise the differences: ## Plotting the differences par(mfrow = c(2,2), bty = "n") ## Plotting the normal disparity plot(euro_disp, main = "Distance differences") ## Adding the p-value text(1.5, 4000, paste0("p=",round(euro_diff[[2]][[1]], digit = 5))) ## Plotting the rarefied disparity plot(euro_disp, rarefaction = 9, main = "Distance differences (rarefied)") ## Adding the p-value text(1.5, 4000, paste0("p=",round(euro_diff_rar[[2]][[1]], digit = 5))) ## Plotting the ordinated disparity plot(euro_ord_disp, main = "Ordinated differences") ## Adding the p-value text(1.5, 1400, paste0("p=",round(euro_ord_diff[[2]][[1]], digit = 5) )) ## Plotting the rarefied disparity plot(euro_ord_disp, rarefaction = 9, main = "Ordinated differences (rarefied)") ## Adding the p-value text(1.5, 1400, paste0("p=",round(euro_ord_diff_rar[[2]][[1]], digit = 5) )) As expected, the results are pretty similar in pattern but different in terms of scale. The median centroids distance is expressed in km in the “Distance differences” plots and in Euclidean units of variation in the “Ordinated differences” plots. 4.10 Disparity from multiple matrices (and multiple trees!) Since the version 1.4 of this package, it is possible to use multiple trees and multiple matrices in dispRity objects. To use multiple matrices, this is rather easy: just supply a list of matrices to any of the dispRity functions and, as long as they have the same size and the same rownames they will be handled as a distribution of matrices. set.seed(1) ## Creating 3 matrices with 4 dimensions and 10 elements each (called t1, t2, t3, etc...) matrix_list <- replicate(3, matrix(rnorm(40), 10, 4, dimnames = list(paste0("t", 1:10))), simplify = FALSE) class(matrix_list) # This is a list of matrices ## [1] "list" ## Measuring some disparity metric on one of the matrices summary(dispRity(matrix_list[[1]], metric = c(sum, variances))) ## subsets n obs ## 1 1 10 3.32 ## Measuring the same disparity metric on the three matrices summary(dispRity(matrix_list, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 1 10 3.32 3.044 3.175 3.381 3.435 As you can see, when measuring the sum of variances on multiple matrices, we now have a distribution of sum of variances rather than a single observed value. Similarly as running disparity analysis using multiple matrices, you can run the chrono.subsets function using multiple trees. This can be useful if you want to use a tree posterior distribution rather than a single consensus tree. These trees can be passed to chrono.subsets as a \"multiPhylo\" object (with the same node and tip labels in each tree). First let’s define a function to generate multiple trees with the same labels and root ages: set.seed(1) ## Matches the trees and the matrices ## A bunch of trees make.tree <- function(n, fun = rtree) { ## Make the tree tree <- fun(n) tree <- chronos(tree, quiet = TRUE, calibration = makeChronosCalib(tree, age.min = 10, age.max = 10)) class(tree) <- "phylo" ## Add the node labels tree$node.label <- paste0("n", 1:Nnode(tree)) ## Add the root time tree$root.time <- max(tree.age(tree)$ages) return(tree) } trees <- replicate(3, make.tree(10), simplify = FALSE) class(trees) <- "multiPhylo" trees ## 3 phylogenetic trees We can now simulate some ancestral states for the matrices in the example above to have multiple matrices associated with the multiple trees. ## A function for running the ancestral states estimations do.ace <- function(tree, matrix) { ## Run one ace fun.ace <- function(character, tree) { results <- ace(character, phy = tree)$ace names(results) <- paste0("n", 1:Nnode(tree)) return(results) } ## Run all ace return(rbind(matrix, apply(matrix, 2, fun.ace, tree = tree))) } ## All matrices matrices <- mapply(do.ace, trees, matrix_list, SIMPLIFY = FALSE) Let’s first see an example of time-slicing with one matrix and multiple trees. This assumes that your tip values (observed) and node values (estimated) are fixed with no error on them. It also assumes that the nodes in the matrix always corresponds to the node in the trees (in other words, the tree topologies are fixed): ## Making three "proximity" time slices across one tree one_tree <- chrono.subsets(matrices[[1]], trees[[1]], method = "continuous", model = "proximity", time = 3) ## Making three "proximity" time slices across the three trees three_tree <- chrono.subsets(matrices[[1]], trees, method = "continuous", model = "proximity", time = 3) ## Measuring disparity as the sum of variances and summarising it summary(dispRity(one_tree, metric = c(sum, variances))) ## subsets n obs ## 1 8.3 3 0.079 ## 2 4.15 5 2.905 ## 3 0 10 3.320 summary(dispRity(three_tree, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 7.9 3 0.253 0.088 0.166 0.309 0.360 ## 2 3.95 5 0.257 0.133 0.192 1.581 2.773 ## 3 0 10 3.320 3.320 3.320 3.320 3.320 This results show the effect of considering a tree distribution: in the first case (one_tree) the time slice at 3.95 Mya has a sum of variances of 2.9 but this values goes down to 0.256 in the second case (three_tree) which is due to the differences in branch lengths distributions: par(mfrow = c(3,1)) slices <- c(7.9, 3.95, 0) fun.plot <- function(tree) { plot(tree) nodelabels(tree$node.label, cex = 0.8) axisPhylo() abline(v = tree$root.time - slices) } silent <- lapply(trees, fun.plot) Note that in this example, the nodes are actually even different in each tree! The node n4 for example, is not direct descendent of t4 and t6 in all trees! To fix that, it is possible to input a list of trees and a list of matrices that correspond to each tree in chrono.subsets by using the bind.data = TRUE option. In this case, the matrices need to all have the same row names and the trees all need the same labels as before: ## Making three "proximity" time slices across three trees and three bound matrices bound_data <- chrono.subsets(matrices, trees, method = "continuous", model = "proximity", time = 3, bind.data = TRUE) ## Making three "proximity" time slices across three trees and three matrices unbound_data <- chrono.subsets(matrices, trees, method = "continuous", model = "proximity", time = 3, bind.data = FALSE) ## Measuring disparity as the sum of variances and summarising it summary(dispRity(bound_data, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 7.9 3 0.079 0.076 0.077 0.273 0.447 ## 2 3.95 5 1.790 0.354 1.034 2.348 2.850 ## 3 0 10 3.320 3.044 3.175 3.381 3.435 summary(dispRity(unbound_data, metric = c(sum, variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 7.9 3 0.79 0.48 0.63 0.83 0.85 ## 2 3.95 5 3.25 1.36 2.25 3.94 4.56 ## 3 0 10 9.79 9.79 9.79 9.79 9.79 Note here that the results are again rather different: with the bound data, the slices are done across the three trees and each of their corresponding matrix (resulting in three observation) which is more accurate than the previous results from three_trees above. With the unbound data, the slices are done across the three trees and applied to the three matrices (resulting in 9 observations). As we’ve seen before, this is incorrect in this case since the trees don’t have the same topology (so the nodes selected by a slice through the second tree are not equivalent to the nodes in the first matrix) but it can be useful if the topology is fixed to integrate both uncertainty in branch length (slicing through different trees) and uncertainty from, say, ancestral states estimations (applying the slices on different matrices). Note that since the version 1.8 the trees and the matrices don’t have to match allowing to run disparity analyses with variable matrices and trees. This can be useful when running ancestral states estimations from a tree distribution where not all trees have the same topology. 4.11 Disparity with trees: dispRitree! Since the package’s version 1.5.10, trees can be directly attached to dispRity objects. This allows any function in the package that has an input argument called “tree” to automatically intake the tree from the dispRity object. This is especially useful for disparity metrics that requires calculations based on a phylogenetic tree (e.g. ancestral.dist or projections.tree) and if phylogeny (or phylogenie*s*) are going to be an important part of your analyses. Trees are attached to dispRity object as soon as they are called in any function of the package (e.g. as an argument in chrono.subsets or in dispRity) and are stored in my_dispRity_object$tree. You can always manually attach, detach or modify the tree parts of a dispRity object using the utility functions get.tree (to access the trees), remove.tree (to remove it) and add.tree (to… add trees!). The only requirement for this to work is that the labels in the tree must match the ones in the data. If the tree has node labels, their node labels must also match the data. Similarly if the data has entries for node labels, they must be present in the tree. Here is a quick demo on how attaching trees to dispRity objects can work and make your life easy: for example here we will measure how the sum of branch length changes through time when time slicing through some demo data with a acctran split time slice model (see more info here). ## Loading some demo data: ## An ordinated matrix with node and tip labels data(BeckLee_mat99) ## The corresponding tree with tip and node labels data(BeckLee_tree) ## A list of tips ages for the fossil data data(BeckLee_ages) ## Time slicing through the tree using the equal split algorithm time_slices <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, FADLAD = BeckLee_ages, method = "continuous", model = "acctran", time = 15) ## We can visualise the resulting trait space with the phylogeny ## (using the specific argument as follows) plot(time_slices, type = "preview", specific.args = list(tree = TRUE)) ## Note that some nodes are never selected thus explaining the branches not reaching them. And we can then measure disparity as the sum of the edge length at each time slice on the bootstrapped data: ## Measuring the sum of the edge length per slice sum_edge_length <- dispRity(boot.matrix(time_slices), metric = c(sum, edge.length.tree)) ## Summarising and plotting summary(sum_edge_length) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 133.51 3 51 51 36 40 61 69 ## 2 123.97 6 163 166 141 158 172 188 ## 3 114.44 9 332 331 287 317 354 383 ## 4 104.9 12 558 565 489 540 587 620 ## 5 95.37 15 762 763 723 745 782 815 ## 6 85.83 20 1303 1305 1218 1271 1342 1415 ## 7 76.29 19 1565 1559 1408 1491 1620 1802 ## 8 66.76 23 2055 2040 1865 1965 2095 2262 ## 9 57.22 20 2029 2031 1842 1949 2091 2190 ## 10 47.68 16 1908 1892 1727 1840 1945 2057 ## 11 38.15 16 2017 2016 1910 1975 2081 2152 ## 12 28.61 10 1391 1391 1391 1391 1391 1391 ## 13 19.07 10 1391 1391 1391 1391 1391 1391 ## 14 9.54 10 1391 1391 1391 1391 1391 1391 ## 15 0 10 1391 1391 1391 1391 1391 1391 plot(sum_edge_length) Of course this can be done with multiple trees and be combined with an approach using multiple matrices (see here)! 4.12 Disparity of variance-covariance matrices (covar) Variance-covariance matrices are sometimes a useful way to summarise multidimensional data. In fact, you can express the variation in your multidimensional dataset directly in terms of how your trait covary rather than simply the positions of your elements in the trait space. Furthermore, variance-covariance matrices can be estimated from multidimensional in sometimes more useful ways that simply looking at the the data in your trait space. This can be done by describing your data as hierarchical models like generalised linear mixed effect models (glmm). For example, you might have a multidimensional dataset where your observations have a nested structure (e.g. they are part of the same phylogeny). You can then analyse this data using a glmm with something like my_data ~ observations + phylogeny + redisduals. For more info on these models start here. For more details on running these models, I suggest using the MCMCglmm package (Hadfield (2010a)) from Hadfield (2010b) (but see also Thomas Guillerme and Healy (2014)). For an example use of this code, see Thomas Guillerme et al. (2023). 4.12.1 Creating a dispRity object with a $covar component Once you have a trait space and variance-covariance matrices output from the MCMCglmm model, you can use the function MCMCglmm.subsets to create a \"dispRity\" object that contains the classic \"dispRity\" data (the matrix, the subsets, etc…) but also a the new $covar element: ## Loading the charadriiformes data data(charadriiformes) Here we using precaculated variance-covariance matrices from the charadriiformes dataset that contains a set of posteriors from a MCMCglmm model. The model here was data ~ traits + clade specific phylogenetic effect + global phylogenetic effect + residuals. We can retrieve the model information using the MCMCglmm utilities tools, namely the MCMCglmm.levels function to directly extract the terms names as used in the model and then build our \"dispRity\" object with the correct data, the posteriors and the correct term names: ## The term names model_terms <- MCMCglmm.levels(charadriiformes$posteriors)[1:4] ## Note that we're ignoring the 5th term of the model that's just the normal residuals ## The dispRity object MCMCglmm.subsets(data = charadriiformes$data, posteriors = charadriiformes$posteriors, group = model_terms) ## ---- dispRity object ---- ## 4 covar subsets for 359 elements in one matrix with 3 dimensions: ## animal:clade_1, animal:clade_2, animal:clade_3, animal. ## Data is based on 1000 posterior samples. As you can see this creates a normal dispRity object with the information you are now familiar with. However, we can be more fancy and provide more understandable names for the groups and provide the underlying phylogenetic structure used: ## A fancier dispRity object my_covar <- MCMCglmm.subsets(data = charadriiformes$data, posteriors = charadriiformes$posteriors, group = model_terms, tree = charadriiformes$tree, rename.groups = c(levels(charadriiformes$data$clade), "phylogeny")) ## Note that the group names is contained in the clade column of the charadriiformes dataset as factors 4.12.2 Visualising covar objects One useful thing to do with these objects is then to visualise them in 2D. Here we can use the covar.plot function (that has many different options that just plot.dispRity for plotting covar objects) to plot the trait space, the 95% confidence interval ellipses of the variance-covariance matrices and the major axes from these ellipses. See the ?covar.plot help page for all the options available: par(mfrow = c(2,2)) ## The traitspace covar.plot(my_covar, col = c("orange", "darkgreen", "blue"), main = "Trait space") ## The traitspace's variance-covariance mean ellipses covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean VCV ellipses", points = FALSE, ellipses = mean) ## The traitspace's variance-covariance mean ellipses covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Mean major axes", points = FALSE, major.axes = mean) ## A bit of everything covar.plot(my_covar, col = c("orange", "darkgreen", "blue", "grey"), main = "Ten random VCV matrices", points = TRUE, major.axes = TRUE, points.cex = 1/3, n = 10, ellipses = TRUE, legend = TRUE) 4.12.3 Disparity analyses with a $covar component You can then calculate disparity on the \"dispRity\" object like shown previously. For example, you can get the variances of the groups that where used in the model by using the normal dispRity function: summary(dispRity(my_covar, metric = variances)) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 gulls 159 0.009 0.009 0.009 0.129 0.238 ## 2 plovers 98 0.008 0.003 0.005 0.173 0.321 ## 3 sandpipers 102 0.007 0.003 0.005 0.177 0.331 ## 4 phylogeny 359 0.023 0.007 0.015 0.166 0.294 However this is not applied on the variance-covariance matrices from the posteriors of the MCMCglmm. To do that, you need to modify the metric to be recognised as a “covar” metric using the as.covar function. This function transforms any disparity metric (or disparity metric style function) to be applied to the $covar part of a \"dispRity\" object. Basically this $covar part is a list containing, for each posterior sample $VCV, the variance-covariance matrix and $loc, it’s optional location in the traitspace. ## The first variance covariance matrix for the "gulls" group my_covar$covar[["gulls"]][[1]] ## $VCV ## [,1] [,2] [,3] ## [1,] 0.23258067 -2.180519e-02 -2.837630e-02 ## [2,] -0.02180519 3.137106e-02 -8.711996e-05 ## [3,] -0.02837630 -8.711996e-05 1.943929e-02 ## ## $loc ## [1] 0.0007118691 0.1338917465 -0.0145412698 And this is how as.covar modifies the disparity metric: ## Using the variances function on a VCV matrix variances(my_covar$covar[["gulls"]][[1]]$VCV) ## [1] 0.0221423147 0.0007148342 0.0005779815 ## The same but using it as a covar metric as.covar(variances)(my_covar$covar[["gulls"]][[1]]) ## [1] 0.0221423147 0.0007148342 0.0005779815 ## The same but applied to the dispRity function summary(dispRity(my_covar, metric = as.covar(variances))) ## subsets n obs.median 2.5% 25% 75% 97.5% ## 1 gulls 159 0.001 0 0 0.012 0.068 ## 2 plovers 98 0.000 0 0 0.000 0.002 ## 3 sandpipers 102 0.000 0 0 0.000 0.016 ## 4 phylogeny 359 0.000 0 0 0.006 0.020 4.13 Disparity and distances There are two ways to use distances in dispRity, either with your input data being directly a distance matrix or with your disparity metric involving some kind of distance calculations. 4.13.1 Disparity data is a distance If your disparity data is a distance matrix, you can use the option dist.data = TRUE in dispRity to make sure that all the operations done on your data take into account the fact that your disparity data has distance properties. For example, if you bootstrap the data, this will automatically bootstrap both rows AND columns (i.e. so that the bootstrapped matrices are still distances). This also improves speed on some calculations if you use disparity metrics directly implemented in the package by avoiding recalculating distances (the full list can be seen in ?dispRity.metric - they are usually the metrics with dist in their name). 4.13.1.1 Subsets By default, the dispRity package does not treat any matrix as a distance matrix. It will however try to guess whether your input data is a distance matrix or not. This means that if you input a distance matrix, you might get a warning letting you know the input matrix might not be treated correctly (e.g. when bootstrapping or subsetting). For the functions dispRity, custom.subsets and chrono.subsets you can simply toggle the option dist.data = TRUE to make sure you treat your input data as a distance matrix throughout your analysis. ## Creating a distance matrix distance_data <- as.matrix(dist(BeckLee_mat50)) ## Measuring the diagonal of the distance matrix dispRity(distance_data, metric = diag, dist.data = TRUE) ## ---- dispRity object ---- ## 50 elements in one matrix with 50 dimensions. ## Disparity was calculated as: diag. If you use a pipeline of any of these functions, you only need to specify it once and the data will be treated as a distance matrix throughout. ## Creating a distance matrix distance_data <- as.matrix(dist(BeckLee_mat50)) ## Creating two subsets specifying that the data is a distance matrix subsets <- custom.subsets(distance_data, group = list(c(1:5), c(6:10)), dist.data = TRUE) ## Measuring disparity treating the data as distance matrices dispRity(subsets, metric = diag) ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 50 dimensions: ## 1, 2. ## Disparity was calculated as: diag. ## Measuring disparity treating the data as a normal matrix (toggling the option to FALSE) dispRity(subsets, metric = diag, dist.data = FALSE) ## Warning in dispRity(subsets, metric = diag, dist.data = FALSE): data.dist is ## set to FALSE (the data will not be treated as a distance matrix) even though ## subsets contains distance treated data. ## ---- dispRity object ---- ## 2 customised subsets for 50 elements in one matrix with 50 dimensions: ## 1, 2. ## Disparity was calculated as: diag. ## Note that a warning appears but the function still runs 4.13.1.2 Bootstrapping The function boot.matrix also can deal with distance matrices by bootstrapping both rows and columns in a linked way (e.g. if a bootstrap pseudo-replicate draws the values 1, 2, and 5, it will select both columns 1, 2, and 5 and rows 1, 2, and 5 - keeping the distance structure of the data). You can do that by using the boot.by = \"dist\" function that will bootstrap the data in a distance matrix fashion: ## Measuring the diagonal of a bootstrapped matrix boot.matrix(distance_data, boot.by = "dist") ## ---- dispRity object ---- ## 50 elements in one matrix with 50 dimensions. ## Rows and columns were bootstrapped 100 times (method:"full"). Similarly to the dispRity, custom.subsets and chrono.subsets function above, the option to treat the input data as a distance matrix is recorded and recycled so there is no need to specify it each time. 4.13.2 Disparity metric is a distance On the other hand if your data is not a distance matrix but you are using a metric that uses some kind of distance calculations, you can use the option dist.helper to greatly speed up calculations. dist.helper can be either a pre-calculated distance matrix (or a list of distance matrices) or, better yet, a function to calculate distance matrices, like stats::dist or vegan::vegdist. This option directly stores the distance matrix separately in the RAM and allows the disparity metric to directly access it at every disparity calculation iteration, making it much faster. Note that if you provide a function for dist.helper, you can also provide any un-ambiguous optional argument to that function, for example method = \"euclidean\". If you use a disparity metric implemented in dispRity, the dist.helper option is correctly loaded onto the RAM regardless of the argument you provide (a matrix, a list of matrix or any function to calculate a distance matrix). On the other hand, if you use your own function for the disparity metric, make sure that dist.helper exactly matches the internal distance calculation function. For example if you use the already implemented pairwise.dist metric all the following options will be using dist.helper optimally: ## Using the dist function from stats (specifying it comes from stats) dispRity(my_data, metric = pairwise.dist, dist.helper = stats::dist) ## Using the dist function from vegdist function (without specifying its origin) dispRity(my_data, metric = pairwise.dist, dist.helper = vegdist) ## Using some pre-calculated distance with a generic function my_distance_matrix <- dist(my_distance_data) dispRity(my_data, metric = pairwise.dist, dist.helper = my_distance_matrix) ## Using some pre-calculated distance with a user function defined elsewhere my_distance_matrix <- my.personalised.function(my_distance_data) dispRity(my_data, metric = pairwise.dist, dist.helper = my_distance_matrix) However, if you use a homemade metric for calculating distances like this: ## a personalised distance function my.sum.of.dist <- function(matrix) { return(sum(dist(matrix))) } The dist.helper will only work if you specify the function using the same syntax as in the user function: ## The following uses the helper correctly (as in saves a lot of calculation time) dispRity(my_data, metric = my.sum.of.dist, dist.helper = dist) ## These ones however, work but don't use the dist.helper (don't save time) ## The dist.helper is not a function dispRity(my_data, metric = my.sum.of.dist, dist.helper = dist(my_data)) ## The dist.helper is not the correct function (should be dist) dispRity(my_data, metric = my.sum.of.dist, dist.helper = vegdist) ## The dist.helper is not the correct function (should be just dist) dispRity(my_data, metric = my.sum.of.dist, dist.helper = stats::dist) References "],["making-stuff-up.html", "5 Making stuff up! 5.1 Simulating discrete morphological data 5.2 Simulating multidimensional spaces", " 5 Making stuff up! The dispRity package also offers some advanced data simulation features to allow to test hypothesis, explore ordinate-spaces or metrics properties or simply playing around with data! All the following functions are based on the same modular architecture of the package and therefore can be used with most of the functions of the package. 5.1 Simulating discrete morphological data The function sim.morpho allows to simulate discrete morphological data matrices (sometimes referred to as “cladistic” matrices). It allows to evolve multiple discrete characters on a given phylogenetic trees, given different models, rates, and states. It even allows to include “proper” inapplicable data to make datasets as messy as in real life! In brief, the function sim.morpho takes a phylogenetic tree, the number of required characters, the evolutionary model, and a function from which to draw the rates. The package also contains a function for quickly checking the matrix’s phylogenetic signal (as defined in systematics not phylogenetic comparative methods) using parsimony. The methods are described in details below set.seed(3) ## Simulating a starting tree with 15 taxa as a random coalescent tree my_tree <- rcoal(15) ## Generating a matrix with 100 characters (85% binary and 15% three state) and ## an equal rates model with a gamma rate distribution (0.5, 1) with no ## invariant characters. my_matrix <- sim.morpho(tree = my_tree, characters = 100, states = c(0.85, 0.15), rates = c(rgamma, 0.5, 1), invariant = FALSE) ## The first few lines of the matrix my_matrix[1:5, 1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## t10 "1" "0" "1" "0" "1" "0" "0" "1" "0" "0" ## t1 "0" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## t9 "0" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## t14 "1" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## t13 "1" "0" "1" "0" "0" "0" "0" "1" "0" "0" ## Checking the matrix properties with a quick Maximum Parsimony tree search check.morpho(my_matrix, my_tree) ## ## Maximum parsimony 144.0000000 ## Consistency index 0.7430556 ## Retention index 0.9160998 ## Robinson-Foulds distance 2.0000000 Note that this example produces a tree with a great consistency index and an identical topology to the random coalescent tree! Nearly too good to be true… 5.1.1 A more detailed description The protocol implemented here to generate discrete morphological matrices is based on the ones developed in (Thomas Guillerme and Cooper 2016; O’Reilly et al. 2016; Puttick et al. 2017; E. et al., n.d.). The first tree argument will be the tree on which to “evolve” the characters and therefore requires branch length. You can generate quick and easy random Yule trees using ape::rtree(number_of_taxa) but I would advise to use more realistic trees for more realistic simulations based on more realistic models (really realistic then) using the function tree.bd from the diversitree package (FitzJohn 2012). The second argument, character is the number of characters. Pretty straight forward. The third, states is the proportion of characters states above two (yes, the minimum number of states is two). This argument intakes the proportion of n-states characters, for example states = c(0.5,0.3,0.2) will generate 50% of binary-state characters, 30% of three-state characters and 20% of four-state characters. There is no limit in the number of state characters proportion as long as the total makes up 100%. The forth, model is the evolutionary model for generating the character(s). More about this below. The fifth and sixth, rates and substitution are the model parameters described below as well. Finally, the two logical arguments, are self explanatory: invariant whether to allow invariant characters (i.e. characters that don’t change) and verbose whether to print the simulation progress on your console. 5.1.1.1 Available evolutionary models There are currently three evolutionary models implemented in sim.morpho but more will come in the future. Note also that they allow fine tuning parameters making them pretty plastic! \"ER\": this model allows any number of character states and is based on the Mk model (Lewis 2001). It assumes a unique overall evolutionary rate equal substitution rate between character states. This model is based on the ape::rTraitDisc function. \"HKY\": this is binary state character model based on the molecular HKY model (Hasegawa, Kishino, and Yano 1985). It uses the four molecular states (A,C,G,T) with a unique overall evolutionary rate and a biased substitution rate towards transitions (A <-> G or C <-> T) against transvertions (A <-> C and G <-> T). After evolving the nucleotide, this model transforms them into binary states by converting the purines (A and G) into state 0 and the pyrimidines (C and T) into state 1. This method is based on the phyclust::seq.gen.HKY function and was first proposed by O’Reilly et al. (2016). \"MIXED\": this model uses a random (uniform) mix between both the \"ER\" and the \"HKY\" models. The models can take the following parameters: (1) rates is the evolutionary rate (i.e. the rate of changes along a branch: the evolutionary speed) and (2) substitution is the frequency of changes between one state or another. For example if a character can have high probability of changing (the evolutionary rate) with, each time a change occurs a probability of changing from state X to state Y (the substitution rate). Note that in the \"ER\" model, the substitution rate is ignore because… by definition this (substitution) rate is equal! The parameters arguments rates and substitution takes a distributions from which to draw the parameters values for each character. For example, if you want an \"HKY\" model with an evolutionary rate (i.e. speed) drawn from a uniform distribution bounded between 0.001 and 0.005, you can define it as rates = c(runif, min = 0.001, max = 0.005), runif being the function for random draws from a uniform distribution and max and min being the distribution parameters. These distributions should always be passed in the format c(random_distribution_function, distribution_parameters) with the names of the distribution parameters arguments. 5.1.1.2 Checking the results An additional function, check.morpho runs a quick Maximum Parsimony tree search using the phangorn parsimony algorithm. It quickly calculates the parsimony score, the consistency and retention indices and, if a tree is provided (e.g. the tree used to generate the matrix) it calculates the Robinson-Foulds distance between the most parsimonious tree and the provided tree to determine how different they are. 5.1.1.3 Adding inapplicable characters Once a matrix is generated, it is possible to apply inapplicable characters to it for increasing realism! Inapplicable characters are commonly designated as NA or simply -. They differ from missing characters ? in their nature by being inapplicable rather than unknown(see Brazeau, Guillerme, and Smith 2018 for more details). For example, considering a binary character defined as “colour of the tail” with the following states “blue” and “red”; on a taxa with no tail, the character should be coded as inapplicable (“-”) since the state of the character “colour of tail” is known: it’s neither “blue” or “red”, it’s just not there! It contrasts with coding it as missing (“?” - also called as ambiguous) where the state is unknown, for example, the taxon of interest is a fossil where the tail has no colour preserved or is not present at all due to bad conservation! This type of characters can be added to the simulated matrices using the apply.NA function/ It takes, as arguments, the matrix, the source of inapplicability (NAs - more below), the tree used to generate the matrix and the two same invariant and verbose arguments as defined above. The NAs argument allows two types of sources of inapplicability: \"character\" where the inapplicability is due to the character (e.g. coding a character tail for species with no tail). In practice, the algorithm chooses a character X as the underlying character (e.g. “presence and absence of tail”), arbitrarily chooses one of the states as “absent” (e.g. 0 = absent) and changes in the next character Y any state next to character X state 0 into an inapplicable token (“-”). This simulates the inapplicability induced by coding the characters (i.e. not always biological). \"clade\" where the inapplicability is due to evolutionary history (e.g. a clade loosing its tail). In practice, the algorithm chooses a random clade in the tree and a random character Z and replaces the state of the taxa present in the clade by the inapplicable token (“-”). This simulates the inapplicability induced by evolutionary biology (e.g. the lose of a feature in a clade). To apply these sources of inapplicability, simply repeat the number of inapplicable sources for the desired number of characters with inapplicable data. ## Generating 5 "character" NAs and 10 "clade" NAs my_matrix_NA <- apply.NA(my_matrix, tree = my_tree, NAs = c(rep("character", 5), rep("clade", 10))) ## The first few lines of the resulting matrix my_matrix_NA[1:10, 90:100] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] ## t10 "-" "1" "1" "2" "1" "0" "0" "0" "1" "0" "0" ## t1 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t9 "-" "1" "1" "0" "1" "0" "0" "0" "-" "0" "0" ## t14 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t13 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t5 "-" "1" "0" "0" "1" "0" "0" "0" "-" "0" "0" ## t2 "1" "1" "0" "0" "1" "0" "0" "0" "0" "0" "0" ## t8 "2" "1" "0" "0" "1" "0" "0" "0" "0" "0" "0" ## t6 "-" "1" "1" "0" "0" "1" "1" "2" "0" "1" "1" ## t15 "-" "1" "1" "0" "0" "1" "1" "2" "0" "1" "1" 5.1.2 Parameters for a realistic(ish) matrix There are many parameters that can create a “realistic” matrix (i.e. not too different from the input tree with a consistency and retention index close to what is seen in the literature) but because of the randomness of the matrix generation not all parameters combination end up creating “good” matrices. The following parameters however, seem to generate fairly “realist” matrices with a starting coalescent tree, equal rates model with 0.85 binary characters and 0.15 three state characters, a gamma distribution with a shape parameter (\\(\\alpha\\)) of 5 and no scaling (\\(\\beta\\) = 1) with a rate of 100. set.seed(0) ## tree my_tree <- rcoal(15) ## matrix morpho_mat <- sim.morpho(my_tree, characters = 100, model = "ER", rates = c(rgamma, rate = 100, shape = 5), invariant = FALSE) check.morpho(morpho_mat, my_tree) ## ## Maximum parsimony 103.0000000 ## Consistency index 0.9708738 ## Retention index 0.9919571 ## Robinson-Foulds distance 4.0000000 5.2 Simulating multidimensional spaces Another way to simulate data is to directly simulate an ordinated space with the space.maker function. This function allows users to simulate multidimensional spaces with a certain number of properties. For example, it is possible to design a multidimensional space with a specific distribution on each axis, a correlation between the axes and a specific cumulative variance per axis. This can be useful for creating ordinated spaces for null hypothesis, for example if you’re using the function null.test (Dı́az et al. 2016). This function takes as arguments the number of elements (data points - elements argument) and dimensions (dimensions argument) to create the space and the distribution functions to be used for each axis. The distributions are passed through the distribution argument as… modular functions! You can either pass a single distribution function for all the axes (for example distribution = runif for all the axis being uniform) or a specific distribution function for each specific axis (for example distribution = c(runif, rnorm, rgamma)) for the first axis being uniform, the second normal and the third gamma). You can of course use your very own functions or use the ones implemented in dispRity for more complex ones (see below). Specific optional arguments for each of these distributions can be passed as a list via the arguments argument. Furthermore, it is possible to add a correlation matrix to add a correlation between the axis via the cor.matrix argument or even a vector of proportion of variance to be bear by each axis via the scree argument to simulate realistic ordinated spaces. Here is a simple two dimensional example: ## Graphical options op <- par(bty = "n") ## A square space square_space <- space.maker(100, 2, runif) ## The resulting 2D matrix head(square_space) ## [,1] [,2] ## [1,] 0.2878797 0.82110157 ## [2,] 0.5989886 0.72890558 ## [3,] 0.8401571 0.53042419 ## [4,] 0.3663870 0.75545936 ## [5,] 0.2122375 0.98768804 ## [6,] 0.9612441 0.07285561 ## Visualising the space plot(square_space, pch = 20, xlab = "", ylab = "", main = "Uniform 2D space") Of course, more complex spaces can be created by changing the distributions, their arguments or adding a correlation matrix or a cumulative variance vector: ## A plane space: uniform with one dimensions equal to 0 plane_space <- space.maker(2500, 3, c(runif, runif, runif), arguments = list(list(min = 0, max = 0), NULL, NULL)) ## Correlation matrix for a 3D space (cor_matrix <- matrix(cbind(1, 0.8, 0.2, 0.8, 1, 0.7, 0.2, 0.7, 1), nrow = 3)) ## [,1] [,2] [,3] ## [1,] 1.0 0.8 0.2 ## [2,] 0.8 1.0 0.7 ## [3,] 0.2 0.7 1.0 ## An ellipsoid space (normal space with correlation) ellipse_space <- space.maker(2500, 3, rnorm, cor.matrix = cor_matrix) ## A cylindrical space with decreasing axes variance cylindrical_space <- space.maker(2500, 3, c(rnorm, rnorm, runif), scree = c(0.7, 0.2, 0.1)) 5.2.1 Personalised dimensions distributions Following the modular architecture of the package, it is of course possible to pass home made distribution functions to the distribution argument. For example, the random.circle function is a personalised one implemented in dispRity. This function allows to create circles based on basic trigonometry allowing to axis to covary to produce circle coordinates. By default, this function generates two sets of coordinates with a distribution argument and a minimum and maximum boundary (inner and outer respectively) to create nice sharp edges to the circle. The maximum boundary is equivalent to the radius of the circle (it removes coordinates beyond the circle radius) and the minimum is equivalent to the radius of a smaller circle with no data (it removes coordinates below this inner circle radius). ## Graphical options op <- par(bty = "n") ## Generating coordinates for a normal circle with a upper boundary of 1 circle <- random.circle(1000, rnorm, inner = 0, outer = 1) ## Plotting the circle plot(circle, xlab = "x", ylab = "y", main = "A normal circle") ## Creating doughnut space (a spherical space with a hole) doughnut_space <- space.maker(5000, 3, c(rnorm, random.circle), arguments = list(list(mean = 0), list(runif, inner = 0.5, outer = 1))) 5.2.2 Visualising the space I suggest using the excellent scatterplot3d package to play around and visualise the simulated spaces: ## Graphical options op <- par(mfrow = (c(2, 2)), bty = "n") ## Visualising 3D spaces require(scatterplot3d) ## Loading required package: scatterplot3d ## The plane space scatterplot3d(plane_space, pch = 20, xlab = "", ylab = "", zlab = "", xlim = c(-0.5, 0.5), main = "Plane space") ## The ellipsoid space scatterplot3d(ellipse_space, pch = 20, xlab = "", ylab = "", zlab = "", main = "Normal ellipsoid space") ## A cylindrical space with a decreasing variance per axis scatterplot3d(cylindrical_space, pch = 20, xlab = "", ylab = "", zlab = "", main = "Normal cylindrical space") ## Axes have different orders of magnitude ## Plotting the doughnut space scatterplot3d(doughnut_space[,c(2,1,3)], pch = 20, xlab = "", ylab = "", zlab = "", main = "Doughnut space") par(op) 5.2.3 Generating realistic spaces It is possible to generate “realistic” spaces by simply extracting the parameters of an existing space and scaling it up to the simulated space. For example, we can extract the parameters of the BeckLee_mat50 ordinated space and simulate a similar space. ## Loading the data data(BeckLee_mat50) ## Number of dimensions obs_dim <- ncol(BeckLee_mat50) ## Observed correlation between the dimensions obs_correlations <- cor(BeckLee_mat50) ## Observed mean and standard deviation per axis obs_mu_sd_axis <- mapply(function(x,y) list("mean" = x, "sd" = y), as.list(apply(BeckLee_mat50, 2, mean)), as.list(apply(BeckLee_mat50, 2, sd)), SIMPLIFY = FALSE) ## Observed overall mean and standard deviation obs_mu_sd_glob <- list("mean" = mean(BeckLee_mat50), "sd" = sd(BeckLee_mat50)) ## Scaled observed variance per axis (scree plot) obs_scree <- variances(BeckLee_mat50)/sum(variances(BeckLee_mat50)) ## Generating our simulated space simulated_space <- space.maker(1000, dimensions = obs_dim, distribution = rep(list(rnorm), obs_dim), arguments = obs_mu_sd_axis, cor.matrix = obs_correlations) ## Visualising the fit of our data in the space (in the two first dimensions) plot(simulated_space[,1:2], xlab = "PC1", ylab = "PC2") points(BeckLee_mat50[,1:2], col = "red", pch = 20) legend("topleft", legend = c("observed", "simulated"), pch = c(20,21), col = c("red", "black")) It is now possible to simulate a space using these observed arguments to test several hypothesis: Is the space uniform or normal? If the space is normal, is the mean and variance global or specific for each axis? ## Measuring disparity as the sum of variance observed_disp <- dispRity(BeckLee_mat50, metric = c(median, centroids)) ## Is the space uniform? test_unif <- null.test(observed_disp, null.distrib = runif) ## Is the space normal with a mean of 0 and a sd of 1? test_norm1 <- null.test(observed_disp, null.distrib = rnorm) ## Is the space normal with the observed mean and sd and cumulative variance test_norm2 <- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim), null.args = rep(list(obs_mu_sd_glob), obs_dim), null.scree = obs_scree) ## Is the space multiple normal with multiple means and sds and a correlation? test_norm3 <- null.test(observed_disp, null.distrib = rep(list(rnorm), obs_dim), null.args = obs_mu_sd_axis, null.cor = obs_correlations) ## Graphical options op <- par(mfrow = (c(2, 2)), bty = "n") ## Plotting the results plot(test_unif, main = "Uniform (0,1)") plot(test_norm1, main = "Normal (0,1)") plot(test_norm2, main = paste0("Normal (", round(obs_mu_sd_glob[[1]], digit = 3), ",", round(obs_mu_sd_glob[[2]], digit = 3), ")")) plot(test_norm3, main = "Normal (variable + correlation)") If we measure disparity as the median distance from the morphospace centroid, we can explain the distribution of the data as normal with the variable observed mean and standard deviation and with a correlation between the dimensions. References "],["other-functionalities.html", "6 Other functionalities 6.1 char.diff 6.2 clean.data 6.3 crown.stem 6.4 get.bin.ages 6.5 match.tip.edge 6.6 MCMCglmm utilities 6.7 pair.plot 6.8 reduce.matrix 6.9 select.axes 6.10 set.root.time 6.11 slice.tree 6.12 slide.nodes and remove.zero.brlen 6.13 tree.age 6.14 multi.ace", " 6 Other functionalities The dispRity package also contains several other functions that are not specific to multidimensional analysis but that are often used by dispRity internal functions. However, we decided to make these functions also available at a user level since they can be handy for certain specific operations! You’ll find a brief description of each of them (alphabetically) here: 6.1 char.diff This is yet another function for calculating distance matrices. There are many functions for calculating pairwise distance matrices in R (stats::dist, vegan::vegdist, cluster::daisy or Claddis::calculate_morphological_distances) but this one is the dispRity one. It is slightly different to the ones mentioned above (though not that dissimilar from Claddis::calculate_morphological_distances) in the fact that it focuses on comparing discrete morphological characters and tries to solve all the problems linked to these kind of matrices (especially dealing with special tokens). The function intakes a matrix with either numeric or integer (NA included) or matrices with character that are indeed integers (e.g.\"0\" and \"1\"). It then uses a bitwise operations architecture implemented in C that renders the function pretty fast and pretty modular. This bitwise operations translates the character states into binary values. This way, 0 becomes 1, 1 becomes 2, 2 becomes 4, 3 becomes 8, etc… Specifically it can handle any rules specific to special tokens (i.e. symbols) for discrete morphological characters. For example, should you treat missing values \"?\" as NA (ignoring them) or as any possible character state (e.g. c(\"0\", \"1\")?)? And how to treat characters with a ampersand (\"&\")? char.diff can answer to all these questions! Let’s start by a basic binary matrix 4*3 with random integer: ## A random binary matrix matrix_binary <- matrix(sample(c(0,1), 12, replace = TRUE), ncol = 4, dimnames = list(letters[1:3], LETTERS[1:4])) By default, char.diff measures the hamming distance between characters: ## The hamming distance between characters (differences <- char.diff(matrix_binary)) ## A B C D ## A 0 0 1 1 ## B 0 0 1 1 ## C 1 1 0 0 ## D 1 1 0 0 ## attr(,"class") ## [1] "matrix" "char.diff" Note that the results is just a pairwise distance (dissimilarity) matrix with some special dual class matrix and char.diff. This means it can easily be plotted via the disparity package: ## Visualising the matrix plot(differences) You can check all the numerous plotting options in the ?plot.char.diff manual (it won’t be developed here). The char.diff function has much more options however (see all of them in the ?char.diff manual) for example to measure different differences (via method) or making the comparison work per row (for a distance matrix between the rows): ## Euclidean distance between rows char.diff(matrix_binary, by.col = FALSE, method = "euclidean") ## a b c ## a 0.000000 1.414214 1.414214 ## b 1.414214 0.000000 0.000000 ## c 1.414214 0.000000 0.000000 ## attr(,"class") ## [1] "matrix" "char.diff" We can however make it more interesting by playing with the different rules to play with different tokens. First let’s create a matrix with morphological characters as numeric characters: ## A random character matrix (matrix_character <- matrix(sample(c("0","1","2"), 30, replace = TRUE), ncol = 5, dimnames = list(letters[1:6], LETTERS[1:5]))) ## A B C D E ## a "1" "1" "1" "1" "0" ## b "0" "2" "0" "2" "0" ## c "2" "2" "1" "2" "0" ## d "1" "2" "0" "0" "1" ## e "2" "2" "1" "1" "2" ## f "0" "2" "0" "2" "0" ## The hamming difference between columns char.diff(matrix_character) ## A B C D E ## A 0.0 0.6 0.6 0.6 0.8 ## B 0.6 0.0 0.4 0.4 0.8 ## C 0.6 0.4 0.0 0.4 0.6 ## D 0.6 0.4 0.4 0.0 1.0 ## E 0.8 0.8 0.6 1.0 0.0 ## attr(,"class") ## [1] "matrix" "char.diff" Here the characters are automatically converted into bitwise integers to be compared efficiently. We can now add some more special tokens like \"?\" or \"0/1\" for uncertainties between state \"0\" and \"1\" but not \"2\": ## Adding uncertain characters matrix_character[sample(1:30, 8)] <- "0/1" ## Adding missing data matrix_character[sample(1:30, 5)] <- "?" ## This is what it looks like now matrix_character ## A B C D E ## a "?" "?" "1" "1" "0" ## b "0" "0/1" "0/1" "0/1" "0" ## c "2" "2" "?" "0/1" "0" ## d "1" "2" "0" "0/1" "1" ## e "?" "2" "1" "1" "2" ## f "0" "2" "0" "?" "0/1" ## The hamming difference between columns including the special characters char.diff(matrix_character) ## A B C D E ## A 0.0000000 0.6666667 1.00 0.50 0.6666667 ## B 0.6666667 0.0000000 1.00 1.00 0.7500000 ## C 1.0000000 1.0000000 0.00 0.00 0.2500000 ## D 0.5000000 1.0000000 0.00 0.00 0.2500000 ## E 0.6666667 0.7500000 0.25 0.25 0.0000000 ## attr(,"class") ## [1] "matrix" "char.diff" Note here that it detected the default behaviours for the special tokens \"?\" and \"/\": \"?\" are treated as NA (not compared) and \"/\" are treated as both states (e.g. \"0/1\" is treated as \"0\" and as \"1\"). We can specify both the special tokens and the special behaviours to consider via special.tokens and special.behaviours. The special.tokens are missing = \"?\", inapplicable = \"-\", uncertainty = \"\\\" and polymorphism = \"&\" meaning we don’t have to modify them for now. However, say we want to change the behaviour for \"?\" and treat them as all possible characters and treat \"/\" as only the character \"0\" (as an integer) we can specify them giving a behaviour function: ## Specifying some special behaviours my_special_behaviours <- list(missing = function(x,y) return(y), uncertainty = function(x,y) return(as.integer(0))) ## Passing these special behaviours to the char.diff function char.diff(matrix_character, special.behaviour = my_special_behaviours) ## A B C D E ## A 0.0 0.6 0.6 0.6 0.6 ## B 0.6 0.0 0.8 0.8 0.8 ## C 0.6 0.8 0.0 0.4 0.6 ## D 0.6 0.8 0.4 0.0 1.0 ## E 0.6 0.8 0.6 1.0 0.0 ## attr(,"class") ## [1] "matrix" "char.diff" The results are quiet different as before! Note that you can also specify some really specific behaviours for any type of special token. ## Adding weird tokens to the matrix matrix_character[sample(1:30, 8)] <- "%" ## Specify the new token and the new behaviour char.diff(matrix_character, special.tokens = c(weird_one = "%"), special.behaviours = list( weird_one = function(x,y) return(as.integer(42))) ) ## A B C D E ## A 0 1 1 0 NaN ## B 1 0 1 1 NaN ## C 1 1 0 0 0 ## D 0 1 0 0 0 ## E NaN NaN 0 0 0 ## attr(,"class") ## [1] "matrix" "char.diff" Of course the results can be quiet surprising then… But that’s the essence of the modularity. You can see more options in the function manual ?char.diff! 6.2 clean.data This is a rather useful function that allows matching a matrix or a data.frame to a tree (phylo) or a distribution of trees (multiPhylo). This function outputs the cleaned data and trees (if cleaning was needed) and a list of dropped rows and tips. ## Generating a trees with labels from a to e dummy_tree <- rtree(5, tip.label = LETTERS[1:5]) ## Generating a matrix with rows from b to f dummy_data <- matrix(1, 5, 2, dimnames = list(LETTERS[2:6], c("var1", "var2"))) ##Cleaning the trees and the data (cleaned <- clean.data(data = dummy_data, tree = dummy_tree)) ## $tree ## ## Phylogenetic tree with 4 tips and 3 internal nodes. ## ## Tip labels: ## D, B, E, C ## ## Rooted; includes branch lengths. ## ## $data ## var1 var2 ## B 1 1 ## C 1 1 ## D 1 1 ## E 1 1 ## ## $dropped_tips ## [1] "A" ## ## $dropped_rows ## [1] "F" 6.3 crown.stem This function quiet handily separates tips from a phylogeny between crown members (the living taxa and their descendants) and their stem members (the fossil taxa without any living relatives). data(BeckLee_tree) ## Diving both crow and stem species (crown.stem(BeckLee_tree, inc.nodes = FALSE)) ## $crown ## [1] "Dasypodidae" "Bradypus" "Myrmecophagidae" "Todralestes" ## [5] "Potamogalinae" "Dilambdogale" "Widanelfarasia" "Rhynchocyon" ## [9] "Procavia" "Moeritherium" "Pezosiren" "Trichechus" ## [13] "Tribosphenomys" "Paramys" "Rhombomylus" "Gomphos" ## [17] "Mimotona" "Cynocephalus" "Purgatorius" "Plesiadapis" ## [21] "Notharctus" "Adapis" "Patriomanis" "Protictis" ## [25] "Vulpavus" "Miacis" "Icaronycteris" "Soricidae" ## [29] "Solenodon" "Eoryctes" ## ## $stem ## [1] "Daulestes" "Bulaklestes" "Uchkudukodon" ## [4] "Kennalestes" "Asioryctes" "Ukhaatherium" ## [7] "Cimolestes" "unnamed_cimolestid" "Maelestes" ## [10] "Batodon" "Kulbeckia" "Zhangolestes" ## [13] "unnamed_zalambdalestid" "Zalambdalestes" "Barunlestes" ## [16] "Gypsonictops" "Leptictis" "Oxyclaenus" ## [19] "Protungulatum" "Oxyprimus" Note that it is possible to include or exclude nodes from the output. To see a more applied example: this function is used in chapter 03: specific tutorials. 6.4 get.bin.ages This function is similar than the crown.stem one as it is based on a tree but this one outputs the stratigraphic bins ages that the tree is covering. This can be useful to generate precise bin ages for the chrono.subsets function: get.bin.ages(BeckLee_tree) ## [1] 132.9000 129.4000 125.0000 113.0000 100.5000 93.9000 89.8000 86.3000 ## [9] 83.6000 72.1000 66.0000 61.6000 59.2000 56.0000 47.8000 41.2000 ## [17] 37.8000 33.9000 28.1000 23.0300 20.4400 15.9700 13.8200 11.6300 ## [25] 7.2460 5.3330 3.6000 2.5800 1.8000 0.7810 0.1260 0.0117 ## [33] 0.0000 Note that this function outputs the stratigraphic age limits by default but this can be customisable by specifying the type of data (e.g. type = \"Eon\" for eons). The function also intakes several optional arguments such as whether to output the startm end, range or midpoint of the stratigraphy or the year of reference of the International Commission of Stratigraphy. To see a more applied example: this function is used in chapter 03: specific tutorials. 6.5 match.tip.edge This function matches a vector of discreet tip values with the edges connecting these tips in the \"phylo\" structure. This can be used to pull the branches of interest for some specific trait of some group of species or for colouring tree tips based on clades. For example, with the charadriiformes dataset, you can plot the tree with the branches coloured by clade. To work properly, the function requires the characteristics of the tip labels (e.g. the clade colour) to match the order of the tips in the tree: ## Loading the charadriiformes data data(charadriiformes) ## Extracting the tree my_tree <- charadriiformes$tree ## Extracting the data column that contains the clade assignments my_data <- charadriiformes$data[, "clade"] ## Changing the levels names (the clade names) to colours levels(my_data) <- c("orange", "blue", "darkgreen") my_data <- as.character(my_data) ## Matching the data rownames to the tip order in the tree my_data <- my_data[match(ladderize(my_tree)$tip.label, rownames(charadriiformes$data))] We can then match this tip data to their common descending edges. We will also colour the edges that is not descendant directly from a common coloured tip in grey using \"replace.na = \"grey\". Note that these edges are usually the edges at the root of the tree that are the descendant edges from multiple clades. ## Matching the tip colours (labels) to their descending edges in the tree ## (and making the non-match edges grey) clade_edges <- match.tip.edge(my_data, my_tree, replace.na = "grey") ## Plotting the results plot(ladderize(my_tree), show.tip.label = FALSE, edge.color = clade_edges) But you can also use this option to only select some specific edges and modify them (for example making them all equal to one): ## Adding a fixed edge length to the green clade my_tree_modif <- my_tree green_clade <- which(clade_edges == "darkgreen") my_tree_modif$edge.length[green_clade] <- 1 plot(ladderize(my_tree_modif), show.tip.label = FALSE, edge.color = clade_edges) 6.6 MCMCglmm utilities Since version 1.7, the dispRity package contains several utility functions for manipulating \"MCMCglmm\" (that is, objects returned by the function MCMCglmm::MCMCglmm). These objects are a modification of the mcmc object (from the package coda) and can be sometimes cumbersome to manipulate because of the huge amount of data in it. You can use the functions MCMCglmm.traits for extracting the number of traits, MCMCglmm.levels for extracting the level names, MCMCglmm.sample for sampling posterior IDs and MCMCglmm.covars for extracting variance-covariance matrices. You can also quickly calculate the variance (or relative variance) for each terms in the model using MCMCglmm.variance (the variance is calculated as the sum of the diagonal of each variance-covariance matrix for each term). ## Loading the charadriiformes data that contains a MCMCglmm object data(charadriiformes) my_MCMCglmm <- charadriiformes$posteriors ## Which traits where used in this model? MCMCglmm.traits(my_MCMCglmm) ## [1] "PC1" "PC2" "PC3" ## Which levels where used for the model's random terms and/or residuals? MCMCglmm.levels(my_MCMCglmm) ## random random random random ## "animal:clade_1" "animal:clade_2" "animal:clade_3" "animal" ## residual ## "units" ## The level names are converted for clarity but you can get them unconverted ## (i.e. as they appear in the model) MCMCglmm.levels(my_MCMCglmm, convert = FALSE) ## random random ## "us(at.level(clade, 1):trait):animal" "us(at.level(clade, 2):trait):animal" ## random random ## "us(at.level(clade, 3):trait):animal" "us(trait):animal" ## residual ## "us(trait):units" ## Sampling 2 random posteriors samples IDs (random_samples <- MCMCglmm.sample(my_MCMCglmm, n = 2)) ## [1] 749 901 ## Extracting these two random samples my_covars <- MCMCglmm.covars(my_MCMCglmm, sample = random_samples) ## Plotting the variance for each term in the model boxplot(MCMCglmm.variance(my_MCMCglmm), horizontal = TRUE, las = 1, xlab = "Relative variance", main = "Variance explained by each term") See more in the $covar section on what to do with these \"MCMCglmm\" objects. 6.7 pair.plot This utility function allows to plot a matrix image of pairwise comparisons. This can be useful when getting pairwise comparisons and if you’d like to see at a glance which pairs of comparisons have high or low values. ## Random data data <- matrix(data = runif(42), ncol = 2) ## Plotting the first column as a pairwise comparisons pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE, diag = 1) Here blue squares are ones that have a high value and orange ones the ones that have low values. Note that the values plotted correspond the first column of the data as designated by what = 1. It is also possible to add some tokens or symbols to quickly highlight to specific cells, for example which elements in the data are below a certain value: ## The same plot as before without the diagonal being ## the maximal observed value pair.plot(data, what = 1, col = c("orange", "blue"), legend = TRUE, diag = "max") ## Highlighting with an asterisk which squares have a value ## below 0.2 pair.plot(data, what = 1, binary = 0.2, add = "*", cex = 2) This function can also be used as a binary display when running a series of pairwise t-tests. For example, the following script runs a wilcoxon test between the time-slices from the disparity example dataset and displays in black which pairs of slices have a p-value below 0.05: ## Loading disparity data data(disparity) ## Testing the pairwise difference between slices tests <- test.dispRity(disparity, test = wilcox.test, correction = "bonferroni") ## Plotting the significance pair.plot(as.data.frame(tests), what = "p.value", binary = 0.05) 6.8 reduce.matrix This function allows to reduce columns or rows of a matrix to make sure that there is enough overlap for further analysis. This is particularly useful if you are going to use distance matrices since it uses the vegan::vegdist function to test whether distances can be calculated or not. For example, if we have a patchy matrix like so (where the black squares represent available data): set.seed(1) ## A 10*5 matrix na_matrix <- matrix(rnorm(50), 10, 5) ## Making sure some rows don't overlap na_matrix[1, 1:2] <- NA na_matrix[2, 3:5] <- NA ## Adding 50% NAs na_matrix[sample(1:50, 25)] <- NA ## Illustrating the gappy matrix image(t(na_matrix), col = "black") We can use the reduce.matrix to double check whether any rows cannot be compared. The functions needs as an input the type of distance that will be used, say a \"gower\" distance: ## Reducing the matrix by row (reduction <- reduce.matrix(na_matrix, distance = "gower")) ## $rows.to.remove ## [1] "9" "1" ## ## $cols.to.remove ## NULL We can not remove the rows 1 and 9 and see if that improved the overlap: image(t(na_matrix[-as.numeric(reduction$rows.to.remove), ]), col = "black") 6.9 select.axes This function allows you to select which axes (or how many of them) are relevant in your trait space analyses. Usually, when the trait space is an ordination, workers select a certain number of axes to reduce the dimensionality of the dataset by removing axes that contain relatively little information. This is often done by selecting the axes from which the cumulative individual variance is lower than an arbitrary threshold. For example, all the axes that contain together 0.95 of the variance: ## The USArrest example in R ordination <- princomp(USArrests, cor = TRUE) ## The loading of each variable loadings(ordination) ## ## Loadings: ## Comp.1 Comp.2 Comp.3 Comp.4 ## Murder 0.536 0.418 0.341 0.649 ## Assault 0.583 0.188 0.268 -0.743 ## UrbanPop 0.278 -0.873 0.378 0.134 ## Rape 0.543 -0.167 -0.818 ## ## Comp.1 Comp.2 Comp.3 Comp.4 ## SS loadings 1.00 1.00 1.00 1.00 ## Proportion Var 0.25 0.25 0.25 0.25 ## Cumulative Var 0.25 0.50 0.75 1.00 ## Or the same operation but manually variances <- apply(ordination$scores, 2, var) scaled_variances <- variances/sum(variances) sumed_variances <- cumsum(scaled_variances) round(rbind(variances, scaled_variances, sumed_variances), 3) ## Comp.1 Comp.2 Comp.3 Comp.4 ## variances 2.531 1.010 0.364 0.177 ## scaled_variances 0.620 0.247 0.089 0.043 ## sumed_variances 0.620 0.868 0.957 1.000 In this example, you can see that the three first axes are required to have at least 0.95 of the variance. You can do that automatically in dispRity using the select.axes function. ## Same operation automatised (selected <- select.axes(ordination)) ## The first 3 dimensions are needed to express at least 95% of the variance in the whole trait space. ## You can use x$dimensions to select them or use plot(x) and summary(x) to summarise them. This function does basically what the script above does and allows the results to be plotted or summarised into a table. ## Summarising this info summary(selected) ## Comp.1.var Comp.1.sum Comp.2.var Comp.2.sum Comp.3.var Comp.3.sum ## whole_space 0.62 0.62 0.247 0.868 0.089 0.957 ## Comp.4.var Comp.4.sum ## whole_space 0.043 1 ## Plotting it plot(selected) ## Extracting the dimensions ## (for the dispRity function for example) selected$dimensions ## [1] 1 2 3 However, it might be interesting to not only consider the variance within the whole trait space but also among groups of specific interest. E.g. if the 95% of the variance is concentrated in the two first axes for the whole trait space, that does not automatically mean that it is the case for each subset in this space. Some subset might require more than the two first axes to express 95% of their variance! You can thus use the select.axes function to look at the results per group as well as through the whole trait space. Note that you can always change the threshold value (default is 0.95). Here for example we set it to 0.9 (we arbitrarily decide that explain 90% of the variance is enough). ## Creating some groups of stats states_groups <- list("Group1" = c("Mississippi","North Carolina", "South Carolina", "Georgia", "Alabama", "Alaska", "Tennessee", "Louisiana"), "Group2" = c("Florida", "New Mexico", "Michigan", "Indiana", "Virginia", "Wyoming", "Montana", "Maine", "Idaho", "New Hampshire", "Iowa"), "Group3" = c("Rhode Island", "New Jersey", "Hawaii", "Massachusetts")) ## Running the same analyses but per groups selected <- select.axes(ordination, group = states_groups, threshold = 0.9) ## Plotting the results plot(selected) As you can see here, the whole space requires the three first axes to explain at least 90% of the variance (in fact, 95% as seen before). However, different groups have a different story! The Group 1 and 3 requires 4 dimensions whereas Group 2 requires only 1 dimensions (note how for Group 3, there is actually nearly no variance explained on the second axes)! Using this method, you can safely use the four axes returned by the function (selected$dimensions) so that every group has at least 90% of their variance explained in the trait space. If you’ve used the function if you’ve already done some grouping in your disparity analyses (e.g. using the function custom.subsets or chrono.subsets), you can use the generated dispRity to automatise this analyses: ## Loading the dispRity package demo data data(demo_data) ## A dispRity object with two groups demo_data$hopkins ## ---- dispRity object ---- ## 2 customised subsets for 46 elements in one matrix: ## adult, juvenile. ## Selecting axes on a dispRity object selected <- select.axes(demo_data$hopkins) plot(selected) ## Displaying which axes are necessary for which group selected$dim.list ## $adult ## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ## ## $juvenile ## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ## ## $whole_space ## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ## Note how the whole space needs only 16 axes ## but both groups need 22 and 23 axes 6.10 set.root.time This function can be used to easily add a $root.time element to \"phylo\" or \"multiPhylo\" objects. This $root.time element is used by dispRity and several packages (e.g. Claddis and paleotree) to scale the branch length units of a tree allowing them to be usually expressed in million of years (Mya). For example, on a standard random tree, no $root.time exist so the edge lengths are not expressed in any specific unit: ## A random tree with no root.time my_tree <- rtree(10) my_tree$root.time # is NULL ## NULL You can add a root time by either manually setting it: ## Adding an arbitrary root time my_tree_arbitrary <- my_tree ## Setting the age of the root to 42 my_tree_arbitrary$root.time <- 42 Or by calculating it automatically from the cumulated branch length information (making the youngest tip age 0 and the oldest the total age/depth of the tree) ## Calculating the root time from the present my_tree_aged <- my_tree my_tree_aged <- set.root.time(my_tree) If you want the youngest tip to not be of age 0, you can define an arbitrary age for it and recalculate the age of the root from there using the present argument (say the youngest tip is 42 Mya old): ## Caculating the root time from 42 Mya my_tree_age <- set.root.time(my_tree, present = 42) This function also works with a distribution of trees (\"multiPhylo\"). 6.11 slice.tree This function is a modification of the paleotree::timeSliceTree function that allows to make slices through a phylogenetic tree. Compared to the paleotree::timeSliceTree, this function allows a model to decide which tip or node to use when slicing through a branch (whereas paleotree::timeSliceTree always choose the first available tip alphabetically). The models for choosing which tip or node are the same as the ones used in the chrono.subsets and are described in chapter 03: specific tutorials. The function works by using at least a tree, a slice age and a model: set.seed(1) ## Generate a random ultrametric tree tree <- rcoal(20) ## Add some node labels tree$node.label <- letters[1:19] ## Add its root time tree$root.time <- max(tree.age(tree)$ages) ## Slicing the tree at age 0.75 tree_75 <- slice.tree(tree, age = 0.75, "acctran") ## Showing both trees par(mfrow = c(1,2)) plot(tree, main = "original tree") axisPhylo() ; nodelabels(tree$node.label, cex = 0.8) abline(v = (max(tree.age(tree)$ages) - 0.75), col = "red") plot(tree_75, main = "sliced tree") 6.12 slide.nodes and remove.zero.brlen This function allows to slide nodes along a tree! In other words it allows to change the branch length leading to a node without modifying the overall tree shape. This can be useful to add some value to 0 branch lengths for example. The function works by taking a node (or a list of nodes), a tree and a sliding value. The node will be moved “up” (towards the tips) for the given sliding value. You can move the node “down” (towards the roots) using a negative value. set.seed(42) ## Generating simple coalescent tree tree <- rcoal(5) ## Sliding node 8 up and down tree_slide_up <- slide.nodes(8, tree, slide = 0.075) tree_slide_down <- slide.nodes(8, tree, slide = -0.075) ## Display the results par(mfrow = c(3,1)) plot(tree, main = "original tree") ; axisPhylo() ; nodelabels() plot(tree_slide_up, main = "slide up!") ; axisPhylo() ; nodelabels() plot(tree_slide_down, main = "slide down!") ; axisPhylo() ; nodelabels() The remove.zero.brlen is a “clever” wrapping function that uses the slide.nodes function to stochastically remove zero branch lengths across a whole tree. This function will slide nodes up or down in successive postorder traversals (i.e. going down the tree clade by clade) in order to minimise the number of nodes to slide while making sure there are no silly negative branch lengths produced! By default it is trying to slide the nodes using 1% of the minimum branch length to avoid changing the topology too much. set.seed(42) ## Generating a tree tree <- rtree(20) ## Adding some zero branch lengths (5) tree$edge.length[sample(1:Nedge(tree), 5)] <- 0 ## And now removing these zero branch lengths! tree_no_zero <- remove.zero.brlen(tree) ## Exaggerating the removal (to make it visible) tree_exaggerated <- remove.zero.brlen(tree, slide = 1) ## Check the differences any(tree$edge.length == 0) ## [1] TRUE any(tree_no_zero$edge.length == 0) ## [1] FALSE any(tree_exaggerated$edge.length == 0) ## [1] FALSE ## Display the results par(mfrow = c(3,1)) plot(tree, main = "with zero edges") plot(tree_no_zero, main = "without zero edges!") plot(tree_exaggerated, main = "with longer edges") 6.13 tree.age This function allows to quickly calculate the ages of each tips and nodes present in a tree. set.seed(1) tree <- rtree(10) ## The tree age from a 10 tip tree tree.age(tree) ## ages elements ## 1 0.7068 t7 ## 2 0.1417 t2 ## 3 0.0000 t3 ## 4 1.4675 t8 ## 5 1.3656 t1 ## 6 1.8949 t5 ## 7 1.5360 t6 ## 8 1.4558 t9 ## 9 0.8147 t10 ## 10 2.3426 t4 ## 11 3.0111 11 ## 12 2.6310 12 ## 13 1.8536 13 ## 14 0.9189 14 ## 15 0.2672 15 ## 16 2.6177 16 ## 17 2.2353 17 ## 18 2.1356 18 ## 19 1.6420 19 It also allows to set the age of the root of the tree: ## The ages starting from -100 units tree.age(tree, age = 100) ## ages elements ## 1 23.4717 t7 ## 2 4.7048 t2 ## 3 0.0000 t3 ## 4 48.7362 t8 ## 5 45.3517 t1 ## 6 62.9315 t5 ## 7 51.0119 t6 ## 8 48.3486 t9 ## 9 27.0554 t10 ## 10 77.7998 t4 ## 11 100.0000 11 ## 12 87.3788 12 ## 13 61.5593 13 ## 14 30.5171 14 ## 15 8.8746 15 ## 16 86.9341 16 ## 17 74.2347 17 ## 18 70.9239 18 ## 19 54.5330 19 Usually tree age is calculated from the present to the past (e.g. in million years ago) but it is possible to reverse it using the order = present option: ## The ages in terms of tip/node height tree.age(tree, order = "present") ## ages elements ## 1 2.3043 t7 ## 2 2.8694 t2 ## 3 3.0111 t3 ## 4 1.5436 t8 ## 5 1.6455 t1 ## 6 1.1162 t5 ## 7 1.4751 t6 ## 8 1.5553 t9 ## 9 2.1964 t10 ## 10 0.6685 t4 ## 11 0.0000 11 ## 12 0.3800 12 ## 13 1.1575 13 ## 14 2.0922 14 ## 15 2.7439 15 ## 16 0.3934 16 ## 17 0.7758 17 ## 18 0.8755 18 ## 19 1.3690 19 6.14 multi.ace This function allows to run ancestral characters estimations on multiple trees. In it’s most basic structure (e.g. using all default arguments) this function is using a mix of ape::ace and castor::asr_mk_model depending on the data and the situation and is generally faster than both functions when applied to a list of trees. However, this function provides also some more complex and modular functionalities, especially appropriate when using discrete morphological character data. 6.14.1 Using different character tokens in different situations This data can be often coded in non-standard way with different character tokens having different meanings. For example, in some datasets the token - can mean “the trait is inapplicable” but this can be also coded by the more conventional NA or can mean “this trait is missing” (often coded ?). This makes the meaning of specific tokens idiosyncratic to different matrices. For example we can have the following discrete morphological matrix with all the data encoded: set.seed(42) ## A random tree with 10 tips tree <- rcoal(10) ## Setting up the parameters my_rates = c(rgamma, rate = 10, shape = 5) ## Generating a bunch of trees multiple_trees <- rmtree(5, 10) ## A random Mk matrix (10*50) matrix_simple <- sim.morpho(tree, characters = 50, model = "ER", rates = my_rates, invariant = FALSE) matrix_simple[1:10, 1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## t8 "1" "1" "1" "1" "0" "0" "0" "0" "0" "1" ## t3 "1" "1" "1" "1" "0" "0" "0" "0" "0" "1" ## t2 "1" "1" "1" "1" "0" "1" "1" "1" "0" "1" ## t1 "1" "1" "1" "1" "0" "0" "1" "1" "0" "1" ## t10 "1" "1" "1" "1" "0" "0" "1" "0" "1" "1" ## t9 "1" "1" "1" "1" "0" "0" "1" "0" "0" "1" ## t5 "0" "0" "0" "0" "1" "1" "1" "0" "0" "0" ## t6 "0" "0" "0" "0" "1" "1" "1" "0" "0" "0" ## t4 "0" "0" "0" "0" "1" "0" "0" "0" "1" "0" ## t7 "0" "0" "0" "0" "1" "0" "0" "0" "1" "0" But of course, as mentioned above, in practice, such matrices have more nuance and can including missing characters, ambiguous characters, multi-state characters, inapplicable characters, etc… All these coded and defined by different authors using different tokens (or symbols). Let’s give it a go and transform this simple data to something more messy: ## Modify the matrix to contain missing and special data matrix_complex <- matrix_simple ## Adding 50 random "-" tokens matrix_complex[sample(1:length(matrix_complex), 50)] <- "-" ## Adding 50 random "?" tokens matrix_complex[sample(1:length(matrix_complex), 50)] <- "?" ## Adding 50 random "0%2" tokens matrix_complex[sample(1:length(matrix_complex), 50)] <- "0%2" matrix_complex[1:10,1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## t8 "1" "1" "1" "1" "?" "0" "0" "0" "0" "0%2" ## t3 "1" "-" "1" "1" "?" "0" "0" "0" "0" "1" ## t2 "1" "1" "1" "0%2" "0" "0%2" "1" "1" "0" "1" ## t1 "1" "1" "1" "1" "0" "0" "1" "?" "0" "1" ## t10 "1" "0%2" "1" "1" "-" "?" "0%2" "0%2" "1" "1" ## t9 "1" "1" "?" "1" "0%2" "0" "1" "0" "0" "1" ## t5 "0" "-" "?" "0" "1" "1" "1" "0" "0" "-" ## t6 "0" "-" "0" "0" "1" "1" "-" "-" "?" "0" ## t4 "?" "0" "0" "0" "1" "0" "0" "0" "1" "0" ## t7 "0" "0" "0" "0%2" "1" "0" "0" "-" "1" "-" In multi.ace you can specify what all these tokens actually mean and how the code should interpret them. For example, - often means inapplicable data (i.e. the specimen does not have the coded feature, for example, the colour of the tail of a tailless bird); or ? that often means missing data (i.e. it is unknown if the specimen has a tail or not since only the head was available). And more than the differences in meaning between these characters, different people treat these characters differently even if they have the same meaning for the token. For example, one might want to treat - as meaning “we don’t know” (which will be treated by the algorithm as “any possible trait value”) or “we know, and it’s no possible” (which will be treated by the algorithm as NA). Because of this situation, multi.ace allows combining any special case marked with a special token to a special behaviour. For example we might want to create a special case called \"missing\" (i.e. the data is missing) that we want to denote using the token \"?\" and we can specify the algorithm to treat this \"missing\" cases (\"?\") as treating the character token value as “any possible values”. This behaviour can be hard coded by providing a function with the name of the behaviour. For example: ## The specific token for the missing cases (note the "\\\\" for protecting the value) special.tokens <- c("missing" = "\\\\?") ## The behaviour for the missing cases (?) special.behaviour <- list(missing <- function(x, y) return(y)) ## Where x is the input value (here "?") and y is all the possible normal values for the character This example shows a very common case (and is actually used by default, more on that below) but this architecture allows for very modular combination of tokens and behaviours. For example, in our code above we introduced the token \"%\" which is very odd (to my knowledge) and might mean something very specific in our case. Say we want to call this case \"weirdtoken\" and mean that whenever this token is encountered in a character, it should be interpreted by the algorithm as the values 1 and 2, no matter what: ## Set a list of extra special tokens my_spec_tokens <- c("weirdtoken" = "\\\\%") ## Weird tokens are considered as state 0 and 3 my_spec_behaviours <- list() my_spec_behaviours$weirdtoken <- function(x,y) return(c(1,2)) If you don’t need/don’t have any of this specific tokens, don’t worry, most special but common tokens are handled by default as such: ## The token for missing values: default_tokens <- c("missing" = "\\\\?", ## The token for inapplicable values: "inapplicable" = "\\\\-", ## The token for polymorphisms: "polymorphism" = "\\\\&", ## The token for uncertainties: "uncertanity" = "\\\\/") With the following associated default behaviours ## Treating missing data as all data values default_behaviour <- list(missing <- function(x,y) y, ## Treating inapplicable data as all data values (like missing) inapplicable <- function(x, y) y, ## Treating polymorphisms as all values present: polymorphism <- function(x,y) strsplit(x, split = "\\\\&")[[1]], ## Treating uncertainties as all values present (like polymorphisms): uncertanity <- function(x,y) strsplit(x, split = "\\\\/")[[1]]) We can then use these token description along with our complex matrix and our list of trees to run the ancestral states estimations as follows: ## Running ancestral states ancestral_states <- multi.ace(matrix_complex, multiple_trees, special.tokens = my_spec_tokens, special.behaviours = my_spec_behaviours, verbose = TRUE) ## Preparing the data:... ## Warning: The character 39 is invariant (using the current special behaviours ## for special characters) and is simply duplicated for each node. ## ..Done. ## Running ancestral states estimations:.....................................................................................................................................................................................................................................................Done. ## This outputs a list of ancestral parts of the matrices for each tree ## For example, here's the first one: ancestral_states[[1]][1:9, 1:10] ## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] ## n1 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1" ## n2 "1" "1" "1" "1" "0/1" "0/1/2" "0/1" "0" "0" "1" ## n3 "1" "1" "1" "1" "0/1" "0/1/2" "0" "0" "0" "1" ## n4 "1" "1" "1" "1" "0" "0/1/2" "1" "1" "0" "1" ## n5 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1" ## n6 "1" "1" "1" "1" "1" "0/1/2" "1" "0" "0" "1" ## n7 "0" "0/1" "0/1" "0" "1" "1" "1" "0" "0" "0/1" ## n8 "0" "0" "0" "0" "1" "0/1/2" "0" "0" "1" "0" ## n9 "0" "0" "0" "0" "1" "1" "0" "0" "1" "0" Note that there are many different options that are not covered here. For example, you can use different models for each character via the models argument, you can specify how to handle uncertainties via the threshold argument, use a branch length modifier (brlen.multiplier), specify the type of output, etc… 6.14.2 Feeding the results to char.diff to get distance matrices After running your ancestral states estimations, it is not uncommon to then use these resulting data to calculate the distances between taxa and then ordinate the results to measure disparity. You can do that using the char.diff function described above but instead of measuring the distances between characters (columns) you can measure the distances between species (rows). You might notice that this function uses the same modular token and behaviour descriptions. That makes sense because they’re using the same core C functions implemented in dispRity that greatly speed up distance calculations. ## Running ancestral states ## and outputing a list of combined matrices (tips and nodes) ancestral_states <- multi.ace(matrix_complex, multiple_trees, special.tokens = my_spec_tokens, special.behaviours = my_spec_behaviours, output = "combined.matrix", verbose = TRUE) ## Preparing the data:... ## Warning: The character 39 is invariant (using the current special behaviours ## for special characters) and is simply duplicated for each node. ## ..Done. ## Running ancestral states estimations:.....................................................................................................................................................................................................................................................Done. We can then feed these matrices directly to char.diff, say for calculating the “MORD” distance: ## Measuring the distances between rows using the MORD distance distances <- lapply(ancestral_states, char.diff, method = "mord", by.col = FALSE) And we now have a list of distances matrices with ancestral states estimated! 6.14.3 Running ancestral states estimations for continuous characters You can also run multi.ace on continuous characters. The function detects any continuous characters as being of class \"numeric\" and runs them using the ape::ace function. set.seed(1) ## Creating three coalescent trees my_trees <- replicate(3, rcoal(15), simplify = FALSE) ## Adding node labels my_trees <- lapply(my_trees, makeNodeLabel) ## Making into a multiPhylo object class(my_trees) <- "multiPhylo" ## Creating a matrix of continuous characters data <- space.maker(elements = 15, dimensions = 5, distribution = rnorm, elements.name = my_trees[[1]]$tip.label) With such data and trees you can easily run the multi.ace estimations. By default, the estimations use the default arguments from ape::ace, knowingly a Brownian Motion (model = \"BM\") with the REML method (method = \"REML\"; this method “first estimates the ancestral value at the root (aka, the phylogenetic mean), then the variance of the Brownian motion process is estimated by optimizing the residual log-likelihood” - from ?ape::ace). ## Running multi.ace on continuous data my_ancestral_states <- multi.ace(data, my_trees) ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## We end up with three matrices of node states estimates str(my_ancestral_states) ## List of 3 ## $ : num [1:14, 1:5] -0.191 -0.155 -0.227 -0.17 0.138 ... ## ..- attr(*, "dimnames")=List of 2 ## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ... ## .. ..$ : NULL ## $ : num [1:14, 1:5] -0.385 -0.552 -0.445 -0.435 -0.478 ... ## ..- attr(*, "dimnames")=List of 2 ## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ... ## .. ..$ : NULL ## $ : num [1:14, 1:5] -0.3866 -0.2232 -0.0592 -0.7246 -0.2253 ... ## ..- attr(*, "dimnames")=List of 2 ## .. ..$ : chr [1:14] "Node1" "Node2" "Node3" "Node4" ... ## .. ..$ : NULL This results in three matrices with ancestral states for the nodes. When using continuous characters, however, you can output the results directly as a dispRity object that allows visualisation and other normal dispRity pipeline: ## Running multi.ace on continuous data my_ancestral_states <- multi.ace(data, my_trees, output = "dispRity") ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## We end up with three matrices of node states estimates plot(my_ancestral_states) You can also mix continuous and discrete characters together. By default the multi.ace detects which character is of which type and applies the correct estimations based on that. However you can always specify models or other details character per characters. ## Adding two discrete characters data <- as.data.frame(data) data <- cbind(data, "new_char" = as.character(sample(1:2, 15, replace = TRUE))) data <- cbind(data, "new_char2" = as.character(sample(1:2, 15, replace = TRUE))) ## Setting up different models for each characters ## BM for all 5 continuous characters ## and ER and ARD for the two discrete ones my_models <- c(rep("BM", 5), "ER", "ARD") ## Running the estimation with the specified models my_ancestral_states <- multi.ace(data, my_trees, models = my_models) ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced ## Warning in sqrt(1/out$hessian): NaNs produced Of course all the options discussed in the first part above also can apply here! "],["the-guts-of-the-disprity-package.html", "7 The guts of the dispRity package 7.1 Manipulating dispRity objects 7.2 dispRity utilities 7.3 The dispRity object content", " 7 The guts of the dispRity package 7.1 Manipulating dispRity objects Disparity analysis involves a lot of manipulation of many matrices (especially when bootstrapping) which can be impractical to visualise and will quickly overwhelm your R console. Even the simple Beck and Lee 2014 example above produces an object with > 72 lines of lists of lists of matrices! Therefore dispRity uses a specific class of object called a dispRity object. These objects allow users to use S3 method functions such as summary.dispRity, plot.dispRity and print.dispRity. dispRity also contains various utility functions that manipulate the dispRity object (e.g. sort.dispRity, extract.dispRity see the full list in the next section). These functions modify the dispRity object without having to delve into its complex structure! The full structure of a dispRity object is detailed here. ## Loading the example data data(disparity) ## What is the class of the median_centroids object? class(disparity) ## [1] "dispRity" ## What does the object contain? names(disparity) ## [1] "matrix" "tree" "call" "subsets" "disparity" ## Summarising it using the S3 method print.dispRity disparity ## ---- dispRity object ---- ## 7 continuous (acctran) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree ## 90, 80, 70, 60, 50 ... ## Rows were bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements. ## Disparity was calculated as: c(median, centroids). Note that it is always possible to recall the full object using the argument all = TRUE in print.dispRity: ## Display the full object print(disparity, all = TRUE) ## This is more nearly ~ 5000 lines on my 13 inch laptop screen! 7.2 dispRity utilities The package also provides some utility functions to facilitate multidimensional analysis. 7.2.1 dispRity object utilities The first set of utilities are functions for manipulating dispRity objects: 7.2.1.1 make.dispRity This function creates empty dispRity objects. ## Creating an empty dispRity object make.dispRity() ## Empty dispRity object. ## Creating an "empty" dispRity object with a matrix (disparity_obj <- make.dispRity(matrix(rnorm(20), 5, 4))) ## ---- dispRity object ---- ## Contains a matrix 5x4. 7.2.1.2 fill.dispRity This function initialises a dispRity object and generates its call properties. ## The dispRity object's call is indeed empty disparity_obj$call ## list() ## Filling an empty disparity object (that needs to contain at least a matrix) (disparity_obj <- fill.dispRity(disparity_obj)) ## Warning in check.data(data, match_call): Row names have been automatically ## added to data$matrix. ## ---- dispRity object ---- ## 5 elements in one matrix with 4 dimensions. ## The dipRity object has now the correct minimal attributes disparity_obj$call ## $dimensions ## [1] 1 2 3 4 7.2.1.3 get.matrix This function extracts a specific matrix from a disparity object. The matrix can be one of the bootstrapped matrices or/and a rarefied matrix. ## Extracting the matrix containing the coordinates of the elements at time 50 str(get.matrix(disparity, "50")) ## num [1:18, 1:97] -0.1 0.427 0.333 0.054 0.674 ... ## - attr(*, "dimnames")=List of 2 ## ..$ : chr [1:18] "Leptictis" "Dasypodidae" "n24" "Potamogalinae" ... ## ..$ : NULL ## Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level ## (15 elements) from the second group (80 Mya) str(get.matrix(disparity, subsets = 1, bootstrap = 3, rarefaction = 2)) ## num [1:15, 1:97] -0.134942 -0.571937 0.000589 0.266188 0.266188 ... ## - attr(*, "dimnames")=List of 2 ## ..$ : chr [1:15] "n15" "Maelestes" "n20" "n34" ... ## ..$ : NULL 7.2.1.4 n.subsets This function simply counts the number of subsets in a dispRity object. ## How many subsets are in this object? n.subsets(disparity) ## [1] 7 7.2.1.5 name.subsets This function gets you the names of the subsets in a dispRity object as a vector. ## What are they called? name.subsets(disparity) ## [1] "90" "80" "70" "60" "50" "40" "30" 7.2.1.6 size.subsets This function tells the number of elements in each subsets of a dispRity object. ## How many elements are there in each subset? size.subsets(disparity) ## 90 80 70 60 50 40 30 ## 18 22 23 21 18 15 10 7.2.1.7 get.subsets This function creates a dispRity object that contains only elements from one specific subsets. ## Extracting all the data for the crown mammals (crown_mammals <- get.subsets(disp_crown_stemBS, "Group.crown")) ## The object keeps the properties of the parent object but is composed of only one subsets length(crown_mammals$subsets) 7.2.1.8 combine.subsets This function allows to merge different subsets. ## Combine the two first subsets in the dispRity data example combine.subsets(disparity, c(1,2)) Note that the computed values (bootstrapped data + disparity metric) are not merge. 7.2.1.9 get.disparity This function extracts the calculated disparity values of a specific matrix. ## Extracting the observed disparity (default) get.disparity(disparity) ## Extracting the disparity from the bootstrapped values from the ## 10th rarefaction level from the second subsets (80 Mya) get.disparity(disparity, observed = FALSE, subsets = 2, rarefaction = 10) 7.2.1.10 scale.dispRity This is the modified S3 method for scale (scaling and/or centring) that can be applied to the disparity data of a dispRity object and can take optional arguments (for example the rescaling by dividing by a maximum value). ## Getting the disparity values of the time subsets head(summary(disparity)) ## Scaling the same disparity values head(summary(scale.dispRity(disparity, scale = TRUE))) ## Scaling and centering: head(summary(scale.dispRity(disparity, scale = TRUE, center = TRUE))) ## Rescaling the value by dividing by a maximum value head(summary(scale.dispRity(disparity, max = 10))) 7.2.1.11 sort.dispRity This is the S3 method of sort for sorting the subsets alphabetically (default) or following a specific pattern. ## Sorting the disparity subsets in inverse alphabetic order head(summary(sort(disparity, decreasing = TRUE))) ## Customised sorting head(summary(sort(disparity, sort = c(7, 1, 3, 4, 5, 2, 6)))) 7.2.1.12 get.tree add.tree and remove.tree These functions allow to manipulate the potential tree components of dispRity objects. ## Getting the tree component of a dispRity object get.tree(disparity) ## Removing the tree remove.tree(disparity) ## Adding a tree add.tree(disparity, tree = BeckLee_tree) Note that get.tree can also be used to extract trees from different subsets (custom or continuous/discrete subsets). For example, if we have three time bins like in the example below we have three time bins and we can extract the subtrees for these three time bins in different ways using the option subsets and to.root: ## Load the Beck & Lee 2014 data data(BeckLee_tree) ; data(BeckLee_mat99) ; data(BeckLee_ages) ## Time binning (discrete method) ## Generate two discrete time bins from 120 to 40 Ma every 20 Ma time_bins <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree, method = "discrete", time = c(120, 100, 80, 60), inc.nodes = TRUE, FADLAD = BeckLee_ages) ## Getting the subtrees all the way to the root root_subsets <- get.tree(time_bins, subsets = TRUE) ## Plotting the bin contents old_par <- par(mfrow = c(2,2)) plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE) axisPhylo() abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60)) for(i in 1:3) { plot(root_subsets[[i]], main = names(root_subsets)[i], show.tip.label = FALSE) axisPhylo() } par(old_par) But we can also extract the subtrees containing only branch lengths for the actual bins using to.root = FALSE: ## Getting the subtrees all the way to the root bin_subsets <- get.tree(time_bins, subsets = TRUE, to.root = FALSE) ## Plotting the bin contents old_par <- par(mfrow = c(2,2)) plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE) axisPhylo() abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60)) for(i in 1:3) { plot(bin_subsets[[i]], main = names(bin_subsets)[i], show.tip.label = FALSE) axisPhylo() } par(old_par) This can be useful for example for calculating the branch lengths in each bin: ## How many cumulated phylogenetic diversity in each bin? lapply(bin_subsets, function(tree) sum(tree$edge.length)) ## $`120 - 100` ## [1] 189.2829 ## ## $`100 - 80` ## [1] 341.7223 ## ## $`80 - 60` ## [1] 426.7486 7.3 The dispRity object content The functions above are utilities to easily and safely access different elements in the dispRity object. Alternatively, of course, each elements can be accessed manually. Here is an explanation on how it works. The dispRity object is a list of two to four elements, each of which are detailed below: $matrix: an object of class list that contains at least one object of class matrix: the full multidimensional space. $call: an object of class list containing information on the dispRity object content. $subsets: an object of class list containing the subsets of the multidimensional space. $disparity: an object of class list containing the disparity values. The dispRity object is loosely based on C structure objects. In fact, it is composed of one unique instance of a matrix (the multidimensional space) upon which the metric function is called via “pointers” to only a certain number of elements and/or dimensions of this matrix. This allows for: (1) faster and easily tractable execution time: the metric functions are called through apply family function and can be parallelised; and (2) a really low memory footprint: at any time, only one matrix (or list of matrices) is present in the R environment rather than multiple copies of it for each subset. 7.3.1 $matrix This is the multidimensional space, stored in the R environment as a list object containing one or more matrix objects. Each matrix requires row names but not column names (optional). By default, if the row names are missing, dispRity function will arbitrarily generate them in numeric order (i.e. rownames(matrix) <- 1:nrow(matrix)). This element of the dispRity object is never modified. 7.3.2 $call This element contains the information on the dispRity object content. It is a list that can contain the following: $call$subsets: a vector of character with information on the subsets type (either \"continuous\", \"discrete\" or \"custom\"), their eventual model (\"acctran\", \"deltran\", \"random\", \"proximity\", \"equal.split\", \"gradual.split\") and eventual information about the trees and matrices used through chrono.subsets. This element generated only once via chrono.subsets() and custom.subsets(). $call$dimensions: either a single numeric value indicating how many dimensions to use or a vector of numeric values indicating which specific dimensions to use. This element is by default the number of columns in $matrix but can be modified through boot.matrix() or dispRity(). $call$bootstrap: this is a list containing three elements: [[1]]: the number of bootstrap replicates (numeric) [[2]]: the bootstrap method (character) [[3]]: the rarefaction levels (numeric vector) $call$disparity: this is a list containing one element, $metric, that is a list containing the different functions passed to the metric argument in dispRity. These are call elements and get modified each time the dispRity function is used (the first element is the first metric(s), the second, the second metric(s), etc.). 7.3.3 $subsets This element contain the eventual subsets of the multidimensional space. It is a list of subset names. Each subset name is in turn a list of at least one element called elements which is in turn a matrix. This elements matrix is the raw (observed) elements in the subsets. The elements matrix is composed of numeric values in one column and n rows (the number of elements in the subset). Each of these values are a “pointer” (C inspired) to the element of the $matrix. For example, lets assume a dispRity object called disparity, composed of at least one subsets called sub1: disparity$subsets$sub1$elements [,1] [1,] 5 [2,] 4 [3,] 6 [4,] 7 The values in the matrix “point” to the elements in $matrix: here, the multidimensional space with only the 4th, 5th, 6th and 7th elements. The following elements in diparity$subsets$sub1 will correspond to the same “pointers” but drawn from the bootstrap replicates. The columns will correspond to different bootstrap replicates. For example: disparity$subsets$sub1[[2]] [,1] [,2] [,3] [,4] [1,] 57 43 70 4 [2,] 43 44 4 4 [3,] 42 84 44 1 [4,] 84 7 2 10 This signifies that we have four bootstrap pseudo-replicates pointing each time to four elements in $matrix. The next element ([[3]]) will be the same for the eventual first rarefaction level (i.e. the resulting bootstrap matrix will have m rows where m is the number of elements for this rarefaction level). The next element after that ([[4]]) will be the same for with an other rarefaction level and so forth… When a probabilistic model was used to select the elements (models that have the \"split\" suffix, e.g. chrono.subsets(..., model = \"gradual.split\")), the $elements is a matrix containing a pair of elements of the matrix and a probability for sampling the first element in that list: disparity$subsets$sub1$elements [,1] [,2] [,3] [1,] 73 36 0.01871893 [2,] 74 37 0.02555876 [3,] 33 38 0.85679821 In this example, you can read the table row by row as: “there is a probability of 0.018 for sampling element 73 and a probability of 0.82 (1-0.018) of sampling element 36”. 7.3.4 $disparity The $disparity element is identical to the $subsets element structure (a list of list(s) containing matrices) but the matrices don’t contain “pointers” to $matrix but the disparity result of the disparity metric applied to the “pointers”. For example, in our first example ($elements) from above, if the disparity metric is of dimensions level 1, we would have: disparity$disparity$sub1$elements [,1] [1,] 1.82 This is the observed disparity (1.82) for the subset called sub1. If the disparity metric is of dimension level 2 (say the function range that outputs two values), we would have: disparity$disparity$sub1$elements [,1] [1,] 0.82 [2,] 2.82 The following elements in the list follow the same logic as before: rows are disparity values (one row for a dimension level 1 metric, multiple for a dimensions level 2 metric) and columns are the bootstrap replicates (the bootstrap with all elements followed by the eventual rarefaction levels). For example for the bootstrap without rarefaction (second element of the list): disparity$disparity$sub1[[2]] [,1] [,2] [,3] [,4] [1,] 1.744668 1.777418 1.781624 1.739679 "],["disprity-ecology-demo.html", "8 dispRity ecology demo 8.1 Data 8.2 Classic analysis 8.3 A multidimensional approach with dispRity", " 8 dispRity ecology demo This is an example of typical disparity analysis that can be performed in ecology. 8.1 Data For this example, we will use the famous iris inbuilt data set data(iris) This data contains petal and sepal length for 150 individual plants sorted into three species. ## Separating the species species <- iris[,5] ## Which species? unique(species) ## [1] setosa versicolor virginica ## Levels: setosa versicolor virginica ## Separating the petal/sepal length measurements <- iris[,1:4] head(measurements) ## Sepal.Length Sepal.Width Petal.Length Petal.Width ## 1 5.1 3.5 1.4 0.2 ## 2 4.9 3.0 1.4 0.2 ## 3 4.7 3.2 1.3 0.2 ## 4 4.6 3.1 1.5 0.2 ## 5 5.0 3.6 1.4 0.2 ## 6 5.4 3.9 1.7 0.4 We can then ordinate the data using a PCA (prcomp function) thus defining our four dimensional space as the poetically named petal-space. ## Ordinating the data ordination <- prcomp(measurements) ## The petal-space petal_space <- ordination$x ## Adding the elements names to the petal-space (the individuals IDs) rownames(petal_space) <- 1:nrow(petal_space) 8.2 Classic analysis A classical way to represent this ordinated data would be to use two dimensional plots to look at how the different species are distributed in the petal-space. ## Measuring the variance on each axis axis_variances <- apply(petal_space, 2, var) axis_variances <- axis_variances/sum(axis_variances) ## Graphical option par(bty = "n") ## A classic 2D ordination plot plot(petal_space[, 1], petal_space[, 2], col = species, xlab = paste0("PC 1 (", round(axis_variances[1], 2), ")"), ylab = paste0("PC 2 (", round(axis_variances[2], 2), ")")) This shows the distribution of the different species in the petal-space along the two first axis of variation. This is a pretty standard way to visualise the multidimensional space and further analysis might be necessary to test wether the groups are different such as a linear discriminant analysis (LDA). However, in this case we are ignoring the two other dimensions of the ordination! If we look at the two other axis we see a totally different result: ## Plotting the two second axis of the petal-space plot(petal_space[, 3], petal_space[, 4], col = species, xlab = paste0("PC 3 (", round(axis_variances[3], 2), ")"), ylab = paste0("PC 4 (", round(axis_variances[4], 2), ")")) Additionally, these two represented dimensions do not represent a biological reality per se; i.e. the values on the first dimension do not represent a continuous trait (e.g. petal length), instead they just represent the ordinations of correlations between the data and some factors. Therefore, we might want to approach this problem without getting stuck in only two dimensions and consider the whole dataset as a n-dimensional object. 8.3 A multidimensional approach with dispRity The first step is to create different subsets that represent subsets of the ordinated space (i.e. sub-regions within the n-dimensional object). Each of these subsets will contain only the individuals of a specific species. ## Creating the table that contain the elements and their attributes petal_subsets <- custom.subsets(petal_space, group = list( "setosa" = which(species == "setosa"), "versicolor" = which(species == "versicolor"), "virginica" = which(species == "virginica"))) ## Visualising the dispRity object content petal_subsets ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix: ## setosa, versicolor, virginica. This created a dispRity object (more about that here) with three subsets corresponding to each subspecies. 8.3.1 Bootstrapping the data We can the bootstrap the subsets to be able test the robustness of the measured disparity to outliers. We can do that using the default options of boot.matrix (more about that here): ## Bootstrapping the data (petal_bootstrapped <- boot.matrix(petal_subsets)) ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix with 4 dimensions: ## setosa, versicolor, virginica. ## Rows were bootstrapped 100 times (method:"full"). 8.3.2 Calculating disparity Disparity can be calculated in many ways, therefore the dispRity function allows users to define their own measure of disparity. For more details on measuring disparity, see the dispRity metrics section. In this example, we are going to define disparity as the median distance between the different individuals and the centroid of the ordinated space. High values of disparity will indicate a generally high spread of points from this centroid (i.e. on average, the individuals are far apart in the ordinated space). We can define the metrics easily in the dispRity function by feeding them to the metric argument. Here we are going to feed the functions stats::median and dispRity::centroids which calculates distances between elements and their centroid. ## Calculating disparity as the median distance between each elements and ## the centroid of the petal-space (petal_disparity <- dispRity(petal_bootstrapped, metric = c(median, centroids))) ## ---- dispRity object ---- ## 3 customised subsets for 150 elements in one matrix with 4 dimensions: ## setosa, versicolor, virginica. ## Rows were bootstrapped 100 times (method:"full"). ## Disparity was calculated as: c(median, centroids). 8.3.3 Summarising the results (plot) Similarly to the custom.subsets and boot.matrix function, dispRity displays a dispRity object. But we are definitely more interested in actually look at the calculated values. First we can summarise the data in a table by simply using summary: ## Displaying the summary of the calculated disparity summary(petal_disparity) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 setosa 50 0.421 0.432 0.363 0.409 0.456 0.502 ## 2 versicolor 50 0.693 0.662 0.563 0.618 0.702 0.781 ## 3 virginica 50 0.785 0.719 0.548 0.652 0.786 0.902 We can also plot the results in a similar way: ## Graphical options par(bty = "n") ## Plotting the disparity in the petal_space plot(petal_disparity) Now contrary to simply plotting the two first axis of the PCA where we saw that the species have a different position in the two first petal-space, we can now also see that they occupy this space clearly differently! 8.3.4 Testing hypothesis Finally we can test our hypothesis that we guessed from the disparity plot (that some groups occupy different volume of the petal-space) by using the test.dispRity option. ## Running a PERMANOVA test.dispRity(petal_disparity, test = adonis.dispRity) ## Warning in test.dispRity(petal_disparity, test = adonis.dispRity): adonis.dispRity test will be applied to the data matrix, not to the calculated disparity. ## See ?adonis.dispRity for more details. ## Warning in adonis.dispRity(data, ...): The input data for adonis.dispRity was not a distance matrix. ## The results are thus based on the distance matrix for the input data (i.e. dist(data$matrix[[1]])). ## Make sure that this is the desired methodological approach! ## Permutation test for adonis under reduced model ## Permutation: free ## Number of permutations: 999 ## ## vegan::adonis2(formula = dist(matrix) ~ group, method = "euclidean") ## Df SumOfSqs R2 F Pr(>F) ## Model 2 592.07 0.86894 487.33 0.001 *** ## Residual 147 89.30 0.13106 ## Total 149 681.37 1.00000 ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## Post-hoc testing of the differences between species (corrected for multiple tests) test.dispRity(petal_disparity, test = t.test, correction = "bonferroni") ## [[1]] ## statistic: t ## setosa : versicolor -33.37334 ## setosa : virginica -28.36656 ## versicolor : virginica -5.24564 ## ## [[2]] ## parameter: df ## setosa : versicolor 166.2319 ## setosa : virginica 127.7601 ## versicolor : virginica 164.6248 ## ## [[3]] ## p.value ## setosa : versicolor 4.126944e-75 ## setosa : virginica 1.637347e-56 ## versicolor : virginica 1.420552e-06 ## ## [[4]] ## stderr ## setosa : versicolor 0.006875869 ## setosa : virginica 0.010145340 ## versicolor : virginica 0.011117360 We can now see that there is a significant difference in petal-space occupancy between all species of iris. 8.3.4.1 Setting up a multidimensional null-hypothesis One other series of test can be done on the shape of the petal-space. Using a MCMC permutation test we can simulate a petal-space with specific properties and see if our observed petal-space matches these properties (similarly to Dı́az et al. (2016)): ## Testing against a uniform distribution disparity_uniform <- null.test(petal_disparity, replicates = 200, null.distrib = runif, scale = FALSE) plot(disparity_uniform) ## Testing against a normal distribution disparity_normal <- null.test(petal_disparity, replicates = 200, null.distrib = rnorm, scale = TRUE) plot(disparity_normal) In both cases we can see that our petal-space is not entirely normal or uniform. This is expected because of the simplicity of these parameters. References "],["palaeobiology-demo-disparity-through-time-and-within-groups.html", "9 Palaeobiology demo: disparity-through-time and within groups 9.1 Before starting 9.2 A disparity-through-time analysis 9.3 Some more advanced stuff", " 9 Palaeobiology demo: disparity-through-time and within groups This demo aims to give quick overview of the dispRity package (v.1.7) for palaeobiology analyses of disparity, including disparity through time analyses. This demo showcases a typical disparity-through-time analysis: we are going to test whether the disparity changed through time in a subset of eutherian mammals from the last 100 million years using a dataset from Beck and Lee (2014). 9.1 Before starting 9.1.1 The morphospace In this example, we are going to use a subset of the data from Beck and Lee (2014). See the example data description for more details. Briefly, this dataset contains an ordinated matrix of the Gower distance between 50 mammals based (BeckLee_mat50), another matrix of the same 50 mammals and the estimated discrete data characters of their descendants (thus 50 + 49 rows, BeckLee_mat99), a dataframe containing the ages of each taxon in the dataset (BeckLee_ages) and finally a phylogenetic tree with the relationships among the 50 mammals (BeckLee_tree). The ordinated matrix will represent our full morphospace, i.e. all the mammalian morphologies that ever existed through time (for this dataset). ## Loading demo and the package data library(dispRity) ## Setting the random seed for repeatability set.seed(123) ## Loading the ordinated matrix/morphospace: data(BeckLee_mat50) data(BeckLee_mat99) head(BeckLee_mat50[,1:5]) ## [,1] [,2] [,3] [,4] [,5] ## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084 0.18825039 ## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995 0.28510479 ## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511 0.07132646 ## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160 0.39962626 ## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351 0.37385914 ## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782 0.34857351 dim(BeckLee_mat50) ## [1] 50 48 ## The morphospace contains 50 taxa and has 48 dimensions (or axes) ## Showing a list of first and last occurrences data for some fossils data(BeckLee_ages) head(BeckLee_ages) ## FAD LAD ## Adapis 37.2 36.8 ## Asioryctes 83.6 72.1 ## Leptictis 33.9 33.3 ## Miacis 49.0 46.7 ## Mimotona 61.6 59.2 ## Notharctus 50.2 47.0 ## Plotting a phylogeny data(BeckLee_tree) plot(BeckLee_tree, cex = 0.7) axisPhylo(root = 140) You can have an even nicer looking tree if you use the strap package! if(!require(strap)) install.packages("strap") strap::geoscalePhylo(BeckLee_tree, cex.tip = 0.7, cex.ts = 0.6) 9.1.2 Setting up your own data I greatly encourage you to follow along this tutorial with your very own data: it is more exciting and, ultimately, that’s probably your objective. What data can I use? You can use any type of morphospace in any dataset form (\"matrix\", \"data.frame\"). Throughout this tutorial, you we assume you are using the (loose) morphospace definition from Thomas Guillerme, Cooper, et al. (2020): any matrix were columns are traits and rows are observations (in a distance matrix, columns are still trait, i.e. “distance to species A”, etc.). We won’t cover it here but you can also use lists of matrices and list of trees. How should I format my data for this tutorial? To go through this tutorial you will need: A matrix with tip data A phylogenetic tree A matrix with tip and node data A table of first and last occurrences data (FADLAD) If you are missing any of these, fear not, here are a couple of functions to simulate the missing data, it will surely make your results look funky but it’ll let you go through the tutorial. WARNING: the data generated by the functions i.need.a.matrix, i.need.a.tree, i.need.node.data and i.need.FADLAD are used to SIMULATE data for this tutorial. This is not to be used for publications or analysing real data! If you need a data matrix, a phylogenetic tree or FADLAD data, (i.need.a.matrix, i.need.a.tree and i.need.FADLAD), you will actually need to collect data from the literature or the field! If you need node data, you will need to use ancestral states estimations (e.g. using estimate_ancestral_states from the Claddis package). ## Functions to get simulate a PCO looking like matrix from a tree i.need.a.matrix <- function(tree) { matrix <- space.maker(elements = Ntip(tree), dimensions = Ntip(tree), distribution = rnorm, scree = rev(cumsum(rep(1/Ntip(tree), Ntip(tree))))) rownames(matrix) <- tree$tip.label return(matrix) } ## Function to simulate a tree i.need.a.tree <- function(matrix) { tree <- rtree(nrow(matrix)) tree$root.time <- max(tree.age(tree)$age) tree$tip.label <- rownames(matrix) tree$node.label <- paste0("n", 1:(nrow(matrix)-1)) return(tree) } ## Function to simulate some "node" data i.need.node.data <- function(matrix, tree) { matrix_node <- space.maker(elements = Nnode(tree), dimensions = ncol(matrix), distribution = rnorm, scree = apply(matrix, 2, var)) if(!is.null(tree$node.label)) { rownames(matrix_node) <- tree$node.label } else { rownames(matrix_node) <- paste0("n", 1:(nrow(matrix)-1)) } return(rbind(matrix, matrix_node)) } ## Function to simulate some "FADLAD" data i.need.FADLAD <- function(tree) { tree_ages <- tree.age(tree)[1:Ntip(tree),] return(data.frame(FAD = tree_ages[,1], LAD = tree_ages[,1], row.names = tree_ages[,2])) } You can use these functions for the generating the data you need. For example ## Aaaaah I don't have FADLAD data! my_FADLAD <- i.need.FADLAD(tree) ## Sorted. In the end this is what your data should be named to facilitate the rest of this tutorial (fill in yours here): ## A matrix with tip data my_matrix <- BeckLee_mat50 ## A phylogenetic tree my_tree <- BeckLee_tree ## A matrix with tip and node data my_tip_node_matrix <- BeckLee_mat99 ## A table of first and last occurrences data (FADLAD) my_fadlad <- BeckLee_ages 9.2 A disparity-through-time analysis 9.2.1 Splitting the morphospace through time One of the crucial steps in disparity-through-time analysis is to split the full morphospace into smaller time subsets that contain the total number of morphologies at certain points in time (time-slicing) or during certain periods in time (time-binning). Basically, the full morphospace represents the total number of morphologies across all time and will be greater than any of the time subsets of the morphospace. The dispRity package provides a chrono.subsets function that allows users to split the morphospace into time slices (using method = continuous) or into time bins (using method = discrete). In this example, we are going to split the morphospace into five equal time bins of 20 million years long from 100 million years ago to the present. We will also provide to the function a table containing the first and last occurrences dates for some fossils to take into account that some fossils might occur in several of our different time bins. ## Creating the vector of time bins ages time_bins <- rev(seq(from = 0, to = 100, by = 20)) ## Splitting the morphospace using the chrono.subsets function binned_morphospace <- chrono.subsets(data = my_matrix, tree = my_tree, method = "discrete", time = time_bins, inc.nodes = FALSE, FADLAD = my_fadlad) The output object is a dispRity object (see more about that here. In brief, dispRity objects are lists of different elements (i.e. disparity results, morphospace time subsets, morphospace attributes, etc.) that display only a summary of the object when calling the object to avoiding filling the R console with superfluous output. It also allows easy plotting/summarising/analysing for repeatability down the line but we will not go into this right now. ## Printing the class of the object class(binned_morphospace) ## [1] "dispRity" ## Printing the content of the object str(binned_morphospace) ## List of 4 ## $ matrix :List of 1 ## ..$ : num [1:50, 1:48] -0.561 -0.419 -0.834 -0.771 -0.832 ... ## .. ..- attr(*, "dimnames")=List of 2 ## .. .. ..$ : chr [1:50] "Cimolestes" "Maelestes" "Batodon" "Bulaklestes" ... ## .. .. ..$ : NULL ## $ tree :Class "multiPhylo" ## List of 1 ## ..$ :List of 6 ## .. ..$ edge : int [1:98, 1:2] 51 52 52 53 53 51 54 55 56 56 ... ## .. ..$ edge.length: num [1:98] 24.5 24.6 12.7 11.8 11.8 ... ## .. ..$ Nnode : int 49 ## .. ..$ tip.label : chr [1:50] "Daulestes" "Bulaklestes" "Uchkudukodon" "Kennalestes" ... ## .. ..$ node.labels: chr [1:49] "n1" "n2" "n3" "n4" ... ## .. ..$ root.time : num 139 ## .. ..- attr(*, "class")= chr "phylo" ## .. ..- attr(*, "order")= chr "cladewise" ## $ call :List of 1 ## ..$ subsets: Named chr [1:4] "discrete" "1" "1" "FALSE" ## .. ..- attr(*, "names")= chr [1:4] "" "trees" "matrices" "bind" ## $ subsets:List of 5 ## ..$ 100 - 80:List of 1 ## .. ..$ elements: int [1:8, 1] 5 4 6 8 43 10 11 42 ## ..$ 80 - 60 :List of 1 ## .. ..$ elements: int [1:15, 1] 7 8 9 1 2 3 12 13 14 44 ... ## ..$ 60 - 40 :List of 1 ## .. ..$ elements: int [1:13, 1] 41 49 24 25 26 27 28 21 22 19 ... ## ..$ 40 - 20 :List of 1 ## .. ..$ elements: int [1:6, 1] 15 39 40 35 23 47 ## ..$ 20 - 0 :List of 1 ## .. ..$ elements: int [1:10, 1] 36 37 38 32 33 34 50 48 29 30 ## - attr(*, "class")= chr "dispRity" names(binned_morphospace) ## [1] "matrix" "tree" "call" "subsets" ## Printing the object as a dispRity class binned_morphospace ## ---- dispRity object ---- ## 5 discrete time subsets for 50 elements in one matrix with 1 phylogenetic tree ## 100 - 80, 80 - 60, 60 - 40, 40 - 20, 20 - 0. These objects will gradually contain more information when completing the following steps in the disparity-through-time analysis. 9.2.2 Bootstrapping the data Once we obtain our different time subsets, we can bootstrap and rarefy them (i.e. pseudo-replicating the data). The bootstrapping allows us to make each subset more robust to outliers and the rarefaction allows us to compare subsets with the same number of taxa to remove sampling biases (i.e. more taxa in one subset than the others). The boot.matrix function bootstraps the dispRity object and the rarefaction option within performs rarefaction. ## Getting the minimum number of rows (i.e. taxa) in the time subsets minimum_size <- min(size.subsets(binned_morphospace)) ## Bootstrapping each time subset 100 times and rarefying them rare_bin_morphospace <- boot.matrix(binned_morphospace, bootstraps = 100, rarefaction = minimum_size) Note how information is adding up to the dispRity object. 9.2.3 Calculating disparity We can now calculate the disparity within each time subsets along with some confidence intervals generated by the pseudoreplication step above (bootstraps/rarefaction). Disparity can be calculated in many ways and this package allows users to come up with their own disparity metrics. For more details, please refer to the dispRity metric section (or directly use moms). In this example, we are going to look at how the spread of the data in the morphospace through time. For that we are going to use the sum of the variance from each dimension of the morphospace in the morphospace. We highly recommend using a metric that makes sense for your specific analysis and for your specific dataset and not just because everyone uses it Thomas Guillerme, Cooper, et al. (2020)! How can I be sure that the metric is the most appropriate for my morphospace and question? This is not a straightforward question but you can use the test.metric function to check your assumptions (more details here): basically what test.metric does is modifying your morphospace using a null process of interest (e.g. changes in size) and checks whether your metric does indeed pick up that change. For example here, let see if the sum of variances picks up changes in size but not random changes: my_test <- test.metric(my_matrix, metric = c(sum, dispRity::variances), shifts = c("random", "size")) summary(my_test) ## 10% 20% 30% 40% 50% 60% 70% 80% 90% 100% slope ## random 2.53 2.50 2.56 2.50 2.54 2.51 2.52 2.53 2.53 2.52 0.0003234646 ## size.increase 2.23 2.17 2.25 2.26 2.31 2.35 2.39 2.47 2.50 2.52 0.0037712409 ## size.hollowness 2.40 2.50 2.59 2.65 2.63 2.62 2.60 2.57 2.55 2.52 0.0008954035 ## p_value R^2(adj) ## random 9.689431e-02 0.06301936 ## size.increase 1.016309e-17 0.93443767 ## size.hollowness 6.630162e-02 0.08377594 plot(my_test) We see that changes in the inner size (see Thomas Guillerme, Puttick, et al. (2020) for more details) is actually picked up by the sum of variances but not random changes or outer changes. Which is a good thing! As you’ve noted, the sum of variances is defined in test.metric as c(sum, variances). This is a core bit of the dispRity package were you can define your own metric as a function or a set of functions. You can find more info about this in the dispRity metric section but in brief, the dispRity package considers metrics by their “dimensions” level which corresponds to what they output. For example, the function sum is a dimension level 1 function because no matter the input it outputs a single value (the sum), variances on the other hand is a dimension level 2 function because it will output the variance of each column in a matrix (an example of a dimensions level 3 would be the function var that outputs a matrix). The dispRity package always automatically sorts the dimensions levels: it will always run dimensions level 3 > dimensions level 2 > and dimensions level 1. In this case both c(sum, variances) and c(variances, sum) will result in actually running sum(variances(matrix)). Anyways, let’s calculate the sum of variances on our bootstrapped and rarefied morphospaces: ## Calculating disparity for the bootstrapped and rarefied data disparity <- dispRity(rare_bin_morphospace , metric = c(sum, dispRity::variances)) To display the actual calculated scores, we need to summarise the disparity object using the S3 method summary that is applied to a dispRity object (see ?summary.dispRity for more details). By the way, as for any R package, you can refer to the help files for each individual function for more details. ## Summarising the disparity results summary(disparity) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 100 - 80 8 2.207 1.962 1.615 1.876 2.017 2.172 ## 2 100 - 80 6 NA 1.923 1.477 1.768 2.065 2.222 ## 3 80 - 60 15 2.315 2.167 1.979 2.111 2.227 2.308 ## 4 80 - 60 6 NA 2.167 1.831 2.055 2.300 2.460 ## 5 60 - 40 13 2.435 2.244 2.006 2.183 2.304 2.384 ## 6 60 - 40 6 NA 2.284 1.683 2.140 2.383 2.532 ## 7 40 - 20 6 2.604 2.206 1.628 2.026 2.388 2.604 ## 8 20 - 0 10 2.491 2.257 1.958 2.170 2.326 2.421 ## 9 20 - 0 6 NA 2.302 1.766 2.143 2.366 2.528 The summary.dispRity function comes with many options on which values to calculate (central tendency and quantiles) and on how many digits to display. Refer to the function’s manual for more details. 9.2.4 Plotting the results It is sometimes easier to visualise the results in a plot than in a table. For that we can use the plot S3 function to plot the dispRity objects (see ?plot.dispRity for more details). ## Graphical options quartz(width = 10, height = 5) ; par(mfrow = (c(1,2)), bty = "n") ## Warning in quartz(width = 10, height = 5): Quartz device is not available on ## this platform ## Plotting the bootstrapped and rarefied results plot(disparity, type = "continuous", main = "bootstrapped results") plot(disparity, type = "continuous", main = "rarefied results", rarefaction = minimum_size) Nice. The curves look pretty similar. Same as for the summary.dispRity function, check out the plot.dispRity manual for the many, many options available. 9.2.5 Testing differences Finally, to draw some valid conclusions from these results, we can apply some statistical tests. We can test, for example, if mammalian disparity changed significantly through time over the last 100 million years. To do so, we can compare the means of each time-bin in a sequential manner to see whether the disparity in bin n is equal to the disparity in bin n+1, and whether this is in turn equal to the disparity in bin n+2, etc. Because our data is temporally autocorrelated (i.e. what happens in bin n+1 depends on what happened in bin n) and pseudoreplicated (i.e. each bootstrap draw creates non-independent time subsets because they are all based on the same time subsets), we apply a non-parametric mean comparison: the wilcox.test. Also, we need to apply a p-value correction (e.g. Bonferroni correction) to correct for multiple testing (see ?p.adjust for more details). ## Testing the differences between bins in the bootstrapped dataset. test.dispRity(disparity, test = wilcox.test, comparison = "sequential", correction = "bonferroni") ## [[1]] ## statistic: W ## 100 - 80 : 80 - 60 730 ## 80 - 60 : 60 - 40 2752 ## 60 - 40 : 40 - 20 5461 ## 40 - 20 : 20 - 0 4506 ## ## [[2]] ## p.value ## 100 - 80 : 80 - 60 7.081171e-25 ## 80 - 60 : 60 - 40 1.593988e-07 ## 60 - 40 : 40 - 20 1.000000e+00 ## 40 - 20 : 20 - 0 9.115419e-01 ## Testing the differences between bins in the rarefied dataset. test.dispRity(disparity, test = wilcox.test, comparison = "sequential", correction = "bonferroni", rarefaction = minimum_size) ## [[1]] ## statistic: W ## 100 - 80 : 80 - 60 1518 ## 80 - 60 : 60 - 40 3722 ## 60 - 40 : 40 - 20 5676 ## 40 - 20 : 20 - 0 4160 ## ## [[2]] ## p.value ## 100 - 80 : 80 - 60 7.158946e-17 ## 80 - 60 : 60 - 40 7.199018e-03 ## 60 - 40 : 40 - 20 3.953427e-01 ## 40 - 20 : 20 - 0 1.609715e-01 Here our results show significant changes in disparity through time between all time bins (all p-values < 0.05). However, when looking at the rarefied results, there is no significant difference between the time bins in the Palaeogene (60-40 to 40-20 Mya), suggesting that the differences detected in the first test might just be due to the differences in number of taxa sampled (13 or 6 taxa) in each time bin. 9.3 Some more advanced stuff The previous section detailed some of the basic functionalities in the dispRity package but of course, you can do some much more advanced analysis, here is just a list of some specific tutorials from this manual that you might be interested in: Time slicing: an alternative method to look at disparity through time that allows you to specify evolutionary models (T. Guillerme and Cooper 2018). Many more disparity metrics: there are many, many different things you might be interested to measure in your morphospace! This manual has some extended documentation on what to use (or check Thomas Guillerme, Puttick, et al. (2020)). Many more ways to look at disparity: you can for example, use distributions rather than point estimates for your disparity metric (e.g. the variances rather than the sum of variances); or calculate disparity from non ordinated matrices or even from multiple matrices and trees. And finally there are much more advanced statistical tests you might be interested in using, such as the NPMANOVA, the “disparity-through-time test”, using a null model approach or some model fitting… You can even come up with your own ideas, implementations and modifications of the package: the dispRity package is a modular and collaborative package and I encourage you to contact me (guillert@tcd.e) for any ideas you have about adding new features to the package (whether you have them already implemented or not)! References "],["morphometric-geometric-demo-a-between-group-analysis.html", "10 Morphometric geometric demo: a between group analysis 10.1 Before starting 10.2 Calculating disparity 10.3 Analyse the results", " 10 Morphometric geometric demo: a between group analysis This demo aims to give quick overview of the dispRity package (v.1.7) for palaeobiology analyses of disparity, including disparity through time analyses. This demo showcases a typical between groups geometric morphometric analysis: we are going to test whether the disparity in two species of salamander (plethodons!) are different and in which ways they are different. 10.1 Before starting Here we are going to use the geomorph plethodon dataset that is a set of 12 2D landmark coordinates for 40 specimens from two species of salamanders. This section will really quickly cover how to make a Procrustes sumperimposition analysis and create a geomorph data.frame to have data ready for the dispRity package. ## Loading geomorph library(geomorph) ## Loading the plethodon dataset data(plethodon) ## Running a simple Procrustes superimposition gpa_plethodon <- gpagen(plethodon$land) ## ## Performing GPA ## | | | 0% | |================== | 25% | |=================================== | 50% | |======================================================================| 100% ## ## Making projections... Finished! ## Making a geomorph data frame object with the species and sites attributes gdf_plethodon <- geomorph.data.frame(gpa_plethodon, species = plethodon$species, site = plethodon$site) You can of course use your very own landmark coordinates dataset (though you will have to do some modifications in the scripts that will come below - they will be easy though!). ## You can replace the gdf_plethodon by your own geomorph data frame! my_geomorph_data <- gdf_plethodon 10.1.1 The morphospace The first step of every disparity analysis is to define your morphospace. Note that this is actually not true at all and kept as a erroneous sentence: the first step of your disparity analysis should be to define your question! Our question here will be: is there a difference in disparity between the different species of salamanders and between the different sites (allopatric and sympatric)? OK, now we can go to the second step of every disparity analysis: defining the morphospace. Here we will define it with the ordination of all possible Procrustes superimposed plethodon landmark coordinates. You can do this directly in dispRity using the geomorph.ordination function that can input a geomorph data frame: ## The morphospace morphospace <- geomorph.ordination(gdf_plethodon) This automatically generates a dispRity object with the information of each groups. You can find more information about dispRity objects here but basically it summarises the content of your object without spamming your R console and is associated with many utility functions like summary or plot. For example here you can quickly visualise the two first dimensions of your space using the plot function: ## The dispRity object morphospace ## ---- dispRity object ---- ## 4 customised subsets for 40 elements in one matrix: ## species.Jord, species.Teyah, site.Allo, site.Symp. ## Plotting the morphospace plot(morphospace) ## Note that this only displays the two last groups (site.Allo and site.Symp) since they overlap! The dispRity package function comes with a lot of documentation of examples so don’t hesitate to type plot.dispRity to check more plotting options. 10.2 Calculating disparity Now that we have our morphospace, we can think about what we want to measure. Two aspects of disparity that would be interesting for our question (is there a difference in disparity between the different species of salamanders and between the different sites?) would be the differences in size in the morphospace (do both groups occupy the same amount of morphospace) and position in the morphospace (do the do groups occupy the same position in the morphospace?). To choose which metric would cover best these two aspects, please check the Thomas Guillerme, Puttick, et al. (2020) paper and associated app. Here we are going to use the procrustes variance (geomorph::morphol.disparity) for measuring the size of the trait space and the average displacements (Thomas Guillerme, Puttick, et al. 2020) for the position in the trait space. ## Defining a the procrustes variance metric ## (as in geomorph::morphol.disparity) proc.var <- function(matrix) {sum(matrix^2)/nrow(matrix)} ## The size metric test_size <- test.metric(morphospace, metric = proc.var, shifts = c("random", "size")) plot(test_size) summary(test_size) ## The position metric test_position <- test.metric(morphospace, metric = c(mean, displacements), shifts = c("random", "position")) plot(test_position) summary(test_position) You can see here for more details on the test.metric function but basically these graphs are showing that there is a relation between changes in size and in position for each metric. Note that there are some caveats here but the selection of the metric is just for the sake of the example! Note also the format of defining the disparity metrics here using metric = c(mean, displacements) or metric = proc.var. This is a core bit of the dispRity package were you can define your own metric as a function or a set of functions. You can find more info about this in the dispRity metric section but in brief, the dispRity package considers metrics by their “dimensions” level which corresponds to what they output. For example, the function mean is a dimension level 1 function because no matter the input it outputs a single value (the mean), displacements on the other hand is a dimension level 2 function because it will output the ratio between the distance from the centroid and from the centre of the trait space for each row in a matrix (an example of a dimensions level 3 would be the function var that outputs a matrix). The dispRity package always automatically sorts the dimensions levels: it will always run dimensions level 3 > dimensions level 2 > and dimensions level 1. In this case both c(mean, displacements) and c(mean, displacements) will result in actually running mean(displacements(matrix)). Alternatively you can define your metric prior to the disparity analysis like we did for the proc.var function. Anyways, we can measure disparity using these two metrics on all the groups as follows: ## Bootstrapped disparity disparity_size <- dispRity(boot.matrix(morphospace), metric = proc.var) disparity_position <- dispRity(boot.matrix(morphospace), metric = c(mean, displacements)) Note that here we use the boot.matrix function for quickly bootstrapping the matrix. This is not an essential step in this kind of analysis but it allows to “reduce” the effect of outliers and create a distribution of disparity measures (rather than single point estimates). 10.3 Analyse the results We can visualise the results using the plot function on the resulting disparity objects (or summarising them using summary): ## Plotting the results par(mfrow = c(1,2)) plot(disparity_size, main = "group sizes", las = 2, xlab = "") plot(disparity_position, main = "group positions", las = 2, xlab = "") ## Summarising the results summary(disparity_size) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 species.Jord 20 0.005 0.005 0.004 0.005 0.005 0.005 ## 2 species.Teyah 20 0.005 0.005 0.004 0.005 0.005 0.006 ## 3 site.Allo 20 0.004 0.004 0.003 0.003 0.004 0.004 ## 4 site.Symp 20 0.006 0.006 0.006 0.006 0.006 0.007 summary(disparity_position) ## subsets n obs bs.median 2.5% 25% 75% 97.5% ## 1 species.Jord 20 1.096 1.122 1.069 1.104 1.168 1.404 ## 2 species.Teyah 20 1.070 1.095 1.029 1.070 1.146 1.320 ## 3 site.Allo 20 1.377 1.415 1.311 1.369 1.464 1.526 ## 4 site.Symp 20 1.168 1.220 1.158 1.190 1.270 1.498 Just from looking at the data, we can guess that there is not much difference in terms of morphospace occupancy and position for the species but there is on for the sites (allopatric or sympatric). We can test it using a simple non-parametric mean difference test (e.g. wilcox.test) using the dispRity package. ## Testing the differences test.dispRity(disparity_size, test = wilcox.test, correction = "bonferroni") ## [[1]] ## statistic: W ## species.Jord : species.Teyah 3842 ## species.Jord : site.Allo 9919 ## species.Jord : site.Symp 7 ## species.Teyah : site.Allo 9939 ## species.Teyah : site.Symp 155 ## site.Allo : site.Symp 0 ## ## [[2]] ## p.value ## species.Jord : species.Teyah 2.808435e-02 ## species.Jord : site.Allo 1.718817e-32 ## species.Jord : site.Symp 1.896841e-33 ## species.Teyah : site.Allo 9.504256e-33 ## species.Teyah : site.Symp 1.507734e-31 ## site.Allo : site.Symp 1.537286e-33 test.dispRity(disparity_position, test = wilcox.test, correction = "bonferroni") ## [[1]] ## statistic: W ## species.Jord : species.Teyah 6639 ## species.Jord : site.Allo 262 ## species.Jord : site.Symp 1386 ## species.Teyah : site.Allo 91 ## species.Teyah : site.Symp 981 ## site.Allo : site.Symp 9373 ## ## [[2]] ## p.value ## species.Jord : species.Teyah 3.744848e-04 ## species.Jord : site.Allo 3.288928e-30 ## species.Jord : site.Symp 6.326430e-18 ## species.Teyah : site.Allo 2.309399e-32 ## species.Teyah : site.Symp 5.609280e-22 ## site.Allo : site.Symp 7.278818e-26 So by applying the tests we see a difference in terms of position between each groups and differences in size between groups but between the species. References "],["disprity-r-package-manual.html", "11 dispRity R package manual", " 11 dispRity R package manual "],["references.html", "References", " References "],["references-1.html", "12 References", " 12 References "],["404.html", "Page not found", " Page not found The page you requested cannot be found (perhaps it was moved or renamed). You may want to try searching to find the page's new location, or use the table of contents to find the page you are looking for. "]]
diff --git a/inst/gitbook/_book/the-guts-of-the-disprity-package.html b/inst/gitbook/_book/the-guts-of-the-disprity-package.html
index 214e7b64..5d18980b 100644
--- a/inst/gitbook/_book/the-guts-of-the-disprity-package.html
+++ b/inst/gitbook/_book/the-guts-of-the-disprity-package.html
@@ -23,7 +23,7 @@
-
+
@@ -49,38 +49,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -205,7 +227,11 @@
4.1.2 Time-slicing
4.2 Customised subsets
-4.3 Bootstraps and rarefactions
+4.3 Bootstraps and rarefactions
+
4.4 Disparity metrics
+4.13 Disparity and distances
+
5 Making stuff up!
@@ -273,13 +304,15 @@
- 6.7
pair.plot
- 6.8
reduce.matrix
- 6.9
select.axes
-- 6.10
slice.tree
-- 6.11
slide.nodes
and remove.zero.brlen
-- 6.12
tree.age
-- 6.13
multi.ace
-
- 7 The guts of the
dispRity
package
@@ -293,7 +326,7 @@
@@ -369,26 +402,26 @@ 7.1 Manipulating dispRity
dispRity
also contains various utility functions that manipulate the dispRity
object (e.g. sort.dispRity
, extract.dispRity
see the full list in the next section).
These functions modify the dispRity
object without having to delve into its complex structure!
The full structure of a dispRity
object is detailed here.
-## Loading the example data
-data(disparity)
-
-## What is the class of the median_centroids object?
-class(disparity)
+## Loading the example data
+data(disparity)
+
+## What is the class of the median_centroids object?
+class(disparity)
## [1] "dispRity"
-## What does the object contain?
-names(disparity)
+
## [1] "matrix" "tree" "call" "subsets" "disparity"
-## Summarising it using the S3 method print.dispRity
- disparity
+
## ---- dispRity object ----
## 7 continuous (acctran) time subsets for 99 elements in one matrix with 97 dimensions with 1 phylogenetic tree
## 90, 80, 70, 60, 50 ...
-## Data was bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements.
+## Rows were bootstrapped 100 times (method:"full") and rarefied to 20, 15, 10, 5 elements.
## Disparity was calculated as: c(median, centroids).
Note that it is always possible to recall the full object using the argument all = TRUE
in print.dispRity
:
-## Display the full object
-print(disparity, all = TRUE)
-## This is more nearly ~ 5000 lines on my 13 inch laptop screen!
+
7.2 dispRity
utilities
@@ -399,28 +432,28 @@ 7.2.1 dispRity
objec
7.2.1.1 make.dispRity
This function creates empty dispRity
objects.
-## Creating an empty dispRity object
-make.dispRity()
+
## Empty dispRity object.
-## Creating an "empty" dispRity object with a matrix
- make.dispRity(matrix(rnorm(20), 5, 4))) (disparity_obj <-
+## Creating an "empty" dispRity object with a matrix
+(disparity_obj <- make.dispRity(matrix(rnorm(20), 5, 4)))
## ---- dispRity object ----
## Contains a matrix 5x4.
7.2.1.2 fill.dispRity
This function initialises a dispRity
object and generates its call properties.
-## The dispRity object's call is indeed empty
-$call disparity_obj
+
## list()
-## Filling an empty disparity object (that needs to contain at least a matrix)
- fill.dispRity(disparity_obj)) (disparity_obj <-
+## Filling an empty disparity object (that needs to contain at least a matrix)
+(disparity_obj <- fill.dispRity(disparity_obj))
## Warning in check.data(data, match_call): Row names have been automatically
## added to data$matrix.
## ---- dispRity object ----
## 5 elements in one matrix with 4 dimensions.
-## The dipRity object has now the correct minimal attributes
-$call disparity_obj
+
## $dimensions
## [1] 1 2 3 4
@@ -428,16 +461,16 @@ 7.2.1.2 fill.dispRity
7.2.1.3 get.matrix
This function extracts a specific matrix from a disparity object.
The matrix can be one of the bootstrapped matrices or/and a rarefied matrix.
-## Extracting the matrix containing the coordinates of the elements at time 50
-str(get.matrix(disparity, "50"))
-## num [1:18, 1:97] -0.1036 0.4318 0.3371 0.0501 0.685 ...
+## Extracting the matrix containing the coordinates of the elements at time 50
+str(get.matrix(disparity, "50"))
+## num [1:18, 1:97] -0.1 0.427 0.333 0.054 0.674 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:18] "Leptictis" "Dasypodidae" "n24" "Potamogalinae" ...
## ..$ : NULL
-## Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level
-## (15 elements) from the second group (80 Mya)
-str(get.matrix(disparity, subsets = 1, bootstrap = 3, rarefaction = 2))
-## num [1:15, 1:97] -0.12948 -0.57973 0.00361 0.27123 0.27123 ...
+## Extracting the 3rd bootstrapped matrix with the 2nd rarefaction level
+## (15 elements) from the second group (80 Mya)
+str(get.matrix(disparity, subsets = 1, bootstrap = 3, rarefaction = 2))
+## num [1:15, 1:97] -0.134942 -0.571937 0.000589 0.266188 0.266188 ...
## - attr(*, "dimnames")=List of 2
## ..$ : chr [1:15] "n15" "Maelestes" "n20" "n34" ...
## ..$ : NULL
@@ -445,139 +478,139 @@ 7.2.1.3 get.matrix
7.2.1.4 n.subsets
This function simply counts the number of subsets in a dispRity
object.
-## How many subsets are in this object?
-n.subsets(disparity)
+
## [1] 7
7.2.1.5 name.subsets
This function gets you the names of the subsets in a dispRity
object as a vector.
-## What are they called?
-name.subsets(disparity)
+
## [1] "90" "80" "70" "60" "50" "40" "30"
7.2.1.6 size.subsets
This function tells the number of elements in each subsets of a dispRity
object.
-## How many elements are there in each subset?
-size.subsets(disparity)
+
## 90 80 70 60 50 40 30
## 18 22 23 21 18 15 10
7.2.1.7 get.subsets
This function creates a dispRity object that contains only elements from one specific subsets.
-## Extracting all the data for the crown mammals
- get.subsets(disp_crown_stemBS, "Group.crown"))
- (crown_mammals <-
-## The object keeps the properties of the parent object but is composed of only one subsets
-length(crown_mammals$subsets)
+
7.2.1.8 combine.subsets
This function allows to merge different subsets.
-## Combine the two first subsets in the dispRity data example
-combine.subsets(disparity, c(1,2))
+
Note that the computed values (bootstrapped data + disparity metric) are not merge.
7.2.1.9 get.disparity
This function extracts the calculated disparity values of a specific matrix.
-## Extracting the observed disparity (default)
-get.disparity(disparity)
-
-## Extracting the disparity from the bootstrapped values from the
-## 10th rarefaction level from the second subsets (80 Mya)
-get.disparity(disparity, observed = FALSE, subsets = 2, rarefaction = 10)
+
7.2.1.10 scale.dispRity
This is the modified S3 method for scale
(scaling and/or centring) that can be applied to the disparity data of a dispRity
object and can take optional arguments (for example the rescaling by dividing by a maximum value).
-## Getting the disparity values of the time subsets
-head(summary(disparity))
-
-## Scaling the same disparity values
-head(summary(scale.dispRity(disparity, scale = TRUE)))
-
-## Scaling and centering:
-head(summary(scale.dispRity(disparity, scale = TRUE, center = TRUE)))
-
-## Rescaling the value by dividing by a maximum value
-head(summary(scale.dispRity(disparity, max = 10)))
+## Getting the disparity values of the time subsets
+head(summary(disparity))
+
+## Scaling the same disparity values
+head(summary(scale.dispRity(disparity, scale = TRUE)))
+
+## Scaling and centering:
+head(summary(scale.dispRity(disparity, scale = TRUE, center = TRUE)))
+
+## Rescaling the value by dividing by a maximum value
+head(summary(scale.dispRity(disparity, max = 10)))
7.2.1.11 sort.dispRity
This is the S3 method of sort
for sorting the subsets alphabetically (default) or following a specific pattern.
-## Sorting the disparity subsets in inverse alphabetic order
-head(summary(sort(disparity, decreasing = TRUE)))
-
-## Customised sorting
-head(summary(sort(disparity, sort = c(7, 1, 3, 4, 5, 2, 6))))
+
7.2.1.12 get.tree
add.tree
and remove.tree
These functions allow to manipulate the potential tree components of dispRity
objects.
-## Getting the tree component of a dispRity object
-get.tree(disparity)
-
-## Removing the tree
-remove.tree(disparity)
-
-## Adding a tree
-add.tree(disparity, tree = BeckLee_tree)
+## Getting the tree component of a dispRity object
+get.tree(disparity)
+
+## Removing the tree
+remove.tree(disparity)
+
+## Adding a tree
+add.tree(disparity, tree = BeckLee_tree)
Note that get.tree
can also be used to extract trees from different subsets (custom or continuous/discrete subsets).
For example, if we have three time bins like in the example below we have three time bins and we can extract the subtrees for these three time bins in different ways using the option subsets
and to.root
:
-## Load the Beck & Lee 2014 data
-data(BeckLee_tree) ; data(BeckLee_mat99) ; data(BeckLee_ages)
-
-## Time binning (discrete method)
-## Generate two discrete time bins from 120 to 40 Ma every 20 Ma
- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree,
- time_bins <-method = "discrete", time = c(120, 100, 80, 60),
- inc.nodes = TRUE, FADLAD = BeckLee_ages)
-
-## Getting the subtrees all the way to the root
- get.tree(time_bins, subsets = TRUE)
- root_subsets <-
-## Plotting the bin contents
- par(mfrow = c(2,2))
- old_par <-plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE)
-axisPhylo()
-abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60))
-for(i in 1:3) {
-plot(root_subsets[[i]], main = names(root_subsets)[i],
- show.tip.label = FALSE)
- axisPhylo()
- }
-
-par(old_par)
+## Load the Beck & Lee 2014 data
+data(BeckLee_tree) ; data(BeckLee_mat99) ; data(BeckLee_ages)
+
+## Time binning (discrete method)
+## Generate two discrete time bins from 120 to 40 Ma every 20 Ma
+time_bins <- chrono.subsets(data = BeckLee_mat99, tree = BeckLee_tree,
+ method = "discrete", time = c(120, 100, 80, 60),
+ inc.nodes = TRUE, FADLAD = BeckLee_ages)
+
+## Getting the subtrees all the way to the root
+root_subsets <- get.tree(time_bins, subsets = TRUE)
+
+## Plotting the bin contents
+old_par <- par(mfrow = c(2,2))
+plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE)
+axisPhylo()
+abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60))
+for(i in 1:3) {
+ plot(root_subsets[[i]], main = names(root_subsets)[i],
+ show.tip.label = FALSE)
+ axisPhylo()
+}
+
+
But we can also extract the subtrees containing only branch lengths for the actual bins using to.root = FALSE
:
-## Getting the subtrees all the way to the root
- get.tree(time_bins, subsets = TRUE, to.root = FALSE)
- bin_subsets <-
-## Plotting the bin contents
- par(mfrow = c(2,2))
- old_par <-plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE)
-axisPhylo()
-abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60))
-for(i in 1:3) {
-plot(bin_subsets[[i]], main = names(bin_subsets)[i],
- show.tip.label = FALSE)
- axisPhylo()
- }
-
-par(old_par)
+## Getting the subtrees all the way to the root
+bin_subsets <- get.tree(time_bins, subsets = TRUE, to.root = FALSE)
+
+## Plotting the bin contents
+old_par <- par(mfrow = c(2,2))
+plot(BeckLee_tree, main = "original tree", show.tip.label = FALSE)
+axisPhylo()
+abline(v = BeckLee_tree$root.time - c(120, 100, 80, 60))
+for(i in 1:3) {
+ plot(bin_subsets[[i]], main = names(bin_subsets)[i],
+ show.tip.label = FALSE)
+ axisPhylo()
+}
+
+
This can be useful for example for calculating the branch lengths in each bin:
-## How many cumulated phylogenetic diversity in each bin?
-lapply(bin_subsets, function(tree) sum(tree$edge.length))
+## How many cumulated phylogenetic diversity in each bin?
+lapply(bin_subsets, function(tree) sum(tree$edge.length))
## $`120 - 100`
-## [1] 189.2799
+## [1] 189.2829
##
## $`100 - 80`
-## [1] 341.7199
+## [1] 341.7223
##
## $`80 - 60`
-## [1] 426.7493
+## [1] 426.7486
@@ -619,8 +652,8 @@ 7.3.2 $call
-7.3.3 $subsets
+
+7.3.3 $subsets
This element contain the eventual subsets of the multidimensional space.
It is a list
of subset names.
Each subset name is in turn a list
of at least one element called elements
which is in turn a matrix
.
diff --git a/inst/gitbook/dispRity_manual.log b/inst/gitbook/dispRity_manual.log
index fd04c9b2..3fb1189c 100644
--- a/inst/gitbook/dispRity_manual.log
+++ b/inst/gitbook/dispRity_manual.log
@@ -1,173 +1,140 @@
-This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2022/dev/Debian) (preloaded format=xelatex 2023.11.17) 6 DEC 2023 16:18
+This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023/Debian) (preloaded format=xelatex 2024.10.8) 12 NOV 2024 15:35
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**dispRity_manual.tex
(./dispRity_manual.tex
-LaTeX2e <2021-11-15> patch level 1
-L3 programming layer <2022-01-21> (/usr/share/texlive/texmf-dist/tex/latex/base
-/book.cls
-Document Class: book 2021/10/04 v1.4n Standard LaTeX document class
+LaTeX2e <2023-11-01> patch level 1
+L3 programming layer <2024-01-22>
+(/usr/share/texlive/texmf-dist/tex/latex/base/book.cls
+Document Class: book 2023/05/17 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo
-File: bk10.clo 2021/10/04 v1.4n Standard LaTeX file (size option)
+File: bk10.clo 2023/05/17 v1.4n Standard LaTeX file (size option)
)
-\c@part=\count181
-\c@chapter=\count182
-\c@section=\count183
-\c@subsection=\count184
-\c@subsubsection=\count185
-\c@paragraph=\count186
-\c@subparagraph=\count187
-\c@figure=\count188
-\c@table=\count189
-\abovecaptionskip=\skip47
-\belowcaptionskip=\skip48
-\bibindent=\dimen138
-) (/usr/share/texmf/tex/latex/lm/lmodern.sty
-Package: lmodern 2009/10/30 v1.6 Latin Modern Fonts
-LaTeX Font Info: Overwriting symbol font `operators' in version `normal'
-(Font) OT1/cmr/m/n --> OT1/lmr/m/n on input line 22.
-LaTeX Font Info: Overwriting symbol font `letters' in version `normal'
-(Font) OML/cmm/m/it --> OML/lmm/m/it on input line 23.
-LaTeX Font Info: Overwriting symbol font `symbols' in version `normal'
-(Font) OMS/cmsy/m/n --> OMS/lmsy/m/n on input line 24.
-LaTeX Font Info: Overwriting symbol font `largesymbols' in version `normal'
-(Font) OMX/cmex/m/n --> OMX/lmex/m/n on input line 25.
-LaTeX Font Info: Overwriting symbol font `operators' in version `bold'
-(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 26.
-LaTeX Font Info: Overwriting symbol font `letters' in version `bold'
-(Font) OML/cmm/b/it --> OML/lmm/b/it on input line 27.
-LaTeX Font Info: Overwriting symbol font `symbols' in version `bold'
-(Font) OMS/cmsy/b/n --> OMS/lmsy/b/n on input line 28.
-LaTeX Font Info: Overwriting symbol font `largesymbols' in version `bold'
-(Font) OMX/cmex/m/n --> OMX/lmex/m/n on input line 29.
-LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `normal'
-(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 31.
-LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `normal'
-(Font) OT1/cmss/m/n --> OT1/lmss/m/n on input line 32.
-LaTeX Font Info: Overwriting math alphabet `\mathit' in version `normal'
-(Font) OT1/cmr/m/it --> OT1/lmr/m/it on input line 33.
-LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `normal'
-(Font) OT1/cmtt/m/n --> OT1/lmtt/m/n on input line 34.
-LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `bold'
-(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 35.
-LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `bold'
-(Font) OT1/cmss/bx/n --> OT1/lmss/bx/n on input line 36.
-LaTeX Font Info: Overwriting math alphabet `\mathit' in version `bold'
-(Font) OT1/cmr/bx/it --> OT1/lmr/bx/it on input line 37.
-LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `bold'
-(Font) OT1/cmtt/m/n --> OT1/lmtt/m/n on input line 38.
-) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
-Package: amssymb 2013/01/14 v3.01 AMS font symbols
-(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty
-Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support
-\@emptytoks=\toks16
-\symAMSa=\mathgroup4
-\symAMSb=\mathgroup5
-LaTeX Font Info: Redeclaring math symbol \hbar on input line 98.
-LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold'
-(Font) U/euf/m/n --> U/euf/b/n on input line 106.
-)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty
-Package: amsmath 2021/10/15 v2.17l AMS math features
-\@mathmargin=\skip49
+\c@part=\count183
+\c@chapter=\count184
+\c@section=\count185
+\c@subsection=\count186
+\c@subsubsection=\count187
+\c@paragraph=\count188
+\c@subparagraph=\count189
+\c@figure=\count190
+\c@table=\count191
+\abovecaptionskip=\skip48
+\belowcaptionskip=\skip49
+\bibindent=\dimen140
+) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty
+Package: amsmath 2023/05/13 v2.17o AMS math features
+\@mathmargin=\skip50
For additional information on amsmath, use the `?' option.
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2021/08/26 v2.01 AMS text
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0 generic functions
\@emptytoks=\toks17
-\ex@=\dimen139
+\ex@=\dimen141
)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d Bold Symbols
-\pmbraise@=\dimen140
+\pmbraise@=\dimen142
) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty
-Package: amsopn 2021/08/26 v2.02 operator names
+Package: amsopn 2022/04/08 v2.04 operator names
)
-\inf@bad=\count190
+\inf@bad=\count192
LaTeX Info: Redefining \frac on input line 234.
-\uproot@=\count191
-\leftroot@=\count192
+\uproot@=\count193
+\leftroot@=\count194
LaTeX Info: Redefining \overline on input line 399.
-\classnum@=\count193
-\DOTSCASE@=\count194
+LaTeX Info: Redefining \colon on input line 410.
+\classnum@=\count195
+\DOTSCASE@=\count196
LaTeX Info: Redefining \ldots on input line 496.
LaTeX Info: Redefining \dots on input line 499.
LaTeX Info: Redefining \cdots on input line 620.
-\Mathstrutbox@=\box50
-\strutbox@=\box51
-\big@size=\dimen141
+\Mathstrutbox@=\box51
+\strutbox@=\box52
+LaTeX Info: Redefining \big on input line 722.
+LaTeX Info: Redefining \Big on input line 723.
+LaTeX Info: Redefining \bigg on input line 724.
+LaTeX Info: Redefining \Bigg on input line 725.
+\big@size=\dimen143
LaTeX Font Info: Redeclaring font encoding OML on input line 743.
LaTeX Font Info: Redeclaring font encoding OMS on input line 744.
-\macc@depth=\count195
-\c@MaxMatrixCols=\count196
+\macc@depth=\count197
+LaTeX Info: Redefining \bmod on input line 905.
+LaTeX Info: Redefining \pmod on input line 910.
+LaTeX Info: Redefining \smash on input line 940.
+LaTeX Info: Redefining \relbar on input line 970.
+LaTeX Info: Redefining \Relbar on input line 971.
+\c@MaxMatrixCols=\count198
\dotsspace@=\muskip16
-\c@parentequation=\count197
-\dspbrk@lvl=\count198
+\c@parentequation=\count199
+\dspbrk@lvl=\count266
\tag@help=\toks18
-\row@=\count199
-\column@=\count266
-\maxfields@=\count267
+\row@=\count267
+\column@=\count268
+\maxfields@=\count269
\andhelp@=\toks19
-\eqnshift@=\dimen142
-\alignsep@=\dimen143
-\tagshift@=\dimen144
-\tagwidth@=\dimen145
-\totwidth@=\dimen146
-\lineht@=\dimen147
+\eqnshift@=\dimen144
+\alignsep@=\dimen145
+\tagshift@=\dimen146
+\tagwidth@=\dimen147
+\totwidth@=\dimen148
+\lineht@=\dimen149
\@envbody=\toks20
-\multlinegap=\skip50
-\multlinetaggap=\skip51
+\multlinegap=\skip51
+\multlinetaggap=\skip52
\mathdisplay@stack=\toks21
-LaTeX Info: Redefining \[ on input line 2938.
-LaTeX Info: Redefining \] on input line 2939.
-) (/usr/share/texlive/texmf-dist/tex/generic/iftex/ifxetex.sty
-Package: ifxetex 2019/10/25 v0.7 ifxetex legacy package. Use iftex instead.
-(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty
-Package: iftex 2020/03/06 v1.0d TeX engine tests
-)) (/usr/share/texlive/texmf-dist/tex/generic/iftex/ifluatex.sty
-Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
+LaTeX Info: Redefining \[ on input line 2953.
+LaTeX Info: Redefining \] on input line 2954.
+) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty
+Package: amssymb 2013/01/14 v3.01 AMS font symbols
+(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty
+Package: amsfonts 2013/01/14 v3.01 Basic AMSFonts support
+\symAMSa=\mathgroup4
+\symAMSb=\mathgroup5
+LaTeX Font Info: Redeclaring math symbol \hbar on input line 98.
+LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold'
+(Font) U/euf/m/n --> U/euf/b/n on input line 106.
+)) (/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty
+Package: iftex 2022/02/03 v1.0f TeX engine tests
) (/usr/share/texlive/texmf-dist/tex/latex/unicode-math/unicode-math.sty (/usr/
share/texlive/texmf-dist/tex/latex/l3kernel/expl3.sty
-Package: expl3 2022-01-21 L3 programming layer (loader)
+Package: expl3 2024-01-22 L3 programming layer (loader)
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-xetex.def
-File: l3backend-xetex.def 2022-01-12 L3 backend support: XeTeX
-(|extractbb --version)
-\c__kernel_sys_dvipdfmx_version_int=\count268
-\l__color_backend_stack_int=\count269
-\g__color_backend_stack_int=\count270
-\g__graphics_track_int=\count271
-\l__pdf_internal_box=\box52
-\g__pdf_backend_object_int=\count272
-\g__pdf_backend_annotation_int=\count273
-\g__pdf_backend_link_int=\count274
+File: l3backend-xetex.def 2024-01-04 L3 backend support: XeTeX
+\g__graphics_track_int=\count270
+\l__pdf_internal_box=\box53
+\g__pdf_backend_object_int=\count271
+\g__pdf_backend_annotation_int=\count272
+\g__pdf_backend_link_int=\count273
))
-Package: unicode-math 2020/01/31 v0.8q Unicode maths in XeLaTeX and LuaLaTeX
+Package: unicode-math 2023/08/13 v0.8r Unicode maths in XeLaTeX and LuaLaTeX
(/usr/share/texlive/texmf-dist/tex/latex/unicode-math/unicode-math-xetex.sty
-Package: unicode-math-xetex 2020/01/31 v0.8q Unicode maths in XeLaTeX and LuaLa
+Package: unicode-math-xetex 2023/08/13 v0.8r Unicode maths in XeLaTeX and LuaLa
TeX
(/usr/share/texlive/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
-Package: xparse 2022-01-12 L3 Experimental document command parser
+Package: xparse 2023-10-10 L3 Experimental document command parser
) (/usr/share/texlive/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty
-Package: l3keys2e 2022-01-12 LaTeX2e option processing using LaTeX3 keys
+Package: l3keys2e 2023-10-10 LaTeX2e option processing using LaTeX3 keys
) (/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.sty
Package: fontspec 2022/01/15 v2.8a Font selection for XeLaTeX and LuaLaTeX
(/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec-xetex.sty
Package: fontspec-xetex 2022/01/15 v2.8a Font selection for XeLaTeX and LuaLaTe
X
-\l__fontspec_script_int=\count275
-\l__fontspec_language_int=\count276
-\l__fontspec_strnum_int=\count277
-\l__fontspec_tmp_int=\count278
-\l__fontspec_tmpa_int=\count279
-\l__fontspec_tmpb_int=\count280
-\l__fontspec_tmpc_int=\count281
-\l__fontspec_em_int=\count282
-\l__fontspec_emdef_int=\count283
-\l__fontspec_strong_int=\count284
-\l__fontspec_strongdef_int=\count285
-\l__fontspec_tmpa_dim=\dimen148
-\l__fontspec_tmpb_dim=\dimen149
-\l__fontspec_tmpc_dim=\dimen150
+\l__fontspec_script_int=\count274
+\l__fontspec_language_int=\count275
+\l__fontspec_strnum_int=\count276
+\l__fontspec_tmp_int=\count277
+\l__fontspec_tmpa_int=\count278
+\l__fontspec_tmpb_int=\count279
+\l__fontspec_tmpc_int=\count280
+\l__fontspec_em_int=\count281
+\l__fontspec_emdef_int=\count282
+\l__fontspec_strong_int=\count283
+\l__fontspec_strongdef_int=\count284
+\l__fontspec_tmpa_dim=\dimen150
+\l__fontspec_tmpb_dim=\dimen151
+\l__fontspec_tmpc_dim=\dimen152
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
Package: fontenc 2021/04/29 v2.0v Standard LaTeX package
) (/usr/share/texlive/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/share
@@ -177,75 +144,207 @@ Package: fix-cm 2020/11/24 v1.1t fixes to LaTeX
File: ts1enc.def 2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
LaTeX Font Info: Redeclaring font encoding TS1 on input line 47.
))
-\g__um_fam_int=\count286
-\g__um_fonts_used_int=\count287
-\l__um_primecount_int=\count288
+\g__um_fam_int=\count285
+\g__um_fonts_used_int=\count286
+\l__um_primecount_int=\count287
\g__um_primekern_muskip=\muskip17
(/usr/share/texlive/texmf-dist/tex/latex/unicode-math/unicode-math-table.tex)))
-(/usr/share/texlive/texmf-dist/tex/latex/upquote/upquote.sty
+(/usr/share/texmf/tex/latex/lm/lmodern.sty
+Package: lmodern 2015/05/01 v1.6.1 Latin Modern Fonts
+LaTeX Font Info: Overwriting symbol font `operators' in version `normal'
+(Font) OT1/cmr/m/n --> OT1/lmr/m/n on input line 22.
+LaTeX Font Info: Overwriting symbol font `letters' in version `normal'
+(Font) OML/cmm/m/it --> OML/lmm/m/it on input line 23.
+LaTeX Font Info: Overwriting symbol font `symbols' in version `normal'
+(Font) OMS/cmsy/m/n --> OMS/lmsy/m/n on input line 24.
+LaTeX Font Info: Overwriting symbol font `largesymbols' in version `normal'
+(Font) OMX/cmex/m/n --> OMX/lmex/m/n on input line 25.
+LaTeX Font Info: Overwriting symbol font `operators' in version `bold'
+(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 26.
+LaTeX Font Info: Overwriting symbol font `letters' in version `bold'
+(Font) OML/cmm/b/it --> OML/lmm/b/it on input line 27.
+LaTeX Font Info: Overwriting symbol font `symbols' in version `bold'
+(Font) OMS/cmsy/b/n --> OMS/lmsy/b/n on input line 28.
+LaTeX Font Info: Overwriting symbol font `largesymbols' in version `bold'
+(Font) OMX/cmex/m/n --> OMX/lmex/m/n on input line 29.
+LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `normal'
+(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 31.
+LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `normal'
+(Font) OT1/cmss/m/n --> OT1/lmss/m/n on input line 32.
+LaTeX Font Info: Overwriting math alphabet `\mathit' in version `normal'
+(Font) OT1/cmr/m/it --> OT1/lmr/m/it on input line 33.
+LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `normal'
+(Font) OT1/cmtt/m/n --> OT1/lmtt/m/n on input line 34.
+LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `bold'
+(Font) OT1/cmr/bx/n --> OT1/lmr/bx/n on input line 35.
+LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `bold'
+(Font) OT1/cmss/bx/n --> OT1/lmss/bx/n on input line 36.
+LaTeX Font Info: Overwriting math alphabet `\mathit' in version `bold'
+(Font) OT1/cmr/bx/it --> OT1/lmr/bx/it on input line 37.
+LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `bold'
+(Font) OT1/cmtt/m/n --> OT1/lmtt/m/n on input line 38.
+) (/usr/share/texlive/texmf-dist/tex/latex/upquote/upquote.sty
Package: upquote 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verba
tim
(/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty
Package: textcomp 2020/02/02 v2.0n Standard LaTeX package
)) (/usr/share/texlive/texmf-dist/tex/latex/microtype/microtype.sty
-Package: microtype 2021/12/10 v3.0b Micro-typographical refinements (RS)
+Package: microtype 2023/03/13 v3.1a Micro-typographical refinements (RS)
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
-Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
+Package: keyval 2022/05/29 v1.15 key=value parser (DPC)
\KV@toks@=\toks22
) (/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
-\etb@tempcnta=\count289
+\etb@tempcnta=\count288
)
\MT@toks=\toks23
-\MT@count=\count290
-\MT@tempbox=\box53
-LaTeX Info: Redefining \leftprotrusion on input line 1010.
-LaTeX Info: Redefining \rightprotrusion on input line 1018.
-LaTeX Info: Redefining \textls on input line 1173.
-\MT@outer@kern=\dimen151
-LaTeX Info: Redefining \textmicrotypecontext on input line 1759.
-\MT@listname@count=\count291
+\MT@tempbox=\box54
+\MT@count=\count289
+LaTeX Info: Redefining \noprotrusionifhmode on input line 1059.
+LaTeX Info: Redefining \leftprotrusion on input line 1060.
+\MT@prot@toks=\toks24
+LaTeX Info: Redefining \rightprotrusion on input line 1078.
+LaTeX Info: Redefining \textls on input line 1368.
+\MT@outer@kern=\dimen153
+LaTeX Info: Redefining \textmicrotypecontext on input line 1988.
+\MT@listname@count=\count290
(/usr/share/texlive/texmf-dist/tex/latex/microtype/microtype-xetex.def
-File: microtype-xetex.def 2021/12/10 v3.0b Definitions specific to xetex (RS)
-LaTeX Info: Redefining \lsstyle on input line 234.
+File: microtype-xetex.def 2023/03/13 v3.1a Definitions specific to xetex (RS)
+LaTeX Info: Redefining \lsstyle on input line 238.
)
Package microtype Info: Loading configuration file microtype.cfg.
(/usr/share/texlive/texmf-dist/tex/latex/microtype/microtype.cfg
-File: microtype.cfg 2021/12/10 v3.0b microtype main configuration file (RS)
+File: microtype.cfg 2023/03/13 v3.1a microtype main configuration file (RS)
)) (/usr/share/texlive/texmf-dist/tex/latex/parskip/parskip.sty
Package: parskip 2021-03-14 v2.0h non-zero parskip adjustments
(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty
-Package: kvoptions 2020-10-07 v3.14 Key value format for package options (HO)
+Package: kvoptions 2022-06-15 v3.15 Key value format for package options (HO)
(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty
-Package: ltxcmds 2020-05-10 v1.25 LaTeX kernel commands for general use (HO)
-) (/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty
-Package: kvsetkeys 2019/12/15 v1.18 Key value parser (HO)
+Package: ltxcmds 2023-12-04 v1.26 LaTeX kernel commands for general use (HO)
+) (/usr/share/texlive/texmf-dist/tex/latex/kvsetkeys/kvsetkeys.sty
+Package: kvsetkeys 2022-10-05 v1.19 Key value parser (HO)
))) (/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
-Package: xcolor 2021/10/31 v2.13 LaTeX color extensions (UK)
+Package: xcolor 2023/11/15 v3.01 LaTeX color extensions (UK)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
-Package xcolor Info: Driver file: xetex.def on input line 227.
+Package xcolor Info: Driver file: xetex.def on input line 274.
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/xetex.def
-File: xetex.def 2021/03/18 v5.0k Graphics/color driver for xetex
+File: xetex.def 2022/09/22 v5.0n Graphics/color driver for xetex
+) (/usr/share/texlive/texmf-dist/tex/latex/graphics/mathcolor.ltx)
+Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1350.
+Package xcolor Info: Model `RGB' extended on input line 1366.
+Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1368.
+Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1369.
+Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1370.
+Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1371.
+Package xcolor Info: Model `Gray' substituted by `gray' on input line 1372.
+Package xcolor Info: Model `wave' substituted by `hsb' on input line 1373.
+) (/usr/share/texlive/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
+Package: fancyvrb 2024/01/20 4.5c verbatim text (tvz,hv)
+\FV@CodeLineNo=\count291
+\FV@InFile=\read2
+\FV@TabBox=\box55
+\c@FancyVerbLine=\count292
+\FV@StepNumber=\count293
+\FV@OutFile=\write3
+) (/usr/share/texlive/texmf-dist/tex/latex/framed/framed.sty
+Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks
+\OuterFrameSep=\skip53
+\fb@frw=\dimen154
+\fb@frh=\dimen155
+\FrameRule=\dimen156
+\FrameSep=\dimen157
+) (/usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty
+Package: longtable 2023-11-01 v4.19 Multi-page Table package (DPC)
+\LTleft=\skip54
+\LTright=\skip55
+\LTpre=\skip56
+\LTpost=\skip57
+\LTchunksize=\count294
+\LTcapwidth=\dimen158
+\LT@head=\box56
+\LT@firsthead=\box57
+\LT@foot=\box58
+\LT@lastfoot=\box59
+\LT@gbox=\box60
+\LT@cols=\count295
+\LT@rows=\count296
+\c@LT@tables=\count297
+\c@LT@chunks=\count298
+\LT@p@ftn=\toks25
+) (/usr/share/texlive/texmf-dist/tex/latex/booktabs/booktabs.sty
+Package: booktabs 2020/01/12 v1.61803398 Publication quality tables
+\heavyrulewidth=\dimen159
+\lightrulewidth=\dimen160
+\cmidrulewidth=\dimen161
+\belowrulesep=\dimen162
+\belowbottomsep=\dimen163
+\aboverulesep=\dimen164
+\abovetopsep=\dimen165
+\cmidrulesep=\dimen166
+\cmidrulekern=\dimen167
+\defaultaddspace=\dimen168
+\@cmidla=\count299
+\@cmidlb=\count300
+\@aboverulesep=\dimen169
+\@belowrulesep=\dimen170
+\@thisruleclass=\count301
+\@lastruleclass=\count302
+\@thisrulewidth=\dimen171
+) (/usr/share/texlive/texmf-dist/tex/latex/tools/array.sty
+Package: array 2023/10/16 v2.5g Tabular extension package (FMi)
+\col@sep=\dimen172
+\ar@mcellbox=\box61
+\extrarowheight=\dimen173
+\NC@list=\toks26
+\extratabsurround=\skip58
+\backup@length=\skip59
+\ar@cellbox=\box62
+) (/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty
+Package: calc 2023/07/08 v4.3 Infix arithmetic (KKT,FJ)
+\calc@Acount=\count303
+\calc@Bcount=\count304
+\calc@Adimen=\dimen174
+\calc@Bdimen=\dimen175
+\calc@Askip=\skip60
+\calc@Bskip=\skip61
+LaTeX Info: Redefining \setlength on input line 80.
+LaTeX Info: Redefining \addtolength on input line 81.
+\calc@Ccount=\count305
+\calc@Cskip=\skip62
+) (/usr/share/texlive/texmf-dist/tex/latex/footnotehyper/footnotehyper.sty
+Package: footnotehyper 2021/08/13 v1.1e hyperref aware footnote.sty (JFB)
+\FNH@notes=\box63
+\FNH@width=\dimen176
+\FNH@toks=\toks27
+) (/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
+Package: graphicx 2021/09/16 v1.2d Enhanced LaTeX Graphics (DPC,SPQR)
+(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
+Package: graphics 2022/03/10 v1.4e Standard LaTeX Graphics (DPC,SPQR)
+(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty
+Package: trig 2021/08/11 v1.11 sin cos tan (DPC)
+) (/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
+File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
-Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1352.
-Package xcolor Info: Model `RGB' extended on input line 1368.
-Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1370.
-Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1371.
-Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1372.
-Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1373.
-Package xcolor Info: Model `Gray' substituted by `gray' on input line 1374.
-Package xcolor Info: Model `wave' substituted by `hsb' on input line 1375.
-) (/usr/share/texlive/texmf-dist/tex/latex/xurl/xurl.sty
-Package: xurl 2022/01/09 v 0.10 modify URL breaks
-(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty
-\Urlmuskip=\muskip18
-Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc.
-)) (/usr/share/texlive/texmf-dist/tex/latex/bookmark/bookmark.sty
-Package: bookmark 2020-11-06 v1.29 PDF bookmarks (HO)
+Package graphics Info: Driver file: xetex.def on input line 107.
+)
+\Gin@req@height=\dimen177
+\Gin@req@width=\dimen178
+) (/usr/share/texlive/texmf-dist/tex/latex/natbib/natbib.sty
+Package: natbib 2010/09/13 8.31b (PWD, AO)
+\bibhang=\skip63
+\bibsep=\skip64
+LaTeX Info: Redefining \cite on input line 694.
+\c@NAT@ctr=\count306
+) (/usr/share/texlive/texmf-dist/tex/latex/bookmark/bookmark.sty
+Package: bookmark 2023-12-10 v1.31 PDF bookmarks (HO)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
-Package: hyperref 2021-06-07 v7.00m Hypertext links for LaTeX
+Package: hyperref 2024-01-20 v7.01h Hypertext links for LaTeX
+(/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty
+Package: kvdefinekeys 2019-12-19 v1.6 Define keys (HO)
+) (/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty
+Package: pdfescape 2019/12/09 v1.15 Implements pdfTeX's escape features (HO)
(/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty
Package: pdftexcmds 2020-06-27 v0.33 Utility functions of pdfTeX for LuaTeX (HO
)
@@ -255,85 +354,84 @@ Package: infwarerr 2019/12/03 v1.5 Providing info/warning/error messages (HO)
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode not found.
-) (/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty
-Package: kvdefinekeys 2019-12-19 v1.6 Define keys (HO)
-) (/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty
-Package: pdfescape 2019/12/09 v1.15 Implements pdfTeX's escape features (HO)
-) (/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty
+)) (/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty
Package: hycolor 2020-01-27 v1.10 Color options for hyperref/bookmark (HO)
-) (/usr/share/texlive/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty
-Package: letltxmacro 2019/12/03 v1.6 Let assignment for LaTeX macros (HO)
) (/usr/share/texlive/texmf-dist/tex/latex/auxhook/auxhook.sty
Package: auxhook 2019-12-17 v1.6 Hooks for auxiliary files (HO)
+) (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
+Package: nameref 2023-11-26 v2.56 Cross-referencing by name of section
+(/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty
+Package: refcount 2019/12/15 v3.6 Data extraction from label references (HO)
+) (/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty
+Package: gettitlestring 2019/12/15 v1.6 Cleanup title references (HO)
)
-\@linkdim=\dimen152
-\Hy@linkcounter=\count292
-\Hy@pagecounter=\count293
+\c@section@level=\count307
+)
+\@linkdim=\dimen179
+\Hy@linkcounter=\count308
+\Hy@pagecounter=\count309
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def
-File: pd1enc.def 2021-06-07 v7.00m Hyperref: PDFDocEncoding definition (HO)
-) (/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref-langpatches.def
-File: hyperref-langpatches.def 2021-06-07 v7.00m Hyperref: patches for babel la
-nguages
+File: pd1enc.def 2024-01-20 v7.01h Hyperref: PDFDocEncoding definition (HO)
) (/usr/share/texlive/texmf-dist/tex/generic/intcalc/intcalc.sty
Package: intcalc 2019/12/15 v1.3 Expandable calculations with integers (HO)
-) (/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty
-Package: etexcmds 2019/12/15 v1.7 Avoid name clashes with e-TeX commands (HO)
)
-\Hy@SavedSpaceFactor=\count294
+\Hy@SavedSpaceFactor=\count310
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/puenc.def
-File: puenc.def 2021-06-07 v7.00m Hyperref: PDF Unicode definition (HO)
+File: puenc.def 2024-01-20 v7.01h Hyperref: PDF Unicode definition (HO)
)
-Package hyperref Info: Option `unicode' set `true' on input line 4073.
-Package hyperref Info: Hyper figures OFF on input line 4192.
-Package hyperref Info: Link nesting OFF on input line 4197.
-Package hyperref Info: Hyper index ON on input line 4200.
-Package hyperref Info: Plain pages OFF on input line 4207.
-Package hyperref Info: Backreferencing OFF on input line 4212.
+Package hyperref Info: Option `unicode' set `true' on input line 4062.
+Package hyperref Info: Hyper figures OFF on input line 4179.
+Package hyperref Info: Link nesting OFF on input line 4184.
+Package hyperref Info: Hyper index ON on input line 4187.
+Package hyperref Info: Plain pages OFF on input line 4194.
+Package hyperref Info: Backreferencing OFF on input line 4199.
Package hyperref Info: Implicit mode ON; LaTeX internals redefined.
-Package hyperref Info: Bookmarks ON on input line 4445.
-\c@Hy@tempcnt=\count295
-LaTeX Info: Redefining \url on input line 4804.
-\XeTeXLinkMargin=\dimen153
+Package hyperref Info: Bookmarks ON on input line 4446.
+\c@Hy@tempcnt=\count311
+(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty
+\Urlmuskip=\muskip18
+Package: url 2013/09/16 ver 3.4 Verb mode for urls, etc.
+)
+LaTeX Info: Redefining \url on input line 4784.
+\XeTeXLinkMargin=\dimen180
(/usr/share/texlive/texmf-dist/tex/generic/bitset/bitset.sty
Package: bitset 2019/12/09 v1.3 Handle bit-vector datatype (HO)
(/usr/share/texlive/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty
Package: bigintcalc 2019/12/15 v1.5 Expandable calculations on big integers (HO
)
))
-\Fld@menulength=\count296
-\Field@Width=\dimen154
-\Fld@charsize=\dimen155
-Package hyperref Info: Hyper figures OFF on input line 6076.
-Package hyperref Info: Link nesting OFF on input line 6081.
-Package hyperref Info: Hyper index ON on input line 6084.
-Package hyperref Info: backreferencing OFF on input line 6091.
-Package hyperref Info: Link coloring OFF on input line 6096.
-Package hyperref Info: Link coloring with OCG OFF on input line 6101.
-Package hyperref Info: PDF/A mode OFF on input line 6106.
-LaTeX Info: Redefining \ref on input line 6146.
-LaTeX Info: Redefining \pageref on input line 6150.
+\Fld@menulength=\count312
+\Field@Width=\dimen181
+\Fld@charsize=\dimen182
+Package hyperref Info: Hyper figures OFF on input line 6063.
+Package hyperref Info: Link nesting OFF on input line 6068.
+Package hyperref Info: Hyper index ON on input line 6071.
+Package hyperref Info: backreferencing OFF on input line 6078.
+Package hyperref Info: Link coloring OFF on input line 6083.
+Package hyperref Info: Link coloring with OCG OFF on input line 6088.
+Package hyperref Info: PDF/A mode OFF on input line 6093.
(/usr/share/texlive/texmf-dist/tex/latex/base/atbegshi-ltx.sty
Package: atbegshi-ltx 2021/01/10 v1.0c Emulation of the original atbegshi
package with kernel methods
)
-\Hy@abspage=\count297
-\c@Item=\count298
-\c@Hfootnote=\count299
+\Hy@abspage=\count313
+\c@Item=\count314
+\c@Hfootnote=\count315
)
Package hyperref Info: Driver (autodetected): hxetex.
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hxetex.def
-File: hxetex.def 2021-06-07 v7.00m Hyperref driver for XeTeX
+File: hxetex.def 2024-01-20 v7.01h Hyperref driver for XeTeX
(/usr/share/texlive/texmf-dist/tex/generic/stringenc/stringenc.sty
Package: stringenc 2019/11/29 v1.12 Convert strings between diff. encodings (HO
)
)
-\pdfm@box=\box54
-\c@Hy@AnnotLevel=\count300
-\HyField@AnnotCount=\count301
-\Fld@listcount=\count302
-\c@bookmark@seq@number=\count303
+\pdfm@box=\box64
+\c@Hy@AnnotLevel=\count316
+\HyField@AnnotCount=\count317
+\Fld@listcount=\count318
+\c@bookmark@seq@number=\count319
(/usr/share/texlive/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty
-Package: rerunfilecheck 2019/12/05 v1.9 Rerun checks for auxiliary files (HO)
+Package: rerunfilecheck 2022-07-10 v1.10 Rerun checks for auxiliary files (HO)
(/usr/share/texlive/texmf-dist/tex/latex/base/atveryend-ltx.sty
Package: atveryend-ltx 2020/08/19 v1.0a Emulation of the original atveryend pac
kage
@@ -342,125 +440,51 @@ with kernel methods
Package: uniquecounter 2019/12/15 v1.4 Provide unlimited unique counter (HO)
)
Package uniquecounter Info: New unique counter `rerunfilecheck' on input line 2
-86.
+85.
)
-\Hy@SectionHShift=\skip52
+\Hy@SectionHShift=\skip65
) (/usr/share/texlive/texmf-dist/tex/latex/bookmark/bkm-dvipdfm.def
-File: bkm-dvipdfm.def 2020-11-06 v1.29 bookmark driver for dvipdfm (HO)
-\BKM@id=\count304
-)) (/usr/share/texlive/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty
-Package: fancyvrb 2021/12/21 4.1b verbatim text (tvz,hv)
-\FV@CodeLineNo=\count305
-\FV@InFile=\read2
-\FV@TabBox=\box55
-\c@FancyVerbLine=\count306
-\FV@StepNumber=\count307
-\FV@OutFile=\write3
-) (/usr/share/texlive/texmf-dist/tex/latex/framed/framed.sty
-Package: framed 2011/10/22 v 0.96: framed or shaded text with page breaks
-\OuterFrameSep=\skip53
-\fb@frw=\dimen156
-\fb@frh=\dimen157
-\FrameRule=\dimen158
-\FrameSep=\dimen159
-) (/usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty
-Package: longtable 2021-09-01 v4.17 Multi-page Table package (DPC)
-\LTleft=\skip54
-\LTright=\skip55
-\LTpre=\skip56
-\LTpost=\skip57
-\LTchunksize=\count308
-\LTcapwidth=\dimen160
-\LT@head=\box56
-\LT@firsthead=\box57
-\LT@foot=\box58
-\LT@lastfoot=\box59
-\LT@gbox=\box60
-\LT@cols=\count309
-\LT@rows=\count310
-\c@LT@tables=\count311
-\c@LT@chunks=\count312
-\LT@p@ftn=\toks24
-) (/usr/share/texlive/texmf-dist/tex/latex/booktabs/booktabs.sty
-Package: booktabs 2020/01/12 v1.61803398 Publication quality tables
-\heavyrulewidth=\dimen161
-\lightrulewidth=\dimen162
-\cmidrulewidth=\dimen163
-\belowrulesep=\dimen164
-\belowbottomsep=\dimen165
-\aboverulesep=\dimen166
-\abovetopsep=\dimen167
-\cmidrulesep=\dimen168
-\cmidrulekern=\dimen169
-\defaultaddspace=\dimen170
-\@cmidla=\count313
-\@cmidlb=\count314
-\@aboverulesep=\dimen171
-\@belowrulesep=\dimen172
-\@thisruleclass=\count315
-\@lastruleclass=\count316
-\@thisrulewidth=\dimen173
-) (/usr/share/texlive/texmf-dist/tex/latex/footnotehyper/footnotehyper.sty
-Package: footnotehyper 2021/08/13 v1.1e hyperref aware footnote.sty (JFB)
-\FNH@notes=\box61
-\FNH@width=\dimen174
-\FNH@toks=\toks25
-) (/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
-Package: graphicx 2021/09/16 v1.2d Enhanced LaTeX Graphics (DPC,SPQR)
-(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
-Package: graphics 2021/03/04 v1.4d Standard LaTeX Graphics (DPC,SPQR)
-(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty
-Package: trig 2021/08/11 v1.11 sin cos tan (DPC)
-) (/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
-File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
-)
-Package graphics Info: Driver file: xetex.def on input line 107.
-)
-\Gin@req@height=\dimen175
-\Gin@req@width=\dimen176
-) (/usr/share/texlive/texmf-dist/tex/latex/natbib/natbib.sty
-Package: natbib 2010/09/13 8.31b (PWD, AO)
-\bibhang=\skip58
-\bibsep=\skip59
-LaTeX Info: Redefining \cite on input line 694.
-\c@NAT@ctr=\count317
+File: bkm-dvipdfm.def 2023-12-10 v1.31 bookmark driver for dvipdfm (HO)
+\BKM@id=\count320
+)) (/usr/share/texlive/texmf-dist/tex/latex/xurl/xurl.sty
+Package: xurl 2022/01/09 v 0.10 modify URL breaks
) (./dispRity_manual.aux)
\openout1 = `dispRity_manual.aux'.
-LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for TU/lmr/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
-LaTeX Font Info: Checking defaults for PU/pdf/m/n on input line 118.
-LaTeX Font Info: ... okay on input line 118.
+LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for TU/lmr/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for PD1/pdf/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
+LaTeX Font Info: Checking defaults for PU/pdf/m/n on input line 125.
+LaTeX Font Info: ... okay on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathrm' in version `normal'
-(Font) OT1/lmr/m/n --> TU/lmr/m/n on input line 118.
+(Font) OT1/lmr/m/n --> TU/lmr/m/n on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathit' in version `normal'
-(Font) OT1/lmr/m/it --> TU/lmr/m/it on input line 118.
+(Font) OT1/lmr/m/it --> TU/lmr/m/it on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathbf' in version `normal'
-(Font) OT1/lmr/bx/n --> TU/lmr/bx/n on input line 118.
+(Font) OT1/lmr/bx/n --> TU/lmr/bx/n on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `normal'
-(Font) OT1/lmss/m/n --> TU/lmss/m/n on input line 118.
+(Font) OT1/lmss/m/n --> TU/lmss/m/n on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathsf' in version `bold'
-(Font) OT1/lmss/bx/n --> TU/lmss/bx/n on input line 118.
+(Font) OT1/lmss/bx/n --> TU/lmss/bx/n on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `normal'
-(Font) OT1/lmtt/m/n --> TU/lmtt/m/n on input line 118.
+(Font) OT1/lmtt/m/n --> TU/lmtt/m/n on input line 125.
LaTeX Font Info: Overwriting math alphabet `\mathtt' in version `bold'
-(Font) OT1/lmtt/m/n --> TU/lmtt/bx/n on input line 118.
+(Font) OT1/lmtt/m/n --> TU/lmtt/bx/n on input line 125.
Package fontspec Info: latinmodern-math scale = 0.9999964596882403.
@@ -489,7 +513,7 @@ pt=math;language=dflt;"
(fontspec) - 'bold small caps' (b/sc) with NFSS spec.:
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(0)/m/n' will be
-(Font) scaled to size 10.0pt on input line 118.
+(Font) scaled to size 10.0pt on input line 125.
Package fontspec Info: latinmodern-math scale = 0.9999964596882403.
@@ -528,18 +552,18 @@ pt=math;language=dflt;"
(fontspec) - 'bold small caps' (b/sc) with NFSS spec.:
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(1)/m/n' will be
-(Font) scaled to size 10.0pt on input line 118.
+(Font) scaled to size 10.0pt on input line 125.
LaTeX Font Info: Encoding `OT1' has changed to `TU' for symbol font
-(Font) `operators' in the math version `normal' on input line 118.
+(Font) `operators' in the math version `normal' on input line 125.
LaTeX Font Info: Overwriting symbol font `operators' in version `normal'
(Font) OT1/lmr/m/n --> TU/latinmodern-math.otf(1)/m/n on input
- line 118.
+ line 125.
LaTeX Font Info: Encoding `OT1' has changed to `TU' for symbol font
-(Font) `operators' in the math version `bold' on input line 118.
+(Font) `operators' in the math version `bold' on input line 125.
LaTeX Font Info: Overwriting symbol font `operators' in version `bold'
(Font) OT1/lmr/bx/n --> TU/latinmodern-math.otf(1)/b/n on inpu
-t line 118.
+t line 125.
Package fontspec Info: latinmodern-math scale = 0.9999964596882403.
@@ -626,15 +650,15 @@ t=math;language=dflt;"
(fontspec) \fontdimen 21\font =0pt\relax
LaTeX Font Info: Encoding `OMS' has changed to `TU' for symbol font
-(Font) `symbols' in the math version `normal' on input line 118.
+(Font) `symbols' in the math version `normal' on input line 125.
LaTeX Font Info: Overwriting symbol font `symbols' in version `normal'
(Font) OMS/lmsy/m/n --> TU/latinmodern-math.otf(2)/m/n on inpu
-t line 118.
+t line 125.
LaTeX Font Info: Encoding `OMS' has changed to `TU' for symbol font
-(Font) `symbols' in the math version `bold' on input line 118.
+(Font) `symbols' in the math version `bold' on input line 125.
LaTeX Font Info: Overwriting symbol font `symbols' in version `bold'
(Font) OMS/lmsy/b/n --> TU/latinmodern-math.otf(2)/b/n on inpu
-t line 118.
+t line 125.
Package fontspec Info: latinmodern-math scale = 0.9999964596882403.
@@ -704,21 +728,22 @@ pt=math;language=dflt;"
LaTeX Font Info: Encoding `OMX' has changed to `TU' for symbol font
(Font) `largesymbols' in the math version `normal' on input line 1
-18.
+25.
LaTeX Font Info: Overwriting symbol font `largesymbols' in version `normal'
(Font) OMX/lmex/m/n --> TU/latinmodern-math.otf(3)/m/n on inpu
-t line 118.
+t line 125.
LaTeX Font Info: Encoding `OMX' has changed to `TU' for symbol font
-(Font) `largesymbols' in the math version `bold' on input line 118
+(Font) `largesymbols' in the math version `bold' on input line 125
.
LaTeX Font Info: Overwriting symbol font `largesymbols' in version `bold'
(Font) OMX/lmex/m/n --> TU/latinmodern-math.otf(3)/b/n on inpu
-t line 118.
-LaTeX Info: Redefining \microtypecontext on input line 118.
-Package microtype Info: Applying patch `item' on input line 118.
-Package microtype Info: Applying patch `toc' on input line 118.
-Package microtype Info: Applying patch `eqnum' on input line 118.
-Package microtype Info: Applying patch `footnote' on input line 118.
+t line 125.
+LaTeX Info: Redefining \microtypecontext on input line 125.
+Package microtype Info: Applying patch `item' on input line 125.
+Package microtype Info: Applying patch `toc' on input line 125.
+Package microtype Info: Applying patch `eqnum' on input line 125.
+Package microtype Info: Applying patch `footnote' on input line 125.
+Package microtype Info: Applying patch `verbatim' on input line 125.
Package microtype Info: Character protrusion enabled (level 2).
Package microtype Info: Using protrusion set `basicmath'.
Package microtype Info: No adjustment of tracking.
@@ -728,50 +753,38 @@ Package microtype Info: No adjustment of kerning.
File: mt-LatinModernRoman.cfg 2021/02/21 v1.1 microtype config. file: Latin Mod
ern Roman (RS)
)
-Package hyperref Info: Link coloring OFF on input line 118.
-(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
-Package: nameref 2021-04-02 v2.47 Cross-referencing by name of section
-(/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty
-Package: refcount 2019/12/15 v3.6 Data extraction from label references (HO)
-) (/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty
-Package: gettitlestring 2019/12/15 v1.6 Cleanup title references (HO)
-)
-\c@section@level=\count318
-)
-LaTeX Info: Redefining \ref on input line 118.
-LaTeX Info: Redefining \pageref on input line 118.
-LaTeX Info: Redefining \nameref on input line 118.
+Package hyperref Info: Link coloring OFF on input line 125.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(1)/m/n' will be
-(Font) scaled to size 12.0pt on input line 120.
+(Font) scaled to size 12.0pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(1)/m/n' will be
-(Font) scaled to size 8.0pt on input line 120.
+(Font) scaled to size 8.0pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(1)/m/n' will be
-(Font) scaled to size 6.0pt on input line 120.
+(Font) scaled to size 6.0pt on input line 127.
LaTeX Font Info: Trying to load font information for OML+lmm on input line 1
-20.
+27.
(/usr/share/texmf/tex/latex/lm/omllmm.fd
-File: omllmm.fd 2009/10/30 v1.6 Font defs for Latin Modern
+File: omllmm.fd 2015/05/01 v1.6.1 Font defs for Latin Modern
)
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(2)/m/n' will be
-(Font) scaled to size 12.0011pt on input line 120.
+(Font) scaled to size 12.0011pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(2)/m/n' will be
-(Font) scaled to size 8.00073pt on input line 120.
+(Font) scaled to size 8.00073pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(2)/m/n' will be
-(Font) scaled to size 6.00055pt on input line 120.
+(Font) scaled to size 6.00055pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(3)/m/n' will be
-(Font) scaled to size 11.99872pt on input line 120.
+(Font) scaled to size 11.99872pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(3)/m/n' will be
-(Font) scaled to size 7.99915pt on input line 120.
+(Font) scaled to size 7.99915pt on input line 127.
LaTeX Font Info: Font shape `TU/latinmodern-math.otf(3)/m/n' will be
-(Font) scaled to size 5.99936pt on input line 120.
-LaTeX Font Info: Trying to load font information for U+msa on input line 120
+(Font) scaled to size 5.99936pt on input line 127.
+LaTeX Font Info: Trying to load font information for U+msa on input line 127
.
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd
File: umsa.fd 2013/01/14 v3.01 AMS symbols A
) (/usr/share/texlive/texmf-dist/tex/latex/microtype/mt-msa.cfg
File: mt-msa.cfg 2006/02/04 v1.1 microtype config. file: AMS symbols (a) (RS)
)
-LaTeX Font Info: Trying to load font information for U+msb on input line 120
+LaTeX Font Info: Trying to load font information for U+msb on input line 127
.
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd
File: umsb.fd 2013/01/14 v3.01 AMS symbols B
@@ -808,15 +821,20 @@ LaTeX Font Info: Font shape `TU/latinmodern-math.otf(3)/m/n' will be
[4]
Chapter 1.
LaTeX Font Info: Font shape `TU/lmtt/bx/n' in size <24.88> not available
-(Font) Font shape `TU/lmtt/b/n' tried instead on input line 126.
+(Font) Font shape `TU/lmtt/b/n' tried instead on input line 133.
LaTeX Font Info: Font shape `TU/lmtt/bx/n' in size <14.4> not available
-(Font) Font shape `TU/lmtt/b/n' tried instead on input line 134.
+(Font) Font shape `TU/lmtt/b/n' tried instead on input line 141.
Underfull \vbox (badness 1205) has occurred while \output is active []
[5
]
+
+LaTeX Font Warning: Font shape `TU/lmtt/bx/it' in size <10> not available
+(Font) Font shape `TU/lmtt/b/sl' tried instead on input line 171.
+
+
Underfull \vbox (badness 4108) has occurred while \output is active []
[6]
@@ -838,163 +856,163 @@ Underfull \vbox (badness 6188) has occurred while \output is active []
[11] [12]
Chapter 3.
LaTeX Font Info: Font shape `TU/lmtt/bx/n' in size <12> not available
-(Font) Font shape `TU/lmtt/b/n' tried instead on input line 404.
+(Font) Font shape `TU/lmtt/b/n' tried instead on input line 376.
[13
]
-Overfull \hbox (33.0pt too wide) in paragraph at lines 432--432
+Overfull \hbox (33.0pt too wide) in paragraph at lines 404--404
[]\TU/lmtt/m/n/10 ## PC1 PC2 PC3 PC4
PC5[]
[]
-Overfull \hbox (33.0pt too wide) in paragraph at lines 432--432
+Overfull \hbox (33.0pt too wide) in paragraph at lines 404--404
[]\TU/lmtt/m/n/10 ## [1,] -0.0369930887 0.05118246 -0.0016971586 -0.003128881 -
0.010935739[]
[]
-Overfull \hbox (33.0pt too wide) in paragraph at lines 432--432
+Overfull \hbox (33.0pt too wide) in paragraph at lines 404--404
[]\TU/lmtt/m/n/10 ## [2,] -0.0007493689 0.05942083 0.0001371682 -0.002768621 -
0.008117767[]
[]
-Overfull \hbox (33.0pt too wide) in paragraph at lines 432--432
+Overfull \hbox (33.0pt too wide) in paragraph at lines 404--404
[]\TU/lmtt/m/n/10 ## [3,] 0.0056004751 0.07419599 -0.0052612189 -0.005034502 -
0.002747104[]
[]
-Overfull \hbox (33.0pt too wide) in paragraph at lines 432--432
+Overfull \hbox (33.0pt too wide) in paragraph at lines 404--404
[]\TU/lmtt/m/n/10 ## [4,] -0.0134808326 0.06463958 -0.0458436274 -0.007887336
0.009817034[]
[]
-Overfull \hbox (33.0pt too wide) in paragraph at lines 432--432
+Overfull \hbox (33.0pt too wide) in paragraph at lines 404--404
[]\TU/lmtt/m/n/10 ## [5,] -0.0334696064 0.06863518 0.0136292227 0.007359383
0.022347215[]
[]
[14] [15]
-Overfull \hbox (75.0pt too wide) in paragraph at lines 553--553
+Overfull \hbox (75.0pt too wide) in paragraph at lines 525--525
[]\TU/lmtt/m/n/10 ## - attr(*, "Labels")= chr [1:21] "Athens" "Barcelona" "Bru
ssels" "Calais" ...[]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## [,1] [,2] [,3] [,4]
[,5][]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## Athens 2290.27468 1798.8029 53.79314 -103.82696 -156.
95511[]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## Barcelona -825.38279 546.8115 -113.85842 84.58583 291.
44076[]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## Brussels 59.18334 -367.0814 177.55291 38.79751 -95.
62045[]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## Calais -82.84597 -429.9147 300.19274 106.35369 -180.
44614[]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## Cherbourg -352.49943 -290.9084 457.35294 111.44915 -417.
49668[]
[]
-Overfull \hbox (1.5pt too wide) in paragraph at lines 571--571
+Overfull \hbox (1.5pt too wide) in paragraph at lines 543--543
[]\TU/lmtt/m/n/10 ## Cologne 293.68963 -405.3119 360.09323 -636.20238 159.
39266[]
[]
[16]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## [,1] [,2] [,3] [,4]
- [,5][]
+ [,5][]
[]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## Cimolestes -0.5613001 0.06006259 0.08414761 -0.2313084
- -0.18825039[]
+ 0.18825039[]
[]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## Maelestes -0.4186019 -0.12186005 0.25556379 0.2737995
- -0.28510479[]
+ 0.28510479[]
[]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## Batodon -0.8337640 0.28718501 -0.10594610 -0.2381511
- -0.07132646[]
+ 0.07132646[]
[]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## Bulaklestes -0.7708261 -0.07629583 0.04549285 -0.4951160
- -0.39962626[]
+ 0.39962626[]
[]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## Daulestes -0.8320466 -0.09559563 0.04336661 -0.5792351
- -0.37385914[]
+ 0.37385914[]
[]
-Overfull \hbox (38.25pt too wide) in paragraph at lines 622--622
+Overfull \hbox (33.0pt too wide) in paragraph at lines 594--594
[]\TU/lmtt/m/n/10 ## Uchkudukodon -0.5074468 -0.34273248 0.40410310 -0.1223782
- -0.34857351[]
+ 0.34857351[]
[]
-Overfull \hbox (27.75pt too wide) in paragraph at lines 637--637
-[]\TU/lmtt/m/n/10 ## [,1] [,2] [,3] [,4]
- [,5][]
+Overfull \hbox (38.25pt too wide) in paragraph at lines 609--609
+[]\TU/lmtt/m/n/10 ## [,1] [,2] [,3] [,4]
+ [,5][]
[]
-Overfull \hbox (27.75pt too wide) in paragraph at lines 637--637
-[]\TU/lmtt/m/n/10 ## Cimolestes -0.6794737 0.15658591 0.04918307 0.22509831 -
-0.38139436[]
+Overfull \hbox (38.25pt too wide) in paragraph at lines 609--609
+[]\TU/lmtt/m/n/10 ## Cimolestes -0.6662114 0.152778203 0.04859246 -0.34158286
+ 0.26817202[]
[]
-Overfull \hbox (27.75pt too wide) in paragraph at lines 637--637
-[]\TU/lmtt/m/n/10 ## Maelestes -0.5797289 0.04223105 -0.20329542 -0.15453876 -
-0.06993258[]
+Overfull \hbox (38.25pt too wide) in paragraph at lines 609--609
+[]\TU/lmtt/m/n/10 ## Maelestes -0.5719365 0.051636855 -0.19877079 -0.08318416
+ -0.14166592[]
[]
-Overfull \hbox (27.75pt too wide) in paragraph at lines 637--637
-[]\TU/lmtt/m/n/10 ## n48 0.2614394 0.01712426 0.21997583 -0.05383777
-0.07919679[]
+Overfull \hbox (38.25pt too wide) in paragraph at lines 609--609
+[]\TU/lmtt/m/n/10 ## n48 0.2511551 -0.002014967 0.22408002 0.06857018
+ -0.05660113[]
[]
-Overfull \hbox (27.75pt too wide) in paragraph at lines 637--637
-[]\TU/lmtt/m/n/10 ## n49 0.3881123 0.13771446 0.11966941 0.01856597 -
-0.15263921[]
+Overfull \hbox (38.25pt too wide) in paragraph at lines 609--609
+[]\TU/lmtt/m/n/10 ## n49 0.3860798 0.131742956 0.12604056 -0.14738050
+ 0.05095751[]
[]
[17]
@@ -1005,7 +1023,7 @@ ype pdf)
Underfull \vbox (badness 10000) has occurred while \output is active []
[18]
-Overfull \hbox (180.0pt too wide) in paragraph at lines 719--719
+Overfull \hbox (180.0pt too wide) in paragraph at lines 691--691
[]\TU/lmtt/m/n/10 ## 3 discrete time subsets for 50 elements in one matrix with
48 dimensions with 1 phylogenetic tree[]
[]
@@ -1015,10 +1033,10 @@ File: dispRity_manual_files/figure-latex/unnamed-chunk-16-1.pdf Graphic file (t
ype pdf)