ShiVa Example"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Introduction

This vignette demonstrates how to use the ShiVa R package to detect evolutionary shifts in both optimal trait values (mean) and evolutionary variance under an Ornstein-Uhlenbeck (OU) model. We illustrate the process using a floral trait dataset from Euphorbiaceae species. It is available at phylolm.

library(ShiVa)
library(phylolm)

Setup

Load the required packages:

data('flowerTree')
data('flowerSize')

Load example data

We load the phylogenetic tree and trait data. The trait is floral diameter, log-transformed.

Y = flowerSize$log_transformed_size
names(Y) = rownames(flowerSize)
tree = flowerTree
# normalize the tree
tree$edge.length = flowerTree$edge.length/max(node.depth.edgelength(flowerTree))

Run ShiVa

set.seed(111)
result = ShiVa(Y,tree, lambda.type = "lambda.min")

Visualize Detected Shifts

plot(result$best_model,title = "ShiVa")

Summarize Shifts

print(summary(result$best_model))


Try the ShiVa package in your browser

Any scripts or data that you put into this service are public.

ShiVa documentation built on Aug. 22, 2025, 9:14 a.m.