Main

Secondary adaptations to aquatic lifestyles, such as wading behaviour (shoreline specialist and/or only partially submerged habit), subaqueous foraging (fully submerged behaviour) and deep diving, evolved multiple times in every major amniote group1,2. Aquatic habits are widespread among extant birds, ranging from subaqueous foragers to waders. Moreover, water-related ecologies have deep evolutionary roots on the avian stem lineage, occurring in some of the earliest (Early Cretaceous) ornithuromorphs18,19. Therefore, the scarcity of evidence for aquatic adaptation in non-avian dinosaurs, which comprise the deep evolutionary stem lineage of birds, is striking.

Non-avian dinosaurs are generally hypothesized to have been restricted to terrestrial environments, with only a few proposed exceptions. Suggestions as to why dinosaurs did not evolve aquatic adaptations as frequently as other amniotes include constraints imposed by the musculoskeletal anatomy of the pelvis, hind limb and tail20. However, the discovery of a new skeleton of the predatory dinosaur Spinosaurus aegyptiacus has challenged this long-held narrative9,11: the conical dentition, retracted nostrils, shortened hindlimbs, paddle-like feet and fin-like tail, together with more ambiguous evidence from isotopic analyses21,22 are consistent with an aquatic lifestyle. This has sparked a heated debate regarding the degree of ecological specialization in Spinosaurus, which has been described as actively pursuing prey in waters11, with alternative proposals suggesting a more terrestrial or ‘wader-heron’ model on the basis of anatomical observations and 3D digital models12,13,23. Aquatic habits have also been suggested for a handful of other dinosaurs based on gut contents (other spinosaurids24 and ornithomimosaurs6,8) or anatomical proxies (halszkaraptorine dromaeosaurids10, compsognathids5 and various ornithischians3,4,7), but remain ambiguous and controversial. This illustrates the inherent challenges of reconstructing ecomorphological relationships in vertebrates25 and the resulting difficulties in inferring ecological traits in extinct species.

Adaptation to aquatic habits, such as subaqueous foraging or deep diving, constitutes a major evolutionary transition, often culminating in a fundamental transformation of the body plan25. Nevertheless, even in groups that exhibit a high degree of aquatic specialization, such as cetaceans and many marine reptiles, this transformation occurred gradually over millions or tens of millions of years. Some extant species, and the early fossil members of even the most specialized aquatic groups, show relatively subtle skeletal changes14,15,16,26,27. Many aquatic taxa possess few anatomical indicators of water-related ecology, and instead share numerous traits with land animals (for example, Hippopotamus and the earliest cetaceans14,15,26,27). It is therefore plausible that dinosaurs currently considered to have been terrestrial on the basis of anatomical proxies and phylogenetic bracketing might instead represent the early stages of an evolutionary transition towards more specialized aquatic ecologies (for example, early cetaceans) or amphibious animals (for example, Hippopotamus and Tapirus) that evolved relatively limited anatomical transformations despite spending much of their lives in water.

Because of the difficulty of inferring aquatic habits from skeletal morphology alone, proxies that reveal ecological adaptations in extinct taxa are required. Osteohistological features such as variation in bone density provide one such possibility. Osteosclerosis occurs widely as an adaptation to aquatic life in extant amniotes26,27,28,29, and has been used to infer aquatic ecologies in extinct tetrapods such as crocodyliforms, avialans, marine reptiles and cetaceans15,26,27. Osteosclerosis involves additional deposition of bone mass per volumetric unit leading to the presence of a thick bone cortex with dense trabecular networks infilling the medullary cavity2,26,27,28,29. This results in increased body density, facilitating buoyancy control during subaqueous immersion related to either submerged aquatic foraging (for example, in underwater pursuit divers), concealment or refuge14,15,16,26,27,28,29. Although previously used for paleoecological inference, bone density has generally been used on single-clade-specific studies (for example, in ref. 30), and a phylogenetically broad test is required to validate the use of bone compactness as a proxy for aquatic adaptation in deep time, including in species outside of the extant crown clades such as non-avian dinosaurs.

