Title: | Fast Evolutionary Trait Modelling on Phylogenies using Branch Regression Models |
---|---|
Description: | Implements Phylogenetic Branch Regression models which allow for flexible and versatile models of evolution along a phylogeny. The model can be used to detect shifts in rates of evolution along branches. The model uses a continuous and linear model structure and so can be easily combined with other non-phylogenetic statistical structures, as long as they are implemented using the R package INLA. One major uses of this are to condition on phylogeny in a standard regression between two traits, thus 'accounting' for phylogenetic structure in the response variable, similar to how pgls is used but allowing for a more flexible phylogenetic model. This also allows the phylogenetic model to be combined with the spatial models that INLA excels at (and with comparable flexibility to those spatial models). |
Authors: | Russell Dinnage [aut, cre] |
Maintainer: | Russell Dinnage <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9000 |
Built: | 2024-11-01 04:12:08 UTC |
Source: | https://github.com/rdinnager/fibre |
This function is meant to be called only in the formula
argument of fibre()
.
bre( phyf, rate_distribution = c("iid", "laplacian", "student-t", "horseshoe", "Brownian", "re"), hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), latent = 0, label = NULL, standardise = TRUE )
bre( phyf, rate_distribution = c("iid", "laplacian", "student-t", "horseshoe", "Brownian", "re"), hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), latent = 0, label = NULL, standardise = TRUE )
phyf |
A |
rate_distribution |
What distribution to use to model rates of evolution? |
hyper |
Hyper parameters as a list. Specify the prior distribution for
|
latent |
How many latent variables to generate in |
label |
An optional label used to identify the random effect later
The default is a label generated from the expression in |
standardise |
Should the |
A list of data to be used by the model.
This function is meant to be called only in the formula
argument of fibre()
.
bre_brownian( phyf, hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), latent = 0, label = NULL, standardise = TRUE )
bre_brownian( phyf, hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), latent = 0, label = NULL, standardise = TRUE )
phyf |
A |
hyper |
Hyper parameters as a list. Specify the prior distribution for
|
latent |
How many latent variables to generate in |
label |
An optional label used to identify the random effect later
The default is a label generated from the expression in |
standardise |
Should the |
A list of data to be used by the model.
This function is meant to be called only in the formula
argument of fibre()
.
bre_second_order( phyf, hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), latent = 0, label = NULL, standardise = TRUE )
bre_second_order( phyf, hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), latent = 0, label = NULL, standardise = TRUE )
phyf |
A |
hyper |
Hyper parameters as a list. Specify the prior distribution for
|
latent |
How many latent variables to generate in |
label |
An optional label used to identify the random effect later
The default is a label generated from the expression in |
standardise |
Should the |
A list of data to be used by the model.
Create a Evolutionary Autodecoder Model
evo_autodecoder( latent_dim, n_edges, decoder, reconstruction_loss, device, decoder_args = list(), loss_args = list() )
evo_autodecoder( latent_dim, n_edges, decoder, reconstruction_loss, device, decoder_args = list(), loss_args = list() )
latent_dim |
Number of latent dimensions |
decoder |
A |
A torch::nn_module()
fibre
fibre()
fits a model.
fibre(x, ...) ## Default S3 method: fibre(x, ...) ## S3 method for class 'data.frame' fibre( x, y, intercept = TRUE, engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... ) ## S3 method for class 'matrix' fibre( x, y, intercept = TRUE, engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... ) ## S3 method for class 'formula' fibre( formula, data, intercept = TRUE, family = "gaussian", engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... ) ## S3 method for class 'recipe' fibre( x, data, intercept = TRUE, engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... )
fibre(x, ...) ## Default S3 method: fibre(x, ...) ## S3 method for class 'data.frame' fibre( x, y, intercept = TRUE, engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... ) ## S3 method for class 'matrix' fibre( x, y, intercept = TRUE, engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... ) ## S3 method for class 'formula' fibre( formula, data, intercept = TRUE, family = "gaussian", engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... ) ## S3 method for class 'recipe' fibre( x, data, intercept = TRUE, engine = c("inla", "glmnet", "torch"), engine_options = list(), ncores = NULL, verbose = 0, ... )
x |
Depending on the context:
|
... |
Not currently used, but required for extensibility. |
y |
When
|
formula |
A formula specifying the outcome terms on the left-hand side, and the predictor terms on the right-hand side. |
data |
When a recipe or formula is used,
|
A fibre
object.
predictors <- mtcars[, -1] outcome <- mtcars[, 1] # XY interface #mod <- fibre(predictors, outcome) # Formula interface #mod2 <- fibre(mpg ~ ., mtcars) # Recipes interface #library(recipes) #rec <- recipe(mpg ~ ., mtcars) #rec <- step_log(rec, disp) #mod3 <- fibre(rec, mtcars)
predictors <- mtcars[, -1] outcome <- mtcars[, 1] # XY interface #mod <- fibre(predictors, outcome) # Formula interface #mod2 <- fibre(mpg ~ ., mtcars) # Recipes interface #library(recipes) #rec <- recipe(mpg ~ ., mtcars) #rec <- step_log(rec, disp) #mod3 <- fibre(rec, mtcars)
Title
get_aces( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
get_aces( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
x |
A fitted model object produced by |
type |
What kind of posterior summary to return? |
n |
If |
p |
If |
For all types except "hpd", "ci", and "marginals", a numeric vector, otherwise a list for "hpd" and "marginals", and a matrix for "ci".
Title
get_rates( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
get_rates( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
x |
A fitted model object produced by |
type |
What kind of posterior summary to return? |
n |
If |
p |
If |
For all types except "hpd", "ci", and "marginals", a numeric vector, otherwise a list for "hpd" and "marginals", and a matrix for "ci".
Title
get_tces( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
get_tces( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
x |
A fitted model object produced by |
type |
What kind of posterior summary to return? |
n |
If |
p |
If |
For all types except "hpd", "ci", and "marginals", a numeric vector, otherwise a list for "hpd" and "marginals", and a matrix for "ci".
Title
get_tips( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
get_tips( x, type = c("marginals", "samples", "mode", "mean", "median", "lower", "upper", "ci", "hpd", "sd"), n = 1, p = 0.05 )
x |
A fitted model object produced by |
type |
What kind of posterior summary to return? |
n |
If |
p |
If |
For all types except "hpd", "ci", and "marginals", a numeric vector, otherwise a list for "hpd" and "marginals", and a matrix for "ci".
Load a model
load_model(name)
load_model(name)
name |
Name of the model. Currently only |
A torch::nn_module()
with pre-trained weights
if(torch::torch_is_installed()) { model <- load_model("bird_beaks") }
if(torch::torch_is_installed()) { model <- load_model("bird_beaks") }
fibre
Predict from a fibre
## S3 method for class 'fibre' predict(object, new_data = NULL, type = "numeric", ...)
## S3 method for class 'fibre' predict(object, new_data = NULL, type = "numeric", ...)
object |
A |
new_data |
A data frame or matrix of new predictors. |
type |
A single character. The type of predictions to generate. Valid options are:
|
... |
Not used, but required for extensibility. |
A tibble of predictions. The number of rows in the tibble is guaranteed
to be the same as the number of rows in new_data
.
train <- mtcars[1:20,] test <- mtcars[21:32, -1] # Fit #mod <- fibre(mpg ~ cyl + log(drat), train) # Predict, with preprocessing #predict(mod, test)
train <- mtcars[1:20,] test <- mtcars[21:32, -1] # Fit #mod <- fibre(mpg ~ cyl + log(drat), train) # Predict, with preprocessing #predict(mod, test)
This function is meant to be called only in the formula
argument of fibre()
.
re( groups, hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), label = NULL, standardise = TRUE )
re( groups, hyper = list(prec = list(prior = "pc.prec", param = c(1, 0.1))), label = NULL, standardise = TRUE )
groups |
A character or factor column containing the grouping variable for the random effect |
hyper |
Hyper parameters as a list. Specify the prior distribution for
|
label |
An optional label used to identify the random effect later
The default is a label generated from the expression in |
standardise |
Should the |
A list of data to be used by the model.
A signed distance field based neural network model for generating 3d shapes
sdf_net(n_latent = 64, breadth = 512)
sdf_net(n_latent = 64, breadth = 512)
n_latent |
Number of dimensions for the latent space |
breadth |
Breadth of the multilayer perceptron networks |
A torch::nn_module()
if(torch::torch_is_installed()) { sdf_net() }
if(torch::torch_is_installed()) { sdf_net() }
Function to simulate continuous trait value histories on a phylogeny.
simulate_traits( phy, rate_model = c("continuous", "discrete"), temp_trend_rates = 0, rate_change, rates = NULL, anc = c(`1` = 0), internal = FALSE, nsim = 1, pos_strat = c("none", "log", "add_const"), temp_trend_mean = 0 )
simulate_traits( phy, rate_model = c("continuous", "discrete"), temp_trend_rates = 0, rate_change, rates = NULL, anc = c(`1` = 0), internal = FALSE, nsim = 1, pos_strat = c("none", "log", "add_const"), temp_trend_mean = 0 )
phy |
A phylogenetic tree (phylo object) on which to simulate traits |
rate_model |
The type of rate model for how rates of evolution evolve on the phylogeny: "continuous" for continuous Brownian motion evolution of rates, or "discrete" for evolution of rate "classes" across the phylogeny, using an mk model. |
temp_trend_rates |
What temporal trend in rates should there be? A positive number for an increase, and negative number for a decrease with the magnitude controlling the strength of linear change. This trend is added to rates simulated under the rate_model. |
rate_change |
If |
rates |
Only used if |
anc |
Value of the trait at the root ancestor. For |
internal |
Logical value. If |
nsim |
Number of simulation to run. |
pos_strat |
? |
temp_trend_mean |
A temporal trend in rates. |
A vector or matrix (for nsim > 1
) containing simulated trait values
for each tip if internal = FALSE
, or for each node if internal = TRUE
Tidy Model Results
## S3 method for class 'fibre' tidy( x, effects = c("fixed", "rates", "random", "hyper"), conf.type = c("cred.int", "marginals"), indexes = NULL, ... )
## S3 method for class 'fibre' tidy( x, effects = c("fixed", "rates", "random", "hyper"), conf.type = c("cred.int", "marginals"), indexes = NULL, ... )
x |
A |
effects |
Which effects do you want tidied? One of: |
conf.type |
What kind of confidence interval. Choices are:
|
indexes |
If |
... |
Not used. |
A tidy tibble
with information about the fitted model parameters.