Skip to contents

Estimate rates of change based on seasonal metrics

Usage

anlz_trndseason(
  mod,
  metfun = mean,
  doystr = 1,
  doyend = 364,
  justify = c("center", "left", "right"),
  win = 5,
  nsim = 10000,
  yromit = NULL,
  useave = FALSE,
  ...
)

Arguments

mod

input model object as returned by anlz_gam

metfun

function input for metric to calculate, e.g., mean, var, max, etc

doystr

numeric indicating start Julian day for extracting averages

doyend

numeric indicating ending Julian day for extracting averages

justify

chr string indicating the justification for the trend window

win

numeric indicating number of years to use for the trend window, see details

nsim

numeric indicating number of random draws for simulating uncertainty

yromit

optional numeric vector for years to omit from the output

useave

logical indicating if anlz_avgseason is used for the seasonal metric calculation

...

additional arguments passed to metfun, e.g., na.rm = TRUE)

Value

A data frame of slope estimates and p-values for each year

Details

Trends are based on the slope of the fitted linear trend within the window, where the linear trend is estimated using a meta-analysis regression model (from anlz_mixmeta) for the seasonal metrics (from anlz_metseason).

Note that for left and right windows, the exact number of years in win is used. For example, a left-centered window for 1990 of ten years will include exactly ten years from 1990, 1991, ... , 1999. The same applies to a right-centered window, e.g., for 1990 it would include 1981, 1982, ..., 1990 (if those years have data). However, for a centered window, picking an even number of years for the window width will create a slightly off-centered window because it is impossible to center on an even number of years. For example, if win = 8 and justify = 'center', the estimate for 2000 will be centered on 1997 to 2004 (three years left, four years right, eight years total). Centering for window widths with an odd number of years will always create a symmetrical window, i.e., if win = 7 and justify = 'center', the estimate for 2000 will be centered on 1997 and 2003 (three years left, three years right, seven years total).

The optional yromit vector can be used to omit years from the trend assessment. This may be preferred if seasonal estimates for a given year have very wide confidence intervals likely due to limited data, which can skew the trend assessments.

See also

Other analyze: anlz_sumtrndseason(), anlz_trans()

Examples

library(dplyr)

# data to model
tomod <- rawdat %>%
  filter(station %in% 34) %>%
  filter(param %in% 'chl') %>% 
  filter(yr > 2015)

mod <- anlz_gam(tomod, trans = 'log10')
anlz_trndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 4)
#> # A tibble: 4 × 12
#>      yr   met     se bt_lwr bt_upr bt_met dispersion   yrcoef    pval
#>   <dbl> <dbl>  <dbl>  <dbl>  <dbl>  <dbl>      <dbl>    <dbl>   <dbl>
#> 1  2016 0.766 0.0833   4.58   9.71   6.67     0.0504 NaN      NaN    
#> 2  2017 0.772 0.0788   4.74   9.66   6.77     0.0504   0.0373   0.562
#> 3  2018 1.03  0.0728   8.77  16.9   12.2      0.0504 NaN      NaN    
#> 4  2019 0.808 0.0722   5.30  10.2    7.34     0.0504 NaN      NaN    
#> # ℹ 3 more variables: appr_yrcoef <dbl>, yrcoef_lwr <dbl>, yrcoef_upr <dbl>