<- c("warbleR", "baRulho", "readxl", "pbapply", "ape", "brms", "phytools", "ggtree", "viridis", "ggplot2", "corrplot", "cowplot", "kableExtra", "tidybayes", "cowplot", "ggrepel", "posterior", "ggridges")
x
<- lapply(x, function(y){
aa if(!y %in% installed.packages()[,"Package"]) {if(y != "warbleR") install.packages(y) else devtools::install_github("maRce10/warbleR")
}try(require(y, character.only = T), silent = T)
})
::opts_knit$set(root.dir = normalizePath(".."))
knitr
::opts_chunk$set(dpi = 80, fig.width = 12, fig.height = 8)
knitr
theme_set(theme_classic(base_size = 30))
<- function(x, ...) {
tibble <- kbl(x, digits=4, align= 'c', row.names = FALSE)
x <- kable_styling(x, position ="center", full_width = FALSE, bootstrap_options = c("striped", "hover", "condensed", "responsive"))
x asis_output(x)
}
registerS3method("knit_print", "data.frame", tibble)
<- function(x) sd(x) / sqrt(length(x))
se
<- function(x, plot = TRUE){
summary_brm_model
<- summary(x)$fixed
summ <- x$fit
fit <- grep("^b_", names(fit@sim$samples[[1]]), value = TRUE)
betas <- t(sapply(betas, function(y) hdi(fit@sim$samples[[1]][[y]]))
hdis
)<- data.frame(summ, hdis, iterations = attr(fit, "stan_args")[[1]]$iter, chains = length(attr(fit, "stan_args")))
summ_table <- summ_table[rownames(summ_table) != "Intercept", c("Estimate", "Rhat", "Bulk_ESS", "l.95..CI", "u.95..CI", "iterations", "chains")]
summ_table
<- as.data.frame(summ_table)
summ_table $Rhat <- round(summ_table$Rhat, digits = 3)
summ_table$CI_low <- round(unlist(summ_table$l.95..CI), digits = 3)
summ_table$CI_high <- round(unlist(summ_table$u.95..CI), digits = 3)
summ_table$l.95..CI <- summ_table$u.95..CI <- NULL
summ_table
<- lapply(betas, function(y) data.frame(variable = y, value = sort(fit@sim$samples[[1]][[y]], decreasing = FALSE)))
out
<- do.call(rbind, out)
posteriors <- posteriors[posteriors$variable != "b_Intercept", ]
posteriors
<- ggplot(data = posteriors, aes(y = variable, x = value, fill = stat(quantile))) +
gg geom_density_ridges_gradient(quantile_lines = TRUE, quantile_fun = HDInterval::hdi, vline_linetype = 2) +
theme_classic() +
xlim(c(min(summ_table[ , "CI_low"]), max(summ_table[ , "CI_high"]))) +
geom_vline(xintercept = 0, col = "red") +
scale_fill_manual(values = c("transparent", "lightblue", "transparent"), guide = "none") + ggtitle(x$formula)
$Rhat <- ifelse(summ_table$Rhat > 1.05, cell_spec(summ_table$Rhat, "html", color ="white", background = "red", bold = TRUE, font_size = 12), cell_spec(summ_table$Rhat, "html"))
summ_table
<- summ_table[,"CI_low"] * summ_table[,"CI_high"] > 0
signif
<- kbl(summ_table, row.names = TRUE, escape = FALSE, format = "html", digits = 3)
df1
<- row_spec(kable_input = df1,row = which(summ_table$CI_low * summ_table$CI_high > 0), background = adjustcolor(cols[9], alpha.f = 0.3))
df1
<- kable_styling(df1, bootstrap_options = c("striped", "hover", "condensed", "responsive"), full_width = FALSE, font_size = 12)
df1
print(df1)
if (plot)
print(gg)
}
<- viridis(10, begin = 0.3, end = 0.8)
cols
print("Closed color:")
## [1] "Closed color:"
10] cols[
## [1] "#7AD151FF"
print("Open color:")
## [1] "Open color:"
1] cols[
## [1] "#35608DFF"
<- read.csv("./data/processed/selection_table_open_and_closed_habitat_shuffled.csv")
master_sels
<- wav_info(path = "./data/raw/recordings")
wi table(wi$sample.rate)
<- list.files(path = "./data/raw/recordings", pattern = "wav$", ignore.case = TRUE)
test_files
<- test_files[grep("TB22", test_files, invert = TRUE)]
test_files
# search template on incomplete re-recorded files (those not including start marker)
<- search_templates(X = master_sels, template.rows = which(master_sels$orig.sound.file =="end_marker"), test.files = test_files, path = "./data/raw/recordings", parallel = 1)
ends
<- align_test_files(X = master_sels, Y = ends, path = "./data/raw/recordings", by.song = TRUE, marker = "end")
alg_complete
<- align_test_files(X = master_sels, Y = ends, path = "./data/raw/recordings", by.song = TRUE, output = "data.frame")
alg_complete_df
<- alg_complete
full_alg
full_spectrograms(X = alg_complete_df, flim = c(1, 13), sxrow = 6, rows = 15, ovlp = 50, fast.spec = TRUE, path = "./data/raw/recordings", wl = 300, parallel = 3, horizontal = TRUE, suffix = "first_day")
<- read_excel("./data/raw/re-recorded_files_metadata.xlsx")
metadat
$transect <- sapply(full_alg$sound.files, function(x) strsplit(x, "-")[[1]][1])
full_alg
$distance <- sapply(full_alg$sound.files, function(x) strsplit(x, "-")[[1]][2])
full_alg
$distance <- as.numeric(gsub("d", "", full_alg$distance))
full_alg
$playback.habitat <- sapply(full_alg$sound.files, function(x) strsplit(x, "-")[[1]][3])
full_alg
$playback.habitat <- sub(".WAV", "", full_alg$playback.habitat, ignore.case = TRUE)
full_alg
$signal.type <- full_alg$template
full_alg
saveRDS(full_alg, "./data/processed/extended_selection_table_re-recorded_aligned_signals.RDS")
<- readRDS("./data/processed/extended_selection_table_re-recorded_aligned_signals.RDS")
full_alg
# remove duplicates to make it run faster
<- full_alg[grep("-dup$", invert = TRUE, full_alg$signal.type), ]
sub_alg
<- 20
prl
# test
<- full_alg[full_alg$transect == "t2" & full_alg$signal.type %in% unique(full_alg$signal.type)[1:3], ]
full_alg
<- data.frame(sub_alg)
sub_alg_df
$blur.ratio <- blur_ratio(sub_alg, method = 1, pb = TRUE, parallel = prl, output = "data.frame")$blur.ratio
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$spectral.blur.ratio <- spectral_blur_ratio(sub_alg, method = 1, pb = TRUE, parallel = prl, output = "data.frame")$spectral.blur.ratio
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$envelope.correlation <- envelope_correlation(sub_alg, method = 1, pb = TRUE, parallel = prl, output = "data.frame")$envelope.correlation
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$spectral_correlation <- spectral_correlation(sub_alg, method = 1, pb = TRUE, parallel = prl, output = "data.frame")$spectral.correlation
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$signal.to.noise.ratio <- signal_to_noise_ratio(sub_alg, pb = TRUE, parallel = prl, noise.ref = "adjacent", mar = 0.01, output = "data.frame")$signal.to.noise.ratio
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$tail.to.signal.ratio <- tail_to_signal_ratio(sub_alg, pb = TRUE, parallel = prl, mar = 0.01, output = "data.frame")$tail.to.signal.ratio
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$cross.correlation <- spcc(X = sub_alg, method = 1, pb = TRUE, parallel = prl, output = "data.frame")$cross.correlation
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
$excess.attenuation <- excess_attenuation(X = sub_alg, method = 1, pb = TRUE, parallel = prl, output = "data.frame")$excess.attenuation
sub_alg_df
write.csv(sub_alg_df, "./data/processed/degradation_measurements.csv", row.names = FALSE)
<- read.csv("./data/processed/degradation_measurements.csv")
degrad
# force them to be numeric
$blur.ratio <- as.numeric(degrad$blur.ratio)
degrad$spectral.blur.ratio <- as.numeric(degrad$spectral.blur.ratio)
degrad$envelope.correlation <- as.numeric(degrad$envelope.correlation)
degrad$spectral_correlation <- as.numeric(degrad$spectral_correlation)
degrad
<- read.csv("./data/processed/selection_table_open_and_closed_habitat_shuffled.csv")
master_sels
# remove markers
<- degrad[grep("marker$", degrad$signal.type, invert = TRUE), ]
degrad
$clade <- sapply(1:nrow(degrad), function(x){
degrad
$clade[master_sels$orig.sound.file == degrad$template[x]]
master_sels
})
$sp.habitat <- sapply(1:nrow(degrad), function(x){
degrad
$habitat[master_sels$orig.sound.file == degrad$template[x]]
master_sels
})
$species <- sapply(1:nrow(degrad), function(x){
degrad
$species[master_sels$orig.sound.file == degrad$template[x]]
master_sels
})
# remove species not in phylogeny
<- degrad[grep("amirae$", degrad$species, invert = TRUE), ]
degrad
$rerec.sound.file <- sapply(degrad$sound.files, function(x) strsplit(x, "-song")[[1]][1])
degrad
<- read.csv("./data/raw/transect_metadata.csv")
transc_metadata
$temperature <- sapply(1:nrow(degrad), function(x){
degrad
$TEMPERATURE[tolower(transc_metadata$SOUND_FILE_NAME) == tolower(degrad$rerec.sound.file[x])]
transc_metadata
})
$humidity <- sapply(1:nrow(degrad), function(x){
degrad
$HUMIDITY[tolower(transc_metadata$SOUND_FILE_NAME) == tolower(degrad$rerec.sound.file[x])]
transc_metadata
})
# remove noise transects
<- degrad[!(degrad$transect %in% c("t10", "t11") & degrad$distance == 10), ]
degrad
<- read_excel("./data/raw/hummingbird_species_body_mass.xlsx")
humm_mass
$size <- sapply(degrad$species, function(x) {
degrad
<- humm_mass$`Body mass (g)`[humm_mass$sp == x]
y if (length(y) == 0) y <- NA
return(y)
})
write.csv(degrad, "./data/processed/degradation_metrics_and_metadata_hummingbirds_and_frogs.csv", row.names = FALSE)
<- read.csv("./data/processed/degradation_metrics_and_metadata_hummingbirds_and_frogs.csv")
degrad
<- read.tree("./data/raw/amph_shl_new_Consensus_7238.tre")
amph_tree
<- read.tree("./data/raw/consensus_tree_swifts_hummingbirds_and_nighjars_max_cred.tree")
full_hmm_tree
<- unique(degrad$species[!grepl("marker", degrad$species) & degrad$clade == "hummingbirds" & !is.na(degrad$clade == "hummingbirds")])
sp_list_humm
<- unique(degrad$species[!grepl("marker", degrad$species) & degrad$clade == "frogs" & !is.na(degrad$clade == "frogs")])
sp_list_frogs
<- drop.tip(full_hmm_tree, tip = setdiff(full_hmm_tree$tip.label, sp_list_humm))
hmm_tree
all(sp_list_humm %in% hmm_tree$tip.label)
all(hmm_tree$tip.label %in% sp_list_humm)
write.tree(hmm_tree, "./data/processed/prunned_hmm_tree.tre")
<- drop.tip(amph_tree, tip = setdiff(amph_tree$tip.label, sp_list_frogs))
frog_tree
all(sp_list_frogs %in% frog_tree$tip.label)
all(frog_tree$tip.label %in% sp_list_frogs)
write.tree(frog_tree, "./data/processed/prunned_frog_tree.tre")
<- read.csv("./data/processed/selection_table_open_and_closed_habitat_shuffled.csv")
master_sels
<- master_sels[master_sels$in.phlogeny == "yes", ]
master_sels
# remove markers
<- master_sels[grep("marker$", invert = TRUE, master_sels$sound.files),]
master_sels
<- as.numeric(as.factor(master_sels$habitat[master_sels$clade == "hummingbirds"]))
hab_humm
names(hab_humm) <- master_sels$species[master_sels$clade == "hummingbirds"]
<- as.numeric(as.factor(master_sels$habitat[master_sels$clade == "frogs"]))
hab_frogs
names(hab_frogs) <- master_sels$species[master_sels$clade == "frogs"]
<- read.tree("./data/processed/prunned_hmm_tree.tre")
humm_tree
ggtree(humm_tree, layout = "slanted") %<+% master_sels[master_sels$clade == "hummingbirds", c("species", "habitat")] + geom_tippoint(aes(color=habitat), size=5, shape = 20) +
scale_colour_viridis(discrete = TRUE, begin = 0.3, end = 0.8, alpha = 0.7) + ggtitle("Hummingbirds") + theme_classic(base_size = 30) + labs(color = "Species\n habitat") + theme(axis.ticks = element_blank(), axis.text = element_blank(), axis.line = element_blank())
<- read.tree("./data/processed/prunned_frog_tree.tre")
frog_tree
ggtree(frog_tree, layout = "slanted", yscale = "none") %<+% master_sels[master_sels$clade == "frogs", c("species", "habitat")] + geom_tippoint(aes(color=habitat), size=5, shape = 20) +
scale_colour_viridis(discrete = TRUE, begin = 0.3, end = 0.8, alpha = 0.7) + ggtitle("Frogs") + labs(color = "Species\n habitat") + theme_classic(base_size = 30) + theme(axis.ticks = element_blank(), axis.text = element_blank(), axis.line = element_blank())
Hummingbirds
<- read.csv("./data/processed/degradation_metrics_and_metadata_hummingbirds_and_frogs.csv")
degrad
<- degrad[degrad$clade == "hummingbirds", ]
humm_degrad
$phylo <- humm_degrad$species
humm_degrad
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation")
preds
<- cor(humm_degrad[, preds], use = "pairwise.complete.obs")
cormat
corrplot.mixed(cormat)
<- complete.cases(humm_degrad[, preds])
which.complete
<- prcomp(humm_degrad[which.complete, preds],scale. = TRUE)
pca
summary(pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 1.8376 1.0010 0.9922 0.78357 0.6551 0.58907 0.49689
## Proportion of Variance 0.4824 0.1431 0.1406 0.08771 0.0613 0.04957 0.03527
## Cumulative Proportion 0.4824 0.6255 0.7661 0.85386 0.9152 0.96473 1.00000
$rotation pca
## PC1 PC2 PC3 PC4
## blur.ratio -0.42422661 0.07708185 -0.11033943 0.58391475
## spectral.blur.ratio -0.43871973 0.01576826 0.01605090 -0.56325611
## envelope.correlation 0.44548111 -0.13492961 0.23426212 -0.38769472
## spectral_correlation 0.44614461 -0.03985244 0.09208775 0.40368913
## signal.to.noise.ratio 0.16539564 0.40041103 -0.84841333 -0.16228868
## tail.to.signal.ratio 0.44940815 0.05981115 -0.12607154 0.04528832
## excess.attenuation -0.02711006 -0.90006065 -0.43417678 0.01119672
## PC5 PC6 PC7
## blur.ratio -0.442567606 -0.39391984 -0.33154189
## spectral.blur.ratio -0.142409894 -0.54896246 0.41002553
## envelope.correlation -0.224770836 -0.36571142 -0.62760487
## spectral_correlation 0.370724734 -0.61467362 0.33565044
## signal.to.noise.ratio 0.149197488 -0.13645927 -0.15903293
## tail.to.signal.ratio -0.757353751 0.11432303 0.43572402
## excess.attenuation -0.007069975 -0.01442204 0.01621906
$pca1.degradation <- NA
humm_degrad
$pca1.degradation[which.complete] <- pca$x[, 1] * -1
humm_degrad
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- lapply(preds, function(x){
ggs
# plot histogram
ggplot(data = humm_degrad, mapping = aes(x = get(x))) +
labs(x = x) +
geom_histogram(fill = cols[10])
})
::plot_grid(plotlist = ggs, nrow = 4) cowplot
print("After transforming")
## [1] "After transforming"
<- lapply(preds, function(x){
ggs
<- humm_degrad
Y !is.na(Y[, x]), x] <- log(Y[!is.na(Y[, x]), x] + abs(min(Y[!is.na(Y[, x]), x])) + 1)
Y[
# plot histogram
ggplot(data = Y, mapping = aes(x = get(x))) +
labs(x = x) +
geom_histogram(fill = cols[10])
})
::plot_grid(plotlist = ggs, nrow = 4) cowplot
Frogs
<- read.csv("./data/processed/degradation_metrics_and_metadata_hummingbirds_and_frogs.csv")
degrad
<- degrad[degrad$clade == "frogs", ]
frog_degrad
$phylo <- frog_degrad$species
frog_degrad
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation")
preds
<- cor(frog_degrad[, preds], use = "pairwise.complete.obs")
cormat
corrplot.mixed(cormat)
<- complete.cases(frog_degrad[, preds])
which.complete
<- prcomp(frog_degrad[which.complete, preds],scale. = TRUE)
pca
summary(pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 1.5773 1.1715 1.0006 0.8546 0.82804 0.66793 0.52558
## Proportion of Variance 0.3554 0.1961 0.1430 0.1043 0.09795 0.06373 0.03946
## Cumulative Proportion 0.3554 0.5515 0.6945 0.7988 0.89680 0.96054 1.00000
$rotation pca
## PC1 PC2 PC3 PC4
## blur.ratio -0.45812142 0.38623868 -0.007587817 -0.25390189
## spectral.blur.ratio -0.39324518 -0.29739172 -0.045422275 0.52861424
## envelope.correlation 0.35445934 -0.62272717 0.007517892 0.19404464
## spectral_correlation 0.42073609 -0.07482098 0.030458467 -0.54772403
## signal.to.noise.ratio 0.32265464 0.53032340 -0.022184720 0.53527684
## tail.to.signal.ratio 0.47810182 0.29558897 -0.037764220 0.16975946
## excess.attenuation -0.01163411 0.01935948 0.997485191 0.05573429
## PC5 PC6 PC7
## blur.ratio 0.36220879 0.27672919 -0.60716262
## spectral.blur.ratio 0.61507278 0.09437001 0.29698479
## envelope.correlation 0.05936817 0.11374776 -0.65756862
## spectral_correlation 0.66422584 -0.22462553 0.15748347
## signal.to.noise.ratio 0.19003270 -0.48497383 -0.23733009
## tail.to.signal.ratio 0.09662412 0.78418133 0.17182791
## excess.attenuation 0.01791857 0.03130659 0.01027921
$pca1.degradation <- NA
frog_degrad
$pca1.degradation[which.complete] <- pca$x[, 1] * -1
frog_degrad
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- lapply(preds, function(x){
ggs
# plot histogram
ggplot(data = frog_degrad, mapping = aes(x = get(x))) +
labs(x = x) +
geom_histogram(fill = cols[10])
})
::plot_grid(plotlist = ggs, nrow = 4) cowplot
print("After transforming")
## [1] "After transforming"
<- lapply(preds, function(x){
ggs
<- frog_degrad
Y !is.na(Y[, x]), x] <- log(Y[!is.na(Y[, x]), x] + abs(min(Y[!is.na(Y[, x]), x])) + 1)
Y[
# plot histogram
ggplot(data = Y, mapping = aes(x = get(x))) +
labs(x = x) +
geom_histogram(fill = cols[10])
})
::plot_grid(plotlist = ggs, nrow = 4) cowplot
<- read.tree("./data/processed/prunned_hmm_tree.tre")
humm_tree
all(all(humm_tree$tip.label %in% humm_degrad$species),
all(humm_degrad$species %in% humm_tree$tip.label))
<- ape::vcv.phylo(humm_tree)
inv_phylo
<- 3000
itrn <- 4
chains
$phylo <- humm_degrad$species
humm_degrad$distance.cat <- as.character(humm_degrad$distance)
humm_degrad
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- c(habitat.only = "~ playback.habitat + (1|gr(phylo, cov = A)) + (1|species) + (1 | transect) + (1 | signal.type)",
base_models habitat.by.species = "~ playback.habitat * sp.habitat + (1|gr(phylo, cov = A)) + (1|species) + (1 | transect) + (1 | signal.type)",
null.model =
"~ 1 + (1|gr(phylo, cov = A)) + (1|species) + (1 | transect) + (1 | signal.type)")
# pca.1.models <- gsub("response", "pca1.degradation", models)
<- paste(rep(preds, each = 3), base_models)
models
names(models) <- paste(rep(preds, each = 3), names(base_models))
<- lapply(models, function(x){
mods
<- brm(x,
md data = humm_degrad[humm_degrad$distance == 20, ],
family = gaussian(),
data2 = list(A = inv_phylo),
sample_prior = TRUE, chains = chains, cores = chains,
iter = itrn
)<- add_criterion(md, "loo")
md
return(md)
})
names(mods) <- names(models)
saveRDS(mods, "./output/models_habitat_sound_degradation_hummingbirds.RDS")
<- readRDS("./output/models_habitat_sound_degradation_hummingbirds.RDS")
mods
for(i in 1:length(mods)){
print(names(mods)[i])
summary_brm_model(mods[[i]], plot = FALSE)
}
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.02 | 1.01 | 1194.041 | 3000 | 4 | -0.062 | 0.02 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.021 | 1.002 | 2968.173 | 3000 | 4 | -0.064 | 0.020 |
sp.habitatopen | 0.006 | 1.001 | 1696.861 | 3000 | 4 | -0.023 | 0.035 |
playback.habitatopen:sp.habitatopen | 0.001 | 1.001 | 7669.907 | 3000 | 4 | -0.010 | 0.011 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.073 | 1.003 | 1896.638 | 3000 | 4 | -0.3 | 0.149 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.077 | 1.003 | 1887.722 | 3000 | 4 | -0.309 | 0.160 |
sp.habitatopen | -0.062 | 1.001 | 2263.998 | 3000 | 4 | -0.109 | -0.015 |
playback.habitatopen:sp.habitatopen | 0.000 | 1 | 10419.003 | 3000 | 4 | -0.023 | 0.023 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.069 | 1.002 | 1972.58 | 3000 | 4 | -0.075 | 0.221 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.081 | 1.001 | 2245.202 | 3000 | 4 | -0.073 | 0.232 |
sp.habitatopen | 0.092 | 1.001 | 2037.779 | 3000 | 4 | 0.017 | 0.165 |
playback.habitatopen:sp.habitatopen | -0.015 | 1 | 9733.527 | 3000 | 4 | -0.048 | 0.019 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.097 | 1.004 | 1527.642 | 3000 | 4 | -0.272 | 0.446 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.108 | 1.003 | 1549.442 | 3000 | 4 | -0.248 | 0.458 |
sp.habitatopen | 0.093 | 1.001 | 1695.011 | 3000 | 4 | -0.031 | 0.218 |
playback.habitatopen:sp.habitatopen | -0.006 | 1.001 | 7878.486 | 3000 | 4 | -0.070 | 0.060 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.138 | 1.01 | 1599.121 | 3000 | 4 | -2.391 | 2.07 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.316 | 1.001 | 3371.965 | 3000 | 4 | -2.579 | 2.084 |
sp.habitatopen | -0.350 | 1.001 | 2568.952 | 3000 | 4 | -1.733 | 0.984 |
playback.habitatopen:sp.habitatopen | 0.282 | 1 | 11354.265 | 3000 | 4 | -0.206 | 0.775 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 2.296 | 1 | 1688.103 | 3000 | 4 | -0.128 | 4.847 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 2.360 | 1.002 | 1744.868 | 3000 | 4 | -0.210 | 5.046 |
sp.habitatopen | 1.317 | 1.001 | 1469.278 | 3000 | 4 | -0.154 | 2.770 |
playback.habitatopen:sp.habitatopen | 0.021 | 1.001 | 9233.236 | 3000 | 4 | -0.677 | 0.725 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 1.308 | 1.002 | 2499.761 | 3000 | 4 | -4.075 | 6.716 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 4.330 | 1 | 2953.673 | 3000 | 4 | -2.255 | 10.964 |
sp.habitatopen | 2.877 | 1 | 5558.623 | 3000 | 4 | -0.386 | 6.197 |
playback.habitatopen:sp.habitatopen | -4.084 | 1 | 4993.579 | 3000 | 4 | -9.178 | 1.092 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.751 | 1.001 | 2199.061 | 3000 | 4 | -2.528 | 0.992 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.792 | 1.001 | 2271.619 | 3000 | 4 | -2.560 | 0.952 |
sp.habitatopen | -0.627 | 1.001 | 2379.023 | 3000 | 4 | -1.162 | -0.087 |
playback.habitatopen:sp.habitatopen | 0.038 | 1.001 | 14944.611 | 3000 | 4 | -0.210 | 0.291 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
<- read.tree("./data/processed/prunned_frog_tree.tre")
frog_tree
all(all(frog_tree$tip.label %in% frog_degrad$species),
all(frog_degrad$species %in% frog_tree$tip.label))
<- ape::vcv.phylo(frog_tree)
inv_phylo
<- 4000
itrn <- 4
chains
$phylo <- frog_degrad$species
frog_degrad$distance.cat <- as.character(frog_degrad$distance)
frog_degrad
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- c(habitat.only = "~ playback.habitat + (1|gr(phylo, cov = A)) + (1|species) + (1 | transect) + (1 | signal.type)",
base_models habitat.by.species = "~ playback.habitat * sp.habitat + (1|gr(phylo, cov = A)) + (1|species) + (1 | transect) + (1 | signal.type)",
null.model =
"~ 1 + (1|gr(phylo, cov = A)) + (1|species) + (1 | transect) + (1 | signal.type)")
<- paste(rep(preds, each = 3), base_models)
models
names(models) <- paste(rep(preds, each = 3), names(base_models))
<- lapply(models, function(x){
mods
<- brm(x,
md data = frog_degrad[frog_degrad$distance == 20, ],
family = gaussian(),
data2 = list(A = inv_phylo),
sample_prior = TRUE, chains = chains, cores = chains,
iter = itrn
)<- add_criterion(md, "loo")
md
return(md)
})
names(mods) <- names(models)
saveRDS(mods, "./output/models_habitat_sound_degradation_frogs.RDS")
<- readRDS("./output/models_habitat_sound_degradation_hummingbirds.RDS")
mods
for(i in 1:length(mods)){
print(names(mods)[i])
summary_brm_model(mods[[i]], plot = FALSE)
}
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.02 | 1.01 | 1194.041 | 3000 | 4 | -0.062 | 0.02 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.021 | 1.002 | 2968.173 | 3000 | 4 | -0.064 | 0.020 |
sp.habitatopen | 0.006 | 1.001 | 1696.861 | 3000 | 4 | -0.023 | 0.035 |
playback.habitatopen:sp.habitatopen | 0.001 | 1.001 | 7669.907 | 3000 | 4 | -0.010 | 0.011 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.073 | 1.003 | 1896.638 | 3000 | 4 | -0.3 | 0.149 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.077 | 1.003 | 1887.722 | 3000 | 4 | -0.309 | 0.160 |
sp.habitatopen | -0.062 | 1.001 | 2263.998 | 3000 | 4 | -0.109 | -0.015 |
playback.habitatopen:sp.habitatopen | 0.000 | 1 | 10419.003 | 3000 | 4 | -0.023 | 0.023 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.069 | 1.002 | 1972.58 | 3000 | 4 | -0.075 | 0.221 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.081 | 1.001 | 2245.202 | 3000 | 4 | -0.073 | 0.232 |
sp.habitatopen | 0.092 | 1.001 | 2037.779 | 3000 | 4 | 0.017 | 0.165 |
playback.habitatopen:sp.habitatopen | -0.015 | 1 | 9733.527 | 3000 | 4 | -0.048 | 0.019 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.097 | 1.004 | 1527.642 | 3000 | 4 | -0.272 | 0.446 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 0.108 | 1.003 | 1549.442 | 3000 | 4 | -0.248 | 0.458 |
sp.habitatopen | 0.093 | 1.001 | 1695.011 | 3000 | 4 | -0.031 | 0.218 |
playback.habitatopen:sp.habitatopen | -0.006 | 1.001 | 7878.486 | 3000 | 4 | -0.070 | 0.060 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.138 | 1.01 | 1599.121 | 3000 | 4 | -2.391 | 2.07 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.316 | 1.001 | 3371.965 | 3000 | 4 | -2.579 | 2.084 |
sp.habitatopen | -0.350 | 1.001 | 2568.952 | 3000 | 4 | -1.733 | 0.984 |
playback.habitatopen:sp.habitatopen | 0.282 | 1 | 11354.265 | 3000 | 4 | -0.206 | 0.775 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 2.296 | 1 | 1688.103 | 3000 | 4 | -0.128 | 4.847 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 2.360 | 1.002 | 1744.868 | 3000 | 4 | -0.210 | 5.046 |
sp.habitatopen | 1.317 | 1.001 | 1469.278 | 3000 | 4 | -0.154 | 2.770 |
playback.habitatopen:sp.habitatopen | 0.021 | 1.001 | 9233.236 | 3000 | 4 | -0.677 | 0.725 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 1.308 | 1.002 | 2499.761 | 3000 | 4 | -4.075 | 6.716 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | 4.330 | 1 | 2953.673 | 3000 | 4 | -2.255 | 10.964 |
sp.habitatopen | 2.877 | 1 | 5558.623 | 3000 | 4 | -0.386 | 6.197 |
playback.habitatopen:sp.habitatopen | -4.084 | 1 | 4993.579 | 3000 | 4 | -9.178 | 1.092 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.751 | 1.001 | 2199.061 | 3000 | 4 | -2.528 | 0.992 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
playback.habitatopen | -0.792 | 1.001 | 2271.619 | 3000 | 4 | -2.560 | 0.952 |
sp.habitatopen | -0.627 | 1.001 | 2379.023 | 3000 | 4 | -1.162 | -0.087 |
playback.habitatopen:sp.habitatopen | 0.038 | 1.001 | 14944.611 | 3000 | 4 | -0.210 | 0.291 |
Estimate | Rhat | Bulk_ESS | iterations | chains | CI_low | CI_high | |
---|---|---|---|---|---|---|---|
<- pblapply(preds, cl = 1, function(i){
mods_closed
<- degrad[!(is.na(degrad[, i]) | is.infinite(degrad[, i])), ]
subdat <- subdat[subdat$habitat == "closed", ]
subdat
<- try(MCMCglmm(as.formula(paste(i, " ~ distance * sp_habitat + size")), random = ~ equipment + transect + signal.type + phylo, data = subdat, verbose = FALSE, ginverse = list(phylo = inv.phylo$Ainv), nitt = itrn), silent = TRUE)
mod
if(!is(mod, "try-error"))
return(mod) else
return(NULL)
})names(mods_closed) <- preds
saveRDS(mods_closed, "./output/mcmcglmm_models_habitat_by_distance_sound_degradation_in_closed_habitat.RDS")
<- pblapply(preds, cl = 1, function(i){
mods_open
<- degrad[!(is.na(degrad[, i]) | is.infinite(degrad[, i])), ]
subdat <- subdat[subdat$habitat == "open", ]
subdat
<- try(MCMCglmm(as.formula(paste(i, " ~ distance * sp_habitat + size")), random = ~ equipment + transect + signal.type + phylo, data = subdat, verbose = FALSE, ginverse = list(phylo = inv.phylo$Ainv), nitt = itrn), silent = TRUE)
mod
if(!is(mod, "try-error"))
return(mod) else
return(NULL)
})names(mods_open) <- preds
saveRDS(mods_open, "./output/mcmcglmm_models_habitat_by_distance_sound_degradation_in_open_habitat.RDS")
<- read_wave("./data/raw/recordings/ETC21_duplicated_master_44.1.wav")
wv
library(dynaSpec)
scrolling_spectro(wave = wv, wl = 400,
t.display = 1, ovlp = 95, pal = inferno,
grid = FALSE, flim = c(1, 13), width = 900,
height = 250, res = 100, collevels = seq(-40, 0, 5),
file.name = "./output/playback_full_osc.mp4", colbg = "black", lcol = "#FFFFFFE6",
speed = 0.7, fps = 200, buffer = 0, loop = 1, lty = 1,
osc = TRUE, colwave = inferno(10, alpha = 0.9)[3])
scrolling_spectro(wave = wv, wl = 400, lower.spectro = TRUE,
t.display = 1, ovlp = 95, pal = inferno,
grid = FALSE, flim = c(1, 13), width = 900,
height = 400, res = 100, collevels = seq(-40, 0, 5),
file.name = "./output/playback_full.mp4", colbg = "black", lcol = "#FFFFFFE6",
speed = 0.7, fps = 200, buffer = 0, loop = 1, lty = 1,
osc = FALSE, colwave = inferno(10, alpha = 0.9)[3])
scrolling_spectro(wave = wv, wl = 400, lower.spectro = TRUE,axis.type = "minimal",
t.display = 1, ovlp = 95, pal = inferno,
grid = FALSE, flim = c(1, 13), width = 900,
height = 400, res = 100, collevels = seq(-40, 0, 5),
file.name = "./output/playback_full_minimal.mp4", colbg = "black", lcol = "#FFFFFFE6",
speed = 0.7, fps = 200, buffer = 0, loop = 1, lty = 1,
osc = FALSE, colwave = inferno(10, alpha = 0.9)[3])
scrolling_spectro(wave = wv, wl = 400, lower.spectro = TRUE,axis.type = "none",
t.display = 1, ovlp = 95, pal = inferno,
grid = FALSE, flim = c(1, 13), width = 900,
height = 400, res = 100, collevels = seq(-40, 0, 5),
file.name = "./output/playback_full_no_axis.mp4", colbg = "black", lcol = "#FFFFFFE6",
speed = 0.7, fps = 200, buffer = 0, loop = 1, lty = 1,
osc = FALSE, colwave = inferno(10, alpha = 0.9)[3])
# master_sels <- read.csv("./data/processed/selection_table_open_and_closed_habitat_shuffled.csv")
<- read.csv("./data/processed/degradation_metrics_and_metadata_hummingbirds_and_frogs.csv")
degrad
# master_sels <- master_sels[master_sels$in.phlogeny == "yes", ]
# # remove markers
# master_sels <- master_sels[grep("marker$", invert = TRUE, master_sels$sound.files),]
# number of especies per clade in open habitat
print("number of especies per clade in open habitat")
## [1] "number of especies per clade in open habitat"
table(degrad$sp.habitat[!duplicated(degrad$species)], degrad$clade[!duplicated(degrad$species)])
##
## frogs hummingbirds
## closed 20 14
## open 20 35
# mean number of sounds per especies
print("mean number of sounds per especies")
## [1] "mean number of sounds per especies"
mean(table(degrad$species[degrad$transect == "t1" & degrad$distance == 1]))
## [1] 2.505618
print("range of number of sounds per especies")
## [1] "range of number of sounds per especies"
range(table(degrad$species[degrad$transect == "t1" & degrad$distance == 1]))
## [1] 1 5
# number of signals
print("number of signals (sounds)")
## [1] "number of signals (sounds)"
length(unique(degrad$signal.type))
## [1] 223
print("number of signals per clade")
## [1] "number of signals per clade"
aggregate(signal.type ~ clade, data = degrad, FUN = function(x) length(unique(x)))
clade | signal.type |
---|---|
frogs | 130 |
hummingbirds | 93 |
print("total number of signals")
## [1] "total number of signals"
nrow(degrad)
## [1] 10481
print("total number of signals per clade")
## [1] "total number of signals per clade"
tapply(1:nrow(degrad), degrad$clade, length)
## frogs hummingbirds
## 6110 4371
print("species per habitat")
## [1] "species per habitat"
<- degrad[!duplicated(degrad$species), c("clade", "species", "sp.habitat")]
sub_degrad
order(sub_degrad$clade, sub_degrad$sp.habitat), ] sub_degrad[
clade | species | sp.habitat |
---|---|---|
frogs | Craugastor_melanostictus | closed |
frogs | Aplastodiscus_cochranae | closed |
frogs | Proceratophrys_concavitympanum | closed |
frogs | Dendropsophus_ebraccatus | closed |
frogs | Diasporus_ventrimaculatus | closed |
frogs | Isthmohyla_zeteki | closed |
frogs | Craugastor_crassidigitus | closed |
frogs | Odontophrynus_carvalhoi | closed |
frogs | Hypsiboas_rufitelus | closed |
frogs | Craugastor_talamancae | closed |
frogs | Diasporus_hylaeformis | closed |
frogs | Diasporus_diastema | closed |
frogs | Craugastor_fitzingeri | closed |
frogs | Anotheca_spinosa | closed |
frogs | Pristimantis_cruentus | closed |
frogs | Syncope_bassleri | closed |
frogs | Oophaga_pumilio | closed |
frogs | Pristimantis_altae | closed |
frogs | Dendrobates_auratus | closed |
frogs | Allobates_talamancae | closed |
frogs | Leptodactylus_fragilis | open |
frogs | Scinax_x-signatus | open |
frogs | Scinax_boulengeri | open |
frogs | Hypsiboas_raniceps | open |
frogs | Leptodactylus_savagei | open |
frogs | Phyllomedusa_nordestina | open |
frogs | Leptodactylus_insularum | open |
frogs | Hypsiboas_albopunctatus | open |
frogs | Scinax_staufferi | open |
frogs | Smilisca_puma | open |
frogs | Smilisca_phaeota | open |
frogs | Dendropsophus_phlebodes | open |
frogs | Hypsiboas_rosenbergi | open |
frogs | Hypsiboas_albomarginatus | open |
frogs | Engystomops_pustulosus | open |
frogs | Isthmohyla_pseudopuma | open |
frogs | Scinax_elaeochroa | open |
frogs | Incilius_coniferus | open |
frogs | Leptodactylus_poecilochilus | open |
frogs | Incilius_luetkenii | open |
hummingbirds | Calypte_anna | closed |
hummingbirds | Oreotrochilus_melanogaster | closed |
hummingbirds | Amazilia_yucatanensis | closed |
hummingbirds | Phaethornis_koepckeae | closed |
hummingbirds | Phaethornis_malaris | closed |
hummingbirds | Glaucis_hirsutus | closed |
hummingbirds | Sappho_sparganurus | closed |
hummingbirds | Polytmus_guainumbi | closed |
hummingbirds | Metallura_phoebe | closed |
hummingbirds | Eupetomena_macroura | closed |
hummingbirds | Phaethornis_bourcieri | closed |
hummingbirds | Glaucis_dohrnii | closed |
hummingbirds | Threnetes_leucurus | closed |
hummingbirds | Oxypogon_stubelii | closed |
hummingbirds | Amazilia_cyanifrons | open |
hummingbirds | Campylopterus_villaviscensio | open |
hummingbirds | Lepidopyga_goudoti | open |
hummingbirds | Oreotrochilus_estella | open |
hummingbirds | Calypte_costae | open |
hummingbirds | Lepidopyga_lilliae | open |
hummingbirds | Eriocnemis_cupreoventris | open |
hummingbirds | Anthracothorax_veraguensis | open |
hummingbirds | Chlorostilbon_alice | open |
hummingbirds | Chalcostigma_stanleyi | open |
hummingbirds | Metallura_eupogon | open |
hummingbirds | Heliodoxa_gularis | open |
hummingbirds | Anthracothorax_nigricollis | open |
hummingbirds | Myrtis_fanny | open |
hummingbirds | Ramphodon_naevius | open |
hummingbirds | Oxypogon_guerinii | open |
hummingbirds | Phaethornis_squalidus | open |
hummingbirds | Metallura_theresiae | open |
hummingbirds | Doryfera_johannae | open |
hummingbirds | Heliactin_bilophus | open |
hummingbirds | Coeligena_wilsoni | open |
hummingbirds | Phaethornis_aethopygus | open |
hummingbirds | Selasphorus_flammula | open |
hummingbirds | Oreotrochilus_adela | open |
hummingbirds | Heliomaster_furcifer | open |
hummingbirds | Phaethornis_hispidus | open |
hummingbirds | Heliodoxa_schreibersii | open |
hummingbirds | Anthocephala_floriceps | open |
hummingbirds | Amazilia_versicolor | open |
hummingbirds | Metallura_williami | open |
hummingbirds | Phaethornis_longuemareus | open |
hummingbirds | Chrysolampis_mosquitus | open |
hummingbirds | Chlorestes_notata | open |
hummingbirds | Androdon_aequatorialis | open |
hummingbirds | Aglaeactis_cupripennis | open |
Hummingbirds
theme_set(theme_classic(base_size = 24))
<- humm_degrad[humm_degrad$distance != 40, ]
humm_degrad
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat, humm_degrad, FUN = se)
agg_deg_humm
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat, humm_degrad, FUN = se)
se.humm
names(se.humm) <- paste0(names(se.humm), ".se")
<- data.frame(agg_deg_humm, se.humm)
agg_deg_humm
$se <- aggregate(pca1.degradation ~ playback.habitat + sp.habitat, humm_degrad, FUN = se)$pca1.degradation
agg_deg_humm
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- lapply(preds, function(x){
ggs
<- paste(x, "se", sep = ".")
x.se
ggplot(agg_deg_humm, aes(x = playback.habitat, y = get(x), color = sp.habitat)) + geom_pointrange(aes(ymin = get(x) - get(x.se), ymax = get(x) + get(x.se)), position = position_dodge(width = 0.5), size = 2) + labs(x = "Playback habitat", y = x, color = "Species\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7)
})
::plot_grid(plotlist = ggs, ncol = 2) cowplot
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat + distance, humm_degrad, FUN = se)
agg_deg_humm
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat + distance, humm_degrad, FUN = se)
se.humm
names(se.humm) <- paste0(names(se.humm), ".se")
<- data.frame(agg_deg_humm, se.humm)
agg_deg_humm
# agg_deg_humm$se <- aggregate(pca1.degradation ~ playback.habitat + sp.habitat, humm_degrad, FUN = se)$pca1.degradation
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- lapply(preds, function(x){
ggs
<- paste(x, "se", sep = ".")
x.se
ggplot(agg_deg_humm, aes(x = distance, y = get(x), color = sp.habitat, shape = playback.habitat)) + geom_pointrange(aes(ymin = get(x) - get(x.se), ymax = get(x) + get(x.se)), position = position_dodge(width = 1.5), size = 1.2) + geom_line(position = position_dodge(width = 1.5)) +
labs(x = "Distance", y = x, color = "Species\n habitat", shape = "Playback\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7)
})
::plot_grid(plotlist = ggs, ncol = 1) cowplot
Frogs
<- frog_degrad[frog_degrad$distance != 40, ]
frog_degrad
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat, frog_degrad, FUN = se)
agg_deg_frog
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat, frog_degrad, FUN = se)
se.frog
names(se.frog) <- paste0(names(se.frog), ".se")
<- data.frame(agg_deg_frog, se.frog)
agg_deg_frog
$se <- aggregate(pca1.degradation ~ playback.habitat + sp.habitat, frog_degrad, FUN = se)$pca1.degradation
agg_deg_frog
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- lapply(preds, function(x){
ggs
<- paste(x, "se", sep = ".")
x.se
ggplot(agg_deg_frog, aes(x = playback.habitat, y = get(x), color = sp.habitat)) + geom_pointrange(aes(ymin = get(x) - get(x.se), ymax = get(x) + get(x.se)), position = position_dodge(width = 0.5), size = 2) + labs(x = "Playback habitat", y = x, color = "Species\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7)
})
::plot_grid(plotlist = ggs, ncol = 2) cowplot
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat + distance, frog_degrad, FUN = se)
agg_deg_frog
<- aggregate(cbind(blur.ratio, spectral.blur.ratio, envelope.correlation, spectral_correlation, signal.to.noise.ratio, tail.to.signal.ratio, excess.attenuation, pca1.degradation) ~ playback.habitat + sp.habitat + distance, frog_degrad, FUN = se)
se.frog
names(se.frog) <- paste0(names(se.frog), ".se")
<- data.frame(agg_deg_frog, se.frog)
agg_deg_frog
# agg_deg_frog$se <- aggregate(pca1.degradation ~ playback.habitat + sp.habitat, frog_degrad, FUN = se)$pca1.degradation
<- c("blur.ratio", "spectral.blur.ratio", "envelope.correlation", "spectral_correlation", "signal.to.noise.ratio", "tail.to.signal.ratio", "excess.attenuation", "pca1.degradation")
preds
<- lapply(preds, function(x){
ggs
<- paste(x, "se", sep = ".")
x.se
ggplot(agg_deg_frog, aes(x = distance, y = get(x), color = sp.habitat, shape = playback.habitat)) + geom_pointrange(aes(ymin = get(x) - get(x.se), ymax = get(x) + get(x.se)), position = position_dodge(width = 1.5), size = 1.2) + geom_line(position = position_dodge(width = 1.5)) +
labs(x = "Distance", y = x, color = "Species\n habitat", shape = "Playback\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7)
})
::plot_grid(plotlist = ggs, ncol = 1) cowplot
theme_set(theme_classic(base_size = 30))
# set seed
set.seed(13)
# number of observations
<- 300
n <- 4
b0 <- 0
b1 <- 0
b2 <- rnorm(n = n, mean = 0, sd = 1)
error
# random variables
<- sample(0:1, size = n, replace = TRUE)
x1_num <- sample(0:1, size = n, replace = TRUE)
x2_num
<- b0 + b1 * x1_num + b2* x2_num + error
y
<- factor(x1_num, labels = c("Open", "Closed"))
sp_hab
<- factor(x2_num, labels = c("Open", "Closed"))
playb_hab
# create data frame
<- data.frame(sp_hab, x1_num, playb_hab, x2_num, y)
xy_data_cat
<- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = mean)
agg_xy
$sd <- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = sd)$y
agg_xy
ggplot(agg_xy, aes(x = playb_hab, y = y, color = sp_hab)) + geom_pointrange(aes(ymin = y - sd, ymax = y + sd), position = position_dodge(width = 0.5), size = 2) + labs(x = "Playback habitat", y = "- Degradation +", color = "Species\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7) + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())
# set seed
set.seed(13)
# number of observations
<- 300
n <- 4
b0 <- 0
b1 <- 2
b2 <- rnorm(n = n, mean = 0, sd = 1)
error
# random variables
<- sample(0:1, size = n, replace = TRUE)
x1_num <- sample(0:1, size = n, replace = TRUE)
x2_num
<- b0 + b1 * x1_num + b2* x2_num + error
y
<- factor(x1_num, labels = c("Open", "Closed"))
sp_hab
<- factor(x2_num, labels = c("Open", "Closed"))
playb_hab
# create data frame
<- data.frame(sp_hab, x1_num, playb_hab, x2_num, y)
xy_data_cat
<- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = mean)
agg_xy
$sd <- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = sd)$y
agg_xy
ggplot(agg_xy, aes(x = playb_hab, y = y, color = sp_hab)) + geom_pointrange(aes(ymin = y - sd, ymax = y + sd), position = position_dodge(width = 0.5), size = 2) + labs(x = "Playback habitat", y = "- Degradation +", color = "Species\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7) + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())
# set seed
set.seed(13)
# number of observations
<- 300
n <- 4
b0 <- -2
b1 <- 2
b2 <- rnorm(n = n, mean = 0, sd = 1)
error
# random variables
<- sample(0:1, size = n, replace = TRUE)
x1_num <- sample(0:1, size = n, replace = TRUE)
x2_num
<- b0 + b1 * x1_num + b2* x2_num + error
y
<- factor(x1_num, labels = c("Open", "Closed"))
sp_hab
<- factor(x2_num, labels = c("Open", "Closed"))
playb_hab
# create data frame
<- data.frame(sp_hab, x1_num, playb_hab, x2_num, y)
xy_data_cat
<- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = mean)
agg_xy
$sd <- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = sd)$y
agg_xy
ggplot(agg_xy, aes(x = playb_hab, y = y, color = sp_hab)) + geom_pointrange(aes(ymin = y - sd, ymax = y + sd), position = position_dodge(width = 0.5), size = 2) + labs(x = "Playback habitat", y = "- Degradation +", color = "Species\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7) + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())
# set seed
set.seed(13)
# number of observations
<- 300
n <- 4
b0 <- 2
b1 <- 3
b2 <- -4
b3 <- rnorm(n = n, mean = 0, sd = 1)
error
# random variables
<- sample(0:1, size = n, replace = TRUE)
x1_num <- sample(0:1, size = n, replace = TRUE)
x2_num
<- b0 + b1 * x1_num + b2 * x2_num + b3 * x1_num * x2_num + error
y
<- factor(x1_num, labels = c("Open", "Closed"))
sp_hab
<- factor(x2_num, labels = c("Open", "Closed"))
playb_hab
# create data frame
<- data.frame(sp_hab, x1_num, playb_hab, x2_num, y)
xy_data_cat
<- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = mean)
agg_xy
$sd <- aggregate(y ~ sp_hab + playb_hab, xy_data_cat, FUN = sd)$y
agg_xy
ggplot(agg_xy, aes(x = playb_hab, y = y, color = sp_hab)) + geom_pointrange(aes(ymin = y - sd, ymax = y + sd), position = position_dodge(width = 0.5), size = 2) + labs(x = "Playback habitat", y = "- Degradation +", color = "Species\n habitat") + scale_color_viridis_d(begin = 0.3, end = 0.8, alpha = 0.7) + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())