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 regression for left-censored log-normal data using analysis result as dependent variable and year of analysis as independent variable, and implemented using the NADA package for r R.version.string. The graphs show the analysis results, with the left-censored observations highlighted in red. If applicable, the fitted trend line is also plotted. The annual change is calculated as the exponent of the regression coefficient for "year", and corresponds to the fitted response 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
  }

  df <-
    with(out$out_list[[i]]$x,
         data.frame(result = result,
                    cen = cen,
                    year = year))

  yri <- out$out_list[[i]]$years
  ni <- with(df, tapply(result, year, length))
  ni2 <- ni[as.character(yri)]
  ni2[is.na(ni2)] <- 0
  xlabs <- paste(yri, "\n", ni2)

  p <-
    ggplot(df, aes(x = year, y = result)) +
      geom_jitter(aes(color = cen),
                  size = 1,
                  width = 0.2,
                  height = 0) +
      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,
                         breaks = out$out_list[[i]]$years,
                         labels = xlabs,
                         expand = c(0, 0.4)) +
      scale_y_continuous(NULL,
                         limits = c(0, 1.1 * max(df$result, na.rm = TRUE))) +
      scale_color_manual(values = c("grey50", "#F8766D"),
                         limits = c(FALSE, TRUE),
                         guide = FALSE) +
      coord_cartesian(xlim = range(out$out_list[[i]]$years)) +
      ggtitle(out$out_tab$Matrix[i])

  Pval <- out$out_list[[i]]$P
  if (!is.na(Pval)) {
    COEF <- out$out_list[[i]]$COEF
    years <- out$out_list[[i]]$years
    yseq <- seq(min(years), max(years), 0.1)
    df2 <- data.frame(x = yseq, y = exp(COEF[1] + yseq * COEF[2]))
    p <-
      p +
      geom_line(data = df2, aes(x = x, y = y), color = "red") +
      labs(subtitle =
             paste0("annual change: ", round(exp(COEF[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.