count_multinom {multinomineq} | R Documentation |
Count How Many Samples Satisfy Linear Inequalities (Multinomial)
Description
Draws prior/posterior samples for product-multinomial data and counts how many samples are
inside the convex polytope defined by
(1) the inequalities A*x <= b
or
(2) the convex hull over the vertices V.
Usage
count_multinom(
k = 0,
options,
A,
b,
V,
prior = rep(1, sum(options)),
M = 5000,
steps,
start,
cmin = 0,
maxiter = 500,
burnin = 5,
progress = TRUE,
cpu = 1
)
Arguments
k |
the number of choices for each alternative ordered by item type (e.g.
|
options |
number of observable categories/probabilities for each item
type/multinomial distribution, e.g., |
A |
a matrix defining the convex polytope via |
b |
a vector of the same length as the number of rows of |
V |
a matrix of vertices (one per row) that define the polytope of
admissible parameters as the convex hull over these points
(if provided, |
prior |
the prior parameters of the Dirichlet-shape parameters.
Must have the same length as |
M |
number of posterior samples drawn from the encompassing model |
steps |
an integer vector that indicates the row numbers at which the matrix |
start |
only relevant if |
cmin |
if |
maxiter |
if |
burnin |
number of burnin samples per step that are discarded. Since the
maximum-likelihood estimate is used as a start value (which is updated for each step in
the stepwise procedure in |
progress |
whether a progress bar should be shown (if |
cpu |
either the number of CPUs used for parallel sampling, or a parallel
cluster (e.g., |
Value
a list with the elements
a matrix with the columns
count
: number of samples in polytope / that satisfy order constraintsM
: the total number of samples in each stepsteps
: the"steps"
used to sample from the polytope (i.e., the row numbers ofA
that were considered stepwise)
with the attributes:
proportion
: estimated probability that samples are in polytopese
: standard error of probability estimate
References
Hoijtink, H. (2011). Informative Hypotheses: Theory and Practice for Behavioral and Social Scientists. Boca Raton, FL: Chapman & Hall/CRC.
See Also
Examples
### frequencies:
# (a1,a2,a3, b1,b2,b3,b4)
k <- c(1, 5, 9, 5, 3, 7, 8)
options <- c(3, 4)
### linear order constraints
# a1<a2<a3 AND b2<b3<.50
# (note: a2<a3 <=> a2 < 1-a1-a2 <=> a1+2*a2 < 1)
# matrix A:
# (a1,a2, b1,b2,b3)
A <- matrix(
c(
1, -1, 0, 0, 0,
1, 2, 0, 0, 0,
0, 0, 0, 1, -1,
0, 0, 0, 0, 1
),
ncol = sum(options - 1), byrow = TRUE
)
b <- c(0, 1, 0, .50)
# count prior and posterior samples and get BF
prior <- count_multinom(0, options, A, b, M = 2e4)
posterior <- count_multinom(k, options, A, b, M = 2e4)
count_to_bf(posterior, prior)
bf_multinom(k, options, A, b, M = 10000)
bf_multinom(k, options, A, b, cmin = 5000, M = 1000)