
Nested regression in phylogenetic comparative methods
James T. Thorson
Source:vignettes/web_only/nested.Rmd
nested.RmdSpecies traits include parameters that represent a function-valued trait. In fishes, for example, we often treat growth parameters as species traits, and proceed by first fitting a von Bertalanffy growth function (VBGF) to measurements of animal length and age, extract estimated parameters, and then include those parameters in a second-stage model for trait imputation. In this case, animal growth is a function-valued trait using the VBGF, and VBGF parameters are treated as species traits.
As alternative to this two-stage process, phylosem allows us to fit a regression model to lower-level measurements, and then treat some of those estimated parameters as traits that are then used in the phylogenetic structural equation model. Here, we demonstrate the method using an example of natural mortality for fishes at different lengths.
Natural mortality at length
We first fit the model to data from (Gislason et al. 2010), which includes published values for natural mortality of fishes at different lengths. We first load the data table and tree:
# Load packages
library(phylosem)
# Load data
data( gislason_2010 )
tree = gislason_2010$tree
experiments = gislason_2010$dataNext, the key step is to make a list within_tips, where
each element is processed using phylosem::linear (for
linear models) or phylosem::beverton_holt (for a
Beverton-Holt, a.k.a. Michaelis-Menten function). Here, we use the
linear option, which involves specifying a linear model
formula.
# Format for phylosem
within_tips = vector("list", length = length(unique(experiments$validName)))
names(within_tips) = unique(experiments$validName)
for( i in seq_along(within_tips) ){
sub = subset( experiments, validName == names(within_tips)[i] )
within_tips[[i]] = linear(
taxon = names(within_tips)[i],
data = sub,
formula = log(M) ~ 1 + log(L) + log(Linf) + log(K)
)
}Then, we specify which of the estimated parameters from that linear model is treated as a species trait within the phylogenetic structural equation model. In this case, we will estimate phylogenetic variation in the intercept, representing among-species evolutionary variation in excess natural mortality after controlling for predictors:
# User interface
data = data.frame(
"(Intercept)" = rep(NA_real_,ape::Ntip(tree)),
check.names = FALSE
)Finally, we can then specify the paths of the PSEM and fit the model:
sem = "
(Intercept) <-> (Intercept), sd_residual
"
fit = phylosem(
data = data,
data_labels = tree$tip.label,
sem = sem,
tree = tree,
within_tips = within_tips,
)Any parameter from the linear model that is not included in
data are treated as constant across the phylogeny and
estimated as gamma_m:
# Display estimates
table = subset( summary(fit$sdrep), rownames(summary(fit$sdrep)) == "gamma_m")
table = data.frame( Parameter = c("L","Linf","K"), table )
knitr::kable(table, digits=3)| Parameter | Estimate | Std..Error | |
|---|---|---|---|
| gamma_m | L | -1.304 | 0.130 |
| gamma_m.1 | Linf | 0.877 | 0.183 |
| gamma_m.2 | K | 0.692 | 0.123 |
These estimates differ from the original published results from (Gislason et al. 2010). However, we can replicate those original results by eliminating the phylogenetic correlations. To do so, we simply change the PSEM to not include any linear-model parameters (such that they are all then treated as constant across species), while also including a dummy variable with known variance (so that PSEM has at least one variable included):
# User interface
data = data.frame(
"dummy" = rep(NA_real_,ape::Ntip(tree)),
check.names = FALSE
)
sem = "
dummy <-> dummy, NA, 1
"
fit = phylosem(
data = data,
data_labels = tree$tip.label,
sem = sem,
tree = tree,
estimate_xbar = character(),
within_tips = within_tips,
)
#> Coefficient_name Number_of_coefficients Type
#> 1 gamma_m 4 Fixed
#> 2 logsigmaY_q 1 Fixed
#> 3 x_vj 167 Random
# Display estimates
table = subset( summary(fit$sdrep), rownames(summary(fit$sdrep)) == "gamma_m")
rownames(table) = NULL
table = data.frame( Parameter = c("Intercept","log(L)","log(Linf)","log(K)"), table )
knitr::kable(table, digits=3)| Parameter | Estimate | Std..Error |
|---|---|---|
| Intercept | 0.624 | 0.297 |
| log(L) | -1.618 | 0.137 |
| log(Linf) | 1.394 | 0.124 |
| log(K) | 0.915 | 0.080 |
We then compare that with a standard linear model
Lm = lm(
log(M) ~ 1 + log(L) + log(Linf) + log(K),
data = experiments
)
# Display estimates
table = summary(Lm)$coefficients[,1:2]
knitr::kable(table, digits=3)| Estimate | Std. Error | |
|---|---|---|
| (Intercept) | 0.624 | 0.300 |
| log(L) | -1.618 | 0.139 |
| log(Linf) | 1.394 | 0.126 |
| log(K) | 0.915 | 0.081 |
This confirms that phylosem behaves (almost) identically to the linear model when it is expecte to do so.