The challenge: quantifying the effect of intraspecific variability in trait spaces

Trait spaces are tools routinely used in trait-based ecology to synthesise the overarching diversity of organismal features (i.e. traits)1,2,3,4,5 and their relationship with ecosystem processes and functioning6,7. This approach allows eco(physio)logists to condense trait variability by sorting species along the synthetic axes defining target trait spaces1. Nowadays, trait spaces provide a standard procedure to describe the functional strategies evolved by species to thrive in a given environment, under the assumption that trait combinations in a trait space are related to species performance, which, in turn, directly determines their fitness in a given environment8. Another assumption of this approach, stemming from both theoretical9 and practical10 reasons, is that intraspecific trait variability (ITV, expressed by both its genetic and/or plastic component) is generally negligible compared to trait variation between species11. However, we now know that ITV is widespread across the tree of life12,13,14,15, and it appears at different levels of biological organisation, from the inter-population down to the intra-individual level16,17,18. The importance of ITV has been recognised for decades, being it tightly hinged on the niche theory19. By influencing both resource use and competitive dynamics20, ITV bridges individual-level variability with community assembly rules, eventually shaping the eco-evolutionary dimensions of niches and related ecological processes18. A shift in focus from trait space analyses based on species (that is, each data point in a trait space represents a species) to approaches that fully embrace ITV21,22 is therefore needed to fully elucidate the impact of ITV on organisms’ functional strategies. However, how to quantify the influence of ITV in trait spaces remains debated.

When answering ecological questions by means of trait spaces, species’ functional strategies are generally summarised by interpreting two main trait space properties: (i) the major axes of trait variation/covariation defined across species, reflecting key trade-offs, allometric scaling relationships and/or simple correlations among traits affecting species’ functional diversity1,2,3,4,5,23,24,25,26,27,28,29,30,31; and (ii) trait space occupancy patterns resulting from the relative sorting of species along the previously established axes of trait variation/covariation. The latter allows the identification of trait combinations that are much more frequent than others within a trait space, as well as the exploration of the outer boundaries of a trait space1,4,5,28,29,30,32,33,34. In the last decade, methodological advances permitted the evaluation of species and individuals as distributions instead of central tendencies10,17,35,36,37, allowing the inclusion of ITV when defining trait spaces. Currently available methods, despite allowing the use of intraspecific information, do not allow for testing the synergetic effect of ITV on the two main trait space properties outlined above.

A recent study38 showed that the inclusion of ITV in a trait space affects both its major axes of trait variation/covariation and its occupancy patterns. Building and expanding on this case study, we propose a generalised quantitative framework to test the effect of ITV in any trait space, both considering its effect on the major axes of trait variation defined across species and changes in species occupancy patterns within the trait space.

A swapping procedure to evaluate the effect of ITV in trait spaces

The most common procedures to build and describe trait spaces in the case of continuous trait values are: (i) for bivariate trait spaces, that is, those built using only two traits, (Standardised) major axis regression―(S)MA, allows testing whether two traits can be expressed as a single trait dimension (or axis of trait variation)39; (ii) for multivariate trait spaces, principal component analysis (PCA) is generally used40,41, and from now on, we only address multivariate trait spaces defined through PCA. SMA and PCA have in common the calculation of eigenvectors and eigenvalues from a variance-covariance matrix, that is, identifying orthogonal leading directions in the data that sequentially capture most of the variance in the data39. While, unlike PCA, (S)MA estimates a slope associated with the first eigenvector (or major axis) and uses the direction defined by the second eigenvector to calculate the residual variance of the linear model, this difference is not relevant for our argument, and we refer to Warton et al39. for details. The key point is that we can always leverage eigenvectors and eigenvalues to define trait space dimensions from any variance-covariance matrix of bivariate or multivariate trait data38. Under this premise, we propose a quantitative procedure based on eigenvectors and eigenvalues to assess the effect of ITV on the main trait space properties (Fig. 1a–d).

Fig. 1: Essentials of the swapping procedure.
figure 1

