Tutorial 13: Phylogenetic GLM for binary and count data
Objectives
Fit a binomial model for a binary trait and a Poisson model for a count trait. Check the response, model family, and fit diagnostics before interpreting coefficient estimates.
Prerequisites and working directory
Install PhyKIT and create a working directory. Save the tutorial files there under the listed names, then run the commands from that directory.
mkdir phykit-tutorial-13
cd phykit-tutorial-13
Download these example files into that directory.
Workflow
Standard PGLS handles continuous response variables. When the response is binary (e.g., presence/absence) or count data (e.g., number of offspring), a Generalized Linear Model is needed. Phylogenetic GLM extends GLM to account for phylogenetic non-independence among species.
Hypothetical study question. Is body mass a significant predictor of a binary trait (e.g., dietary specialization) or a count trait (e.g., litter size) after accounting for phylogenetic relationships?
PhyKIT's phylogenetic_glm command (aliases: phylo_glm, pglm) supports
two families: binomial (logistic MPLE) and Poisson (GEE).
Step 1: Fit a binomial (logistic) model
Test whether body mass predicts a binary trait:
phykit phylogenetic_glm \
-t tree_simple.tre \
-d tree_simple_glm_traits.tsv \
-y binary_trait \
-x body_mass \
--family binomial
Phylogenetic GLM (Logistic MPLE)
Formula: binary_trait ~ body_mass
Family: binomial, Method: logistic_MPLE
Estimated alpha: 0.0215
Coefficients:
Estimate Std.Error z-value p-value
(Intercept) -2.2374 2.0639 -1.0841 0.278342
body_mass 2.2432 1.6808 1.3346 0.181992
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1
Log-likelihood: -1.8327 AIC: 9.6653
Pseudo-R² (McFadden): 0.6131
Number of observations: 8
The logistic MPLE method jointly estimates regression coefficients and the phylogenetic parameter alpha. In this run, the body-mass coefficient is positive with substantial uncertainty (p = 0.182). Treat the fitted values as an example of the output from an eight-observation dataset. Optimizer results can vary slightly across environments.
Step 2: Fit a Poisson model for count data
Test whether body mass predicts count data:
phykit phylogenetic_glm \
-t tree_simple.tre \
-d tree_simple_glm_traits.tsv \
-y count_trait \
-x body_mass \
--family poisson
Phylogenetic GLM (Poisson GEE)
Formula: count_trait ~ body_mass
Family: poisson, Method: poisson_GEE
Overdispersion (phi): 0.1730
Coefficients:
Estimate Std.Error z-value p-value
(Intercept) 0.6741 0.1678 4.0176 0.000059 ***
body_mass 0.5968 0.0877 6.8082 0.000000 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1
Log-likelihood: -13.4024 AIC: 30.8048
Number of observations: 8
The Poisson GEE uses phylogenetic correlations derived from the tree and reports the overdispersion parameter phi. Both predictors are highly significant.
Step 3: Export results as JSON
phykit phylogenetic_glm \
-t tree_simple.tre \
-d tree_simple_glm_traits.tsv \
-y count_trait \
-x body_mass \
--family poisson \
--json
Summary
In this tutorial, we used phylogenetic GLMs to model binary and count response variables while accounting for phylogenetic non-independence. The key steps were: (1) fitting a logistic model for binary data with the binomial family, (2) fitting a Poisson model for count data, and (3) exporting results as JSON. Phylogenetic GLM complements PGLS by handling non-continuous response variables.
For methodological details, see
Ives and Garland (2010) for logistic MPLE
and Paradis and Claude (2002)
for Poisson GEE. The R equivalent is phylolm::phyloglm().
Expected artifacts
The two fits each use eight observations. The output names the model family and reports coefficients with standard errors. The Poisson output also reports dispersion.
Troubleshooting
Run
phykit <command> --helpto compare an invocation with the live interface.Confirm that downloaded files are in the current working directory and retain the filenames shown in the tutorial.
For parsing errors, compare taxon names exactly across alignments, trees, and trait tables, including capitalization and underscores.
See Troubleshooting for installation, format, and error-reporting guidance.