Here we conduct phylogenetic comparative analyses of bone density data in a broad sample of amniotes and use our findings to assess the extent of aquatic adaptations in non-avian dinosaurs. Our analyses provide evidence that one clade of dinosaurs—Spinosauridae—was ecologically adapted to life in water, representing the first known aquatic radiation among non-avian dinosaurs.

We quantify bone density in the femoral diaphysis and proximal region of dorsal ribs of 206 and 174 extant and extinct amniotes, respectively (380 total observations with n = 83 overlapping taxa between the two datasets; see Supplementary Dataset and Supplementary Table 1). Our dataset includes novel osteohistological data for non-avian dinosaurs (36 femora and 12 ribs) and Mesozoic stem-avialans (7 femora) (Extended Data Figs. 17 visualize novel data used in this study; see Methods, Supplementary Dataset for the list of taxa and bone density values used in this study and Supplementary Table 2 for a list of spinosaurids and their investigated skeletal elements).

We compared alternative explanations of variation in bone density using corrected Akaike information criterion (AIC)-based model comparison of phylogenetic multiple regressions31, and evaluated the influence of allometry using the maximum diameter of the femoral diaphysis and proximal region of the dorsal ribs as a size proxy. As ecological adaptations are often reflective of the most demanding biomechanical behaviour (Liem’s paradox32: whereas specialized animals are capable of less functionally demanding behaviours, less specialized taxa often cannot satisfy the requirements linked to functionally challenging habits such as sustained flight or subaqueous foraging), taxa were scored using two categorical explanatory variables that encode the presence of (1) subaqueous foraging (0, unable; 1, able but infrequent; 2, frequent), and (2) flying (0, unable; 1, non-sustained flight; 2, sustained flight) in a comprehensive evolutionary framework. We used two independently varying variables because flight and subaqueous foraging evolved at least partly independently of one another as indicated by the occurrence of both flying and flightless diving birds. Our datasets include extant and extinct taxa with undisputed aquatic adaptations, specifically marine mammals (cetaceans and pinnipeds) and non-archosaurian marine reptiles (ichthyosaurs, sauropterygians and mosasaurs), and aquatic archosaurs such as metriorhynchids, living crocodilians and various clades of subaqueous foraging birds (penguins, auks, loons, grebes and cormorants), in addition to extant and extinct terrestrial and flying archosaurs, lepidosaurs and mammals (see Supplementary Dataset).

The best linear model is ‘bone compactness ~ subaqueous foraging’ (state 2: frequent subaqueous foraging) in both datasets (AIC of weight = 0.673 (femur) and 0.638 (rib); Table 1, Supplementary Tables 34). This indicates that frequent subaqueous foraging is associated with increased femoral and rib density across amniotes (P < 0.001), a relationship that exhibits a strong phylogenetic signal (median λ = 0.97 (femur) and 0.969 (rib)). Infrequent subaqueous foraging and wading behaviour are not significantly associated with variation in bone density (Table 1, Supplementary Tables 3, 4), consistent with the observation that wading birds that feed in water but rarely submerge (for example, herons, pelicans, gulls, flamingoes and some ducks) have similar compactness to non-aquatic taxa.

Table 1 Phylogenetic regressions comparing explanations of bone compactness as a function of size and ecological traits among femora and dorsal ribs