a Starting from an input dataset including individual observations at the species level (\({M}_{{data}}\)) for three traits, we can aggregate them at the species level (\({M}_{{mean}}\)) to b characterise the trait space between species via eigenvectors (\(\vec{v}\)), eigenvalues (\(\lambda\)) and functional diversity indices. c The subsequent step is generating a swapped matrix (\({M}^{{swap}}\)) and performing the eigendecomposition to extract eigenvectors (\({\vec{v}}_{i}^{{sw}}\)), eigenvalues (\({\lambda }_{i}^{{sw}}\)) and functional diversity indices of the swapped matrix. (d) Finally, we can calculate the angle (\(\theta\)) between \(\vec{v}\) and \({\vec{v}}_{i}^{{sw}}\), the eigenvalue ratio (\(\varLambda\)), and trait loadings per each principal component (PC) and compare the functional diversity indices obtained from \({M}^{{swap}}\) against those defined at the between-species level. For clarity, we only show the application when replacing one row of \({M}_{{mean}}\) with the first row of \({M}_{{data}}\), denoted as i, and only for the first PC (the same applies to all PCs), but we indicate that this procedure is applied to each species × observation available in \({M}_{{data}}\).

Step 1: Input data and definition of a trait space at the between-species level

For any study that includes both intra- and interspecific components of trait variation, the input data is a matrix \({M}_{{data}}\) containing individual observations at the species level (Fig. 1a). For each of the xi species there are \({n}_{{x}_{i}}\) observations of the trait \({{tr}}_{k}\) contained in the vector \({\overrightarrow{{Sp}}}_{{x}_{i}}^{{{tr}}_{k}}\). Thus \({M}_{{data}}\) is composed of n column vectors \({\overrightarrow{{Sp}}}_{{x}_{i}}^{{{tr}}_{k}}\) grouping the observations for a given species i and a given trait k, where i = (1, …, \(n\)) and k = (1, …, p):

$${M}_{{data}}=\left(\begin{array}{ccc}{\overrightarrow{{Sp}}}_{1}^{1} & \cdots & {\overrightarrow{{Sp}}}_{1}^{p}\\ \vdots & \ddots & \vdots \\ {\overrightarrow{{Sp}}}_{n}^{1} & \cdots & {\overrightarrow{{Sp}}}_{n}^{p}\end{array}\right)$$

Thus, \({M}_{{data}}\) is a \(\left({\sum }_{i=1}^{n}{n}_{{x}_{i}}\right)\times p\) matrix (Fig. 2 for an explanation of the notation).

Fig. 2: Explaining the notation used to describe the input data matrix (\({M}_{{data}}\)) for the swapping procedure.
figure 2

\({M}_{{data}}\) is a data matrix containing individual observations (obs) at the species level (x) for p traits (tr). For example, the green box indicates the first species (species indexing is marked by the orange circle), for which we have three individual observations of a trait (marked by the brown circle). The information in the green box can therefore be written as a vector, \({\overrightarrow{{Sp}}}_{1}^{1}\) (see green box in the right-hand matrix), containing all the observations relative to species 1 for trait 1. The same reasoning applies to species 2 (identified by the purple box).

The subsequent step to build the trait space is to generate a new n × p data matrix, \({M}_{{mean}}\) (Fig. 1a), where each element is the average of the \(i\) observations of each \({\overrightarrow{{Sp}}}_{{x}_{i}}^{{{tr}}_{k}}\) vector denoted as the number \({\widehat{{Sp}}}_{x}^{{tr}}\):

$${M}_{{mean}}=\left(\begin{array}{ccc}{\widehat{{Sp}}}_{1}^{1} & \cdots & {\widehat{{Sp}}}_{1}^{p}\\ \vdots & \ddots & \vdots \\ {\widehat{{Sp}}}_{n}^{1} & \cdots & {\widehat{{Sp}}}_{n}^{p}\end{array}\right)$$

Since we are dealing with trait spaces, p must always be ≥2.

The proposed approach is based on the determination of eigenvalues and eigenvectors. Therefore, we can use the variance-covariance matrix of \({M}_{{mean}}\) (\({{Cov}}_{{MM}}\)) to calculate the eigenvectors \(\vec{v}\) and eigenvalues \(\lambda\) at the between-species level (Fig. 1b) by using the fundamental eigenvalue equation:

$${{Cov}}_{{MM}}v=\lambda {{Cov}}_{{MM}}$$

Step 2: The swapping procedure

