12 PCB ~ Exploratory Batch 1
2016 - 2019 Analysis Years (excluding 2022 & 2023)
12.3 What influences PCBs?
Use Hurdle Model framework - first presence/absence of PCBs and then use sum of non-zero PCBs.
12.3.1 Data
# Subset pups with PCBs Present
dataP <-
data_tidy %>%
filter(sumpcb > 0) %>%
mutate(logpcb=log(sumpcb))12.3.1.1 Are the non-zero data normal?
- Raw data
- not normally distributed
- Log-transformed data
- not significantly different than a normal distribution!
# Raw data
hist <- ggplot(dataP, aes(x=sumpcb)) +
geom_histogram()
dens <- ggdensity(dataP$sumpcb)
qq <- ggqqplot(dataP$sumpcb)
grid.arrange(hist, dens, qq, ncol=3)
##
## Shapiro-Wilk normality test
##
## data: dataP$sumpcb
## W = 0.7037, p-value = 7.433e-07
# Log-transformed
hist <- ggplot(dataP, aes(x=logpcb)) +
geom_histogram()
dens <- ggdensity(dataP$logpcb)
qq <- ggqqplot(dataP$logpcb)
grid.arrange(hist, dens, qq, ncol=3)
##
## Shapiro-Wilk normality test
##
## data: dataP$logpcb
## W = 0.9387, p-value = 0.06229
12.3.1.2 Year - Presence/Absence
## Analysis of Deviance Table (Type II tests)
##
## Response: pcbbin
## LR Chisq Df Pr(>Chisq)
## year 2.6059 1 0.1065
# Make predictions from model
logit_preds <- data.frame(stats::predict(yearmodel, type="link", se.fit=TRUE))
logit_preds$lwr <- logit_preds$fit + 1.96 * logit_preds$se.fit
logit_preds$upr <- logit_preds$fit - 1.96 * logit_preds$se.fit
real_preds <- apply(logit_preds, 2, invlogit)
# Combine with original data & plot
datapreds <- data.frame(data_tidy, real_preds)
yearlogplot <-
ggplot(datapreds, aes(x = year, y = fit)) +
geom_ribbon(aes(ymin = lwr, ymax = upr), alpha = 0.25) +
geom_line() +
labs(x="Year", y="Probality of PCBs") +
theme_bw() +
theme(panel.grid = element_blank(),
text=element_text(size=13))
yearlogplot
yearpresplot <-
data_tidy %>%
mutate(pcbbin=ifelse(pcbbin=="1", "Present", "Absent"),
pcbbin=factor(pcbbin, levels=c("Present", "Absent"))) %>%
ggplot(data=.) +
geom_mosaic(aes(x=product(pcbbin, year), fill=pcbbin)) +
scale_fill_manual(values=c("Present"="gray60", "Absent"="lightgray"), name="PCB Status") +
scale_y_continuous(labels = scales::percent) +
labs(y="Proportion of Samples") +
theme_classic() +
theme(axis.title.x=element_blank(),
text=element_text(size=13),
axis.text.x=element_text(angle=45, hjust=1))
yearpresplot