dbinom_vector {nimbleSCR}R Documentation

Vectorized binomial distribution

Description

The dbinom_vector distribution is a vectorized version of the binomial distribution. It can be used to model a vector of binomial realizations. NB: using the vectorized version is beneficial only when the entire joint likelihood of the vector of binomial realizations (x) is calculated simultaneously.

Usage

dbinom_vector(x, size, prob, log = 0)

rbinom_vector(n = 1, size, prob)

Arguments

x

Vector of quantiles.

size

Vector of number of trials (zero or more).

prob

Vector of success probabilities on each trial

log

Logical argument, specifying whether to return the log-probability of the distribution.

n

Number of observations. Only n = 1 is supported.

Value

The log-likelihood value associated with the vector of binomial observations.

Author(s)

Pierre Dupont

Examples

## define vectorized model code
code <- nimbleCode({
    p ~ dunif(0,1)
    p_vector[1:J] <- p
    y[1:J] ~ dbinom_vector(size = trials[1:J],
                           prob = p_vector[1:J])
})
 
## simulate binomial data
J <- 1000
trials <- sample(x = 10, size = J, replace = TRUE)
y <- rbinom_vector(J, size = trials, prob = 0.21)
 
constants <- list(J = J, trials = trials)
 
data <- list(y = y)
 
inits <- list(p = 0.5)
 
## create NIMBLE model object
Rmodel <- nimbleModel(code, constants, data, inits)
 
## use model object for MCMC, etc.


[Package nimbleSCR version 0.2.1 Index]