Skip to content

Commit

Permalink
Start Mayfield calculations [no version bump]
Browse files Browse the repository at this point in the history
  • Loading branch information
gmyenni committed May 3, 2024
1 parent 473f87d commit 52ed23f
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 17 deletions.
166 changes: 166 additions & 0 deletions DataCleaningScripts/mayfield.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#' Do summary calculations
#'

`%>%` <- magrittr::`%>%`
success_summary <- read.csv("Nesting/nest_success_summary.csv")
species <- read.csv("SiteandMethods/species_list.csv")
success <- read.csv("Nesting/nest_success.csv") %>%
dplyr::filter(year>=2017) %>%
merge(species[,c(1,5,6)]) %>%
# make consistent use of success columns
dplyr::mutate(incubation_success = dplyr::case_when(is.na(incubation_success) & brood %in% c(1:10) ~ 1,
is.na(incubation_success) & fledged %in% c(1:10) ~ 1,
TRUE ~ incubation_success),
nestling_success = dplyr::case_when(is.na(nestling_success) & fledged %in% c(1:10) ~ 1,
TRUE ~ nestling_success)) %>%
dplyr::group_by(year,colony,species) %>%
dplyr::summarise(incubation_k=sum(!is.na(nest_number)),
incubation_sumy=sum(incubation_success==1, na.rm=TRUE),
incubation_e=sum(n_days_incubation, na.rm = TRUE),
incubation_j=mean(incubation_j, na.rm = TRUE),
nestling_k=sum(incubation_success==1, na.rm=TRUE),
nestling_sumy=sum(nestling_success==1, na.rm=TRUE),
nestling_e=sum(n_days_nestling, na.rm = TRUE),
nestling_j=mean(nestling_j, na.rm = TRUE)) %>%
dplyr::mutate(incubation_p = 1-((incubation_k-incubation_sumy)/incubation_e),
incubation_pj = incubation_p^incubation_j,
incubation_varp=(incubation_p*(1-incubation_p))/incubation_e,
incubation_varpj = incubation_varp*((incubation_j*(incubation_p^(incubation_j-1)))^2),
incubation_sdpj = sqrt(incubation_varpj),
nestling_p = 1-((nestling_k-nestling_sumy)/nestling_e),
nestling_pj = nestling_p^nestling_j,
nestling_varp=(nestling_p*(1-nestling_p))/nestling_e,
nestling_varpj = nestling_varp*((nestling_j*(nestling_p^(nestling_j-1)))^2),
nestling_sdpj = sqrt(nestling_varpj),
overall_p = (incubation_p^incubation_j)*(nestling_p^nestling_j),
overall_varp = ((incubation_pj^2)*nestling_varpj)+((nestling_pj^2)*incubation_varpj)+(incubation_varpj*nestling_varpj),
overall_sd = sqrt(overall_varp))

compare <- dplyr::left_join(success,success_summary, by=dplyr::join_by(year, colony, species)) %>%
dplyr::filter(species %in% c("bcnh","gbhe","glib","greg","rosp","smhe","sneg","whib","wost"))

