scieee Science in your language
[en] (orig)

Data and code for: Trade-offs across life history stages and social association types shape winter communal roosting in a long-lived raptor

Author: Catitti, Benedetta; Mindt, Lorenz P.; Aebischer, Adrian; Grüebler, Martin U.; Schlick-Steiner, Birgit C.; Steiner, Florian M.; Kormann, Urs G.
Publisher: Zenodo
DOI: 10.5281/zenodo.17610458
Source: https://zenodo.org/records/17610458/files/Communal_roosting_redkites_JAE.pdf
T ade-o s ac oss li e his o y s ages and social
associa ion ypes shape win e communal
oos ing in a long-li ed ap o
Code o gene a e communal oos ing es ima es using GPS- acking da a and
model communal oos ing p opensi ies
Table o con en s
1. Iden i y indi iduals communal oos ing . . . . . . . . . . . . . . . . . . . . . 3
2.Da aanno a ion.................................. 8
3.Summa y...................................... 15
4.Da a o ma ing.................................. 15
5. Explo e he ela ionship be ween oos ing p opensi y ac oss he season (in
ju sandadul s) ............................... 19
6. Model ( oos ing ~ age, sex, b eeding s a us) . . . . . . . . . . . . . . . . . . 20
Ju eniles........................................ 20
Adul s......................................... 25
7. Disen angling elec i e disappea ance s beha iou al plas ici y . . . . . . . . 27
1
Figu e 1: A Red ki e oos in he Can on o F ibou g, Swi ze land. Pho o: Pa ick Sche le
# Clea R's mind
m(lis = ls())
# Load lib a ies
lib a y(he e) # easy e e encing
lib a y(lub ida e) # da a w angling
lib a y(dply ) # da a w angling
lib a y( idy e se) # da a w angling
lib a y(ggplo 2) # plo
lib a y(s ) # spa ial da a w angling
lib a y(da a. able) # da a w angling
lib a y(b ms) # model
lib a y(pe o mance) # o he bayesian R2
lib a y(bayes es R) # o he desc ibe_pos e io unc ion
lib a y( idybayes) # o he add_ep ed_d aws unc ion
lib a y(model ) # o gene a e simula ed da ase
lib a y( cd) # o C ame s' coe icien
2
lib a y(zoo) # da a w angling
lib a y(b oom.mixed) # o expo idy model ou pu s
lib a y( eadxl)
1. Iden i y indi iduals communal oos ing
We use nigh ly-a e aged, indi idual GPS loca ion o pe o m a spa ial join o iden i y loca ions
ha in e sec wi h each o he .
This will gi e you pai s o indi iduals ha a e wi hin 300 me e s o each o he . The gene a ed
da a ame (“spa ial_join”) consis s o he pai s o indi iduals wi hin 300m o each o he . This
is epea ed o each empo al in e al
oos _dayweek <- lis ()
o (j in 1:14) {
esul s <- lis ()
unique_nigh s <- na.omi (unique(nigh med[[pas e0("in e al",j)]]))
o (i in 1:leng h(unique_nigh s)) {
# Fil e da a o he cu en nigh
da a_nigh <- nigh med[which(nigh med[[pas e0("in e al",j)]] ==
unique_nigh s[i]),]↪
# C ea e a spa ial bu e o he cu en nigh
bu e _ adius <- 300 # in me e s
da a_nigh _bu e <- s _bu e (da a_nigh , dis = bu e _ adius)
# Pe o m a spa ial join o he cu en nigh
spa ial_join <- s _join(da a_nigh _bu e , da a_nigh , join =
s _in e sec s)↪
# Exclude pai s whe e he same indi idual is p esen in bo h columns
p oximi y_pai s <- subse (spa ial_join, id.x != id.y)
p oximi y_pai s$agg <-
as.cha ac e (p oximi y_pai s[[pas e0("in e al",j,".x")]])↪
# Add o he da ase also he indi iduals ha don' in e sec wi h anyone
oadd <- da a_nigh %>% il e (!id %in% p oximi y_pai s$id.x)
3
colnames( oadd) <- pas e0(colnames( oadd), ".x")
colnames( oadd)[which(colnames( oadd) == "geome y.x")] <- "geome y"
oadd2 <- oadd
colnames( oadd2) <- s _ eplace(colnames( oadd2),".x",".y")
oadd2 <- oadd2 %>% s _d op_geome y()
oadd <- cbind( oadd, oadd2)
oadd$agg <- as.cha ac e ( oadd[[pas e0("in e al",j,".x")]])
oadd <- oadd[,c(o de (colnames(p oximi y_pai s)))]
oadd$id.y <- NA
p oximi y_pai s <- bind(p oximi y_pai s, oadd)
# S o e he esul s o he cu en nigh
esul s[[i]] <- p oximi y_pai s
}
oos _dayweek[[j]] <- esul s
}
Associa e he b ood ID o each indi idual and yea
d <- as.da a. able(combined_ esul s)
id_b ood <- unique(d , by = c("id.x","win e .x")) %>%
dply :: ename(id = id.x) # combina ion o each unique indi idual
pe win e ↪
# Fo indi iduals agged as ju eniles, un il hey s a b eeding, he
b ood_ID is he one o o igin↪
a ibu es <- ead_cs (he e::he e("./Da a/b ood_in o.cs ")) %>%
dply ::selec (id, age, ha ch_yea , sex_compiled,
nes _o _o igin_ID, b ood_ID, nes _ID_15, nes _ID_16, nes _ID_17,
nes _ID_18, nes _ID_19, nes _ID_20, nes _ID_21, e i o yID_2016,
↪
↪
e i o yID_2017,
e i o yID_2018,
e i o yID_2019,
e i o yID_2020,
e i o yID_2021 , ag_yea , manu ac u e )
# ids agged as adul s
adul s_a <- a ibu es %>%
4
il e (!age == "1CY")%>%
dply ::selec (id, nes _ID_15, nes _ID_16, nes _ID_17,
nes _ID_18, nes _ID_19, nes _ID_20, nes _ID_21) %>%↪
mu a e_all(as.cha ac e ) %>%
pi o _longe (!id, names_ o = "win e .x", alues_ o =
"nes _ID")%>%↪
mu a e(win e .x = sub(".*_( d+)","20 1", win e .x)) %>% #
ans o m he nes yea o b ood yea ↪
mu a e(b ood_ID = pas e(nes _ID, win e .x, sep=" "), age =
"adul ")↪
# ids agged as ju eniles - hei b ood o o igin
ju s_a <- a ibu es %>%
il e (age == "1CY")%>%
dply ::selec (id, ha ch_yea , nes _o _o igin_ID, b ood_ID) %>%
dply :: ename(win e .x = ha ch_yea , nes _ID =
nes _o _o igin_ID)↪
# ids agged as ju eniles - hei b ood when hey s a b eeding
se l_a <- a ibu es %>%
il e (age == "1CY")%>%
dply ::selec (id, nes _ID_15, nes _ID_16, nes _ID_17,
nes _ID_18, nes _ID_19, nes _ID_20, nes _ID_21) %>%↪
mu a e_all(as.cha ac e ) %>%
pi o _longe (!id, names_ o = "win e .x", alues_ o = "nes _ID")
%>%↪
mu a e(win e .x = sub(".*_( d+)","20 1", win e .x)) %>% #
ans o m he nes yea o b ood yea ↪
mu a e(b ood_ID = pas e(nes _ID, win e .x, sep=" ")) %>%
d op_na(nes _ID)
ju s <- bind(ju s_a , se l_a )
# o each ju enile, we add he comple e his o y yea -his o y.
# The b ood ID will i s be he b ood o o igin and i swi ches when i
s a s b eeding↪
ju s$win e .x <- as.nume ic(ju s$win e .x)
ju s <- ju s %>%
a ange(id, win e .x) %>%
g oup_by(id) %>%
5