Models that include flight or shaft diameter as additional covariates receive less support from AIC (Table 1, Supplementary Tables 3, 4). This indicates that evidence for an amniote-wide common allometry in bone density, or for association of flight with decreased skeletal density, is weak, and that those effects are secondary to those of aquatic adaptation (see Table 1, Extended Data Figs. 8, 9, Supplementary Tables 3, 4). Nevertheless, negative allometry in bone compactness (reduction of bone density with size increase) is found in flying taxa (volant extant birds, Cretaceous enantiornithines and pterosaurs; Table 1, Supplementary Tables 3, 4). This shows the importance of skeletal weight reduction in association with or preceding the origin of active flight33,34: postcranial bones of predatory dinosaurs typically show an open medullary cavity, a trait inherited by birds14,34 (Fig. 1, Extended Data Figs. 19). Large-bodied terrestrial amniotes have relatively high femoral compactness related to graviportality: trabeculae invade the medullary cavity to support increased weight in graviportal mammals15,27,35,36 and sauropod dinosaurs (Fig. 1, Extended Data Figs. 17, Supplementary Tables 5, 6). Deep diving animals, such as ichthyosaurs, mosasaurs, living cetaceans and seals, are characterized by lower bone density when compared to shallow-water subaqueous foragers: the compact bone cortex of deep divers is replaced by cancellous bone characterized by extensive trabeculae and vascularization2,27 (Fig. 1, Extended Data Figs. 17, Supplementary Tables 5, 6), hypothesized as counteracting compression in deep waters and increases in metabolism1,2. High bone density is therefore an excellent indicator for the initial stages of aquatic adaptation, but poorly distinguishes between wading, deep diving, and terrestrial habits. These limitations can be overcome using anatomical observations because deep diving shows other transformations of the body plan, such as presence of fins and flippers. Graviportal animals can be distinguished from aquatic species by the presence of columnar limbs, an anatomical trait which is generally missing among subaqueous foragers. Furthermore, graviportality does not affect rib compactness (Fig. 1, Extended Data Figs. 17, Supplementary Dataset). These analyses therefore demonstrate that bone density is a powerful proxy of shallow subaqueous foraging across amniotes.

Fig. 1: Osteohistology and ecological variation among amniotes, including the analysed spinosaurid taxa.
figure 1

a, Bipedal, land-dwelling archosaurs such as theropods show the presence of an open medullary cavity. This condition is more pronounced in flying archosaurs such as birds. Two osteosclerotic patterns are present among subaqueous foraging animals: (1) increase in thickness of the bone cortex, as observed in crocodilians and penguins, for animals adapted to shallow waters; or (2) substitution of the bony cortex with trabecular networks, usually found in deep divers—for example, ichthyosaurs, mosasaurs and cetaceans. Occupation of the medullary cavity by spongiosa is also observed in quadrupedal, graviportal animals such as sauropods, ornithischians and large-bodied terrestrial mammals. b, Femur and dorsal rib sections and bone density of the holotype of Baryonyx, Suchomimus and the neotype of Spinosaurus used for calculation of bone density in this study. Skeletal reconstructions are based on single individuals (holotype of Baryonyx and neotype of Spinosaurus), exception made for Suchomimus (see Supplementary Information for further details); preserved bones are highlighted in orange. The schematic tree is based on the phylogenetic analyses performed in this study (see Supplementary Information for results and discussion of these analyses). bd, bone density.

We used this relationship to establish quantitative predictions of subaqueous foraging in a range of non-avian dinosaurs, including groups that were previously suggested to be linked to water4,6,8,9,10,11, using phylogenetically flexible discriminant analyses with all amniotes in our sample (Methods). We repeated analyses across 100 informal supertrees with varying branch lengths to account for stratigraphic uncertainty. The informal consensus trees include a novel phylogenetic analysis of Tetanurae modified from recently published datasets17,37, including new observations of the Spinosaurus neotype (Figs. 13, Supplementary Fig. 1; Supplementary Materials). Our analyses include osteohistological data for the spinosaurids Baryonyx24, Suchomimus9,38 and Spinosaurus9,11, as well as other tetanuran theropods (see Supplementary Materials for ontogenetic assessments of these taxa and other carnosaurs analysed in this study; Fig. 1, Extended Data Fig. 10, Supplementary Figs. 2, 3).

