Recovery of dung beetle biodiversity and traits in a regenerating rainforest: a case study from Costa Rica's Osa Peninsula

Dung beetles are frequently used to assess tropical biodiversity patterns and recovery in human‐modified forests. We conducted a comprehensive dung beetle survey (coprophagous and necrophagous communities) within five habitat types, across a land‐use gradient, in the ecologically biodiverse Osa Peninsula, located in Costa Rica's south Pacific. In addition to assessing species richness, abundance, and biomass, we also assessed community level traits and species‐specific responses using a generalised joint attribute modelling approach. We found that under favourable conditions (40–50 years of regeneration, close proximity to contiguous old‐growth forest and control of poaching), secondary rainforest recovered similar levels of species richness, and key traits of old‐growth forest dung beetle communities. However, at the community‐level, dung beetle abundance, richness, biomass, and diversity varied between habitat types of different anthropogenic disturbance and land‐use. Generally, the carrion beetle community did not recover as well as the dung beetle community and the abundance of dung beetles was a third lower in naturally regenerating secondary forest compared with old growth. Regenerating secondary growth and plantation forests showed community compositions similar to old growth forests, while open and fragmented habitats had degraded and impoverished levels of dung beetle biodiversity. Overall, the levels of dung‐beetle biodiversity detected are encouraging for naturally regenerating secondary forest, suggesting a high potential value of these areas to buffer the pressure of deforestation and habitat alteration on remaining old‐growth tropical forests.


Introduction
To conserve rainforest biodiversity and ecosystem function, we need to both protect remaining intact old growth forests (Barlow et al., 2007a;Gibson et al., 2011;Poulsen et al., 2020) and regenerate secondary forests (Dunn, 2004;Letcher & Chazdon, 2009). Old growth rainforest provides the baseline measure of maximal biodiversity (Gibson et al., 2011) against which we compare both regenerating and human-modified forests. Studies have suggested that secondary rainforests can contain species richness levels comparable to those of old growth rainforests (Dunn, 2004;Letcher & Chazdon, 2009) and can recover within a relatively short space of time (80% recovery after 20 years and an average of 54 years for full recovery; see Rozendaal et al., 2019). However, the recovery of other biodiversity measures (community composition and ecosystem function) has shown to take longer to reach levels associated with old growth reference forests (centuries for biodiversity composition, if ever at allan average of 780 years; see Dunn, 2004;Rozendaal et al., 2019). In addition to recovery age, the types of surrounding forest, fragment size, the distance to contiguous primary forest patches, and the scale of past disturbance are all influential on the pace of recovery and the composition of regenerating areas (Whitworth et al., 2016).
The resilience of dung beetle assemblages to anthropogenic disturbance is not ubiquitous to all regions. In one of the most comprehensive assessments of rainforest dung beetles to date (Nichols et al., 2007), it is suggested that land-uses which maintain a high degree of general forest cover (e.g. secondary forest and agroforests) have similar community-level attributes (species richness and abundance) to those found within old-growth forests. In some cases, a high level of forest disturbance is associated with higher species diversity (Nichols et al., 2007;Torppa et al., 2020). Torppa (2020) found diverse communities of dung beetles in highly degraded landscapes, but only when closed canopy forest was relatively nearby.
However, Audino et al. (2014) found that despite 18 years of recovery in regenerating Atlantic forests of Brazil, dung beetle species richness and abundance displayed an impoverished community of dung beetles compared with that of old-growth forest. In some of the secondary forest sites species richness and abundance of dung beetles were similar or lower than pastures. Another study from Brazil also found contrasting findings to those by Nichols et al. (2007). Species richness of secondary forest (14-19 years post abandonment) was 67% of that found in old growth forest and abundance just 40% (Gardner et al., 2008).
Focusing on dung beetle species richness alone may mask important changes in the functional diversity of a given community (Audino et al., 2014;Nunes et al., 2016). Dung beetle morphological and life history traits like size, biomass, colour activity period, and burial strategy have been shown to be valuable indicators of habitat condition and recovery. Heavily disturbed areas such as open-grasslands, clear-cuts, and intensely fragmented areas are often dominated by abundant small-bodied species and few forest specialists (Nichols et al., 2007;Filgueiras et al., 2011;Slade et al., 2011). This change in the composition of morphological and life-history traits represents degraded function and habitat health. For example, significantly lower mean dung and seed removal rates have been detected in intensively logged forest sites, whereas community measures of abundance and richness appeared unchanged (Bui et al., 2020).
Although beetles in the subfamily Scarabaeinae are predominantly coprophagous, some species have a feeding preference towards carrionnecrophagous species, and some beetles show a more generalist feeding habit whereby they feed and bury both dung and carrion. When we compared the tropical studies assessed by Nichols et al. (2007) with recent studies from the last decade (see Supporting Information Appendix S1 for details), 67% used dung-baited pitfall traps (n = 31), 4% used carrion-baited pitfall traps (n = 2), and 28% used both (n = 13). Where carrion and dung baited pitfall traps were both utilised, their samples were pooled to provide a representation of the overall community (Klein, 1989;Diaz et al., 2010;Salomão et al., 2020;Quintero et al., 2009). Such assessments lack detail upon the recovery of specific sub-groups. Especially considering that dung or carrion resources might be differentially affected by habitat type depending on how other wildlife utilise specific habitats.
Different sampling methodologies (either survey type or bait choice) that target sub-groups of a taxon have been shown to produce different results in terms of biodiversity responses to habitat change (Klingbeil & Willig, 2009;Whitworth et al., 2017). In some cases, focusing on one method can lead to underestimating the true proportion of species losses from the degradation or loss of old growth forests (Whitworth et al., 2017). Variable responses within taxa have been detected for butterflies (Whitworth et al., 2018b,c), birds (Barlow et al., 2007b) and amphibians (Whitworth et al., 2017), and the same might be true for dung beetles, whereby the environmental conditions of different habitats are conducive for one group to be more diverse than the other. As such, understanding how different feeding guilds (both coprophagous and necrophagous) respond separately can give better insight into how habitat disturbance and forest recovery affect functional processes.
Costa Rica is an ideal location to study the value of recovering landscapes and habitat matrices for biodiversity. Between 1940 and 1987, primary forest cover was reduced from 67% to just 17% (Sader & Joyce, 1988;Hall et al., 2000). Since then, many interventions and changes (e.g. forestry laws and payment for ecosystem services) have helped return forest cover to 51%. Of this, 24% is classified as primary forest, 9% as planted forests, and 67% as recovering secondary-growth forest (FAO, 2011). As few areas of primary forest in Costa Rica are sufficiently large enough to completely support genetically viable populations of larger vertebrates (such as tapirs, white-lipped peccary, and spider monkeys), secondary forest is thus likely to be important for the persistence of species between contiguous key protected areas (Vaughan, 2012), and associated biodiversity groups such as dung beetles.
We conducted a comprehensive dung beetle survey using both carrion and dung baits to sample coprophagous and necrophagous beetle species, across five habitat types (old-growth primary forest, naturally regenerating secondary forest, recovering secondary plantation forest, recently abandoned agricultural land, and remnant forest strips within agricultural land). We did this in a site that has been protected from hunting for over 18 years, in the ecologically biodiverse Osa Peninsula located in Costa Rica's south Pacific coastal region. Specifically, we aimed to answer the following questions: (i) Do dung beetle abundance, richness, biomass, and community evenness vary along a land use gradient of different habitats? (ii) How do species-specific responses underpin community-level responses to habitat disturbance? and (iii) How are dung beetle community morphological and life-history traits influenced by habitat disturbance?