comple e(win e .x = ull_seq(min(win e .x):2021,1)) %>%
mu a e(nes _ID = na.loc (nes _ID), b ood_ID = na.loc (b ood_ID)) %>%
ung oup() %>%
mu a e(age = "ju ")
#pu oge he all in o
all_a <- bind(adul s_a , ju s) # he NAs a e he adul s ha s opped
ansmi ing o died↪
all_a $id_yea <- pas e(all_a $id, all_a $win e .x, sep="_")# o join
i o he o iginal obse ed da ase ↪
# c ea e a id_win e column and hen join i o he main da ase
(combined_ esul s)↪
combined_ esul s <- combined_ esul s %>% mu a e(id_yea = pas e(id.x,
win e .x, sep="_"))↪
combined_ esul s <- combined_ esul s %>%
le _join(all_a [,c("b ood_ID","id_yea ")] %>% dply :: ename(b ood_ID.x
=b ood_ID))
↪
↪
# add he b ood ID o he second indi idual o he couple
combined_ esul s <- combined_ esul s %>% mu a e(id_yea = pas e(id.y,
win e .x, sep="_"))↪
all_a <- all_a %>% dply :: ename(b ood_ID.y = b ood_ID)
# Fo he 3 indi iduals ha a e agged as ju eniles and hen s a b eeding
# we ha e o change he age (6, 322 and 91)
# 6 om 2019 on
# 322 and 91 om 2020 on
all_a $age[which(all_a $id == "6" &all_a $win e .x %in% c("2019",
"2020","2021"))] <- "adul "↪
all_a $age[which(all_a $id == "322" &all_a $win e .x %in% c("2020",
"2021"))] <- "adul "↪
all_a $age[which(all_a $id == "91" &all_a $win e .x %in% c("2020",
"2021"))] <- "adul "↪
combined_ esul s <- combined_ esul s %>%
le _join(all_a [,c("b ood_ID.y","id_yea ")], by = "id_yea ")↪
# i he e is "unknown" in he b ood ID is because he bi d was caugh
wi hou inding he nes --> we make i NA↪
combined_ esul s <- combined_ esul s %>%
6
mu a e(b ood_ID.x = i else(g epl("unknown", b ood_ID.x,
igno e.case = TRUE), NA, b ood_ID.x),↪
b ood_ID.y = i else(g epl("unknown", b ood_ID.y,
igno e.case = TRUE), NA, b ood_ID.y))↪
combined_ esul s$id_unique <- seq(1:leng h(combined_ esul s$id.x))
# Expo associa ion da a o he
# pa en -o sp ing and kin-kin associa ion
# analysis la e
# combined_ esul s %>%
# il e ( emp_ h esh == 5) %>%
# w i e_ ds(he e::he e("./Da a/Associa ion_ ypes/ k_300_5nigh . ds"))
# As well as he indi idual a ibu es
# all_a %>%
# w i e_ ds(he e::he e("./Da a/Associa ion_ ypes/all_a . ds"))
De ine an indi idual as oos ing o no depending on he numbe o indi iduals i ’s oos ing
wi h
# How many o he indi iduals we e in he same loca ion ha nigh ? I mo e
han 2, de ine as communal oos ing↪
d <- as.da a. able(combined_ esul s)
oos s_ o <- d [, .(n_ind = n_dis inc (id.y, na. m=T)), by = .( emp_ h esh,
id.x, agg )] %>%↪
as_ ibble() %>%
mu a e( oos ing = i _else(n_ind >= 2,1,0))
# a ach he coo dina es o he nigh loca ions o plo
oos s_xy <- unique(d , by = c("id.x"," emp_ h esh","agg ","doy.x"))
oos s_ o <- oos s_ o %>%
le _join( oos s_xy[,c("id.x","win e .x"," emp_ h esh",
"agg ","doy.x","geome y","b ood_ID.x")], by =
c("id.x"," emp_ h esh","agg ")) %>%
↪
↪
dis inc ( emp_ h esh, agg , id.x, .keep_all = T) %>%
s _as_s ()
m(d , oos s_xy)
7
# This oos s_ o ile will be needed o he alida ion wi h he coun da a
# (Supplemen a y In o ma ion)
sa eRDS( oos s_ o , he e::he e("./Da a/ oos s_ o . ds"))
Based on sensi i i y analysis and compa ison wi h communal oos ing census da a (see Supp.
In o ma ion), we decided o use 5 nigh s as empo al h eshold and 300 m as spa ial h eshold
2. Da a anno a ion
Add indi idual in o ma ion (age, b eeding s a us, sex)
oos s_ o _5 <- oos s_ o _5 %>%
dply :: ename(id = id.x) %>%
dply ::selec (-c( emp_ h esh)) %>%
le _join(a ibu es[,c("id","ha ch_yea ","sex_compiled"," ag_yea ")],
by = "id")
↪
↪
# add age
oos s_ o _5 <- oos s_ o _5 %>%
g oup_by(id) %>%
mu a e(age = (as.nume ic(win e .x) -
as.nume ic(ha ch_yea ))+1)%>% # he NAs a e adul s. we
add 1 because 0 is he 1s CY
↪
↪
ung oup() %>%
il e (!age %in% c(8:18))
oos s_ o _5$age[which(is.na( oos s_ o _5$age))] <- "3+"
# add b eeding s a us o he yea be o e
oos s_ o _5$id_yea <- pas e( oos s_ o _5$id, oos s_ o _5$win e .x, sep
="_")↪
oos s_4 <- lis ()
o (i in 1:leng h(unique( oos s_ o _5$id_yea ))) {
idx <- oos s_ o _5 %>% il e (id_yea == unique(id_yea )[i])
idx_ e i o y <- a ibu es %>% il e (id == unique(idx$id)) %>%
dply ::selec (pas e0(" e i o yID_",unique(idx$win e .x)))
idx$b eeding <- as.nume ic(idx_ e i o y)
8
idx <- idx %>% mu a e(b eeding = i _else(is.na(b eeding),"0","1"))
oos s_4[[i]] <- idx
}
oos s_ o _5 <- do.call(bind_ ows, oos s_4)
m( oos s_4)
unique( oos s_ o _5$age)
Add dis ance o he s udy a ea as weigh
# Add dis ance o he s udy a ea as a co a ia e
lon_ex en <- c(7.144554,7.373007)# longi udinal e ices o he s udy a ea
la _ex en <- c(46.68084,46.90619)# la i udinal e ices o he s udy a ea
# add dis ance o he ma gin ins ead o la -lon
bbox <- da a. ame(lon = lon_ex en , la = la _ex en ) %>%
s _as_s (coo ds = c("lon","la "), c s = 4326)%>%
s _ ans o m(2056)%>%
s _bbox()
# C ea e a ma ix ep esen ing he bounding box as a polygon
bbox_ma ix <- ma ix(c(bbox['xmin'], bbox['ymin'],
bbox['xmax'], bbox['ymin'],
bbox['xmax'], bbox['ymax'],
bbox['xmin'], bbox['ymax'],
bbox['xmin'], bbox['ymin']), ncol = 2,by ow = TRUE)
# C ea e an s polygon objec
bbox <- s _polygon(lis (bbox_ma ix)) %>% s _s c(c s = 2056)
oos s_ o _5$sa <- as.nume ic(s _wi hin( oos s_ o _5, bbox)) # now i 's
ei he 0 (in he s udy a ea) o NA (no in he s udy a ea)↪
oos s_ o _5$sa[which(is.na( oos s_ o _5$sa))] <- "0"
# isual check
ggplo () +
geom_s (da a = bbox, alpha = .2)+
geom_s (da a = oos s_ o _5, mapping = aes(col = sa)) +
heme_bw()
9
oos ing_ju $age.z <- scale( oos ing_ju $age)[,1]
oos ing_ju <- oos ing_ju %>% a ange(id,win e .x,doy.x)
# adul s
oos ing_ad$id <- as. ac o ( oos ing_ad$id)
oos ing_ad$doy.x[which( oos ing_ad$doy.x <100)] <-
oos ing_ad$doy.x[which( oos ing_ad$doy.x <100)] +365↪
oos ing_ad$doy.z <- scale( oos ing_ad$doy.x, cen e = TRUE)[,1]
oos ing_ad$win e .x <- as. ac o ( oos ing_ad$win e .x)
oos ing_ad$ oos ing <- as. ac o ( oos ing_ad$ oos ing)
oos ing_ad$sex_compiled <- as. ac o ( oos ing_ad$sex_compiled)
oos ing_ad <- oos ing_ad %>% a ange(id,win e .x,doy.x)
# Wha a e he sample sizes pe ca ego ies?
oos ing_ju %>%
g oup_by(age, b eeding, sex_compiled) %>%
dply ::summa ise(n_obs = n(), n_ind = n_dis inc (id))
# A ibble: 22 x 5
# G oups: age, b eeding [11]
age b eeding sex_compiled n_obs n_ind
<dbl> < c > < c > <in > <in >
1 1 0 121 14
2 1 0 m 173 19
3 2 0 149 17
4 2 0 m 491 45
5 3 0 201 19
6 3 0 m 545 53
7 3 1 141 13
8 3 1 m 45 4
9 4 0 100 8
10 4 0 m 279 20
# i 12 mo e ows
oos ing_ad %>%
g oup_by(sex_compiled) %>%
dply ::summa ise(n_obs = n(), n_ind = n_dis inc (id))
# A ibble: 2 x 3
16

