| Title: | Aggregated Abundance Trends using GAMs |
|---|---|
| Description: | The package supplies a set of functions for stochastically imputing missing site-level abundance measurements so sites can be aggregated to regional abundance for trend estimation. This package is specifically intended for trend estimation for the NMFS Alaska Fisheries Science Center's assessment of Steller sea lion trends in Alaska and the U.S. west coast. Although the methodology is applicable to other applications, there are aspects of sea lion surveys hard coded into the analysis. |
| Authors: | Devin Johnson [aut, cre] |
| Maintainer: | Devin Johnson <[email protected]> |
| License: | CC0 |
| Version: | 0.0.0.9006 |
| Built: | 2026-05-24 09:11:52 UTC |
| Source: | https://github.com/dsjohnson/agTrend.ssl |
This package contains functions to fit GAM models to Steller sea lion survey data. It uses mgcv to fit Tweedie models and aggreates site estimates to regional trend estimates
This software package is developed and maintained by scientists at the NOAA Fisheries Alaska Fisheries Science Center and should be considered a fundamental research communication. The recommendations and conclusions presented here are those of the authors and this software should not be construed as official communication by NMFS, NOAA, or the U.S. Dept. of Commerce. In addition, reference to trade names does not imply endorsement by the National Marine Fisheries Service, NOAA. While the best efforts have been made to insure the highest quality, tools such as this are under constant development and are subject to change.
Devin S. Johnson [email protected] (Maintainer)
Takes abundance samples created with the function
sample.abund and aggregates them based on a factor variable in
(or added) to the sample.abund data set.
ag.abund(x, ag.var)ag.abund(x, ag.var)
x |
A sample abundance data frame produced by |
ag.var |
A factor (or character) variable in |
Devin S. Johnson
The posterior distribution of the count sample is summarized for each site. The resulting data frame can be used for site-level plots, etc.
ag.summary(x, ci.prob = 0.9)ag.summary(x, ci.prob = 0.9)
x |
A data frame created with the sampling function |
ci.prob |
Probability level for credible intervals. Defaults to 0.9. |
Devin S. Johnson
The growth trend of is estimated from the samples obtained from the
functions sample.abund and ag.abund.
ag.trend(x, timeframe, ci.prob = 0.9)ag.trend(x, timeframe, ci.prob = 0.9)
x |
A abundance sample data frame from |
timeframe |
a 2-vector giving the start year and end year of the desired
trend estimate, e.g., |
ci.prob |
The probability for the credible interval. Defaults to 0.9. |
The function returns a named list with elements growth, fitted,
and sample. The growth element contains a table with the estimated
growth of each aggregation in percent growth form. The fitted element contains a
table with the fitted trendline values on the count scale. This can be used for plotting.
Finally, the sample element contains the posterior sample. This can be used for further
analysis of trends such as comparisons, etc.
Devin S. Johnson
This function takes a processed data frame with counts during survey years for each site and fits a multi-site GAM using a Tweedie response distribution.
fit.gam(data, obl.corr, alt.mod = NULL, warn = FALSE, debug = FALSE, ...)fit.gam(data, obl.corr, alt.mod = NULL, warn = FALSE, debug = FALSE, ...)
data |
A data frame containing the sites, counts, and years. |
obl.corr |
Logical. Should oblique photo correction be used? |
alt.mod |
An alternative to the defaul model. See Details. |
warn |
Logical. Should fitting warnings be printed. Defaults to |
debug |
Logical. If set to |
... |
Extra arguments passed to |
A penalized GAM model is fit to the data with a Tweedie distribution for the response distribution.
The mean function for site i in year t is modeled with a smooth year term for all sites plus
a factor smooth such that each site has its own smooth year function as well the mgcv formula is
mu.form = count ~ s(year, SITE, bs='fs', k=8, m=1). For the power and dispersion formulas,
p.form = ~ s(SITE, bs='re') and phi.form = ~ s(SITE, bs='re'), so that each
site has its own p and phi parameters for the Tweedie specification. Thus, for each site, the
mean count is mu(i,t) and the variance is V(i,t) = phi(i)*mu(i,t)^p(i). To specify a different formula for the model, set
alt.model = list(mu=mu.form.alt, p=p.form.alt, phi=phi.form.alt) where the *.alt signifies
the formula for the desired alternative.
If obl.corr = TRUE then a model will be fitted that corrects for the approximately
3.8% reduction in the expected count if the data were collected using an oblique
photo vs. a medium format vertical photo. Unlike the original agTrend package
the uncertainty in this estimate is not accounted for in the model. A few initial tests
revealed that is source of variation seems insignificant when compared to the
natural variation of the observed counts and the model was significantly easier to
fit and more robust when fixing this quantity.
Devin S. Johnson
The current 'ALLCOUNTS_v(x).xlsx' file is processed into the separate, R friendly, data sets necessary for trend analysis.
proc.data(allcounts, age, dps)proc.data(allcounts, age, dps)
allcounts |
the file path of the current allcounts excel file. |
age |
Age needed, must be one of 'pup' or 'nonpup' |
dps |
DPS needed, must be one of 'wdps' or 'edps' |
Devin S. Johnson
Using a fitted GAM SSL model (see fit.gam) and the data used
for fitting, missing survey counts are imputed for aggregated trend and abundance
analysis.
sample.abund( fit, data, yrs, size = 1000, add.site.data = NULL, keep.par = FALSE, debug = FALSE )sample.abund( fit, data, yrs, size = 1000, add.site.data = NULL, keep.par = FALSE, debug = FALSE )
fit |
A fitted model object from a call to |
data |
Data used for model fitting. |
yrs |
Years used for simulation. Defaults to a sequence of years from the first to the last. But this can be any subset of years in the survey window. |
size |
The sample size of the random imputation draws. Defaults to 1,000. |
add.site.data |
An additional data set with a column lableled 'site' matching the sites used in the model fitting data that contain additional groupings of other site-level data. |
keep.par |
Logical. Should the sample of parameters used be retained? It is not often needed for further analysis. |
debug |
Enter into the function for debugging. |
Devin S. Johnson