Site description
The Osa Peninsula in southwest Costa Rica is home to the largest remaining tract of Pacific lowland wet forest in Mesoamerica (Holdridge, 1967). The Osa Peninsula also exhibits a unique landscape matrix of cattle farms, oil palm, pineapple, secondary forest (with an increase of 10.4% of secondary forest between 1987 and 2017; Shrestha et al., 2018), interspersed with primary forest of which less than half of the original area remains (Weissenhofer et al., 2001). As much of the secondary forest in Costa Rica is >30 years old, we would expect that the recovery of dung beetles in secondary forests has had sufficient time to recover at least 80% of original richness levels as those found within old growth, if estimates of tropical meta-analyses are accurate (Nichols et al., 2007).
The Osa hosts four protected areas -Corcovado and Piedras Blancas National Parks, the Terraba del Sierpe Wetland, and the Reserva Forestal Golfo Dulce. The climate is tropical, with temperatures ranging between 23.4 C and 28.8 C (Whitworth et al., 2018a). Rainfall averages 3000-7000 mm yr −1 (Taylor et al., 2015) and is seasonal, with a rainy season from June to November and a dry season from December to May.
We conducted this study in May to September 2017 at the Osa Conservation Campus (formerly known as Piro Biological Station;8.40388 N,83.336618 W; the study year saw an annual total rainfall of 3975.7 mm, a temperature high of 32.9 C and low of 15.5 C), situated in the biological corridor (the Golfo Dulce Forest reserve) that buffers Corcovado National Park. The Osa Conservation Campus comprises 1330 ha of privately protected land with a variety of habitat types, including among others; old-growth primary forest, naturally regenerating secondary-growth forest (35-45 years), secondary plantation forest (cattle pastures that were converted to monoculture plantations 30 years ago, enriched by recently planting 80 000 trees of 50 native species over the past 5 years), recently abandoned cattle pastures (cleared over 40 years ago and was actively farmed), and remnant forest strips, which contain a variety of mature fruiting trees that provided shade for cattle (Figures 1 Figure 1. Representative photographs of the five major habitat types we investigated in the study site on the south-eastern Pacific coastline of the Osa Peninsula, southwest Costa Rica: (a) old-growth primary forest containing giant mature Ajo trees (Caryocar costarincense); (b) naturally regenerating secondary-growth forest (40 years old); (c) secondary plantation forest (initially cattle pasture, followed by monoculture-style plantation, with recent enrichment planting); (d) active agricultural farmland; (e) and (f) remnant forest strips of varying widths (outside (e) and inside (f) perspective). [Color figure can be viewed at wileyonlinelibrary.com] and 2). We combined three different sources of information for categorising and mapping habitat types: (i) local historical knowledge, (ii) a thesis detailing restoration in the secondary plantation forest (Foster, 2002), and (iii) aerial imagery from Google Earth, the National Geographic Society archives in San Jose, and (Sandor & Chazdon, 2014). For further information regarding land use history and vegetative characteristics of the study site see Whitworth et al. (2018a).

