-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasion_de_Herrerillos.Rmd
126 lines (91 loc) · 2.75 KB
/
Pasion_de_Herrerillos.Rmd
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
---
title: "Pasion_de_Herrerillos"
author: "RRM & CGC"
date: "2022-09-21"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, echo=FALSE, eval=TRUE}
library("tidyverse")
library("here")
library('performance')
library('DHARMa')
```
# Data management
Importamos los datos *"To what extent is the growth of nestling blue tits (Cyanistes caeruleus) influenced by competition with siblings?"*. Timothy H. Parker et al. (2020)
```{r}
data<-read_csv(here('blue_tit_data.csv'))
```
Haremos una selección de los pollos cuyos nidos no han sido manipulados, además retiraremos los casos donde no se conoce la paternidad de los pollos.
```{r}
data1<-data%>%
#filter(rear_nest_trt==7)%>%
filter(`Extra-pair_paternity`!= '.')
```
Nos quedaremos con las variables que nos interesan para el análisis, las renombraremos y recodificaremos las variables categóricas porque me da la gana::
```{r}
b_tit<- data1 %>%
select(chick_ID = chick_ring_number,
year = hatch_year,
paternity = `Extra-pair_paternity`,
hatch_size = d0_hatch_nest_brood_size,
n_fledgings = number_chicks_fledged_from_rear_nest,
date_14 = Date_of_day14,
tarsus = day_14_tarsus_length,
weight = day_14_weight,
sex = chick_sex_molec,
survival = (chick_survival_to_first_breed_season))%>%
mutate (sex= recode(sex,
"1" = "M",
"2" = "F"))%>%
mutate (paternity= recode(paternity,
"1" = "Amante",
"2" = "Marido"))
```
# Exploratory analysis
Ploteamos las variables
```{r}
b_tit %>%
select(date_14,tarsus,weight,survival)%>%
pairs()
```
```{r}
ggplot(b_tit, aes(x = log(tarsus), y= log(weight)))+
geom_smooth(method = 'lm')+
geom_point(aes(color=as.factor(paternity)),
alpha = 0.4)
```
## Las infidelidades afectan al destino de los pollitos herrerillo???
Calculamos una nueva variable Condición Corporal a partir de los residuos de la regresión tarso-peso
```{r}
body_cond<- lm(log(weight) ~ log(tarsus), data = b_tit)
summary(body_cond)
residuals <- body_cond$residuals
b_tit<- b_tit%>%
mutate(body_condition = residuals)
head(b_tit)
```
```{r}
m1 <- glm(body_condition ~ paternity, family = 'gaussian', data = b_tit)
summary(m1)
library(DHARMa)
simulateResiduals(m1, plot = TRUE)
library('performance')
check_model(m1)
```
```{r}
hist(b_tit$body_condition)
check_outliers(m1)
```
```{r}
tit_glm <- glm(survival ~ paternity + body_condition, family = 'binomial', data = b_tit)
check_model(tit_glm)
summary(tit_glm)
simulateResiduals(tit_glm, plot = TRUE)
sjPlot::plot_model(tit_glm, type="pred", terms="body_condition")
```
```{r}
table(b_tit$paternity)
```