library(ggplot2)
library(ggpubr)
# Compare basics
a <- ggplot(compare, aes(x=incubation_k.x, y=incubation_k.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=20, y=150, color="red",
label=paste("Missing:",sum(is.na(compare$incubation_k.y)))) +
xlab("Raw Incubation K") +
ylab("Reported Incubation K") +
theme_minimal()

b <- ggplot(compare, aes(x=nestling_k.x, y=nestling_k.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=20, y=110, color="red",
label=paste("Missing:",sum(is.na(compare$nestling_k.y)))) +
xlab("Raw Nestling K") +
ylab("Reported Nestling K") +
theme_minimal()

c <- ggplot(compare, aes(x=incubation_sumy.x, y=incubation_sumy.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=20, y=100, color="red",
label=paste("Missing:",sum(is.na(compare$incubation_sumy.y)))) +
xlab("Raw Incubation SumY") +
ylab("Reported Incubation SumY") +
theme_minimal()

d <- ggplot(compare, aes(x=nestling_sumy.x, y=nestling_sumy.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=20, y=100, color="red",
label=paste("Missing:",sum(is.na(compare$nestling_sumy.y)))) +
xlab("Raw Nestling_SumY") +
ylab("Reported Nestling SumY") +
theme_minimal()

e <- ggplot(compare, aes(x=incubation_e.x, y=incubation_e.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=2500, y=2500, color="red",
label=paste("Missing:",sum(is.na(compare$incubation_e.y)))) +
xlab("Raw Incubation E") +
ylab("Reported Incubation E") +
theme_minimal()

f <- ggplot(compare, aes(x=nestling_e.x, y=nestling_e.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=500, y=3500, color="red",
label=paste("Missing:",sum(is.na(compare$nestling_e.y)))) +
xlab("Raw Nestling E") +
ylab("Reported Nestling E") +
theme_minimal()

g <- ggplot(compare, aes(x=incubation_j.x, y=incubation_j.y)) +
geom_jitter(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=22, y=28, color="red",
label=paste("Missing:",sum(is.na(compare$incubation_j.y)))) +
xlab("Raw Incubation j") +
ylab("Reported Incubation j") +
theme_minimal()

h <- ggplot(compare, aes(x=nestling_j.x, y=nestling_j.y)) +
geom_jitter(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
annotate(geom="text", x=20, y=50, color="red",
label=paste("Missing:",sum(is.na(compare$nestling_j.y)))) +
xlab("Raw Nestling j") +
ylab("Reported Nestling j") +
theme_minimal()

ggarrange(a, b, c, d, e, f, g, h, ncol = 4, nrow = 2, common.legend = TRUE)

# Compare calculations
u <- ggplot(compare, aes(x=incubation_pj.x, y=incubation_pj.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
xlab("Raw Incubation pj") +
ylab("Reported Incubation pj") +
theme_minimal()

v <- ggplot(compare, aes(x=nestling_pj.x, y=nestling_pj.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
xlab("Raw Nestling pj") +
ylab("Reported Nestling pj") +
theme_minimal()

w <- ggplot(compare, aes(x=incubation_p.x, y=incubation_p.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
xlim(0,1) +
ylim(0,1) +
xlab("Raw Incubation p") +
ylab("Reported Incubation p") +
theme_minimal()

x <- ggplot(compare, aes(x=nestling_p.x, y=nestling_p.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
xlim(0,1) +
ylim(0,1) +
xlab("Raw Nestling p") +
ylab("Reported Nestling p") +
theme_minimal()

y <- ggplot(compare, aes(x=overall_p.x, y=overall_p.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
xlab("Raw Overall p") +
ylab("Reported Overall p") +
theme_minimal()

z <- ggplot(compare, aes(x=overall_varp.x, y=overall_varp.y)) +
geom_point(aes(color=species)) +
geom_abline(slope = 1, intercept = 0) +
xlab("Raw Overall Variance") +
ylab("Reported Overall Variance") +
theme_minimal()

ggarrange(u, v, w, x, y, z, ncol = 3, nrow = 2, common.legend = TRUE)
2 changes: 1 addition & 1 deletion DataCleaningScripts/old_nest_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ nests <- nests %>%
write.table(nests, "Nesting/nest_checks.csv", row.names = FALSE, na = "", sep = ",", quote = 9)

species <- species %>% dplyr::arrange(species)
write.table(species, "SiteandMethods/species_list.csv", row.names = FALSE, na = "", sep = ",", quote = 5:25)
write.table(species, "SiteandMethods/species_list.csv", row.names = FALSE, na = "", sep = ",", quote = 7:27)

colonies <- colonies %>% dplyr::arrange(colony)
write.table(colonies, "SiteandMethods/colonies.csv", row.names = FALSE, col.names = TRUE,
Expand Down
32 changes: 16 additions & 16 deletions SiteandMethods/species_list.csv
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
"species","commonname","scientificname","target_species","incubation_j","nestling_j","clutch_size","egg_color","nest_size","nest_materials","nest_microhabitat","colony_habitat","brood_size","nest_success","chick_description","typical_timing_range","courtship_period","nestbuilding_period","reproductive_period","nestling_period","incubation_period","branchling_period","feeding_methods","foraging_depth","foraging_type","niche_description","prey"
anhi,Anhinga,Anhinga anhinga,no,,,"2 - 5","Conspicuously pointed at one end, pale bluish green, and overlaid with a chalky coating","","","","shallow, slow-moving, sheltered waters","1","","Naked, with eyes open","","","","","14 - 21 days","26 - 30 days","","swims slowly underwater, stalking fish around submerged vegetation, spear fish","","","","small- to medium-sized wetland fishes, with very small amounts of crustaceans and invertebrates"
anhi,Anhinga,Anhinga anhinga,no,22,14,"2 - 5","Conspicuously pointed at one end, pale bluish green, and overlaid with a chalky coating","","","","shallow, slow-moving, sheltered waters","1","","Naked, with eyes open","","","","","14 - 21 days","26 - 30 days","","swims slowly underwater, stalking fish around submerged vegetation, spear fish","","","","small- to medium-sized wetland fishes, with very small amounts of crustaceans and invertebrates"
bcnh,Black Crowned Night Heron,Nycticorax nycticorax,no,28,21,"","","","","","","","","","","","","","","","","","","","",""
caeg,Cattle Egret,Bubulcus ibis,no,,,"","","","","","","","","","","","","","","","","","","","",""
coga,Common Gallinule,Gallinula galeata,no,,,"","","","","","","","","","","","","","","","","","","","",""
dcco,Double-crested Cormorant,Phalacrocorax auritus,no,,,"","","","","","","","","","","","","","","","","","","","",""
caeg,Cattle Egret,Bubulcus ibis,no,22,14,"","","","","","","","","","","","","","","","","","","","",""
coga,Common Gallinule,Gallinula galeata,no,21,40,"","","","","","","","","","","","","","","","","","","","",""
dcco,Double-crested Cormorant,Phalacrocorax auritus,no,27,25,"","","","","","","","","","","","","","","","","","","","",""
gbhe,Great Blue Heron,Ardea herodias,yes,28,60,"2 - 6","Pale blue, fading slightly with age","50 cm - 122 cm","sticks, lined with grass, reeds, moss, cupped","mainly in trees, but will also nest on the ground, on bushes, in mangroves, and on structures such as duck blinds, channel markers, or artificial nest platforms","","1 - 2","","bluish eyes open, covered in pale gray down, able to vocalize","","","","","49 - 81 days","27 - 29 days","","grab smaller prey in their strong mandibles or use their dagger-like bills to impale larger fish, often shaking them to break or relax the sharp spines before gulping them down","","exploiter","","anything within striking distance, including fish, amphibians, reptiles, small mammals, insects, and other birds"
glib,Glossy Ibis,Plegadis falcinellus,no,,,"","","","","","","","","","","","","","","","","","","","",""
glib,Glossy Ibis,Plegadis falcinellus,no,21,14,"","","","","","","","","","","","","","","","","","","","",""
greg,Great Egret,Ardea alba,yes,28,21,"1 - 6, 4 normal","light blue green","widths of ground nests (49.2 cm ± 5.9 SD) versus tree nests (42.5 cm ± 3.7 SD) were significantly different, as were nest depths (21.2 cm ± 8.7 SD and 10.5 cm ± 2.2 SD),","sticks, vary in size","open canopy","","1 - 3","","white down, body dak gray, wram pale gray bill balck tip, change to yellow by 7 days.","Jan - May","7 - 11 days","3 - 5days","80","21","27","50+ days","walking slowly, standing and waiting, second to SNEG in number of different foraging behaviors; kleptoparasitism from other species","average 28 cm, GE will increase to 20 - 40 cm then decline","exploiter","depth more important than salinity, but will stay in open areas","98% fish, but opportunistic, size larger than other herons except for GBHE"
grhe,Green Heron,Butorides virescens,no,,,"","","","","","","","","","","","","","","","","","","","",""
lada,large dark unidentified bird,unknown,no,,,"","","","","","","","","","","","","","","","","","","","",""
lawh,large white unidentified bird,unknown,no,,,"","","","","","","","","","","","","","","","","","","","",""
lbhe,Little Blue Heron,Egretta caerulea,yes,,,"","","","","","","","","","","","","","","","","","","","",""
grhe,Green Heron,Butorides virescens,no,22,14,"","","","","","","","","","","","","","","","","","","","",""
lada,large dark unidentified bird,unknown,no,27,25,"","","","","","","","","","","","","","","","","","","","",""
lawh,large white unidentified bird,unknown,no,28,55,"","","","","","","","","","","","","","","","","","","","",""
lbhe,Little Blue Heron,Egretta caerulea,yes,22,14,"","","","","","","","","","","","","","","","","","","","",""
rosp,Roseate Spoonbill,Platalea ajaja,yes,22,21,"1 - 5, 4 typical","dull white, brown spots","","twigs and large sticks","subcanopy","","","","pinkish down, tubular to flattened bills, exceptionally cute","Nov - Feb","","20 days","80","5-6weeks","22 days","60 days","tactolocation, head sweeping, will use grabbing or probing, and will run after abundant or active prey.","<12 cm, max 20 cm based on leg length","high grader","fresh to hypersaline, will feed at night; prefers coastal habitat",""
rsha,Red-shouldered Hawk,Buteo lineatus,no,,,"","","","","","","","","","","","","","","","","","","","",""
smda,small dark unidentified bird,unknown,no,,,"","","","","","","","","","","","","","","","","","","","",""
rsha,Red-shouldered Hawk,Buteo lineatus,no,36,46,"","","","","","","","","","","","","","","","","","","","",""
smda,small dark unidentified bird,unknown,no,22,14,"","","","","","","","","","","","","","","","","","","","",""
smhe,small heron,unknown,no,22,14,"","","","","","","","","","","","","","","","","","","","",""
smwh,small white unidentified bird,unknown,no,,,"","","","","","","","","","","","","","","","","","","","",""
sneg,Snowy Egret,Egretta thula,yes,,,"3 - 5","pale greenish blue","","fine twigs , cupped","head to chest height, never canopy","","","","white down, leg yellowish to grayish to black, pink mouth, pale gray iris","mid - late March","","4.4 days","","15 days","22 days","","broadest repertoire of foraging of any n. american heron. Foot stirring, fly-stabbing, foot dragging, lots of habitats,","","high grader","brackish and marine, shallow water","worms, insects, crustaceans, fishes, anurans 75% fish, mosquitofish, needlefish"
trhe,Tricolored Heron,Egretta tricolor,no,,,"3 - 4","pale bluish green","","small twigs, woody vege, no green material, will nest in needlerush","subcanopy, dense, well shaded 0.15 - 3.7 m above ground","","","","brownish reddish crown, bronish gray on back, white down abdoment,","Feb - March","5 - 6 days","","","83 days","21 days","50 - 56 days","broad - striking, running, wing shading, foot raking,. Slow walking, usually solitary foraging or on edge of groups","deeper than snowy, to belly deep, 18cm max","exploiter","estuarine, coastal primary habitat","primarily fish, opportunistic, fundulus, killifishes"
unkn,Unknown,Unknown,no,,,"","","","","","","","","","","","","","","","","","","","",""
smwh,small white unidentified bird,unknown,no,22,14,"","","","","","","","","","","","","","","","","","","","",""
sneg,Snowy Egret,Egretta thula,yes,22,14,"3 - 5","pale greenish blue","","fine twigs , cupped","head to chest height, never canopy","","","","white down, leg yellowish to grayish to black, pink mouth, pale gray iris","mid - late March","","4.4 days","","15 days","22 days","","broadest repertoire of foraging of any n. american heron. Foot stirring, fly-stabbing, foot dragging, lots of habitats,","","high grader","brackish and marine, shallow water","worms, insects, crustaceans, fishes, anurans 75% fish, mosquitofish, needlefish"
trhe,Tricolored Heron,Egretta tricolor,no,22,14,"3 - 4","pale bluish green","","small twigs, woody vege, no green material, will nest in needlerush","subcanopy, dense, well shaded 0.15 - 3.7 m above ground","","","","brownish reddish crown, bronish gray on back, white down abdoment,","Feb - March","5 - 6 days","","","83 days","21 days","50 - 56 days","broad - striking, running, wing shading, foot raking,. Slow walking, usually solitary foraging or on edge of groups","deeper than snowy, to belly deep, 18cm max","exploiter","estuarine, coastal primary habitat","primarily fish, opportunistic, fundulus, killifishes"
unkn,Unknown,Unknown,no,22,14,"","","","","","","","","","","","","","","","","","","","",""
whib,White Ibis,Eudocimus albus,yes,21,14,"2 - 3","creamy white to greenish, brown splotches","25 cm average","various, twigs to grass","various height, very dense","","1 - 3","5 - 70%","dark downy, pink bills with dark markings,","Feb - March in Everglades","5 - 6 days","","","15 - 18 days","22 days","61 days mean, as early as 40 days","walk and probe quickly, will use visual foraging, foot raking, pecking at surface,","14 cm on average","high grader","prefer freshwater in breeding season, will feed in coastal","crustaceans, insects, small fishes, gambusia, crayfish, fiddler crabs"
wost,Wood Stork,Mycteria americana,yes,28,50,"1 - 5","creamy white","","twigs and sticks","open at top","historically cypress swamps, now many types including impoundments","","","white, sparse down, eyes closed, 60 gm at hatching","historically november, now Feb - March","","2 - 3 days","99 - 118 days","25 days","28 days","50 - 55 days","grope foraging, walking slowly with bill open in water, side to side motion, snap reflex, unitary foraging technique. Foot stirring and wing flicking","15 - 50 cm","high grader","wetlands,","fish>1 yr old, sunfishes, catfishes, killifishes, mollies,"
ycnh,Yellow-crowned Night-Heron,Nyctanassa violacea,no,,,"","","","","","","","","","","","","","","","","","","","",""
ycnh,Yellow-crowned Night-Heron,Nyctanassa violacea,no,22,14,"","","","","","","","","","","","","","","","","","","","",""

0 comments on commit 52ed23f

Please sign in to comment.