-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from AngusMcLure/period-sampling
Period sampling
- Loading branch information
Showing
16 changed files
with
789 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,6 @@ RoxygenNote: 7.2.3 | |
Imports: | ||
glue, | ||
hypergeo, | ||
purrr | ||
purrr, | ||
distributions3, | ||
dplyr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(design_effect) | ||
export(design_effect_random) | ||
export(fi_pool) | ||
export(fi_pool_cluster) | ||
export(fi_pool_cluster_random) | ||
export(fi_pool_random) | ||
export(nb_catch) | ||
export(optimise_random_prevalence) | ||
export(optimise_sN_prevalence) | ||
export(optimise_s_prevalence) | ||
export(pois_catch) | ||
export(pool_max_size) | ||
export(pool_target_number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#' Tools for defining catch-size distributions | ||
#' | ||
#' `nb_catch()` and `pois_catch()` are convenience functions for defining the | ||
#' distribution of catche sizes (aka cluster sizes) for the negative binomial | ||
#' and Poisson distributions respectively | ||
#' | ||
#' @param mean numeric The mean number of units per cluster (catch) | ||
#' @param variance numeric The variance of the number of units per cluster | ||
#' (catch) | ||
#' | ||
#' @return An object of class `distr` summarising the distribution of | ||
#' cluster/catch sizes | ||
#' @rdname catch_distributions | ||
#' @export | ||
#' | ||
#' @examples | ||
#' nb_catch(10,20) | ||
#' | ||
#' pois_catch(10) | ||
|
||
nb_catch <- function(mean,variance){ | ||
if(mean>variance){stop('variance must be greater than or equal to mean')} | ||
distributions3::NegativeBinomial(size = mean^2/(variance - mean), p = mean/variance) | ||
} | ||
|
||
#' @rdname catch_distributions | ||
#' @export | ||
pois_catch <- function(mean){ | ||
distributions3::Poisson(lambda = mean) | ||
} | ||
|
||
## Functions for implementing common pooling strategies | ||
|
||
|
||
|
||
# ## No longer actually used: but this help you multiply out the product over k of | ||
# ## (1-(1-p)^s_k)^y_k as polynomial in (1-p) which lets you write out likelihood | ||
# ## in terms of sums of beta functions. The output is the coefficients of the | ||
# ## polynomial starting at c_0 | ||
# det_poly <- function(s,y){ | ||
# if(length(s) != length(y) || !all((c(s,y) %% 1) == 0)){ | ||
# stop('s and y must be integer vectors of common length') | ||
# } | ||
# | ||
# K <- length(s) | ||
# out <- 1 | ||
# for(k in 1:K){ | ||
# out <- out * polynom::polynomial(c(1,rep(0,s[k]-1),-1))^y[k] | ||
# } | ||
# coef(out) | ||
# } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.