A user-friendly wrapper for any random effect whose covariance is a
user-supplied matrix. Mirrors brms's (1 | gr(species, cov = M)).
Inside a gllvmTMB() formula, this desugars to
propto(0 + group | trait). The actual covariance matrix used by
the engine is the top-level phylo_vcv = argument of gllvmTMB() when
one is supplied; otherwise the formula-level cov = matrix is used. When
both are given, the top-level phylo_vcv = wins and cov = is ignored.
Same convention as phylo() and phylo_rr().
Arguments
- group
An unquoted column name giving the grouping factor.
- cov
Optional covariance matrix. Used when no top-level
phylo_vcvis passed togllvmTMB(); ignored whenphylo_vcvis also supplied.
Examples
if (requireNamespace("ape", quietly = TRUE)) {
set.seed(1)
tree <- ape::rcoal(60); tree$tip.label <- paste0("sp", seq_len(60))
sim <- simulate_site_trait(
n_sites = 1, n_species = 60, n_traits = 3,
mean_species_per_site = 60,
Cphy = ape::vcv(tree, corr = TRUE),
sigma2_phy = rep(1, 3), sigma2_eps = 0.2, seed = 1
)
df <- sim$data
df$species <- factor(tree$tip.label[as.integer(df$species)],
levels = tree$tip.label)
Cphy <- ape::vcv(tree, corr = TRUE)
# \donttest{
# gr() is a deprecated alias and prints a message; new code can use
# phylo_indep(0 + trait | species, tree = tree, common = TRUE).
fit <- gllvmTMB(value ~ 0 + trait + gr(species),
data = df,
trait = "trait",
unit = "species",
cluster = "species",
phylo_vcv = Cphy)
# }
}
#> ! Formula keyword `gr()` is a deprecated alias; use `phylo_indep()` for new
#> code.
#> ℹ `phylo_indep(0 + trait | species, common = TRUE)` =/=> `gr(species)`
#> → Aliases will be dropped at the next minor release. See `?phylo_indep`.
