-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
158 lines (111 loc) · 5.08 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.width = 5,
fig.height = 4
)
library(bboutools)
```
# bboutools
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![R-CMD-check](https://github.com/poissonconsulting/bboutools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/bboutools/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/bboutools/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/bboutools)
<!-- badges: end -->
`bboutools` is an R package to estimate the annual survival, recruitment and population growth for boreal caribou populations using Bayesian and Maximum Likelihood models with fixed and random effects.
It was developed to facilitate direct comparison of estimates across jurisdictions.
## Installation
To install the latest development version:
``` r
# install.packages("remotes")
remotes::install_github("poissonconsulting/bboutools")
```
## Introduction
### Survival
`bboutools` accepts survival data for a single population in a specific format.
```{r}
library(tibble) # for printing data frames
library(ggplot2) # for plotting
library(bboudata) # for boreal caribou datasets
library(bboutools)
surv_data <- bboudata::bbousurv_a
head(surv_data)
```
The survival model, which includes a random effect of month, is fitted using `bb_fit_survival()`.
To achieve convergence increase `nthin`.
```{r, message=FALSE}
set.seed(99)
surv_fit <- bb_fit_survival(surv_data, quiet = TRUE)
glance(surv_fit)
```
Predictions can then be generated using `bb_predict_survival()`.
```{r}
surv_pred <- bb_predict_survival(surv_fit)
surv_pred
```
And plotted using `bb_plot_year()`
```{r}
bb_plot_year_survival(surv_pred) +
expand_limits(y = c(0, 1))
```
The survival in each month can be plotted using `bb_plot_month()`
```{r}
bb_plot_month_survival(surv_fit)
```
These estimates represent the annual survival rate if that month lasted the whole year.
### Recruitment
The equivalent functions for recruitment data are
```{r}
recruit_data <- bboudata::bbourecruit_a
head(recruit_data)
set.seed(99)
recruit_fit <- bb_fit_recruitment(recruit_data, quiet = TRUE)
bb_plot_year_recruitment(recruit_fit)
```
### Population Growth
The function `bb_predict_growth()` predicts the annual population growth (lambda) rate from the survival and recruitment models.
```{r}
lambda <- bb_predict_growth(surv_fit, recruit_fit)
bb_plot_year_growth(lambda)
```
`bb_predict_population_change()` calculates the population change (%) with uncertainty as the cumulative product of population growth.
```{r}
change <- bb_predict_population_change(surv_fit, recruit_fit)
bb_plot_year_population_change(change)
```
## Information
Additional information is available from the [bboutools website](https://poissonconsulting.github.io/bboutools/), which includes the following articles:
- [Get Started](https://poissonconsulting.github.io/bboutools/articles/bboutools.html).
- [Analytic Methods for Estimation of Boreal Caribou Survival, Recruitment and Population Growth](https://poissonconsulting.github.io/bboutools/articles/bbmethods.html).
- [Prior Selection and Influence](https://poissonconsulting.github.io/bboutools/articles/priors.html).
There is also a [user-friendly graphical interface](https://poissonconsulting.shinyapps.io/bboushiny/), called [`bboushiny`](https://github.com/poissonconsulting/bboushiny), for non-R users.
## bbou Suite
`bboutools` is part of the bbou suite of tools.
Other packages in this suite include:
- [bboudata](https://github.com/poissonconsulting/bboudata)
- [bbouretro](https://github.com/poissonconsulting/bbouretro)
- [bboushiny](https://github.com/poissonconsulting/bboushiny)
- [bbousims](https://github.com/poissonconsulting/bbousims)
## Contribution
Please report any [issues](https://github.com/poissonconsulting/bboutools/issues).
[Pull requests](https://github.com/poissonconsulting/bboutools/pulls) are always welcome.
## Code of Conduct
Please note that the `bboutools` project is released with a [Contributor Code of Conduct](https://poissonconsulting.github.io/bboutools/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
## License
The code is released under the Apache License 2.0
Copyright 2022 Environment and Climate Change Canada
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.