Description Details References Examples
This R package aims at providing the data and documenting the R code behind the analysis of the paper entitled 'Mate choice, reproductive success and inbreeding in white rhinos (Ceratotherium simum Burchell, 1817): new insights for conservation management' by Kretzschmar P., Auld H., Boag P., Ganslosser U., Scott C., Van Coeverden de Groot P.J. & Courtiol A. (accepted in Evolutionary Applications).
This package has not been conceived for general use!
The main functions of this package contain a small documentation and examples
which could be useful for those who try to understand our code. Type
ls('package:matingRhinos')
for a list of all (exported) functions and
datasets.
You may directly explore the files contained in the package on GitHub at
https://github.com/courtiol/matingRhinos, or after uncompressing the
content of the *.tar.gz file (link available on the GitHub as well). To
uncompress such a tarball, you can use the R function untar
.
The package contains all the original data.
In the examples below, we provide the workflow leading the results presented in the paper.
Kretzschmar P., Auld H., Boag P., Ganslosser U., Scott C., Van Coeverden de Groot P.J. & Courtiol A. (accepted in Evolutionary Applications) Mate choice, reproductive success and inbreeding in white rhinos (Ceratotherium simum Burchell, 1817): new insights for conservation management.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | ###############################################
## Setting general options for this workflow ##
###############################################
### Note: set the following options to TRUE or FALSE depending on what you want.
options(matingRhinos_PDF = TRUE) # export figures on hard drive as pdf?
options(matingRhinos_colours = TRUE) # use colours in figures?
############################
## Preparing the datasets ##
############################
### 1. We split the dataset per cohort:
malesC1 <- droplevels(males[males$Cohort == 'C1', ])
malesC2 <- droplevels(males[males$Cohort == 'C2', ])
femalesC1 <- droplevels(females[females$Cohort == 'C1', ])
femalesC2 <- droplevels(females[females$Cohort == 'C2', ])
### 2. Running the Principal Component Analyses (PCA) on horns characteristics:
PCA_C1_males <- compute_PCA(data = malesC1)
PCA_C2_males <- compute_PCA(data = malesC2)
males$Horn <- NA
males$Horn[males$Cohort == 'C1'] <- PCA_C1_males$data$PC1
malesC1$Horn <- PCA_C1_males$data$PC1
males$Horn[males$Cohort == 'C2'] <- PCA_C2_males$data$PC1
malesC2$Horn <- PCA_C2_males$data$PC1
### 3. We visuallise the first 6 rows of each dataset:
head(males)
head(malesC1)
head(malesC2)
head(females)
head(femalesC1)
head(femalesC2)
########################
## Parentage analysis ##
########################
### Note: the bioinformatic work leading to parentage has not been done using R.
### 1. Fatherhood successfully assigned
sum(males$Rep_succ) # number assigned for all males
round(100*sum(males$Rep_succ)/104, 1) # proportion assigned for all males
sum(malesC1$Rep_succ) # number assigned for C1 males
round(100*sum(malesC1$Rep_succ)/53, 1) # proportion assigned for C1 males
sum(malesC2$Rep_succ) # number assigned for C2 males
round(100*sum(malesC2$Rep_succ)/51, 1) # proportion assigned for C2 males
fisher.test(matrix(c(sum(malesC1$Rep_succ), 53 - sum(malesC1$Rep_succ),
sum(malesC2$Rep_succ), 51 - sum(malesC2$Rep_succ)),
byrow = TRUE,
nrow = 2))
#####################################
## Mating and reproductive success ##
#####################################
### 1. Computing the skewness tests for males:
test_NonacsB(benef = males$Mat_succ, time = males$Time)
test_NonacsB(benef = males$Rep_succ, time = males$Time)
### 2. Creating figure 1:
figure_NonacsB(data_males = males, data_females = females_C1C2merged)
### 3. Relationship between mating and reproductive success for males:
compute_correlation(var1 = malesC1$Mat_succ, var2 = malesC1$Rep_succ)
compute_Bateman(mating_success = malesC1$Mat_succ, reproductive_success = malesC1$Rep_succ)
compute_correlation(var1 = malesC2$Mat_succ, var2 = malesC2$Rep_succ)
compute_Bateman(mating_success = malesC2$Mat_succ, reproductive_success = malesC2$Rep_succ)
### 4. Creating figure 2:
figure_Bateman(data_agg = rhinos_agg)
### 5. Computing the skewness tests for females:
test_NonacsB(benef = females_C1C2merged$Mat_succ, time = females_C1C2merged$Time)
test_NonacsB(benef = females_C1C2merged$Rep_succ, time = females_C1C2merged$Time)
### 6. Relationship between mating and reproductive success for females:
compute_correlation(var1 = femalesC1$Mat_succ, var2 = femalesC1$Rep_succ)
nrow(femalesC1)
compute_Bateman(mating_success = femalesC1$Mat_succ, reproductive_success = femalesC1$Rep_succ)
compute_correlation(var1 = femalesC2$Mat_succ, var2 = femalesC2$Rep_succ)
nrow(femalesC2)
compute_Bateman(mating_success = femalesC2$Mat_succ, reproductive_success = femalesC2$Rep_succ)
### 7. Successful males:
malesC1[malesC1$Rep_succ == max(malesC1$Rep_succ), c('No', 'Rep_succ', 'Mat_succ')]
range(malesC1$Mat_succ[malesC1$Rep_succ != max(malesC1$Rep_succ)])
range(malesC1$Rep_succ[malesC1$Rep_succ != max(malesC1$Rep_succ)])
malesC2[malesC2$Rep_succ == max(malesC2$Rep_succ), c('No', 'Rep_succ', 'Mat_succ')]
##########################
## Horn characteristics ##
##########################
### 1. Variance explained:
round(100*PCA_C1_males$var_expl[1], 1)
round(100*PCA_C2_males$var_expl[1], 1)
### 2. Creating figure 3:
figure_PCA(data = males)
######################
## All correlations ##
######################
### 1. Computing all the correlation tests
compute_correlation_table(cohort = 'C1', fitness = 'Mat_succ', data = males)
compute_correlation_table(cohort = 'C1', fitness = 'Rep_succ', data = males)
compute_correlation_table(cohort = 'C2', fitness = 'Mat_succ', data = males)
compute_correlation_table(cohort = 'C2', fitness = 'Rep_succ', data = males)
### 2. Creating figures 4 & 5:
figure_correlations(data = males)
## note: rerun if bug 'polygon edge not found'; this is a ggplot hiccup.
#############################################
## Testosterone metabolites concentration ##
#############################################
### 1. Mean +/- SD:
round(mean(malesC1$Testo_mean, na.rm = TRUE), digits = 3L)
round(sd(malesC1$Testo_mean, na.rm = TRUE), digits = 3L)
round(mean(malesC2$Testo_mean, na.rm = TRUE), digits = 3L)
round(sd(malesC2$Testo_mean, na.rm = TRUE), digits = 3L)
### 2. Creating figure S1:
figure_testosterone(data = males)
######################
## Male territories ##
######################
### 1. Computing the range of the territory sizes:
rbind(malesC1[which.min(malesC1$Ter_map), c('No', 'Cohort', 'Ter_map')],
malesC1[which.max(malesC1$Ter_map), c('No', 'Cohort', 'Ter_map')])
rbind(malesC2[which.min(malesC2$Ter_map), c('No', 'Cohort', 'Ter_map')],
malesC2[which.max(malesC2$Ter_map), c('No', 'Cohort', 'Ter_map')])
#################
## Relatedness ##
#################
### 1. Relatedness of the male the most related to females:
males[which.max(males$Related_mean), c('No', 'Cohort', 'Related_mean', 'Related_SD')]
### 2. Comparing mean relatedness of female mates and all candidate females:
wilcox.test(males$Related_mean_mated_fem, males$Related_mean, paired = TRUE)
wilcox.test(malesC1$Related_mean_mated_fem, malesC1$Related_mean, paired = TRUE)
wilcox.test(malesC2$Related_mean_mated_fem, malesC2$Related_mean, paired = TRUE)
### 3. Creating figure S2:
figure_relatedness_simulation(relat_sim)
### 4. Creating figure S3:
figure_relatedness(data = males)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.