The Iberian Lynx (Lynx pardinus) is a species first discovered by Temminck in 1827 [Fosse; et al. 2024]; it is a small carnivore with a patchy distribution of sites across Spain and Portugal [IUCN Red List; 2023]. With a diet consisting of primarily the European rabbit (Oryctolagus cuniculus); a species now considered endangered [IUCN Red List; 2019]; it is a delicate balance for conservationists to properly conserve both predators and prey.
The lynx is currently classified as vulnerable within the IUCN Red List [2023]; but this wasn’t always the case. In 2001, their status was classified as Endangered [IUCN; 2024]. This is estimated to be due to a lack of prey, habitat loss, and persecution from humans [IUCN, 2024]. Conservationists have been working to increase the numbers of prey, protect and restore the forest and scrubland habitats utilized by the lynx, and work on repairing their relationships with humans [IUCN, 2024]. Other issues such as the virus outbreaks, disease transfers from domestic cats (Felis catus), and lack of genetic diversity are issues being worked on by geneticists [IUCN, 2024]
Therefore, the data is implied to be a part of the conservation efforts undertaken by conservationists to protect the Iberian lynx. One question could be “How have the populations of Iberian Lynx (Lynx pardinus) changed between the 19th and 20th centuries?”, alternatively this could be a study on the European rabbit conservation and showing how the lynx populations have been impacted by the conservation efforts undertaken to protect them.
Our questions are:
How have the populations of Iberian Lynx (Lynx pardinus) changed between the 19th and 20th centuries?
Are different environmental factors between site A and site B impacting on the conservation of the Iberian Lynx (Lynx pardinus)?
century: Categorical, representing two unique values: 19 and 20.
Since we have a categorical predictor variable (“century”) with two groups, and a quantitative outcome variable (“lynx”), the appropriate statistical test would be a T-test to compare the means of lynx populations between the 19th and 20th centuries.
Installing and loading relevant packages
The following r code chunk installs and loads the various packages used to analysing the lynx data set.
Code
library(kableExtra) # loads the kableExtra packagelibrary(tidyverse) # loads the tidyverse package for ggplot functionslibrary("magrittr") # loads the magrittr package, which provides functions that helps make code more readablelibrary(knitr) # loads the knitr package, for dynamic report generation
Creating a table from the lynx data set
The lynx data set has been altered to make it easier to work with for subsequent analysis (the letter preceeding the numbers for each study site ID has been removed). The altered lynx data set is loaded and a table is created.
Code
library(readr)Lynx_Data_set_altered <-read_csv("C:/Users/tamsi/Downloads/Lynx Data set_altered.csv")View(Lynx_Data_set_altered)
Code
data("lynx_Data_set_altered") # loads the altered lynx data setas_tibble(Lynx_Data_set_altered) # creates a tibble, which basically is a dataframe
Computing the total number of lynxes grouped according to study site and century of capture
The following r code chunk facilitates the calculation of the sum of the number of lynxes grouped by study site and century of capture. All missing values recorded as ‘NA’ are removed. The resulting output adopts a wider format from a longer one. Finally, a new column named ‘sum_lynx’ is created with the sum of row values.
Code
lynx_summary <- Lynx_Data_set_altered %>%# altered lynx data set is assigned to lynx_summarygroup_by(id, century) %>%# data set is grouped by ID and centurysummarize(total_lynx =sum(lynx, na.rm =TRUE), .groups ='drop') %>%# sum of number of lynxes is computed as total_lynx, with missing data values coded as 'NA' removed and result ungrouped spread(century, total_lynx, fill =0) %>%# spreads the key-value pair across multiple columns into a wider formatmutate(sum_lynx =rowSums(select(., -id), na.rm =TRUE)) # sum of row values calculated and assigned a new column
Create a table with kable
The following r code chunk creates a table with the sum of each row for both the 19th and 20th centuries.
Code
lynx_summary |># specifies data to be used for subsequent operationskable() %>%# converts dataframes and matrices into well-formatted tableskable_classic_2(full_width = F) # manipulates table styles, with full width set to false
id
19
20
sum_lynx
1
3311
387
3698
2
6721
758
7479
3
4254
1307
5561
4
687
3465
4152
5
255
6991
7246
6
473
6313
6786
7
358
3794
4152
8
784
1836
2620
9
1594
345
1939
10
1676
382
2058
11
2251
808
3059
12
1426
1388
2814
13
756
2713
3469
14
299
3800
4099
15
201
3091
3292
16
229
2985
3214
17
469
3790
4259
18
736
674
1410
19
2042
81
2123
20
2811
80
2891
21
4431
108
4539
22
2511
229
2740
23
389
399
788
24
73
1132
1205
25
39
2432
2471
26
49
3574
3623
27
59
2935
2994
28
188
1537
1725
29
377
529
906
30
1292
485
1777
31
4031
662
4693
32
3495
1000
4495
33
587
1590
2177
34
105
2657
2762
35
153
3396
3549
Computing the total number of lynxes grouped according to study site
The following r code chunk facilitates the calculation of the sum of the number of lynxes grouped by study site . All missing values recorded as ‘NA’ are removed.
Code
lynx_summary <- Lynx_Data_set_altered %>%# altered lynx data set assigned to 'lynx_summary'group_by(id) %>%# data grouped by idsummarize(total_lynx =sum(lynx, na.rm =TRUE), .groups ='drop') # sum of number of lynxes calculated, with missing values coded as 'NA' removed and result ungrouped
Creating a table with kable
The following r code chunk creates a table with the sum of each row.
Code
lynx_summary |># specifies data for subsequent operationskable() %>%# converts dataframes and matrices into well-formatted tableskable_classic_2(full_width = F) # manipulates table styles, with full width set to false
id
total_lynx
1
3698
2
7479
3
5561
4
4152
5
7246
6
6786
7
4152
8
2620
9
1939
10
2058
11
3059
12
2814
13
3469
14
4099
15
3292
16
3214
17
4259
18
1410
19
2123
20
2891
21
4539
22
2740
23
788
24
1205
25
2471
26
3623
27
2994
28
1725
29
906
30
1777
31
4693
32
4495
33
2177
34
2762
35
3549
Computing the total number of lynxes grouped according to study site
The following r code chunk facilitates the calculation of the sum of the number of lynxes grouped by study site . All missing values recorded as ‘NA’ are removed.
Code
lynx_summary <- Lynx_Data_set_altered %>%# altered lynx data set assigned to 'lynx_summary'group_by(id) %>%# data grouped by idsummarize(total_lynx =sum(lynx, na.rm =TRUE), .groups ='drop') # sum of number of lynxes calculated, with missing values coded as 'NA' removed and result ungrouped
Creating a table with kable
The following r code chunk creates a table with the sum of each row for the 19th century.
Code
lynx_summary |># specifies data for subsequent operationskable() %>%# converts dataframes and matrices into well-formatted tableskable_classic_2(full_width = F) # manipulates table styles, with full width set to false
id
total_lynx
1
3698
2
7479
3
5561
4
4152
5
7246
6
6786
7
4152
8
2620
9
1939
10
2058
11
3059
12
2814
13
3469
14
4099
15
3292
16
3214
17
4259
18
1410
19
2123
20
2891
21
4539
22
2740
23
788
24
1205
25
2471
26
3623
27
2994
28
1725
29
906
30
1777
31
4693
32
4495
33
2177
34
2762
35
3549
Calculating the mean lynx counts by century
The following r code chunk facilitates the calculation of the mean of the number of lynxes grouped by century. All missing values recorded as ‘NA’ are removed.
Code
lynx_mean_summary <- Lynx_Data_set_altered %>%# altered lynx data set assigned to 'lynx_mean_summary'group_by(century) %>%# data grouped by centurysummarize(mean_lynx =mean(lynx, na.rm =TRUE), .groups ='drop') # mean of number of lynxes calculated, with missing values coded as 'NA' removed and result ungrouped
Displaying the table with kable
The following r code chunk creates a table with the mean of lynx numbers for each century.
Code
lynx_mean_summary %>%# specifies data for subsequent operationskable() %>%# converts dataframes and matrices into well-formatted tableskable_classic_2(full_width = F) # manipulates table styles, with full width set to false
century
mean_lynx
19
1403.200
20
1932.943
Creating graphics
Summarizing data by century
The following r code chunk facilitates the calculation of the total number of lynxes grouped by century. All missing values recorded as ‘NA’ are removed.
Code
lynx_by_century <- Lynx_Data_set_altered %>%# specifies data for subsequent operationsgroup_by(century) %>%# data grouped by centurysummarize(total_lynx =sum(lynx, na.rm =TRUE), .groups ='drop') # total number of lynxes calculated, with missing values coded as 'NA' removed and result ungrouped
Creating a graph
The following chunk of r code helps generate a bar graph of the total number of lynxes captured in each century
Code
ggplot(lynx_by_century, aes(x = century, y = total_lynx)) +# ggplot functions are used to generate graphics, with data set specified, x- and y-variables assigned accordinglygeom_bar(stat ="identity", fill ="purple") +# generates a bar graph, with sum of values for variable used instead of counts, fill colour manually set to purplelabs(title ="Total Lynx Counts by Century", # title of graph specifiedx ="Century", # label of a-axis assigned accordinglyy ="Total Lynx Count") +# label of y-axis assigned accordinglytheme_dark() # theme set to dark
Summarizing total lynx counts by id
The following r code chunk facilitates the calculation of the total number of lynxes grouped by study site id. All missing values recorded as ‘NA’ are removed.
Code
lynx_by_id <- Lynx_Data_set_altered %>%# specifies data for subsequent operationsgroup_by(id) %>%# data grouped by idsummarize(total_lynx =sum(lynx, na.rm =TRUE), .groups ='drop') # total number of lynxes calculated, with missing values coded as 'NA' removed and result ungrouped
Creating a figure showing total lynx counts by id
Code
ggplot(lynx_by_id, aes(x =reorder(id, total_lynx), y = total_lynx)) +# ggplot functions are used to generate graphics, with data set specified, x- and y-variables assigned accordingly and values reordered according to specified ordergeom_bar(stat ="identity", fill ="purple") +# generates a bar graph, with sum of values for variable used instead of counts, fill colour manually set to purplelabs(title ="Total Lynx Counts by ID", # title of graph specifiedx ="ID", # label of x-axis assigned accordinglyy ="Total Lynx Count") +# label of y-axis assigned accordinglytheme_dark() +# theme set to darkcoord_flip() # Flips the axes for better readability
References
Fosse; et al. 2024. The lynxes (Lynx pardinus/spelaeus, Lynx lynx) from the Middle Pleistocene to the Holocene in southern France: a paleontological and taphonomical overview. [online]. HAL Open Science: Fosse; et al. Available at: The lynxes (Lynx pardinus/spelaeus, Lynx lynx) from the Middle Pleistocene to the Holocene in southern France: a paleontological and taphonomical overview. [Date accessed: 28th October 2024].
IUCN Red List, 2019. European Rabbit [online]. IUCN Red List. Available at: Oryctolagus cuniculus (European Rabbit) [Date accessed: 27th October 2024].
IUCN Red List, 2023. Iberian Lynx [online]. IUCN Red List. Available at: Lynx pardinus (Iberian Lynx) [Date accessed: 27th October 2024].
IUCN, 2024. Iberian lynx rebounding thanks to conservation action - IUCN Red List [online]. Press Released: IUCN. Available at: Iberian lynx rebounding thanks to conservation action - IUCN Red List - Press release | IUCN [Date accessed: 28th October 2024].