out <- params$out

Report generated on r Sys.Date()

Input file: r params$inFile

Matrix level analysed: r ifelse(params$level == 6, "Description", params$level)

Years analysed: r paste(params$yearrange, collapse = ":")

The trend analyses in this report are based on a logistic regression using non-conformity as dependent variable and year of analysis as independent variable, and implemented using r R.version.string. The annual change is calculated as the exponent of the regression coefficient for "year", and corresponds to the fitted odds ratio between two consecutive years.

IMPORTANT: The results have to be interpreted carefully accounting for expert knowledge on sampling design and diagnostic methods. The conclusions are based on assumptions linked to the selected models, such as linearity and heteroscedasticity.

Summary table

summary_tab <- out$out_tab
colnames(summary_tab) <- paste0("**", colnames(summary_tab), "**")
knitr::kable(summary_tab)

Detailed trend analyses

all_par <- unique(out$out_tab$Parameter)
old_par <- 0

for (i in seq_along(out$out_list)) {
  this_par <- which(all_par == out$out_tab$Parameter[i])
  if (this_par != old_par) {
    cat("  \n\n### ", this_par, ". ", out$out_tab$Parameter[i], "   \n\n", sep = "")
    old_par <- old_par + 1
  }

  mxi <- out$out_list[[i]]$mx
  yri <- out$out_list[[i]]$years
  xlabs <- paste(yri, "\n", mxi[, 1], "/", rowSums(mxi))
  xlabs[grepl("NA", xlabs)] <- gsub(" \n.*", "", xlabs[grepl("NA", xlabs)])

  df <-
    data.frame(year = yri,
               result = apply(mxi, 1, prop.table)[1,])
  p <-
    ggplot(df, aes(x = year, y = result)) +
      geom_point() +
      theme_bw() +
      theme(axis.text = element_text(size = 6),
            axis.title = element_text(size = 6),
            plot.title = element_text(size = 8),
            plot.subtitle = element_text(size = 7)) +
      scale_x_continuous(NULL,
                         limits = range(yri),
                         breaks = yri,
                         labels = xlabs) +
      scale_y_continuous(NULL, limits = c(0, 1)) +
      ggtitle(gsub(" - ", "\n", out$out_tab$Matrix[i]))

  Pval <- out$out_list[[i]]$p
  if (!is.na(Pval)) {
    fit <- out$out_list[[i]]$fit
    yseq <- seq(min(yri), max(yri), 0.1)
    df2 <- data.frame(x = yseq,
                      y = expit(predict(fit, newdata = data.frame(years = yseq))))
    p <-
      p +
        geom_line(data = df2, aes(x = x, y = y), color = "red") +
        labs(subtitle =
               paste0("annual change: ", round(exp(coef(fit)[2]), 3),
                      ifelse(Pval < 0.001,
                             " (P < 0.001)",
                             sprintf(" (P = %s)", round(Pval, 3)))))

  } else {
    p <- p + labs(subtitle = "no trend analysis possible")
  }

  print(p)
}


brechtdv/trends documentation built on March 11, 2020, 11:16 a.m.