Developmental Environment Effects on Sexual Selection in Male and Female Drosophila melanogaster

The developmental environment can potentially alter the adult social environment and influence traits targeted by sexual selection such as body size. In this study, we manipulated larval density in male and female Drosophila melanogaster, which results in distinct adult size phenotypes–high (low) densities for small (large) adults–and measured sexual selection in experimental groups consisting of adult males and females from high, low, or a mixture of low and high larval densities. Overall, large adult females (those reared at low larval density) had more matings, more mates and produced more offspring than small females (those reared at high larval density). The number of offspring produced by females was positively associated with their number of mates (i.e. there was a positive female Bateman gradient) in social groups where female size was experimentally varied, likely due to the covariance between female productivity and mating rate. For males, we found evidence that the larval environment affected the relative importance of sexual selection via mate number (Bateman gradients), mate productivity, paternity share, and their covariances. Mate number and mate productivity were significantly reduced for small males in social environments where males were of mixed sizes, versus social environments where all males were small, suggesting that social heterogeneity altered selection on this subset of males. Males are commonly assumed to benefit from mating with large females, but in contrast to expectations we found that in groups where both the male and female size varied, males did not gain more offspring per mating with large females. Collectively, our results indicate sex-specific effects of the developmental environment on the operation of sexual selection, via both the phenotype of individuals, and the phenotype of their competitors and mates.


