Skip to content

Commit

Permalink
update data, add basic tests
Browse files Browse the repository at this point in the history
Data updated through Nov 2023
  • Loading branch information
ericward-noaa committed Jan 22, 2024
1 parent 8c66668 commit 54ff44d
Show file tree
Hide file tree
Showing 45 changed files with 915 additions and 1,345 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
58 changes: 58 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: rcmdcheck

- uses: r-lib/actions/check-r-package@v2

- name: Show testthat output
if: always()
run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
Package: kwdemog
Type: Package
Title: Package for processing and exploring killer whale demographic data
Version: 1.0.2
Date: 2021-12-12
Version: 1.0.3
Date: 2023-12-15
Authors@R: c(
person(c("Eric", "J."), "Ward", email = "[email protected]",
role = c("aut", "cre")))
Description: Generates killer whale demographic data from rows (observations) and fits preliminary models.
Depends:
R (>= 4.0.0)
Imports: dplyr,ggplot2,mgcv,usethis,rstanarm,stringr,viridis,ggridges
Imports: dplyr,mgcv,usethis,stringr,ggridges,ggplot2,rstanarm,viridis
Suggests: knitr,
rmarkdown,
gridExtra
URL: https://noaa-nwfsc.github.io/srkw-status/
BugReports: https://github.com/noaa-nwfsc/srkw-status/issues
License: GPL (>=3)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Encoding: UTF-8
VignetteBuilder: knitr
LazyData: true
Expand Down
674 changes: 0 additions & 674 deletions LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(project)
export(writedata)
import(dplyr)
import(mgcv)
importFrom(stats,rbeta)
importFrom(stats,rnorm)
importFrom(stats,runif)
importFrom(stringr,str_locate)
Expand Down
4 changes: 2 additions & 2 deletions R/expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ expand <- function(filename, start_year = 1976, current_year = NULL,
fem_age_mat = 10, fem_age_senesc = 43, ages2stages = NULL) {
if(is.null(current_year)) current_year = as.numeric(substr(Sys.Date(),1,4))

if(class(filename) == "data.frame") orca = filename
if(class(filename) == "character") orca = read.csv(filename, stringsAsFactors = FALSE)
if(inherits(filename, "data.frame")) orca = filename
if(inherits(filename, "character")) orca = read.csv(filename, stringsAsFactors = FALSE)
orca$population = ifelse(orca$pod %in% c("J001","K001","L001"), "SRKW", "NRKW")
# create expanded data frame of all years and animals
alldat = expand.grid("year" = start_year:current_year,
Expand Down
14 changes: 6 additions & 8 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
#' e.g. "1981:1985" to use rates from 1981 to 1985 or ("1981:1985","1981:2021")
#' @param verbose whether to print status updates to screen, defaults to FALSE
#' @param p_female The probability of a female birth, defaults to the empirical value since 1980
#' @param n_births Used for uncertainty in the sex ratio at birth. The distribution of female births is
#' assumed to be beta binomial, with shape parameters `(n_births+1)*p_female` and `(n_births+1)*(1-p_female)`.
#' There have been approximately 100 births since 1980, and this defaults to the empirical number
#' of births
#' formula above
#' @param n_births The number of births used to calculate `p_female`. By default, this defaults to the empirical
#' value observed since 1980 the probability of female birth. Larger values result in more precise estimates of `p_female`
#'
#' @import dplyr
#' @import mgcv
#' @importFrom stats rnorm runif
#' @importFrom stats rnorm runif rbeta
#' @importFrom stringr str_locate
#'
#' @export
Expand All @@ -27,7 +24,7 @@ project = function(whale_data, seed = 123,
n_iter = 200,
verbose = FALSE,
p_female = NA,
sd_female = NA) {
n_births = NA) {
set.seed(seed)

data = whale_data
Expand Down Expand Up @@ -101,7 +98,8 @@ project = function(whale_data, seed = 123,

initPopCurrent$sex = as.numeric(initPopCurrent$sex)
# assign sexes to unsexed individuals [0s]
initPopCurrent$sex[which(initPopCurrent$Sex==0)] = ifelse(runif(length(which(initPopCurrent$sex==0))) < rnorm(length(which(initPopCurrent$sex==0)),p_female, sd_female), 1, 2)
initPopCurrent$sex[which(initPopCurrent$Sex==0)] = ifelse(runif(length(which(initPopCurrent$sex==0))) < rbeta(length(which(initPopCurrent$sex==0)), beta_1, beta_2), 1, 2)
#initPopCurrent$sex[which(initPopCurrent$Sex==0)] = ifelse(runif(length(which(initPopCurrent$sex==0))) < rnorm(length(which(initPopCurrent$sex==0)),p_female, sd_female), 1, 2)
newID = 9999

for(yrs in 1:dim(popSize)[2]) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 'kwdemog' package

This is a repository (pkgdown site here: https://nwfsc-cb.github.io/srkw-status/) for archiving code and data related to projecting Southern Resident killer whale population status. The data are included as an .rda file in the /data folder. In addition to using this framework for population projections this has been used extensively for the Pacific Fishery Management Council Working Group to understand the effects of ocean salmon fisheries on killer whales.
This is a repository (pkgdown site here: https://noaa-nwfsc.github.io/srkw-status/) for archiving code and data related to projecting Southern Resident killer whale population status. The data are included as an .rda file in the /data folder. In addition to using this framework for population projections this has been used extensively for the Pacific Fishery Management Council Working Group to understand the effects of ocean salmon fisheries on killer whales.

[2020 PFMC Risk Assessment](https://www.pcouncil.org/documents/2020/02/e-3-a-srkw-workgroup-report-1-electronic-only.pdf/)

Expand Down
Binary file modified data/orca.rda
Binary file not shown.
Binary file modified data/projections.rda
Binary file not shown.
11 changes: 9 additions & 2 deletions docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 27 additions & 21 deletions docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 54ff44d

Please sign in to comment.