Once we have defined the trait space at the between-species level, we propose a species-wise solution based on resamplings of individual-level trait observations to account for the effect of ITV within a trait space defined at the between-species level (Fig. 1c). The rationale for a species-wise solution is that species inherently differ in their degree of ITV due to different degrees of genetic variability and/or phenotypic plasticity. For example, some species are distributed across broader environmental gradients compared to others, potentially displaying greater ITV. In addition, some species are naturally more abundant than others, and any multi-species dataset will include a different number of trait values per species. The same effect might also appear when ITV-level data are gathered from different sources, for instance, because of sampling biases (e.g. toward charismatic or easier-to-measure species). The devised species-wise solution allows us to account for these and related effects, since we can test how each individual observation alters the overall configuration of a trait space.

The easiest solution to calculate a species-wise effect on a trait space is to sequentially replace a row in \({M}_{{mean}}\) with all the individual observations available for that species while keeping the other rows of \({M}_{{mean}}\) fixed (that is, keeping species means), and then recalculate the eigenvectors and eigenvalues of the resulting matrix, defined as \({M}^{{swap}}\) (Fig. 1c). \({M}^{{swap}}\) is a n × p matrix that can be obtained by applying the following formula:

$${M}^{{swap}}={I}^{{\prime} }\left(x\right)\times {M}_{{mean}}+{I}^{{\prime} {\prime} }(i)\times {M}_{{data}}$$

where \({I}^{{\prime} }\) and \({I}^{{\prime} {\prime} }\) are place-holding matrices necessary for replacing a species mean with target individual-level observations in an iterative fashion while keeping all the other species fixed (Box 1, Fig. 1c).

This allows us to leverage each individual observation in \({M}_{{data}}\) in a between-species comparative context—the key innovation of our proposal—under the assumption that individual observations of a species are alternative trait states drawn from the true multivariate distribution of the considered traits.

Applying the swapping formula, we obtain \(\left({\sum }_{i=1}^{n}{n}_{{x}_{i}}\right)\) swapped matrices, and for each of them, we can calculate eigenvectors and eigenvalues. This means that for each species, we obtain a set of eigenvectors and eigenvalues, \({\vec{v}}_{{x}_{i}}^{{sw}}\) and \({\lambda }_{{x}_{i}}^{{sw}}\), respectively (Fig. 1c). Each element of \({\vec{v}}_{i}^{{sw}}\) and \({\lambda }_{{x}_{i}}^{{sw}}\) obtained by inserting the ith row of \({M}_{{data}}\) (i.e. an individual observation) into \({M}_{{mean}}\) can be directly compared to \(\vec{v}\) and \(\lambda\) calculated from \({M}_{{mean}}\) (Fig. 1d). To do that, we propose the two metrics and related interpretations as described by Puglielli et al38. :

  1. 1.

    Angle between eigenvectors (Fig. 1c, d), that is the angle (\(\theta\)), between each \({\vec{v}}_{{x}_{i}}^{{sw}}\) and \(\vec{v}\):

    $$\theta =\left({\cos }^{-1}\left[\frac{\vec{v}\,{{\cdot }}\,{\vec{v}}_{{x}_{i}}^{{sw}}}{\left|\left|\vec{v}\right|\right|{||}{\vec{v}}_{{x}_{i}}^{{sw}}{||}}\right]\right)\times 180/\pi$$

    \(\theta\) quantifies the rotation of trait space dimensions relative to \(\vec{v}\) when replacing a species mean with a specific individual observation while keeping the other species fixed. Thus, the swapping procedure returns a value of \(\theta\) per each observation in \({M}_{{data}}\). Considering that eigenvectors define directions in the data that sequentially capture most of the variance in the data, and that ITV is the sample trait variance of a species, any ITV-level observation can potentially alter the direction along which an eigenvector is identified. Thus, from an ecological perspective, \(\theta\) can be used to evaluate the extent to which single observations affect the interpretation of major axes of trait variation defined across species (i.e. the first trait space property outlined above).

  2. 2.

    Since each eigenvector is inherently associated with an eigenvalue, that is, the amount of variance in the data that is captured along a given eigenvector, ITV can also modify eigenvalues. To quantify this effect, we propose the eigenvalue ratio (\(\varLambda\)) (Fig. 1d), that is, the ratio between each element of the vector \({\lambda }_{{x}_{i}}^{{sw}}\) and \(\lambda\):

