Skip to content

Commit

Permalink
fix a few urls; update buildignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Apr 18, 2024
1 parent 7be8d52 commit f27b7ad
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 52 deletions.
13 changes: 8 additions & 5 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
^doc$
^_pkgdown\.yml$
^docs$
^misc$
^pkgdown$
^\.github$
^README.Rmd
^index.Rmd
^index.md
^tests/testthat/Rplots\.pdf$
^README\.Rmd$
^README-.*\.png$
^\README_cache$
^index\.Rmd
^index\.md
^base_gam.txt
^Meta$
^CRAN-SUBMISSION$
^cran-comments\.md$
^tests/mvgam_examples\.R$
^tests/testthat/Rplots\.pdf$
^tests/local$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Fit Bayesian Dynamic Generalised Additive Models to sets of time se
with Hamiltonian Monte Carlo in the software Stan. The package also includes
utilities for online updating of forecast distributions with a recursive particle filter that
uses sequential importance sampling to assimilate new observations as they become available.
References: Clark & Wells (2022) <https://doi.org/10.1111/2041-210X.13974>.
References: Clark & Wells (2022) <doi.org/10.1111/2041-210X.13974>.
URL: https://github.com/nicholasjclark/mvgam, https://nicholasjclark.github.io/mvgam/
BugReports: https://github.com/nicholasjclark/mvgam/issues
License: MIT + file LICENSE
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ knitr::opts_chunk$set(
================
[![R-CMD-check](https://github.com/nicholasjclark/mvgam/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nicholasjclark/mvgam/actions/)
[![test-coverage](https://github.com/nicholasjclark/mvgam/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/nicholasjclark/mvgam/actions/workflows/test-coverage.yaml)
[![codecov](https://codecov.io/gh/nicholasjclark/mvgam/graph/badge.svg?token=RCJ2B7S0BL)](https://codecov.io/gh/nicholasjclark/mvgam)
[![codecov](https://codecov.io/gh/nicholasjclark/mvgam/graph/badge.svg?token=RCJ2B7S0BL)](https://app.codecov.io/gh/nicholasjclark/mvgam)

The goal of `mvgam` is to fit Bayesian Dynamic Generalized Additive Models to time series data. The motivation for the package is described in [Clark & Wells 2022](https://besjournals.onlinelibrary.wiley.com/doi/10.1111/2041-210X.13974){target="_blank"} (published in *Methods in Ecology and Evolution*), with additional inspiration on the use of Bayesian probabilistic modelling coming from [Michael Betancourt](https://betanalpha.github.io/writing/){target="_blank"}, [Michael Dietze](https://www.bu.edu/earth/profiles/michael-dietze/){target="_blank"} and [Emily Fox](https://emilybfox.su.domains/){target="_blank"}, among many others.

Expand Down
84 changes: 42 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[![R-CMD-check](https://github.com/nicholasjclark/mvgam/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/nicholasjclark/mvgam/actions/)
[![test-coverage](https://github.com/nicholasjclark/mvgam/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/nicholasjclark/mvgam/actions/workflows/test-coverage.yaml)
[![codecov](https://codecov.io/gh/nicholasjclark/mvgam/graph/badge.svg?token=RCJ2B7S0BL)](https://codecov.io/gh/nicholasjclark/mvgam)
[![codecov](https://codecov.io/gh/nicholasjclark/mvgam/graph/badge.svg?token=RCJ2B7S0BL)](https://app.codecov.io/gh/nicholasjclark/mvgam)

The goal of `mvgam` is to fit Bayesian Dynamic Generalized Additive
Models to time series data. The motivation for the package is described
Expand Down Expand Up @@ -328,29 +328,29 @@ summary(lynx_mvgam)
#>
#>
#> GAM coefficient (beta) estimates:
#> 2.5% 50% 97.5% Rhat n_eff
#> (Intercept) 6.000 6.600 7.0000 1.01 454
#> s(season).1 -0.630 0.024 0.6500 1.00 945
#> s(season).2 -0.180 0.810 1.8000 1.01 318
#> s(season).3 -0.012 1.200 2.5000 1.01 302
#> s(season).4 -0.490 0.410 1.3000 1.00 1019
#> s(season).5 -1.200 -0.170 0.9100 1.01 482
#> s(season).6 -1.000 -0.038 1.0000 1.01 557
#> s(season).7 -0.690 0.350 1.4000 1.00 628
#> s(season).8 -0.920 0.280 1.8000 1.02 290
#> s(season).9 -1.100 -0.270 0.7200 1.02 367
#> s(season).10 -1.300 -0.670 -0.0058 1.00 493
#> 2.5% 50% 97.5% Rhat n_eff
#> (Intercept) 6.100 6.600 7.00 1.00 875
#> s(season).1 -0.620 0.032 0.70 1.00 965
#> s(season).2 -0.260 0.840 1.80 1.01 432
#> s(season).3 -0.032 1.200 2.50 1.01 395
#> s(season).4 -0.480 0.430 1.30 1.01 1063
#> s(season).5 -1.200 -0.150 0.92 1.00 459
#> s(season).6 -1.100 -0.015 1.00 1.00 457
#> s(season).7 -0.710 0.390 1.40 1.00 987
#> s(season).8 -0.950 0.310 1.80 1.00 446
#> s(season).9 -1.100 -0.250 0.65 1.00 565
#> s(season).10 -1.300 -0.710 -0.02 1.01 691
#>
#> Approximate significance of GAM smooths:
#> edf Ref.df Chi.sq p-value
#> s(season) 9.91 10 19870 0.21
#> s(season) 9.91 10 19271 0.22
#>
#> Latent trend AR parameter estimates:
#> 2.5% 50% 97.5% Rhat n_eff
#> ar1[1] 0.73 1.10 1.400 1.01 555
#> ar2[1] -0.83 -0.39 0.062 1.00 1494
#> ar3[1] -0.49 -0.12 0.320 1.01 466
#> sigma[1] 0.40 0.50 0.650 1.00 924
#> ar1[1] 0.73 1.10 1.400 1.01 614
#> ar2[1] -0.82 -0.40 0.049 1.00 1284
#> ar3[1] -0.45 -0.12 0.290 1.00 621
#> sigma[1] 0.40 0.50 0.650 1.00 995
#>
#> Stan MCMC diagnostics:
#> n_eff / iter looks reasonable for all parameters
Expand All @@ -359,7 +359,7 @@ summary(lynx_mvgam)
#> 0 of 2000 iterations saturated the maximum tree depth of 12 (0%)
#> E-FMI indicated no pathological behavior
#>
#> Samples were drawn using NUTS(diag_e) at Wed Apr 17 1:49:33 PM 2024.
#> Samples were drawn using NUTS(diag_e) at Thu Apr 18 8:23:57 PM 2024.
#> For each parameter, n_eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor on split MCMC chains
#> (at convergence, Rhat = 1)
Expand Down Expand Up @@ -468,7 +468,7 @@ plotted on the outcome scale, for example:
``` r
require(ggplot2)
#> Loading required package: ggplot2
#> Warning: package 'ggplot2' was built under R version 4.2.3
#> Warning: package 'ggplot2' was built under R version 4.3.3
plot_predictions(lynx_mvgam, condition = 'season', points = 0.5) +
theme_classic()
```
Expand All @@ -485,7 +485,7 @@ plot(lynx_mvgam, type = 'forecast', newdata = lynx_test)
<img src="man/figures/README-unnamed-chunk-21-1.png" alt="Plotting forecast distributions using mvgam in R" width="60%" style="display: block; margin: auto;" />

#> Out of sample CRPS:
#> [1] 2872.775
#> [1] 2850.77

And the estimated latent trend component, again using the more flexible
`plot_mvgam_...()` option to show first derivatives of the estimated
Expand Down Expand Up @@ -612,41 +612,41 @@ summary(mod, include_betas = FALSE)
#>
#> Observation precision parameter estimates:
#> 2.5% 50% 97.5% Rhat n_eff
#> phi[1] 5.4 8.3 12 1 1780
#> phi[2] 5.8 8.8 13 1 1497
#> phi[3] 5.8 8.5 12 1 1845
#> phi[1] 5.5 8.4 12 1 1516
#> phi[2] 5.8 8.7 13 1 1333
#> phi[3] 5.6 8.5 12 1 1690
#>
#> GAM coefficient (beta) estimates:
#> 2.5% 50% 97.5% Rhat n_eff
#> (Intercept) -0.23 0.18 0.44 1.01 665
#> (Intercept) -0.19 0.19 0.44 1 822
#>
#> Approximate significance of GAM smooths:
#> edf Ref.df Chi.sq p-value
#> s(season) 4.47 5 34.03 <2e-16 ***
#> s(season):seriesseries_1 1.44 4 0.27 0.98
#> s(season):seriesseries_2 1.00 4 0.30 0.99
#> s(season):seriesseries_3 1.13 4 1.64 0.77
#> edf Ref.df Chi.sq p-value
#> s(season) 4.639 5 35.50 <2e-16 ***
#> s(season):seriesseries_1 0.887 4 0.53 0.98
#> s(season):seriesseries_2 0.940 4 0.44 0.99
#> s(season):seriesseries_3 1.391 4 1.40 0.78
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Latent trend marginal deviation (alpha) and length scale (rho) estimates:
#> 2.5% 50% 97.5% Rhat n_eff
#> alpha_gp[1] 0.049 0.42 0.94 1.01 564
#> alpha_gp[2] 0.370 0.71 1.20 1.01 867
#> alpha_gp[3] 0.160 0.48 0.99 1.00 980
#> rho_gp[1] 1.200 3.70 13.00 1.01 491
#> rho_gp[2] 1.800 7.30 31.00 1.01 522
#> rho_gp[3] 1.400 4.70 21.00 1.00 760
#> 2.5% 50% 97.5% Rhat n_eff
#> alpha_gp[1] 0.10 0.44 0.98 1.00 770
#> alpha_gp[2] 0.37 0.74 1.30 1.00 1129
#> alpha_gp[3] 0.16 0.46 0.98 1.00 824
#> rho_gp[1] 1.20 3.80 14.00 1.00 705
#> rho_gp[2] 1.80 7.30 33.00 1.01 411
#> rho_gp[3] 1.30 4.90 23.00 1.01 658
#>
#> Stan MCMC diagnostics:
#> n_eff / iter looks reasonable for all parameters
#> Rhat looks reasonable for all parameters
#> 8 of 2000 iterations ended with a divergence (0.4%)
#> 3 of 2000 iterations ended with a divergence (0.15%)
#> *Try running with larger adapt_delta to remove the divergences
#> 0 of 2000 iterations saturated the maximum tree depth of 12 (0%)
#> E-FMI indicated no pathological behavior
#>
#> Samples were drawn using NUTS(diag_e) at Wed Apr 17 1:50:51 PM 2024.
#> Samples were drawn using NUTS(diag_e) at Thu Apr 18 8:25:56 PM 2024.
#> For each parameter, n_eff is a crude measure of effective sample size,
#> and Rhat is the potential scale reduction factor on split MCMC chains
#> (at convergence, Rhat = 1)
Expand All @@ -662,11 +662,11 @@ for(i in 1:3){
```

#> Out of sample CRPS:
#> [1] 2.123262
#> [1] 2.0731
#> Out of sample CRPS:
#> [1] 1.849232
#> [1] 1.833157
#> Out of sample CRPS:
#> [1] 1.758914
#> [1] 1.736085

<img src="man/figures/README-beta_fc-1.png" width="60%" style="display: block; margin: auto;" />

Expand Down
Binary file modified man/figures/README-beta_fc-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-13-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-16-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-17-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-18-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-19-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-20-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-21-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-22-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-23-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-24-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vignettes/forecast_evaluation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ plot(fc_mod2, series = 1)
```

## Scoring forecast distributions
A primary purpose of the `mvgam_forecast` class is to readily allow forecast evaluations for each series in the data, using a variety of possible scoring functions. See `?mvgam::score.mvgam_forecast` to view the types of scores that are available. A useful scoring metric is the [Continuous Rank Probability Score (CRPS)](https://www.annualreviews.org/doi/10.1146/annurev-statistics-062713-085831){target="_blank"}. A CRPS value is similar to what we might get if we calculated a weighted absolute error using the full forecast distribution.
A primary purpose of the `mvgam_forecast` class is to readily allow forecast evaluations for each series in the data, using a variety of possible scoring functions. See `?mvgam::score.mvgam_forecast` to view the types of scores that are available. A useful scoring metric is the [Continuous Rank Probability Score (CRPS)](https://www.annualreviews.org/content/journals/10.1146/annurev-statistics-062713-085831){target="_blank"}. A CRPS value is similar to what we might get if we calculated a weighted absolute error using the full forecast distribution.
```{r warning=FALSE}
crps_mod1 <- score(fc_mod1, score = 'crps')
str(crps_mod1)
Expand Down
4 changes: 2 additions & 2 deletions vignettes/time_varying_effects.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ plot(fc)
```

## Salmon survival example
Here we will use openly available data on marine survival of Chinook salmon to illustrate how time-varying effects can be used to improve ecological time series models. [Scheuerell and Williams (2005)]() used a dynamic linear model to examine the relationship between marine survival of Chinook salmon and an index of ocean upwelling strength along the west coast of the USA. The authors hypothesized that stronger upwelling in April should create better growing conditions for phytoplankton, which would then translate into more zooplankton and provide better foraging opportunities for juvenile salmon entering the ocean. The data on survival is measured as a proportional variable over 42 years (1964–2005) and is available in the `MARSS` package:
Here we will use openly available data on marine survival of Chinook salmon to illustrate how time-varying effects can be used to improve ecological time series models. [Scheuerell and Williams (2005)](https://onlinelibrary.wiley.com/doi/abs/10.1111/j.1365-2419.2005.00346.x) used a dynamic linear model to examine the relationship between marine survival of Chinook salmon and an index of ocean upwelling strength along the west coast of the USA. The authors hypothesized that stronger upwelling in April should create better growing conditions for phytoplankton, which would then translate into more zooplankton and provide better foraging opportunities for juvenile salmon entering the ocean. The data on survival is measured as a proportional variable over 42 years (1964–2005) and is available in the `MARSS` package:
```{r}
load(url('https://github.com/atsa-es/MARSS/raw/master/data/SalmonSurvCUI.rda'))
dplyr::glimpse(SalmonSurvCUI)
Expand Down Expand Up @@ -349,7 +349,7 @@ Bürkner, PC, Gabry, J and Vehtari, A [Approximate leave-future-out cross-valida

Herrero, Asier, et al. [From the individual to the landscape and back: time‐varying effects of climate and herbivory on tree sapling growth at distribution limits](https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/1365-2745.12527). *Journal of Ecology* 104.2 (2016): 430-442.

Holmes, Elizabeth E., Eric J. Ward, and Wills Kellie. "[MARSS: multivariate autoregressive state-space models for analyzing time-series data.](https://d1wqtxts1xzle7.cloudfront.net/30588864/rjournal_2012-1_holmes_et_al-libre.pdf?1391843792=&response-content-disposition=inline%3B+filename%3DMARSS_Multivariate_Autoregressive_State.pdf&Expires=1695861526&Signature=TCRXULs0mUKRM4m1pmvZxwE10bUqS6vzLcuKeUBCj57YIjx23iTxS1fEgBpV0fs2wb5XAw7ZkG84XyMaoS~vjiqZ-DpheQDHwAHpIWG-TcckHQjEjPWTNajFvAemToUdCiHnDa~yrhW9HRgXjgncdalkjzjvjT3HLSW8mcjBDhQN-WJ3MKQFSXtxoBpWfcuPYbf-HC1E1oSl7957y~w0I1gcIVdu6LHjP~CEKXa0BQzS4xuarL2nz~tHD2MverbNJYMrDGrAxIi-MX6i~lfHWuwV6UKRdoOZ0pXIcMYWBTv9V5xYey76aMKTICiJ~0NqXLZdXO5qlS4~~2nFEO7b7w__&Key-Pair-Id=APKAJLOHF5GGSLRBV4ZA)" *R Journal*. 4.1 (2012): 11.
Holmes, Elizabeth E., Eric J. Ward, and Wills Kellie. "[MARSS: multivariate autoregressive state-space models for analyzing time-series data.](https://journal.r-project.org/archive/2012/RJ-2012-002/index.html)" *R Journal*. 4.1 (2012): 11.

Scheuerell, Mark D., and John G. Williams. [Forecasting climate induced changes in the survival of Snake River Spring/Summer Chinook Salmon (*Oncorhynchus Tshawytscha*)](https://onlinelibrary.wiley.com/doi/10.1111/j.1365-2419.2005.00346.x) *Fisheries Oceanography* 14 (2005): 448–57.

Expand Down

0 comments on commit f27b7ad

Please sign in to comment.