Discrete uniform | R Documentation |
dUnif
creates a vector or matrix to be used with the categorical distribution, dcat
, in JAGS to generate a discrete uniform prior.
dUnif(lower, upper)
lower, upper |
Range of the discrete uniform prior. Either scalars, or vectors of the same length. Values are rounded to integers. |
If the arguments are scalar, a vector of length equal to upper
, with the first lower - 1
elements filled with zeros and remainder holding a constant value such that the vector sums to 1.
Otherwise a matrix with each row constructed as above: the columns from lower
to upper
have a constant value, other columns hold zeros. See the examples.
Michael Schaub, Marc Kéry, Mike Meredith
Schaub, M., Kéry, M. (2022) Integrated Population Models, Academic Press, section 5.4.4.
# Both arguments scalar, vector output
(p <- dUnif(lower = 4, upper = 8))
# 0.0 0.0 0.0 0.2 0.2 0.2 0.2 0.2
sum(p)
# Non-integer arguments are rounded
(p <- dUnif(lower = 3.8, upper = 8.2)) # same as above
# Vector arguments, matrix output
(p <- dUnif(lower = c(4, 2, 5), upper = c(8,11,6)))
# [1,] 0 0.0 0.0 0.2 0.2 0.2 0.2 0.2 0.0 0.0 0.0
# [2,] 0 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
# [3,] 0 0.0 0.0 0.0 0.5 0.5 0.0 0.0 0.0 0.0 0.0
rowSums(p) # all 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.