Flight Trials Winter 2020 Dataset was conducted from 2/17/2020 - 3/10/2020. Soapberry bugs were flight tested twice in the flight mill and observed from 8 AM to (5-8 PM) each day.
source_path = "~/Desktop/git_repositories/SBB-dispersal/avbernat/Rsrc/"
script_names = c("center_flight_data.R", # Re-centers data
"clean_flight_data.R", # Loads and cleans data
# groups explanatory values into categories and calculates
# the sample of proportion of flight for each category
"categorize_binomial_data.R",
"categorize_binomial_data-MF.R",
"categorize_binomial_data3.R",
"categorize_binomial_data-MF2.R")
for (script in script_names) {
path = paste0(source_path, script)
source(path)
}
output_col = FALSE # Change to TRUE if working in Base R or RStudio; FALSE if generating an HTML
data <- read_flight_data("data/all_flight_data-Winter2020.csv")
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
## Warning: `funs()` was deprecated in dplyr 0.8.0.
## Please use a list of either functions or lambdas:
##
## # Simple named list:
## list(mean = mean, median = median)
##
## # Auto named with `tibble::lst()`:
## tibble::lst(mean, median)
##
## # Using lambdas
## list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
data_all <- data[[1]]
data_tested <- data[[2]]
cat_data1 <- categorize_data(data_tested, all_of("min_from_IncStart"), all_of("flew_b"), 30, 0, 30)
## min_from_IncStart 30 Cases: 72 Sample Proportion: 0.5694444
## min_from_IncStart 60 Cases: 84 Sample Proportion: 0.6190476
## min_from_IncStart 90 Cases: 66 Sample Proportion: 0.4848485
## min_from_IncStart 120 Cases: 53 Sample Proportion: 0.5471698
## min_from_IncStart 150 Cases: 43 Sample Proportion: 0.3488372
## min_from_IncStart 180 Cases: 42 Sample Proportion: 0.547619
## min_from_IncStart 210 Cases: 43 Sample Proportion: 0.5348837
## min_from_IncStart 240 Cases: 31 Sample Proportion: 0.7096774
## min_from_IncStart 270 Cases: 17 Sample Proportion: 0.5882353
## min_from_IncStart 300 Cases: 19 Sample Proportion: 0.6315789
## min_from_IncStart 330 Cases: 22 Sample Proportion: 0.6363636
## min_from_IncStart 360 Cases: 26 Sample Proportion: 0.5769231
## min_from_IncStart 390 Cases: 21 Sample Proportion: 0.7142857
## min_from_IncStart 420 Cases: 28 Sample Proportion: 0.5
## min_from_IncStart 450 Cases: 14 Sample Proportion: 0.7142857
## min_from_IncStart 480 Cases: 22 Sample Proportion: 0.6363636
## min_from_IncStart 510 Cases: 7 Sample Proportion: 0.2857143
cat_data2 <- categorize_data(data_tested, all_of("minute_duration"), all_of("flew_b"), 30, 0, 30)
## minute_duration 30 Cases: 9 Sample Proportion: 0.1111111
## minute_duration 60 Cases: 431 Sample Proportion: 0.3897912
## minute_duration 90 Cases: 31 Sample Proportion: 1
## minute_duration 120 Cases: 25 Sample Proportion: 1
## minute_duration 150 Cases: 9 Sample Proportion: 1
## minute_duration 180 Cases: 14 Sample Proportion: 1
## minute_duration 210 Cases: 7 Sample Proportion: 1
## minute_duration 240 Cases: 6 Sample Proportion: 1
## minute_duration 270 Cases: 3 Sample Proportion: 1
## minute_duration 300 Cases: 6 Sample Proportion: 1
## minute_duration 330 Cases: 4 Sample Proportion: 1
## minute_duration 360 Cases: 3 Sample Proportion: 1
## minute_duration 390 Cases: 5 Sample Proportion: 1
## minute_duration 420 Cases: 8 Sample Proportion: 1
## minute_duration 450 Cases: 6 Sample Proportion: 1
## minute_duration 480 Cases: 6 Sample Proportion: 1
## minute_duration 510 Cases: 5 Sample Proportion: 1
## minute_duration 540 Cases: 2 Sample Proportion: 1
## minute_duration 570 Cases: 3 Sample Proportion: 1
## minute_duration 600 Cases: 2 Sample Proportion: 1
## minute_duration 630 Cases: 3 Sample Proportion: 1
## minute_duration 660 Cases: 4 Sample Proportion: 1
## minute_duration 690 Cases: 5 Sample Proportion: 1
## minute_duration 720 Cases: 2 Sample Proportion: 1
## minute_duration 750 Cases: 6 Sample Proportion: 1
## minute_duration 780 Cases: 1 Sample Proportion: 1
## minute_duration 810 Cases: 8 Sample Proportion: 1
# Plotting observed proportions of yes flew by minutes from incubation start
p1 <- as.grob(expression(plot(sample_prop ~ min_from_IncStart, data=cat_data1,
ylab="Sample Proportion of Yes Flew", xlab="Minutes From Incubtation Start (min) ",
main="Observed proportions of yes flew by minutes from incubation start")
))
# Plotting observed proportions of yes flew by minutes from trial start
p2 <- as.grob(expression(
plot(sample_prop ~ minute_duration, data=cat_data2,
ylab="Sample Proportion of Yes Flew", xlab="Minutes From Trial Start (min)",
main="Observed proportions of yes flew by minutes from trial start") %>%
abline(v=120, col="red")
))
grid.arrange(p1,p2, ncol=2)
cat_data1$min_from_IncStart
## [1] 30 60 90 120 150 180 210 240 270 300 330 360 390 420 450 480 510
fit <- lm(`sample_prop`~ min_from_IncStart, data=cat_data1)
summary(fit) # NO significant effect
##
## Call:
## lm(formula = sample_prop ~ min_from_IncStart, data = cat_data1)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.29473 -0.02922 0.01515 0.06312 0.14394
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 5.527e-01 6.136e-02 9.007 1.94e-07 ***
## min_from_IncStart 5.447e-05 1.996e-04 0.273 0.789
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.121 on 15 degrees of freedom
## Multiple R-squared: 0.00494, Adjusted R-squared: -0.0614
## F-statistic: 0.07446 on 1 and 15 DF, p-value: 0.7887
cf <- round(coef(fit), 2) ## rounded coefficients for better output
eq <- paste0("portion_flew = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "),
abs(cf[2]), "*time_start ") ## sign check to avoid having plus followed by minus for negative coefficients
plot(cat_data1$min_from_IncStart,cat_data1$sample_prop,
xlab= "Starting Time", ylab="Proportion of 24-H Day Spent Flying")
abline(coef(fit)[1:2], col="blue")
mtext(eq, 3, line=-2, side=3)
text(300,0.4, c("not significant"), col= "red")
cat_data2$log_min_duration <- log(cat_data2$minute_duration)
m <- quap(
alist(
sample_prop ~ dnorm(mu, sigma),
mu <- alpha + beta*(log_min_duration),
alpha ~ dnorm(5.792217, 5), # this should be in terms of height not weight
beta ~ dlnorm(0,1),
sigma ~ dunif(0,10)
),
data=cat_data2
)
precis(m)
## mean sd 5.5% 94.5%
## alpha -0.06860877 0.18661744 -0.3668595 0.2296419
## beta 0.17493445 0.03187770 0.1239877 0.2258812
## sigma 0.14093514 0.01918159 0.1102792 0.1715910
#x_seq <- log(min(cat_data2$minute_duration):max(cat_data2$minute_duration))
x_seq <- log(seq(from=0, to=840, length.out=30))
mu <- sim(m,data=list(log_min_duration=x_seq))
mu_mean <- apply(mu,2,mean)
mu_ci <- apply(mu,2,PI,prob=0.89)
# Plot Log
plot( cat_data2$log_min_duration , cat_data2$sample_prop , col=col.alpha(rangi2,0.7),
ylab="Sample Proportion of Yes Flew",
xlab="Log(Minutes From Trial Start) log(min)",
main="Observed proportions of yes flew by log(minutes) from trial start" )
lines(x_seq, mu_mean)
shade(mu_ci, lim = x_seq)
text(6,0.3, c("significant"), col= "darkolivegreen4")
# Plot Non-log
plot( cat_data2$minute_duration , cat_data2$sample_prop, col=col.alpha(rangi2,0.7),
ylab="Sample Proportion of Yes Flew",
xlab="Minutes From Trial Start (min)",
main="Observed proportions of yes flew by minutes from trial start" )
lines( exp(x_seq), mu_mean)
shade(mu_ci, lim = exp(x_seq))
abline(v=120, col="red", lty=2)
par(mfrow=c(1,2))
# What is happening for those who flew?
x = chron(times = data_tested$time_start)
y = data_tested$recording_duration / (60*60) # hours
fit <- lm(y~x, data=data_tested)
summary(fit) # significant effect
##
## Call:
## lm(formula = y ~ x, data = data_tested)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8061 -1.4060 -1.1175 -0.5736 11.2788
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.9330 0.5573 5.263 1.97e-07 ***
## x -2.2654 1.1912 -1.902 0.0577 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.89 on 612 degrees of freedom
## Multiple R-squared: 0.005875, Adjusted R-squared: 0.004251
## F-statistic: 3.617 on 1 and 612 DF, p-value: 0.05767
cf <- round(coef(fit), 2) ## rounded coefficients for better output
eq <- paste0("portion_flew = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "),
abs(cf[2]), "*time_start ") ## sign check to avoid having plus followed by minus for negative coefficients
plot(x,y, xlab= "Starting Time", ylab="Duration (hr)")
abline(coef(fit)[1:2], col="blue") # Alternative: lines(x, fitted(fit), col="blue")
#mtext(eq, 3, line=-2, side=3)
# Filter out those that didn't fly.
all_flew <- filter(data_all, flew_b == 1)
# What is happening for those who flew?
x = chron(times = all_flew$time_start)
y = all_flew$recording_duration / (60*60) # hours
fit <- lm(y~x, data=all_flew)
summary(fit) # significant effect
##
## Call:
## lm(formula = y ~ x, data = all_flew)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8203 -2.3285 -1.6447 0.4281 10.0744
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 4.8432 0.9162 5.286 2.23e-07 ***
## x -4.2197 1.9521 -2.162 0.0313 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3.547 on 341 degrees of freedom
## Multiple R-squared: 0.01352, Adjusted R-squared: 0.01062
## F-statistic: 4.672 on 1 and 341 DF, p-value: 0.03135
cf <- round(coef(fit), 2) ## rounded coefficients for better output
eq <- paste0("portion_flew = ", cf[1],
ifelse(sign(cf[2])==1, " + ", " - "),
abs(cf[2]), "*time_start ") ## sign check to avoid having plus followed by minus for negative coefficients
plot(x,y, xlab= "Starting Time", ylab="Duration (hr)")
abline(coef(fit)[1:2], col="blue") # Alternative: lines(x, fitted(fit), col="blue")
#mtext(eq, 3, line=-2, side=3)
# Missing mass for some (3 NA)
missing_mass <- subset(data_all, is.na(data_all$mass))
# IDs 339, 48, and 342 have no mass and were tested on the same date
# Remove missing mass
data_mass <- data_all %>%
filter(!is.na(mass))
## ALL DATA: Observed proportions of yes flew by mass
cat_data3 <- categorize_data(data_mass, all_of("mass"), all_of("flew_b"), 0.010, 0.015, 0.025)
## mass 0.025 Cases: 4 Sample Proportion: 0.25
## mass 0.035 Cases: 123 Sample Proportion: 0.6747967
## mass 0.045 Cases: 206 Sample Proportion: 0.7281553
## mass 0.055 Cases: 92 Sample Proportion: 0.5434783
## mass 0.065 Cases: 41 Sample Proportion: 0.4390244
## mass 0.075 Cases: 35 Sample Proportion: 0.5142857
## mass 0.085 Cases: 31 Sample Proportion: 0.1935484
## mass 0.095 Cases: 28 Sample Proportion: 0.2142857
## mass 0.105 Cases: 20 Sample Proportion: 0.2
## mass 0.115 Cases: 13 Sample Proportion: 0.3076923
## mass 0.125 Cases: 7 Sample Proportion: 0
## mass 0.135 Cases: 6 Sample Proportion: 0.1666667
## mass 0.145 Cases: 3 Sample Proportion: 0.3333333
## mass 0.155 Cases: 1 Sample Proportion: 0
## mass 0.185 Cases: 1 Sample Proportion: 0
## TRIAL 1 DATA: Observed proportions of yes flew by mass
data_T1 <-data_all[data_all$trial_type=="T1",]
data_mass_T1 <- data_T1 %>%
filter(!is.na(mass))
cat_data4 <- categorize_data(data_mass_T1, all_of("mass"), all_of("flew_b"), 0.010, 0.015, 0.025)
## mass 0.025 Cases: 4 Sample Proportion: 0.25
## mass 0.035 Cases: 79 Sample Proportion: 0.7468354
## mass 0.045 Cases: 104 Sample Proportion: 0.7596154
## mass 0.055 Cases: 52 Sample Proportion: 0.5384615
## mass 0.065 Cases: 21 Sample Proportion: 0.5238095
## mass 0.075 Cases: 19 Sample Proportion: 0.5789474
## mass 0.085 Cases: 12 Sample Proportion: 0.25
## mass 0.095 Cases: 11 Sample Proportion: 0.1818182
## mass 0.105 Cases: 9 Sample Proportion: 0.2222222
## mass 0.115 Cases: 8 Sample Proportion: 0.375
## mass 0.125 Cases: 4 Sample Proportion: 0
## mass 0.135 Cases: 4 Sample Proportion: 0.25
## mass 0.155 Cases: 1 Sample Proportion: 0
## mass 0.185 Cases: 1 Sample Proportion: 0
plot(data_T1$mass, data_T1$flew_b)
# ALL DATA
#all_fit <-lm(flew_b~mass, data=data_mass)
all_fit <-lm(sample_prop~ mass, data=cat_data3)
coeff <- coefficients(summary(all_fit))
coeff
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.6632107 0.09698041 6.838605 1.190673e-05
## mass -3.7251863 0.90996926 -4.093750 1.267907e-03
mass_seq <- seq(from=0.02, to=0.20, length.out=30)
mu <- link(all_fit, data=data.frame(mass=mass_seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
eq <- paste0("portion_flew = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass")
plot(as.matrix(cat_data3[1]),
as.matrix(cat_data3[3]),
ylab="Sample Proportion of Yes Flew",
xlab="Mass (g)",
main="All Data: Observed proportions of yes flew by mass")
shade(mu.PI, mass_seq)
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4)
# TRIAL 1 - FIX THIS TOO
fit_mass<-lm(flew_b~mass, data=data_mass_T1)
coeff <- coefficients(summary(fit_mass))
mass_seq <- seq(from=0.01, to=0.180, length.out=30)
mu <- link(fit_mass, data=data.frame(mass=mass_seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
eq <- paste0("portion_flew = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass")
plot(as.matrix(cat_data4[1]),
as.matrix(cat_data4[3]),
ylab="Sample Proportion of Yes Flew",
xlab="Mass (g)",
main="Trial 1: Observed proportions of yes flew by mass")
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4)
shade(mu.PI, mass_seq)
summary <-aggregate(flew_b~sex*host_plant*sym_dist, data=data_all, FUN=mean)
summary
## sex host_plant sym_dist flew_b
## 1 F K. elegans 0.0000000 0.33333333
## 2 M K. elegans 0.0000000 0.30555556
## 3 F C. corindum 0.2046150 0.44444444
## 4 M C. corindum 0.2046150 0.50000000
## 5 F C. corindum 0.2047546 0.00000000
## 6 M C. corindum 0.2047546 0.00000000
## 7 F C. corindum 0.2178735 0.29629630
## 8 M C. corindum 0.2178735 0.76470588
## 9 F C. corindum 0.2178735 0.00000000
## 10 M C. corindum 0.2178735 0.00000000
## 11 F C. corindum 0.2348005 0.10000000
## 12 M C. corindum 0.2348005 0.95000000
## 13 F C. corindum 0.2638382 0.18181818
## 14 M C. corindum 0.2638382 0.52173913
## 15 F C. corindum 0.2962120 0.25000000
## 16 M C. corindum 0.2962120 0.59259259
## 17 F C. corindum 0.3092689 0.00000000
## 18 M C. corindum 0.3092689 0.61666667
## 19 F C. corindum 0.3157918 0.25000000
## 20 M C. corindum 0.3157918 0.51515152
## 21 F C. corindum 0.3629042 0.52631579
## 22 M C. corindum 0.3629042 0.63636364
## 23 F C. corindum 0.3913469 0.20000000
## 24 M C. corindum 0.3913469 0.50000000
## 25 F C. corindum 0.5177872 0.00000000
## 26 M C. corindum 0.5177872 0.58620690
## 27 F C. corindum 0.5271220 0.30303030
## 28 M C. corindum 0.5271220 0.70000000
## 29 F K. elegans 1.8072690 0.37500000
## 30 M K. elegans 1.8072690 0.76000000
## 31 F K. elegans 1.8072980 0.00000000
## 32 M K. elegans 1.8072980 0.00000000
## 33 F K. elegans 2.4053783 0.41666667
## 34 M K. elegans 2.4053783 0.62500000
## 35 F K. elegans 3.3049815 0.09090909
## 36 M K. elegans 3.3049815 0.46428571
## 37 F K. elegans 4.1706402 0.00000000
## 38 M K. elegans 4.1706402 0.50000000
## 39 F K. elegans 4.1706604 0.00000000
## 40 M K. elegans 4.1706604 0.00000000
par(mar=c(6.5, 5.5, 5.5, 9.5), xpd=TRUE) # Add extra space to right of plot area; change clipping to figure
plot(summary$flew_b~summary$sym_dist,
col=c(1,2)[as.factor(summary$sex)], # Female = Black, Male = Red
pch=c(19,22)[as.factor(summary$host_plant)],
main="Observed Data",
xlab = "Distance from Sympatric Zone (°)",
ylab= "Proportion Flew" # K. elegans = Squares C.corindum = circles
#sub=eq_glmer
)
legend("topright",
legend = c("C. corindum and F", "C. corindum and M", "K. elegans and F" , "K. elegans and M"),
inset=c(-0.23,0.2),
col=c(1,2),
pch = c(19,19, 22,22),
title="Groups")
missing_mass <- subset(data_all, is.na(data_all$mass))
data_mass <- data_all %>%
filter(!is.na(mass))
cat_data5 <- categorize_data_MF(data_mass, all_of("mass"), all_of("sex_c"),
all_of("host_c"), all_of("flew_b"), 0.010, 0.015, 0.025)
## Mass 0.035 Sex: M Host Plant: 1 Cases: 2 Sample Proportion: 0
## Mass 0.045 Sex: M Host Plant: -1 Cases: 2 Sample Proportion: 0.5
## Mass 0.055 Sex: F Host Plant: 1 Cases: 8 Sample Proportion: 0.25
## Mass 0.055 Sex: M Host Plant: 1 Cases: 11 Sample Proportion: 0.3636364
## Mass 0.055 Sex: F Host Plant: -1 Cases: 22 Sample Proportion: 0.4545455
## Mass 0.055 Sex: M Host Plant: -1 Cases: 51 Sample Proportion: 0.6666667
## Mass 0.065 Sex: F Host Plant: 1 Cases: 10 Sample Proportion: 0.5
## Mass 0.065 Sex: M Host Plant: 1 Cases: 1 Sample Proportion: 0
## Mass 0.065 Sex: F Host Plant: -1 Cases: 20 Sample Proportion: 0.4
## Mass 0.065 Sex: M Host Plant: -1 Cases: 10 Sample Proportion: 0.5
## Mass 0.075 Sex: F Host Plant: 1 Cases: 12 Sample Proportion: 0.5833333
## Mass 0.085 Sex: F Host Plant: -1 Cases: 23 Sample Proportion: 0.4782609
## Mass 0.105 Sex: F Host Plant: 1 Cases: 1 Sample Proportion: 1
## Mass 0.115 Sex: F Host Plant: -1 Cases: 19 Sample Proportion: 0.1578947
## Mass 0.135 Sex: F Host Plant: 1 Cases: 1 Sample Proportion: 1
## Mass 0.145 Sex: F Host Plant: -1 Cases: 5 Sample Proportion: 0
## Mass 0.205 Sex: F Host Plant: -1 Cases: 1 Sample Proportion: 0
cat_data5
## mass n_cases sample_prop sex_c host_c
## 2 0.035 2 0.000 -1 1
## 4 0.045 2 0.500 -1 -1
## 5 0.055 8 0.250 1 1
## 6 0.055 11 0.364 -1 1
## 7 0.055 22 0.455 1 -1
## 8 0.055 51 0.667 -1 -1
## 9 0.065 10 0.500 1 1
## 10 0.065 1 0.000 -1 1
## 11 0.065 20 0.400 1 -1
## 12 0.065 10 0.500 -1 -1
## 13 0.075 12 0.583 1 1
## 15 0.085 23 0.478 1 -1
## 17 0.105 1 1.000 1 1
## 19 0.115 19 0.158 1 -1
## 21 0.135 1 1.000 1 1
## 23 0.145 5 0.000 1 -1
## 27 0.205 1 0.000 1 -1
gf_point(sample_prop ~ mass, data=cat_data5, col=~sex_c, size=~host_c,
xlab = "Mass (g)", ylab= "Sample Proportion that Flew",
title= "Observed Data")
par(mar=c(6.5, 5.5, 5.5, 9.5), xpd=TRUE)
plot(cat_data5$sample_prop~cat_data5$mass,
col=c(1,2)[as.factor(cat_data5$sex_c)], # Female = Black, Male = Red
pch=c(19,22)[as.factor(cat_data5$host_c)],
main="Observed Data",
xlab = "Mass (g)",
ylab= "Proportion Flew", # K. elegans = Squares, C.corindum = circles
#sub=eq_glmer
)
legend("topright",
legend = c("C. corindum and F", "C. corindum and M", "K. elegans and F" , "K. elegans and M"),
inset=c(-0.23,0.2),
col=c(1,2),
pch = c(19,19, 22,22),
title="Groups")
data_T2 <-data_all[data_all$trial_type=="T2",]
plot(data_T2$mass, data_T2$flew_b)
##### TRIAL 2 DATA: Observed proportions of yes flew by mass #############
cat_data6 <- categorize_data(data_T2, all_of("mass"), all_of("flew_b"), 0.010, 0.015, 0.025)
## mass 0.035 Cases: 44 Sample Proportion: 0.5454545
## mass 0.045 Cases: 102 Sample Proportion: 0.6960784
## mass 0.055 Cases: 40 Sample Proportion: 0.55
## mass 0.065 Cases: 20 Sample Proportion: 0.35
## mass 0.075 Cases: 16 Sample Proportion: 0.4375
## mass 0.085 Cases: 19 Sample Proportion: 0.1578947
## mass 0.095 Cases: 17 Sample Proportion: 0.2352941
## mass 0.105 Cases: 11 Sample Proportion: 0.1818182
## mass 0.115 Cases: 5 Sample Proportion: 0.2
## mass 0.125 Cases: 3 Sample Proportion: 0
## mass 0.135 Cases: 2 Sample Proportion: 0
## mass 0.145 Cases: 3 Sample Proportion: 0.3333333
fit<-lm(flew_b~mass, data=data_T2)
coeff <- coefficients(summary(fit))
mass_seq <- seq(from=0.0, to=0.18, length.out=30)
mu <- link(fit, data=data.frame(mass=mass_seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
eq <- paste0("portion_flew = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass")
plot(as.matrix(cat_data6[1]),
as.matrix(cat_data6[3]),
ylab="Sample Proportion of Yes Flew",
xlab="Mass (g)",
main="Trial 2: Observed proportions of yes flew by mass")
shade(mu.PI, mass_seq)
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4)
data_fem <- data_all[data_all$sex=="F",]
plot(data_fem$sym_dist, data_fem$flew_b)
fem_sum <-aggregate(flew_b~host_plant*sym_dist, data=data_fem, FUN=mean)
fem_sum
## host_plant sym_dist flew_b
## 1 K. elegans 0.0000000 0.33333333
## 2 C. corindum 0.2046150 0.44444444
## 3 C. corindum 0.2047546 0.00000000
## 4 C. corindum 0.2178735 0.29629630
## 5 C. corindum 0.2178735 0.00000000
## 6 C. corindum 0.2348005 0.10000000
## 7 C. corindum 0.2638382 0.18181818
## 8 C. corindum 0.2962120 0.25000000
## 9 C. corindum 0.3092689 0.00000000
## 10 C. corindum 0.3157918 0.25000000
## 11 C. corindum 0.3629042 0.52631579
## 12 C. corindum 0.3913469 0.20000000
## 13 C. corindum 0.5177872 0.00000000
## 14 C. corindum 0.5271220 0.30303030
## 15 K. elegans 1.8072690 0.37500000
## 16 K. elegans 1.8072980 0.00000000
## 17 K. elegans 2.4053783 0.41666667
## 18 K. elegans 3.3049815 0.09090909
## 19 K. elegans 4.1706402 0.00000000
## 20 K. elegans 4.1706604 0.00000000
par(mar=c(6.5, 5.5, 5.5, 9.5), xpd=TRUE) # Add extra space to right of plot area; change clipping to figure
plot(fem_sum$flew_b~fem_sum$sym_dist,
pch=c(19,22)[as.factor(fem_sum$host_plant)],
main="Observed Data",
xlab = "Distance from Sympatric Zone (°)",
ylab= "Proportion Flew", # K. elegans = Squares C.corindum = circles
#sub=eq_glmer
)
legend("topright",
legend = c("C.corindum","K.elegans"),
inset=c(-0.23,0.2),
pch = c(19,22),
title="Groups")
cat_data7 <- categorize_data(data_fem, all_of("sym_dist"), all_of("flew_b"), 0.1, 0, 0.05)
## sym_dist 0.05 Cases: 27 Sample Proportion: 0.3333333
## sym_dist 0.25 Cases: 52 Sample Proportion: 0.25
## sym_dist 0.35 Cases: 33 Sample Proportion: 0.1515152
## sym_dist 0.55 Cases: 40 Sample Proportion: 0.25
## sym_dist 1.85 Cases: 19 Sample Proportion: 0.3157895
## sym_dist 2.45 Cases: 12 Sample Proportion: 0.4166667
## sym_dist 3.35 Cases: 11 Sample Proportion: 0.09090909
fit_fem <- lm(flew_b~sym_dist, data=data_fem)
coefff <- coefficients(summary(fit_fem))
eq <- paste0("portion_flew = ", round(coefff[1],3),
ifelse(sign(coefff[2])==1, " + ", " - "),
abs(round(coefff[2],3)), "*sym_dist")
plot(as.matrix(cat_data7[1]),
as.matrix(cat_data7[3]),
ylab="Sample Proportion of Yes Flew",
xlab="Distance From Sympatric Zone (°)",
main="Observed proportions of yes flew by distance from sympatric zone")
abline(coefff[1], coefff[2], col="blue")
mtext(eq, side=4)
pf1 <- as.grob(expression(
plot(data_fem$flew_b, data_fem$total_eggs)))
# seems like if you generally laid less eggs you flew, but a lot of females laid few and also didn't fly
pf2 <- as.grob(expression(
plot(data_fem$mass, data_fem$total_eggs)))
pf3 <- as.grob(expression(
plot(data_fem$sym_dist,data_fem$total_eggs)))
grid.arrange(pf1,pf2,pf3, ncol=3)
####### Sample proportion that laid eggs by mass ####### AND
####### Total eggs laid by mass #######
data <- read_flight_data("data/all_flight_data-Winter2020.csv")
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
data_all <- data[[1]]
data_tested <- data[[2]]
data_fem <- data_tested[data_tested$sex=="F",]
# Data Manipulation - filtering, removing duplicates, and recentering mass
data_fem_filtered <- data_fem %>%
filter(!is.na(total_eggs)) %>%
filter(!is.na(mass))
data_fem_filtered <-data_fem_filtered[!duplicated(data_fem_filtered$ID,
data_fem_filtered$total_eggs),]
data_fem_filtered$mass_c <- data_fem_filtered$mass - mean(data_fem_filtered$mass)
cat_data8 <- categorize_data(data_fem_filtered, all_of("mass"), all_of("total_eggs"), 0.010, 0.015, 0.025)
## mass 0.045 Cases: 4 Sample Proportion: 40.75
## mass 0.055 Cases: 13 Sample Proportion: 48.46154
## mass 0.065 Cases: 16 Sample Proportion: 66.8125
## mass 0.075 Cases: 22 Sample Proportion: 74
## mass 0.085 Cases: 16 Sample Proportion: 100.1875
## mass 0.095 Cases: 14 Sample Proportion: 130
## mass 0.105 Cases: 10 Sample Proportion: 117.9
## mass 0.115 Cases: 10 Sample Proportion: 147.1
## mass 0.125 Cases: 5 Sample Proportion: 192.8
## mass 0.135 Cases: 6 Sample Proportion: 214.8333
## mass 0.155 Cases: 1 Sample Proportion: 330
## mass 0.185 Cases: 1 Sample Proportion: 75
####### Sample proportion that laid eggs by mass ####### AND
####### Total eggs laid by mass #######
# Plotting - lm, PI
par(mfrow=c(1,2))
# Plot 1 ---------------------------------------------------
fit_prop <- lm(sample_prop~mass, data=cat_data8)
coeff <- coefficients(summary(fit_prop))
eq <- paste0("portion_total_eggs = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass")
mass.seq <- seq(from=0, to=.25, length.out=30)
mu <- link(fit_prop, data=data.frame(mass=mass.seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
plot(as.matrix(cat_data8[1]),
as.matrix(cat_data8[3]),
ylab="Proportion of Total Eggs Laid",
xlab="Mass (g)",
main="Observed proportions of eggs laid by mass",
cex.main=0.8)
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4, cex=0.9)
shade(mu.PI, mass.seq)
# Plot 2 ---------------------------------------------------
fit_eggs <- lm(total_eggs~mass_c, data=data_fem_filtered)
coeff <- coefficients(summary(fit_eggs))
eq <- paste0("total_eggs = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass_c")
mass_c.seq <- seq(from=-.1, to=.15, length.out=30)
mu <- link(fit_eggs, data=data.frame(mass_c=mass_c.seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
plot(total_eggs ~ mass_c, data= data_fem_filtered,
ylab="Total Eggs Laid",
xlab="Mass Centered (g)",
main="Female Data: Total eggs laid by mass",
cex.main=0.9)
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4, cex=0.9)
shade(mu.PI, mass_c.seq)
##### Egg laid day of flight by variations/change in mass ########
# Data Manipulation - filtering, removing duplicates, recentering mass, and calculating changes in mass
data_fem <- data_tested[data_tested$sex=="F",] # 1.) Reselect the data (for integrity purposes)
data_f <- select(data_fem, ID, eggs_b)
duplicates <- data_f[duplicated(data_f),] # 2.) This will give you duplicate rows:
dim(data_f[duplicated(data_f),])[1] # 3.) This will give you the number of duplicates:
## [1] 59
omit <- duplicates$ID # 4.) # Pull out IDs that are duplicate and put them in an omit vector
# 5.) Remove those IDs from the original dataframe and return dataframe of unique values
data_fem_u <- data_fem[!data_fem$ID %in% omit, ]
# 6.) Filter and recenter
data_eggs <- data_fem_u %>%
filter(!is.na(mass))
data_eggs$mass_c <- data_eggs$mass - mean(data_eggs$mass)
# 7.) Determine in diff dataframes which female bugs had egg switch responses (on one day they laid eggs and were tested and on another they were testedthey did not lay eggs)
data_eggs_f <- select(data_eggs, ID, eggs_b)
dupCheck<- data_eggs_f[duplicated(data_eggs_f),] # check that there are no duplicates of ID and eggs_b
dupCheck # if there are zero rows then good
## [1] ID eggs_b
## <0 rows> (or 0-length row.names)
dupIDs <- data_eggs[duplicated(data_eggs$ID),] # duplicated IDs in this set (aka. T2 bugs)
data_eggs_compare <- data_eggs[data_eggs$ID %in% dupIDs$ID, ] # keep all duplicated IDs (aka. T1 and T2 bugs who switch egg repsonse)
#ID_match <- data_eggs_compare[duplicated(data_eggs_compare$ID),]
data_eggs_compare2 <- data_eggs_compare %>% # filter for only T1 bugs
filter(trial_type == "T1")
# NOTE: one bug: ID number 109 had two trial 1's so we'll say the second trial 1 is 'trial 2'
rows_to_keep <- data_eggs_compare2$filename != "set005-2-21-2020-B3_109.txt"
egg_data = data_eggs_compare2[rows_to_keep,]
egg_data_s <- egg_data[order(egg_data$ID),] # Sort the data
ID_match_s <- dupIDs[order(dupIDs$ID),] # Sort the data
By this point we have filtered the data for female bugs that have an egg switch response, meaning, on one day they laid eggs and were tested and on another they were testedthey did not lay eggs. But how did the flight response change? Let’s calculate flight responses and reinscribe those as well.
First, calculate variances/change in mass between trial 1 and trial 2 (between trials). Second, reinscribe flew_b to be 0 if flew in T1 but not T2 and 1 if flew in T2 but not T1
# 8.) Calcualte mass differences and flight response differences for fem bugs who had yes-no egg laying differences.
#######################################################################################
# KEY
#
# if mass diff is + , then mass was gained from T1 to T2
# if mass diff is -, then mass was lost from T1 to T2
#
# if flight diff = 0, then no flight reponse change (flew or did not fly both times))
# if flight diff = -1, then flew in T1 but not T2
# if flight diff = 1, then flew in T2 but not T1
#
#######################################################################################
egg_data_s <- egg_data[order(egg_data$ID),] # Sort the data
egg_data_s
## ID filename trial_type chamber channel_letter set_number
## 18 7 set006-2-24-2020-A2_7.txt T1 A-2 A 6
## 9 12 set003-2-19-2020-A4_12.txt T1 A-4 A 3
## 30 20 set010-2-28-2020-A2_20.txt T1 A-2 A 10
## 27 26 set009-2-27-2020-A4_26.txt T1 A-4 A 9
## 2 37 set001-2-17-2020-A2_37.txt T1 A-2 A 1
## 19 47 set006-2-24-2020-B2_47.txt T1 B-2 B 6
## 21 53 set007-2-25-2020-A3_53.txt T1 A-3 A 7
## 4 63 set001-2-17-2020-B1_63.txt T1 B-1 B 1
## 3 92 set001-2-17-2020-A4_92.txt T1 A-4 A 1
## 23 96 set008-2-26-2020-A2_96.txt T1 A-2 A 8
## 31 97 set010-2-28-2020-A2_97.txt T1 A-2 A 10
## 32 101 set010-2-28-2020-A4_101.txt T1 A-4 A 10
## 8 109 set003-2-19-2020-A4_109.txt T1 A-4 A 3
## 33 116 set010-2-28-2020-B2_116.txt T1 B-2 B 10
## 5 130 set002-2-18-2020-A4_130.txt T1 A-4 A 2
## 13 132 set004-2-20-2020-B1_132.txt T1 B-1 B 4
## 25 140 set008-2-26-2020-A4_140.txt T1 A-4 A 8
## 7 147 set002-2-18-2020-B3_147.txt T1 B-3 B 2
## 12 149 set004-2-20-2020-A2_149.txt T1 A-2 A 4
## 11 151 set003-2-19-2020-B4_151.txt T1 B-4 B 3
## 14 155 set004-2-20-2020-B1_155.txt T1 B-1 B 4
## 22 161 set007-2-25-2020-B2_161.txt T1 B-2 B 7
## 6 164 set002-2-18-2020-B2_164.txt T1 B-2 B 2
## 24 211 set008-2-26-2020-A3_211.txt T1 A-3 A 8
## 34 214 set010-2-28-2020-B3_214.txt T1 B-3 B 10
## 20 233 set006-2-24-2020-B3_233.txt T1 B-3 B 6
## 10 269 set003-2-19-2020-B3_269.txt T1 B-3 B 3
## 16 271 set005-2-21-2020-A4_271.txt T1 A-4 A 5
## 1 318 set001-2-17-2020-A2_318.txt T1 A-2 A 1
## 17 319 set006-2-24-2020-A1_319.txt T1 A-1 A 6
## 15 375 set004-2-20-2020-B4_375.txt T1 B-4 B 4
## 26 407 set008-2-26-2020-B2_407.txt T1 B-2 B 8
## 29 424 set009-2-27-2020-B4_424.txt T1 B-4 B 9
## 28 438 set009-2-27-2020-B1_438.txt T1 B-1 B 9
## average_speed total_flight_time distance shortest_flying_bout
## 18 0.46 40821.69 17696.70 106.25
## 9 0.30 7346.70 2168.89 0.00
## 30 0.52 1653.82 860.77 0.00
## 27 0.40 136.21 30.79 0.00
## 2 0.00 0.00 1.26 0.00
## 19 0.37 27759.02 10115.00 0.00
## 21 0.27 40.83 13.19 0.00
## 4 0.50 1261.41 632.70 0.00
## 3 0.37 110.16 37.70 74.34
## 23 0.00 0.00 0.00 0.00
## 31 0.00 0.00 0.63 0.00
## 32 0.00 0.00 1.26 0.00
## 8 0.00 0.00 0.00 0.00
## 33 0.38 29.09 10.05 0.00
## 5 0.42 27391.98 11170.55 0.00
## 13 0.00 0.00 0.00 0.00
## 25 0.34 23.41 10.68 0.00
## 7 0.30 690.30 6.91 0.00
## 12 0.14 10.77 1.88 0.00
## 11 0.33 8022.63 2576.03 0.00
## 14 0.00 0.00 0.00 0.00
## 22 0.27 23530.80 6072.52 0.00
## 6 0.20 28935.42 5809.89 63.47
## 24 0.00 0.00 0.00 0.00
## 34 0.37 12.89 4.40 0.00
## 20 0.00 0.00 0.00 0.00
## 10 0.46 28561.11 12702.97 0.00
## 16 0.37 12233.13 4344.07 0.00
## 1 0.31 6101.21 1818.30 0.00
## 17 0.22 51.49 16.96 0.00
## 15 0.22 31671.89 6699.56 93.46
## 26 0.00 0.00 0.00 0.00
## 29 0.22 1328.07 251.32 185.63
## 28 0.34 44480.18 14265.55 0.00
## longest_flying_bout recording_duration max_speed test_date time_start
## 18 35892.42 40957.71 0.68 2020-02-24 9:54:00
## 9 7346.70 8490.31 0.47 2020-02-19 11:34:00
## 30 1653.82 2370.39 0.62 2020-02-28 8:01:00
## 27 52.41 2475.51 0.92 2020-02-27 8:56:00
## 2 0.00 1977.11 0.00 2020-02-17 15:07:00
## 19 27707.54 27828.11 0.50 2020-02-24 14:17:00
## 21 16.14 2297.03 0.41 2020-02-25 8:05:00
## 4 1261.41 4210.83 0.57 2020-02-17 8:45:00
## 3 74.34 2258.43 0.51 2020-02-17 12:48:00
## 23 0.00 2180.87 0.00 2020-02-26 9:05:00
## 31 0.00 3266.91 0.00 2020-02-28 10:26:00
## 32 0.00 3288.43 0.00 2020-02-28 10:28:00
## 8 0.00 2031.67 0.00 2020-02-19 13:56:00
## 33 29.09 3288.59 0.49 2020-02-28 10:30:00
## 5 27391.98 28285.15 0.62 2020-02-18 8:05:00
## 13 0.00 2159.71 0.00 2020-02-20 10:48:00
## 25 11.66 2100.77 0.51 2020-02-26 15:55:00
## 7 646.27 2389.27 0.32 2020-02-18 8:45:00
## 12 10.77 2524.95 0.19 2020-02-20 8:50:00
## 11 8022.63 8346.35 0.44 2020-02-19 8:26:00
## 14 0.00 2237.43 0.00 2020-02-20 9:30:00
## 22 23530.80 23902.63 0.46 2020-02-25 9:24:00
## 6 28593.62 30516.39 0.59 2020-02-18 9:21:00
## 24 0.00 2100.83 0.00 2020-02-26 15:54:00
## 34 12.89 2406.31 0.48 2020-02-28 8:06:00
## 20 0.00 2116.03 0.00 2020-02-24 11:10:00
## 10 27116.46 29029.67 0.77 2020-02-19 9:36:00
## 16 12233.13 12407.39 0.56 2020-02-21 9:06:00
## 1 6101.21 6300.43 0.48 2020-02-17 15:39:00
## 17 22.71 2339.43 0.92 2020-02-24 13:35:00
## 15 27292.21 47308.59 0.35 2020-02-20 8:54:00
## 26 0.00 2289.55 0.00 2020-02-26 9:05:00
## 29 1142.44 2721.03 0.33 2020-02-27 8:18:00
## 28 43355.05 44789.15 0.62 2020-02-27 9:37:00
## time_end sex population site host_plant flew flight_type
## 18 21:16:42 F Plantation Key Founder's C. corindum Y C
## 9 13:47:00 F Key Largo KLMRL C. corindum Y C
## 30 08:37:00 F Key Largo JP C. corindum Y B
## 27 09:32:00 F North Key Largo Charlemagne C. corindum Y B
## 2 15:38:00 F North Key Largo Dagny Trellis C. corindum N
## 19 22:00:57 F Homestead SW 296th St K. elegans Y C
## 21 08:37:00 F Lake Placid 110N Main K. elegans Y B
## 4 09:15:00 F Lake Wales Polk Ave K. elegans Y C
## 3 13:22:00 F North Key Largo Dynamite Docks C. corindum Y B
## 23 09:35:00 F North Key Largo MM165 C. corindum N
## 31 11:04:00 F North Key Largo MM165 C. corindum N
## 32 11:04:00 F Plantation Key Aregood Ln C. corindum N
## 8 14:29:00 F Plantation Key Founder's C. corindum N
## 33 11:00:00 F Key Largo JP C. corindum Y B
## 5 15:48:00 F North Key Largo Carysfort C. corindum Y C
## 13 11:21:00 F North Key Largo DD front C. corindum N
## 25 16:30:00 F North Key Largo Dagny Trellis C. corindum Y
## 7 09:16:00 F North Key Largo Dynamite Docks C. corindum Y B
## 12 09:27:00 F North Key Largo Dynamite Docks C. corindum N
## 11 10:44:00 F Homestead SW 296th St K. elegans Y C
## 14 10:05:00 F Homestead SW 296th St K. elegans N
## 22 16:03:00 F Lake Placid 110N Main K. elegans Y C
## 6 17:50:33 F Lake Placid 110N Main K. elegans Y C
## 24 16:30:00 F Key Largo KLMRL C. corindum N
## 34 08:37:00 F Key Largo KLMRL C. corindum Y B
## 20 11:42:00 F North Key Largo Carysfort C. corindum N
## 10 17:40:00 F Lake Placid 110N Main K. elegans Y C
## 16 12:34:00 F Lake Wales Polk Ave K. elegans Y C
## 1 17:34:00 F Key Largo JP C. corindum Y C
## 17 14:11:00 F Key Largo JP C. corindum Y B
## 15 18:46:12 F Lake Wales Polk Ave K. elegans Y C
## 26 09:35:00 F Key Largo JP C. corindum N
## 29 08:50:00 F North Key Largo Charlemagne C. corindum Y CB
## 28 22:03:45 F North Key Largo DD front C. corindum Y BC
## mass EWM latitude longitude total_eggs beak thorax wing body w_morph
## 18 0.064 N 24.96424 -80.56733 8 8.19 3.64 9.30 13.02 L
## 9 0.074 N 25.10002 -80.43752 329 8.79 3.86 10.07 14.00 L
## 30 0.066 N 25.12846 -80.40809 55 8.73 3.59 9.71 13.59 L
## 27 0.039 N 25.19515 -80.34592 33 7.15 3.01 7.91 11.29 L
## 2 0.066 N 25.17557 -80.36780 53 7.44 3.07 7.86 11.20 L
## 19 0.059 N 25.49136 -80.48582 53 7.83 3.40 8.98 12.67 L
## 21 0.106 Y 27.29863 -81.36615 22 8.31 3.71 9.77 13.61 L
## 4 0.069 N 27.89674 -81.58047 144 7.75 3.58 9.34 13.26 L
## 3 0.084 N 25.28675 -80.29059 9 7.85 3.73 9.71 13.20 L
## 23 0.098 Y 25.22752 -80.32838 5 8.18 3.48 8.57 12.28 L
## 31 0.099 N 25.22752 -80.32838 249 8.45 3.95 10.00 14.16 L
## 32 0.090 N 24.97357 -80.55392 130 7.01 3.68 9.23 13.04 L
## 8 0.055 N 24.96424 -80.56733 7 6.76 3.59 9.29 12.87 L
## 33 0.066 N 25.12846 -80.40809 4 7.57 3.33 8.38 12.11 L
## 5 0.062 N 25.25656 -80.31080 7 9.02 3.71 9.47 13.43 L
## 13 0.074 N 25.27349 -80.30410 88 8.29 3.64 9.99 13.81 L
## 25 0.090 N 25.17557 -80.36780 46 9.08 3.71 9.68 13.81 L
## 7 0.066 N 25.28675 -80.29059 56 8.04 3.32 8.36 11.72 L
## 12 0.082 Y 25.28675 -80.29059 72 7.41 3.79 9.98 13.66 L
## 11 0.095 N 25.49136 -80.48582 44 7.09 3.13 8.73 12.08 L
## 14 0.092 Y 25.49136 -80.48582 38 7.01 3.25 8.17 11.63 L
## 22 0.066 N 27.29863 -81.36615 18 6.55 3.27 9.44 12.93 L
## 6 0.053 N 27.29863 -81.36615 61 6.38 3.46 9.10 12.75 L
## 24 0.056 N 25.10002 -80.43752 156 7.70 3.36 9.15 12.65 L
## 34 0.105 N 25.10002 -80.43752 36 7.98 3.57 8.95 12.72 L
## 20 0.066 Y 25.25656 -80.31080 23 6.39 2.88 7.56 10.70 L
## 10 0.059 N 27.29863 -81.36615 103 6.98 3.71 9.85 13.50 L
## 16 0.050 N 27.89674 -81.58047 34 7.59 3.31 9.21 12.82 L
## 1 0.039 N 25.12846 -80.40809 91 7.51 3.31 9.00 12.27 L
## 17 0.099 N 25.12846 -80.40809 70 7.84 3.37 8.61 12.22 L
## 15 0.063 N 27.89674 -81.58047 88 6.62 3.60 9.83 13.61 L
## 26 0.076 Y 25.12846 -80.40809 72 6.39 2.98 6.46 9.82 LS
## 29 0.060 N 25.19515 -80.34592 39 7.32 3.05 8.34 11.68 L
## 28 0.069 N 25.27349 -80.30410 7 6.79 3.61 9.77 13.39 L
## morph_notes tested flew_b host_temp host_c sex_c w_morph_c
## 18 yes 1 C. corindum -1 1 1
## 9 yes 1 C. corindum -1 1 1
## 30 yes 1 C. corindum -1 1 1
## 27 yes 1 C. corindum -1 1 1
## 2 yes 0 C. corindum -1 1 1
## 19 yes 1 K. elegans 1 1 1
## 21 yes 1 K. elegans 1 1 1
## 4 yes 1 K. elegans 1 1 1
## 3 yes 1 C. corindum -1 1 1
## 23 yes 0 C. corindum -1 1 1
## 31 yes 0 C. corindum -1 1 1
## 32 wings torn at the end yes 0 C. corindum -1 1 1
## 8 yes 0 C. corindum -1 1 1
## 33 yes 1 C. corindum -1 1 1
## 5 yes 1 C. corindum -1 1 1
## 13 yes 0 C. corindum -1 1 1
## 25 yes 1 C. corindum -1 1 1
## 7 yes 1 C. corindum -1 1 1
## 12 yes 0 C. corindum -1 1 1
## 11 yes 1 K. elegans 1 1 1
## 14 yes 0 K. elegans 1 1 1
## 22 yes 1 K. elegans 1 1 1
## 6 yes 1 K. elegans 1 1 1
## 24 yes 0 C. corindum -1 1 1
## 34 yes 1 C. corindum -1 1 1
## 20 yes 0 C. corindum -1 1 1
## 10 yes 1 K. elegans 1 1 1
## 16 yes 1 K. elegans 1 1 1
## 1 yes 1 C. corindum -1 1 1
## 17 yes 1 C. corindum -1 1 1
## 15 wings torn at the end yes 1 K. elegans 1 1 1
## 26 yes 0 C. corindum -1 1 0
## 29 yes 1 C. corindum -1 1 1
## 28 yes 1 C. corindum -1 1 1
## eggs_b lat_c sym_dist sym_dist_s minute_duration minute_duration_c
## 18 0 -0.7733926 0.5271220 -0.2206474 682 568.674267
## 9 0 -0.6376175 0.3913469 -0.3502651 141 27.674267
## 30 0 -0.6091748 0.3629042 -0.3774180 39 -74.325733
## 27 0 -0.5424826 0.2962120 -0.4410857 41 -72.325733
## 2 0 -0.5620624 0.3157918 -0.4223938 32 -81.325733
## 19 0 -0.2462706 0.0000000 -0.7238646 463 349.674267
## 21 1 1.5609984 1.8072690 1.0014454 38 -75.325733
## 4 0 2.1591077 2.4053783 1.5724307 70 -43.325733
## 3 0 -0.4508856 0.2046150 -0.5285288 37 -76.325733
## 23 1 -0.5101088 0.2638382 -0.4719914 36 -77.325733
## 31 0 -0.5101088 0.2638382 -0.4719914 54 -59.325733
## 32 0 -0.7640578 0.5177872 -0.2295589 54 -59.325733
## 8 0 -0.7733926 0.5271220 -0.2206474 33 -80.325733
## 33 0 -0.6091748 0.3629042 -0.3774180 54 -59.325733
## 5 0 -0.4810711 0.2348005 -0.4997122 471 357.674267
## 13 0 -0.4641441 0.2178735 -0.5158716 35 -78.325733
## 25 0 -0.5620624 0.3157918 -0.4223938 35 -78.325733
## 7 0 -0.4508856 0.2046150 -0.5285288 39 -74.325733
## 12 1 -0.4508856 0.2046150 -0.5285288 42 -71.325733
## 11 0 -0.2462706 0.0000000 -0.7238646 139 25.674267
## 14 1 -0.2462706 0.0000000 -0.7238646 37 -76.325733
## 22 0 1.5609984 1.8072690 1.0014454 398 284.674267
## 6 0 1.5609984 1.8072690 1.0014454 508 394.674267
## 24 0 -0.6376175 0.3913469 -0.3502651 35 -78.325733
## 34 0 -0.6376175 0.3913469 -0.3502651 40 -73.325733
## 20 1 -0.4810711 0.2348005 -0.4997122 35 -78.325733
## 10 0 1.5609984 1.8072690 1.0014454 483 369.674267
## 16 0 2.1591077 2.4053783 1.5724307 206 92.674267
## 1 0 -0.6091748 0.3629042 -0.3774180 105 -8.325733
## 17 0 -0.6091748 0.3629042 -0.3774180 38 -75.325733
## 15 0 2.1591077 2.4053783 1.5724307 788 674.674267
## 26 1 -0.6091748 0.3629042 -0.3774180 38 -75.325733
## 29 0 -0.5424826 0.2962120 -0.4410857 45 -68.325733
## 28 0 -0.4641441 0.2178735 -0.5158716 746 632.674267
## min_from_IncStart min_from_IncStart_c min_from_IncStart_s days_from_start
## 18 114 -64.79153 -0.45914560 7
## 9 214 35.20847 0.24950504 2
## 30 1 -177.79153 -1.25992081 11
## 27 56 -122.79153 -0.87016296 10
## 2 427 248.20847 1.75893089 0
## 19 377 198.20847 1.40460558 7
## 21 5 -173.79153 -1.23157479 8
## 4 45 -133.79153 -0.94811453 0
## 3 288 109.20847 0.77390651 0
## 23 65 -113.79153 -0.80638441 9
## 31 146 -32.79153 -0.23237739 11
## 32 148 -30.79153 -0.21820438 11
## 8 356 177.20847 1.25578894 2
## 33 150 -28.79153 -0.20403137 11
## 5 5 -173.79153 -1.23157479 1
## 13 168 -10.79153 -0.07647425 3
## 25 475 296.20847 2.09908320 9
## 7 45 -133.79153 -0.94811453 1
## 12 50 -128.79153 -0.91268200 3
## 11 26 -152.79153 -1.08275816 2
## 14 90 -88.79153 -0.62922175 3
## 22 84 -94.79153 -0.67174079 8
## 6 81 -97.79153 -0.69300031 1
## 24 474 295.20847 2.09199669 9
## 34 6 -172.79153 -1.22448828 11
## 20 190 11.20847 0.07942889 7
## 10 96 -82.79153 -0.58670271 2
## 16 66 -112.79153 -0.79929790 4
## 1 459 280.20847 1.98569910 0
## 17 335 156.20847 1.10697231 7
## 15 54 -124.79153 -0.88433598 3
## 26 65 -113.79153 -0.80638441 9
## 29 18 -160.79153 -1.13945021 10
## 28 97 -81.79153 -0.57961620 10
## days_from_start_c mass_c mass_s avg_mass avg_mass_c
## 18 -4.4283388 -0.0108736842 0.46018244 0.0845 0.031653094
## 9 -9.4283388 -0.0008736842 0.86803199 0.1060 0.053153094
## 30 -0.4283388 -0.0088736842 0.54175235 0.0855 0.032653094
## 27 -1.4283388 -0.0358736842 -0.55944141 0.0600 0.007153094
## 2 -11.4283388 -0.0088736842 0.54175235 0.0640 0.011153094
## 19 -4.4283388 -0.0158736842 0.25625767 0.0725 0.019653094
## 21 -3.4283388 0.0311263158 2.17315052 0.0865 0.033653094
## 4 -11.4283388 -0.0058736842 0.66410722 0.0780 0.025153094
## 3 -11.4283388 0.0091263158 1.27588153 0.1110 0.058153094
## 23 -2.4283388 0.0231263158 1.84687089 0.1010 0.048153094
## 31 -0.4283388 0.0241263158 1.88765584 0.1145 0.061653094
## 32 -0.4283388 0.0151263158 1.52059125 0.0770 0.024153094
## 8 -9.4283388 -0.0198736842 0.09311786 0.0540 0.001153094
## 33 -0.4283388 -0.0088736842 0.54175235 0.0755 0.022653094
## 5 -10.4283388 -0.0128736842 0.37861254 0.0580 0.005153094
## 13 -8.4283388 -0.0008736842 0.86803199 0.0710 0.018153094
## 25 -2.4283388 0.0151263158 1.52059125 0.0950 0.042153094
## 7 -10.4283388 -0.0088736842 0.54175235 0.0590 0.006153094
## 12 -8.4283388 0.0071263158 1.19431162 0.0860 0.033153094
## 11 -9.4283388 0.0201263158 1.72451602 0.0880 0.035153094
## 14 -8.4283388 0.0171263158 1.60216116 0.0790 0.026153094
## 22 -3.4283388 -0.0088736842 0.54175235 0.0770 0.024153094
## 6 -10.4283388 -0.0218736842 0.01154795 0.0610 0.008153094
## 24 -2.4283388 -0.0188736842 0.13390281 0.0645 0.011653094
## 34 -0.4283388 0.0301263158 2.13236557 0.0860 0.033153094
## 20 -4.4283388 -0.0088736842 0.54175235 0.0650 0.012153094
## 10 -9.4283388 -0.0158736842 0.25625767 0.0695 0.016653094
## 16 -7.4283388 -0.0248736842 -0.11080691 0.0650 0.012153094
## 1 -11.4283388 -0.0358736842 -0.55944141 0.0505 -0.002346906
## 17 -4.4283388 0.0241263158 1.88765584 0.0820 0.029153094
## 15 -8.4283388 -0.0118736842 0.41939749 0.0705 0.017653094
## 26 -2.4283388 0.0011263158 0.94960189 0.0660 0.013153094
## 29 -1.4283388 -0.0148736842 0.29704263 0.0750 0.022153094
## 28 -1.4283388 -0.0058736842 0.66410722 0.0705 0.017653094
## avg_mass_s total_eggs_c beak_c thorax_c thorax_s body_c
## 18 1.33035302 -95.3608247 1.74364821 0.49786645 1.64448307 1.4933713
## 9 2.23397999 225.6391753 2.34364821 0.71786645 2.37115641 2.4733713
## 30 1.37238218 -48.3608247 2.28364821 0.44786645 1.47933004 2.0633713
## 27 0.30063856 -70.3608247 0.70364821 -0.13213355 -0.43644513 -0.2366287
## 2 0.46875521 -50.3608247 0.99364821 -0.07213355 -0.23826149 -0.3266287
## 19 0.82600308 -50.3608247 1.38364821 0.25786645 0.85174852 1.1433713
## 21 1.41441134 -81.3608247 1.86364821 0.56786645 1.87569732 2.0833713
## 4 1.05716347 40.6391753 1.30364821 0.43786645 1.44629943 1.7333713
## 3 2.44412580 -94.3608247 1.40364821 0.58786645 1.94175853 1.6733713
## 23 2.02383419 -98.3608247 1.73364821 0.33786645 1.11599337 0.7533713
## 31 2.59122787 145.6391753 2.00364821 0.80786645 2.66843187 2.6333713
## 32 1.01513431 26.6391753 0.56364821 0.53786645 1.77660550 1.5133713
## 8 0.04846359 -96.3608247 0.31364821 0.44786645 1.47933004 1.3433713
## 33 0.95209057 -99.3608247 1.12364821 0.18786645 0.62053427 0.5833713
## 5 0.21658024 -96.3608247 2.57364821 0.56786645 1.87569732 1.9033713
## 13 0.76295934 -15.3608247 1.84364821 0.49786645 1.64448307 2.2833713
## 25 1.77165922 -57.3608247 2.63364821 0.56786645 1.87569732 2.2833713
## 7 0.25860940 -47.3608247 1.59364821 0.17786645 0.58750367 0.1933713
## 12 1.39339676 -31.3608247 0.96364821 0.64786645 2.13994217 2.1333713
## 11 1.47745509 -59.3608247 0.64364821 -0.01213355 -0.04007785 0.5533713
## 14 1.09919263 -65.3608247 0.56364821 0.10786645 0.35628942 0.1033713
## 22 1.01513431 -85.3608247 0.10364821 0.12786645 0.42235064 1.4033713
## 6 0.34266772 -42.3608247 -0.06635179 0.31786645 1.04993216 1.2233713
## 24 0.48976979 52.6391753 1.25364821 0.21786645 0.71962609 1.1233713
## 34 1.39339676 -67.3608247 1.53364821 0.42786645 1.41326883 1.1933713
## 20 0.51078437 -80.3608247 -0.05635179 -0.26213355 -0.86584301 -0.8266287
## 10 0.69991560 -0.3608247 0.53364821 0.56786645 1.87569732 1.9733713
## 16 0.51078437 -69.3608247 1.14364821 0.16786645 0.55447306 1.2933713
## 1 -0.09863847 -12.3608247 1.06364821 0.16786645 0.55447306 0.7433713
## 17 1.22528012 -33.3608247 1.39364821 0.22786645 0.75265670 0.6933713
## 15 0.74194476 -15.3608247 0.17364821 0.45786645 1.51236065 2.0833713
## 26 0.55281353 -31.3608247 -0.05635179 -0.16213355 -0.53553695 -1.7066287
## 29 0.93107599 -64.3608247 0.87364821 -0.09213355 -0.30432270 0.1533713
## 28 0.74194476 -96.3608247 0.34364821 0.46786645 1.54539125 1.8633713
## wing_c wing2body wing2body_c wing2body_s trial_type_og
## 18 1.0163355 0.7142857 -4.084348e-03 -0.226345199 T1
## 9 1.7863355 0.7192857 9.156518e-04 0.050743320 T1
## 30 1.4263355 0.7144960 -3.874110e-03 -0.214694257 T1
## 27 -0.3736645 0.7006200 -1.775004e-02 -0.983666723 T1
## 2 -0.4236645 0.7017857 -1.658435e-02 -0.919066495 T1
## 19 0.6963355 0.7087609 -9.609210e-03 -0.532520357 T1
## 21 1.4863355 0.7178545 -5.155438e-04 -0.028570251 T1
## 4 1.0563355 0.7043741 -1.399601e-02 -0.775626468 T1
## 3 1.4263355 0.7356061 1.723600e-02 0.955179437 T1
## 23 0.2863355 0.6978827 -2.048733e-02 -1.135360581 T1
## 31 1.7163355 0.7062147 -1.215537e-02 -0.673622872 T1
## 32 0.9463355 0.7078221 -1.054798e-02 -0.584544642 T1
## 8 1.0063355 0.7218337 3.463659e-03 0.191948047 T1
## 33 0.0963355 0.6919901 -2.637997e-02 -1.461917454 T1
## 5 1.1863355 0.7051378 -1.323231e-02 -0.733304301 T1
## 13 1.7063355 0.7233888 5.018786e-03 0.278129605 T1
## 25 1.3963355 0.7009413 -1.742872e-02 -0.965859400 T1
## 7 0.0763355 0.7133106 -5.059482e-03 -0.280384890 T1
## 12 1.6963355 0.7306003 1.223023e-02 0.677771281 T1
## 11 0.4463355 0.7226821 4.312057e-03 0.238964282 T1
## 14 -0.1136645 0.7024936 -1.587651e-02 -0.879839801 T1
## 22 1.1563355 0.7300851 1.171501e-02 0.649219008 T1
## 6 0.8163355 0.7137255 -4.644572e-03 -0.257391531 T1
## 24 0.8663355 0.7233202 4.950096e-03 0.274322932 T1
## 34 0.6663355 0.7036164 -1.475371e-02 -0.817616746 T1
## 20 -0.7236645 0.7065421 -1.182801e-02 -0.655480955 T1
## 10 1.5663355 0.7296296 1.125957e-02 0.623979356 T1
## 16 0.9263355 0.7184087 3.867386e-05 0.002143217 T1
## 1 0.7163355 0.7334963 1.512627e-02 0.838263151 T1
## 17 0.3263355 0.7045827 -1.378741e-02 -0.764066663 T1
## 15 1.5463355 0.7222630 3.892979e-03 0.215739979 T1
## 26 -1.8236645 0.6578411 -6.052892e-02 -3.354373865 T1
## 29 0.0563355 0.7140411 -4.328967e-03 -0.239901388 T1
## 28 1.4863355 0.7296490 1.127893e-02 0.625052362 T1
## dt_start_c dt_end_c datetime_start
## 18 2020-02-24 9:54:00 2020-02-24 21:16:42 2020-02-24 09:54:00
## 9 2020-02-19 11:34:00 2020-02-19 13:47:00 2020-02-19 11:34:00
## 30 2020-02-28 8:01:00 2020-02-28 08:37:00 2020-02-28 08:01:00
## 27 2020-02-27 8:56:00 2020-02-27 09:32:00 2020-02-27 08:56:00
## 2 2020-02-17 15:07:00 2020-02-17 15:38:00 2020-02-17 15:07:00
## 19 2020-02-24 14:17:00 2020-02-24 22:00:57 2020-02-24 14:17:00
## 21 2020-02-25 8:05:00 2020-02-25 08:37:00 2020-02-25 08:05:00
## 4 2020-02-17 8:45:00 2020-02-17 09:15:00 2020-02-17 08:45:00
## 3 2020-02-17 12:48:00 2020-02-17 13:22:00 2020-02-17 12:48:00
## 23 2020-02-26 9:05:00 2020-02-26 09:35:00 2020-02-26 09:05:00
## 31 2020-02-28 10:26:00 2020-02-28 11:04:00 2020-02-28 10:26:00
## 32 2020-02-28 10:28:00 2020-02-28 11:04:00 2020-02-28 10:28:00
## 8 2020-02-19 13:56:00 2020-02-19 14:29:00 2020-02-19 13:56:00
## 33 2020-02-28 10:30:00 2020-02-28 11:00:00 2020-02-28 10:30:00
## 5 2020-02-18 8:05:00 2020-02-18 15:48:00 2020-02-18 08:05:00
## 13 2020-02-20 10:48:00 2020-02-20 11:21:00 2020-02-20 10:48:00
## 25 2020-02-26 15:55:00 2020-02-26 16:30:00 2020-02-26 15:55:00
## 7 2020-02-18 8:45:00 2020-02-18 09:16:00 2020-02-18 08:45:00
## 12 2020-02-20 8:50:00 2020-02-20 09:27:00 2020-02-20 08:50:00
## 11 2020-02-19 8:26:00 2020-02-19 10:44:00 2020-02-19 08:26:00
## 14 2020-02-20 9:30:00 2020-02-20 10:05:00 2020-02-20 09:30:00
## 22 2020-02-25 9:24:00 2020-02-25 16:03:00 2020-02-25 09:24:00
## 6 2020-02-18 9:21:00 2020-02-18 17:50:33 2020-02-18 09:21:00
## 24 2020-02-26 15:54:00 2020-02-26 16:30:00 2020-02-26 15:54:00
## 34 2020-02-28 8:06:00 2020-02-28 08:37:00 2020-02-28 08:06:00
## 20 2020-02-24 11:10:00 2020-02-24 11:42:00 2020-02-24 11:10:00
## 10 2020-02-19 9:36:00 2020-02-19 17:40:00 2020-02-19 09:36:00
## 16 2020-02-21 9:06:00 2020-02-21 12:34:00 2020-02-21 09:06:00
## 1 2020-02-17 15:39:00 2020-02-17 17:34:00 2020-02-17 15:39:00
## 17 2020-02-24 13:35:00 2020-02-24 14:11:00 2020-02-24 13:35:00
## 15 2020-02-20 8:54:00 2020-02-20 18:46:12 2020-02-20 08:54:00
## 26 2020-02-26 9:05:00 2020-02-26 09:35:00 2020-02-26 09:05:00
## 29 2020-02-27 8:18:00 2020-02-27 08:50:00 2020-02-27 08:18:00
## 28 2020-02-27 9:37:00 2020-02-27 22:03:45 2020-02-27 09:37:00
## datetime_end hr_start hr_end
## 18 2020-02-24 21:16:42 9.900000 21.266667
## 9 2020-02-19 13:47:00 11.566667 13.783333
## 30 2020-02-28 08:37:00 8.016667 8.616667
## 27 2020-02-27 09:32:00 8.933333 9.533333
## 2 2020-02-17 15:38:00 15.116667 15.633333
## 19 2020-02-24 22:00:57 14.283333 22.000000
## 21 2020-02-25 08:37:00 8.083333 8.616667
## 4 2020-02-17 09:15:00 8.750000 9.250000
## 3 2020-02-17 13:22:00 12.800000 13.366667
## 23 2020-02-26 09:35:00 9.083333 9.583333
## 31 2020-02-28 11:04:00 10.433333 11.066667
## 32 2020-02-28 11:04:00 10.466667 11.066667
## 8 2020-02-19 14:29:00 13.933333 14.483333
## 33 2020-02-28 11:00:00 10.500000 11.000000
## 5 2020-02-18 15:48:00 8.083333 15.800000
## 13 2020-02-20 11:21:00 10.800000 11.350000
## 25 2020-02-26 16:30:00 15.916667 16.500000
## 7 2020-02-18 09:16:00 8.750000 9.266667
## 12 2020-02-20 09:27:00 8.833333 9.450000
## 11 2020-02-19 10:44:00 8.433333 10.733333
## 14 2020-02-20 10:05:00 9.500000 10.083333
## 22 2020-02-25 16:03:00 9.400000 16.050000
## 6 2020-02-18 17:50:33 9.350000 17.833333
## 24 2020-02-26 16:30:00 15.900000 16.500000
## 34 2020-02-28 08:37:00 8.100000 8.616667
## 20 2020-02-24 11:42:00 11.166667 11.700000
## 10 2020-02-19 17:40:00 9.600000 17.666667
## 16 2020-02-21 12:34:00 9.100000 12.566667
## 1 2020-02-17 17:34:00 15.650000 17.566667
## 17 2020-02-24 14:11:00 13.583333 14.183333
## 15 2020-02-20 18:46:12 8.900000 18.766667
## 26 2020-02-26 09:35:00 9.083333 9.583333
## 29 2020-02-27 08:50:00 8.300000 8.833333
## 28 2020-02-27 22:03:45 9.616667 22.050000
if (egg_data$ID %in% ID_match_s$ID) {
egg_data_s$mass_diff <- ID_match_s$mass - egg_data_s$mass # T2 - T1 masses differences
egg_data_s$flew_delta <- ID_match_s$flew_b - egg_data_s$flew_b # T2 - T1 flight response differences
}
## Warning in if (egg_data$ID %in% ID_match_s$ID) {: the condition has length > 1
## and only the first element will be used
# 9.) Calcualte the number of times the bug yes flew for all trials
for (row in seq(1:nrow(egg_data_s))) {
egg_data_s$flew_count[row] <- 1 # flew once
if (ID_match_s$flew_b[row] == 1 && egg_data_s$flew_b[row] == 1) {
egg_data_s$flew_count[row] <- 2 # flew twice
}
if (ID_match_s$flew_b[row] == 0 && egg_data_s$flew_b[row] == 0) {
egg_data_s$flew_count[row] <- 0 # didn't fly for either
}
} # 12 of the 34 rows flew twice
egg_data_s2 <- egg_data_s[order(egg_data_s$mass_diff),]
egg_data_compact <- select(egg_data_s2, ID, flew_delta, mass_diff, flew_count)
egg_data_compact
## ID flew_delta mass_diff flew_count
## 21 53 0 -0.039 2
## 34 214 0 -0.038 2
## 17 319 0 -0.034 2
## 32 101 0 -0.026 0
## 14 155 0 -0.026 0
## 26 407 0 -0.020 0
## 7 147 0 -0.014 2
## 11 151 0 -0.014 2
## 5 130 -1 -0.008 1
## 13 132 0 -0.006 0
## 2 37 0 -0.004 0
## 8 109 0 -0.002 0
## 20 233 0 -0.002 0
## 28 438 0 0.003 2
## 23 96 0 0.006 0
## 12 149 0 0.008 0
## 25 140 0 0.010 2
## 15 375 -1 0.015 1
## 6 164 0 0.016 2
## 24 211 0 0.017 0
## 4 63 -1 0.018 1
## 33 116 0 0.019 2
## 10 269 -1 0.021 1
## 22 161 -1 0.022 1
## 1 318 -1 0.023 1
## 19 47 -1 0.027 1
## 16 271 -1 0.030 1
## 29 424 -1 0.030 1
## 31 97 0 0.031 0
## 30 20 -1 0.039 1
## 18 7 0 0.041 2
## 27 26 0 0.042 2
## 3 92 0 0.054 2
## 9 12 -1 0.064 1
Three things noticed:
12 of the 34 rows flew twice (in both trials).
12 of the 34 did not flew at all (in either trial).
there were no cases in which the flight diff = 1, so no female bugs flew in T2 but not T1. But 10 cases of the 34 that flew in T1 but not T2.
# Plot flight proportions by negative | positive mass_change.
cat_data9 <- categorize_data3(egg_data_s2, all_of("mass_diff"), all_of("flew_delta"), 0.005, 0.010, -0.040)
## mass_diff -0.03 Cases: 3 Sample Proportion: 0
## mass_diff -0.02 Cases: 2 Sample Proportion: 0
## mass_diff -0.01 Cases: 3 Sample Proportion: 0
## mass_diff 0.00 Cases: 5 Sample Proportion: -0.2
## mass_diff 0.01 Cases: 3 Sample Proportion: 0
## mass_diff 0.02 Cases: 6 Sample Proportion: -0.3333333
## mass_diff 0.03 Cases: 6 Sample Proportion: -1
## mass_diff 0.04 Cases: 2 Sample Proportion: -0.5
## mass_diff 0.05 Cases: 2 Sample Proportion: 0
## mass_diff 0.06 Cases: 1 Sample Proportion: 0
## mass_diff 0.07 Cases: 1 Sample Proportion: -1
##### Proportion flew for females who laid eggs day of flight in one trial but not the other COMPARED to their variations/change in mass ########
fit <- lm(sample_prop~mass_diff, data=cat_data9)
coeff <- coefficients(summary(fit))
eq <- paste0("portion_flew = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass_diff")
mass_diff.seq <- seq(from=-0.04, to=0.08, length.out=30)
mu <- link(fit, data=data.frame(mass_diff=mass_diff.seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
plot(as.matrix(cat_data9[1]),
as.matrix(cat_data9[3]),
ylim = c(-1,1),
ylab="Proportion Flew Over Trials",
xlab="Mass Differences between T1 to T2 (g)",
main="Observed proportions of yes flew by mass differences between trials",
cex=0.9)
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4, cex=0.9)
shade(mu.PI, mass_diff.seq)
abline(v=0, col="mediumpurple3", type="l", lty=2)
## Warning in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): graphical
## parameter "type" is obsolete
text(0.01, 0.95, c("gained mass"),col="mediumpurple4")
text(-0.009, 0.963, c("lost mass"), col="mediumpurple4")
abline(h=0, col="darkolivegreen4", type="l", lty=2)
## Warning in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): graphical
## parameter "type" is obsolete
text(0.060, 0.087, c("flew in T2 but not T1"),col="darkolivegreen4")
text(0.060, -0.087, c("flew in T1 but not T2"),col="darkolivegreen4")
egg_data_compact
## ID flew_delta mass_diff flew_count
## 21 53 0 -0.039 2
## 34 214 0 -0.038 2
## 17 319 0 -0.034 2
## 32 101 0 -0.026 0
## 14 155 0 -0.026 0
## 26 407 0 -0.020 0
## 7 147 0 -0.014 2
## 11 151 0 -0.014 2
## 5 130 -1 -0.008 1
## 13 132 0 -0.006 0
## 2 37 0 -0.004 0
## 8 109 0 -0.002 0
## 20 233 0 -0.002 0
## 28 438 0 0.003 2
## 23 96 0 0.006 0
## 12 149 0 0.008 0
## 25 140 0 0.010 2
## 15 375 -1 0.015 1
## 6 164 0 0.016 2
## 24 211 0 0.017 0
## 4 63 -1 0.018 1
## 33 116 0 0.019 2
## 10 269 -1 0.021 1
## 22 161 -1 0.022 1
## 1 318 -1 0.023 1
## 19 47 -1 0.027 1
## 16 271 -1 0.030 1
## 29 424 -1 0.030 1
## 31 97 0 0.031 0
## 30 20 -1 0.039 1
## 18 7 0 0.041 2
## 27 26 0 0.042 2
## 3 92 0 0.054 2
## 9 12 -1 0.064 1
cat_data10 <- categorize_data_MF2(egg_data_s2, all_of("mass_diff"), all_of("flew_count"), all_of("flew_delta"), 0.005, 0.010, -0.040)
## Mass -0.03 Flight Count: 2 Cases: 3 Sample Proportion: 0
## Mass -0.02 Flight Count: 0 Cases: 2 Sample Proportion: 0
## Mass -0.01 Flight Count: 0 Cases: 1 Sample Proportion: 0
## Mass -0.01 Flight Count: 2 Cases: 2 Sample Proportion: 0
## Mass 0.00 Flight Count: 1 Cases: 5 Sample Proportion: -0.2
## Mass 0.01 Flight Count: 0 Cases: 2 Sample Proportion: 0
## Mass 0.01 Flight Count: 2 Cases: 1 Sample Proportion: 0
## Mass 0.02 Flight Count: 1 Cases: 3 Sample Proportion: -0.6666667
## Mass 0.02 Flight Count: 2 Cases: 3 Sample Proportion: 0
## Mass 0.03 Flight Count: 1 Cases: 6 Sample Proportion: -1
## Mass 0.04 Flight Count: 0 Cases: 2 Sample Proportion: -0.5
## Mass 0.05 Flight Count: 2 Cases: 2 Sample Proportion: 0
## Mass 0.06 Flight Count: 2 Cases: 1 Sample Proportion: 0
## Mass 0.07 Flight Count: 1 Cases: 1 Sample Proportion: -1
gf_point(sample_prop ~ mass_diff, data=cat_data10, col=~flew_count,
xlab = "Mass Differences between T1 and T2 (g)", ylab= "Proportion Flew Over Trials",
title= "Observed proportions of yes flew by mass differences between trials")
fit <- lm(sample_prop~mass_diff, data=cat_data10)
coeff <- coefficients(summary(fit))
eq <- paste0("portion_flew = ", round(coeff[1],3),
ifelse(sign(coeff[2])==1, " + ", " - "),
abs(round(coeff[2],3)), "*mass_diff")
mass_diff.seq <- seq(from=-0.04, to=0.08, length.out=30)
mu <- link(fit, data=data.frame(mass_diff=mass_diff.seq)) # gives warning
## Warning in .local(fit, data, n, ...): The link method for lm fits is not
## complete and not tested. Proceed with abundant caution.
mu.PI <- apply(mu,2,PI, prob=0.89)
plot(as.matrix(cat_data10[1]),
as.matrix(cat_data10[3]),
#col=c(3,2,1)[as.factor(cat_data10$flew_count)], # green = 2, black = -1
#col=c(1,2)[as.factor(summary$sex)], # Female = Black, Male = Red
pch=c(19,22,21)[as.factor(cat_data10$flew_count)],
ylim = c(-1,1),
ylab="Proportion Flew Over Trials",
xlab="Mass Differences between T1 to T2 (g)",
main="Observed proportions of yes flew by mass differences between trials",
cex=0.9)
abline(coeff[1], coeff[2], col="blue")
mtext(eq, side=4, cex=0.9)
shade(mu.PI, mass_diff.seq)
abline(v=0, col="mediumpurple3", type="l", lty=2)
## Warning in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): graphical
## parameter "type" is obsolete
text(0.01, 0.95, c("gained mass"),col="mediumpurple4")
text(-0.009, 0.963, c("lost mass"), col="mediumpurple4")
abline(h=0, col="darkolivegreen4", type="l", lty=2)
## Warning in int_abline(a = a, b = b, h = h, v = v, untf = untf, ...): graphical
## parameter "type" is obsolete
text(0.060, 0.087, c("flew in T2 but not T1"),col="darkolivegreen4")
text(0.060, -0.087, c("flew in T1 but not T2"),col="darkolivegreen4")
legend("topright",
#legend = c("Both Trials","One Trial", "No Trial"),
legend = c("2", "1", "0"),
#inset=c(-0.03,0.02),
pch = c(19,22,21),
title="Flight Count")
data <- read_flight_data("data/all_flight_data-Winter2020.csv")
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
data_all <- data[[1]]
data_tested <- data[[2]]
# Eggs laid by week graph
eggs_laid <- read.csv("data/egg_data-Winter2020.csv") # go merge ID with population in Python - could also transpose this data into the data_all sheet
# Check which ID's flew to see which female bugs were tested and only keep those
highest_ID <- max(as.integer(data_tested$ID))
cat("Highest ID tested:", highest_ID)
## Highest ID tested: 334
eggs_laid <- filter(eggs_laid, ID <= 333)
# Convert date_collected to a Date object.
eggs_laid$date <- as_date(eggs_laid$date_collected)
eggs_laid
## date_collected ID eggs total_eggs pop date
## 1 2020-02-17 93 1 1 North Key Largo 2020-02-17
## 2 2020-02-17 41 6 255 Homestead 2020-02-17
## 3 2020-02-17 321 9 9 North Key Largo 2020-02-17
## 4 2020-02-17 188 14 148 Leesburg 2020-02-17
## 5 2020-02-17 112 15 241 Key Largo 2020-02-17
## 6 2020-02-17 132 17 88 North Key Largo 2020-02-17
## 7 2020-02-17 148 18 18 North Key Largo 2020-02-17
## 8 2020-02-17 29 20 67 North Key Largo 2020-02-17
## 9 2020-02-17 5 21 209 Plantation Key 2020-02-17
## 10 2020-02-17 327 22 225 North Key Largo 2020-02-17
## 11 2020-02-17 126 31 31 North Key Largo 2020-02-17
## 12 2020-02-17 75 48 48 Leesburg 2020-02-17
## 13 2020-02-17 97 55 249 North Key Largo 2020-02-17
## 14 2020-02-17 13 59 296 Key Largo 2020-02-17
## 15 2020-02-18 16 1 1 Key Largo 2020-02-18
## 16 2020-02-18 195 1 1 Gainesville 2020-02-18
## 17 2020-02-18 111 4 171 Key Largo 2020-02-18
## 18 2020-02-18 135 6 225 North Key Largo 2020-02-18
## 19 2020-02-18 234 7 7 North Key Largo 2020-02-18
## 20 2020-02-18 8 10 92 Plantation Key 2020-02-18
## 21 2020-02-18 227 11 318 North Key Largo 2020-02-18
## 22 2020-02-18 330 11 323 North Key Largo 2020-02-18
## 23 2020-02-18 221 14 138 North Key Largo 2020-02-18
## 24 2020-02-18 244 14 100 North Key Largo 2020-02-18
## 25 2020-02-18 141 15 41 North Key Largo 2020-02-18
## 26 2020-02-18 222 15 330 North Key Largo 2020-02-18
## 27 2020-02-18 328 21 138 North Key Largo 2020-02-18
## 28 2020-02-18 292 22 22 Gainesville 2020-02-18
## 29 2020-02-18 187 25 196 Leesburg 2020-02-18
## 30 2020-02-18 217 25 81 Key Largo 2020-02-18
## 31 2020-02-18 211 26 156 Key Largo 2020-02-18
## 32 2020-02-18 133 30 208 North Key Largo 2020-02-18
## 33 2020-02-18 229 31 347 North Key Largo 2020-02-18
## 34 2020-02-18 101 37 130 Plantation Key 2020-02-18
## 35 2020-02-18 199 38 38 Gainesville 2020-02-18
## 36 2020-02-18 30 40 278 North Key Largo 2020-02-18
## 37 2020-02-18 314 44 92 Key Largo 2020-02-18
## 38 2020-02-18 302 45 45 Plantation Key 2020-02-18
## 39 2020-02-18 241 53 97 North Key Largo 2020-02-18
## 40 2020-02-18 149 55 72 North Key Largo 2020-02-18
## 41 2020-02-18 229 69 347 North Key Largo 2020-02-18
## 42 2020-02-19 106 18 18 Plantation Key 2020-02-19
## 43 2020-02-19 219 20 30 Key Largo 2020-02-19
## 44 2020-02-19 329 34 221 North Key Largo 2020-02-19
## 45 2020-02-20 326 15 147 North Key Largo 2020-02-20
## 46 2020-02-20 227 35 318 North Key Largo 2020-02-20
## 47 2020-02-20 115 106 226 Key Largo 2020-02-20
## 48 2020-02-25 29 7 67 North Key Largo 2020-02-25
## 49 2020-02-25 140 7 46 North Key Largo 2020-02-25
## 50 2020-02-25 219 10 30 Key Largo 2020-02-25
## 51 2020-02-25 136 15 117 North Key Largo 2020-02-25
## 52 2020-02-25 149 17 72 North Key Largo 2020-02-25
## 53 2020-02-25 37 20 53 North Key Largo 2020-02-25
## 54 2020-02-25 326 20 147 North Key Largo 2020-02-25
## 55 2020-02-25 141 26 41 North Key Largo 2020-02-25
## 56 2020-02-25 147 27 56 North Key Largo 2020-02-25
## 57 2020-02-25 318 33 91 Key Largo 2020-02-25
## 58 2020-02-25 31 35 114 North Key Largo 2020-02-25
## 59 2020-02-25 133 36 208 North Key Largo 2020-02-25
## 60 2020-02-25 132 38 88 North Key Largo 2020-02-25
## 61 2020-02-25 101 40 130 Plantation Key 2020-02-25
## 62 2020-02-25 115 40 226 Key Largo 2020-02-25
## 63 2020-02-25 221 40 138 North Key Largo 2020-02-25
## 64 2020-02-25 91 42 114 North Key Largo 2020-02-25
## 65 2020-02-25 241 44 97 North Key Largo 2020-02-25
## 66 2020-02-25 217 50 81 Key Largo 2020-02-25
## 67 2020-02-25 111 52 171 Key Largo 2020-02-25
## 68 2020-02-25 8 53 92 Plantation Key 2020-02-25
## 69 2020-02-25 27 67 158 North Key Largo 2020-02-25
## 70 2020-02-25 135 89 225 North Key Largo 2020-02-25
## 71 2020-02-25 227 93 318 North Key Largo 2020-02-25
## 72 2020-02-25 229 95 347 North Key Largo 2020-02-25
## 73 2020-02-25 330 109 323 North Key Largo 2020-02-25
## 74 2020-02-25 112 121 241 Key Largo 2020-02-25
## 75 2020-02-26 63 6 144 Lake Wales 2020-02-26
## 76 2020-02-26 43 8 54 Homestead 2020-02-26
## 77 2020-02-26 188 9 148 Leesburg 2020-02-26
## 78 2020-02-26 41 12 255 Homestead 2020-02-26
## 79 2020-02-26 155 12 38 Homestead 2020-02-26
## 80 2020-02-26 233 12 23 North Key Largo 2020-02-26
## 81 2020-02-26 5 13 209 Plantation Key 2020-02-26
## 82 2020-02-26 164 17 61 Lake Placid 2020-02-26
## 83 2020-02-26 97 19 249 North Key Largo 2020-02-26
## 84 2020-02-26 237 23 59 North Key Largo 2020-02-26
## 85 2020-02-26 59 24 56 Lake Placid 2020-02-26
## 86 2020-02-26 151 27 44 Homestead 2020-02-26
## 87 2020-02-26 314 33 92 Key Largo 2020-02-26
## 88 2020-02-26 269 36 103 Lake Placid 2020-02-26
## 89 2020-02-26 254 38 82 Homestead 2020-02-26
## 90 2020-02-26 176 39 75 Lake Wales 2020-02-26
## 91 2020-02-26 328 40 138 North Key Largo 2020-02-26
## 92 2020-02-26 211 47 156 Key Largo 2020-02-26
## 93 2020-02-26 329 59 221 North Key Largo 2020-02-26
## 94 2020-02-26 327 67 225 North Key Largo 2020-02-26
## 95 2020-02-26 244 68 100 North Key Largo 2020-02-26
## 96 2020-02-26 30 76 278 North Key Largo 2020-02-26
## 97 2020-02-26 156 83 153 Homestead 2020-02-26
## 98 2020-02-26 187 90 196 Leesburg 2020-02-26
## 99 2020-02-26 246 90 155 North Key Largo 2020-02-26
## 100 2020-02-26 222 123 330 North Key Largo 2020-02-26
## 101 2020-03-02 233 10 23 North Key Largo 2020-03-02
## 102 2020-03-02 13 15 296 Key Largo 2020-03-02
## 103 2020-03-02 92 3 9 North Key Largo 2020-03-02
## 104 2020-03-02 328 25 138 North Key Largo 2020-03-02
## 105 2020-03-02 29 15 67 North Key Largo 2020-03-02
## 106 2020-03-02 187 59 196 Leesburg 2020-03-02
## 107 2020-03-02 37 21 53 North Key Largo 2020-03-02
## 108 2020-03-02 136 30 117 North Key Largo 2020-03-02
## 109 2020-03-02 155 15 38 Homestead 2020-03-02
## 110 2020-03-02 329 52 221 North Key Largo 2020-03-02
## 111 2020-03-02 319 59 70 Key Largo 2020-03-02
## 112 2020-03-02 327 59 225 North Key Largo 2020-03-02
## 113 2020-03-02 164 22 61 Lake Placid 2020-03-02
## 114 2020-03-02 112 58 241 Key Largo 2020-03-02
## 115 2020-03-02 97 61 249 North Key Largo 2020-03-02
## 116 2020-03-02 5 57 209 Plantation Key 2020-03-02
## 117 2020-03-02 130 5 7 North Key Largo 2020-03-02
## 118 2020-03-02 132 14 88 North Key Largo 2020-03-02
## 119 2020-03-02 59 28 56 Lake Placid 2020-03-02
## 120 2020-03-02 140 16 46 North Key Largo 2020-03-02
## 121 2020-03-02 41 56 255 Homestead 2020-03-02
## 122 2020-03-02 156 56 153 Homestead 2020-03-02
## 123 2020-03-02 188 32 148 Leesburg 2020-03-02
## 124 2020-03-02 63 63 144 Lake Wales 2020-03-02
## 125 2020-03-02 53 22 22 Lake Placid 2020-03-02
## 126 2020-03-02 47 1 53 Homestead 2020-03-02
## 127 2020-03-02 111 72 171 Key Largo 2020-03-02
## 128 2020-03-02 43 24 54 Homestead 2020-03-02
## 129 2020-03-02 91 33 114 North Key Largo 2020-03-02
## 130 2020-03-02 27 60 158 North Key Largo 2020-03-02
## 131 2020-03-02 31 33 114 North Key Largo 2020-03-02
## 132 2020-03-02 30 67 278 North Key Largo 2020-03-02
## 133 2020-03-02 54 43 89 Lake Placid 2020-03-02
## 134 2020-03-02 96 5 5 North Key Largo 2020-03-02
## 135 2020-03-02 12 161 329 Key Largo 2020-03-02
## 136 2020-03-02 8 29 92 Plantation Key 2020-03-02
## 137 2020-03-02 211 4 156 Key Largo 2020-03-02
## 138 2020-03-02 253 30 34 Homestead 2020-03-02
## 139 2020-03-02 271 24 34 Lake Wales 2020-03-02
## 140 2020-03-02 217 3 81 Key Largo 2020-03-02
## 141 2020-03-02 269 16 103 Lake Placid 2020-03-02
## 142 2020-03-02 221 37 138 North Key Largo 2020-03-02
## 143 2020-03-02 227 85 318 North Key Largo 2020-03-02
## 144 2020-03-02 229 78 347 North Key Largo 2020-03-02
## 145 2020-03-02 237 15 59 North Key Largo 2020-03-02
## 146 2020-03-02 314 14 92 Key Largo 2020-03-02
## 147 2020-03-02 326 27 147 North Key Largo 2020-03-02
## 148 2020-03-02 330 113 323 North Key Largo 2020-03-02
## 149 2020-03-02 318 28 91 Key Largo 2020-03-02
## 150 2020-03-02 222 99 330 North Key Largo 2020-03-02
## 151 2020-03-02 254 13 82 Homestead 2020-03-02
## 152 2020-03-02 244 18 100 North Key Largo 2020-03-02
## 153 2020-03-02 214 32 36 Key Largo 2020-03-02
## 154 2020-03-02 246 47 155 North Key Largo 2020-03-02
## 155 2020-03-02 176 28 75 Lake Wales 2020-03-02
## 156 2020-03-02 151 12 44 Homestead 2020-03-02
## 157 2020-03-02 147 7 56 North Key Largo 2020-03-02
## 158 2020-03-02 133 57 208 North Key Largo 2020-03-02
## 159 2020-03-02 161 7 18 Lake Placid 2020-03-02
## 160 2020-03-02 101 26 130 Plantation Key 2020-03-02
## 161 2020-03-02 115 77 226 Key Largo 2020-03-02
## 162 2020-03-02 135 60 225 North Key Largo 2020-03-02
## 163 2020-03-10 31 46 114 North Key Largo 2020-03-10
## 164 2020-03-10 214 4 36 Key Largo 2020-03-10
## 165 2020-03-10 130 2 7 North Key Largo 2020-03-10
## 166 2020-03-10 253 4 34 Homestead 2020-03-10
## 167 2020-03-10 269 51 103 Lake Placid 2020-03-10
## 168 2020-03-10 222 93 330 North Key Largo 2020-03-10
## 169 2020-03-10 5 39 209 Plantation Key 2020-03-10
## 170 2020-03-10 211 79 156 Key Largo 2020-03-10
## 171 2020-03-10 20 55 55 Key Largo 2020-03-10
## 172 2020-03-10 319 11 70 Key Largo 2020-03-10
## 173 2020-03-10 188 42 148 Leesburg 2020-03-10
## 174 2020-03-10 330 90 323 North Key Largo 2020-03-10
## 175 2020-03-10 7 8 8 Plantation Key 2020-03-10
## 176 2020-03-10 147 22 56 North Key Largo 2020-03-10
## 177 2020-03-10 101 27 130 Plantation Key 2020-03-10
## 178 2020-03-10 221 47 138 North Key Largo 2020-03-10
## 179 2020-03-10 63 75 144 Lake Wales 2020-03-10
## 180 2020-03-10 135 70 225 North Key Largo 2020-03-10
## 181 2020-03-10 69 19 19 Lake Wales 2020-03-10
## 182 2020-03-10 27 31 158 North Key Largo 2020-03-10
## 183 2020-03-10 91 39 114 North Key Largo 2020-03-10
## 184 2020-03-10 47 52 53 Homestead 2020-03-10
## 185 2020-03-10 13 60 296 Key Largo 2020-03-10
## 186 2020-03-10 29 25 67 North Key Largo 2020-03-10
## 187 2020-03-10 37 12 53 North Key Largo 2020-03-10
## 188 2020-03-10 97 80 249 North Key Largo 2020-03-10
## 189 2020-03-10 161 11 18 Lake Placid 2020-03-10
## 190 2020-03-10 151 5 44 Homestead 2020-03-10
## 191 2020-03-10 140 23 46 North Key Largo 2020-03-10
## 192 2020-03-10 112 47 241 Key Largo 2020-03-10
## 193 2020-03-10 176 8 75 Lake Wales 2020-03-10
## 194 2020-03-10 41 70 255 Homestead 2020-03-10
## 195 2020-03-10 318 30 91 Key Largo 2020-03-10
## 196 2020-03-10 43 22 54 Homestead 2020-03-10
## 197 2020-03-10 227 94 318 North Key Largo 2020-03-10
## 198 2020-03-10 237 21 59 North Key Largo 2020-03-10
## 199 2020-03-10 92 6 9 North Key Largo 2020-03-10
## 200 2020-03-10 30 95 278 North Key Largo 2020-03-10
## 201 2020-03-10 254 31 82 Homestead 2020-03-10
## 202 2020-03-10 155 11 38 Homestead 2020-03-10
## 203 2020-03-10 26 33 33 North Key Largo 2020-03-10
## 204 2020-03-10 115 3 226 Key Largo 2020-03-10
## 205 2020-03-10 116 4 4 Key Largo 2020-03-10
## 206 2020-03-10 179 3 3 Lake Wales 2020-03-10
## 207 2020-03-10 48 2 2 Homestead 2020-03-10
## 208 2020-03-10 187 22 196 Leesburg 2020-03-10
## 209 2020-03-10 54 14 89 Lake Placid 2020-03-10
## 210 2020-03-10 332 4 4 North Key Largo 2020-03-10
## 211 2020-03-10 217 3 81 Key Largo 2020-03-10
## 212 2020-03-10 233 1 23 North Key Largo 2020-03-10
## 213 2020-03-10 246 18 155 North Key Largo 2020-03-10
## 214 2020-03-10 156 14 153 Homestead 2020-03-10
## 215 2020-03-10 59 4 56 Lake Placid 2020-03-10
## 216 2020-03-10 314 1 92 Key Largo 2020-03-10
## 217 2020-03-10 271 10 34 Lake Wales 2020-03-10
## 218 2020-03-10 251 2 2 Homestead 2020-03-10
## 219 2020-03-10 42 1 1 Homestead 2020-03-10
## 220 2020-03-10 12 168 329 Key Largo 2020-03-10
## 221 2020-03-10 229 74 347 North Key Largo 2020-03-10
## 222 2020-03-10 164 22 61 Lake Placid 2020-03-10
## 223 2020-03-10 308 2 2 Plantation Key 2020-03-10
## 224 2020-03-10 328 52 138 North Key Largo 2020-03-10
## 225 2020-03-10 329 76 221 North Key Largo 2020-03-10
## 226 2020-03-10 133 85 208 North Key Largo 2020-03-10
## 227 2020-03-10 132 19 88 North Key Largo 2020-03-10
## 228 2020-03-10 136 72 117 North Key Largo 2020-03-10
## 229 2020-03-10 326 85 147 North Key Largo 2020-03-10
## 230 2020-03-10 327 77 225 North Key Largo 2020-03-10
## 231 2020-03-10 111 43 171 Key Largo 2020-03-10
## 232 2020-02-24 188 51 148 Leesburg 2020-02-24
## 233 2020-02-24 97 34 249 North Key Largo 2020-02-24
## 234 2020-02-24 5 79 209 Plantation Key 2020-02-24
## 235 2020-02-24 41 111 255 Homestead 2020-02-24
## 236 2020-02-24 109 7 7 Plantation Key 2020-02-24
## 237 2020-02-24 13 162 296 Key Largo 2020-02-24
## 238 2020-02-24 54 32 89 Lake Placid 2020-02-24
# Make sure all the eggs are summed up for that week
df <- eggs_laid %>%
group_by(ID, date,pop) %>%
summarise(egg_n = sum(eggs))
## `summarise()` has grouped output by 'ID', 'date'. You can override using the `.groups` argument.
# Cumulative sum of eggs through time
df <- df %>%
group_by(c(ID)) %>%
mutate(c_eggs = cumsum(egg_n))
# For simplicity, add a new column - days_from_EggStart (days from when first collected eggs)
df$days_from_EggStart <- df$date - df$date[1]
# Calculate mean eggs each day laid by all females:
d <- c()
m <- c()
for (i in 1:max(df$days_from_EggStart)) {
df_day <- filter(df, days_from_EggStart == i)
if (nrow(df_day) == 0 | nrow(df_day) ==1) { # those that only said eggs once removed.
next
}
d <- c(d, i)
mean <- round(mean(df_day$c_eggs))
m <- c(m,mean)
}
# Plot all lines - could color by population or distance from the sympatric zone or do the mean of each population
cols <- terrain.colors(max(df$ID))
plot(NA, ylim = c(0, 360), xlim = c(0, 24),
xlab="Days From First Egg Collection",
ylab="Cumulative Eggs Laid",
main="Cumulative Eggs Laid Over Time",
bty="n")
df_m <- c()
for(i in 1:max(df$ID)) {
df_ID <- filter(df, ID == i)
if (nrow(df_ID) == 0 | nrow(df_ID) == 1) { # those that only said eggs once removed.
next
}
lines(c_eggs ~ days_from_EggStart, data=df_ID, type="o", col=cols[i])
}
lines(d, m, type="o")
text(23.5,110, labels = c("mean"))
rand_colors <- randomColor(df$ID, luminosity="bright")
# Group and calcualte mean eggs laid each day by population:
plot(NA, ylim = c(0, 250), xlim = c(0, 28),
xlab="Days From First Egg Collection",
ylab="Mean Eggs Laid",
main="Mean Eggs Laid Over Time By Population",
bty="n")
pops <- unique(unlist(df$pop))
e <- 0
o <- -1
for (p in 1:length(pops)) {
df_pop <- filter(df, pop == pops[p])
days <- c()
pm <- c()
for (d in 1:max(df_pop$days_from_EggStart)) { # want the mean of each day for each population
df_pop_day <- filter(df_pop,days_from_EggStart == d )
if (nrow(df_pop_day) == 0 ) {
next }
days <- c(days, d)
pop_m <- round(mean(df_pop_day$c_eggs))
pm <- c(pm, pop_m)
}
lines(days, pm, type="o", col=rand_colors[p]) # why won't the color change??
if (p %% 2 == 0) {
e <- e + 2
text(x=25.5, y=pop_m, labels=pops[e],cex=0.8)
} else {
o <- o + 2
text(x=25.5, y=(pop_m+10), labels=pops[o],cex=0.8)
}
}
data <- read_flight_data("data/all_flight_data-Winter2020.csv")
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
## Warning in d$latitude - sym_zone: longer object length is not a multiple of
## shorter object length
data_all <- data[[1]]
data_tested <- data[[2]]
data_male <- data_tested[data_tested$sex=="M",]
plot(data_male$sym_dist, data_male$flew_b)
male_sum <-aggregate(flew_b~host_plant*sym_dist, data=data_male, FUN="mean")
male_sum
## host_plant sym_dist flew_b
## 1 K. elegans 0.0000000 0.4230769
## 2 C. corindum 0.2046150 0.5000000
## 3 C. corindum 0.2178735 0.7647059
## 4 C. corindum 0.2348005 0.9500000
## 5 C. corindum 0.2638382 0.5714286
## 6 C. corindum 0.2962120 0.8421053
## 7 C. corindum 0.3092689 0.6981132
## 8 C. corindum 0.3157918 0.7727273
## 9 C. corindum 0.3629042 0.6363636
## 10 C. corindum 0.3913469 0.5000000
## 11 C. corindum 0.5177872 0.5862069
## 12 C. corindum 0.5271220 0.8536585
## 13 K. elegans 1.8072690 0.7600000
## 14 K. elegans 2.4053783 0.6250000
## 15 K. elegans 3.3049815 0.8125000
## 16 K. elegans 4.1706402 0.5000000
par(mar=c(6.5, 5.5, 5.5, 9.5), xpd=TRUE) # Add extra space to right of plot area; change clipping to figure
plot(male_sum$flew_b~male_sum$sym_dist,
pch=c(19,22)[as.factor(male_sum$host_plant)],
main="Observed Data",
xlab = "Distance from Sympatric Zone (°)",
ylab= "Proportion Flew", # K. elegans = Squares C.corindum = circles
#sub=eq_glmer
)
legend("topright",
legend = c("C.corindum","K.elegans"),
inset=c(-0.23,0.2),
pch = c(19,22),
title="Groups")
cat_data7 <- categorize_data(data_male, all_of("sym_dist"), all_of("flew_b"), 0.1, 0, 0.05)
## sym_dist 0.05 Cases: 26 Sample Proportion: 0.4230769
## sym_dist 0.25 Cases: 58 Sample Proportion: 0.8103448
## sym_dist 0.35 Cases: 75 Sample Proportion: 0.72
## sym_dist 0.55 Cases: 70 Sample Proportion: 0.7428571
## sym_dist 1.85 Cases: 25 Sample Proportion: 0.76
## sym_dist 2.45 Cases: 8 Sample Proportion: 0.625
## sym_dist 3.35 Cases: 16 Sample Proportion: 0.8125
fit_male <- lm(flew_b~sym_dist, data=data_male)
coeffm <- coefficients(summary(fit_male))
coeffm
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.69670394 0.02885293 24.1467338 7.544215e-80
## sym_dist -0.01600994 0.02041235 -0.7843261 4.333177e-01
eq <- paste0("portion_flew = ", round(coeffm[1],3),
ifelse(sign(coeffm[2])==1, " + ", " - "),
abs(round(coeffm[2],3)), "*sym_dist")
plot(as.matrix(cat_data7[1]),
as.matrix(cat_data7[3]),
ylab="Sample Proportion of Yes Flew",
xlab="Distance From Sympatric Zone (°)",
main="Observed proportions of yes flew by distance from sympatric zone")
abline(coeffm[1], coeffm[2], col="blue")
mtext(eq, side=4)
plot(data_male$mass, data_male$flew_b) # only a few large ones...really driving this but need to go back and check in the morphology if it's a typo or a a big male, but beside that looks pretty 50-50