Skip to content

Commit

Permalink
Cran updates and gear scaling coefficient
Browse files Browse the repository at this point in the history
  • Loading branch information
abigailkeller committed Oct 2, 2024
1 parent 013991a commit 0252f1a
Show file tree
Hide file tree
Showing 16 changed files with 1,061 additions and 1,179 deletions.
123 changes: 0 additions & 123 deletions .ipynb_checkpoints/README-checkpoint.md

This file was deleted.

5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ Package: eDNAjoint
Title: Joint Modeling of Traditional and Environmental DNA Survey Data
Version: 0.2
Maintainer: Abigail G. Keller <[email protected]>
Author: Abigail G. Keller
Authors@R:
c(person("Abigail G.", "Keller", role = c("aut", "cre"), email="[email protected]"),
person("Ryan P.", "Kelly", role = "ctb", email="[email protected]"),
person("Chitra M.", "Saraswati", role = "rev"),
person("Saras M.", "Windecker", role = "rev"))
Description: Models integrate environmental DNA (eDNA) detection data and traditional survey data to jointly estimate species catch rate (see package vignette: https://bookdown.org/abigailkeller/eDNAjoint_vignette/). Models can be used with count data via traditional survey methods (i.e., trapping, electrofishing, visual) and replicated eDNA detection/nondetection data via polymerase chain reaction (i.e., PCR or qPCR) from multiple survey locations. Estimated parameters include probability of a false positive eDNA detection, a site-level covariates that scale the sensitivity of eDNA surveys relative to traditional surveys, and catchability coefficients for traditional gear types. Models are implemented with a Bayesian framework (Markov chain Monte Carlo) using the 'Stan' probabilistic programming language.
Description: Models integrate environmental DNA (eDNA) detection data and traditional survey data to jointly estimate species catch rate (see package vignette: <https://bookdown.org/abigailkeller/eDNAjoint_vignette/>). Models can be used with count data via traditional survey methods (i.e., trapping, electrofishing, visual) and replicated eDNA detection/nondetection data via polymerase chain reaction (i.e., PCR or qPCR) from multiple survey locations. Estimated parameters include probability of a false positive eDNA detection, a site-level covariates that scale the sensitivity of eDNA surveys relative to traditional surveys, and catchability coefficients for traditional gear types. Models are implemented with a Bayesian framework (Markov chain Monte Carlo) using the 'Stan' probabilistic programming language.
License: GPL-3
URL: https://github.com/ropensci/eDNAjoint, https://docs.ropensci.org/eDNAjoint
URL: https://github.com/ropensci/eDNAjoint, https://docs.ropensci.org/eDNAjoint/
BugReports: https://github.com/ropensci/eDNAjoint/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE, roclets = c ("namespace", "rd", "srr::srr_stats_roclet"))
Expand Down
6 changes: 3 additions & 3 deletions R/detectionCalculate.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ detectionCalculate <- function(modelfit, mu, cov.val = NULL, probability = 0.9,
sum <- sum(lapply(rstan::get_sampler_params(modelfit,inc_warmup = FALSE),
div_check)[[1]])

warning <- paste0('Warning: There are ',sum,
' divergent transitions in your model fit. ')
print(warning)
warning_msg <- paste0('Warning: There are ',sum,
' divergent transitions in your model fit. ')
warning(warning_msg)

}

Expand Down
4 changes: 2 additions & 2 deletions R/detectionPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ detectionPlot <- function(modelfit, mu.min, mu.max, cov.val = NULL,
sum <- sum(lapply(rstan::get_sampler_params(modelfit,inc_warmup = FALSE),
div_check)[[1]])

warning <- paste0('Warning: There are ',sum,
warning_msg <- paste0('Warning: There are ',sum,
' divergent transitions in your model fit. ')
print(warning)
warning(warning_msg)

}

Expand Down
33 changes: 19 additions & 14 deletions R/jointModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
#'
#' This function implements a Bayesian model that integrates data from paired
#' eDNA and traditional surveys, as described in Keller et al. (2022)
#' <https://doi.org/10.1002/eap.2561>. The model estimates parameters including
#' <doi.org/10.1002/eap.2561>. The model estimates parameters including
#' the expected species catch rate and the probability of false positive eDNA
#' detection. This function allows for optional model variations, like inclusion
#' of site-level covariates that scale the sensitivity of eDNA sampling relative
#' to traditional sampling, as well as estimation of catchability coefficients
#' when multiple traditional gear types are used. Model is implemented using
#' Bayesian inference using the `rstan` package, which uses Hamiltonian Monte
#' Carlo to simulate the posterior distributions. See more examples in the
#' to traditional sampling, as well as estimation of gear scaling coefficients
#' that scales the relative catchability of multiple traditional gear types.
#' Model is implemented using Bayesian inference using the `rstan` package,
#' which uses Hamiltonian Monte Carlo to simulate the posterior distributions.
#' See more examples in the
#' \href{https://bookdown.org/abigailkeller/eDNAjoint_vignette/}{Package
#' Vignette}.
#'
Expand Down Expand Up @@ -55,9 +56,9 @@
#' @param p10priors A numeric vector indicating beta distribution
#' hyperparameters (alpha, beta) used as the prior distribution for the eDNA
#' false positive probability (p10). Default vector is c(1,20).
#' @param q A logical value indicating whether to estimate a catchability
#' coefficient, q, for traditional survey gear types (TRUE) or to not
#' estimate a catchability coefficient, q, for traditional survey gear types
#' @param q A logical value indicating whether to estimate gear scaling
#' coefficients, q, for traditional survey gear types (TRUE) or to not
#' estimate gear scaling coefficients, q, for traditional survey gear types
#' (FALSE). Default value is FALSE.
#' @srrstats {BS1.0,G2.1a,BS1.2} Description of hyperparameters and how to
#' specify prior distributions, explicit documentation of vector input types
Expand Down Expand Up @@ -162,7 +163,7 @@
#' dim(greencrabData$qPCR.N)[1]
#' dim(greencrabData$count)[1]
#'
#' # Fit a model estimating a catchability coefficient for traditional survey
#' # Fit a model estimating a gear scaling coefficient for traditional survey
#' # gear types.
#' # This model does not assume all traditional survey methods have the same
#' # catchability.
Expand Down Expand Up @@ -447,7 +448,7 @@ jointModel <- function(data, cov = NULL, family = 'poisson',
inc_warmup = FALSE),
div_check)[[1]])
# print either troubleshooting or visualization tips
if(div_trans>0){
if(div_trans>0 & verbose){
url <- paste0('https://bookdown.org/abigailkeller/eDNAjoint_vignette/',
'tips.html#troubleshooting-tips')
message <- 'Refer to the eDNAjoint guide for troubleshooting tips: '
Expand Down Expand Up @@ -559,7 +560,8 @@ init_joint_cov <- function(n.chain,qPCR_all,cov,initial_values,
L_match_trad,L_match_dna,data){

# get mu means
mu_means_trad <- as.vector(na.omit(rowMeans(data$count,na.rm=TRUE)+0.01))
mu_means_trad <- as.vector(stats::na.omit(rowMeans(data$count,
na.rm=TRUE)+0.01))
mu_means_all <- rep(NA,dim(L_match_dna)[1]+dim(L_match_trad)[1])
mu_means_all[L_match_trad$L] <- mu_means_trad
if(dim(L_match_dna)[1]>0){
Expand Down Expand Up @@ -618,7 +620,8 @@ init_joint_cov_catchability <- function(n.chain,qPCR_all,q_names,cov,
L_match_dna,data){

# get mu means
mu_means_trad <- as.vector(na.omit(rowMeans(data$count,na.rm=TRUE)+0.01))
mu_means_trad <- as.vector(stats::na.omit(rowMeans(data$count,
na.rm=TRUE)+0.01))
mu_means_all <- rep(NA,dim(L_match_dna)[1]+dim(L_match_trad)[1])
mu_means_all[L_match_trad$L] <- mu_means_trad
if(dim(L_match_dna)[1]>0){
Expand Down Expand Up @@ -684,7 +687,8 @@ init_joint_catchability <- function(n.chain,qPCR_all,q_names,initial_values,
L_match_trad,L_match_dna,data){

# get mu means
mu_means_trad <- as.vector(na.omit(rowMeans(data$count,na.rm=TRUE)+0.01))
mu_means_trad <- as.vector(stats::na.omit(rowMeans(data$count,
na.rm=TRUE)+0.01))
mu_means_all <- rep(NA,dim(L_match_dna)[1]+dim(L_match_trad)[1])
mu_means_all[L_match_trad$L] <- mu_means_trad
if(dim(L_match_dna)[1]>0){
Expand Down Expand Up @@ -749,7 +753,8 @@ init_joint <- function(n.chain,qPCR_all,initial_values,
L_match_trad,L_match_dna,data){

# get mu means
mu_means_trad <- as.vector(na.omit(rowMeans(data$count,na.rm=TRUE)+0.01))
mu_means_trad <- as.vector(stats::na.omit(rowMeans(data$count,
na.rm=TRUE)+0.01))
mu_means_all <- rep(NA,dim(L_match_dna)[1]+dim(L_match_trad)[1])
mu_means_all[L_match_trad$L] <- mu_means_trad
if(dim(L_match_dna)[1]>0){
Expand Down
Loading

0 comments on commit 0252f1a

Please sign in to comment.