Title: | Assess Water Quality Trends with Generalized Additive Models |
---|---|
Description: | Assess Water Quality Trends for Long-Term Monitoring Data in Estuaries using Generalized Additive Models following Wood (2017) <doi:10.1201/9781315370279> and Error Propagation with Mixed-Effects Meta-Analysis following Sera et al. (2019) <doi:10.1002/sim.8362>. Methods are available for model fitting, assessment of fit, annual and seasonal trend tests, and visualization of results. |
Authors: | Marcus Beck [aut, cre] , Perry de Valpine [aut], Rebecca Murphy [aut], Ian Wren [aut], Ariella Chelsky [aut], Melissa Foley [aut] , David Senn [aut] |
Maintainer: | Marcus Beck <[email protected]> |
License: | CC0 |
Version: | 1.5.0 |
Built: | 2024-11-03 05:07:51 UTC |
Source: | https://github.com/tbep-tech/wqtrends |
Extract period (seasonal) averages from fitted GAM
anlz_avgseason(mod, doystr = 1, doyend = 364, yromit = NULL)
anlz_avgseason(mod, doystr = 1, doyend = 364, yromit = NULL)
mod |
input model object as returned by |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
yromit |
optional numeric vector for years to omit from the output |
A data frame of period averages
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_avgseason(mod, doystr = 90, doyend = 180)
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_avgseason(mod, doystr = 90, doyend = 180)
Back-transform response variable after fitting GAM
anlz_backtrans(dat)
anlz_backtrans(dat)
dat |
input data with |
dat
can be output from anlz_trans
or anlz_prd
dat
with the value
column back-transformed using info from the trans
column
library(dplyr) tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') dat <- anlz_trans(tomod, trans = 'log10') backtrans <- anlz_backtrans(dat) head(backtrans) mod <- anlz_gam(tomod, trans = 'log10') dat <- anlz_prd(mod) backtrans <- anlz_backtrans(dat) head(backtrans)
library(dplyr) tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') dat <- anlz_trans(tomod, trans = 'log10') backtrans <- anlz_backtrans(dat) head(backtrans) mod <- anlz_gam(tomod, trans = 'log10') dat <- anlz_prd(mod) backtrans <- anlz_backtrans(dat) head(backtrans)
Return summary statistics for GAM fits
anlz_fit(mod)
anlz_fit(mod)
mod |
input model object as returned by |
Results show the overall summary of the model as Akaike Information Criterion (AIC
), the generalized cross-validation score (GCV
), and the R2
values. Lower values for AIC
and GCV
and higher values for R2
indicate improved model fit.
A data.frame
with summary statistics for GAM fits
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') anlz_fit(mod)
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') anlz_fit(mod)
Fit a generalized additive model to a water quality time series
anlz_gam(moddat, kts = NULL, ...)
anlz_gam(moddat, kts = NULL, ...)
moddat |
input raw data, one station and paramater |
kts |
optional numeric vector for the upper limit for the number of knots in the term |
... |
additional arguments passed to other methods, i.e., |
The model structure is as follows:
chl ~ s(cont_year, k = large)
The cont_year
vector is measured as a continuous numeric variable for the annual effect (e.g., January 1st, 2000 is 2000.0, July 1st, 2000 is 2000.5, etc.) and doy
is the day of year as a numeric value from 1 to 366. The function s
models cont_year
as a smoothed, non-linear variable. The optimal amount of smoothing on cont_year
is determined by cross-validation as implemented in the mgcv package and an upper theoretical upper limit on the number of knots for k
should be large enough to allow sufficient flexibility in the smoothing term. The upper limit of k
was chosen as 12 times the number of years for the input data. If insufficient data are available to fit a model with the specified k
, the number of knots is decreased until the data can be modelled, e.g., 11 times the number of years, 10 times the number of years, etc.
a gam
model object
library(dplyr) tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') anlz_gam(tomod, trans = 'log10')
library(dplyr) tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') anlz_gam(tomod, trans = 'log10')
Extract period (seasonal) metrics from fitted GAM
anlz_metseason( mod, metfun = mean, doystr = 1, doyend = 364, nsim = 10000, yromit = NULL, ... )
anlz_metseason( mod, metfun = mean, doystr = 1, doyend = 364, nsim = 10000, yromit = NULL, ... )
mod |
input model object as returned by |
metfun |
function input for metric to calculate, e.g., |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
nsim |
numeric indicating number of random draws for simulating uncertainty |
yromit |
optional numeric vector for years to omit from the output |
... |
additional arguments passed to |
This function estimates a metric of interest for a given seasonal period each year using results from a fitted GAM (i.e., from anlz_gam
). The estimates are based on the predicted values for each seasonal period, with uncertainty of the metric based on repeated sampling of the predictions following uncertainty in the model coefficients.
A data frame of period metrics
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_metseason(mod, mean, doystr = 90, doyend = 180, nsim = 100)
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_metseason(mod, mean, doystr = 90, doyend = 180, nsim = 100)
Fit a mixed meta-analysis regression model of trends
anlz_mixmeta(metseason, yrstr = 2000, yrend = 2019)
anlz_mixmeta(metseason, yrstr = 2000, yrend = 2019)
metseason |
output from |
yrstr |
numeric for starting year |
yrend |
numeric for ending year |
Parameters are not back-transformed if the original GAM used a transformation of the response variable
A list of mixmeta
fitted model objects
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') metseason <- anlz_metseason(mod, doystr = 90, doyend = 180) anlz_mixmeta(metseason, yrstr = 2016, yrend = 2019)
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') metseason <- anlz_metseason(mod, doystr = 90, doyend = 180) anlz_mixmeta(metseason, yrstr = 2016, yrend = 2019)
Estimate percent change trends from GAM results for selected time periods
anlz_perchg(mod, baseyr, testyr)
anlz_perchg(mod, baseyr, testyr)
mod |
input model object as returned by |
baseyr |
numeric vector of starting years |
testyr |
numeric vector of ending years |
Working components of this function were taken from the gamDiff function in the baytrends package.
A data frame of summary results for change between the years.
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') anlz_perchg(mod, baseyr = 1990, testyr = 2016)
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') anlz_perchg(mod, baseyr = 1990, testyr = 2016)
Get predicted data from fitted GAMs across period of observation
anlz_prd(mod, annual = FALSE)
anlz_prd(mod, annual = FALSE)
mod |
input model object as returned by |
annual |
logical indicating if predictions only for the |
a data.frame
with predictions
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_prd(mod)
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_prd(mod)
Get predicted data from fitted GAMs across period of observation, every day
anlz_prdday(mod)
anlz_prdday(mod)
mod |
input model object as returned by |
a data.frame
with predictions
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_prdday(mod)
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_prdday(mod)
Get prediction matrix for a fitted GAM
anlz_prdmatrix(mod, doystr = 1, doyend = 364, avemat = FALSE)
anlz_prdmatrix(mod, doystr = 1, doyend = 364, avemat = FALSE)
mod |
input model object as returned by |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
avemat |
logical indicating if the prediction matrix is to be passed to |
Used internally by anlz_metseason
, not to be used by itself
a data.frame
with predictors to use with the fitted GAM
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_prdmatrix(mod, doystr = 90, doyend = 180)
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_prdmatrix(mod, doystr = 90, doyend = 180)
Format p-values for show functions
anlz_pvalformat(x)
anlz_pvalformat(x)
x |
numeric input p-value |
p-value formatted as a text string, one of p < 0.001
, 'p < 0.01'
, p < 0.05
, or ns
for not significant
anlz_pvalformat(0.05)
anlz_pvalformat(0.05)
Return summary statistics for smoothers of GAMs
anlz_smooth(mod)
anlz_smooth(mod)
mod |
input model object as returned by |
Results show the individual effects of the modelled components of each model as the estimated degrees of freedom (edf
), the reference degrees of freedom (Ref.df
), the test statistic (F
), and significance of the component (p-value
). The significance of the component is in part based on the difference between edf
and Ref.df
.
a data.frame
with summary statistics for smoothers in each GAM
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') anlz_smooth(mod)
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') anlz_smooth(mod)
Retrieve summary statistics for seasonal metrics and trend results
anlz_sumstats( mod, metfun = mean, doystr = 1, doyend = 364, yrstr = 2000, yrend = 2019, yromit = NULL, nsim = 10000, confint = 0.95, useave = FALSE, ... )
anlz_sumstats( mod, metfun = mean, doystr = 1, doyend = 364, yrstr = 2000, yrend = 2019, yromit = NULL, nsim = 10000, confint = 0.95, useave = FALSE, ... )
mod |
input model object as returned by |
metfun |
function input for metric to calculate, e.g., |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
yrstr |
numeric for starting year for trend model, see details |
yrend |
numeric for ending year for trend model, see details |
yromit |
optional numeric vector for years to omit from the plot, see details |
nsim |
numeric indicating number of random draws for simulating uncertainty |
confint |
numeric from zero to one indicating confidence interval level for summarizing the mixed-effects meta-analysis model, see details |
useave |
logical indicating if |
... |
additional arguments passed to |
This function is primarily for convenience to return summary statistics of a fitted GAM from anlz_gam
.
Note that confint
only applies to the summary
and coeffs
list outputs. It does not apply to the metseason
list element output that is default set to 95
Set useave = T
to speed up calculations if metfun = mean
. This will use anlz_avgseason
to estimate the seasonal summary metrics using a non-stochastic equation.
A list object with named elements:
mixmet
: mixmeta
object of the fitted mixed-effects meta-analysis trend model
metseason
: tibble object of the fitted seasonal metrics as returned by anlz_metseason
or anlz_avgseason
summary
: summary of the mixmet
object
coeffs
: tibble object of the slope estimate coefficients from the mixmet
model. An approximately linear slope estimate will be included as slope.approx
if trans = 'log10'
for the GAM used in mod
.
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_sumstats(mod, metfun = mean, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, nsim = 100)
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_sumstats(mod, metfun = mean, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, nsim = 100)
Estimate seasonal rates of change based on average estimates for multiple window widths
anlz_sumtrndseason( mod, doystr = 1, doyend = 364, justify = c("center", "left", "right"), win = 5:15, yromit = NULL )
anlz_sumtrndseason( mod, doystr = 1, doyend = 364, justify = c("center", "left", "right"), win = 5:15, yromit = NULL )
mod |
input model object as returned by |
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 vector indicating number of years to use for the trend window |
yromit |
optional numeric vector for years to omit from the plot, see details |
The optional yromit
vector can be used to omit years from the plot and 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.
This function is a wrapper to anlz_trndseason
to loop across values in win
, using useave = TRUE
for quicker calculation of average seasonal metrics. It does not work with any other seasonal metric calculations.
A data frame of slope estimates and p-values for each year
Other analyze:
anlz_trans()
,
anlz_trndseason()
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_sumtrndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 2:3)
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_sumtrndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 2:3)
Transform response variable prior to fitting GAM
anlz_trans(moddat, trans = c("log10", "ident"))
anlz_trans(moddat, trans = c("log10", "ident"))
moddat |
input raw data, one station and paramater |
trans |
chr string indicating desired type of transformation, one of |
moddat
with the value
column transformed as indicated
Other analyze:
anlz_sumtrndseason()
,
anlz_trndseason()
library(dplyr) tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') anlz_trans(tomod, trans = 'log10')
library(dplyr) tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') anlz_trans(tomod, trans = 'log10')
Estimate rates of change based on seasonal metrics
anlz_trndseason( mod, metfun = mean, doystr = 1, doyend = 364, justify = c("center", "left", "right"), win = 5, nsim = 10000, yromit = NULL, useave = FALSE, ... )
anlz_trndseason( mod, metfun = mean, doystr = 1, doyend = 364, justify = c("center", "left", "right"), win = 5, nsim = 10000, yromit = NULL, useave = FALSE, ... )
mod |
input model object as returned by |
metfun |
function input for metric to calculate, e.g., |
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 |
... |
additional arguments passed to |
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
). Set useave = T
to speed up calculations if metfun = mean
. This will use anlz_avgseason
to estimate the seasonal summary metrics using a non-stochastic equation.
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., 1990 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.
A data frame of slope estimates and p-values for each year
Other analyze:
anlz_sumtrndseason()
,
anlz_trans()
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)
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)
Raw data from San Francisco Estuary (South Bay)
rawdat
rawdat
A data.frame
object with 12411 rows and 8 columns
Date
int
chr
num
num
num
num
Ord.factor
Data from datprc
object in https://github.com/fawda123/SFbaytrends
Plot period (seasonal) averages from fitted GAM
show_metseason( mod, metfun = mean, doystr = 1, doyend = 364, yrstr = 2000, yrend = 2019, yromit = NULL, ylab, width = 0.9, size = 1.5, nsim = 10000, useave = FALSE, base_size = 11, xlim = NULL, ylim = NULL, ... )
show_metseason( mod, metfun = mean, doystr = 1, doyend = 364, yrstr = 2000, yrend = 2019, yromit = NULL, ylab, width = 0.9, size = 1.5, nsim = 10000, useave = FALSE, base_size = 11, xlim = NULL, ylim = NULL, ... )
mod |
input model object as returned by |
metfun |
function input for metric to calculate, e.g., |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
yrstr |
numeric for starting year for trend model, see details |
yrend |
numeric for ending year for trend model, see details |
yromit |
optional numeric vector for years to omit from the plot, see details |
ylab |
chr string for y-axis label |
width |
numeric for width of error bars |
size |
numeric for point size |
nsim |
numeric indicating number of random draws for simulating uncertainty |
useave |
logical indicating if |
base_size |
numeric indicating base font size, passed to |
xlim |
optional numeric vector of length two for x-axis limits |
ylim |
optional numeric vector of length two for y-axis limits |
... |
additional arguments passed to |
Setting yrstr
or yrend
to NULL
will suppress plotting of the trend line for the meta-analysis regression model.
The optional yromit
vector can be used to omit years from the plot and 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.
Set useave = T
to speed up calculations if metfun = mean
. This will use anlz_avgseason
to estimate the seasonal summary metrics using a non-stochastic equation.
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'ident') show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)') # show seasonal metrics without annual trend show_metseason(mod, doystr = 90, doyend = 180, yrstr = NULL, yrend = NULL, ylab = 'Chlorophyll-a (ug/L)') # omit years from the analysis show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, yromit = 2017, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'ident') show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, ylab = 'Chlorophyll-a (ug/L)') # show seasonal metrics without annual trend show_metseason(mod, doystr = 90, doyend = 180, yrstr = NULL, yrend = NULL, ylab = 'Chlorophyll-a (ug/L)') # omit years from the analysis show_metseason(mod, doystr = 90, doyend = 180, yrstr = 2016, yrend = 2019, yromit = 2017, ylab = 'Chlorophyll-a (ug/L)')
Plot seasonal metrics and rates of change
show_mettrndseason( mod, metfun = mean, doystr = 1, doyend = 364, justify = c("center", "left", "right"), win = 5, nsim = 10000, useave = FALSE, yromit = NULL, ylab, width = 0.9, size = 3, nms = NULL, fils = NULL, cmbn = F, base_size = 11, xlim = NULL, ylim = NULL, ... )
show_mettrndseason( mod, metfun = mean, doystr = 1, doyend = 364, justify = c("center", "left", "right"), win = 5, nsim = 10000, useave = FALSE, yromit = NULL, ylab, width = 0.9, size = 3, nms = NULL, fils = NULL, cmbn = F, base_size = 11, xlim = NULL, ylim = NULL, ... )
mod |
input model object as returned by |
metfun |
function input for metric to calculate, e.g., |
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 |
useave |
logical indicating if |
yromit |
optional numeric vector for years to omit from the plot, see details |
ylab |
chr string for y-axis label |
width |
numeric for width of error bars |
size |
numeric for point size |
nms |
optional character vector for trend names, see details |
fils |
optional character vector for the fill of interior point colors, see details |
cmbn |
logical indicating if the no trend and no estimate colors should be combined, see details |
base_size |
numeric indicating base font size, passed to |
xlim |
optional numeric vector of length two for x-axis limits |
ylim |
optional numeric vector of length two for y-axis limits |
... |
additional arguments passed to |
The plot is the same as that returned by show_metseason
with the addition of points for the seasonal metrics colored by the trends estimated from anlz_trndseason
for the specified window and justification.
Four colors are used to define increasing, decreasing, no trend, or no estimate (i.e., too few points for the window). The names and the colors can be changed using the nms
and fils
arguments, respectively. The cmbn
argument can be used to combine the no trend and no estimate colors into one color and label. Although this may be desired for aesthetic reasons, the colors and labels may be misleading with the default names since no trend is shown for points where no estimates were made.
The optional yromit
vector can be used to omit years from the plot and 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.
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_mettrndseason(mod, metfun = mean, doystr = 90, doyend = 180, justify = 'center', win = 4, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_mettrndseason(mod, metfun = mean, doystr = 90, doyend = 180, justify = 'center', win = 4, ylab = 'Chlorophyll-a (ug/L)')
Plot percent change trends from GAM results for selected time periods
show_perchg( mod, baseyr, testyr, ylab, base_size = 11, xlim = NULL, ylim = NULL )
show_perchg( mod, baseyr, testyr, ylab, base_size = 11, xlim = NULL, ylim = NULL )
mod |
input model object as returned by |
baseyr |
numeric vector of starting years |
testyr |
numeric vector of ending years |
ylab |
chr string for y-axis label |
base_size |
numeric indicating base font size, passed to |
xlim |
optional numeric vector of length two for x-axis limits |
ylim |
optional numeric vector of length two for y-axis limits |
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') show_perchg(mod, baseyr = 1995, testyr = 2016, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') show_perchg(mod, baseyr = 1995, testyr = 2016, ylab = 'Chlorophyll-a (ug/L)')
Plot a 3-d surface of predictions
show_prd3d(mod, ylab)
show_prd3d(mod, ylab)
mod |
input model object as returned by |
ylab |
chr string for y-axis label |
a plotly
surface
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_prd3d(mod, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_prd3d(mod, ylab = 'Chlorophyll-a (ug/L)')
Plot predictions for GAMs against day of year
show_prddoy(mod, ylab, size = 0.5, alpha = 1, base_size = 11)
show_prddoy(mod, ylab, size = 0.5, alpha = 1, base_size = 11)
mod |
input model object as returned by |
ylab |
chr string for y-axis label |
size |
numeric indicating line size |
alpha |
numeric from 0 to 1 indicating line transparency |
base_size |
numeric indicating base font size, passed to |
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') show_prddoy(mod, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') show_prddoy(mod, ylab = 'Chlorophyll-a (ug/L)')
Plot predictions for GAMs over time, by season
show_prdseason(mod, ylab, base_size = 11, xlim = NULL, ylim = NULL)
show_prdseason(mod, ylab, base_size = 11, xlim = NULL, ylim = NULL)
mod |
input model object as returned by |
ylab |
chr string for y-axis label |
base_size |
numeric indicating base font size, passed to |
xlim |
optional numeric vector of length two for x-axis limits |
ylim |
optional numeric vector of length two for y-axis limits |
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_prdseason(mod, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_prdseason(mod, ylab = 'Chlorophyll-a (ug/L)')
Plot predictions for GAMs over time series
show_prdseries( mod, ylab, alpha = 0.7, base_size = 11, xlim = NULL, ylim = NULL, col = "brown" )
show_prdseries( mod, ylab, alpha = 0.7, base_size = 11, xlim = NULL, ylim = NULL, col = "brown" )
mod |
input model object as returned by |
ylab |
chr string for y-axis label |
alpha |
numeric from 0 to 1 indicating line transparency |
base_size |
numeric indicating base font size, passed to |
xlim |
optional numeric vector of length two for x-axis limits |
ylim |
optional numeric vector of length two for y-axis limits |
col |
optional chr string for line color |
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') show_prdseries(mod, ylab = 'Chlorophyll-a (ug/L)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') mod <- anlz_gam(tomod, trans = 'log10') show_prdseries(mod, ylab = 'Chlorophyll-a (ug/L)')
Plot seasonal rates of change based on average estimates for multiple window widths
show_sumtrndseason( mod, doystr = 1, doyend = 364, yromit = NULL, justify = c("center", "left", "right"), win = 5:15, txtsz = 6, cols = c("lightblue", "lightgreen"), base_size = 11 )
show_sumtrndseason( mod, doystr = 1, doyend = 364, yromit = NULL, justify = c("center", "left", "right"), win = 5:15, txtsz = 6, cols = c("lightblue", "lightgreen"), base_size = 11 )
mod |
input model object as returned by |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
yromit |
optional numeric vector for years to omit from the plot, see details |
justify |
chr string indicating the justification for the trend window |
win |
numeric vector indicating number of years to use for the trend window |
txtsz |
numeric for size of text labels inside the plot |
cols |
vector of low/high colors for trends |
base_size |
numeric indicating base font size, passed to |
This function plots output from anlz_sumtrndseason
.
The optional yromit
vector can be used to omit years from the plot and 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.
A ggplot2
plot
Other show:
show_sumtrndseason2()
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_sumtrndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 2:3)
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_sumtrndseason(mod, doystr = 90, doyend = 180, justify = 'center', win = 2:3)
Plot seasonal rates of change in quarters based on average estimates for multiple window widths
show_sumtrndseason2( mod, yromit = NULL, justify = c("center", "left", "right"), win = 5:15, txtsz = 6, cols = c("lightblue", "lightgreen"), base_size = 11 )
show_sumtrndseason2( mod, yromit = NULL, justify = c("center", "left", "right"), win = 5:15, txtsz = 6, cols = c("lightblue", "lightgreen"), base_size = 11 )
mod |
input model object as returned by |
yromit |
optional numeric vector for years to omit from the plot, see details |
justify |
chr string indicating the justification for the trend window |
win |
numeric vector indicating number of years to use for the trend window |
txtsz |
numeric for size of text labels inside the plot |
cols |
vector of low/high colors for trends |
base_size |
numeric indicating base font size, passed to |
This function is similar to show_sumtrndseason
but results are grouped into seasonal quarters as four separate plots with a combined color scale.
The optional yromit
vector can be used to omit years from the plot and 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.
A ggplot2
plot
Other show:
show_sumtrndseason()
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_sumtrndseason2(mod, justify = 'center', win = 2:3)
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_sumtrndseason2(mod, justify = 'center', win = 2:3)
Plot rates of change based on seasonal metrics
show_trndseason( mod, metfun = mean, doystr = 1, doyend = 364, type = c("log10", "approx"), justify = c("left", "right", "center"), win = 5, ylab, nsim = 10000, yromit = NULL, useave = FALSE, base_size = 11, nms = NULL, fils = NULL, cols = NULL, xlim = NULL, ylim = NULL, ... )
show_trndseason( mod, metfun = mean, doystr = 1, doyend = 364, type = c("log10", "approx"), justify = c("left", "right", "center"), win = 5, ylab, nsim = 10000, yromit = NULL, useave = FALSE, base_size = 11, nms = NULL, fils = NULL, cols = NULL, xlim = NULL, ylim = NULL, ... )
mod |
input model object as returned by |
metfun |
function input for metric to calculate, e.g., |
doystr |
numeric indicating start Julian day for extracting averages |
doyend |
numeric indicating ending Julian day for extracting averages |
type |
chr string indicating if log slopes are shown (if applicable) |
justify |
chr string indicating the justification for the trend window |
win |
numeric indicating number of years to use for the trend window, see details |
ylab |
chr string for y-axis label |
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 |
base_size |
numeric indicating base font size, passed to |
nms |
optional character vector for trend names |
fils |
optional character vector for the fill of interior point colors |
cols |
optional character vector for confidence interval colors |
xlim |
optional numeric vector of length two for x-axis limits |
ylim |
optional numeric vector of length two for y-axis limits |
... |
additional arguments passed to |
A ggplot
object
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_trndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 4, ylab = 'Slope Chlorophyll-a (ug/L/yr)')
library(dplyr) # data to model tomod <- rawdat %>% filter(station %in% 34) %>% filter(param %in% 'chl') %>% filter(yr > 2015) mod <- anlz_gam(tomod, trans = 'log10') show_trndseason(mod, doystr = 90, doyend = 180, justify = 'left', win = 4, ylab = 'Slope Chlorophyll-a (ug/L/yr)')