$$\varLambda =\frac{{\lambda }_{{x}_{i}}^{{sw}}}{\lambda }$$

\(\varLambda\) quantifies the effect of an individual observation in modifying the amount of variance that is captured along a given trait space dimension relative to \(\lambda\). For example, \(\varLambda\) > 1 indicates that a specific observation increases the amount of variance explained by a given dimension of the trait space. From an ecological perspective, trait space dimensions are routinely described in terms of the amount of variance in the data that they explain to sort the most important axes of trait variation across species, and \(\varLambda\) is a metric to evaluate the extent by which including ITV in a trait space increases the amount of variance captured by given trait space dimensions. As for \(\theta\), the swapping procedure returns a value of \(\varLambda\) for each observation in \({M}_{{data}}\).

We note that a similar value of \(\theta\) between observations may be associated with different values of \(\varLambda\). For example, it may be the case that two individual observations have the same value of \(\theta\) but one observation is associated with \(\varLambda =1\) and the other with \(\varLambda \gg 1\). This means that for the first observation (i.e. \(\varLambda =1\)), the observed \(\theta\) does not have any effect on the amount of variance captured along the corresponding trait space dimension. To account for this effect, the obtained \(\theta\) values can be multiplied by the corresponding \(\varLambda\) to obtain \(\theta\) values weighed by their effect on the amount of variance captured along the corresponding trait space dimensions. Furthermore, in cases where each species has a different number of individual observations, \(\theta\) can also be multiplied by the relative frequency of individual observations of each species relative to the total number of observations available for all the species. If all the species have the same number of observations, the latter step is not required. Importantly, we also note that when performing the eigendecomposition analysis at each generated \({M}^{{swap}}\) we can also retrieve information on the trait loadings on each eigenvector, which indicates the effect of individual observations in altering the interpretation of each trait space dimension or trade-off axis in terms of the traits that define it. The swapping procedure returns loadings for each principal component (PC).

Step 3: Patterns of trait space occupancy

The next step is the comparison of the trait space defined using \({M}_{{mean}}\) with those defined using each \({M}^{{swap}}\) in terms of trait space occupancy patterns. For this purpose, following Puglielli et al38., we propose using: (i) functional richness, the amount of space occupied by the data points; and (ii) overlap-based dissimilarity35, the dissimilarity between probability density areas of the trait spaces under comparison. As for \(\theta\) and \(\varLambda\), the swapping procedure returns functional diversity indices for each individual observation in \({M}_{{data}}\) (Fig. 1). However, before performing this comparison, it is essential to make the target trait spaces conformable. This step is achieved by evaluating the trait space defined using \({M}_{{mean}}\) and that resulting from each \({M}^{{swap}}\) within the same trait range after having multiplied the original data in \({M}_{{mean}}\) and in each \({M}^{{swap}}\) for their corresponding eigenvectors (i.e. rotation step of the PCA). Note that the rotation step before comparing the trait space defined using \({M}_{{mean}}\) and that resulting from each \({M}^{{swap}}\) in terms of trait space occupancy is necessary because the procedure to generate each \({M}^{{swap}}\) inherently modifies the covariance matrix of the sample. Consequently, without rotation, the resulting trait spaces are not directly comparable in terms of functional diversity indices38 and overlap-based dissimilarity due to changes in the density of points (i.e. multivariate density estimations) within the trait space caused by the effect of the covariance of the input data, which is removed by the rotation step. By doing so, we are ensuring that any potential difference detected between each pair of trait spaces is only due to ITV. Comparisons in terms of trait space occupancy patterns can be performed using multivariate kernel density-based methods such as the trait probability density (TPD) framework, among others35,36,42. Here we have focused on kernel density-based methods, but other methods that consider the distribution of points in the trait space, such as convex hulls43 or dynamic range boxes44, could be applied as well. However, we also point out that distance-based functional diversity metrics, such as Rao’s quadratic entropy or functional dispersion45 can be seemingly applied to each \({M}^{{swap}}\); we refer to the original references to explore how to apply these frameworks in the context of the swapping procedure.

Diagnosing the effect of ITV on trait space configuration

