Learn R Programming

ShiVa (version 1.0.1)

fit_OU_mean_var: Fit OU Model with Shifts in Mean and Variance

Description

Fits an Ornstein-Uhlenbeck (OU) model with user-specified shifts in both optimal trait values (mean) and evolutionary variance along a phylogeny. The method uses numerical optimization to estimate shift magnitudes, base variance, and intercept, and can optionally incorporate measurement error in trait values.

Usage

fit_OU_mean_var(
  tree,
  Y,
  alpha,
  shifts_mean,
  shifts_var,
  max.steps = 1000,
  t = 0.01,
  thres = 0.01,
  measurement_error = FALSE,
  max.num.shifts = Inf
)

Value

A list containing:

tree

The phylogenetic tree.

Y

The trait values.

shifts_mean

Indices of branches with non-zero shifts in optimal trait value.

shifts_var

Indices of branches with non-zero shifts in evolutionary variance.

beta

Estimated shift magnitudes for optima values.

gamma

Estimated shift magnitudes for variance.

sigma2

Estimated base evolutionary variance.

b0

Estimated intercept (ancestral trait value).

sigma2_error

Estimated measurement error variance (only returned if measurement_error = TRUE).

loglik

Log-likelihood of the fitted model.

BIC

BBIC for model selection.

mBIC

mBIC for accounting shift sparsity and shared support.

pBIC

pBIC incorporating determinant of projected design matrix.

fitted.values

Fitted trait values based on the estimated model.

Sigma

Estimated trait covariance matrix under the fitted model.

Arguments

tree

A phylogenetic tree of class phylo.

Y

A numeric vector of continuous trait values at the tips of the tree.

alpha

A non-negative numeric value specifying the strength of selection in the OU process.

shifts_mean

An integer vector indicating the indices of branches where shifts in the optimal trait value occur.

shifts_var

An integer vector indicating the indices of branches where shifts in evolutionary variance occur.

max.steps

Maximum number of optimization steps. Default is 1000.

t

Step size for the optimizer. Default is 0.01.

thres

Convergence threshold for change in log-likelihood. Default is 0.01.

measurement_error

Logical. If TRUE, a separate measurement error variance is estimated and added to the diagonal of the covariance matrix.

max.num.shifts

Maximum allowed number of shifts (combined for mean and variance). Default is Inf.