Fig. 2: Relationship between midshaft density of femur, diameter and major lifestyle among amniotes including Spinosauridae.
figure 2

a, Phylogenetically gnostic regressions (PGLS) linear model (n = 206 independent observations, n = 200 taxa) of bone density as a function of log10 femur-midshaft diameter values for our dataset of amniotes with main lifestyle category as a factor using a randomly drawn phylogeny from the 100 phylogenies generated (same topology, variable branch lengths). Solid lines represent linear fits for the four categories. b, Violin plots depicting distribution of bone density in each category. Large dots represent medians and lines show 95% confidence intervals. The bone densities of the three spinosaurid taxa studied are indicated. c, Bone density distribution in a time-calibrated archosaur consensus tree showing an ancestrally osteosclerotic Spinosauridae and rapid radiation of tetanuran clades during the Early Jurassic (Extended Data Fig. 8 shows bone density distribution across amniotes). Eoc., Eocene; Mio., Miocene; Olig., Oligocene; Paleo, Palaeogene; Quat., Quaternary.

Fig. 3: Relationship between dorsal ribs density, diameter and major lifestyle among amniotes including Spinosauridae.
figure 3

a, PGLS linear model (n = 174 taxa) of bone density as a function of log10 rib cross-section diameter values for our dataset of amniotes with main lifestyle category as a factor using a randomly drawn phylogeny from the 100 phylogenies generated (same topology, variable branch lengths). Solid lines represent linear fits for the four categories. b, Violin plots depicting distribution of bone compactness values in each category. Large dots represent medians and lines show 95% confidence intervals. Bone compactness of Baryonyx and Spinosaurus are indicated (Extended Data Fig. 9 shows bone compactness distribution across amniotes).

The correct classification rates of our phylogenetically flexible discriminant analyses ranges are 84–85% (femora) and 83–84% (ribs) (Figs. 2, 3, Supplementary Materials, Supplementary Tables 710). This increases to 90% in both datasets when excluding graviportal and deep diving taxa (Figs. 2, 3, Supplementary Tables 710). Contrary to previous hypotheses, our analyses indicate that Spinosauridae is the only clade of non-avian dinosaurs with unambiguous evidence of subaqueous foraging. Within Spinosauridae, disparate ecomorphologies were found. Spinosaurus (median probability for subaqueous foraging 100% (femur) and 95% (rib)) and Baryonyx (median probability for subaqueous foraging 98% (femur) and 96% (rib)) were predicted as subaqueous foragers. By contrast, Suchomimus was found as non-subaqueous-forager (median probability for subaqueous foraging 31% (femur)), similar to other terrestrial non-avian dinosaurs (Figs. 13, Extended Data Fig. 10, Supplementary Tables 710). Considering the similar body size between the skeletally mature specimen of Suchomimus (G51) and the neotypic skeletally immature individual of Spinosaurus, and that our analytical approach accounts for size variation, these results can be confidently attributed to ecological adaptations, rather than the influence of allometry. This is also supported by the presence of open medullary cavities in postcranial elements of other large bodied, bipedal predatory dinosaurs such as femora of Tyrannosaurus, Tyrannotitan, Torvosaurus, and a large carcharodontosaurid rib, contrasting with the osteosclerotic bones of Baryonyx and Spinosaurus (Fig. 1, Extended Data Figs. 17, 10),

All other investigated non-avian dinosaur clades (ornithomimosaurs6,8, halszkaraptorine dromaeosaurids10 and ornithopods3,4,7), also show open medullary cavities and a weak or absent probability of subaqueous foraging (see Supplementary Tables 710). By contrast, the inference of subaqueous foraging in some spinosaurids is especially convincing because osteosclerosis is observed across multiple skeletal elements in both the holotype of Baryonyx (dorsal ribs, scapula, pubis, ischium, femur and fibula) and the neotype of Spinosaurus (dorsal ribs, dorsal and caudal neural spines, femur, tibia, fibula and manual phalanx) (Fig. 1, Extended Data Fig. 10, Supplementary Figs. 2, 3), rendering previous biomechanical models inaccurate12.

