# monthly attainment whole bay segment, june through sep onlymoattain <- otbdat |>summarise(chla =mean(chla, na.rm = T), .by =c('yr', 'mo') ) |>mutate(attain = chla <9.3 ) |>select(-chla)tomod <- otbdat |>filter(mo %in%c(6:9)) |>summarise(chla =mean(chla, na.rm = T), .by =c(yr, mo, subsegment) ) |>filter(subsegment =='NW') |>left_join(moattain, by =c('yr', 'mo')) mod <-glm(attain ~ chla, data = tomod, family = binomial)prddat <-tibble(chla =seq(0, quantile(tomod$chla, 0.9), length.out =200) )prd <-tibble(ave =predict(mod, newdata = prddat, type ='response'),lov = ave -predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96,hiv = ave +predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96 ) |>bind_cols(prddat)# find chlorphyll value that is closes to lov 0.5lns <- prd |>mutate(diff =abs(0.5- ave) ) |>arrange(diff) |>head(1)lnslab <-paste0(round(lns$chla, 1), ' ug/L')ggplot(prd, aes(x = chla, y = ave)) +geom_ribbon(aes(ymin = lov, ymax = hiv), alpha =0.5) +geom_line() +scale_y_continuous(labels = scales::percent) +geom_segment(x = lns$chla, xend = lns$chla, y =0, yend =0.5, linetype ='dashed') +geom_segment(x =0, xend = lns$chla, y =0.5, yend =0.5, linetype ='dashed') +geom_text(x = lns$chla, y =0, label = lnslab, vjust =1) +labs(x ='Chla (ug/L)', y ='Probability', title ='Probability of attaining baywide monthly 9.3 ug/L Chla based on NW subsegment concentrations',subtitle ='June through September' ) +theme_minimal() +theme(panel.grid.minor =element_blank() )
Code
# probability of attaining monthly 50% chl value vs loadtomod2 <- tomod |>mutate(attain = chla < lns$chla ) |>left_join(lddat, by =c('yr', 'mo')) |>mutate(mo =factor(mo),prdvar = lagsum2 )mod <-glm(attain ~ prdvar, data = tomod2, family = binomial)prddat <-tibble(prdvar =seq(0, quantile(tomod2$prdvar, 1), length.out =200) ) prd <-tibble(ave =predict(mod, newdata = prddat, type ='response'),lov = ave -predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96,hiv = ave +predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96 ) |>bind_cols(prddat)ggplot(prd, aes(x = prdvar, y = ave)) +geom_ribbon(aes(ymin = lov, ymax = hiv), alpha =0.5) +geom_line() +scale_y_continuous(labels = scales::percent) +coord_cartesian(ylim =c(0, 1)) +labs(x ='Cumulative two month load (tons / 2 month)', y ='Probability',title =paste('Probability of attaining monthly', lnslab, 'in NW subsegment'),subtitle ='June through September' ) +theme_minimal() +theme(panel.grid.minor =element_blank() )
Code
mod1 <-glm(attain ~ load, data = tomod2, family = binomial)mod2 <-glm(attain ~ lagsum2, data = tomod2, family = binomial)mod3 <-glm(attain ~ lagsum3, data = tomod2, family = binomial)tab_model(mod1, mod2, mod3)
attain
attain
attain
Predictors
Odds Ratios
CI
p
Odds Ratios
CI
p
Odds Ratios
CI
p
(Intercept)
0.31
0.10 – 0.94
0.035
1.01
0.35 – 3.08
0.982
1.15
0.36 – 3.94
0.822
load
1.00
0.99 – 1.01
0.613
lagsum2
0.99
0.97 – 1.00
0.012
lagsum3
0.99
0.98 – 1.00
0.013
Observations
88
88
88
R2 Tjur
0.003
0.111
0.107
Code
# monthly attainment whole bay segment, june through sep onlymoattain <- otbdat |>summarise(chla =mean(chla, na.rm = T), .by =c('yr', 'mo') ) |>mutate(attain = chla <9.3 ) |>select(-chla)tomod <- otbdat |>filter(mo %in%c(6:9)) |>summarise(chla =mean(chla, na.rm = T), .by =c(yr, mo, subsegment) ) |>filter(subsegment =='CW') |>left_join(moattain, by =c('yr', 'mo')) mod <-glm(attain ~ chla, data = tomod, family = binomial)prddat <-tibble(chla =seq(0, quantile(tomod$chla, 0.9), length.out =200) )prd <-tibble(ave =predict(mod, newdata = prddat, type ='response'),lov = ave -predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96,hiv = ave +predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96 ) |>bind_cols(prddat)# find chlorphyll value that is closes to lov 0.5lns <- prd |>mutate(diff =abs(0.5- ave) ) |>arrange(diff) |>head(1)lnslab <-paste0(round(lns$chla, 1), ' ug/L')ggplot(prd, aes(x = chla, y = ave)) +geom_ribbon(aes(ymin = lov, ymax = hiv), alpha =0.5) +geom_line() +scale_y_continuous(labels = scales::percent) +geom_segment(x = lns$chla, xend = lns$chla, y =0, yend =0.5, linetype ='dashed') +geom_segment(x =0, xend = lns$chla, y =0.5, yend =0.5, linetype ='dashed') +geom_text(x = lns$chla, y =0, label = lnslab, vjust =1) +labs(x ='Chla (ug/L)', y ='Probability', title ='Probability of attaining baywide monthly 9.3 ug/L Chla based on NW subsegment concentrations',subtitle ='June through September' ) +theme_minimal() +theme(panel.grid.minor =element_blank() )
Code
# probability of attaining monthly 50% chl value vs loadtomod2 <- tomod |>mutate(attain = chla < lns$chla ) |>left_join(lddat, by =c('yr', 'mo')) |>mutate(mo =factor(mo),prdvar = lagsum2 )mod <-glm(attain ~ prdvar, data = tomod2, family = binomial)prddat <-tibble(prdvar =seq(0, quantile(tomod2$prdvar, 1), length.out =200) ) prd <-tibble(ave =predict(mod, newdata = prddat, type ='response'),lov = ave -predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96,hiv = ave +predict(mod, newdata = prddat, type ='response', se.fit = T)$se.fit *1.96 ) |>bind_cols(prddat)ggplot(prd, aes(x = prdvar, y = ave)) +geom_ribbon(aes(ymin = lov, ymax = hiv), alpha =0.5) +geom_line() +scale_y_continuous(labels = scales::percent) +coord_cartesian(ylim =c(0, 1)) +labs(x ='Cumulative two month load (tons / 2 month)', y ='Probability',title =paste('Probability of attaining monthly', lnslab, 'in NW subsegment'),subtitle ='June through September' ) +theme_minimal() +theme(panel.grid.minor =element_blank() )
Code
mod1 <-glm(attain ~ load, data = tomod2, family = binomial)mod2 <-glm(attain ~ lagsum2, data = tomod2, family = binomial)mod3 <-glm(attain ~ lagsum3, data = tomod2, family = binomial)tab_model(mod1, mod2, mod3)