Introduction
Sexual selection favours traits that confer an advantage in intra-sexual competition in both sexes [1]. While historically, sexual selection studies have focused on males, it is now appreciated that intra-sexual competition can also play an important role in the evolution of females, which in turn affect males responses to female adaptations [2,3]. It is therefore important that studies on sexual selection consider both sexes, because resolving the evolution of sex roles and the nature of sexual conflict hinges largely on understanding the mechanisms that cause sexspecific patterns of sexual selection.
Traditionally, intra-sexual competition was considered exclusively over mating opportunities, and the strength of sexual selection has been measured by the slope of the linear univariate regression of offspring number against number of mates-the "Bateman gradient" [4][5][6][7]. Hence, the Bateman gradient explicitly captures only one component of pre-copulatory sexual selection: the number of mates (i.e. "mating success"). By showing that male Bateman gradients are often steeper than female gradients, this approach has been instrumental in defining sex roles [8][9][10]. Yet, it is becoming increasingly evident that other factors can influence the relationship between mate number and offspring number, particularly for males, where variation in paternity share due to post-copulatory sexual selection and variation in female productivity can be important (e.g. [11][12][13]). This indicates that the total number of offspring sired by a male (i.e. his "reproductive success") is best described through a multivariate approach as follows: where T is the total number of offspring produced, M is the number of females mated by a male, P is his average paternity share of the offspring produced by his mates, N is the average number of eggs produced by his mates and ε is an error term with 0 mean [11,14]. In this case, the multivariate model incorporates measures of both pre-and post-copulatory sexual selection and allows the investigation of their relative contribution to the total number of offspring sired by males [11]. Therefore, the multivariate approach substantially deepens our understanding of the factors that determine variation in the number of offspring sired by different males [11,12,15]. The interpretation of the female Bateman gradient has also attracted considerable debate [12,[16][17][18]. For instance, it is becoming increasingly clear that female Bateman gradients can be steeper than originally assumed (e.g. [2,3,12,[19][20][21][22]). However, the causality of this relationship is not always clear. In principle, a positive female Bateman gradient can measure sexual selection on female mate number, for example when mating provides cumulative direct benefits to females [17,23]. However, positive female Bateman gradients can also arise as a result of non-causal or inverse associations between mate number and the number of offspring produced [16,18,24], for example when inherently more fecund females either attract or require more mates [12,22].
A likely modulator of sex-specific patterns of sexual selection is the pool of resources available to individuals to allocate to traits [25] (i.e. individual's environmental conditions) and the pool of resources available for individual's competitors (i.e. social condition). Both the individual's environmental and social conditions can influence the strength of sexual selection, for example through the modulation of adult competitive ability, mate preferences, or productivity and body size, if body size is correlated with environmental conditions that affect any of these traits [26,27]. For instance, Janicke, David [28] recently showed that fluctuations in adult food availability levels can affect body weight, reproductive traits and the strength of sexual selection on a simultaneously hermaphroditic snail, Physa acuta. In food-restricted snails, mating was not significantly associated with increments in offspring number, resulting in non-significant Bateman gradients for both male and female roles, in contrast to larger, food-unrestricted snails where gradients were significantly positive. Adult diet manipulation rather than developmental diet implies relatively rapid plastic responses. However, the study of simultaneous hermaphrodites makes it difficult to disentangle the independent effect that diet may have on male and female roles from its influence on trade-offs in sex allocation within individuals.
In insects, including Drosophila melanogaster, adult body size is often mediated by the environment during development [29][30][31][32], which in turn tends to positively correlate with female productivity (i.e. large females produce more eggs than small females) and male quality [26]. Adult body size is expected to be under productivity selection (in females) and sexual selection (in males) in adult insects [3,26,[33][34][35]. A recent study showed that males with small body size (raised at high larval density) have reduced reserves of seminal fluid but invest proportionally more of this seminal fluid per mating than large males (raised at low larval density) [36]. Given that seminal fluid is limited in supply in D. melanogaster [37][38][39] small males may have a reduced ability to transfer multiple full-sized ejaculates. If so, being small could potentially reduce the benefits of multiple matings for males-in which case we would expect to observe reduced Bateman gradients-and could also modulate post-copulatory competitiveness [40]. Furthermore, both large and small males invest more seminal fluid when mating with large females, suggesting that males can adjust their ejaculate investment depending on the body size of their mates [36]. Importantly, the developmental environment tends to affect male fitness more than female fitness [41], suggesting that environmental conditions can have sex-specific direct (i.e. on the individual) or indirect (i.e. on the individual's mate) effects on selective forces. It is consequently reasonable to expect that there may be links between variation in the developmental environment, adult body size and the strength and form of sexual selection within adult populations.
Together, these previous studies indicate that environmental effects, particularly larval environment-mediated effects on adult body size or on traits associated with body size, have the potential to influence the strength of both pre-and post-copulatory sexual selection within populations. However, despite the growing interest in ecological factors affecting reproduction [28,29,[41][42][43][44], the effects of the developmental environment on patterns of sexual selection have received little attention. In this study, we manipulated adult traits, including body size, by varying larval density in D. melanogaster. Increasing larval density limits the quantity and quality of the food available per larvae, results in reduced adult body size, and has far-reaching consequences for male and female reproduction [29,30,[45][46][47][48][49]. Larval density may also signal as an index of population density, which is expected to play a central role life-history traits in species with high reproductive rates such as D. melanogaster and other insects [50], and therefore has important ecological and evolutionary implications. For example, high developmental densities might provide cues of intense intrasexual competition in adulthood [51,52]. Here, we tested how larval density influences reproductive behaviour and the strength of sexual selection, as measured by the Bateman gradient. Although, as described above, a manipulation of larval density is likely to affect multiple traits and impose different selective pressure on the larvae [29,45,53], for conciseness we refer to the set of experiments and groups according to the body size of adults, because this is the most striking adult phenotype from the larval density manipulation and is consistent with terminology in previous literature (e.g. [29,43]).
In principle, the developmental environment can influence the fitness of a focal individual directly by influencing a focal individual's own phenotypes, and by modulating the phenotypes of other group members (i.e. the competitors and potential mates of the focal individual), which can in turn feedback on the fitness of the focal individual. We used an experimental approach to explore these focal and group effects within each sex, by assembling groups of adults in which larval-density manipulations had resulted in body sizes which were constantly large, constantly small or varied in either sex or simultaneously in both sexes. Firstly, we investigated how the larval density manipulations on individuals and on group composition influenced the number of mates, mating frequency and the number of offspring produced by males and females. Then, we investigated how the larval density manipulations on individuals and on group composition affected the strength of sexual selection in females and males.

Predictions Reproduction
• Overall, based on previous literature, we expected large individuals to mate more frequently, obtain more mates and produce more offspring than small individuals

Sexual selection
• We expected female Bateman gradients to be steeper in female mixed size social environments due to the association between body size, number of mates and offspring production. Because this effect relies solely on female's physiological and behavioural traits, we did not predict effects of male body size variation in this pattern.
• We expected male Bateman gradients to be generally positive regardless of male body size. However, we also expected the social environment to modulate the strength of sexual selection on male size both before and after copulation. For instance, we predicted stronger postcopulatory sexual selection on large males in homogenous social environments (where competitors are similarly large and equally good competitors) than in heterogeneous social environments (where large males may outcompete small males). Strong post-copulatory sexual selection may increase ejaculate investment and reduce the benefits of multiple copulations. As a result, we also expected the Bateman gradient of large males to be reduced for large when experiencing homogeneous social environments.
• Finally, when manipulating both sexes body size, we expected to strengthen sexual selection on male size by enabling large males to outcompete small males over large, more fecund females and their eggs, and by enabling large females to outcompete small females over access to large males and their sperm.

Fly stocks and culture
We used a wild-type stock of D. melanogaster that was collected in Dahomey (Benin) in North Africa in 1970 and has been maintained in large (>5,000 individuals) outbred populations in cages with overlapping generations [54]. Focal males were wild-type Dahomey, while competitor males and experimental females carried the recessive sparkling poliert mutation (spa), which had been backcrossed into the Dahomey genetic background for more than 5 generations. The spa mutation produces a rough-looking eye phenotype when homozygous [55] and is commonly used in sperm competition assays to assign paternity (Fricke,Martin [56]). All fly stocks were maintained, and all experiments conducted, at 25°C on a 12:12 light:dark cycle in a nonhumidified room and were fed with standard sugar-yeast-maize-molasses medium with excess live yeast granules.

Larval density manipulation to vary adult body size
Following the protocol of Clancy and Kennington [57], we collected eggs from population cages and pipetted eggs. We used the following densities to manipulate the developmental environment: high density~100 larvae/mL of food (~400 larvae in a 34ml vial containing~4mL fly food), and low density~4 larvae/mL of food (~200 larvae in a 170ml bottle containing~50mL fly food), which generated adult flies of small and large body size, respectively. Using this protocol we previously obtained adult females and males of significantly different and non-  [36]). Using a larger container for the low-density manipulation allowed us to keep the overall population size per container of a similar order of magnitude across the different larval manipulation regimes (i.e. all flies were grown in a container with hundreds of conspecifics) (see [40]). We subsequently refer to the body sizes of adult flies as shorthand for their larval density manipulation: i.e. "large" or "small" to indicate those individuals grown in low and high larval density, respectively. Virgin flies were collected within 8 hours of eclosion and kept in vials of same-sex and same-larval manipulation groups of 15-20 individuals for 2-5 days prior to experiments. In order to track individual flies throughout the behavioural observations we marked all flies of both sexes using 4 colours of acrylic paintwhite, yellow, red and orange-one colour per individual per sex. 24h before experiments began, female flies were randomly allocated to one of these 4 paint colours and were marked on the thorax [58,59]; this was done for females across all treatments. Focal males were painted in half of the vials with white colour and with yellow colour in the remaining half of the vials. The three competitor males were assigned the remaining paint colours. After paint marking, flies were allocated to their experimental groups (see below), and held in single-sex vials prior to the start of experimentation.

Experimental design
Our experimental design for measuring the strength of sexual selection in groups of flies was based on that of Bjork and Pitnick [60]. Briefly, replicate vials contained 4 flies of each sex (i.e. 8 flies per vial) were allowed to interact for 4 hours per day over 4 days, before being discarded. Within each vial, three of the males and all females were spa, and one male-the "focal" malewas wild-type, which allowed us to assign the paternity to the focal male (because spa is recessive). We conducted three experiments to manipulate social environments. We varied: 1) female adult body size, while keeping male size constant (the "Female Experiment"); 2) male adult body size, while keeping female size constant (the "Male Experiment"); and 3) both male and female body size simultaneously (the "Female-Male Experiment", see Fig 1). The Female Experiment-In this experiment, female body size was manipulated while male body size was kept constant (i.e. large body size). The heterogeneous social environment (Het F ) comprised of two large (HetL F ) and two small (HetS L ) females with the four large males. The homogeneous social environment groups consisted of females with constant body size class (i.e. all from the same larval density rearing environments)-i.e. either all large (HomL F ) or all small (HomS F ) females.
The Male Experiment-In this experiment, male body size was manipulated while female body size was kept constant (i.e. large body size). The heterogeneous social environment (Het M ) comprised of two large (HetL M ) and two small (HetS M ) males with the four large females. For the heterogeneous social environments, focal males had small body size in half of the replicates (N = 10) and large body size in the other half (N = 10) of the replicates. The homogeneous social environment groups consisted of males with constant body size class (i.e. all from the same larval density rearing environments)-i.e. either all large (HomL M ) or all small (HomS M ) males.
The Female-Male Experiment-In this experiment, both male and female body size was manipulated. The heterogeneous social environment (Het FM ) comprised of two large males and two large females (HetL FM ) and two small males and two small females (HetS FM ). For the heterogeneous social environments, focal males had small body size in half of the replicates (N = 10) and large body size in the other half (N = 10) of the replicates. The homogeneous social environment groups consisted of males and females with constant body size class (i.e. all from the same larval density rearing environments)-i.e. either all large (HomL M ) or all small (HomS M ) individuals.
Note that HomL F , HomL M , and HomL FM are identical treatments across each experiment, and the label differences simply represent different experiments they were part of (i.e. Female Experiment, Male Experiment, and Male-Female Experiment, respectively). Therefore, throughout our experiments, individuals in the homogeneous environments were exposed to individuals with the same body size of the sex being manipulated, whereas individuals in the heterogeneous environments were exposed to both small and large individuals. We made 20 replicate vials for each heterogeneous social environment (see below), and 10 for each homogeneous social environment group (i.e. 40 vials for each experiment, 120 in total).
We recorded all matings during the 4-hour interaction periods on each of the 4 days of the experiment. Thus, we scored every mating for every individual, allowing us to calculate both the mating frequency and number of mates for each individual. Between interaction periods females were separated from males and placed individually in fresh oviposition vials, and were allowed to lay eggs for twenty hours (i.e. until the interaction period the following day). Flies were discarded in the fifth day. Oviposition vials were retained and all emerging adults were counted after eclosion (13-15 days after the day of oviposition to ensure all flies had sufficient development time) to measure the number of offspring produced by females. Because all females and the three competitor males carried the recessive spa mutation, we could assess the number of offspring sired by focal males: by counting how many offspring were spa and how many were wild-type we could calculate the focal (wild-type) male's paternity share. Paternity share was calculated as the sum of wild-type offspring produced by all the mates of the focal male divided by the total offspring (spa plus wild-type) produced by those females. Because the three competitor males were all spa, we did not have individual paternity data for these malesthus, only the competitor male's paternity share could be measured. We also calculated "per mating" female offspring production as the total number of offspring produced by a female divided by the total number times that female mated. We used female per mating offspring production as an estimate of the expected average reproductive value of each additional mating for males (Note that offspring per mating is not equivalent to the Bateman gradient, which measures the slope of the observed relationship between number of mates and number of offspring-see below).  (3 vials). Males that failed to mate were kept in the analysis because failing to mate is likely a consequence of sexual selection. There were no non-mating females.

Data analysis
The three experiments were conducted independently so we carried out analyses separately for each experiment. Because we had complete paternity data for one focal male per replicate group (see methods above), whereas we had data for every female in each replicate group, the analyses were also conducted separately for each sex. Therefore, for males, we used the single focal individual per vial as the unit of replication, whereas for females we analysed data from all individuals but included the vial as a covariate in all models, to account for pseudoreplication. We first characterised the effects of developmental environment on female and male reproductive traits, and subsequently measured the effects on sexual selection.
Male and female reproductive trait analyses. First we investigated the potential effects of female deaths ("DF", dead females) on the results. We pooled the data of our three experiments and created a binary variable DF, which contained information on the occurrence (value = 1) or not (value = 0) of a female death in the social environment of a particular individual. A significant effect of DF means that the death of an experimental female increased or decreased reproduction of the remaining individuals in that social group. We used quasipoisson GLMs, which account for overdispersion of the data, to evaluate whether DF had a significant effect on the number of mates, mating frequency and number of offspring of both females and focal males. There was a significant effect of DF on focal male estimates of number of mates and offspring (see 'S1 Text') and, therefore, DF was retained in all analyses of focal male reproduction and sexual selection. Then, we tested for the effect of paint marking, but found no effect of colours on either females or focal male reproduction (see 'S1 Text'); we therefore excluded colours from the final analysis.
We then focused on both females and focal male reproduction. We used generalised linear models (GLM) (family = 'quasipoisson') to test for differences between levels (see below) in male and female mating frequencies and mate numbers, in the number of offspring produced by females, and in female per mating offspring (the number of offspring produced by a female divided by the number of times that female mated). We used a 'quasibinomial' GLM to investigate the average proportion of offspring sired by a focal male. In our models, the explanatory variables were social environment ("social", which was either homogenous or heterogeneous: see experimental design above), the body size of the sex under consideration, and the interaction between social environment group and body size (i.e. social Ã body size) whenever the sex under consideration varied in body size (i.e. females in the Female Experiment, males in the Male Experiment, and both sexes in the Female-Male Experiment). If the sex being analysed did not vary in body size (i.e. males in the Female Experiment, females in the Male Experiment), we used GLMs with "social" environment treated as the variable with three levels (e.g. Hom L , Hom S and Het). For models in which "social" was the explanatory variable with three levels and the analysis showed p-value 0.05, we performed a post-hoc "SNK-test" to investigate the difference between the means of the three levels [61]. P-values are based on F-statistics for all GLM models.
Sexual selection analyses. For females, we measured the strength of sexual selection on mate number, as β, the slope of a linear regression of standardised offspring number (T) on standardised number of mates (M): We standardised T by dividing the offspring number of each individual by the mean number of offspring produced by all members of that sex in the group (to give relative reproductive success; see Arnold 1994). Similarly, we standardised M as the following: we subtracted the mean number of mates of all individuals of that sex in the group from the number of mates of each individual, and divided the resultant value by the standard deviation of the number of mates of all individuals of that sex in the group. In doing so, we scaled M to have a mean of zero and a standard deviation of unity and T to have a mean of 1 (Arnold 1994). We also investigated quadratic effects (see S1 Text) on female Bateman gradients [12] because T might peak at a given number of males mated followed by a plateau or decline (Jones 2009). Whenever the quadratic term was non-significant, it was removed from the analysis.
For males we first characterised sexual selection in a qualitative way, by decomposing variance in T as follows: where M ; P, and N are the mean values of M, P (average paternity share) and N (average number of adult offspring produced by a male's mates), and D includes the variance in the error term ε [11,15,62]. This approach enables us to measure the relative contributions of M, P and N and their covariances to T (see [11,28]). We also used commonality analysis (CA) [63], which decomposes the explained variance of the multivariate linear model (see below) into percentage of variance explained by one (i.e. unique explained variance) or a set of variables (i.e. common explained variance) [64,65], to explore the relative contributions of M, P, N, and their covariate to variation in the number of offspring sired by males (see S1 Text).
Although the decomposition of variances is useful to make qualitative comparisons across social treatments, the quantitative interpretation of variances and covariances can be difficult [66]. To overcome this limitation, we measured linear selection gradients on male M, P and N using a multivariate model based on Eq 1, which was composed of T (dependent variable), M, P and N (independent variables) as well as "total vial productivity" (VP), which accounted for differences in within-vial offspring productivity, and DF, which accounted for female deaths in the social environment (see above). The model was (in 'R' notation): where st() indicates the standardised values of the variables T, M, P and N (see above). This multivariate approach allowed us to investigate the effects of the larval manipulation on the Bateman gradient (i.e. gradient of T regressed over M, controlling for all covariates), the paternity share gradient (i.e. gradient of T regressed over P, controlling for all covariates) and the mate productivity gradient (i.e. T regressed over N, controlling for all covariates). We standardised P and N in the multivariate model dividing P and N of each individual focal male by the mean number of P and N of all focal males in the group, respectively. For both males and females we first tested whether the Bateman gradients of the homogenous and heterogeneous groups significantly differed from 0 in each experiment. We also analysed the gradients of small and large flies within heterogeneous groups (e.g. Het F , Het M , Het FM ) separately. This allowed us to determine whether selection was acting differently on small versus large flies within heterogeneous groups. For males we additionally tested paternity and mate productivity gradients, using the same approach as for Bateman gradients above (i.e. for both homogenous and heterogeneous groups, and for small and large males separately in heterogeneous groups). Finally, we tested the influence of the social environment by comparing the selection gradients on small and large individuals in homogenous versus heterogeneous groups. To do this we fitted a multivariate linear model for large and small individuals separately that included interaction terms of M, P and N and social environment composition (SEC) (i.e. M Ã SEC, P Ã SEC and N Ã SEC), in addition to our covariates of VP and DF. We present p-values from t-statistics for all multivariate linear models. All analyses were performed using the R software (version 3.0.2, [67]).

Patterns of female reproduction
Large adult females (those reared at low larval density) mated significantly more frequently, mated with significantly more mates, and produced significantly more offspring, than small females (those reared at high larval density) across all experiments in which female body size was manipulated (i.e. Female Experiment and Female-Male experiment) ( Table 1 , Fig 2A-2F,  S1 Fig). Large females had higher offspring per mating in the Female Experiment (i.e. where female body sized varied), but this difference was absent in the Female-Male Experiment (where both sexes varied in body size; Table 1, Fig 2G-2I). Social environment (i.e. homogenous or heterogeneous) affected female mating behaviour in the Female Experiment, where females in the homogeneous social environment mated significantly more frequently, and with more mates, than females in heterogeneous environment (Table 1 , Fig 2A, S1 Fig).
The social environment also affected female offspring production in the Male Experiment, where females in the heterogeneous male size environment (i.e. exposed to large and small males) produced significantly fewer offspring than females in a homogeneous male social environment (i.e where all males were had large body size; Table 1, Fig 2B, post-hoc SNK test HomL > HomS > Het (α = 0.05))). We also found a significant interaction between social environment and female body size (i.e. social Ã body size) on female mating frequency in the Table 1. Development effects on reproduction. Analysis of focal male and female mating frequency, number of mates, absolute offspring production, proportion of focal male's offspring production and female per-mating offspring production. Female Experiment, which was driven by a stronger reduction in mating frequency for small females in heterogeneous social environments relative to homogeneous social environments ( Table 1, Fig 2A). We did not detect an effect of social environment or an interaction between social environment and body size on offspring production or offspring per mating of females in the Female Experiment, or on mating frequency, number of mates, or offspring per mating in the Male Experiment, or on any of the reproductive measures in the Female-Male Experiment ( Table 1). The exclusion of a single female in the Female Experiment that mated but did not produce offspring does not qualitatively change the results except for total offspring production, in which the interaction term social Ã body size, that was marginally non-significant (p = 0.081), becomes significant (p = 0.024). This result would indicate that the reduction in Developmental Environment Effects on Sexual Selection offspring production in the heterogeneous groups was stronger for small than for large females.

Sexual selection on females
Female Bateman gradients did not significantly differ from zero for most female groups, with the following exceptions. The two heterogeneous environments in which female body size varied were significantly positive (i.e. Het F and Het FM , where both small and large females are considered as a single population). Also, HetS in the Female-Male Experiment (small females in the heterogeneous group, considered separately from large females), and HomL in the Male Experiment (large females with large males) were significantly positive (see Table 2 & S2 Table; Figs 3 & S2 and S1 Table). We then tested whether the Bateman gradient of large and small females in heterogeneous social environments significantly differed from the Bateman gradient of large and small females in homogeneous social environments (Female and Female-Male Experiments), and found no significant differences (Fig 3, Table 2, S2 Table). The exclusion of a single female in the HomS F group that mated but did not produce any offspring does not qualitatively change the results.

Patterns of male reproduction
The social environment affected the number of offspring sired by focal males in the Female Experiment with males producing more offspring in the HomL than in the Het followed by the HomS groups (post-hoc SNK test, α = 0.05), and in the Female-Male experiment with focal males in homogeneous groups producing more offspring than focal males in the heterogeneous group (Table 1, Fig 4D). Focal male mating frequency, number of mates or proportion of offspring sired across did not significantly differ with social environment in any experiment ( Table 1, Fig 4A-4F, S4 Fig). In the Male Experiment, the proportion of offspring sired by large males (i.e. reared at low larval density) was significantly higher than for than small (high larval density) males (Table 1, S5 Fig). We found a significant interaction between social environment and focal male body size (i.e. social Ã body size) on focal male mating frequency, the proportion of offspring sired by focal males, and on the total number of offspring sired by focal males in the Male Experiment: small focal males in a heterogeneous social environment mated less frequently and sired fewer offspring than small males in a homogenous social environment ( Table 1, Fig 4B and 4E, S5 Fig). We did not detect an effect of body size or the interaction body size and social environment in any of the focal male reproductive measures in the Female-Male Experiment ( Table 1). The exclusion of one male in HomS F and one male in HomL M that failed to obtain any mates changes the analyses for number of offspring: the effect of social environment became non-significant in the Female Experiment (the p-value changed from 0.046 to 0.068) and, the interaction social Ã body size of the focal male on the number of offspring sired by males in the Male Experiment becomes marginally non-significant (p = 0.061) where it had previously been significant (p = 0.033).

Sexual selection on males
Firstly, we applied Eq 3 to investigate the relative contribution of male mate number (M), paternity share (P), mate productivity (N) and their covariances in explaining variance in offspring sired (T). Overall, variance in P explained the largest proportion of variance in T, followed by variance in M and the covariance between M and P ( Table 3, see Methods). We then qualitatively investigated whether the social environment changed the relative contributions of M, P, N and their covariates. The decomposition of the variance in T for large and small focal    male in a heterogeneous social environment had broadly the same characteristics of the decomposition of variance in T for focal males in a homogeneous social environment-i.e. variation in T was largely explained by variance in P followed by variation in M and the covariance between M and P (Table 3). A Commonality Analysis (CA), which uses an alternative method to decompose variance in T, qualitatively supports the overall contribution of variances and covariances related to M, P and N for male reproduction (S3 Table). We then used a predictive multivariate linear model (Eq 4) to test whether the slope of the gradient of a focal male's offspring number regressed over mate number (M), paternity share (P), and mate productivity gradients (N) controlling for the other gradients were influenced by our social manipulations. First, we tested whether the focal male multivariate M, P and N gradients were significantly different from zero in the homogenous and heterogeneous groups. Significantly positive multivariate M gradients (Bateman gradients) were observed for large males in the HomS F group of the Female Experiment (where large males were exposed to small females), for small males in the HomS M group of the Male Experiment (where small males were exposed to large females), and in all groups of the Female-Male Experiment (i.e. HomL FM , HomS FM and Het FM ; Table 2; Fig 5A-5I). However, multivariate M gradients were positive but not significantly different from zero in the HomL F group of the Female Experiment (where large males were exposed to large females), in the Het F group of the Female Experiment (where large males were exposed to females of mixed body sizes), and in the Het M group of the Male Experiment (where mixed size males were exposed to large females) ( Fig 5A, Table 2, S6 Fig).
Multivariate M gradient did not show a positive trend in the HomL M group of the Male Experiment (where large males were exposed to large females; see Fig 5A, Table 2, S6 Fig). Multivariate P gradients were highly significant in all social environment manipulations except HomS F ( Table 2). Significantly positive multivariate N gradients were limited to HomL F , HomS M , Het M , and HomS FM ( Table 2).
We next investigated whether M, P and N gradients were altered when focal males of different body sizes experienced a heterogeneous versus a homogenous social environment. We did not find a significantly greater than zero M gradients for either large or small focal males in a heterogeneous environment of the Male Experiment (i.e. HetL M and HetS M ). However, the M gradient was significantly greater than zero for both large and small focal males of the Female-Male Experiment (i.e. HetL FM and HetS FM ; Table 2

Var-Cov Components
Observed contribution to var(T) Male Experiment, and was significantly positive for both large and small focal males in a heterogeneous environment of the Female-Male Experiment ( Table 2). Multivariate N gradients were not significantly different from zero for small or large males in any of the heterogeneous groups (Table 2). We then compared M, P and N gradients of large and small males in a heterogeneous environment (considering each size class separately) with the gradients of large and small males in a homogeneous environment, respectively. We found for small focal males that both M and N gradients were strongly reduced in a heterogeneous social environment of the Female-Male  Table 2 & S2 Table). These effects were not observed for either small focal males of the Male Experiment (HetS M ) or large focal males of both Male and Female-Male Experiments, where M, P or N did not significantly differ between heterogeneous and homogeneous social environments (Table 2, S2 Table).

Discussion
• We confirmed our predictions that larval density generate large body sized individuals that are more successful in obtaining mates and matings as well as producing offspring.
• We confirmed that the positive relationship between the number of mates and offspring of females arise from differences in female body size (and total productivity) in a group. This result highlights the potential for misleading interpretations of a positive female Bateman gradient.
• We partially confirmed our expectations of an overall positive Bateman gradient for both large and small males, although this was not true for all treatments.
• We found that, in a mixed environment where both sexes varied in body size, neither female body size nor social environment affected the number of offspring per mating produced by females. This finding may open a new perspective on the evolution of male mate choice by showing that males do not necessarily gain additional offspring from mating with large (more fecund) females.
• We also found that small, but not large focal males have a significantly reduced Bateman gradient and partner fecundity gradient in a mixed social environment when both sexes varied in body size, suggesting that small individuals suffer costs from competing with large individuals.
Below, we discuss the main findings of our study in detail.

Sexual selection in females
Our data suggest that the larval environment experienced by individuals within groups can influence adult Bateman gradients in female D. melanogaster. For instance, we found that the Bateman gradients were significantly positive in heterogeneous social environments whereas gradients were less steep, and not significantly different from 0 in most (though not all) homogenous social environments (Table 2, Fig 3). As predicted, the steep Bateman gradients in heterogeneous social environments likely arise as a consequence of associations between larval density effects on the number of offspring produced by adult females (likely linked to body size), and their mating frequency. As expected, females grown at high larval density eclose smaller, produce fewer offspring, and have lower mating frequencies relative to females grown at low density (i.e. large adult females). Thus, in populations containing both large and small females, there is inevitably a correlation between mate number and number of offspring produced, which is ultimately driven by differences in the larval environments. This idea is supported by the fact that, when we compared the heterogeneous social environment Bateman gradients for small and large females considered separately, we did not see significant differences from small and large females in homogeneous social environments. This suggests that it is the heterogeneity of females per se, not changes in selection on small and large females that generates the positive Bateman gradients. In other words, the positive female Bateman gradients in heterogeneous groups are an emergent property of the heterogeneity in larval conditions experienced by female individuals within the group. Our results therefore highlight the fact that Bateman gradients should be interpreted cautiously as a measure of sexual selection on mate number in females, because the correlation between number of offspring produced and number of mates does not necessarily reflect causality [12,16,18,24,29,30,68,69]. We also saw unexplained variation in Bateman gradients between experiments. For example in the HomL group of the Male Experiment the Bateman gradient was significantly different from 0, but in the Female or Female-Male experiments HomL was much less steep, and not significantly different from 0, despite the fact that all HomL groups were treated identically. Thus, we should exhibit some caution when interpreting the data.

Sexual selection in males
Our results suggest a complex architecture of male reproductive success, and highlight the importance of decomposing the offspring number sired by males into its M, P and N components [6,[11][12][13]28]. For example, the covariance between M and P was mostly positive across experiments (except in the HomL FM and HomS FM ), which suggests that males that mate with more females obtain higher paternity share with their mates (Table 3). Conversely, a negative covariance between M and P (as in HomS FM and HomL FM ) reflects a potential trade-off between pre-and post-copulatory success, in which males that attract more mates are poor post-copulatory competitors (Table 3). Whilst males are expected to gain from additional mates, the primary mechanisms by which males gain fitness might in some cases be via mate choice for high productivity females (but see below), or via success in post-copulatory competition, and these traits may or may not be correlated with pre-copulatory success (Table 2) [11,12,70]. Our finding that P explains a large proportion of variance is broadly consistent with the findings in other promiscuous species such as the red jungle fowl Gallus gallus [11,12], guppies Poecilia reticulata [71] and the hermaphrodite snail Physa acuta [28]. However, it is important to interpret our results for P with caution. For instance, in a study on semelparousadapted D. melanogaster population-which was cultured each generation with a single short reproductive bout-most post-copulatory success was explained by last male sperm precedence, leaving only a further~2% of variance in reproductive success explained by additional postcopulatory processes [72,73]. This previous study show that last male precedence can significantly contribute to the overall strength of post-copulatory sexual selection, and could be a confounding effect when analysing post-copulatory processes (P). Other mechanisms that might also contributes to variance in P include cryptic female choice [74] and sperm viability [26,75,76], which skew male fertilization success similar to male precedence. Interestingly, however, Pischedda and Rice [73] showed that the total variance in male reproductive success explained by either general post-copulatory processes or by post-copulatory processes after controlling for male precedence was the same, suggesting that male precedence is a component of, instead of additional to, P (see Fig 2 in [73]). Thus, it is unlikely that considering male precedence (or other processes) would explain additional variance than that already captured by P and, consequently, it would not alter the relative contributions of M and N. Therefore, although male precedence, female cryptic choice and sperm viability are important, their relative contributions to the variance in P lie outside the scope of this paper and should be the focus of future analysis. It will also be particularly informative for future studies to determine how much lastmale sperm precedence explains post-copulatory success in other iteroparous populations.
We found that small males in groups consisting of both males and females from different larval densities (i.e. the heterogeneous group in the Female-Male Experiment.) had significantly reduced Bateman and mate productivity gradients relative to small males in the homogeneous social environment (Table 2, Fig 5). This suggests that the operation of sexual selection-the benefits of obtaining multiple mates, and obtaining mates of high productivityare modified for small males when in the presence of large males and a mix of female phenotypes. This is likely explained by a combination of factors. When in competition with large males, small males have a lower share of paternity because they are outcompeted over access to females and possibly because females favour inseminations by large males during or after mating. Such loss of paternity would erode the benefits of mating with multiple females [77], thus weakening the Bateman gradient of small males. These factors may also mean that small males may have a relatively higher share of paternity with smaller, less fecund females leading to weaker gradients of sexual selection on mate productivity and the large negative covariance between N and P found in small males in the HetS FM treatment (Table 3).
Our results-and previous studies-show that D. melanogaster males who experience favourable developmental environments, that lead to large adult size, display higher success in pre and post-copulatory competition (Fig 4A-4C, Table 2) [30,46]. Large adult males can obtain higher proportion of offspring for several reasons: they may be able to either monopolize most of the mates, elicit mating behaviour more frequently or effectively [46], win sperm competition, or be preferred in cryptic female choice [29]. Moreover, the larval developmental environment influences ejaculate investment, whereby males with small body size invest relatively more ejaculate to each mating relative to large males [36]. Thus, small males experiencing a heterogeneous environment might have adjusted their behaviour to accommodate the competition with large males, leading to an alternative path to reproductive success.
Variation in female productivity is expected to be a major driving force in the evolution of male mate choice, and current theory predicts that male mate choice for large adult females should evolve because large females produce more eggs (reviewed by Bonduriansky [26]). In D. melanogaster, some studies indicate that males preferentially court large, highly fecund females [43,48] to gain fitness as a consequence of mate choice [78]. However, other studies suggest that male D. melanogaster can prefer small females, raising questions over the consistency of male preferences [78,79]. We found that the number of offspring that a female produced per mating was not higher for large (low larval density) females when both sexes varied in size (The Female -Male Experiment, Fig 2G-2I). Large females remate more frequently [29,36] meaning that sperm competition may be more intense for mates of large females, potentially offsetting the benefits of mating with high fecundity large females. The positive correlation between developmental environment-induced changes in body size and productivity [26] may mean that large females are more receptive to mating simply because they require greater quantities of ejaculate in order to fertilize the large number of eggs that are produced [80]. Similarly, large females may have lower sensitivity to male receptivity-inhibiting seminal proteins resulting in a more rapid return to receptivity. In addition, the low larval density might have served as cue of low mating opportunities, hence priming females to have higher receptivity (or lower resistance) to matings [36]. Males might prefer and target large females simply because large females are more willing to remate, or represent larger and slower targets for courtship. The idea that males do not always gain an advantage by mating with large females has received empirical support in the golden-orb web spider Neuphila plumipes, in which males changed their mate preference as the levels of intrasexual competition increased, but not necessarily targeted larger females [81]. Thus, male mate preference can be thought of as analogous to the Ideal-Free Distribution Model (IFD) where females are seen as patches and males tend to distribute themselves according to "female's quality" [81]. Therefore, male choice for large females might arise because body size is correlated with the rate of egg production, not just total egg production, in which fast reproduction is likely beneficial in stable and expanding populations [35,82].
In conclusion, our results suggest that the developmental environment can influence the operation of sexual selection during adulthood. Our study also adds to the growing body of evidence that shows the importance of considering more than simply the number of mates and offspring in measures of the strength of sexual selection on males [11][12][13]. Key questions for future studies include 1) how commonly does variation in female developmental environment or adult condition generate positive associations between mate and offspring number? 2) Do males often gain similar numbers of progeny per mating from low and high condition females? 3) How commonly do environmental conditions influence the benefits of additional mates for males? 4) To what extent do mechanisms other than mate number (e.g. paternity share) explain variation in the number of offspring sired by males?