# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#' Multinomial probability computation for the Multinomial full-conditionals of the latent component memberships
#'
#' The function \code{CompProbZpartial} computes the multinomial probabilities of the Multinomial full-conditionals of the latent component memberships for the Gibbs sampling of a Bayesian mixture of Plackett-Luce models.
#'
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param Y Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of the quantitative latent variables.
#' @param u_bin Binary \eqn{N}\eqn{\times}{x}\eqn{K} matrix indicating whether sample unit \eqn{s} ranked item \eqn{i}.
#' @param n_rank Numeric vector of length \eqn{N} with the number of items ranked by each sample unit.
#' @param omega Numeric vector of the \eqn{G} mixture weights.
#' @return Numeric \eqn{N}\eqn{\times}{x}\eqn{G} matrix of multinomial probabilities.
CompProbZpartial <- function(p, pi_inv, Y, u_bin, n_rank, omega) {
.Call(`_PLMIX_CompProbZpartial`, p, pi_inv, Y, u_bin, n_rank, omega)
}
#' Rate parameter computation for the Gamma full-conditionals of the support parameters
#'
#' The function \code{CompRateP} computes the rate parameters of the Gamma full-conditionals of the support parameters for the Gibbs sampling of a Bayesian mixture of Plackett-Luce models.
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param Y Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of the quantitative latent variables.
#' @param z Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of binary component memberships.
#' @param u_bin Binary \eqn{N}\eqn{\times}{x}\eqn{K} matrix indicating whether sample unit \eqn{s} ranked item \eqn{i}.
#' @param n_rank Numeric vector of length \eqn{N} with the number of items ranked by each sample unit.
#' @param rate0 Numeric vector of \eqn{G} rate hyperparameters.
#' @return Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of rate parameters.
CompRateP <- function(pi_inv, Y, z, u_bin, n_rank, rate0) {
.Call(`_PLMIX_CompRateP`, pi_inv, Y, z, u_bin, n_rank, rate0)
}
#' Rate parameter computation for the Exponential full-conditionals of the quantitative latent variables
#'
#' The function \code{CompRateYpartial} computes the rate parameters of the Exponential full-conditionals of the quantitative latent variables for the Gibbs sampling of a Bayesian mixture of Plackett-Luce models.
#'
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param z Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of binary component memberships.
#' @param n_rank Numeric vector of length \eqn{N} with the number of items ranked by each sample unit.
#' @return Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of rate parameters.
CompRateYpartial <- function(p, pi_inv, ref_order, z, n_rank) {
.Call(`_PLMIX_CompRateYpartial`, p, pi_inv, ref_order, z, n_rank)
}
#' E-step in the EM algorithm for MAP estimation of a Bayesian mixture of Plackett-Luce models
#'
#' The function \code{Estep} updates the posterior component membership probabilities in the EM algorithm for MAP estimation of a Bayesian mixture of Plackett-Luce models.
#'
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @return Numeric \eqn{N}\eqn{\times}{x}\eqn{G} matrix of estimated posterior component membership probabilities.
Estep <- function(p, ref_order, weights, pi_inv) {
.Call(`_PLMIX_Estep`, p, ref_order, weights, pi_inv)
}
#' Random generation from a finite mixture of Plackett-Luce models and subsequent censoring
#'
#' Random generation from a finite mixture of Plackett-Luce models and subsequent censoring according to a given partial ordering matrix.
#'
#' @param N Number of sample units.
#' @param K Number of possible items.
#' @param G Number of mixture components.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @param rankingFormat Logical: whether the final simulated data should be expressed in ranking format.
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings (to replicate the observed missingness patterns).
#' @return Numeric \eqn{N}\eqn{\times}{x}\eqn{G} matrix of simulated data (default is in ordering format) with the same missingness patterns of \code{pi_inv}.
PLMIXsim <- function(N, K, G, p, ref_order, weights, rankingFormat, pi_inv) {
.Call(`_PLMIX_PLMIXsim`, N, K, G, p, ref_order, weights, rankingFormat, pi_inv)
}
#' Gibbs sampling of the quantitative latent variables
#'
#' The function \code{CompRateYpartial} simulates from the Exponential full-conditionals of the quantitative latent variables for the Gibbs sampling of a Bayesian mixture of Plackett-Luce models.
#'
#' @param rate Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of rate parameters.
#' @param n_rank Numeric vector of length \eqn{N} with the number of items ranked by each sample unit.
#' @return Numeric \eqn{N}\eqn{\times}{x}\eqn{K} matrix of posterior samples of the quantitative latent variables.
SimYpsilon <- function(rate, n_rank) {
.Call(`_PLMIX_SimYpsilon`, rate, n_rank)
}
#' M-step for the support parameters of a Bayesian mixture of Plackett-Luce models
#'
#' The function \code{UpPhetpartial} updates the support parameter estimates in the EM algorithm for MAP estimation of a Bayesian mixture of Plackett-Luce models.
#'
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param u_bin Binary \eqn{N}\eqn{\times}{x}\eqn{K} matrix indicating whether sample unit \eqn{s} ranked item \eqn{i}.
#' @param z_hat Numeric \eqn{N}\eqn{\times}{x}\eqn{G} matrix of posterior component membership probabilities.
#' @param shape0 Numeric \eqn{G}\eqn{\times}{x}{K} matrix of shape hyperparameters.
#' @param rate0 Numeric vector of \eqn{G} rate hyperparameters.
#' @param n_rank Numeric vector of length \eqn{N} with the number of items ranked by each sample unit.
#' @return Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of estimated component-specific support parameters.
UpPhetpartial <- function(p, ref_order, pi_inv, u_bin, z_hat, shape0, rate0, n_rank) {
.Call(`_PLMIX_UpPhetpartial`, p, ref_order, pi_inv, u_bin, z_hat, shape0, rate0, n_rank)
}
#' M-step for the weights of a Bayesian mixture of Plackett-Luce models
#'
#' The function \code{UpWhet} updates the mixture weight estimates in the EM algorithm for MAP estimation of a Bayesian mixture of Plackett-Luce models
#'
#' @param z_hat Numeric \eqn{N}\eqn{\times}{x}\eqn{G} matrix of posterior component membership probabilities.
#' @param alpha0 Numeric vector of \eqn{G} Dirichlet hyperparameters.
#' @return Numeric vector of the \eqn{G} estimated mixture weights.
UpWhet <- function(z_hat, alpha0) {
.Call(`_PLMIX_UpWhet`, z_hat, alpha0)
}
#' Chi-squared index relying on paired comparisons for observed data
#'
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @return Chi-squared index value.
chisqmeasureobs <- function(pi_inv, p, weights) {
.Call(`_PLMIX_chisqmeasureobs`, pi_inv, p, weights)
}
#' Chi-squared index relying on top1 preferences for observed data
#'
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @return Chi-squared index value.
chisqmeasureobs1dim <- function(pi_inv, p, weights) {
.Call(`_PLMIX_chisqmeasureobs1dim`, pi_inv, p, weights)
}
#' Conditional Chi-squared index relying on paired comparisons for observed data
#'
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @return Conditional Chi-squared index value.
chisqmeasureobscond <- function(pi_inv, p, weights) {
.Call(`_PLMIX_chisqmeasureobscond`, pi_inv, p, weights)
}
#' Generic term of the conditional Chi-squared index relying on top1 preferences for observed data
#'
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @return Numeric \eqn{K}\eqn{\times}{x}\eqn{K} matrix of the conditional Chi-squared index.
chisqmeasureobsmatrix1dim <- function(pi_inv, p, weights) {
.Call(`_PLMIX_chisqmeasureobsmatrix1dim`, pi_inv, p, weights)
}
#' Chi-squared index relying on paired comparisons for replicated data
#'
#'
#' @param N Number of sample units.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @param pi_inv_obs Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings (to replicate the observed missingness patterns).
#' @return Chi-squared index value.
chisqmeasuretheo <- function(N, ref_order, p, weights, pi_inv_obs) {
.Call(`_PLMIX_chisqmeasuretheo`, N, ref_order, p, weights, pi_inv_obs)
}
#' Chi-squared index relying on top1 preferences for replicated data
#'
#'
#' @param N Number of sample units.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @param pi_inv_obs Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings (to replicate the observed missingness patterns).
#' @return Chi-squared index value.
chisqmeasuretheo1dim <- function(N, ref_order, p, weights, pi_inv_obs) {
.Call(`_PLMIX_chisqmeasuretheo1dim`, N, ref_order, p, weights, pi_inv_obs)
}
#' Conditional Chi-squared index relying on paired comparisons for replicated data
#'
#'
#' @param N Number of sample units.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @param pi_inv_obs Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings (to replicate the observed missingness patterns).
#' @return Conditional Chi-squared index value.
chisqmeasuretheocond <- function(N, ref_order, p, weights, pi_inv_obs) {
.Call(`_PLMIX_chisqmeasuretheocond`, N, ref_order, p, weights, pi_inv_obs)
}
#' Generic term of the conditional Chi-squared index relying on top1 preferences for replicated data
#'
#'
#' @param N Number of sample units.
#' @param ref_order Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific reference orders.
#' @param p Numeric \eqn{G}\eqn{\times}{x}\eqn{K} matrix of component-specific support parameters.
#' @param weights Numeric vector of the \eqn{G} mixture weights.
#' @param pi_inv_obs Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings (to replicate the observed missingness patterns).
#' @return Numeric \eqn{K}\eqn{\times}{x}\eqn{K} matrix of the conditional Chi-squared index.
chisqmeasuretheomatrix1dim <- function(N, ref_order, p, weights, pi_inv_obs) {
.Call(`_PLMIX_chisqmeasuretheomatrix1dim`, N, ref_order, p, weights, pi_inv_obs)
}
#' Counts how many items are ranked in a partial ranking matrix
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @return Numeric vector of length \eqn{N} with the number of items ranked by each sample unit
#' @export
howmanyranked <- function(pi_inv) {
.Call(`_PLMIX_howmanyranked`, pi_inv)
}
#' @rdname loglikelihood
#' @export
loglikPLMIX <- function(p, ref_order, weights, pi_inv) {
.Call(`_PLMIX_loglikPLMIX`, p, ref_order, weights, pi_inv)
}
#' Weighted sampling without replacement from a finite urn
#'
#'
#' @param n Number of distinct integer-labeled balls in the urn.
#' @param size Number of balls sampled without replacement.
#' @param prob Numeric vector of length \eqn{n} probability masses assigned to each ball.
#'
#' @return vector
quickintsample <- function(n, size, prob) {
.Call(`_PLMIX_quickintsample`, n, size, prob)
}
#' Compute paired comparison matrix for a partial ordering dataset
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#'
#' @return The \eqn{K}\eqn{\times}{x}\eqn{K} paired comparison matrix: number of times that item \eqn{i} is preferred to item \eqn{i'}.
tau <- function(pi_inv) {
.Call(`_PLMIX_tau`, pi_inv)
}
#' Computation top1 frequencies conditionally on the number of ranked items
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#' @return Numeric \eqn{K}\eqn{\times}{x}\eqn{K} matrix of top1 frequencies.
top1freq1dim <- function(pi_inv) {
.Call(`_PLMIX_top1freq1dim`, pi_inv)
}
#' Binary matrix detailing the items ranked by each sample unit
#'
#' The function \code{umat} returns a binary matrix whose elements indicate which items has been ranked by each sample unit.
#'
#' @param pi_inv Numeric \eqn{N}\eqn{\times}{x}\eqn{K} data matrix of partial orderings.
#'
#' @return Binary \eqn{N}\eqn{\times}{x}\eqn{K} matrix indicating whether sample unit \eqn{s} ranked item \eqn{i}.
umat <- function(pi_inv) {
.Call(`_PLMIX_umat`, pi_inv)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.