Phylogenetic optimization of bone density and the presence of osteosclerosis tentatively suggests that subaqueous foraging is ancestral for Spinosauridae (Fig. 2c, Extended Data Figs. 8, 9) and that the absence of osteosclerosis in Suchomimus results from secondary loss rather than primitive absence. The absence of osteosclerosis does not rule out a dependency on aquatic habitats for predation in Suchomimus: anatomical traits are consistent with a largely piscivorous diet, including an elongate snout and conical dentition. One possibility is that Suchomimus was a wading predator hunting from riverbanks, as previously hypothesized for other spinosaurids12,13,24,38,39,40. Different ecological adaptations (subaqueous foraging and non-diving habits) are recovered between the anatomically similar sister taxa Baryonyx and Suchomimus, a pattern not unique to Baryonychinae and also observed in other amniote groups, including Phalacrocoracidae (this study) and Hippopotamoidea35. It is possible that environmental factors, such as a sparser distribution of aquatic settings (rivers, lakes)41 led to less specialized foraging in Suchomimus.

Our results suggest the first anatomical adaptations for an aquatic lifestyle appeared in concert with osteosclerosis in spinosaurids. Craniofacial modifications preceded postcranial alterations (Fig. 1). The premaxilla gradually became more elongate, while the external naris diminished in size and migrated posterodorsally9,11, a pattern comparable to the telescoping process observed in the skull evolution of cetaceans14 and ichthyosaurs16. The braincase rotated ventrally and the dentition became conical. These modifications are functionally advantageous for a diet based on slippery, aquatic prey42. Postcranial modifications linked to subaqueous foraging, such as elongation of the caudal neural spines to form a propulsive structure, have been reported for Spinosaurus9,11 and, potentially, for the baryonychine Riparovenator40. Additionally, spinosaurids are characterized by the lowest degree of postcranial pneumatization (restricted to the cervical region and dorsal–sacral neural arches) among large-bodied Cretaceous tetanurans43, consistent with elevated body density and advantageous for buoyancy control. Although reduction in hind limb length and widening of the pes have only been described in Spinosaurus9,11, many spinosaurids are only known from fragmentary remains (Fig. 1), limiting our understanding of their skeletal adaptations. Because of their unique anatomy, spinosaurids may have had ecologies with no modern equivalent, limiting direct autecological interpretations based on modern taxa.

We demonstrate that Spinosauridae, a geographically widespread clade of predatory dinosaurs, was ecomorphologically adapted to life in water, but that aquatic adaptation was otherwise absent among non-avian dinosaurs studied so far. Nonetheless, this finding challenges the hypothesis that non-avian dinosaurs were restricted to terrestrial environments. Spinosaurids were part of the rapid radiation of Tetanurae during the late stages of the Early Jurassic17. Increased diversification appeared in concert with morphological innovation and high rates of homoplasy across tetanurans17. This ecomorphological radiation may be linked to adaptation to previously under-exploited environments, including multiple independent appearances of aerial capabilities33. Our study demonstrates that ecomorphological radiations among non-avian dinosaurs also included the invasion of freshwater ecosystems.

Methods

Osteohistological analyses and assessment of skeletal maturity of spinosaurid specimens

