# Testing the hypothesis of a population size being greater than 5 individuals
# per sampling unit (H: mu > 5). The sequential sampling is made of 5 sampling
# bouts made of one sample each.
set.seed(101)
counts3 <- rpois(5, lambda = 3)
test1F <- stbp_composite(data = counts3,
greater_than = TRUE,
hypothesis = 5,
density_func = "poisson",
prior = 0.5,
lower_bnd = 0,
upper_bnd = Inf,
lower_criterion = 0.001,
upper_criterion = 0.999)
test1F
# returns "reject H".
# Testing the hypothesis of a sampled population being greater than trajectory H
H <- c(2, 5, 10, 20, 40, 40, 20, 10, 5, 2)
# Generating sequential samples (n = 3) from a population that is 1 below H
# (H - 1)
countP <- matrix(NA, 3, 10)
set.seed(101)
for(i in 1:10){
countP[, i] <- rpois(3, lambda = (H[i] - 1))
}
# Running STBP on the sample
test2F <- stbp_composite(data = countP,
greater_than = TRUE,
hypothesis = H,
density_func = "poisson",
prior = 0.5,
lower_bnd = 0,
upper_bnd = Inf,
lower_criterion = 0.001,
upper_criterion = 0.999)
test2F
# returns "reject H".
# Testing the hypothesis of a proportion of infested units being greater than
# 20% per sampling unit (H: mu > 0.2). The sequential sampling is made of 7
# sampling bouts each with 5 clusters of 10 samples from which binomial
# observations are recorded.
set.seed(101)
# binomial data generated with mu (prob) 0.05 over the hypothesized
# value (0.2)
counts4 <- list()
for(i in 1: 7) {
counts4[[i]] <- matrix(c(rbinom(5, size = 10, prob = 0.25), rep(10, 5)),
5, 2)
}
# Run the test. Notice that upper_bnd = 1!
test3F <- stbp_composite(data = counts4,
greater_than = TRUE,
hypothesis = 0.2,
density_func = "binomial",
prior = 0.5,
lower_bnd = 0,
upper_bnd = 1,
lower_criterion = 0.001,
upper_criterion = 0.999)
test3F # returns accept H after 3 sampling bouts
# Assuming a negative binomial count variable whose overdispersion parameter,
# k, varies as a function of the mean, and that the variance-mean relationship
# is well described with Taylor's Power Law, a function to obtain k can be:
estimate_k <- function(mean) {
a = 1.830012
b = 1.218041 # a and b are Taylor's Power Law parameters
(mean^2) / ((a * mean^(b)) - mean)
}
# Generate some counts to create an STBP object with the model specifications
counts3 <- rnbinom(20, mu = 5, size = estimate_k(5))
# Run the test to create the STBP object
test1F <- stbp_composite(data = counts3,
greater_than = TRUE,
hypothesis = 9,
density_func = "negative binomial",
overdispersion = "estimate_k",
prior = 0.5,
lower_bnd = 0,
upper_bnd = Inf,
lower_criterion = 0.01,
upper_criterion = 0.99)
test1F
## End (Not run)
Run the code above in your browser using DataLab