Learn R Programming

mcmcsae (version 0.8.1)

f_multinomial: Specify a multinomial sampling distribution

Description

This function can be used in the family argument of create_sampler or generate_data to specify a multinomial sampling distribution. This includes the special case of categorical (multinoulli) data.

Usage

f_multinomial(
  link = "logit",
  n.trial = NULL,
  K = NULL,
  control = multinomial_control()
)

Value

A family object.

Arguments

link

the name of a link function. Currently the only allowed link function for the multinomial distribution is "logit".

n.trial

the number of multinomial trials. This can be specified either as a formula for a variable number of trials, or as a scalar value for a common number of trials for all units.

K

number of categories for multinomial model; only used for prior predictive sampling.

control

a list with computational options. These options can be specified using function multinomial_control.

Details

For the multinomial family, the left hand side of the formula argument of create_sampler can be specified in one of the following ways:

1

as a single factor, character, boolean or integer variable, say y. The categories then correspond to the levels of as.factor(y). This option can only be used for categorical data.

2

as a n x (K-1) numeric matrix with values between 0 and 1, where n is the number of observations and K the number of categories. The values are interpreted as proportions of observations in each category. This requires specifying the number of multinomial trials through argument n.trial.

3

a K-column integer matrix, where K is the number of categories, each column containing the number of 'successes' for the corresponding category.

Examples

Run this code
y <- factor(sample(c("a", "b", "c"), 800, prob=c(0.3, 0.5, 0.2), replace=TRUE))
sampler <- create_sampler(y ~ 0 + cat_, family=f_multinomial())
sim <- MCMCsim(sampler, n.chain=2, burnin=200, n.iter=300, verbose=FALSE)
summary(sim)
summary(predict(sim, newdata=data.frame(id=1:5)))

Run the code above in your browser using DataLab