We sampled and investigated postcranial elements of the holotype of Baryonyx (NHM R 9951), two individuals of Suchomimus (G51, G94), and the neotype of Spinosaurus (FSAC-KK 11888) to evaluate their somatic maturity and quantify bone density. The dorsal rib of Baryonyx was previously sectioned by Reid44 and this was here studied for estimation of somatic maturity of the holotype. To quantify bone compactness, the femur of Baryonyx was X-ray computed tomography (CT) scanned at the Natural History Museum, London. Breaks of additional postcranial bones (scapula, pubis, ischium and fibula) were considered for comparative purposes with the goal of assessing the skeletal extent of osteosclerosis. Skeletal maturity and bone compactness of Suchomimus were estimated through sampling and thin sectioning of the femora of two individuals (described in brief in Ibrahim et al.9). A dorsal neural spine, dorsal rib, femur, and fibula were sampled for thin sectioning and inference of ontogenetic stage of the Spinosaurus neotype. Moreover, a manual phalanx, caudal neural spines and tibia of this specimen were also available for bone compactness quantification, because of breaks along the diaphysis. Long bones were cut transversely at the diaphysis, whereas samples of dorsal ribs and the dorsal neural spine of Spinosaurus were taken proximally and apically, respectively. The thin sectioning was performed following the protocol by Chinsamy & Rath45. The thin sections have a thickness of 50–70 microns and were analysed with a Leica DM 2500 P petrographic microscope. Photographs of the bone tissue were taken with a ProgRes Cfscan camera. The CT scanned femur of Baryonyx was analysed in VGStudio Max 3.4. Inference of skeletal maturity follows recently proposed nomenclature by Griffin et al.46.

Phylogenetic analyses

The discovery, description, and completeness of the Spinosaurus neotype provides an opportunity to revisit the phylogenetic relationships of spinosaurids. We coded the neotype of Spinosaurus in two recent datasets, published by Malafaia et al.37 and Rauhut and Pol17, respectively. These two datasets differ in terms of operational taxonomic units (OTUs): whereas Malafaia et al.37 includes a specimen-level assessment of phylogenetic relationships among spinosaurids, Rauhut and Pol17 remains the most comprehensive and latest iteration of the original dataset of tetanuran phylogenetic relationships47. These two datasets are therefore needed to infer phylogenetic relationships within Spinosauridae and the placement of this clade among tetanurans. The neotype of Spinosaurus was coded as a separate OTU in the dataset of Malafaia et al.37. On the basis of the results of this analysis, and given the presence of several apomorphies shared between the Spinosaurus neotype and holotype, coding of the neotype specimen based on our anatomical observations was added to the OTU of Spinosaurus in the dataset of Rauhut and Pol17. The recently described spinosaurine Vallibonavenatrix37 was also added to the dataset published by Rauhut and Pol17. We followed the most recent, comprehensive taxonomic and systematic revision of spinosaurid taxa48,49, therefore excluding Sigilmassasaurus and Oxalaia (which are regarded as junior synonyms of Spinosaurus) from this dataset. Both datasets17,37 were analysed under equally weighted parsimony in TNT (Tree analysis using New Technology) v. 1.150. No characters were ordered. We conducted a heuristic search using 1,000 replicates of Wagner trees (with random addition sequence) followed by tree bisection and reconnection (TBR) branch swapping. We calculated decay indices (i.e., Bremer support) and absolute bootstrap frequencies with 10,000 pseudoreplicates to quantify node support.

Bone density

Bone density was used as a proxy for ecological inference. Because different postcranial skeletal elements show contrasting compactness profiles due to allometry during growth15,27,51,52,53,54, we focused on the femur and dorsal ribs in order to employ a consistent comparative framework; these skeletal elements have been previously shown to be reliable skeletal element for confident inference of ecological adaptations (for example, in ref. 27). Femoral and dorsal rib cross sections were mainly obtained from the diaphysis and the proximal region, respectively, through thin sectioning, micro-CT scanning, or data mining from the literature (see Supplementary Dataset for the taxa included and the type of data collected). Among dinosaurs, novel data presented in this study include those for the tetanuran theropods Baryonyx, Spinosaurus, TyrannosaurusMegalosaurus, Tyrannotitan, Eustreptospondylus, and Condorraptor (see Supplementary Dataset for novel osteohistological data collected for this study). Our femoral dataset includes 206 individuals, representing 200 taxa. All known spinosaurid taxa that preserve the femur are included therein. The discrepancy between the number of individuals and taxa is due to the inclusion of multiple individuals of the following marine reptiles: Ichthyosaurus, Nothosaurus, Simosaurus, Placodontia and Champsosaurus. Our dorsal rib dataset includes 174 taxa. The taxonomic overlap between the two datasets (femur and dorsal rib) is equal to 83 taxa, including Baryonyx and Spinosaurus.

