From e5cc9d7132b14c3fe928eb13009b308ec861fc6f Mon Sep 17 00:00:00 2001 From: dochvam Date: Thu, 20 Feb 2020 10:27:37 -0800 Subject: [PATCH 1/2] fix date, fix DHMM double reg, separate dynamic selection of Nmin and Nmax --- DESCRIPTION | 2 +- R/dDHMM.R | 31 ------------------------------- R/dNmixture.R | 11 +++++++---- 3 files changed, 8 insertions(+), 36 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f96d095..8dbf61f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Authors@R: c(person("Benjamin R.", "Goldstein", role = c("aut", "cre"), person("Daniel", "Turek", role = "aut"), person("Lauren", "Ponisio", role = "aut"), person("Perry", "de Valpine", role = "aut")) -Date: 2019-09-24 +Date: 2020-02-20 Description: Common ecological distributions for 'nimble' models in the form of nimbleFunction objects. Includes Cormack-Jolly-Seber, occupancy, dynamic occupancy, hidden Markov, and dynamic hidden Markov models. (Jolly (1965) , Seber (1965) <10.2307/2333827>, Turek et al. (2016) ). diff --git a/R/dDHMM.R b/R/dDHMM.R index af30c35..48c6cb2 100644 --- a/R/dDHMM.R +++ b/R/dDHMM.R @@ -330,34 +330,3 @@ rDHMMo <- nimbleFunction( # } # return(ans) # }) - - - -registerDistributions(list( - dDHMM = list( - BUGSdist = "dDHMM(init, probObs, probTrans, len)", - Rdist = "dDHMM(init, probObs, probTrans, len)", - discrete = TRUE, - types = c('value = double(1)', - 'init = double(1)', - 'probObs = double(2)', - 'probTrans = double(3)', - 'len = double()'), - mixedSizes = TRUE, - pqAvail = FALSE)) - ) - -registerDistributions(list( - dDHMMo = list( - BUGSdist = "dDHMMo(init, probObs, probTrans, len)", - Rdist = "dDHMMo(init, probObs, probTrans, len)", - discrete = TRUE, - types = c('value = double(1)', - 'init = double(1)', - 'probObs = double(3)', - 'probTrans = double(3)', - 'len = double()'), - mixedSizes = TRUE, - pqAvail = FALSE)) - ) - diff --git a/R/dNmixture.R b/R/dNmixture.R index c817b4c..042b33b 100644 --- a/R/dNmixture.R +++ b/R/dNmixture.R @@ -173,11 +173,12 @@ dNmixture_v <- nimbleFunction( ## For each x, the conditional distribution of (N - x | x) is pois(lambda * (1-p)) ## We determine the lowest N and highest N at extreme quantiles and sum over those. - if (Nmin == -1 & Nmax == -1) { + if (Nmin == -1) { Nmin <- min(x + qpois(0.00001, lambda * (1 - prob))) - Nmax <- max(x + qpois(0.99999, lambda * (1 - prob))) } - Nmin <- max( max(x), Nmin ) ## set Nmin to at least the largest x + if (Nmax == -1) { + Nmax <- max(x + qpois(0.99999, lambda * (1 - prob))) + } Nmin <- max( max(x), Nmin ) ## set Nmin to at least the largest x logProb <- -Inf if (Nmax > Nmin) { @@ -217,8 +218,10 @@ dNmixture_s <- nimbleFunction( ## For each x, the conditional distribution of (N - x | x) is pois(lambda * (1-p)) ## We determine the lowest N and highest N at extreme quantiles and sum over those. - if (Nmin == -1 & Nmax == -1) { + if (Nmin == -1) { Nmin <- min(x + qpois(0.00001, lambda * (1 - prob))) + } + if (Nmax == -1) { Nmax <- max(x + qpois(0.99999, lambda * (1 - prob))) } Nmin <- max( max(x), Nmin ) ## set Nmin to at least the largest x From 9d65989f318231d07d41b6b524abd3a235783793 Mon Sep 17 00:00:00 2001 From: dochvam Date: Thu, 20 Feb 2020 10:42:47 -0800 Subject: [PATCH 2/2] Fix syntax glitch in dNmixture --- R/dNmixture.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/dNmixture.R b/R/dNmixture.R index 042b33b..932168c 100644 --- a/R/dNmixture.R +++ b/R/dNmixture.R @@ -178,7 +178,8 @@ dNmixture_v <- nimbleFunction( } if (Nmax == -1) { Nmax <- max(x + qpois(0.99999, lambda * (1 - prob))) - } Nmin <- max( max(x), Nmin ) ## set Nmin to at least the largest x + } + Nmin <- max( max(x), Nmin ) ## set Nmin to at least the largest x logProb <- -Inf if (Nmax > Nmin) {