Title: | Inferring Longitudinal Dominance Hierarchies |
---|---|
Description: | Provides functions for inferring longitudinal dominance hierarchies, which describe dominance relationships and their dynamics in a single latent hierarchy over time. Strauss & Holekamp (in press). |
Authors: | Eli D. Strauss |
Maintainer: | Eli D. Strauss <[email protected]> |
License: | GPL-2 |
Version: | 1.1.0 |
Built: | 2025-02-21 05:00:19 UTC |
Source: | https://github.com/straussed/dynarankr |
Data structures for inferring the ranks of adult female spotted hyenas (Crocuta crocuta) from a single social group in the Maasai Mara National Reserve in southern Kenya. Data are from the Talek clan collected between 1988 and 1995 by the Mara Hyena Project.
C.crocuta.female
C.crocuta.female
List of 3 elements:
Starting order of females in 1988.
Dataframe of 182 rows and 4 variables. There is one row per female per study year. id is the identity of the contestant. period is the study year. convention1 is the mother of the contestant, because female spotted hyena hierarchies are structured by maternal rank inheritance. convention2 is the intra-litter rank for contestants who were part of a twin litter.
Dataframe of 2043 rows and 3 variables. Each row corresponds to the outcome of one aggressive interaction between adult females.
Data structures for inferring the ranks of adult male spotted hyenas (Crocuta crocuta) from a single social group in the Maasai Mara National Reserve in southern Kenya. Data are from the Talek clan collected between 1988 and 1995 by the Mara Hyena Project.
C.crocuta.male
C.crocuta.male
List of 3 elements:
Starting order of males in 1988.
Dataframe of 143 rows and 3 variables. There is one row per male per study year. id is the identity of the contestant. period is the study year. convention1 is the date that the male joined the clan, because male spotted hyena hierarchies are structured by a tenure-based convention.
Dataframe of 474 rows and 3 variables. Each row corresponds to the outcome of one aggressive interaction between adult males.
This function compares two rank orderings that have the same elements. For an order of length n there are n choose 2 dyadic relationships implied by that order. For example, the order a, b, c implies that a > b, a > c, and b > c. The dyadic similarity between two orders is the proportion of implied dyadic relationships that are shared by the two orders.
dyadic_similarity(order1, order2)
dyadic_similarity(order1, order2)
order1 |
The first rank ordering to be compared. Alternatively, this can be supplied as an interaction matrix with identities as the dimension names. All identities in order1 must be in order2. |
order2 |
The second rank ordering to be compared. Alternatively, this can be supplied as an interaction matrix with identities as the dimension names. All identities in order2 must be in order1. |
The proportion of dyadic relationships that are shared by the two orders. This value is 1 if the orders are identical and 0 if the orders are exact opposites.
dyadic_similarity(letters[1:20], letters[1:20]) #identical orders dyadic_similarity(letters[1:20], letters[20:1]) #opposite orders dyadic_similarity(sample(letters[1:20]), sample(letters[1:20])) #random orders
dyadic_similarity(letters[1:20], letters[1:20]) #identical orders dyadic_similarity(letters[1:20], letters[20:1]) #opposite orders dyadic_similarity(sample(letters[1:20]), sample(letters[1:20])) #random orders
This function converts data in edgelist format to an interaction matrix.
edgelist_to_matrix(edgelist, identities)
edgelist_to_matrix(edgelist, identities)
edgelist |
A two column matrix or dataframe with the identities of winners in the first column and losers in the second column. |
identities |
A list of contestant identities. This list dictates the order in which contestants are arranged in the resulting matrix. |
Produces an interaction matrix with winners in the rows and losers in the columns. Contestants are arranged according to the order specified by identities.
edges <- C.crocuta.female$interactions[C.crocuta.female$interactions$period == 1989,1:2] ids <- C.crocuta.female$contestants[C.crocuta.female$contestants$period == 1989,'id'] edgelist_to_matrix(edgelist = edges, identities = ids)
edges <- C.crocuta.female$interactions[C.crocuta.female$interactions$period == 1989,1:2] ids <- C.crocuta.female$contestants[C.crocuta.female$contestants$period == 1989,'id'] edgelist_to_matrix(edgelist = edges, identities = ids)
Calculates hierarchy dynamics from an inferred longitudinal hierarchy, returning the provided longitudinal hierarchy with added columns. The function calculates hierarchy dynamics for each individual in each period (excluding the first period). Dynamics can be calculated in rank units or score units by specifying the type parameter. Rank dynamics are returned as the total dynamics (delta), active dynamics (delta.active), and passive dynamics (delta.passive). Score dynamics are calculated as delta. See Strauss & Holekamp (in revision) for more details.
get_dynamics(ranks, type = c("rank", "score"))
get_dynamics(ranks, type = c("rank", "score"))
ranks |
A dataframe such as the output of the ranking functions provided in the DynaRankR package. Should include at least the following columns:
|
type |
A character string, either 'score' or 'rank'. Determines whether rank dynamics or score dynamics are calculated. |
Returns the supplied dataframe with new column(s) for hierarchy dynamics. New individuals receive NA for all dynamics because they can not have undergone any changes.
Strauss ED & Holekamp KE (in revision). Journal of Animal Ecology.
female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) female.ranks.score <- get_dynamics(ranks = female.ranks, type = 'score') female.ranks.rank <- get_dynamics(ranks = female.ranks, type = 'rank')
female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) female.ranks.score <- get_dynamics(ranks = female.ranks, type = 'score') female.ranks.rank <- get_dynamics(ranks = female.ranks, type = 'rank')
This function converts data in an interaction matrix to edgelist format.
get_edgelist(mat)
get_edgelist(mat)
mat |
Interaction matrix containing outcomes of interactions. Dimension names are interpreted as individual identities. |
A two-column dataframe with winners in the first column and losers in the second column.
edges <- C.crocuta.female$interactions[C.crocuta.female$interactions$period == 1989,1:2] ids <- C.crocuta.female$contestants[C.crocuta.female$contestants$period == 1989,'id'] mat <- edgelist_to_matrix(edgelist = edges, identities = ids) get_edgelist(mat)
edges <- C.crocuta.female$interactions[C.crocuta.female$interactions$period == 1989,1:2] ids <- C.crocuta.female$contestants[C.crocuta.female$contestants$period == 1989,'id'] mat <- edgelist_to_matrix(edgelist = edges, identities = ids) get_edgelist(mat)
Use David's Score method to infer a dominance hierarchy over multiple study periods. New contestants are added according to the convention specified by the user. Scores are calculated using Dij and are normalized. Full description of the addition of new individuals is described in Strauss & Holekamp (in revision). To run the original David's Score procedure, use convention flag 'none'.
informed_ds(contestants, convention, initial.ranks = NULL, interactions)
informed_ds(contestants, convention, initial.ranks = NULL, interactions)
contestants |
A dataframe with the identities of the contestants for each study period along with the relevant data for adding them to the hierarchy. There should be one row per contestant per study period. Periods should appear in chronological order. The dataframe should contain the following columns:
|
convention |
A flag determining how new individuals are added to the hierarchy. The value of this flag influences how the convention1 and convention2 columns of the contestants argument are interpreted. Currently this function supports five options:
|
initial.ranks |
The initial ordering of individuals for the first study period. Required if using maternal rank inheritance as the convention. For other conventions, if initial.ranks is not specified, the order determined by convention1 is used to create the initial order. |
interactions |
A dataframe of interaction data with the following columns:
|
Produces a dataframe with the following columns:
Study period.
Identity of contestant.
David's Score of contestant.
Ordinal rank of contestant in study period. Lower numbers equal higher rank.
Rank of contestant standardized for group size. Values range from 1 (highest rank) to -1 (lowest rank).
Identity of contestants arranged in the previous order (the order they were in before updating the order based on observations from the current study period).
Strauss ED & Holekamp KE (in revision). Journal of Animal Ecology.
de Vries H, Stevens JMG, Vervaecke H (2006). Animal Behavior.
##Informed ds female.ranks <- informed_ds(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) ##Standard ds female.ranks <- informed_ds(contestants = C.crocuta.female$contestants, convention = 'none', interactions = C.crocuta.female$interactions)
##Informed ds female.ranks <- informed_ds(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) ##Standard ds female.ranks <- informed_ds(contestants = C.crocuta.female$contestants, convention = 'none', interactions = C.crocuta.female$interactions)
Use Elo-rating method to infer a dominance hierarchy over multiple study periods. New contestants are added according to the convention specified by the user. Full description of the addition of new individuals is described in Strauss & Holekamp (in revision). To run the original Elo-rating procedure, use convention flag 'none'.
informed_elo( contestants, convention, K = 200, lambda = 100, initial.ranks = NULL, interactions )
informed_elo( contestants, convention, K = 200, lambda = 100, initial.ranks = NULL, interactions )
contestants |
A dataframe with the identities of the contestants for each study period along with the relevant data for adding them to the hierarchy. There should be one row per contestant per study period. Periods should appear in chronological order. The dataframe should contain the following columns:
|
convention |
A flag determining how new individuals are added to the hierarchy. The value of this flag influences how the convention1 and convention2 columns of the contestants argument are interpreted. Currently this function supports five options:
|
K |
Parameter influencing the magnitude of score changes after each outcome. |
lambda |
Parameter influencing the shape of the logistic function linking the difference in score between winner and loser to the expected probability of each contestant winning. |
initial.ranks |
The initial ordering of individuals for the first study period. Required if using maternal rank inheritance as the convention. For other conventions, if initial.ranks is not specified, the order determined by convention1 is used to create the initial order. |
interactions |
A dataframe of interaction data with the following columns:
|
Produces a dataframe with the following columns:
Study period.
Identity of contestant.
Elo-rating score of contestant.
Ordinal rank of contestant in study period. Lower numbers equal higher rank.
Rank of contestant standardized for group size. Values range from 1 (highest rank) to -1 (lowest rank).
Identity of contestants arranged in the previous order (the order they were in before updating the order based on observations from current study period).
Strauss ED & Holekamp KE (in revision). Journal of Animal Ecology.
Albers PCH & de Vries H (2000). Animal Behavior.
##Informed elo female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) ##Standard elo female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'none', interactions = C.crocuta.female$interactions)
##Informed elo female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) ##Standard elo female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'none', interactions = C.crocuta.female$interactions)
Implements the Informed MatReorder method described in Strauss & Holekamp (in revision) to infer a dominance hierarchy over multiple study periods. For each study period, ranks are inferred as modifications of the ranks from the previous study period. First, new contestants are added according to the convention specified by the user, and emigrated/dead contestants are removed. Then, matrix reordering is used to change the position of contestants for whom data from the current study period are inconsistent with this ordering. The optimal order is selected as the order that is most consistent with the data from the current period and is minimally changed from the previous study period.
informed_matreorder( contestants, convention, n = 50, shuffles = 10, require.corroboration = FALSE, initial.ranks = NULL, interactions )
informed_matreorder( contestants, convention, n = 50, shuffles = 10, require.corroboration = FALSE, initial.ranks = NULL, interactions )
contestants |
A dataframe with the identities of the contestants for each study period along with the relevant data for adding them to the hierarchy. There should be one row per contestant per study period. Periods should appear in chronological order. The dataframe should contain the following columns:
|
convention |
A flag determining how new individuals are added to the hierarchy. The value of this flag influences how the convention1 and convention2 columns of the contestants argument are interpreted. Currently this function supports four options:
|
n |
Number of separate reordering attempts per study period. Recommended 100. |
shuffles |
Number of reshuffling steps per reordering attempt. Recommended at least 10. |
require.corroboration |
A logical indicating whether to require corroborating evidence from multiple study periods before changing a contestant's position in the order. Useful for reducing the sensitivity of the method to aberrant observations that don't reflect a lasting change in the true latent hierarchy. If true, evidence indicating a change in status must be corroborated by an additional observation in the following periods. See Strauss & Holekamp (in revision) for full details. |
initial.ranks |
The initial ordering of individuals for the first study period. Required if using maternal rank inheritance as the convention. For other conventions, if initial.ranks is not specified, the order determined by convention1 is used to create the initial order. |
interactions |
A dataframe of interaction data with the following columns:
|
Produces a dataframe with the following columns:
Study period.
Identity of contestant.
Ordinal rank of contestant in study period. Lower numbers equal higher rank.
Rank of contestant standardized for group size. Values range from 1 (highest rank) to -1 (lowest rank).
Identity of contestants arranged in the previous order (the order they were in before updating the order based on observations from current study period).
Strauss ED & Holekamp KE (in revision). Journal of Animal Ecology.
conts <- C.crocuta.female$contestants[C.crocuta.female$contestants$period <= 1990,] female.ranks <- informed_matreorder(contestants = conts, convention = 'mri', n =1, shuffles = 10, require.corroboration = TRUE, initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions)
conts <- C.crocuta.female$contestants[C.crocuta.female$contestants$period <= 1990,] female.ranks <- informed_matreorder(contestants = conts, convention = 'mri', n =1, shuffles = 10, require.corroboration = TRUE, initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions)
Plot ranks of individuals in a single social group over multiple study periods.
plot_ranks(ranks, type = c("rank", "stan.rank", "score"))
plot_ranks(ranks, type = c("rank", "stan.rank", "score"))
ranks |
A dataframe of ranks. There should be one row per contestant per study period. Must include at least the following columns:
|
type |
A character string, either 'score', 'rank', or 'stan.rank'. Determines whether scores, ranks, or standardized ranks are plotted. |
female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) plot_ranks(female.ranks, type = 'rank') plot_ranks(female.ranks, type = 'score') plot_ranks(female.ranks, type = 'stan.rank')
female.ranks <- informed_elo(contestants = C.crocuta.female$contestants, convention = 'mri', initial.ranks = C.crocuta.female$initial.ranks, interactions = C.crocuta.female$interactions) plot_ranks(female.ranks, type = 'rank') plot_ranks(female.ranks, type = 'score') plot_ranks(female.ranks, type = 'stan.rank')