sex_compiled n_obs n_ind
< c > <in > <in >
1 1767 31
2 m 2010 37
17
18
5. Explo e he ela ionship be ween oos ing p opensi y ac oss he season (in ju s and
adul s)
320 340 360 380
0.0 0.2 0.4 0.6 0.8
JUVENILES
doy
p opo ion o nigh s spen a communal oos s
320 340 360 380
0.0 0.2 0.4 0.6 0.8 1.0
ADULTS
doy
p opo ion o nigh s spen a communal oos s
19
The e is a non-signi ican nega i e ela ionship be ween day o he yea and he p obabili y o
oos ing communally in ju eniles and posi i e signi ican ela ionship in indi iduals agged as
adul s:
Pe son’s o ju eniles: -0.148, p- alue: 0.16
Pe son’s o adul s: 0.266, p- alue: 0.01
6. Model ( oos ing ~ age, sex, b eeding s a us)
Ju eniles
# C ea e he nume ical day sequence
oos ing_ju <- oos ing_ju %>%
mu a e(agg = as.nume ic(sub(".*_","", oos ing_ju $agg )))
%>%↪
g oup_by(id, win e .x) %>%
mu a e(doy_num = agg -min(agg ) +1)%>%
ung oup() %>%
mu a e(doy_num.z = scale(doy_num)[,1])
# Add weigh s ha go om 0 o 1
oos ing_ju $weigh s <- scale( oos ing_ju $sa, cen e = min( oos ing_ju $sa),
scale = max( oos ing_ju $sa) -min( oos ing_ju $sa))↪
oos ing_ju $weigh s <- as.nume ic(1- oos ing_ju $weigh s)
ange( oos ing_ju $weigh s)
[1] 0 1
oos ing_ ull_quad <- b m(b ( oos ing|weigh s(weigh s) ~age.z +I(age.z^2)
+sex_compiled +↪
b eeding +(doy_num.z|id_yea ) +(1|id) +
(1|win e .x)),↪
da a= oos ing_ju , amily=be noulli(),
i e = 4000,
co es = 4)
# Expo he able o he inal model
desc ibe_pos e io ( oos ing_ ull_quad , e ec s="all")%>%
mu a e_i (is.nume ic, unc ion(x) ound(x, digi s = 3)) %>%
dply ::selec (1:6)%>%
20
w i e_cs ("./Resul s/Tables/Mod_ju .cs ")
ĎVisualisa ion
Model check
# 1. Binned esidual plo s: The ollowing shows h ee binned esidual plo s,
wi h each poin showing y1−y, whe e y1 is based on simula ed da a om
he pos e io p edic i e dis ibu ions, and y is he obse ed da a. No e
ha we need he binned esiduals o p edic i e e o s, as he p edic ion
e o is ei he 0 o 1, as shown in he Figu e below. he binned ma gins
we e based on he obse ed da a, whe eas he do s we e p edic i e e o s
om eplica ed da a. P edic i e p opo ions (x-axis)
↪
↪
↪
↪
↪
↪
pp_check( oos ing_ ull_quad , ype = "e o _binned",nsamples = 9)
0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00 0.00 0.25 0.50 0.75 1.00
−0.2
−0.1
0.0
0.1
0.2
−0.2
−0.1
0.0
0.1
0.2
−0.2
−0.1
0.0
0.1
0.2
P edic ed p opo ion
A e age E o s
(wi h 2SE bounds)
# 2. A e age classi ica ion accu acy --> OBSERVED VS SIMULATED: Ano he way
o e alua e a logis ic eg ession model is o look a classi ica ion
e o , which is analogous o R^2 o no mal eg ession.The simples
measu e is o assign obse a ions wi h p edic ed p obabili ies la ge
han �0 o ha e a alue o 1, and o assign obse a ions wi h p edic ed
p obabili ies smalle han �0 o ha e a alue o 0, whe e �0 is some
chosen cu o , and is usually chosen as he p opo ion o 1s in he
sample. Fo example, o ou model,
↪
↪
↪
↪
↪
↪
↪
21