Study approach, sampling design and sampling effort
We used a natural experimental approach (Hulbert, 1984), choosing a study site within a location where historic human disturbance had varied across a relatively small area. This approach allows us to be confident that patterns identified associated with bait type or disturbance history can be linked to treatment effects (Davies & Gray, 2015). Studying within-site differences in biodiversity at the site spatial scale can mitigate confounding effects of large-scale drivers of spatial autocorrelation, such as climatic differences or differences in physical geography. There were no geographic barriers (e.g. large rivers such as those found in Amazonia, or high-elevation mountain ranges) that could hinder dispersal across the site. This allows for the interpretation of community composition as a response to habitat variability and not heterogeneity at a larger spatial scale (Barlow et al., 2007a).
A potential caveat of this small spatial scale is that transient species can enter adjacent treatment types (Barlow et al., 2007a), meaning that individuals might not necessarily be able to survive in the habitats they are censused in but could be recorded. This is true of all habitat types and should therefore not dilute any observed differences in biodiversity.
Although our approach at the within-site scale can eliminate the effects of large-scale confounding factors of between site studies, an ideal situation would have been to have habitat types equally interspersed to create a mixed survey design. We controlled for the potentially confounding effect of altitude, yet other subtle underlying factors, such as soil fertility, could play an underlying confounding effecteven at a small spatial scale. Such an interspersed design is not encountered under natural conditions and disturbances are often localised in blocked areas as the case in our study. There is no complete way to overcome this confounding spatial challenge in our survey design, but we do believe the within-site scale gives some confidence that our design is not completely confounded between all habitatsforest strips and pastures were completely interspersed for example.
To test whether human disturbance history differentially impacted biodiversity distribution patterns dung beetles were surveyed across 70 sampling locations, with 14 baited pitfall traps set in each of the five habitat types (Krell, 2007;see Fig. 2). We placed traps with a minimum spacing of 250 m and a minimum distance of 100 m from habitat edges, which well exceeded the proposed minimum spacing of 100 m to avoid trap interference (Giovâni et al., 2015a). Trap survey areas covered approximately 120 ha of old growth, 190 ha natural second growth, 100 ha of secondary plantation forest, and 150 ha of abandoned pastures with forest strips. Field survey methodologydung beetles and environmental covariates At each trapping location (Fig. 2), we installed a baited pitfall trap by using an 473 cm 3 (16 oz) plastic cup filled with water and a small amount of unscented detergent buried flush into the ground. Bait was suspended over the cup and protected from the elements via a plastic plate roof (Larsen & Forsyth, 2005;Krell, 2007). We used human dung, the most effective for sampling dung beetles (Howden & Nealis, 1975), and carrion baits (in separate trapping sessions) to ensure sampling of both coprophagous and necrophagous beetles (Simmons & Ridsdillsmith, 2011). Each trapping location underwent a single 24-h trapping session with 30 g of human dung bait wrapped in nylon thule and a single 24-h trapping session with 30 g of carrion bait (butchers off-cuts; a pig, cow and chicken mix). We used a dung bait size of 30 g and a 24-h sampling duration based on common study design within tropical dung beetle research (Spector & Ayzama, 2003;Flechtmann et al., 2009;Bicknell et al., 2014).
For each 24-h sampling period, we recorded total rainfall (inches) from a weather station at the study site and moon illumination (%) for the Osa Peninsula from a global online database (www.timeanddate.com). Both climatic variables were chosen as they have shown to influence dung beetle activity (Dacke et al., 2014;Batista et al., 2016;Latha, 2019) and we wanted to account for any potential variation between different sampling nights throughout the study period. We also calculated the elevation (m) using ArcGIS as altitude has been previously found to correlate negatively with dung beetle species richness (Nunes et al., 2016).
We stored captured dung beetles in 70% ethyl alcohol and processed them. Processing involved identifying samples to species-level using a handheld digital microscope and magnifying glass by author EF using published literature containing identification keys and specimen records for the region, (Kohlmann et al., 1997(Kohlmann et al., , 2007Solís & Kohlmann, 2012) and online scarabaeinae archives (scarabaeinae.myspecies.info/). Specimen morphological traits were measured and then dried and pinned as a reference collection available at the Osa Conservation Campus and the University of Costa Rica National Insect Museum.

Measuring dung beetle species traits
We assessed four species traits: (i) overall size (body size and wing loading), (ii) diel activity (nocturnal or diurnal), (iii) dung burial strategy (rollertelecoprids, tunnellerparacoprids, or dwellerendocoprids) and (iv) colour pattern (metallic, uniform and patterned). These traits were chosen due to their correspondence to ecological function (Nichols et al. 2008). Body size is tied to rate and amount of food acquisition, competitive ability, soil digging depth ability, seed dispersal rate, and dung removal rate (Slade et al., 2007;Braga et al., 2013;Audino et al., 2014;Barnes et al., 2014;Giovâni et al., 2015b). Wing loading is informative of travel distance and habitat-specific flight requirements, such as perch availability and mammalian predators . Diel activity corresponds to temporally specific resource availability and predator avoidance . Dung burial strategy can tell us about the relative success of larval and adult beetles, linking to seed dispersal depth and rate, plant regeneration, and nutrient recycling (Slade et al., 2007;Braga et al., 2013;Audino et al., 2014;Giovâni et al., 2015b). Finally, colour is suggested to correspond to palatability in relation to toxicity as a defence mechanism for predators or competition linking to mammal community presence and predation pressures .
We calculated overall body size as the product of elytra width and body length (measured from the pygidium to the anterior margin of the pronotum). To measure biomass, we dried beetles in a drying oven at 100 C for 24 hr or until mass had not reduced for 1-h. We measured wing loading (body mass/wing area) by placing a spread, flattened wing from each individual onto a debit card and using the LesionMeter App (Version 1.0.7)surface area measured in cm 2 . Body size, biomass and wing loading were all measured from the same individualsbetween one and 25 individuals for each species (as in the study by Larsen et al., 2008). For species that showed sexual dimorphism we pooled measurements for male (50%) and female (50%), as we did not detect any clear sex differences. When less than three individuals of a species were captured (three of the 33 species detected), measurements that would deform the specimen (biomass and wing loading) were not collected as the individuals were required for reference specimen collections. For dry biomass, we obtained the missing information from the literature; however, wing loading information was unavailable.
We classified diel activity profiles as species captured diurnally (06:00-18:00) or nocturnally (18:00-06:00). We obtained activity profiles via pitfall trapping for 24 h with trap checks every 2 h in four main habitat types (primary forest, secondary forest, plantation forest and grassland) to ensure sampling of all dung beetle species present at the study site and to ensure activity did not change across habitat type. Burial strategy was classified by: (i) tunneller (ii) roller or (iii) dweller. These categories were assigned based on existing literature and incidental inthe-field observations by the field team (Kohlmann et al., 1997(Kohlmann et al., , 2007Solís & Kohlmann, 2012). Dung beetle species were classified during sampling and when possible confirmed by existing literature (Mehrabi et al., 2014). We categorised each species into one of three colour patterns (metallic, non-metallic and patterned) as the colour and patternation of some dung beetle species may be aposematically related to their ability to produce toxins to deter predators (Vulinec, 1997).

Statistical analyses
Community-level responses.
To compare habitat-specific diversity indices we used the iNEXT package (Hsieh et al., 2016) in the R statistical environment (R Team, 2018). We report extrapolated observed richness (q = 0) as individual based rarefaction curves showed that habitats were not sampled to saturation and a different number of individuals were captured in each habitat type (Supporting Information Appendix S2). Habitat-specific richness estimates, and their corresponding confidence intervals, were calculated at 1750 individuals for all bait types, 1500 individuals for dung, and 250 individuals for carrion. Community structure was assessed using rank-abundance (Whittaker) plots for each forest type with the vegan package (Oksanen et al., 2016). Significant differences in slope between the habitat types (assessed using a linear model with log relative abundance as the response term and an interaction between species rank and habitat type as continuous and categorical fixed effects, respectively) was taken to reflect statistical support for habitat-related variation in community skew/evenness.
Observation-level richness, abundance and biomass were compared between forest types using linear mixed effects models with the glmmTMB package (Brooks et al., 2017). We defined observed richness as the number of unique species, abundance as the number of individuals captured (irrespective of species), and biomass as the number of individuals multiplied by their species-specific dry biomass detected in a given 2-days capture event. We included two categorical fixed-effects: habitat type (old growth, secondary forest, plantation forest, forest strip or grassland) and bait type (carrion or dung); and three continuous fixed-effects: altitude (to control for topographical variation in dung beetle activity), rainfall during the capture event (to control for weather effects on trapping efficiency) and moon phase (to control for lunar fluctuations in dung beetle activity). Site was included as a random intercept term to control for the non-independence of repeated samples (dung and carrion) from the same survey location. In all models, a negative binomial family ('nbinom2') was used to account for the overdispersion detected in the count models. As all the covariates were plausible and un-correlated, we ran every combination of the covariates from the global model (including all predictors) to the null model (no predictors). For each response term, we ran we ranked all models by their AICc and defined a top model set as the models ΔAIC ≤6 from the best supported model. To avoid interpretation of spurious candidate variables, we removed all models from the top model set which had a simpler nested-model with more relative support (Harrison et al., 2018;Richards et al., 2011). Informative covariates are discussed in terms of their relative support, defined here as the sum of Akaike weights across all of the 'topset' models in which the covariate occurs, and in terms of their absolute importance, defined here as the effect-size on the response term.
Finally, to confirm that any potential spatial auto-correlation between survey locations had been controlled for in the analysis, a Moran's I test, using inverted distance weighting, was carried out on the residuals of each best-supported model to test if there was any effect from spatial auto-correlation that might lead to pseudo-replication.

Species-level responses.
To characterise species-specific responses to forest type whilst acknowledging that species responses are not independent of one-another, we applied a generalised joint attribute model (GJAM) that explicitly accounts for the residual covariance among species after controlling for the fixed effects (Clark et al., 2017). Here, our response are species counts (n = 33) for each 2-day survey site. As before, we included the categorical effects of forest and bait type, and the continuous effects of elevation and moon phase (rainfall was not included as there was no strong evidence for this parameter in the forest-type level analyses). We used a burn in of 75 000 and 150 000 iterations. For complete details on model specification, see Clark et al. (2017). We focus on the interpretation of species-specific effect sizes for each parameter and the residual covariance matrixwhich represents the covariance between species beyond what has already been explained by the fixed effects. The positive, neutral or negative covariance observed between species can reflect co-occurrences arising through interactions between species, common responses to unmeasured environmental gradients, and other unexplained sources of error (Blanchet et al., 2020). For the fixed effects, we deem any parameter estimate whereby the 95% posterior credible intervals do not span zero as evidence of statistical significance and discuss variable importance in terms of their effects size.
Finally, we generalised the speciesspecific responses into community-weighted mean trait values (de Bello et al., 2010) to explore the functional responses of the dung beetle community to forest type, after controlling for the other covariates. As such, the response terms in this model were the continuous variables of body size and wing loading (see above), and categorical terms of activity pattern (nocturnal, diurnal), dung/carrion use strategy (roller, dweller, tunneller or unknown), and colour (metallic, non-metallic and patterned). Species without traits were removed from the model (n = 5; Supporting Information Appendix S3). We used the same predictor variables described in the species-specific modelling above. We used a burn in of 20 000 iterations and a chain length of 100 000. For the fixed effects, we deem any parameter estimate whereby the 95% credible intervals do not span zero as evidence of statistical significance and discuss variable importance in terms of their effects size.

Capture summary
We captured a total of 2771 dung beetles of 33 species (see Supporting Information Appendix S3 for species list). Of these, 1286 individuals of 24 species were captured in old growth forest (five of which were unique to old growth; the most abundant was Canthon aequinoctalis); 818 individuals of 24 species in secondary forest (three of which were unique to secondary forest; the most abundant was Onthophagus batesi); 361 individuals of 21 species in regenerating plantation forest (and one of which was unique to plantation; the most abundant species was Canthon aequinoctalis); 99 individuals of seven species in the remnant forest strips (no unique species; the most abundant was Onthophagus batesi); and 207 individuals of four species in abandoned pastures (consisting of two dominant species; Onthophagus marginicollis and Canthon mutabalisnote: two of these four species were found in just a single trap occasion; Supporting Information Appendix S3). Old-growth forest contained the most unique species and greatest number of necrophagous species (carrion-feeders), secondary forest had the most coprophagous species (dung-feeders).

Community-level responses
Considering both baits together, the mean estimated richness of dung beetles was similar in the old-growth, secondary, and regenerating plantation habitats (26.4, 26.2 and 23.7 species, respectively; Table 1 and Fig. 3a) but impoverished in the forest strips and abandoned pastures (7.3 and 5.0 species, respectively). The overall pattern was similar when considering the dungbaited traps separately (Fig. 3b), with the only difference being that the abandoned pastures (5.0 species) were estimated to have a slightly higher richness than forest strips (4.0 species), although both still significantly lower than the other three forested habitats (old growth = 20.3, secondary = 21.5, regenerating plantations = 17.9). When considering carrion-baited traps separately, this pattern changes: old growth forest had a greater estimated richness in carrion-baited traps than all other habitats (17.2 species), secondary, regenerating plantation, and forest strips all had similar levels (9.4, 8.0 and 7.6, respectively), with the lowest levels estimated in abandoned pastures (2.0 species; Fig. 3c).
The community evenness of old-growth forest (slope of Whittaker rank abundance curve; Fig. 3d) was the most even with a curve of a few dominant species followed by a long-tail of increasingly rarely encountered species; typical of oldgrowth forests. When comparing the old-growth slope to those of the other habitats, secondary forest showed no difference with similar evenness (P = 0.17), regenerating plantation was steeper but not significantly so (P = 0.07). Forest strips (P < 0.01) and grassland (P < 0.01) showed significantly skewed, less even communities in comparison to old growth forests. Canthon aequinoctalis was the most abundant species within old growth forest, although its rank position dropped in other habitats, except regenerating plantations where it remained the dominant species. This species was also completely absent from forest strips and grasslands and can be considered a contiguous forest specialistparticularly old growth forest. Onthophagus batesi was the second most abundant species and Onthophagus acuminatus was the third most abundant species in all habitats, except for abandoned pastures where just a single individual of each species was captured. These two species are the most dominant in old second growth forests in place of C. aequinoctalis.
There was strong support for both bait type and habitat in predicting the raw abundance of dung beetles (R 2 of best-supported model -fixed effects = 38.4%, random effects = 3%, total = 41.4%), observed species richness (R 2 of best-supported model -fixed effects = 71.9%, random effects = 0%, total = 71.9%) and biomass (R 2 = 37.6%: calculated from linear model without random effects, as the random intercept term possessed zero variance) of dung beetles ( Fig. 4; Table 2; Supporting Information Appendix S4). There was full support for dung-baited traps capturing a greater number of individuals, more species, and a greater biomass of dung beetles than carrion-baited traps for using the same survey effort ( Table 2). Comparison of habitat-specific confidence intervals suggests that the difference in beetle abundance between dung and carrion is clear in all habitats, whereas for species richness, the difference is only clear between old-growth and secondary forest and all other habitats, and for biomass the clearest difference is between contiguous forests, and abandoned pastures and forest strips. Old growth forest dung-baited traps typically captured the greatest individual count and biomass of dung beetles, but a similar number of species as the naturally regenerating secondary forest (Fig. 4). Forest strips supported the lowest numbers of individual counts and observed species richness, but a greater biomass than abandoned pasture sites (Fig. 4). Dungbaited regenerating plantation traps had intermediate counts of individuals and species detected, but a greater biomass than both secondary forest and forest strips, but lower that reference oldgrowth. Carrion-baited traps followed a very similar pattern, although with consistently lower counts of individuals, species, and biomass.
Testing of model residuals showed no evidence of spatial auto-correlation between samples with very low correlations and non-significant (range from P = 0.10-0.38) observed Moran's I values for all response variables (see Supporting Information Appendix S6).
We assessed the explanatory power of three additional covariates (rainfall, moon illumination and elevation) hypothesised to influence dung beetle activity, habitat use, and capture rates. Elevation and moon illumination had a weak positive effect on dung beetle abundance, and elevation had a weak positive effect on observed species richness (Table 2; Supporting Information Appendix S5). None of these covariates had any effect on biomass of dung beetles captured (Table 2). After controlling for the fixed effects (habitat, bait type, elevation, and moon phase), there remains marked structure in species co-occurrences (Fig. 5). Species segregate into three co-varying clusters (Fig. 5a). Group one represents 15 species captured more frequently with dung bait in either old growth, secondary or plantation forests. Group two consists of species with similar habitat preferences to group one species (commonly co-occurring at the same locations) but with a preference for carrion bait. Group three represents two apparent grassland specialist species (Canthon mutabilis and Onthophagus margnincollis), which are largely absent from forested habitats and do not co-occur with any other species. The species falling outside of these groups show no clear affinity to any habitat or covariate or were not captured on a sufficient number of occasions for co-occurrences/covariate associations to be determined.
Examining the species-specific responses to the habitat and environmental covariates reveals that the general trends observed in the community-level analyses are composed of a suite of species-specific responses. Of all the species examined, four of 22 were detected in higher abundance using carrion bait than dung (Fig. 5b). Relative to the capture rate in old growth forest, 14 species were detected more frequently in secondary forest and five species more frequently in plantation forest. There were two species with a clear affinity for grassland habitat, Onthophagus marginicollis and Canthon mutabilis. In comparison to the habitat associations, there were far fewer speciesspecific relationships with elevation and moon phase. Higher elevation positively affects the capture rate of Coprophanaeus pecki but negatively the capture rate of Canthon acutus and

Trait-level responses
Decomposing the species-specific responses to communityaveraged traits revealed strong support for the necrophagous beetles being larger, with a lower proportion of dwellers and rollers, in comparison to the beetles attracted to dung bait (Fig. 6).
Carrion-bait also captured fewer non-metallic dung beetles. The traits represented in old growth forest, secondary forest and regenerating plantation were broadly similar, only more tunnelling dung beetles we captured in secondary forest. Rolling as a breeding strategy trait was generally most prevalent in oldgrowth forest compared with other habitats, but only significantly lower in forest strips and abandoned pastures. In addition to fewer rollers, the forest strip communities had fewer metallic dung beetles. The traits represented in the pasture forest community were lacking in nocturnal, rolling, and non-metallic and metallic dung beetles. This is driven by only patterned dung Figure 4. Observed dung beetle abundance (a), richness (b) and biomass (c) by habitat type from the best supported models in Table 2. Points denote the mean estimated value of each response term, and the whiskers represent 95% confidence intervals. For additional co-variate plots with support see Supporting Information Appendix S5 and for the full model selection output see Supporting Information Appendix S4 [Color figure can be viewed at wileyonlinelibrary.com] Where all models above '...' were included in the top model set; the model below the '...' is the null model (for all models in between see Supporting Information Appendix S4); the grey shading denotes the best supported model used to generate the predictions (Fig. 4); df = degrees of freedom; AIC = Akaike information criterion; ΔAIC = the change in AIC relative to the best supported model; wt = model weight. beetle being in abandoned pastures. Neither elevation nor moon phase showed any affect upon community trait composition.

Discussion
Under the favourable conditions of 40-50 years of regeneration, close proximity to contiguous old growth forest, protection of ongoing disturbance and the control of hunting, secondary rainforests not only recover similar levels of species richness, they have the potential to recover key traits and functions (related to seed dispersal, seed burial and soil aeration) of old-growth forest dung-beetle communities. We find that at the community-level, dung beetle abundance, richness, biomass, and diversity vary between habitat types of different anthropogenic disturbance and land-use in the Osa Peninsulawith the most notable differences between forested and non-forested habitats. Whereas contiguous secondary growth and plantation forests showed community compositions similar to that of old growth forests, open and fragmented habitats had degraded and impoverished levels of dung beetle biodiversity. Although Torppa et al. (2020) found diverse communities of dung beetles in highly degraded landscapes of Madagascar when closed canopy forest was nearby, we did not, even though our grassland and forest strips were surrounded by contiguous high-quality habitat. Torppa et al. (2020) discuss the reduction of mammals in the surrounding forests as a potential contributing factor, whereas at our site in Osa, informal communications with locals and site managers who acquired the property almost 20 years ago, suggest that many mammal species that were absent, like tapir, puma and white-lipped peccary, have now returned (confirmed by the use of camera trap surveys at the site). The community-level changes observed were underpinned by species-specific responses. Co-occurrence estimates suggested the presence of three distinct groups. Two of these showed affinity to contiguous forested habitat (regardless of disturbance history) and were largely absent from fragmented forest strips or recently abandoned pastures. The species-specific differences observed led to shifts in functional trait composition of each habitat relating to diel activity, breeding strategy and colour. We discuss these findings in terms of the implications for recovery of disturbed forests, within the Osa peninsula and beyond, below.
The old-growth rainforests of our study site contained the highest dung beetle species richness, abundance, biomass, community evenness and counts of large-bodied, rolling, and dwelling dung beetles. Naturally regenerating secondary forest had overall high levels of species richness and a community evenness similar to old-growth forest, but community-level abundance and biomass were lower. Old-growth forest generally held the highest number of dung beetles that were dung rolling species when compared with all other habitats, but secondary forest had significantly higher captures of tunnelling species. This is a positive outlook as to the health and recovery of secondary forests in the Osa, as other studies from other regions (Navarrete & Halffter, 2008;Kudavidanage et al., 2012) have reported a loss in large-tunnelling dung beetles (a group that contributes significantly to aeration of soils and improved seed germination rates). The potential for high-quality forest recovery in the Osa is likely high as there are substantial areas of old-growth in the region and important seed dispersing wildlife species remain present (Weghorst, 2007;Gutierrez et al., 2019); as such this should be considered a 'best-case scenario' for recovery potential (Ferraz et al., 2014;Whitworth et al., 2016). Other secondary forests that are isolated from old-growth and have suffered defaunation of important seed-dispersing species might not recover as quickly or to the same degree as the secondary forests studied here. In some cases, the regeneration of disturbed forests may move towards a completely different trajectory whereby forests might completely fail to recover (Sloan et al., 2015;Goosem et al., 2016;Lennox et al., 2018).
Regenerating plantations were not as effective as natural second growth in facilitating dung beetle biodiversity, and narrow, isolated forest strips were poorer still. The ability of dung beetles to utilise plantation forests, albeit in lower abundances, has also been detected by Medina et al. (2002). Reduced abundance of dung beetles is suggested to be due to limited resources; for example, regenerating plantations likely have fewer mammals, birds, and other wildlife that both coprophagous and necrophagous dung beetles depend upon. It is also known that thermal tolerance varies across dung beetle species affecting their internal functions and defining their ecological niche (Gaston & Chown, 1999;Gimenez et al., 2017). As such, a lack of a closed tall canopy and dry seasonally deciduous leaf fall by plantation species such as Tectonia may present thermal barriers for old growth adapted species found in the understory. The plantations, although enrichment planted with a variety of other species in recent years (Whitworth et al., 2018a), are still comprised of mature trees that are predominantly Pochota fendleri, Terminalia amazonia, Tectona grandis and early successional species, Vochysia guatemalensis and Xylopia frutescens. The enrichment planted trees remain small and growing and as such are not yet producing the fruits and resources needed by a diverse array of wildlife. Furthermore, several of the most common species seed with wind-dispersed samaras rather than fleshy fruits. For example, in an unpublished thesis work at the same study site, spider monkeys were detected within the regenerating plantations, but records were far less frequent than in old-growth and secondary forest (Connor & McGowan 2018thesis). Although forest structure allows large-bodied primates to use the plantations, it is likely that there is not yet the diversity of food resources to maintain them in comparable densities to old-growth forest. Thus, there are less dung and carrion resources available for the brown-web detritivore community.
Despite forest strips containing a diversity of mature tree species that can produce a variety of fruits, their isolation and degradation means they are unlikely to support population levels of other wildlife found in contiguous forest, with downstream consequences for the dung beetle communities they support. Dung beetles have been shown to be susceptible to edge effects and fragmentation, with only larger fragments supporting more abundant and diverse community assemblages (Estrada & Coates-estrada, 2002;Andresen, 2003;Chapman & Chapman, 2003;Arellano et al., 2008). This is likely a combination of the inability of small fragments to support other wildlife, and due to the exposure of physical changes (e.g. light, heat and humidity) that affect those species which need more specialised closed forest conditions. The mean average width of forest strips in our study area was 42.5 m (range = 23.3-88.5 m), so despite containing mature rainforest trees, they are narrow and fragmented; enough to support just a subset of forest associated species. The mechanisms described above are taken to extremes in grassland habitat, and as with (Nichols et al., 2007), we find that the abandoned pastures were dominated by a hyper-abundance of just two small-bodied tunnelling species which are rarely found elsewhere. This could be due to the aggressive and competitive nature of tunnellers in utilising the dung resources available (Krell-westerwalbesloh, 2014).
When considered separately to the dung feeding community, necrophagous beetles did not recover in secondary forest to the same extent as the coprophagous feeders. Within-taxon heterogeneity in biodiversity recovery is not uncommon and has been detected for other taxa such as butterflies (Whitworth, et al., 2018b,c), birds (Barlow et al., 2007b) and amphibians (Whitworth et al., 2017). In the case of dung beetles, just 4% of studies we reviewed used carrion-baited pitfall traps (n = 2), and only 28% used carrion in addition to dung (n = 13); but none directly compared the response of both coprophagous and necrophagous communities. Although the size of the necrophagous dung beetle community is smaller than the coprophagous dung beetle community, the function and role this community provides in terms of carrion-processing and removal from ecosystems is critical. On average, the capture rate of necrophagous dung beetles was 15% of the numbers captured using dung bait. This suggests that necrophagous dung beetles are typically rarer and potentially more specialised. This might explain why their communities are slower to recover than the more abundant dung-associated species. It is important to note that we controlled for the effects of altitude, moon phase and rainfall patterns when quantifying the effects of disturbance history on dung beetle communities. Despite altitude, moon phase and rainfall being previously found to influence dung beetle community richness and activity (Dacke et al., 2014;Batista et al., 2016;Nunes et al., 2016;Latha, 2019), we found that their effects were weak or completely absent at this scale. It is possible the importance of these covariates increases with the scale of the study, and that these covariates are highly influential at landscape scales.
In addition to assessing overall patterns of biodiversity, we also investigated species-specific responses and functional traits of the dung beetle community. There is a growing body of literature investigating species-specific responses and functional groups in tropical forests generally (Ding et al., 2011;Carreño-rocabado et al., 2012;Hidasi-Neto & Cianciaruso, 2012;Trimble & Van Aarde, 2014;de Coster et al., 2015), and for dung beetles specifically Nichols et al., 2013;Raine et al., 2018). This provides a better insight as to how shifts in communities might affect specific ecosystem functions, or not. Where studies have addressed the functional responses of dung beetle communities to land-use change they have found that the most intense forms, where forest is completely lost or highly fragmented, are associated with the loss of large-bodied tunnelling species (Navarrete & Halffter, 2008;Kudavidanage et al., 2012 an important group for soil aeration and nutrient recycling services). However, rather than tunnelling species, we find that it is the rolling, nocturnal and non-patterned species that are underrepresented in abandoned pastures in the Osa Peninsula. Abandoned pastures were dominated by two small-bodied tunnelling, diurnal species that were strongly patterned. Such patterning either reflects a warning to predators of toxicity or as better camouflage in open well-lit habitats (as opposed to a uniform or dark coloration that is better adapted for low-light understorey rainforest conditions). The pasture species detected here are widespread throughout Central America, typically occupying disturbed habitat. As they are not found in primary forest, their arrival represents a colonisation event from other disturbed habitat in the area. That the tunnelling functional trait was not lost in this case, highlights that loss of functional traits under disturbance will be region/habitat-specific dependent on the functional traits of colonising disturbance tolerant species. Promisingly, the naturally occurring second growth forests in Osa showed little difference in the community traits of old-growth forest, except for an increased occurrence of tunnellers.
In conclusion, we suggest that under favourable conditions and 40-50 years of regeneration, secondary rainforests not only recover similar levels of species richness, that they have the potential to recover key traits and functions of old-growth forest dung-beetle communities; related to seed dispersal, seed burial and soil aeration processes. However, we also found three pieces of evidence for concern. Firstly, abundance is reduced in naturally regenerating secondary forest compared with old-growth ( a third lower in our study), which suggests the resource base of secondary forest might need more time for recovery to become equivalent to that of an ancient old-growth. Second, the necrophagous community did not recover like the dung beetle community, so some key functions associated with dung beetles in terms of carrion-removal are not completely recovered, at least within 50 years of regeneration. Third, given the close proximity of old-growth forest, this work represents a 'best-case scenario' for re-growth. More isolated and fragmented regenerating forests may not recover biodiversity with the same degree of success via natural regeneration. However, the levels of dung-beetle biodiversity detected here are encouraging for those areas scoring highly under the ecosystem condition scoring system (Ferraz et al., 2014) suggesting a high potential value of regenerating secondary rainforest areas, and to a lesser degree plantation forests, to recover some of the biodiversity losses associated with deforestation and habitat alteration to old-growth tropical forests.

Data availability statement
The data that support the findings of this study are available from the corresponding author upon reasonable request.

Supporting information
Additional supporting information may be found online in the Supporting Information section at the end of the article.
Appendix S1 Supporting Information.