Learn R Programming

aphylo (version 0.3-3)

posterior-probabilities: Posterior probabilities based on parameter estimates

Description

The function predict_pre_order uses a pre-order algorithm to compute the posterior probabilities, whereas the predict_brute_force computes posterior probabilities generating all possible cases.

Usage

# S3 method for aphylo_estimates
predict(
  object,
  which.tree = NULL,
  ids = NULL,
  newdata = NULL,
  params = stats::coef(object),
  loo = TRUE,
  nsamples = 1L,
  centiles = c(0.025, 0.5, 0.975),
  cl = NULL,
  ...
)

predict_pre_order(x, ...)

# S3 method for aphylo_estimates predict_pre_order( x, params = stats::coef(x), which.tree = 1:Ntrees(x), ids = lapply(Ntip(x)[which.tree], seq_len), loo = TRUE, nsamples = 1L, centiles = c(0.025, 0.5, 0.975), ncores = 1L, cl = NULL, ... )

# S3 method for aphylo predict_pre_order(x, psi, mu_d, mu_s, eta, Pi, ...)

predict_brute_force(atree, psi, mu_d, mu_s, Pi, force = FALSE)

Value

In the case of the predict method, a P column numeric matrix with values between \([0,1]\) (probabilities).

Arguments

which.tree

Integer scalar. Which tree to include in the prediction.

ids

Integer vector. Ids (positions) of the nodes that need to be predicted (see details.)

newdata

(optional) An aphylo object.

params

A numeric vector with the corresponding parameters.

loo

Logical scalar. When loo = TRUE, predictions are preformed similar to what a leave-one-out cross-validation scheme would be done (see predict.aphylo_estimates).

nsamples

Integer scalar. When greater than one, the prediction is done using a random sample from the MCMC chain. This only works if the model was fitted using MCMC, of course.

centiles

Used together with nsamples, this indicates the centiles to be computed from the distribution of outcomes.

...

Ignored.

ncores, cl

Passed to parallel::makeCluster().

psi

Numeric vector of length 2. Misclasification probabilities. (see LogLike).

mu_d, mu_s

Numeric vector of length 2. Gain/loss probabilities (see LogLike).

eta

Numeric vector of length 2. Annotation bias probabilities (see LogLike).

Pi

Numeric scalar. Root node probability of having the function (see LogLike).

atree, x, object

Either a tree of class aphylo or an object of class aphylo_estimates

force

Logical scalar. When TRUE it will try to compute the brute-force probabilities for trees with more than 7 nodes.

Prediction on specific nodes

The ids parameter indicates for which nodes, both internal and tips, the predictions should be made. By default, the function will only make predictions on the leaf nodes.

The ids follow ape's convention, this is, 1:Ntips(x) are the leaf nodes, Ntips(x) + 1L is the root node, and everything else are the interior nodes.

Although the prediction algorithm is fast, indicating only a subset of the nodes could make a difference when loo = TRUE and/or nsamples > 1 (calculating a Credible/Confidence Interval.)

In the case of multiAphylo, ids should be passed as a list of length Ntrees(x), with each element indicating the nodes. Otherwise, ids are passed as an integer vector.

Details

The function predict_brute_force is only intended for testing. For predictions after estimating the model, see predict.aphylo_estimates.

In the case of the parameter loo (leave-one-out), while making tip-level predictions, at each leaf the algorithm will drop annotations regarding that leaf, making its prediction using all the available information except the one include in such leaf.

The predict_brute_force function makes the (obviously) brute force calculation of the probabilities. It will perform It returns a list with the following:

  • Pr The conditional probabilities of observing a tree given a particular state of the leave nodes. The size is given by (2^nnodes x 2^nleaves), each entry is read as "The probability of observing scenario i (row) given that the leaves have state j (colum)." The scenarios are specified in the row matrix returned by the function.

  • row Indicates the state of each node (columns) per scenario (row).

  • col Indicates the state of each leaf node (columns) per potential leaf scenario.

Examples

Run this code
# Single tree ---------------------------------------------------------------
set.seed(123)
atree <- raphylo(10)

# Fitting the model with MLE
ans <- aphylo_mle(atree ~ psi + mu_d + mu_s + Pi)

# Prediction on leaves
predict(ans)

# Prediction on all nodes (including root and interior)
predict(ans, ids = 1:Nnode(ans, internal.only = FALSE))

# Multiple trees (multiAphylo) ----------------------------------------------
atree <- c(raphylo(10), raphylo(5))

# Fitting the model with MLE
ans <- aphylo_mle(atree ~ psi + mu_d + mu_s + Pi)

# Prediction on leaves
predict(ans)

# Predicting only interior nodes
predict(ans, ids = list(11:19, 6:9))

Run the code above in your browser using DataLab