Functional trait values are always collected through replicated individual-based sampling, and any functional trait datasets, with some exceptions for those compiled from online databases, will always include a number of observations per each sampling unit. Thus, most of the functional trait datasets aimed at drawing trait spaces will have the same configuration as \({M}_{{data}}\), potentially rendering the swapping procedure a routinely used approach to integrate any trait space analysis. For example, even in cases when no effect of ITV is detected (e.g. \(\theta\) ≈ 0), this can imply that the pattern defined using \({M}_{{mean}}\) is not affected by the inclusion of ITV, which is a desirable test for any trait space analysis. Another important outcome of this approach is the possibility of identifying individuals or species that have a disproportionate impact on the configuration of the trait space, providing the possibility to identify, for example, biological outliers. Finally, if one is only interested in the overall effect of ITV on trait space configuration across species, the obtained metrics can be averaged across species, but this needs to be done by weighing each metric, aggregated at the species level, by species’ relative abundances in the dataset, similar to what is done for calculating community weighted means46. This weighing step is needed to account for the possibility that different species have an uneven number of trait records and, being the swapping procedure a species-wise solution, also an uneven number of metrics returned by the procedure.

Additionally, given that two or more trait spaces are defined using the same traits, one can compare the degree of ITV in different species assemblages, for example, in different ecological contexts or experimental setups (see Supplementary Note S1 for a worked example). However, given the well-known relationship between some functional diversity metrics and species richness, we recommend developing null models to break down this effect when comparing assemblages/groups47 that differ in their species richness. As an example, in its simplest form, this can be achieved by iteratively applying the swapping procedure to equally sized and (carefully) stratified random draws of species from the target assemblages. Similarly, if one can group species defining the trait space in some target categories (e.g. habitats, growth forms), these can be compared in terms of the metrics returned by the swapping procedure38. Aggregation of the proposed metrics can also be performed, for example, using the functionalities available in the TPD framework35,48, particularly useful when the goal is to upscale from species to a higher level of biological organisation (e.g. community and biome). This approach can also easily be extended at different levels of biological organisation, for example, to test for the effect of intra- vs. inter-individual trait variation within populations, among other potential comparisons, as soon as multiple trait observations are available for each sampling unit. In this context, using the swapping procedure, one could, for example, relate the values of \(\theta\) averaged at the individual level within a population to microclimatic information or even to the activity of other trophic levels49. Finally, the values of \(\theta\) and \(\varLambda\) per each retained PC can also be used as response variables in statistical models, for example, in a generalised linear mixed model, to test how the proposed parameters differ among levels of a categorical variable (e.g. habitat types) using species as a random effect50. Similarly, the values of \(\theta\) and \(\varLambda\) can be used as response variables in variance partitioning procedures whereby they can be modelled independently to test, for instance, the relative importance of intra- vs. inter-individual variation (as done for single raw traits).

A new perspective to leverage individual observations in trait space analyses

The proposed swapping procedure contributes to the debate on the importance of including ITV in trait-based studies, but in the context of trait space analyses. Species in this framework are, in fact, considered to have multiple trait states that ultimately might exert an effect on trait space properties, thereby aligning with the growing research strand that considers species or individuals as distributions instead of in terms of central tendencies10,11,17,35,38,51. More broadly, our procedure can contribute to answering important questions in trait-based ecology, such as the potential scale dependence of ITV related to between-species trait variability, or how ITV patterns differ in contrasting ecological setups50 or life forms38, but at the level of integrated trait spaces. Similarly, this approach can be easily applied at different levels of biological organisation (see previous section).

In conclusion, the proposed swapping procedure empowers trait-based ecologists with a solution to fully leverage individual-based trait datasets to systematically assess how each observation modifies the properties of a trait space. This allows for a unique high-resolution sensitivity analysis of the properties of any trait space as a function of ITV. As such, despite inherent limitations (Table 1), the proposed framework introduces a new methodological approach for trait-based analyses that opens new avenues for testing the effect of ITV on the configuration of trait spaces. Considering the ever-rising focus on either ITV or trait space analyses in trait-based ecology, we strongly believe that the proposed framework can inspire many different future applications as well as further methodological developments (for example, implementation of the swapping procedure in the context of ordination techniques other than PCA to accommodate categorical traits) in various biological fields. To promote the use of the swapping procedure, enhance reproducibility, and ultimately increase the impact within the trait-based community, we also provide a set of R functions to perform the swapping procedure.

Table 1 Main limitations of the swapping procedure and proposed mitigation strategies