## Creating a dispRity
data(charadriiformes)
## Creating a dispRity object from the charadriiformes model
covar_data <- MCMCglmm.subsets(data = charadriiformes$data,
posteriors = charadriiformes$posteriors)
## Get one matrix and one covar matrix
one_matrix <- get.matrix(covar_data, subsets = 1)
one_covar <- get.covar(covar_data, subsets = 1, n = 1)[[1]][[1]]
## Measure the centroids
centroids(one_matrix)
## Measure the centroids on the covar matrix
as.covar(centroids)(one_covar)
## Is the same as:
centroids(one_covar$VCV)
## Apply the measurement on a dispRity object:
## On the traitspace:
summary(dispRity(covar_data, metric = c(sum, centroids)))
## On the covariance matrices:
summary(dispRity(covar_data, metric = c(sum, as.covar(centroids))))
## The same but with additional options (centre = 100)
summary(dispRity(covar_data,
metric = c(sum, as.covar(centroids)),
centre = 100))
## Example with the VCV and loc options
## A metric that works with both VCV and loc
## (the sum of the variances minus the distance from the location)
sum.var.dist <- function(matrix, loc = rep(0, ncol(matrix))) {
## Get the sum of the diagonal of the matrix
sum_diag <- sum(diag(matrix))
## Get the distance between 0 and the loc
dist_loc <- dist(matrix(c(rep(0, ncol(matrix)), loc), nrow = 2, byrow = TRUE))[1]
## Return the sum of the diagonal minus the distance
return(sum_diag - dist_loc)
}
## Changing the $loc on one_covar for the demonstration
one_covar$loc <- c(1, 2, 3)
## Metric on the VCV part only
as.covar(sum.var.dist, VCV = TRUE, loc = FALSE)(one_covar)
## Metric on the loc part only
as.covar(sum.var.dist, VCV = FALSE, loc = TRUE)(one_covar)
## Metric on both parts
as.covar(sum.var.dist, VCV = TRUE, loc = TRUE)(one_covar)
Run the code above in your browser using DataLab