df <- read_csv("pollen.dates.csv", col_types = cols(treatment = col_factor(levels = c("1","2", "3", "4")), pollen.start = col_date(format = "%m/%d/%Y"),start.time = col_time(format = "%H:%M:%S"),pollen.end = col_date(format = "%m/%d/%Y"),end.time = col_time(format = "%H:%M:%S"),colony.start = col_date(format = "%m/%d/%Y")))
## Warning: The following named parsers don't match the column names: colony.start
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
df$colony <- as.factor(df$colony)
#https://stackoverflow.com/questions/75580470/emtrends-in-presence-of-a-quadratic-term-difference-in-quadratic-trends
##NEW TIME Variable
df$pollen.time <- as.numeric(df$pollen.time)
df$block <- as.factor(df$block)
LM.fit <- lmer(whole_dif~crithidia*fungicide*poly(pollen.time,2)+(1|colony) + block, data = df)
LM.fit2 <- lmer(whole_dif~(crithidia+fungicide+poly(pollen.time,2))^2+(1|colony) + block, data = df)
LM.fit3 <- lmer(whole_dif~(crithidia+fungicide+poly(pollen.time,2))^2+(1|colony), data = df)
LM.fit4 <- lmer(whole_dif~(crithidia*fungicide+poly(pollen.time,2))^2+(1|colony), data = df)
summary(LM.fit2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: whole_dif ~ (crithidia + fungicide + poly(pollen.time, 2))^2 +
## (1 | colony) + block
## Data: df
##
## REML criterion at convergence: -344.9
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.6514 -0.5244 -0.1313 0.4560 4.6582
##
## Random effects:
## Groups Name Variance Std.Dev.
## colony (Intercept) 0.02156 0.1468
## Residual 0.03095 0.1759
## Number of obs: 733, groups: colony, 35
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 0.42954 0.08771 4.897
## crithidiaTRUE -0.12779 0.07454 -1.714
## fungicideTRUE -0.06971 0.07161 -0.974
## poly(pollen.time, 2)1 2.94132 0.31792 9.252
## poly(pollen.time, 2)2 -2.75860 0.32161 -8.577
## block4 0.45781 0.10748 4.259
## block6 -0.15034 0.10713 -1.403
## block7 0.02902 0.10743 0.270
## block8 0.13906 0.10737 1.295
## block9 0.04396 0.10738 0.409
## block10 0.21771 0.11704 1.860
## block11 -0.09109 0.10723 -0.849
## block12 0.07204 0.10725 0.672
## crithidiaTRUE:fungicideTRUE 0.02148 0.10331 0.208
## crithidiaTRUE:poly(pollen.time, 2)1 -1.35371 0.35888 -3.772
## crithidiaTRUE:poly(pollen.time, 2)2 0.81627 0.36106 2.261
## fungicideTRUE:poly(pollen.time, 2)1 -0.10258 0.35990 -0.285
## fungicideTRUE:poly(pollen.time, 2)2 0.87969 0.36215 2.429
anova(LM.fit2, LM.fit, test = "Chi")
## Data: df
## Models:
## LM.fit2: whole_dif ~ (crithidia + fungicide + poly(pollen.time, 2))^2 + (1 | colony) + block
## LM.fit: whole_dif ~ crithidia * fungicide * poly(pollen.time, 2) + (1 | colony) + block
## npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
## LM.fit2 20 -352.13 -260.19 196.06 -392.13
## LM.fit 22 -349.80 -248.67 196.90 -393.80 1.6763 2 0.4325
anova(LM.fit2, LM.fit3, test = "Chi")
## Data: df
## Models:
## LM.fit3: whole_dif ~ (crithidia + fungicide + poly(pollen.time, 2))^2 + (1 | colony)
## LM.fit2: whole_dif ~ (crithidia + fungicide + poly(pollen.time, 2))^2 + (1 | colony) + block
## npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
## LM.fit3 12 -330.81 -275.64 177.41 -354.81
## LM.fit2 20 -352.13 -260.19 196.06 -392.13 37.318 8 1.006e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
AIC(LM.fit2, LM.fit3, LM.fit4)
## df AIC
## LM.fit2 20 -304.8886
## LM.fit3 12 -313.1797
## LM.fit4 14 -313.3530
Anova(LM.fit3)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: whole_dif
## Chisq Df Pr(>Chisq)
## crithidia 2.7397 1 0.09788 .
## fungicide 0.4755 1 0.49048
## poly(pollen.time, 2) 279.3323 2 < 2.2e-16 ***
## crithidia:fungicide 0.0649 1 0.79894
## crithidia:poly(pollen.time, 2) 20.0616 2 4.402e-05 ***
## fungicide:poly(pollen.time, 2) 5.7454 2 0.05654 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(LM.fit)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: whole_dif
## Chisq Df Pr(>Chisq)
## crithidia 5.0655 1 0.02441 *
## fungicide 1.3478 1 0.24566
## poly(pollen.time, 2) 279.5854 2 < 2.2e-16 ***
## block 43.4624 8 7.187e-07 ***
## crithidia:fungicide 0.0431 1 0.83563
## crithidia:poly(pollen.time, 2) 20.0698 2 4.384e-05 ***
## fungicide:poly(pollen.time, 2) 6.0573 2 0.04838 *
## crithidia:fungicide:poly(pollen.time, 2) 1.7097 2 0.42536
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(LM.fit4)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: whole_dif
## Chisq Df Pr(>Chisq)
## crithidia 2.7377 1 0.09800 .
## fungicide 0.4751 1 0.49064
## poly(pollen.time, 2) 279.2567 2 < 2.2e-16 ***
## crithidia:fungicide 0.0648 1 0.79901
## crithidia:poly(pollen.time, 2) 20.0562 2 4.414e-05 ***
## fungicide:poly(pollen.time, 2) 5.7438 2 0.05659 .
## crithidia:fungicide:poly(pollen.time, 2) 1.7906 2 0.40848
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#LM.fit3 fits better
par(mar = c(5, 5, 4, 2) + 0.1)
df$time2 <- df$pollen.time^2
# Calculate fitted values
time.quad2 <- lme(whole_dif ~ treatment * pollen.time + treatment * time2,
random = list(colony = pdDiag(~ pollen.time)), data = df)
fitted3 <- fitted(time.quad2, level = 0)
# Create a data frame with ordered values
a <- with(df,
data.frame(pollen.time, fitted3, treatment)[order(treatment, pollen.time), ])
# Set the font size multiplier and symbol size multiplier
font_multiplier <- 2
symbol_multiplier <- 2 # Adjust this for larger symbols
legend_cex <- 1.5
# Assuming you have standard error data, here's an example
se <- with(a, tapply(fitted3, treatment, function(x) sd(x)/sqrt(length(x))))
# Plot
with(a, {
# Plot data for treatment 1
plot(pollen.time[treatment==1], fitted3[treatment==1],
ylab = "Average Pollen Consumption (g)", xlab = "Time (days)",
col = "darkorchid4", type = "b", pch = 1,
cex.lab = font_multiplier, # Size of axis labels
cex.axis = font_multiplier, # Size of axis numbers
cex = symbol_multiplier) # Size of symbols
# Add standard error ribbon for treatment 1
polygon(c(pollen.time[treatment==1], rev(pollen.time[treatment==1])),
c(fitted3[treatment==1] + se[1], rev(fitted3[treatment==1] - se[1])),
col = adjustcolor("darkorchid4", alpha.f = 0.2), border = NA)
# Add points for other treatments with increased symbol size
points(pollen.time[treatment==2], fitted3[treatment==2],
pch = 4, col = "dodgerblue", type = "b",
cex = symbol_multiplier) # Size of symbols
# Add standard error ribbon for treatment 2
polygon(c(pollen.time[treatment==2], rev(pollen.time[treatment==2])),
c(fitted3[treatment==2] + se[2], rev(fitted3[treatment==2] - se[2])),
col = adjustcolor("dodgerblue", alpha.f = 0.2), border = NA)
points(pollen.time[treatment==3], fitted3[treatment==3],
pch = 16, col = "orange4", type = "b",
cex = symbol_multiplier) # Size of symbols
# Add standard error ribbon for treatment 3
polygon(c(pollen.time[treatment==3], rev(pollen.time[treatment==3])),
c(fitted3[treatment==3] + se[3], rev(fitted3[treatment==3] - se[3])),
col = adjustcolor("orange4", alpha.f = 0.2), border = NA)
points(pollen.time[treatment==4], fitted3[treatment==4],
pch = 17, col = "orange", type = "b",
cex = symbol_multiplier) # Size of symbols
# Add standard error ribbon for treatment 4
polygon(c(pollen.time[treatment==4], rev(pollen.time[treatment==4])),
c(fitted3[treatment==4] + se[4], rev(fitted3[treatment==4] - se[4])),
col = adjustcolor("orange", alpha.f = 0.2), border = NA)
# Add a legend with larger font
legend("topleft", legend = c(" Control", "Fungicide", "Fungicide + Crithidia", "Crithidia"),
col = c("darkorchid4", "dodgerblue", "orange4", "orange"), pch = c(1, 4, 16, 17),
lty = 1, cex = legend_cex, bty= "n")
})
qpcr <- read_csv("qpcr.csv",
col_types = cols(inoculate_round = col_factor(levels = c("1",
"2", "3")), inoculate_01 = col_logical(),
`end date` = col_date(format = "%m/%d/%Y"),
treatment = col_factor(levels = c("3",
"4")), replicate = col_factor(levels = c("1",
"4", "5", "6", "7", "8", "9",
"10", "11", "12")), start = col_date(format = "%m/%d/%Y"),
innoculation_date = col_date(format = "%m/%d/%Y"),
date = col_date(format = "%m/%d/%Y"),
alive_or_dead = col_logical()))
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
qpcr$fungicide <- as.logical(qpcr$fungicide)
qpcr$crithidia <- as.logical(qpcr$crithidia)
qpcr$qro <- as.factor(qpcr$qro)
qpcr$colony <- as.factor(qpcr$colony)
qpcr$premature_death <- as.factor(qpcr$premature_death)
qpcr$dry <- as.double(qpcr$dry)
qpcr$bee_id <- as.factor(qpcr$bee_id)
qpcr$cell_include <- as.numeric(qpcr$cell_include)
qpcr$col_days <- as.factor(qpcr$col_days)
qpcr_all.na <- na.omit(qpcr)
workers <- read_csv("workers.csv")
workers$colony <- as.factor(workers$colony)
workers$treatment <- as.factor(workers$treatment)
workers$block <- as.factor(workers$block)
workers$qro <- as.factor(workers$qro)
workers$inoculate <- as.logical(workers$inoculate)
custom_labels <- c("Control", "Fungicide", "Fungicide + Crithidia", "Crithidia")
#Over whole experiment
library(survival)
library(coxme)
library(survminer)
workers.na <- na.omit(workers)
workers.na$inoculate_round <- as.factor(workers.na$inoculate_round)
cox <- coxme(Surv(days_alive_since_inoc, inoc_censor) ~ crithidia + fungicide + inoculate_round + inoculate + (1|colony), data = workers.na)
Anova(cox)
## Analysis of Deviance Table (Type II tests)
##
## Response: Surv(days_alive_since_inoc, inoc_censor)
## Df Chisq Pr(>Chisq)
## crithidia 1 4.5618 0.03269 *
## fungicide 1 0.5496 0.45846
## inoculate_round 2 6.5356 0.03809 *
## inoculate 1 3.7609 0.05246 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(cox)
## Mixed effects coxme model
## Formula: Surv(days_alive_since_inoc, inoc_censor) ~ crithidia + fungicide + inoculate_round + inoculate + (1 | colony)
## Data: workers.na
##
## events, n = 53, 175
##
## Random effects:
## group variable sd variance
## 1 colony Intercept 0.8515921 0.7252091
## Chisq df p AIC BIC
## Integrated loglik 38.30 6.0 9.829e-07 26.30 14.47
## Penalized loglik 75.32 18.4 7.517e-09 38.53 2.28
##
## Fixed effects:
## coef exp(coef) se(coef) z p
## crithidia 0.9370 2.5523 0.4387 2.14 0.0327
## fungicide 0.3177 1.3740 0.4285 0.74 0.4585
## inoculate_round2 0.3573 1.4295 0.4951 0.72 0.4705
## inoculate_round3 1.4966 4.4665 0.5855 2.56 0.0106
## inoculateTRUE 0.6020 1.8258 0.3104 1.94 0.0525
emmeans(cox, pairwise ~ crithidia)
## $emmeans
## crithidia emmean SE df asymp.LCL asymp.UCL
## 0 0.0493 0.282 Inf -0.503 0.602
## 1 0.9863 0.266 Inf 0.466 1.507
##
## Results are averaged over the levels of: fungicide, inoculate_round, inoculate
## Results are given on the log (not the response) scale.
## Confidence level used: 0.95
##
## $contrasts
## contrast estimate SE df z.ratio p.value
## crithidia0 - crithidia1 -0.937 0.439 Inf -2.136 0.0327
##
## Results are averaged over the levels of: fungicide, inoculate_round, inoculate
## Results are given on the log (not the response) scale.
emmeans(cox, pairwise ~ inoculate)
## $emmeans
## inoculate emmean SE df asymp.LCL asymp.UCL
## FALSE 0.217 0.152 Inf -0.081 0.514
## TRUE 0.819 0.281 Inf 0.268 1.369
##
## Results are averaged over the levels of: crithidia, fungicide, inoculate_round
## Results are given on the log (not the response) scale.
## Confidence level used: 0.95
##
## $contrasts
## contrast estimate SE df z.ratio p.value
## FALSE - TRUE -0.602 0.31 Inf -1.939 0.0525
##
## Results are averaged over the levels of: crithidia, fungicide, inoculate_round
## Results are given on the log (not the response) scale.
cox.emm <- emmeans(cox, pairwise ~ crithidia, type = "response")
cox.emm
## $emmeans
## crithidia response SE df asymp.LCL asymp.UCL
## 0 1.05 0.296 Inf 0.605 1.83
## 1 2.68 0.712 Inf 1.593 4.51
##
## Results are averaged over the levels of: fungicide, inoculate_round, inoculate
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## crithidia0 / crithidia1 0.392 0.172 Inf 1 -2.136 0.0327
##
## Results are averaged over the levels of: fungicide, inoculate_round, inoculate
## Tests are performed on the log scale
coxcld <- cld(object = cox.emm,
adjust = "Tukey",
alpha = 0.05,
Letters = letters)
coxcld
## crithidia response SE df asymp.LCL asymp.UCL .group
## 0 1.05 0.296 Inf 0.559 1.97 a
## 1 2.68 0.712 Inf 1.480 4.86 b
##
## Results are averaged over the levels of: fungicide, inoculate_round, inoculate
## Confidence level used: 0.95
## Conf-level adjustment: sidak method for 2 estimates
## Intervals are back-transformed from the log scale
## Tests are performed on the log scale
## significance level used: alpha = 0.05
## NOTE: If two or more means share the same grouping symbol,
## then we cannot show them to be different.
## But we also did not show them to be the same.
ggsurvplot(
survfit(Surv(days_alive_since_inoc, inoc_censor) ~ treatment, data = workers.na),
legend.title = "",
censor.shape = 124,
censor.size = 2.5,
ylim = c(0.25, 1),
palette = c("darkorchid4", "dodgerblue", "orange4", "orange"),
legend.labs = c("Control", "Fungicide", "Fungicide + Crithidia", "Crithidia"),
font.x = 16,
font.y = 16,
font.tickslab = 16,
font.legend = 18,
legend = "right"
)
qpcr_all.na$adl_neg <- 1 - qpcr_all.na$adl
qpcr_all.na$round <- as.factor(qpcr_all.na$round)
qpcr_all.na$replicate <- as.factor(qpcr_all.na$replicate)
cbw2 <- glm(cbind(adl, adl_neg) ~ fungicide + round + inoculate + replicate, data = qpcr_all.na, family = binomial("logit"))
drop1(cbw2, test = "Chisq")
## Single term deletions
##
## Model:
## cbind(adl, adl_neg) ~ fungicide + round + inoculate + replicate
## Df Deviance AIC LRT Pr(>Chi)
## <none> 1029.5 1055.5
## fungicide 1 1042.8 1066.8 13.301 0.0002653 ***
## round 2 1046.8 1068.8 17.384 0.0001679 ***
## inoculate 1 1133.2 1157.2 103.784 < 2.2e-16 ***
## replicate 8 1068.0 1078.0 38.535 5.994e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(cbw2)
## Analysis of Deviance Table (Type II tests)
##
## Response: cbind(adl, adl_neg)
## LR Chisq Df Pr(>Chisq)
## fungicide 13.301 1 0.0002653 ***
## round 17.384 2 0.0001679 ***
## inoculate 103.784 1 < 2.2e-16 ***
## replicate 38.535 8 5.994e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(cbw2)
##
## Call:
## glm(formula = cbind(adl, adl_neg) ~ fungicide + round + inoculate +
## replicate, family = binomial("logit"), data = qpcr_all.na)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.06950 0.26025 -7.952 1.84e-15 ***
## fungicideTRUE 0.65047 0.18019 3.610 0.000306 ***
## round2 -1.87110 0.54722 -3.419 0.000628 ***
## round3 1.24446 0.47694 2.609 0.009074 **
## inoculateTRUE 1.73829 0.17349 10.020 < 2e-16 ***
## replicate4 -0.60713 0.34515 -1.759 0.078571 .
## replicate6 0.06331 0.37906 0.167 0.867362
## replicate7 0.04926 0.56135 0.088 0.930068
## replicate8 2.49050 0.62858 3.962 7.43e-05 ***
## replicate9 -0.62715 0.35086 -1.787 0.073863 .
## replicate10 0.22503 0.31370 0.717 0.473164
## replicate11 1.29785 0.66151 1.962 0.049769 *
## replicate12 0.73299 0.38490 1.904 0.056861 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1202.4 on 1077 degrees of freedom
## Residual deviance: 1029.4 on 1065 degrees of freedom
## AIC: 1055.4
##
## Number of Fisher Scoring iterations: 4
emm1 <- emmeans(cbw2, pairwise ~ fungicide, type = "response")
pairs(emm1)
## contrast odds.ratio SE df null z.ratio p.value
## FALSE / TRUE 0.522 0.094 Inf 1 -3.610 0.0003
##
## Results are averaged over the levels of: round, inoculate, replicate
## Tests are performed on the log odds ratio scale
emm1
## $emmeans
## fungicide prob SE df asymp.LCL asymp.UCL
## FALSE 0.268 0.0279 Inf 0.217 0.326
## TRUE 0.412 0.0390 Inf 0.338 0.490
##
## Results are averaged over the levels of: round, inoculate, replicate
## Confidence level used: 0.95
## Intervals are back-transformed from the logit scale
##
## $contrasts
## contrast odds.ratio SE df null z.ratio p.value
## FALSE / TRUE 0.522 0.094 Inf 1 -3.610 0.0003
##
## Results are averaged over the levels of: round, inoculate, replicate
## Tests are performed on the log odds ratio scale
em.df <- as.data.frame(emm1$emmeans)
em.df
## fungicide prob SE df asymp.LCL asymp.UCL
## FALSE 0.2676679 0.02789421 Inf 0.2166336 0.3257258
## TRUE 0.4119249 0.03904250 Inf 0.3380709 0.4899703
##
## Results are averaged over the levels of: round, inoculate, replicate
## Confidence level used: 0.95
## Intervals are back-transformed from the logit scale
emm2 <- emmeans(cbw2, pairwise ~ inoculate, type = "response")
pairs(emm2)
## contrast odds.ratio SE df null z.ratio p.value
## FALSE / TRUE 0.176 0.0305 Inf 1 -10.020 <.0001
##
## Results are averaged over the levels of: fungicide, round, replicate
## Tests are performed on the log odds ratio scale
emm2
## $emmeans
## inoculate prob SE df asymp.LCL asymp.UCL
## FALSE 0.175 0.0187 Inf 0.141 0.215
## TRUE 0.547 0.0417 Inf 0.465 0.627
##
## Results are averaged over the levels of: fungicide, round, replicate
## Confidence level used: 0.95
## Intervals are back-transformed from the logit scale
##
## $contrasts
## contrast odds.ratio SE df null z.ratio p.value
## FALSE / TRUE 0.176 0.0305 Inf 1 -10.020 <.0001
##
## Results are averaged over the levels of: fungicide, round, replicate
## Tests are performed on the log odds ratio scale
ggplot(data = em.df, aes(x = fungicide, y = prob, fill = fungicide)) +
geom_col() +
geom_bar(stat = "identity", color = "black") +
geom_col_pattern(
aes(pattern = fungicide),
pattern_density = c(0, 0.4),
pattern_spacing = 0.03,
position = position_dodge(0.9)
) +
labs(x = NULL, y = "Probability of Testing Above Detection Limit") +
theme_cowplot() +
scale_x_discrete(labels = c("FALSE" = "Crithidia", "TRUE" = "Fungicide + Crithidia")) +
scale_fill_manual(values = c("FALSE" = "orange", "TRUE" = "orange4")) +
scale_pattern_manual(values = c("none", "stripe")) + # Customize bar colors
theme(legend.position = "none") + # Remove the legend
annotate(
geom = "text",
x = 0.8,
y = 0.45,
label = "P < 0.01",
size = 8
) +
geom_errorbar(aes(ymin = prob - SE, ymax = prob + SE), width = 0.2, size = 0.8, position = position_dodge(1)) +
theme(legend.position = "none",
axis.text = element_text(size = 20), # Set axis label font size
axis.title = element_text(size = 20)) + # Set axis title font size
theme(text = element_text(size = 16))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
# Input data
adl <- read.csv("adl.csv")
adl$colony <- as.factor(adl$colony)
adl$treatment <-as.factor(adl$treatment)
adl$round <- as.factor(adl$round)
adl$inoculate <- as.logical(adl$inoculate)
adl$block <- as.factor(adl$block)
adlmod <- glmer.nb(days_to_adl ~ treatment + round + inoculate + block + (1|colony), data = adl)
drop1(adlmod, test = "Chisq")
## Single term deletions
##
## Model:
## days_to_adl ~ treatment + round + inoculate + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 404.34
## treatment 1 403.34 0.9991 0.3175325
## round 2 415.07 14.7353 0.0006314 ***
## inoculate 1 410.09 7.7495 0.0053728 **
## block 9 406.33 19.9943 0.0179474 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(adlmod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: days_to_adl
## Chisq Df Pr(>Chisq)
## treatment 0.9977 1 0.317870
## round 12.4901 2 0.001940 **
## inoculate 7.3987 1 0.006527 **
## block 20.9704 9 0.012782 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
adlemm <- emmeans(adlmod, pairwise ~ treatment, type = "response")
pairs(adlemm)
## contrast ratio SE df null z.ratio p.value
## treatment3 / treatment4 0.866 0.124 Inf 1 -0.999 0.3179
##
## Results are averaged over the levels of: round, inoculate, block
## Tests are performed on the log scale
adlemm
## $emmeans
## treatment response SE df asymp.LCL asymp.UCL
## 3 2.12 0.397 Inf 1.47 3.06
## 4 2.45 0.397 Inf 1.78 3.36
##
## Results are averaged over the levels of: round, inoculate, block
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## treatment3 / treatment4 0.866 0.124 Inf 1 -0.999 0.3179
##
## Results are averaged over the levels of: round, inoculate, block
## Tests are performed on the log scale
adlemm <- emmeans(adlmod, pairwise ~ round, type = "response")
pairs(adlemm)
## contrast ratio SE df null z.ratio p.value
## round1 / round2 1.85 0.745 Inf 1 1.530 0.2767
## round1 / round3 6.76 4.232 Inf 1 3.051 0.0065
## round2 / round3 3.65 2.816 Inf 1 1.678 0.2134
##
## Results are averaged over the levels of: treatment, inoculate, block
## P value adjustment: tukey method for comparing a family of 3 estimates
## Tests are performed on the log scale
adlemm
## $emmeans
## round response SE df asymp.LCL asymp.UCL
## 1 5.288 0.936 Inf 3.738 7.48
## 2 2.857 0.846 Inf 1.598 5.10
## 3 0.783 0.457 Inf 0.249 2.46
##
## Results are averaged over the levels of: treatment, inoculate, block
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## round1 / round2 1.85 0.745 Inf 1 1.530 0.2767
## round1 / round3 6.76 4.232 Inf 1 3.051 0.0065
## round2 / round3 3.65 2.816 Inf 1 1.678 0.2134
##
## Results are averaged over the levels of: treatment, inoculate, block
## P value adjustment: tukey method for comparing a family of 3 estimates
## Tests are performed on the log scale
adlemm <- emmeans(adlmod, pairwise ~ inoculate, type = "response")
pairs(adlemm)
## contrast ratio SE df null z.ratio p.value
## FALSE / TRUE 1.62 0.289 Inf 1 2.720 0.0065
##
## Results are averaged over the levels of: treatment, round, block
## Tests are performed on the log scale
adlemm
## $emmeans
## inoculate response SE df asymp.LCL asymp.UCL
## FALSE 2.90 0.449 Inf 2.14 3.93
## TRUE 1.79 0.370 Inf 1.19 2.68
##
## Results are averaged over the levels of: treatment, round, block
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## FALSE / TRUE 1.62 0.289 Inf 1 2.720 0.0065
##
## Results are averaged over the levels of: treatment, round, block
## Tests are performed on the log scale
detadl <- glmer.nb(total.adl ~ treatment + inoculate + (1|colony), data = adl)
drop1(detadl, test = "Chisq")
## Single term deletions
##
## Model:
## total.adl ~ treatment + inoculate + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 437.45
## treatment 1 435.98 0.5224 0.4698
## inoculate 1 466.19 30.7356 2.957e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(detadl)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: total.adl
## Chisq Df Pr(>Chisq)
## treatment 0.5418 1 0.4617
## inoculate 27.9557 1 1.241e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
adl.t.emm <- emmeans(detadl, pairwise ~ inoculate, type = "response")
pairs(adl.t.emm)
## contrast ratio SE df null z.ratio p.value
## FALSE / TRUE 0.32 0.069 Inf 1 -5.287 <.0001
##
## Results are averaged over the levels of: treatment
## Tests are performed on the log scale
adl.t.emm
## $emmeans
## inoculate response SE df asymp.LCL asymp.UCL
## FALSE 2.01 0.308 Inf 1.49 2.72
## TRUE 6.29 1.299 Inf 4.20 9.43
##
## Results are averaged over the levels of: treatment
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## FALSE / TRUE 0.32 0.069 Inf 1 -5.287 <.0001
##
## Results are averaged over the levels of: treatment
## Tests are performed on the log scale
adl_sum <- adl %>%
group_by(treatment) %>%
summarise(wrkrs = length(bee_id))
adl_sum
## # A tibble: 2 × 2
## treatment wrkrs
## <fct> <int>
## 1 3 50
## 2 4 49
adl$bee_id <- as.factor(adl$bee_id)
qpcr_max_sum <- qpcr %>%
group_by(bee_id, treatment, inoculate, inoculate_round, colony) %>%
summarise(max = max(cells_assumed))
max_sum <- qpcr_max_sum %>%
group_by(inoculate) %>%
summarise(mean = mean(max),
sd= sd(max),
n = length(max)) %>%
mutate(se = sd/sqrt(n))
hist(adl$max_infc)
adl$logmax <- log((adl$max_infc)+1)
hist(adl$logmax)
shapiro.test(adl$logmax)
##
## Shapiro-Wilk normality test
##
## data: adl$logmax
## W = 0.90717, p-value = 3.447e-06
range(adl$logmax)
## [1] 0.000000 6.270988
maxmod <- lmer(logmax ~ treatment + inoculate + round + (1|colony), data = adl)
Anova(maxmod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: logmax
## Chisq Df Pr(>Chisq)
## treatment 0.2929 1 0.588367
## inoculate 9.8498 1 0.001698 **
## round 11.9265 2 0.002572 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
maxmod.emm <- emmeans(maxmod, pairwise ~ inoculate, type = "response")
library(NBZIMM)
max.zig = lme.zig(fixed = logmax ~ treatment + inoculate + round + offset(log(days_to_adl + 1)),
random = ~ 1 | colony, data = adl)
## Computational iterations: 4
## Computational time: 0.001 minutes
Anova(max.zig)
## Analysis of Deviance Table (Type II tests)
##
## Response: zz
## Chisq Df Pr(>Chisq)
## treatment 2.3994 1 0.12138
## inoculate 7.9420 1 0.00483 **
## round 19.3761 2 6.202e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
max_sum <- adl %>%
group_by(treatment) %>%
summarise(m = mean(max_infc),
n = length(max_infc),
sd = sd(max_infc)) %>%
mutate(se = sd/sqrt(n))
max_sum
## # A tibble: 2 × 5
## treatment m n sd se
## <fct> <dbl> <int> <dbl> <dbl>
## 1 3 99.7 50 124. 17.5
## 2 4 81.1 49 106. 15.1
# Input the data
qpcr <- read_csv("qpcr_time2.csv")
qpcr$bee_id <- as.factor(qpcr$bee_id)
qpcr$time_group <- as.factor(qpcr$time_group)
qpcr$inoculate_round <- as.factor(qpcr$inoculate_round)
qpcr$replicate <- as.factor(qpcr$replicate)
qpcr$fungicide <- as.factor(qpcr$fungicide)
# Look at shape
hist(qpcr$cells_assumed)
plot(qpcr$fungicide, qpcr$cells_assumed)
# Transform the data to normalize
qpcr$logcells <- log((qpcr$cells_assumed)+10)
shapiro.test(qpcr$logcells)
##
## Shapiro-Wilk normality test
##
## data: qpcr$logcells
## W = 0.54946, p-value < 2.2e-16
hist(qpcr$logcells)
range(qpcr$logcells)
## [1] 2.302585 5.918894
range(qpcr$cells_assumed)
## [1] 0 362
# Final selected model
f10 = glmer(logcells ~ time_group*fungicide + inoculate + inoculate_round + (1|bee_id), family = Gamma(link = "log"), data = qpcr)
Anova(f10)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: logcells
## Chisq Df Pr(>Chisq)
## time_group 4.1503 2 0.1255346
## fungicide 1.9378 1 0.1639072
## inoculate 13.5467 1 0.0002327 ***
## inoculate_round 31.4479 2 1.483e-07 ***
## time_group:fungicide 19.1116 2 7.079e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(f10)
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: Gamma ( log )
## Formula: logcells ~ time_group * fungicide + inoculate + inoculate_round +
## (1 | bee_id)
## Data: qpcr
##
## AIC BIC logLik deviance df.resid
## 1686.8 1741.6 -832.4 1664.8 1067
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.5267 -0.4995 -0.2416 0.0070 5.5692
##
## Random effects:
## Groups Name Variance Std.Dev.
## bee_id (Intercept) 0.00501 0.07078
## Residual 0.05020 0.22406
## Number of obs: 1078, groups: bee_id, 85
##
## Fixed effects:
## Estimate Std. Error t value Pr(>|z|)
## (Intercept) 0.93643 0.02634 35.548 < 2e-16 ***
## time_group2 -0.07806 0.02097 -3.722 0.000197 ***
## time_group3 -0.08184 0.02118 -3.864 0.000111 ***
## fungicideTRUE -0.03824 0.03226 -1.185 0.235854
## inoculateTRUE 0.12040 0.03271 3.681 0.000233 ***
## inoculate_round2 0.02122 0.03164 0.671 0.502515
## inoculate_round3 0.21184 0.03809 5.561 2.68e-08 ***
## time_group2:fungicideTRUE 0.12279 0.02981 4.120 3.79e-05 ***
## time_group3:fungicideTRUE 0.10416 0.03023 3.446 0.000570 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) tm_gr2 tm_gr3 fnTRUE inTRUE incl_2 incl_3 t_2:TR
## time_group2 -0.433
## time_group3 -0.421 0.535
## fungicdTRUE -0.606 0.345 0.336
## inocultTRUE -0.248 0.011 0.006 -0.006
## inoclt_rnd2 -0.322 -0.008 0.002 -0.070 -0.029
## inoclt_rnd3 -0.390 0.054 0.036 0.093 -0.010 0.247
## tm_gr2:TRUE 0.293 -0.702 -0.376 -0.482 -0.018 0.010 0.000
## tm_gr3:TRUE 0.280 -0.373 -0.699 -0.472 -0.009 0.010 0.015 0.537
f10.emm <- emmeans(f10, pairwise ~ fungicide*time_group, type = "response")
f10.emm
## $emmeans
## fungicide time_group response SE df asymp.LCL asymp.UCL
## FALSE 1 2.93 0.0737 Inf 2.79 3.08
## TRUE 1 2.82 0.0727 Inf 2.68 2.96
## FALSE 2 2.71 0.0678 Inf 2.58 2.84
## TRUE 2 2.95 0.0758 Inf 2.80 3.10
## FALSE 3 2.70 0.0680 Inf 2.57 2.83
## TRUE 3 2.88 0.0753 Inf 2.74 3.03
##
## Results are averaged over the levels of: inoculate, inoculate_round
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## FALSE time_group1 / TRUE time_group1 1.039 0.0335 Inf 1 1.185 0.8440
## FALSE time_group1 / FALSE time_group2 1.081 0.0227 Inf 1 3.722 0.0027
## FALSE time_group1 / TRUE time_group2 0.994 0.0319 Inf 1 -0.202 1.0000
## FALSE time_group1 / FALSE time_group3 1.085 0.0230 Inf 1 3.864 0.0016
## FALSE time_group1 / TRUE time_group3 1.016 0.0329 Inf 1 0.492 0.9965
## TRUE time_group1 / FALSE time_group2 1.041 0.0331 Inf 1 1.250 0.8119
## TRUE time_group1 / TRUE time_group2 0.956 0.0203 Inf 1 -2.107 0.2836
## TRUE time_group1 / FALSE time_group3 1.045 0.0335 Inf 1 1.358 0.7520
## TRUE time_group1 / TRUE time_group3 0.978 0.0211 Inf 1 -1.033 0.9071
## FALSE time_group2 / TRUE time_group2 0.919 0.0291 Inf 1 -2.670 0.0813
## FALSE time_group2 / FALSE time_group3 1.004 0.0204 Inf 1 0.186 1.0000
## FALSE time_group2 / TRUE time_group3 0.940 0.0300 Inf 1 -1.947 0.3734
## TRUE time_group2 / FALSE time_group3 1.092 0.0349 Inf 1 2.766 0.0630
## TRUE time_group2 / TRUE time_group3 1.023 0.0210 Inf 1 1.091 0.8851
## FALSE time_group3 / TRUE time_group3 0.936 0.0301 Inf 1 -2.049 0.3147
##
## Results are averaged over the levels of: inoculate, inoculate_round
## P value adjustment: tukey method for comparing a family of 6 estimates
## Tests are performed on the log scale
workcld10 <- cld(object = f10.emm,
adjust = "Tukey",
alpha = 0.05,
Letters = letters)
workcld10
## fungicide time_group response SE df asymp.LCL asymp.UCL .group
## FALSE 3 2.70 0.0680 Inf 2.52 2.88 a
## FALSE 2 2.71 0.0678 Inf 2.54 2.89 a
## TRUE 1 2.82 0.0727 Inf 2.63 3.02 ab
## TRUE 3 2.88 0.0753 Inf 2.69 3.09 ab
## FALSE 1 2.93 0.0737 Inf 2.74 3.13 b
## TRUE 2 2.95 0.0758 Inf 2.75 3.15 ab
##
## Results are averaged over the levels of: inoculate, inoculate_round
## Confidence level used: 0.95
## Conf-level adjustment: sidak method for 6 estimates
## Intervals are back-transformed from the log scale
## P value adjustment: tukey method for comparing a family of 6 estimates
## Tests are performed on the log scale
## significance level used: alpha = 0.05
## NOTE: If two or more means share the same grouping symbol,
## then we cannot show them to be different.
## But we also did not show them to be the same.
f10.in <- emmeans(f10, pairwise ~ inoculate, type = "response")
f10.in$contrasts
## contrast ratio SE df null z.ratio p.value
## FALSE / TRUE 0.887 0.029 Inf 1 -3.681 0.0002
##
## Results are averaged over the levels of: time_group, fungicide, inoculate_round
## Tests are performed on the log scale
f10.in
## $emmeans
## inoculate response SE df asymp.LCL asymp.UCL
## FALSE 2.66 0.0449 Inf 2.58 2.75
## TRUE 3.00 0.0897 Inf 2.83 3.19
##
## Results are averaged over the levels of: time_group, fungicide, inoculate_round
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
##
## $contrasts
## contrast ratio SE df null z.ratio p.value
## FALSE / TRUE 0.887 0.029 Inf 1 -3.681 0.0002
##
## Results are averaged over the levels of: time_group, fungicide, inoculate_round
## Tests are performed on the log scale
workcldin <- cld(object = f10.in,
adjust = "none",
alpha = 0.05,
Letters = letters)
workcldin
## inoculate response SE df asymp.LCL asymp.UCL .group
## FALSE 2.66 0.0449 Inf 2.58 2.75 a
## TRUE 3.00 0.0897 Inf 2.83 3.19 b
##
## Results are averaged over the levels of: time_group, fungicide, inoculate_round
## Confidence level used: 0.95
## Intervals are back-transformed from the log scale
## Tests are performed on the log scale
## significance level used: alpha = 0.05
## NOTE: If two or more means share the same grouping symbol,
## then we cannot show them to be different.
## But we also did not show them to be the same.
# Create various summaries based on different explanatory variables for later modeling
infec_sum1 <- qpcr %>%
group_by(fungicide, time_group, inoculate) %>%
summarise(m = mean(logcells),
n = length(logcells),
sd = sd(logcells)) %>%
mutate(se = sd/sqrt(n))
infec_sum1
## # A tibble: 12 × 7
## # Groups: fungicide, time_group [6]
## fungicide time_group inoculate m n sd se
## <fct> <fct> <lgl> <dbl> <int> <dbl> <dbl>
## 1 FALSE 1 FALSE 2.74 133 0.875 0.0759
## 2 FALSE 1 TRUE 3.01 36 0.932 0.155
## 3 FALSE 2 FALSE 2.43 156 0.480 0.0384
## 4 FALSE 2 TRUE 2.92 38 0.739 0.120
## 5 FALSE 3 FALSE 2.45 147 0.458 0.0378
## 6 FALSE 3 TRUE 2.95 38 0.717 0.116
## 7 TRUE 1 FALSE 2.58 128 0.707 0.0625
## 8 TRUE 1 TRUE 2.74 35 0.869 0.147
## 9 TRUE 2 FALSE 2.62 147 0.707 0.0583
## 10 TRUE 2 TRUE 2.95 43 0.749 0.114
## 11 TRUE 3 FALSE 2.58 139 0.602 0.0511
## 12 TRUE 3 TRUE 2.82 38 0.742 0.120
infec_sum2 <- qpcr %>%
group_by(fungicide, time_group) %>%
summarise(m = mean(cells_assumed),
n = length(cells_assumed),
sd = sd(cells_assumed)) %>%
mutate(se = sd/sqrt(n))
infec_sum2
## # A tibble: 6 × 6
## # Groups: fungicide [2]
## fungicide time_group m n sd se
## <fct> <fct> <dbl> <int> <dbl> <dbl>
## 1 FALSE 1 18.8 169 46.3 3.56
## 2 FALSE 2 6.84 194 25.9 1.86
## 3 FALSE 3 6.36 185 19.0 1.40
## 4 TRUE 1 13.0 163 46.0 3.60
## 5 TRUE 2 13.2 190 40.3 2.92
## 6 TRUE 3 8.79 177 22.3 1.68
infec_sum4 <- qpcr %>%
group_by(inoculate, time_group) %>%
summarise(m = mean(cells_assumed),
n = length(cells_assumed),
sd = sd(cells_assumed)) %>%
mutate(se = sd/sqrt(n))
infec_sum4
## # A tibble: 6 × 6
## # Groups: inoculate [2]
## inoculate time_group m n sd se
## <lgl> <fct> <dbl> <int> <dbl> <dbl>
## 1 FALSE 1 14.3 261 44.3 2.74
## 2 FALSE 2 8.14 303 34.1 1.96
## 3 FALSE 3 5.70 286 19.2 1.13
## 4 TRUE 1 22.0 71 52.4 6.22
## 5 TRUE 2 16.8 81 32.5 3.61
## 6 TRUE 3 14.5 76 24.6 2.82
infec_sum7 <- qpcr %>%
group_by(inoculate) %>%
summarise(m = mean(cells_assumed),
n = length(cells_assumed),
sd = sd(cells_assumed),
mean_maxinf = mean(max(cells_assumed))) %>%
mutate(se = sd/sqrt(n))
infec_sum7
## # A tibble: 2 × 6
## inoculate m n sd mean_maxinf se
## <lgl> <dbl> <int> <dbl> <dbl> <dbl>
## 1 FALSE 9.23 850 33.9 362 1.16
## 2 TRUE 17.6 228 37.8 277 2.50
infec_sum8 <- qpcr %>%
group_by(inoculate_round) %>%
summarise(m = mean(cells_assumed),
n = length(cells_assumed),
sd = sd(cells_assumed),
mean_maxinf = mean(max(cells_assumed))) %>%
mutate(se = sd/sqrt(n))
infec_sum8
## # A tibble: 3 × 6
## inoculate_round m n sd mean_maxinf se
## <fct> <dbl> <int> <dbl> <dbl> <dbl>
## 1 1 6.99 657 26.5 355 1.03
## 2 2 10.6 275 34.4 325 2.08
## 3 3 29.9 146 56.7 362 4.69
# Combine workcld with infec_sum based on matching columns
infec_sum_3 <- merge(infec_sum2, workcld10[, c("fungicide", "time_group", ".group")],
by = c("fungicide", "time_group"), all.x = TRUE)
# Create the plot with annotations
ggplot(infec_sum_3, aes(x = time_group, y = m, fill = fungicide)) +
geom_col_pattern(
aes(pattern = fungicide),
pattern_spacing = 0.03,
position = position_dodge(0.9)
) +
coord_cartesian(ylim = c(0,28)) +
geom_errorbar(aes(ymin = m - se, ymax = m + se),
position = position_dodge(width = 0.9), width = 0.25) +
geom_text(aes(label = .group, y = m + se + 1),
position = position_dodge(width = 0.9),
size = 5,
hjust = .5) +
scale_fill_manual(values = c("orange", "orange4"),
labels = c("FALSE" = "Crithidia", "TRUE" = "Fungicide + Crithidia")) +
scale_pattern_manual(values = c("none", "stripe"), guide = "none") +
scale_x_discrete(
labels = c("1" = "Days 0-4", "2" = "Days 5-9", "3" = "Days 0-14")
) +
labs(fill = NULL,
y = "Cells/µl",
x = "") +
theme_cowplot()+
theme(
plot.title = element_text(size = 20, face = "bold"), # Title size
axis.title = element_text(size = 20), # Axis titles
axis.text = element_text(size = 20), # Axis text
legend.title = element_text(size = 20), # Legend title
legend.text = element_text(size = 20) # Legend text
) +
theme(legend.position = "right") +
annotate(
geom = "text",
x = 0.8,
y = 27,
label = "P < 0.01",
size = 8
)
drones <- read_csv("drones.csv")
drones$treatment <- as.factor(drones$treatment)
drones$block <- as.factor(drones$block)
drones$colony <- as.factor(drones$colony)
drones$id <- as.factor(drones$id)
drones$abdomen_post_ee <- as.numeric(drones$abdomen_post_ee)
drones$fungicide <- as.factor(drones$fungicide)
drones$crithidia <- as.factor(drones$crithidia)
brood <- read_csv("brood.csv")
em.mod <- glmer.nb(emerge ~ fungicide + crithidia + dry_weight + workers_alive + block + (1|colony), data = drones)
## Warning in theta.ml(Y, mu, weights = object@resp$weights, limit = limit, :
## iteration limit reached
summary(em.mod)
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: Negative Binomial(10522146) ( log )
## Formula: emerge ~ fungicide + crithidia + dry_weight + workers_alive +
## block + (1 | colony)
## Data: drones
##
## AIC BIC logLik deviance df.resid
## 1605.0 1655.9 -788.5 1577.0 266
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.04868 -0.32632 -0.00849 0.30436 1.40892
##
## Random effects:
## Groups Name Variance Std.Dev.
## colony (Intercept) 3.61e-11 6.008e-06
## Number of obs: 280, groups: colony, 25
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.83792 0.05447 70.454 <2e-16 ***
## fungicideTRUE 0.02758 0.02108 1.308 0.1909
## crithidiaTRUE -0.01328 0.02131 -0.623 0.5334
## dry_weight -1.19236 0.08378 -14.233 <2e-16 ***
## workers_alive -0.02434 0.01159 -2.100 0.0357 *
## block4 -0.07057 0.04190 -1.684 0.0921 .
## block7 -0.05655 0.04495 -1.258 0.2084
## block8 -0.07821 0.04988 -1.568 0.1169
## block9 -0.05486 0.04595 -1.194 0.2325
## block10 -0.08649 0.03885 -2.226 0.0260 *
## block11 -0.05048 0.05844 -0.864 0.3877
## block12 -0.09125 0.04660 -1.958 0.0502 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) fnTRUE crTRUE dry_wg wrkrs_ block4 block7 block8 block9
## fungicdTRUE -0.325
## crithidTRUE -0.257 0.007
## dry_weight -0.037 -0.004 -0.010
## workers_alv -0.746 0.208 0.035 -0.009
## block4 -0.112 -0.140 0.022 -0.005 -0.466
## block7 -0.321 0.105 0.059 -0.020 -0.175 0.605
## block8 -0.138 -0.141 0.196 -0.016 -0.392 0.696 0.525
## block9 -0.268 0.009 0.065 -0.020 -0.240 0.651 0.539 0.567
## block10 -0.407 -0.049 0.056 -0.016 -0.133 0.700 0.595 0.610 0.618
## block11 -0.244 0.112 0.167 -0.006 -0.195 0.503 0.438 0.456 0.447
## block12 -0.393 0.082 0.264 -0.023 -0.139 0.603 0.537 0.560 0.549
## blck10 blck11
## fungicdTRUE
## crithidTRUE
## dry_weight
## workers_alv
## block4
## block7
## block8
## block9
## block10
## block11 0.479
## block12 0.609 0.466
## optimizer (Nelder_Mead) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
drop1(em.mod, test = "Chisq")
## Single term deletions
##
## Model:
## emerge ~ fungicide + crithidia + dry_weight + workers_alive +
## block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 1605.0
## fungicide 1 1604.5 1.4509 0.2284
## crithidia 1 1603.4 0.3331 0.5639
## dry_weight 1 1603.7 0.6426 0.4228
## workers_alive 1 1605.4 2.3678 0.1239
## block 7 1595.2 4.1697 0.7600
em1 <- update(em.mod, .~. -block)
drop1(em1, test = "Chisq")
## Single term deletions
##
## Model:
## emerge ~ fungicide + crithidia + dry_weight + workers_alive +
## (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 1595.2
## fungicide 1 1595.0 1.8500 0.17378
## crithidia 1 1593.2 0.0121 0.91234
## dry_weight 1 1595.1 1.9003 0.16805
## workers_alive 1 1596.5 3.2603 0.07097 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
em2 <- update(em1, .~. -dry_weight)
drop1(em2, test = "Chisq")
## Single term deletions
##
## Model:
## emerge ~ fungicide + crithidia + workers_alive + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 1595.1
## fungicide 1 1595.0 1.8874 0.16950
## crithidia 1 1593.2 0.0613 0.80442
## workers_alive 1 1597.0 3.9384 0.04719 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(em2)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: emerge
## Chisq Df Pr(>Chisq)
## fungicide 2.1257 1 0.144849
## crithidia 0.0616 1 0.803990
## workers_alive 7.0899 1 0.007752 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(em2)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: emerge
## Chisq Df Pr(>Chisq)
## fungicide 2.1257 1 0.144849
## crithidia 0.0616 1 0.803990
## workers_alive 7.0899 1 0.007752 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(em2)
## Generalized linear mixed model fit by maximum likelihood (Laplace
## Approximation) [glmerMod]
## Family: Negative Binomial(10522146) ( log )
## Formula: emerge ~ fungicide + crithidia + workers_alive + (1 | colony)
## Data: drones
##
## AIC BIC logLik deviance df.resid
## 1595.1 1616.9 -791.5 1583.1 274
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -0.88824 -0.34661 -0.06239 0.25739 1.88255
##
## Random effects:
## Groups Name Variance Std.Dev.
## colony (Intercept) 6.279e-11 7.924e-06
## Number of obs: 280, groups: colony, 25
##
## Fixed effects:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.717321 0.041846 88.833 < 2e-16 ***
## fungicideTRUE 0.027693 0.018994 1.458 0.14485
## crithidiaTRUE -0.004997 0.020134 -0.248 0.80399
## workers_alive -0.023682 0.008894 -2.663 0.00775 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) fnTRUE crTRUE
## fungicdTRUE -0.271
## crithidTRUE -0.219 -0.053
## workers_alv -0.938 0.100 0.048
## optimizer (Nelder_Mead) convergence code: 0 (OK)
## boundary (singular) fit: see help('isSingular')
em_sum <- drones %>%
group_by(treatment) %>%
summarise(m = mean(emerge),
sd = sd(emerge),
n = length(emerge)) %>%
mutate(se = sd/sqrt(n))
em_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 37.0 2.41 102 0.238
## 2 2 38.1 2.53 68 0.307
## 3 3 38.4 4.08 49 0.583
## 4 4 36.7 2.54 61 0.325
em_sum$plot <- em_sum$m + em_sum$se
hist(drones$relative_fat)
range(drones$relative_fat)
## [1] -0.000150305 0.003399280
shapiro.test(drones$relative_fat)
##
## Shapiro-Wilk normality test
##
## data: drones$relative_fat
## W = 0.97859, p-value = 0.0003281
drones$sqrt_rf <- (sqrt(drones$relative_fat))
## Warning in sqrt(drones$relative_fat): NaNs produced
drones$logrf <- log(drones$relative_fat)
## Warning in log(drones$relative_fat): NaNs produced
shapiro.test(drones$logrf)
##
## Shapiro-Wilk normality test
##
## data: drones$logrf
## W = 0.94405, p-value = 9.012e-09
shapiro.test(drones$sqrt_rf)
##
## Shapiro-Wilk normality test
##
## data: drones$sqrt_rf
## W = 0.99049, p-value = 0.06877
rf.mod <- lmer(sqrt_rf ~ fungicide + crithidia + workers_alive + block + (1|colony), data = drones)
drop1(rf.mod, test = "Chisq")
## Single term deletions
##
## Model:
## sqrt_rf ~ fungicide + crithidia + workers_alive + block + (1 |
## colony)
## npar AIC LRT Pr(Chi)
## <none> -2019.2
## fungicide 1 -2017.6 3.5558 0.0593382 .
## crithidia 1 -2017.8 3.3635 0.0666578 .
## workers_alive 1 -2021.2 0.0041 0.9486992
## block 7 -2007.6 25.5725 0.0006004 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rf2 <- update(rf.mod, .~. -workers_alive)
drop1(rf2, test = "Chisq")
## Single term deletions
##
## Model:
## sqrt_rf ~ fungicide + crithidia + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> -2021.2
## fungicide 1 -2019.2 4.0103 0.045222 *
## crithidia 1 -2019.6 3.5526 0.059451 .
## block 7 -2008.8 26.3561 0.000435 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(rf2)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: sqrt_rf
## Chisq Df Pr(>Chisq)
## fungicide 3.1661 1 0.0751799 .
## crithidia 2.7294 1 0.0985137 .
## block 26.4613 7 0.0004165 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rf_sum <- drones %>%
group_by(treatment) %>%
summarise(m = mean(relative_fat),
sd = sd(relative_fat),
n = length(relative_fat)) %>%
mutate(se = sd/sqrt(n))
rf_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 0.00112 0.000482 102 0.0000477
## 2 2 0.00111 0.000408 68 0.0000495
## 3 3 0.00129 0.000508 49 0.0000725
## 4 4 0.00127 0.000435 61 0.0000557
hist(drones$radial_um)
shapiro.test(drones$radial_um)
##
## Shapiro-Wilk normality test
##
## data: drones$radial_um
## W = 0.97721, p-value = 0.0001896
range(drones$radial_um)
## [1] 2073.526 3083.439
drones$cuberc <- (drones$radial_um)^3
shapiro.test(drones$cuberc)
##
## Shapiro-Wilk normality test
##
## data: drones$cuberc
## W = 0.99255, p-value = 0.1738
hist(drones$cuberc)
rc_mod <- lmer(cuberc ~ fungicide + crithidia + block + workers_alive + (1|colony), data = drones)
drop1(rc_mod, test = "Chisq")
## Single term deletions
##
## Model:
## cuberc ~ fungicide + crithidia + block + workers_alive + (1 |
## colony)
## npar AIC LRT Pr(Chi)
## <none> 13130
## fungicide 1 13136 7.6994 0.005524 **
## crithidia 1 13130 1.9668 0.160792
## block 7 13126 9.6578 0.208808
## workers_alive 1 13129 0.8686 0.351356
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rc2 <- update(rc_mod, .~. -workers_alive)
drop1(rc2, test = "Chisq")
## Single term deletions
##
## Model:
## cuberc ~ fungicide + crithidia + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 13129
## fungicide 1 13137 10.3573 0.00129 **
## crithidia 1 13128 1.4461 0.22916
## block 7 13126 11.0296 0.13733
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rc3 <- update(rc2, .~. -block)
Anova(rc3)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: cuberc
## Chisq Df Pr(>Chisq)
## fungicide 4.9350 1 0.02632 *
## crithidia 0.3472 1 0.55568
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rc_sum <- drones %>%
group_by(treatment) %>%
summarise(m = mean(radial_um),
sd = sd(radial_um),
n = length(radial_um)) %>%
mutate(se = sd/sqrt(n))
rc_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 2690. 188. 102 18.6
## 2 2 2664. 174. 68 21.1
## 3 3 2660. 173. 49 24.7
## 4 4 2749. 135. 61 17.3
rc_sum$plot <- rc_sum$m + rc_sum$se
rc_sum
## # A tibble: 4 × 6
## treatment m sd n se plot
## <fct> <dbl> <dbl> <int> <dbl> <dbl>
## 1 1 2690. 188. 102 18.6 2708.
## 2 2 2664. 174. 68 21.1 2685.
## 3 3 2660. 173. 49 24.7 2685.
## 4 4 2749. 135. 61 17.3 2766.
rc_plot <- ggplot(rc_sum, aes(x = treatment, y = m, fill = treatment)) +
geom_bar(stat = "identity", color = "black") +
geom_col_pattern(
aes(pattern = treatment),
pattern_density = c(0, 0, 0.4, 0), # Add density for the fourth column
pattern_spacing = 0.03,
position = position_dodge(0.9)
) +
scale_fill_viridis_d() +
geom_errorbar(aes(ymin = m - se, ymax = m + se), width = 0.2, position = position_dodge(0.9)) +
labs(x = "Treatment", y = "Radial cell length (um)") +
theme_classic(base_size = 20) +
coord_cartesian(ylim=c(2600, 2800)) +
annotate(geom = "text",
x = 1, y = 2745,
label = "P = 0.02",
size = 8) +
theme(legend.position = "none",
axis.text = element_text(size = 20), # Set axis label font size
axis.title = element_text(size = 20)) + # Set axis title font size
theme(text = element_text(size = 20)) +
scale_fill_manual(values = c("darkorchid4", "dodgerblue", "orange4", "orange")) +
scale_pattern_manual(values = c("none", "none", "stripe", "none")) + # Add stripes to the fourth column
scale_x_discrete(labels = custom_labels) +
theme(legend.position = "none") +
geom_segment(x = 2, xend = 3, y = 2710, yend = 2710,
lineend = "round", linejoin = "round") +
geom_segment(x = 2, xend = 2, y = 2700, yend = 2720,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 3, y = 2700, yend = 2720,
lineend = "round", linejoin = "round") +
geom_segment(x = 1, xend = 4, y = 2790, yend = 2790,
lineend = "round", linejoin = "round") +
geom_segment(x = 1, xend = 1, y = 2780, yend = 2800,
lineend = "round", linejoin = "round") +
geom_segment(x = 4, xend = 4, y = 2780, yend = 2800,
lineend = "round", linejoin = "round") +
geom_text(x = 2.5, y = 2712, label = "b", size = 6, vjust = -0.5) +
geom_text(x = 2.5, y = 2792, label = "a", size = 6, vjust = -0.5)
rc_plot
brood <- read_csv("brood.csv")
brood <- read_csv("brood.csv")
brood$colony <- as.factor(brood$colony)
brood$treatment <- as.factor(brood$treatment)
brood$block <- as.factor(brood$block)
brood$fungicide <- as.logical(brood$fungicide)
brood$crithidia <- as.logical(brood$crithidia)
male_count <- glm.nb(total_drones ~ fungicide + crithidia + block + workers_alive, data = brood)
## Warning in glm.nb(total_drones ~ fungicide + crithidia + block + workers_alive,
## : alternation limit reached
drop1(male_count, test = "Chisq")
## Single term deletions
##
## Model:
## total_drones ~ fungicide + crithidia + block + workers_alive
## Df Deviance AIC LRT Pr(>Chi)
## <none> 42.183 190.34
## fungicide 1 42.673 188.83 0.490 0.4840
## crithidia 1 42.767 188.93 0.584 0.4446
## block 8 94.592 226.75 52.408 1.404e-08 ***
## workers_alive 1 72.919 219.08 30.736 2.957e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(male_count)
## Analysis of Deviance Table (Type II tests)
##
## Response: total_drones
## LR Chisq Df Pr(>Chisq)
## fungicide 0.490 1 0.4840
## crithidia 0.584 1 0.4446
## block 52.408 8 1.404e-08 ***
## workers_alive 30.736 1 2.957e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(male_count)
##
## Call:
## glm.nb(formula = total_drones ~ fungicide + crithidia + block +
## workers_alive, data = brood, init.theta = 6.826554202, link = log)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -6.452e-01 6.069e-01 -1.063 0.287785
## fungicideTRUE -1.500e-01 2.099e-01 -0.714 0.475035
## crithidiaTRUE -1.671e-01 2.126e-01 -0.786 0.431855
## block4 9.474e-01 4.131e-01 2.294 0.021808 *
## block6 -3.766e+01 3.355e+07 0.000 0.999999
## block7 5.753e-01 4.511e-01 1.275 0.202200
## block8 2.564e-01 4.383e-01 0.585 0.558634
## block9 1.972e-01 4.331e-01 0.455 0.648894
## block10 1.442e+00 4.027e-01 3.581 0.000342 ***
## block11 -2.076e-01 5.231e-01 -0.397 0.691532
## block12 8.826e-01 4.625e-01 1.908 0.056345 .
## workers_alive 5.700e-01 1.086e-01 5.247 1.55e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for Negative Binomial(6.8266) family taken to be 1)
##
## Null deviance: 172.432 on 35 degrees of freedom
## Residual deviance: 42.183 on 24 degrees of freedom
## AIC: 192.34
##
## Number of Fisher Scoring iterations: 1
##
##
## Theta: 6.83
## Std. Err.: 3.60
## Warning while fitting theta: alternation limit reached
##
## 2 x log-likelihood: -166.341
m0 <- glmmTMB(total_drones ~ fungicide + crithidia + block + workers_alive, data = brood)
Anova(m0)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: total_drones
## Chisq Df Pr(>Chisq)
## fungicide 2.7355 1 0.09814 .
## crithidia 0.3672 1 0.54456
## block 58.4296 8 9.465e-10 ***
## workers_alive 18.9357 1 1.352e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
mc_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(total_drones),
n = length(total_drones),
sd = sd(total_drones)) %>%
mutate(se = sd/sqrt(n))
mc_sum
## # A tibble: 4 × 5
## treatment m n sd se
## <fct> <dbl> <int> <dbl> <dbl>
## 1 1 11.3 9 7.84 2.61
## 2 2 7.67 9 7.37 2.46
## 3 3 5.44 9 8.16 2.72
## 4 4 6.89 9 7.18 2.39
hist(drones$dry_weight)
shapiro.test(drones$dry_weight)
##
## Shapiro-Wilk normality test
##
## data: drones$dry_weight
## W = 0.99166, p-value = 0.1147
range(drones$dry_weight)
## [1] 0.0166 0.0541
drones$log.dry_weight <- log((drones$dry_weight))
shapiro.test(drones$log.dry_weight)
##
## Shapiro-Wilk normality test
##
## data: drones$log.dry_weight
## W = 0.95647, p-value = 2.014e-07
hist(drones$log.dry_weight)
mdw <- lmer(dry_weight ~ fungicide + crithidia + block + workers_alive + (1|colony), data = drones )
drop1(mdw, test = "Chisq")
## Single term deletions
##
## Model:
## dry_weight ~ fungicide + crithidia + block + workers_alive +
## (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> -1993.7
## fungicide 1 -1995.2 0.5266 0.468026
## crithidia 1 -1990.1 5.6389 0.017566 *
## block 7 -1987.5 20.2244 0.005105 **
## workers_alive 1 -1991.7 3.9608 0.046570 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(mdw)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: dry_weight
## Chisq Df Pr(>Chisq)
## fungicide 0.6628 1 0.41559
## crithidia 3.1104 1 0.07779 .
## block 17.0762 7 0.01691 *
## workers_alive 2.8255 1 0.09278 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qqnorm(resid(mdw));qqline(resid(mdw))
male_dw <- drones %>%
group_by(treatment) %>%
summarise(m = mean(dry_weight),
sd = sd(dry_weight),
n = length(dry_weight)) %>%
mutate(se = sd/sqrt(n))
male_dw
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 0.0373 0.00752 102 0.000745
## 2 2 0.0376 0.00658 68 0.000798
## 3 3 0.0378 0.00706 49 0.00101
## 4 4 0.0393 0.00668 61 0.000855
workers <- na.omit(workers)
workers <- read_csv("workers.csv")
workers$colony <- as.factor(workers$colony)
workers$treatment <- as.factor(workers$treatment)
workers$block <- as.factor(workers$block)
workers$qro <- as.factor(workers$qro)
workers$inoculate <- as.logical(workers$inoculate)
workers$dry <- as.double(workers$dry)
## Warning: NAs introduced by coercion
hist(workers$dry)
shapiro.test(workers$dry)
##
## Shapiro-Wilk normality test
##
## data: workers$dry
## W = 0.96135, p-value = 3.197e-05
workers$logdry <- log(workers$dry)
shapiro.test(workers$logdry)
##
## Shapiro-Wilk normality test
##
## data: workers$logdry
## W = 0.99094, p-value = 0.2537
hist(workers$logdry)
workers$fungicide <- as.logical(workers$fungicide)
workers$crithidia <- as.logical(workers$crithidia)
wrkdry1 <- lmer(logdry ~ fungicide*crithidia + inoculate +block + (1|colony), data = workers)
drop1(wrkdry1, test = "Chisq")
## Single term deletions
##
## Model:
## logdry ~ fungicide * crithidia + inoculate + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 93.353
## inoculate 1 91.391 0.0373 0.8468608
## block 9 104.116 28.7625 0.0007106 ***
## fungicide:crithidia 1 91.794 0.4412 0.5065339
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
wrkdry <- lmer(logdry ~ fungicide + crithidia + inoculate +block + (1|colony), data = workers)
drop1(wrkdry, test = "Chisq")
## Single term deletions
##
## Model:
## logdry ~ fungicide + crithidia + inoculate + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 91.794
## fungicide 1 95.101 5.3065 0.0212462 *
## crithidia 1 102.738 12.9433 0.0003211 ***
## inoculate 1 89.833 0.0381 0.8452327
## block 9 102.295 28.5009 0.0007863 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(wrkdry1, wrkdry, test = "Chisq")
## Data: workers
## Models:
## wrkdry: logdry ~ fungicide + crithidia + inoculate + block + (1 | colony)
## wrkdry1: logdry ~ fungicide * crithidia + inoculate + block + (1 | colony)
## npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
## wrkdry 15 91.794 141.04 -30.897 61.794
## wrkdry1 16 93.353 145.88 -30.677 61.353 0.4412 1 0.5065
Anova(wrkdry1)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: logdry
## Chisq Df Pr(>Chisq)
## fungicide 3.8656 1 0.0492852 *
## crithidia 10.4098 1 0.0012535 **
## inoculate 0.0413 1 0.8390495
## block 28.4252 9 0.0008097 ***
## fungicide:crithidia 0.2749 1 0.6000361
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(wrkdry)
## Linear mixed model fit by REML ['lmerMod']
## Formula: logdry ~ fungicide + crithidia + inoculate + block + (1 | colony)
## Data: workers
##
## REML criterion at convergence: 104.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.91492 -0.56289 -0.00892 0.66798 2.04904
##
## Random effects:
## Groups Name Variance Std.Dev.
## colony (Intercept) 0.02217 0.1489
## Residual 0.07178 0.2679
## Number of obs: 197, groups: colony, 40
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) -2.781148 0.105194 -26.438
## fungicideTRUE -0.122302 0.061443 -1.990
## crithidiaTRUE -0.200682 0.061443 -3.266
## inoculateTRUE -0.009667 0.047465 -0.204
## block4 0.087618 0.135147 0.648
## block5 -0.156602 0.136922 -1.144
## block6 -0.008842 0.135923 -0.065
## block7 -0.100143 0.135922 -0.737
## block8 0.121194 0.135147 0.897
## block9 -0.386717 0.135147 -2.861
## block10 -0.126487 0.135147 -0.936
## block11 -0.378121 0.135922 -2.782
## block12 -0.156229 0.135147 -1.156
wrkdry1 <- update(wrkdry, .~. -inoculate)
drop1(wrkdry1, test = "Chisq")
## Single term deletions
##
## Model:
## logdry ~ fungicide + crithidia + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 89.833
## fungicide 1 93.139 5.3061 0.0212508 *
## crithidia 1 100.782 12.9492 0.0003201 ***
## block 9 100.343 28.5101 0.0007835 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
wm2 <- update(wrkdry1, .~. -fungicide)
drop1(wm2, test = "Chisq")
## Single term deletions
##
## Model:
## logdry ~ crithidia + block + (1 | colony)
## npar AIC LRT Pr(Chi)
## <none> 93.139
## crithidia 1 102.998 11.859 0.0005738 ***
## block 9 100.838 25.700 0.0022873 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(wrkdry, wm2, test = "Chisq")
## Data: workers
## Models:
## wm2: logdry ~ crithidia + block + (1 | colony)
## wrkdry: logdry ~ fungicide + crithidia + inoculate + block + (1 | colony)
## npar AIC BIC logLik deviance Chisq Df Pr(>Chisq)
## wm2 13 93.139 135.82 -33.569 67.139
## wrkdry 15 91.794 141.04 -30.897 61.794 5.3442 2 0.06911 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(wrkdry1)
## Linear mixed model fit by REML ['lmerMod']
## Formula: logdry ~ fungicide + crithidia + block + (1 | colony)
## Data: workers
##
## REML criterion at convergence: 100.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.91419 -0.57743 -0.00892 0.67578 2.02348
##
## Random effects:
## Groups Name Variance Std.Dev.
## colony (Intercept) 0.02225 0.1492
## Residual 0.07134 0.2671
## Number of obs: 197, groups: colony, 40
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) -2.78308 0.10475 -26.568
## fungicideTRUE -0.12228 0.06144 -1.990
## crithidiaTRUE -0.20072 0.06144 -3.267
## block4 0.08762 0.13513 0.648
## block5 -0.15659 0.13691 -1.144
## block6 -0.00897 0.13590 -0.066
## block7 -0.10021 0.13590 -0.737
## block8 0.12119 0.13513 0.897
## block9 -0.38672 0.13513 -2.862
## block10 -0.12649 0.13513 -0.936
## block11 -0.37822 0.13590 -2.783
## block12 -0.15623 0.13513 -1.156
##
## Correlation of Fixed Effects:
## (Intr) fnTRUE crTRUE block4 block5 block6 block7 block8 block9
## fungicdTRUE -0.286
## crithidTRUE -0.286 -0.023
## block4 -0.645 0.000 0.000
## block5 -0.637 0.115 -0.115 0.494
## block6 -0.641 -0.005 0.005 0.497 0.490
## block7 -0.638 -0.005 -0.005 0.497 0.491 0.494
## block8 -0.645 0.000 0.000 0.500 0.494 0.497 0.497
## block9 -0.645 0.000 0.000 0.500 0.494 0.497 0.497 0.500
## block10 -0.645 0.000 0.000 0.500 0.494 0.497 0.497 0.500 0.500
## block11 -0.644 0.005 0.005 0.497 0.491 0.494 0.494 0.497 0.497
## block12 -0.645 0.000 0.000 0.500 0.494 0.497 0.497 0.500 0.500
## blck10 blck11
## fungicdTRUE
## crithidTRUE
## block4
## block5
## block6
## block7
## block8
## block9
## block10
## block11 0.497
## block12 0.500 0.497
Anova(wrkdry1)
## Analysis of Deviance Table (Type II Wald chisquare tests)
##
## Response: logdry
## Chisq Df Pr(>Chisq)
## fungicide 3.9617 1 0.0465471 *
## crithidia 10.6738 1 0.0010866 **
## block 29.1364 9 0.0006146 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
qqnorm(resid(wrkdry1));qqline(resid(wrkdry1))
pe <- emmeans(wrkdry1, pairwise ~ crithidia, type = "response")
pe
## $emmeans
## crithidia emmean SE df lower.CL upper.CL
## FALSE -2.95 0.0443 27.9 -3.05 -2.86
## TRUE -3.16 0.0421 28.1 -3.24 -3.07
##
## Results are averaged over the levels of: fungicide, block
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
##
## $contrasts
## contrast estimate SE df t.ratio p.value
## FALSE - TRUE 0.201 0.0614 28 3.267 0.0029
##
## Results are averaged over the levels of: fungicide, block
## Degrees-of-freedom method: kenward-roger
pairs(pe)
## contrast estimate SE df t.ratio p.value
## FALSE - TRUE 0.201 0.0614 28 3.267 0.0029
##
## Results are averaged over the levels of: fungicide, block
## Degrees-of-freedom method: kenward-roger
pef <- emmeans(wrkdry1, pairwise ~ fungicide, type = "response")
pef
## $emmeans
## fungicide emmean SE df lower.CL upper.CL
## FALSE -2.99 0.0421 28.1 -3.08 -2.91
## TRUE -3.12 0.0443 27.9 -3.21 -3.03
##
## Results are averaged over the levels of: crithidia, block
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
##
## $contrasts
## contrast estimate SE df t.ratio p.value
## FALSE - TRUE 0.122 0.0614 28 1.990 0.0564
##
## Results are averaged over the levels of: crithidia, block
## Degrees-of-freedom method: kenward-roger
wrkdry.df <- na.omit(workers)
wrkdrysum <- wrkdry.df %>%
group_by(treatment) %>%
summarise(m = mean(dry),
sd = sd(dry),
n = length(dry)) %>%
mutate(se = sd/sqrt(n))
wrkdrysum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 0.0586 0.0186 44 0.00280
## 2 2 0.0528 0.0169 45 0.00252
## 3 3 0.0418 0.0128 42 0.00198
## 4 4 0.0488 0.0184 43 0.00281
wtuk.means <- emmeans(object = wrkdry1,
specs = "crithidia",
adjust = "Tukey",
type = "response")
wtuk.means
## crithidia emmean SE df lower.CL upper.CL
## FALSE -2.95 0.0443 27.9 -3.06 -2.85
## TRUE -3.16 0.0421 28.1 -3.25 -3.06
##
## Results are averaged over the levels of: fungicide, block
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
## Conf-level adjustment: sidak method for 2 estimates
w.cld.model <- cld(object = wtuk.means,
adjust = "Tukey",
Letters = letters,
alpha = 0.05)
w.cld.model
## crithidia emmean SE df lower.CL upper.CL .group
## TRUE -3.16 0.0421 28.1 -3.25 -3.06 a
## FALSE -2.95 0.0443 27.9 -3.06 -2.85 b
##
## Results are averaged over the levels of: fungicide, block
## Degrees-of-freedom method: kenward-roger
## Confidence level used: 0.95
## Conf-level adjustment: sidak method for 2 estimates
## significance level used: alpha = 0.05
## NOTE: If two or more means share the same grouping symbol,
## then we cannot show them to be different.
## But we also did not show them to be the same.
blockdry <- emmeans(wrkdry1, pairwise ~ block, type = "response")
blockdrymeans <- as.data.frame(blockdry$emmeans)
work_dry <- ggplot(data = wrkdrysum, aes(x = treatment, y = m, fill = treatment)) +
geom_col(col = "black") +
coord_cartesian(ylim = c(0, 0.08)) +
labs(x = "Treatment", y = "Worker Dry Weight (g)") +
geom_col_pattern(
aes(pattern = treatment),
pattern_density = c(0, 0, 0.4, 0), # Add density for the fourth column
pattern_spacing = 0.03,
position = position_dodge(0.9)
) +
geom_errorbar(aes(ymin = m - se, ymax = m + se), width = 0.2, position = position_dodge(0.9)) +
theme_classic(base_size = 20) +
theme(legend.position = "none") +
annotate(
geom = "text",
x = 4,
y = 0.079,
label = "P < 0.01",
size = 7
) +
theme(legend.position = "none") +
scale_x_discrete(labels = custom_labels) +
scale_fill_manual(values = c("darkorchid4", "dodgerblue", "orange4", "orange")) +
scale_pattern_manual(values = c("none", "none", "stripe", "none")) +
geom_segment(x = 1, xend = 2, y = 0.07, yend = 0.07,
lineend = "round", linejoin = "round") +
geom_segment(x = 1, xend = 1, y = 0.07, yend = 0.069,
lineend = "round", linejoin = "round") +
geom_segment(x = 2, xend = 2, y = 0.07, yend = 0.069,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 4, y = 0.06, yend = 0.06,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 3, y = 0.06, yend = 0.059,
lineend = "round", linejoin = "round") +
geom_segment(x = 4, xend = 4, y = 0.06, yend = 0.059,
lineend = "round", linejoin = "round") +
geom_text(x = 1.5, y = 0.071, label = "a", size = 6, vjust = -0.5) +
geom_text(x = 3.5, y = 0.061, label = "b", size = 6, vjust = -0.5)
work_dry
bcm <- glm.nb(brood_cells ~ fungicide + crithidia + workers_alive + block, data = brood)
Anova(bcm)
## Analysis of Deviance Table (Type II tests)
##
## Response: brood_cells
## LR Chisq Df Pr(>Chisq)
## fungicide 3.070 1 0.07973 .
## crithidia 0.010 1 0.91928
## workers_alive 92.831 1 < 2e-16 ***
## block 102.709 8 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
b_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(brood_cells),
sd = sd(brood_cells),
n = length(brood_cells)) %>%
mutate(se = sd/sqrt(n))
b_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 30.7 23.1 9 7.71
## 2 2 29.8 21.1 9 7.04
## 3 3 21.7 24.9 9 8.30
## 4 4 23.9 26.3 9 8.77
hpm <- glm(honey_pots ~ fungicide + crithidia + workers_alive + block, data = brood, family = "poisson")
Anova(hpm)
## Analysis of Deviance Table (Type II tests)
##
## Response: honey_pots
## LR Chisq Df Pr(>Chisq)
## fungicide 3.5096 1 0.0610131 .
## crithidia 1.2041 1 0.2725029
## workers_alive 8.0172 1 0.0046336 **
## block 27.4941 8 0.0005806 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hp_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(honey_pots),
sd = sd(honey_pots),
n = length(honey_pots)) %>%
mutate(se = sd/sqrt(n))
hp_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 3.33 2.5 9 0.833
## 2 2 4.11 3.02 9 1.01
## 3 3 2.56 2.24 9 0.747
## 4 4 1.89 1.90 9 0.633
tlm <- glm.nb(total_larvae ~ fungicide + crithidia + workers_alive + block, data = brood)
Anova(tlm)
## Analysis of Deviance Table (Type II tests)
##
## Response: total_larvae
## LR Chisq Df Pr(>Chisq)
## fungicide 0.646 1 0.4217
## crithidia 0.037 1 0.8478
## workers_alive 39.129 1 3.967e-10 ***
## block 66.939 8 1.994e-11 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tl_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(total_larvae),
sd = sd(total_larvae),
n = length(total_larvae)) %>%
mutate(se = sd/sqrt(n))
tl_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 22.4 20.9 9 6.97
## 2 2 16.3 11.3 9 3.76
## 3 3 14.2 20.4 9 6.79
## 4 4 16 19.9 9 6.62
dlm <- glm.nb(dead_larvae ~ fungicide + crithidia + workers_alive, data = brood)
Anova(dlm)
## Analysis of Deviance Table (Type II tests)
##
## Response: dead_larvae
## LR Chisq Df Pr(>Chisq)
## fungicide 0.0725 1 0.78771
## crithidia 0.3865 1 0.53413
## workers_alive 4.4928 1 0.03404 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
dl_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(dead_larvae),
sd = sd(dead_larvae),
n = length(dead_larvae)) %>%
mutate(se = sd/sqrt(n))
dl_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 1.78 2.82 9 0.940
## 2 2 1.22 2.11 9 0.703
## 3 3 1.44 1.81 9 0.603
## 4 4 1.11 1.96 9 0.655
llm <- glm.nb(live_larvae ~ fungicide + crithidia + workers_alive + block, data = brood)
Anova(llm)
## Analysis of Deviance Table (Type II tests)
##
## Response: live_larvae
## LR Chisq Df Pr(>Chisq)
## fungicide 0.516 1 0.4723
## crithidia 0.002 1 0.9656
## workers_alive 44.398 1 2.680e-11 ***
## block 82.510 8 1.526e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
ll_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(live_larvae),
sd = sd(live_larvae),
n = length(live_larvae)) %>%
mutate(se = sd/sqrt(n))
ll_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 20.7 19.0 9 6.34
## 2 2 15.1 11.0 9 3.68
## 3 3 12.8 19.5 9 6.52
## 4 4 14.9 18.7 9 6.23
plmod <- glm(cbind(live_larvae, dead_larvae) ~ fungicide + crithidia + block + workers_alive, data = brood, family = binomial("logit"))
Anova(plmod)
## Analysis of Deviance Table (Type II tests)
##
## Response: cbind(live_larvae, dead_larvae)
## LR Chisq Df Pr(>Chisq)
## fungicide 0.0179 1 0.893715
## crithidia 0.0067 1 0.934615
## block 24.1726 8 0.002144 **
## workers_alive 6.1501 1 0.013140 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tpm <- glm(total_pupae ~ fungicide + crithidia + workers_alive + block, data = brood, family = "poisson")
Anova(tpm)
## Analysis of Deviance Table (Type II tests)
##
## Response: total_pupae
## LR Chisq Df Pr(>Chisq)
## fungicide 0.005 1 0.94611
## crithidia 4.885 1 0.02709 *
## workers_alive 51.869 1 5.932e-13 ***
## block 50.394 8 3.433e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
tp_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(total_pupae),
sd = sd(total_pupae),
n = length(total_pupae)) %>%
mutate(se = sd/sqrt(n))
tp_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 8.33 7.78 9 2.59
## 2 2 6 7.55 9 2.52
## 3 3 3.11 3.22 9 1.07
## 4 4 4.11 5.21 9 1.74
dpm <- glm.nb(dead_pupae ~ fungicide + crithidia + workers_alive + block, data = brood)
## Warning: glm.fit: fitted rates numerically 0 occurred
## Warning in theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace =
## control$trace > : iteration limit reached
## Warning in theta.ml(Y, mu, sum(w), w, limit = control$maxit, trace =
## control$trace > : iteration limit reached
Anova(dpm)
## Analysis of Deviance Table (Type II tests)
##
## Response: dead_pupae
## LR Chisq Df Pr(>Chisq)
## fungicide 1.9743 1 0.15999
## crithidia 0.1183 1 0.73086
## workers_alive 4.5035 1 0.03383 *
## block 16.8182 8 0.03206 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
dp_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(dead_pupae),
sd = sd(dead_pupae),
n = length(dead_pupae)) %>%
mutate(se = sd/sqrt(n))
dp_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 0.111 0.333 9 0.111
## 2 2 0.111 0.333 9 0.111
## 3 3 0.222 0.441 9 0.147
## 4 4 0.111 0.333 9 0.111
lpm <- glm(live_pupae ~ fungicide + crithidia + workers_alive + block, data = brood, family = "poisson")
Anova(lpm)
## Analysis of Deviance Table (Type II tests)
##
## Response: live_pupae
## LR Chisq Df Pr(>Chisq)
## fungicide 0.002 1 0.96330
## crithidia 5.386 1 0.02029 *
## workers_alive 58.627 1 1.905e-14 ***
## block 45.223 8 3.339e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
lp_sum <- brood %>%
group_by(treatment) %>%
summarise(m = mean(live_pupae),
sd = sd(live_pupae),
n = length(live_pupae)) %>%
mutate(se = sd/sqrt(n))
lp_sum
## # A tibble: 4 × 5
## treatment m sd n se
## <fct> <dbl> <dbl> <int> <dbl>
## 1 1 8.22 7.58 9 2.53
## 2 2 5.89 7.54 9 2.51
## 3 3 2.89 3.30 9 1.10
## 4 4 4 5.17 9 1.72
ppmod <- glm(cbind(live_pupae, dead_pupae) ~ fungicide + crithidia + workers_alive, data = brood, family = binomial("logit"))
Anova(ppmod)
## Analysis of Deviance Table (Type II tests)
##
## Response: cbind(live_pupae, dead_pupae)
## LR Chisq Df Pr(>Chisq)
## fungicide 0.0779 1 0.78011
## crithidia 0.0444 1 0.83313
## workers_alive 6.0550 1 0.01387 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
live_pup <- ggplot(data = lp_sum, aes(x = treatment, y = m, fill = treatment)) +
geom_col(col = "black") +
coord_cartesian(ylim = c(0, 13)) +
labs(x = "Treatment", y = "Live Pupae Count") +
geom_col_pattern(
aes(pattern = treatment),
pattern_density = c(0, 0, 0.4, 0), # Add density for the fourth column
pattern_spacing = 0.03,
position = position_dodge(0.9)
) +
geom_errorbar(aes(ymin = m - se, ymax = m + se), width = 0.2, position = position_dodge(0.9)) +
theme_classic(base_size = 20) +
theme(legend.position = "none") +
annotate(
geom = "text",
x = 4,
y = 12,
label = "P = 0.02",
size = 7
) +
theme(legend.position = "none") +
scale_x_discrete(labels = custom_labels) +
scale_fill_manual(values = c("darkorchid4", "dodgerblue", "orange4", "orange")) +
scale_pattern_manual(values = c("none", "none", "stripe", "none")) +
geom_segment(x = 1, xend = 2, y = 12, yend = 12,
lineend = "round", linejoin = "round") +
geom_segment(x = 1, xend = 1, y = 11.7, yend = 12.3,
lineend = "round", linejoin = "round") +
geom_segment(x = 2, xend = 2, y = 11.7, yend = 12.3,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 4, y = 7, yend = 7,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 3, y = 6.7, yend = 7.3,
lineend = "round", linejoin = "round") +
geom_segment(x = 4, xend = 4, y = 6.7, yend = 7.3,
lineend = "round", linejoin = "round") +
geom_text(x = 1.5, y = 12.1, label = "a", size = 6, vjust = -0.5) +
geom_text(x = 3.5, y = 7.1, label = "b", size = 6, vjust = -0.5)
live_pup
tp_plot <- ggplot(data = tp_sum, aes(x = treatment, y = m, fill = treatment)) +
geom_col(col = "black") +
coord_cartesian(ylim = c(0, 13)) +
scale_fill_viridis_d() +
labs(x = "Treatment", y = "Total Pupae Count") +
geom_col_pattern(
aes(pattern = treatment),
pattern_density = c(0, 0, 0.4, 0), # Add density for the fourth column
pattern_spacing = 0.03,
position = position_dodge(0.9)
) +
geom_errorbar(aes(ymin = m - se, ymax = m + se), width = 0.2, position = position_dodge(0.9)) +
theme_classic(base_size = 20) +
theme(legend.position = "none") +
annotate(
geom = "text",
x = 4,
y = 12,
label = "P = 0.03",
size = 7
) +
theme(legend.position = "none") +
scale_x_discrete(labels = custom_labels) +
scale_fill_manual(values = c("darkorchid4", "dodgerblue", "orange4", "orange")) +
scale_pattern_manual(values = c("none", "none", "stripe", "none")) +
geom_segment(x = 1, xend = 2, y = 12, yend = 12,
lineend = "round", linejoin = "round") +
geom_segment(x = 1, xend = 1, y = 11.7, yend = 12.3,
lineend = "round", linejoin = "round") +
geom_segment(x = 2, xend = 2, y = 11.7, yend = 12.3,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 4, y = 7, yend = 7,
lineend = "round", linejoin = "round") +
geom_segment(x = 3, xend = 3, y = 6.7, yend = 7.3,
lineend = "round", linejoin = "round") +
geom_segment(x = 4, xend = 4, y = 6.7, yend = 7.3,
lineend = "round", linejoin = "round") +
geom_text(x = 1.5, y = 12.1, label = "a", size = 6, vjust = -0.5) +
geom_text(x = 3.5, y = 7.1, label = "b", size = 6, vjust = -0.5)
tp_plot
plot_grid(tp_plot, live_pup, ncol=1, nrow =2)
egg.mod <- glm.nb(eggs ~ fungicide + crithidia + workers_alive + block, data = brood)
drop1(egg.mod, test = "Chisq")
## Single term deletions
##
## Model:
## eggs ~ fungicide + crithidia + workers_alive + block
## Df Deviance AIC LRT Pr(>Chi)
## <none> 46.045 281.46
## fungicide 1 46.605 280.02 0.5603 0.454128
## crithidia 1 46.053 279.46 0.0079 0.929219
## workers_alive 1 61.824 295.24 15.7787 7.12e-05 ***
## block 8 67.938 287.35 21.8931 0.005118 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Anova(egg.mod)
## Analysis of Deviance Table (Type II tests)
##
## Response: eggs
## LR Chisq Df Pr(>Chisq)
## fungicide 0.5603 1 0.454128
## crithidia 0.0079 1 0.929219
## workers_alive 15.7787 1 7.12e-05 ***
## block 21.8931 8 0.005118 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
block_sum <- brood %>%
group_by(block) %>%
summarise(
mbc = mean(brood_cells),
sdbc = sd(brood_cells),
nbc = length(brood_cells),
# Larvae
ml = mean(live_larvae),
sdl = sd(live_larvae),
nl = length(live_larvae),
mdl = mean(dead_larvae),
sddl = sd(dead_larvae),
ndl = length(dead_larvae),
mtl = mean(total_larvae),
sdtl = sd(total_larvae),
ntl = length(total_larvae),
# Pupae
mp = mean(live_pupae),
sdp = sd(live_pupae),
np = length(live_pupae),
mdp = mean(dead_pupae),
sddp = sd(dead_pupae),
ndp = length(dead_pupae),
mtp = mean(total_pupae),
sdtp = sd(total_pupae),
ntp = length(total_pupae),
# Eggs
me = mean(eggs),
sde = sd(eggs),
ne = length(eggs),
# Honey pots
mhp = mean(honey_pots),
sdhp = sd(honey_pots),
nhp = length(honey_pots),
# Drones
mtd = mean(total_drones),
sdtd = sd(total_drones),
ntd = length(total_drones)
)
#write.csv(block_sum, file = "C:/Users/runni/OneDrive - The Ohio State University/Runnion and Sivakoff/Synergism Experiment/Disease Dynamics Manuscript/Data and code/block_sum.csv", row.names = FALSE)
library(dplyr)
library(tidyr)
library(ggplot2)
block_sum <- brood %>%
group_by(block) %>%
summarise(
mbc = mean(brood_cells),
sdbc = sd(brood_cells),
nbc = length(brood_cells),
# Larvae
ml = mean(live_larvae),
sdl = sd(live_larvae),
nl = length(live_larvae),
mdl = mean(dead_larvae),
sddl = sd(dead_larvae),
ndl = length(dead_larvae),
mtl = mean(total_larvae),
sdtl = sd(total_larvae),
ntl = length(total_larvae),
# Pupae
mp = mean(live_pupae),
sdp = sd(live_pupae),
np = length(live_pupae),
mdp = mean(dead_pupae),
sddp = sd(dead_pupae),
ndp = length(dead_pupae),
mtp = mean(total_pupae),
sdtp = sd(total_pupae),
ntp = length(total_pupae),
# Eggs
me = mean(eggs),
sde = sd(eggs),
ne = length(eggs),
# Honey pots
mhp = mean(honey_pots),
sdhp = sd(honey_pots),
nhp = length(honey_pots),
# Drones
mtd = mean(total_drones),
sdtd = sd(total_drones),
ntd = length(total_drones)
)
block_sum_long <- block_sum %>%
pivot_longer(cols = starts_with("m"), # Select all mean columns
names_to = "variable",
values_to = "mean_value") %>%
mutate(variable = factor(variable,
levels = c("ml", "mdl", "mtl", "mp", "mdp", "mtp",
"me", "mhp", "mtd"),
labels = c("Live Larvae", "Dead Larvae", "Total Larvae",
"Live Pupae", "Dead Pupae", "Total Pupae",
"Eggs", "Honey Pots", "Total Drones")))
# Create the plot
ggplot(block_sum_long, aes(x = variable, y = mean_value, fill = block)) +
geom_col() +
theme_minimal() +
labs(title = "Mean Values of Brood Variables by Block",
x = "Variable",
y = "Mean Value") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_viridis_d(option = "A") # Optional color scheme for differentiation
adl_round_sum <- adl %>%
group_by(round) %>%
summarise(
mmax = mean(max_infc, na.rm = TRUE),
se_mmax = sd(max_infc, na.rm = TRUE) / sqrt(n()),
m_total_adl = mean(total.adl, na.rm = TRUE),
se_m_total_adl = sd(total.adl, na.rm = TRUE) / sqrt(n()),
m_first_adl = mean(days_to_adl, na.rm = TRUE),
se_m_first_adl = sd(days_to_adl, na.rm = TRUE) / sqrt(n()),
m_avg = mean(avg_infc, na.rm = TRUE),
se_m_avg = sd(avg_infc, na.rm = TRUE) / sqrt(n())
)
# Reshape data to include standard errors
adl_long <- adl_round_sum %>%
pivot_longer(
cols = starts_with("m"), # Select mean columns
names_to = "metric", # Create a column for metric names
values_to = "mean_value" # Create a column for mean values
) %>%
mutate(
se_value = case_when(
metric == "mmax" ~ se_mmax,
metric == "m_total_adl" ~ se_m_total_adl,
metric == "m_first_adl" ~ se_m_first_adl,
metric == "m_avg" ~ se_m_avg,
TRUE ~ NA_real_
)
)
# Filter for m_avg and mmax
adl_long_avg_max <- adl_long %>%
filter(metric %in% c("m_avg", "mmax"))
# Plot with error bars
plot1 <- ggplot(adl_long_avg_max, aes(x = round, y = mean_value, fill = metric)) +
geom_col(position = position_dodge(0.7), width = 0.7) +
geom_errorbar(
aes(ymin = mean_value - se_value, ymax = mean_value + se_value),
position = position_dodge(0.7), width = 0.2
) +
labs(
x = "Round",
y = "Cells/ul",
fill = NULL
) +
scale_fill_manual(
values = c("m_avg" = "purple", "mmax" = "skyblue"),
labels = c("m_avg" = "Average Infection Level", "mmax" = "Maximum Infection Level")
) +
theme_minimal() +
theme(
axis.title = element_text(size = 14),
axis.text = element_text(size = 12),
legend.text = element_text(size = 12),
legend.position = "top"
)
# Filter for m_total_adl and m_first_adl
adl_long_adl <- adl_long %>%
filter(metric %in% c("m_total_adl", "m_first_adl"))
# Plot with error bars
plot2 <- ggplot(adl_long_adl, aes(x = round, y = mean_value, fill = metric)) +
geom_col(position = position_dodge(0.7), width = 0.7) +
geom_errorbar(
aes(ymin = mean_value - se_value, ymax = mean_value + se_value),
position = position_dodge(0.7), width = 0.2
) +
labs(
x = "Round",
y = "Days",
fill = NULL
) +
scale_fill_manual(
values = c("m_total_adl" = "tomato", "m_first_adl" = "gold"),
labels = c(
"m_total_adl" = "Number of Days Infection was Detected",
"m_first_adl" = "Days Until First Infection Detected"
)
) +
theme_minimal() +
theme(
axis.title = element_text(size = 14),
axis.text = element_text(size = 12),
legend.text = element_text(size = 12),
legend.position = "top"
)
plot_grid(plot1, plot2, ncol=2, nrow =1)