Red knots: how physiology and behaviour vary together
An online extension showing how incomplete repeated measurements can inform between-bird and within-period covariance models.
Question. Do red knots that differ in one physiological or behavioural measure also differ in another? When a measure differs from a bird’s usual value, how does another measure tend to differ within that recorded period?
Body mass, gizzard mass and basal metabolic rate describe different aspects of a bird’s physiology. Exploration, activity and feeding describe its behaviour. Do birds with a larger gizzard tend to be heavier? When a bird has a larger gizzard than usual, is it also heavier than usual during that period? These are two questions about trait integration. The first compares birds, and the second compares periods within each bird.
The model estimates a mean for each trait and keeps all observed responses. Year and diet are left out of the mean model, so differences associated with the study design can contribute to the fitted associations.
The measurements come from captive red knots studied across non-breeding seasons (Kok et al. 2019; Mathot et al. 2020). The included file combines the data used in those studies; both are cited in the data notes and References. All input data and scripts are included here so the analysis can be run from a repository checkout.
Choose a route. Start with the three sample counts. To work in R, prepare the data, read the saved fit checks and recalculate the mass–gizzard contrast. To read along, follow the figure and the two contrasting examples of uncertainty. Both routes end at Finish the example. Fresh fits are under Go further.
The dataset contains 58 birds, 464 periods and 2,101 observed measurements across six traits. Each period is one bird-by-year-by-replicate record and can contribute several measurements. The 58 birds provide the individuals for estimating between-bird associations. Their repeated periods provide the comparisons within birds. The 2,101 measurements are the observed trait values across those periods.
Look at the counts for whatever traits you want to compare. Body mass and gizzard mass were recorded in all 464 periods. Activity and feeding each have 161 observations from 54 birds, all in year 1. A dataset with hundreds of periods can still give wide intervals for particular associations. The worked intervals below show what that looks like.
Trait
Observed values
Missing values
Body mass
464
0
Gizzard mass
464
0
Basal metabolic rate
387
77
Exploration
464
0
Activity
161
303
Feeding
161
303
Missing responses are left missing, never changed to zero. A missing cell contributes no direct response value, while other observed traits from that bird-period still contribute. This is one practical advantage of the multivariate likelihood, but it does not make every missingness pattern harmless. Activity and feeding each have 161 observations from 54 birds, all from year 1. These records cannot tell us how their associations change across years.
Prepare the traits
The three proportions, activity, feeding and exploration, are clipped at 0.001 and 0.999 before the logit transformation. Each trait is then standardised using its observed values. Body mass, gizzard mass and basal metabolic rate are standardised without a logit transformation. The same transformed values and missing-response mask are used in both packages.
Extract the reproduction download and work from the folder containing tutorial/ and analysis/. Install digest in R, then run the command below in a terminal. Check for 58 birds, 464 periods and 2,101 observed values.
The script stores the six-trait analysis data in analysis/cache/tutorial-data/red-knots-six-intercept.rds and writes the response-count table. The source file and the transformation rule are documented in the data notes.
Ask the two-level question
The between-bird covariance describes differences among birds in this model. The within-period covariance describes how trait departures co-vary within a bird-period. Traits in the same period were not necessarily measured at the same moment, so “within-period” does not mean simultaneous measurement. These associations may reflect short-term conditions and differences in when or how each measure was taken.
There are no diet or year terms in this example. Therefore the estimated between-bird component may include variation associated with the study design. We omit those predictors to keep attention on the two covariance levels, not because they are unimportant.
Each response has its own intercept. At each level, the model represents covariance as shared axes plus trait-specific variance. In the code, d = 2 means two shared axes. The formulae below show the matched structures; the linked runner records the seed, optimizer settings and other fitting controls used for the checked results.
value ~0+ trait +rr(0+ trait | individual, d =2) +diag(0+ trait | individual) +rr(0+ trait | occasion, d =2)
The between-bird model has two shared axes and a diagonal trait-specific component. The within-period model has two shared axes; its trait-specific variance is represented by the Gaussian dispersion model, with one dispersion for each trait.
value ~0+ trait +latent(0+ trait | individual, d =2, unique =TRUE) +latent(0+ trait | occasion, d =2, unique =TRUE)
Here unique = TRUE asks the model to include trait-specific variance alongside the shared axes at both levels. Both packages use the same 2,101 observed responses and maximum-likelihood target.
Check the saved fit
The point estimates and intervals on this page belong to the six-trait model with two axes at each level. The bootstrap uses the selected gllvmTMB model. Read its saved check before interpreting the intervals.
The saved row has convergence code 0, a positive-definite Hessian and a maximum absolute gradient of about 0.0015. This checks the selected fit’s numerical behaviour. The smaller-rank model’s better AIC and the limited observations for some trait pairs still matter when interpreting the results.
Read the results from correlations to variance shares
The six-panel figure begins with pairwise correlations, then shows the joint ordination patterns, and ends with two different variance summaries. Communality comes first because it describes how much of a trait’s variance at one level belongs to the shared axes. Repeatability then gives the familiar comparison of how a trait’s total fitted variance divides between birds and periods. The rank labels give the number of shared axes between birds and within periods, respectively: 1/1 means one axis at each level, and 2/2 means two at each level. We show 2/2 so readers can see two-dimensional projections. Among the four tested rank combinations, 1/1 has the lowest AIC in both packages. The displayed 2/2 model is not the AIC-preferred result; some between-bird unique variances are also near zero, so communalities near one are boundary-sensitive. The figure uses the same six-trait fit for the estimates and their bootstrap intervals.
If the figure is too wide for your screen, tab to its labelled region and use the left and right arrow keys. The tables below and the downloadable intervals give the numerical results.
Figure 1: Six panels for the six-trait intercept-only red-knot model.
The estimates below come from the checked gllvmTMB fit. The matched glmmTMB results are in the downloadable table and differ only slightly for this 2/2 fit.
Point estimates from the six-trait intercept-only 2/2 gllvmTMB fit.
Trait
Repeatability
B communality
W communality
Body mass
0.598
1.000
0.074
Gizzard mass
0.070
1.000
0.746
Basal metabolic rate
0.153
0.411
0.152
Exploration
0.509
0.037
0.076
Activity
0.087
1.000
0.226
Feeding
0.002
1.000
0.589
Why uncertainty matters here
The point estimates suggest a stronger association between body mass and gizzard mass among birds than across periods within birds. To assess that difference, subtract the within-period correlation from the between-bird correlation in each retained refit and take percentiles of the differences. The direct difference was 0.62 (95% interval 0.26 to 0.84), so the model supports a stronger association between birds.
Selected results and pointwise 95% bootstrap intervals for the displayed fit.
Quantity
Level
Trait
Pair
Estimate
Lower
Upper
correlation
Between birds
mass
gizzard
0.795
0.435
0.988
correlation
Within periods
mass
gizzard
0.172
0.076
0.269
correlation contrast
Between minus within
mass
gizzard
0.623
0.257
0.837
correlation
Between birds
activity
feeding
-0.898
-0.998
0.973
correlation
Within periods
activity
feeding
-0.293
-0.446
-0.152
correlation contrast
Between minus within
activity
feeding
-0.604
-0.756
1.278
communality
Between birds
gizzard
1.000
0.451
1.000
communality
Within periods
gizzard
0.746
0.461
1.000
communality
Between birds
feeding
1.000
0.046
1.000
communality
Within periods
feeding
0.589
0.430
1.000
repeatability
Between fraction
feeding
0.002
0.001
0.108
Activity and feeding tell a different story. The estimated between-bird correlation was −0.90, yet its interval stretched from −1.00 to +0.97. We cannot tell whether more active birds tend to feed more or less. Within periods, the correlation was −0.29 (−0.45 to −0.15). The interval for the direct contrast spans zero, so the data do not clearly distinguish the two levels for this pair. Across the 15 pairs, only two between-bird intervals exclude zero, compared with six within-period intervals.
Feeding also illustrates why we need both panels E and F. Between-bird communality is the share of between-bird feeding variance on the shared axes. Repeatability asks how much of all fitted feeding variance is between birds. Its between-bird communality was near one, with a wide interval from 0.05 to 1.00. Its repeatability was 0.0025 (0.0006 to 0.1085). Thus, the data support a small between-bird share of total feeding variance, while leaving its split into shared and trait-specific variance unresolved. Only 54 birds contributed feeding observations, all from one year.
Wide intervals are common in panel E. All twelve communality intervals span at least 0.45 on the zero-to-one scale. For between-bird exploration, the interval runs from 0.003 to nearly 1.00. Repeatability was better resolved for body mass (0.60, 0.48 to 0.69) and exploration (0.51, 0.39 to 0.61).
We simulated the same fitted Gaussian model and kept the observed response pattern fixed. Of 2,000 attempts, 1,361 passed the convergence, Hessian, gradient and covariance checks. For 638 of the 639 excluded datasets, none of the attempted fits had a positive definite Hessian. The percentiles describe the retained refits under this model and rank. From the first 1,500 simulations to the full run, the largest change in an interval limit was 0.054. The same correlation intervals excluded zero. See the fit and bootstrap records and the full interval table. The reference receipt records the point-fit recipe used to initialise the campaign. The later figure receipt identifies the campaign and the exact interval and draw files used for the figure.
The ordination panels retain BMR_W, the source variable name for basal metabolic rate. The correlation and variance-share panels use shorter reader-facing labels. To recreate this figure from a new fit, see the optional refit instructions.
Recalculate one contrast
The target file contains the between-minus-within contrasts calculated in the retained refits. Select body mass and gizzard mass, then check how many draws you have.
Report the saved result. Body mass and gizzard mass were more strongly associated among birds than across periods within birds in this model (between minus within 0.62, 95% bootstrap interval 0.26 to 0.84). For activity and feeding, the between-bird interval spans substantial negative and positive values. The strong point estimate leaves the direction uncertain.
You’ve finished when you can explain what the three sample counts represent and why one trait pair gives a clearer answer than another. Next: Random slopes
Go further
Compare the tested ranks below, run a fresh fit, or use your own data to define an individual and a repeat occasion.
Compare the tested ranks
The table reports fit and diagnostic results for the four tested rank combinations. AIC differences are calculated within each package, using the same observations and mean structure.
Four tested rank combinations, compared within each package.
Package
Between axes
Within axes
AIC
Delta AIC
Fit qualified
Near-zero unique B variance
glmmTMB
1
1
5391.183
0.000
TRUE
TRUE
glmmTMB
1
2
5394.185
3.003
TRUE
TRUE
glmmTMB
2
1
5392.488
1.305
TRUE
TRUE
glmmTMB
2
2
5395.475
4.293
TRUE
TRUE
gllvmTMB
1
1
5391.183
0.000
TRUE
TRUE
gllvmTMB
1
2
5394.185
3.003
TRUE
TRUE
gllvmTMB
2
1
5393.285
2.102
TRUE
TRUE
gllvmTMB
2
2
5395.475
4.293
TRUE
TRUE
The 2/2 fits reconstruct closely matched covariance matrices across packages (maximum absolute entry difference about \(1\times10^{-5}\)). The glmmTMB 2/2 fit uses a recorded BFGS refit because its default nlminb fit reached a worse likelihood. One qualified 2/1 fit pair produced a larger cross-package difference and remains unresolved; the complete rank table records the optimizer for each candidate and keeps that comparison visible.
The rank comparisons also show why a high communality needs its denominator beside it. Several between-bird unique variances are close to zero under these fits. Near-one communality is then a boundary-sensitive allocation, not a stable biological conclusion.
Recalculate the intervals or refit the model
From the repository root, use the saved target draws to recalculate the intervals. This takes seconds and writes the result to analysis/cache/tutorial-data/.
The fit script prepares the six traits, fits the matched 2/2 models and checks agreement. Its plotting step checks that the saved interval table belongs to the plotted targets. Use a separate checkout for fresh fits so you can compare them with the published files. The second fits all four rank combinations in both packages and reports AIC separately by engine. Neither script exports individual scores, IDs or fitted model objects. The included dataset and preparation code make the lesson runnable without downloading data from another repository.
For a new simulate-and-refit campaign, use the bootstrap runner. It records all attempts and requires the same package and R versions throughout a campaign. The example below is a small run to check that the procedure works. Use the saved campaign results for interpretation.
The 2/2 fits have nearly identical likelihoods and covariance estimates across packages. That agreement checks this matched implementation; it is not independent biological replication. The model remains a simplified Gaussian illustration. The response transformations, intercept-only mean structure, rank and design-linked missingness all matter to its interpretation.
References
Kok, Eva M. A., Joseph B. Burant, Anne Dekinga, et al. 2019. “Within-Individual Canalization Contributes to Age-Related Increases in Trait Repeatability: A Longitudinal Experiment in Red Knots.”The American Naturalist 194 (4): 455–69. https://doi.org/10.1086/704593.
Mathot, Kimberley J., Eva M. A. Kok, Piet van den Hout, Anne Dekinga, and Theunis Piersma. 2020. “Red Knots (Calidris Canutus Islandica) Manage Body Mass with Dieting and Activity.”Journal of Experimental Biology 223 (21): jeb231993. https://doi.org/10.1242/jeb.231993.