-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
103 lines (74 loc) · 4.62 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
---
output:
github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-figs/",
cache.path = "README-cache/"
)
```
# phenomix
R package for fitting distributions to run timing data via maximum likelihood
[![R build status](https://github.com/nwfsc-cb/phenomix/workflows/R-CMD-check/badge.svg)](https://github.com/nwfsc-cb/phenomix/actions)
pkgdown site: [https://nwfsc-cb.github.io/phenomix/](https://nwfsc-cb.github.io/phenomix/)
### DOI
The DOI for this repository is [![DOI](https://zenodo.org/badge/243336401.svg)](https://zenodo.org/doi/10.5281/zenodo.4435275)
## Installation
You can install phenomix with:
```{r, eval=TRUE}
remotes::install_github("nwfsc-cb/phenomix",build_vignettes = TRUE)
```
Load libraries
```{r}
library(phenomix)
library(ggplot2)
```
## Functions
The package pheomix provides a suite of curve fitting to describe data that may be generated from a process when distributions in time might be concentrated (from fisheries, this occurs with counts over time of salmon returning from the ocean to spawn or juvenile fish emigrating from streams to the ocean).
```{r echo=FALSE}
set.seed(123)
df = expand.grid(year = 1:10, doy=100:250)
mus = rnorm(10, 175, 10)
thetas = runif(10, 5, 8)
sigmas = runif(10, 7, 10)
df$y = dnorm(df$doy, mus[df$year], sigmas[df$year], log=TRUE) + thetas[df$year]
df$year = as.factor(df$year)
df$data = rnorm(nrow(df), df$y, 0.2)
```
```{r fig.cap="Predicted (black line) and observed counts (red dots) for hypothetical dataset. Multiple observations may exist for some days, or no observations on others.", echo=FALSE}
ggplot(dplyr::filter(df,year==1), aes(doy,exp(y))) +
geom_line() + xlab("Calendar day") + ylab("Count") +
geom_point(aes(doy,exp(data)),col="red") + theme_bw()
```
In a given year, the curve might be described by a symmetric or asymmetric Gaussian or Student-t distribution (shown here in log-scale on the y-axis). Questions of interest might be
- are the means (x-axis) shifting through time?
- are the variances shifting through time?
- does the model support a symmetric or asymmetric distribution?
```{r echo=FALSE}
ggplot(df, aes(doy,exp(y),col=year,group=year)) +
geom_line() + xlab("Calendar day") + ylab("Count") + theme_bw()
```
## Examples
The main functions are `create_data()` and `fit()`. See `?create_data` and `?fit` for additional details and examples. A vignette includes additional detail, and examples of several models as well as function arguments available [https://nwfsc-cb.github.io/phenomix/](https://nwfsc-cb.github.io/phenomix/).
## References
For description of fisheries applications of asymmetric models:
Methot, R.D. 2000. Technical description of the stock synthesis assessment program. U.S. Dept. Commer., NOAA Tech. Memo. NMFS-NWFSC-43, 46 p. [link](https://repository.library.noaa.gov/view/noaa/3172/noaa_3172_DS1.pdf)
For statistical background of asymmetric models:
Rubio, F.J. and Steel, M.F.J. 2020. The family of two-piece distributions. Significance, 17(1) 120--13. [link](https://rss.onlinelibrary.wiley.com/doi/full/10.1111/j.1740-9713.2020.01352.x)
Wallis, K.F. 2014. The two-piece normal, binormal, or double Gaussian distribution: Its origin and rediscoveries. Statistical Science, 29(1), 106--112. [link](https://arxiv.org/abs/1405.4995)
## NOAA Disclaimer
This repository is a scientific product and is not official communication of the National Oceanic and
Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project code is
provided on an ‘as is’ basis and the user assumes responsibility for its use. Any claims against the Department of
Commerce or Department of Commerce bureaus stemming from the use of this GitHub project will be governed
by all applicable Federal law. Any reference to specific commercial products, processes, or services by service
mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or
favoring by the Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a
DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by
DOC or the United States Government.
<img src="https://raw.githubusercontent.com/nmfs-general-modeling-tools/nmfspalette/main/man/figures/noaa-fisheries-rgb-2line-horizontal-small.png" height="75" alt="NOAA Fisheries">
[U.S. Department of Commerce](https://www.commerce.gov/) | [National Oceanographic and Atmospheric Administration](https://www.noaa.gov) | [NOAA Fisheries](https://www.fisheries.noaa.gov/)