DOI: 10.5061/dryad.cnp5hqcg5
title: Simulating contests to determine the relative importance of correlated traits on the winning chances

description: In intraspecific agonistic interactions, it is expected that traits that
 are more important in determining the winning chances should exhibit
 greater differences between winners and losers than traits that are less
 important. However, several of the traits used to determine the winning
 chances are correlated. When these traits vary in their importance to win,
 it becomes hard (if not impossible) to disentangle an effect due to trait
 correlation from the true effect of each trait on winning. To test the
 impact of trait correlation on the relative importance of each trait on
 winning chances, we developed an individual-based simulation model that
 investigates how different values of trait correlation and the relative
 importance of each trait impact the expression of trait differences
 between winners and losers. The simulation was made in R and generates
 traits according to a normal distribution. Traits are correlated with each
 other through the function rnorm_multi. In each iteration, the values are
 generated from scratch. Through many simulations, we see the same patterns
 emerge. We hypothesized that less important traits may show smaller
 winner-loser differences than more important traits for small trait
 correlation values. Surprisingly, we found that the most important trait
 for winning had a detectably larger difference between winners and losers
 than the less important trait for strong correlations (up to 0.9). Also,
 for correlation values around 0.5, it was harder to detect the difference
 between winners and losers, even for the trait that was more important in
 determining victory. We provide a suggested guide on how the patterns
 obtained in our model may be used to identify the relative importance of
 correlated traits on winning chances in empirical studies.
description: #### The stochastic model of agonistic interactions regarding `code1.R`
 This is an individual-based simulation model, in which we establish
 scenarios combining different levels of correlation between attributes and
 their relative importance in determining Fighting Capacity. This model was
 used to investigate emerging patterns of differences between winners and
 losers for each attribute involved in the fight. The correlated attributes
 used to exemplify the system were **body size** and **weapon size**. ---
 #### Setting up the environment These packages were used: * `faux` *
 `dplyr` * `tidyverse` * `boot` * `sciplot` * `ggplot2` * `ggthemes` *
 `devtools` --- #### Main function The main function is called
 **`simulation`**. Its parameters are: * `cor.weapon.body`: the value of
 the correlation between the traits weapon and body * `weapon.imp`: the
 relative importance of the weapon size trait for the chance of winning a
 contest * `body.imp`: the relative importance of the body size trait for
 the chance of winning a contest. Since this is a consequential value of
 `weapon.imp`It is calculated within the function. --- #### Inside the
 function The following empty vectors will store the corresponding data: *
 `mean.body.win`: the mean of the body size values of the individuals that
 won * `mean.body.los`: the mean of the body size values of the individuals
 that lost * `mean.weap.win`: the mean of the weapon size values of the
 individuals that won * `mean.weap.los`: the mean of the weapon size values
 of the individuals that lost * `body.diff`: the difference between the
 mean body size of winners and losers * `weap.diff`: the difference between
 the mean weapon size of winners and losers --- #### Creating Individuals *
 `group.1` and `group.2` These are objects that store two sets of data. The
 `rnorm_multi` A function is used to create two correlated normal
 distributions. * The correlation value is set outside the function. * One
 distribution represents **body size**, the other **weapon size**. *
 `data.1` Is the data frame where the information is stored? * `group.1`
 and `group.2` are added to the data frame so each individual's body
 and weapon size is in a separate column. --- #### Simulate fight Each row
 of `data.1` represents a fight between a pair of individuals. *
 `data.1$FC.1` and `data.1$FC.2`: columns that store the Fighting Capacity
 of individuals from `group.1` and `group.2` * `data.1$FCdiff`: the
 difference between the Fighting Capacity of `group.1` and `group.2` *
 `data.1$prob.win.cont`: probability (between 0 and 1) of the individual
 from `group.1` winning the fight --- #### Determine winner *
 `data.1$prob.win`: stores a value of `1` or `0` depending on the win
 probability * A value of `1` means the individual from `group.1` won; a
 value of `0` means the individual from `group.2` won --- ### Store data
 about winners and losers * `data.1$win.body`: stores the body size of the
 winner * If `prob.win` is `1`, it uses `group.1`; otherwise, `group.2` *
 `data.1$los.body`: stores the body size of the loser * The opposite of the
 winner's source group * `data.1$win.weap`: stores the weapon size of
 the winner * If `prob.win` is `1`, it uses `group.1`; otherwise, `group.2`
 * `data.1$los.weap`: stores the weapon size of the loser * The opposite of
 the winner's source group --- #### Determine differences between
 winners and losers * `data.1$diff.body`: stores the difference in body
 size between the winner and the loser * `data.1$diff.weap`: stores the
 difference in weapon size between the winner and the loser --- #### Means
 The following lists store the mean values from each iteration of the loop:
 * `mean.body.win[m]`: mean body size of winners * `mean.body.los[m]`: mean
 body size of losers * `mean.weap.win[m]`: mean weapon size of winners *
 `mean.weap.los[m]`: mean weapon size of losers * `body.diff[m]`: mean
 difference in body size between winners and losers * `weap.diff[m]`: mean
 difference in weapon size between winners and losers --- #### The for loop
 ends here Means and Confidence Intervals * `mean.mean.body`: mean across
 iterations for body size differences * `mean.mean.weap`: mean across
 iterations for weapon size differences * `body.mean.CI`: confidence
 interval for body size difference * `weap.mean.CI`: confidence interval
 for weapon size difference * `data.2`: the return object from the
 simulation function. It includes: * `mean.mean.body` * `mean.mean.weap` *
 `body.mean.CI` * `weap.mean.CI` #### The simulation function ends here
 **Applying the simulation function** * `func.values` is an empty vector
 used in the loop to store output values * The loop index `i` ranges from
 80 to 99 * Each `i` is divided by 100, resulting in correlation values
 from 0.80 to 0.99 (incremented by 0.01) * The `weapon.imp` The parameter
 can be adjusted, but in this example, it is set to `0.5` --- #### Organize
 data for the figure * `treatments`: a list of labels (`mean.mean.body`,
 `mean.mean.weap`, `body.mean.CI`, `weap.mean.CI`) repeated 20 times (for
 the 20 simulations) * `correlations`: labels for the correlation values
 corresponding to each output * `data.mix`: a new data frame that combines
 the labels and their respective outputs * `data.fig`: a similar data frame
 where confidence intervals are moved to their own column to support figure
 creation