Archosaurs are represented in the dataset by extant crocodilians, pterosaurs, non-avian dinosaurs, and birds, the latter including both Mesozoic and extant taxa (see Supplementary Dataset for included taxa). Stem and crown marine mammals, such as cetaceans and seals, and extinct marine reptiles (ichthyosaurs, sauropterygians, and mosasaurs) were included to infer thresholds of bone compactness related to aquatic lifestyle and to calibrate the discriminant analyses aimed to infer ecological adaptations in extinct taxa.

Cross (CT scan) and thin sections of femoral diaphysis and dorsal rib were transformed into black and white figures (black for bone and white for medullary cavity, vascularization, and background) in Adobe Photoshop, following previous protocols (for example, refs. 15,27,36,54). Images were then imported into the freely available software Bone Profiler55 (http://134.158.74.46/BoneProfileR/) to quantify bone compactness. In cases where portions of the femoral diaphysis and rib cross sections were missing or deformed, retro-deformation and reconstruction were applied following the methods presented by De Ricqlès et al.56, to minimize the occurrence of taphonomic artifacts in the data. Because the femoral diaphysis of Baryonyx is eroded and crushed, the cross section for this taxon was taken from a more intact and better-preserved region closer to the distal portion of the femur (Supplementary Fig. 3). Because the diaphysis of the femur coincides with the highest degree of bone compactness among amniotes15,27, the quantified degree of osteosclerosis in Baryonyx should be regarded as underestimated.

Informal consensus tree

To address the statistical non-independence of interspecific comparisons, we assembled two informal amniote-wide supertrees (Extended Data Figs. 8, 9) using Mesquite v. 3.4057 on the basis of Upham et al.58 for Mammalia, Simoes et al.59 for the backbone of Diapsida, Nesbitt et al.60 for Archosauria, Langer et al.61 for Dinosauria, this study for Tetanurae, Brusatte et al.62 for Coelurosauria, and Prum et al.63 for Neoaves. We calibrated the resulting tree using the function ‘bin_timePaleoPhy’ from the R package Paleotree64, scaling the branches on the basis of genus-level stratigraphic ranges sourced from the Paleobiology Database (www.paleodb.org) and from the specialized literature (see Supplementary Dataset). We generated 100 trees using this method, which randomly draws first appearance dates and last appearance dates for each taxon from within their stratigraphic ranges. To avoid zero-length branches we set a minimum branch length of one million years.

Ecological inference

We scored extant and extinct taxa whose ecomorphological attributes could confidently be inferred (for example, ichthyosaurs as being able to dive frequently and not being able to fly) as being able to engage in (a) subaqueous-foraging (0, unable; 1, able but infrequent (for example, rails); 2, frequent), and (b) flying (0, unable; 1, non-sustained flight (for example, tinamous, galliforms and Xenicus longipes); 2, sustained flight). Extinct taxa with ambiguous ecological inference were scored as unknown. Therefore, the autecology of each taxon is represented by two numerical categories with three states each. Previous studies applied different categorizations for the characterization of aquatic lifestyles among extant and extinct taxa: ‘aquatic’ and ‘semiaquatic’ were used contra  ‘subaqueous foraging’ applied in this study. Our ecomorphological attribution is focused on a specific behaviour linked to an ecology, rather than a categorization of its entirety. We find our categorization to be more accurate: for example, previous studies coded penguins and cetaceans as aquatic, while crocodilians were stated as semiaquatic. Whereas penguins and crocodilians are still ecologically dependent on terrestrial environments (for example, for laying eggs), cetaceans are completely independent from land. On the other hand, all these clades engage in subaqueous foraging. Therefore, our ecological attribution is in agreement with previously applied ecological categories, but do not exclude dependency to terrestrial environments to satisfy autecological requirements, such as reproductive behaviour.

Maximum femoral diaphyseal and dorsal rib cross section diameter was used as a proxy for body size, in order to allow the inclusion of fragmentary fossil remains and to optimize the inclusion of taxa with significantly different body plans. As femoral and rib diameter values range from those of small-bodied modern passerines (Xenicus) to very large non-avian theropods (Tyrannosaurus and Spinosaurus), maximum femoral diameter was log10-transformed.

Bone compactness, femoral midshaft diameter, and different combinations of these ecological traits were used to build 12 linear models upon which PGLS were performed using the R core function gls (R Core Team). The AIC was used to establish which linear model best explains variation in bone compactness. Pagel’s lambda values were simultaneously calculated to evaluate the degree of phylogenetic signal in each of the relationships. These analyses were run over the 100 trees generated for all amniotes to evaluate the effects of stratigraphic uncertainty on our analyses; the results were summarized thereafter.

To establish explicit predictions of ecology in extinct taxa, we built a phylogenetically flexible discriminant analysis (pfDA) using the function phylo.fda (Schmitz & Motani65, sourced from https://github.com/lschmitz/phylo.fda) and following the protocol described65, including our two main metric variables (maximum diameter and bone density) and the ecological classifiers from the linear model with the best fit (lowest AIC score). The model in which bone density is explained by subaqueous-foraging exhibits the best fit (see Results, Table 1, and Supplementary Tables 3, 4); therefore, we scored all taxa to a more inclusive category depending on whether or not they are frequent subaqueous-foragers (Supplementary Tables 3, 4). Because our overarching goal is to ascertain aquatic proficiency in large, flightless theropod dinosaurs, we also excluded modern birds that are able to both submerge-forage and fly as this functional trade-off is likely to influence their bone histology and introduce a confounding factor in our predictions. A series of taxa for which aquatic lifestyles have been proposed or fragmentary remains cannot allow a confident scoring were scored as ‘unknown’ and their ecologies were predicted along with the three spinosaurid target taxa (see supplementary dataset). In order to correct for the bias that phylogenetic structure introduces in form to function relationships, phylo.fda adjusts the phylogeny with the value of phylogenetic signal (Pagel’s lambda) which maximizes the log likelihood of the linear fit among variables65,66. Because branch lengths in our phylogenies exhibit some degree of uncertainty, we repeated this analysis with the 100 different trees we generated and summarized the accuracy and predictions across all iterations. This was repeated for both the femora and rib datasets and again excluding graviportals and deep diving taxa in both datasets (see Supplementary Tables 5, 6 for taxa classified with these ecological traits). In each iteration, the variables (bone compactness and diameter) from the training set of taxa with known ecologies, together with the phylogenetic structure of data, are used to generate the discriminant functions, which are subsequently used to predict the ecologies in extinct taxa with unknown ecologies (including spinosaurids). A species is predicted as subaqueous forager if the posterior probability is 50% or more, because our inference has only two possible outcomes: subaqueous forager or non-subaqueous forager. We summarised our results by providing the median value of those 100 posterior probabilities and the number of times a particular taxon is predicted as subaqueous forager (median probability of 50% or more). This gives us two proxies of the likelihood of each taxon to be an actual subaqueous forager. For instance, a taxon could be predicted 100 times as subaqueous forager with a median probability of 51% which means the evidence for this extinct species to be an actual subaqueous forager is very weak and this inference has to be considered very unlikely. Median probabilities need to be within the range of 80–100% to be considered as strong evidence of subaqueous forager. Additionally, we considered the presence of an open medullary cavity or osteosclerosis to support our inferences.

Reporting summary

Further information on research design is available in the Nature Research Reporting Summary linked to this paper.