logger$info("Entering trend analysis section")



Trend analysis

For each location code and the type names and group codes specified in the settings file, the following statistics have been estimated for the period r str_c(DATE_FROM, " to ", DATE_TO):

A p-value less than an a priori specified significance level (e.g., often α = 0.05), indicates a significant trend. If the p-value is greater than this significance level, we can't say that there is no trend. We can only conclude that our data do not show evidence for a significant trend (due to lack of data, noise, etc.).

The Mann-Kendall test is a non-parametric test and as such does not make distributional assumptions on the data.


# check location_codes
missing_location_codes <- LOCATION_CODE %>%
  setdiff(unique(d_stats$location_code))
if (length(missing_location_codes) > 0) {
    logger$warn("The following specified location code(s) are not found and will be skipped: ",
        missing_location_codes %>% sQuote %>% enumerate)
}
LOCATION_CODE <- d_stats %>%
    chuck("location_code") %>% 
    unique %>%
    intersect(LOCATION_CODE)

# check type names
missing_type_names <- TYPE_NAME %>%
  setdiff(unique(d_stats$type_name))
if (length(missing_type_names) > 0) {
    logger$warn("The following specified type name(s) are not found and will be skipped: ",
        missing_type_names %>% sQuote %>% enumerate)
}
TYPE_NAME <- d_stats %>%
    chuck("type_name") %>% 
    unique %>%
    intersect(TYPE_NAME)

# check group codes
missing_group_codes <- GROUP_CODE %>%
  setdiff(unique(d_stats$type_name))
if (length(missing_group_codes) > 0) {
    logger$warn("The following specified group code(s) are not found and will be skipped: ",
          missing_group_codes %>% sQuote %>% enumerate)
}
GROUP_CODE <- d_stats %>%
    chuck("type_name") %>% 
    unique %>%
    intersect(GROUP_CODE)


logger$info("Creating table with trend statistics")
d_stats %>%
    filter(type_name %in% unique(c("TC", TYPE_NAME, GROUP_CODE))) %>%
    mutate(
        p_value = formatC(p_value, format = "f", digits = 4),
        slope = b1 * 365.25) %>%
    select(location_code, type_name, from, to, N = n, slope, `p-value` = p_value) %>%
    arrange(location_code, desc(abs(slope))) %>%
    rename(`type name / group code` = type_name) %>%
    mutate_if(
        is_double,
        formatC, format = "fg", digits = 4) %>%
    kable(align = "llllrrr")
logger$info("Table with trend statistics created")


Descriptive statisics and trend analysis results have been stored in file r sQuote(basename(FILE_STATS)).

  logger$info("No valid location_code(s) found. Therefore, time-series plot are skipped.")



Try the litteR package in your browser

Any scripts or data that you put into this service are public.

litteR documentation built on Aug. 27, 2022, 1:05 a.m.