m1_p ed <- p edic ( oos ing_ ull_quad , ype = " esponse")[ , "Es ima e"]
m1_p ed <- as.nume ic(m1_p ed >
mean(as.nume ic(as.cha ac e ( oos ing_ju $ oos ing))))↪
# Classi ica ion able
(class ab_m1 <- able(p edic ed = m1_p ed, obse ed = oos ing_ju $ oos ing))
obse ed
p edic ed 0 1
0 1863 231
1 312 1746
# A e age classi ica ion accu acy
(acc_m1 <- sum(diag(class ab_m1)) /sum(class ab_m1))
[1] 0.8692197
Plo he age and sex e ec
Age_sex_e ec <- oos ing_ju %>%
da a_g id(sex_compiled, age.z, b eeding) %>%
add_ep ed_d aws( oos ing_ ull_quad , e_ o mula=NA,nd aws
=100)%>%↪
mu a e(age =
age.z*sd( oos ing_ju $age)+mean( oos ing_ju $age))↪
Age_sex_e ec _b <- Age_sex_e ec [which(Age_sex_e ec $b eeding == "1"),]
Age_sex_e ec _nb <- Age_sex_e ec [which(Age_sex_e ec $b eeding == "0"),]
# awda a o he poin s
awda a <- oos ing_ju
awda a$ oos ing <- as.nume ic(as.cha ac e ( awda a$ oos ing))
awda a$ oos ing[which( awda a$sex_compiled == " "& awda a$ oos ing == 0)] <-
-0.05↪
awda a$ oos ing[which( awda a$sex_compiled == "m"& awda a$ oos ing == 1)] <-
1.05↪
# Plo only he non-b eede s
e ec _g ouped_nb <- Age_sex_e ec _nb %>%
22
g oup_by(age, sex_compiled) %>%
dply ::summa ise(med_p ed = median(.ep ed)) %>%
ung oup
e ec _g ouped <- Age_sex_e ec %>%
g oup_by(age, sex_compiled, b eeding) %>%
dply ::summa ise(med_p ed = median(.ep ed)) %>%
ung oup
# Remo e om he igu e he b eede s a age 1 ( he e a e none in eali y)
Age_sex_e ec $.ep ed[which(Age_sex_e ec $b eeding == 1&Age_sex_e ec $age
== 1)] <- NA↪
e ec _g ouped$med_p ed[which(e ec _g ouped$b eeding == 1&
e ec _g ouped$age == 1)] <- NA↪
Age_sex_e ec $.ep ed[which(Age_sex_e ec $b eeding == 1&Age_sex_e ec $age
== 2)] <- NA↪
e ec _g ouped$med_p ed[which(e ec _g ouped$b eeding == 1&
e ec _g ouped$age == 2)] <- NA↪
ig2 <- ggplo (Age_sex_e ec , aes(y = .ep ed, x = age, ill=sex_compiled,
g oup = in e ac ion(sex_compiled, b eeding))) +
s a _line ibbon(alpha=.5,.wid h=.95)+
geom_poin (da a = e ec _g ouped,
aes(y = med_p ed,x = age, g oup =
in e ac ion(sex_compiled, b eeding)),↪
size = 3.5)+
scale_colo _manual( alues=c("khaki3","s eelblue4")) +
scale_ ill_manual( alues=c("khaki3","s eelblue4")) +
xlab("Age [yea s]")+ylab("% Time spen in a communal
oos ")+↪
scale_x_con inuous(b eaks=seq(1,7,1))+
scale_y_con inuous(b eaks=seq(0,1,0.2)) +
ace _g id(.~b eeding) +
heme_classic()+
heme(legend.posi ion = "none",
axis. ex = elemen _ ex (size = 15),
axis. i le = elemen _ ex (size = 15),
s ip.backg ound = elemen _blank(), # emo e ace _g id
labels↪
s ip. ex .x = elemen _blank())
23
ig2
12345671234567
0.0
0.2
0.4
0.6
0.8
Age [yea s]
% Time spen in a communal oos
# ggsa e( ig2, ile = "./Resul s/Plo s/Fig2.png",
# wid h = 8, heigh = 5)
# Ex ac numbe s o he manusc ip - median and 95 % C I o
# Age ca ego ies
Age_sex_e ec %>%
il e (sex_compiled == le els(sex_compiled)[2], b eeding ==
le els(b eeding)[1]) %>%↪
g oup_by(age) %>%
dply ::summa ise(m_p ob = median(.ep ed),
low_c i = quan ile(.ep ed, 0.025),
up_c i = quan ile(.ep ed, 0.975)) %>%
mu a e(ac oss(c(m_p ob, low_c i, up_c i), ~ ound(., 2)))
# A ibble: 7 x 4
age m_p ob low_c i up_c i
<dbl> <dbl> <dbl> <dbl>
1 1 0.56 0.28 0.81
2 2 0.74 0.6 0.86
24
3 3 0.79 0.65 0.89
4 4 0.76 0.58 0.88
5 5 0.64 0.42 0.83
6 6 0.37 0.15 0.73
7 7 0.1 0.02 0.48
# Sex
Age_sex_e ec %>%
il e (b eeding == le els(b eeding)[1], age == 4)%>%
g oup_by(sex_compiled) %>%
summa ise(m_p ob = median(.ep ed),
low_c i = quan ile(.ep ed, 0.025),
up_c i = quan ile(.ep ed, 0.975)) %>%
mu a e(ac oss(c(m_p ob, low_c i, up_c i), ~ ound(., 2)))
# A ibble: 2 x 4
sex_compiled m_p ob low_c i up_c i
< c > <dbl> <dbl> <dbl>
1 0.37 0.18 0.59
2 m 0.76 0.58 0.88
# B eeding e ec
Age_sex_e ec %>%
il e (age == 4, sex_compiled == le els(sex_compiled)[1]) %>%
g oup_by(b eeding) %>%
summa ise(m_p ob = median(.ep ed),
low_c i = quan ile(.ep ed, 0.025),
up_c i = quan ile(.ep ed, 0.975)) %>%
mu a e(ac oss(c(m_p ob, low_c i, up_c i), ~ ound(., 2)))
# A ibble: 2 x 4
b eeding m_p ob low_c i up_c i
< c > <dbl> <dbl> <dbl>
1 0 0.37 0.18 0.59
2 1 0.14 0.07 0.27
Adul s
25