| MB {MM} | R Documentation |
Multivariate multiplicative binomial distribution
Description
Various utilities to coerce and manipulate MB objects
Usage
MB(dep, m, pnames=character(0))
## S3 method for class 'MB'
as.array(x, ...)
## S4 method for signature 'MB'
getM(x)
## S3 method for class 'gunter_MB'
print(x, ...)
Arguments
dep |
Primary argument to |
m |
Vector containing the relative sizes of the various marginal binomial distributions |
x |
Object of class |
... |
Further arguments to |
pnames |
In function |
Details
Function MB() returns an object of class MB. This is
essentially a matrix with one row corresponding to a single
observation; repeated rows indicate identical observations as shown
below. Observational data is typically in this form. The idea is
that the user can coerce to a gunter_MB object, which is then
analyzable by Lindsey().
The multivariate multiplicative binomial distribution is defined by \[ \prod_{i=1}^t {m_i\choose x_i\, z_i}p_i^{x_i}q_i^{z_i}\theta_i^{x_iz_i} \prod_{i < j}\phi_{ij}^{x_ix_j} \]
Thus if \(\theta=\phi=1\) the system reduces to a product of independent binomial distributions with probability \(p_i\) and size \(m_i\) for \(i=1,\ldots,t\).
There follows a short R transcript showing the MB class in use,
with annotation.
The first step is to define an m vector:
R> m <- c(2,3,1)
This means that \(m_1=2,m_2=3,m_3=1\). So \(m_1=2\) means that \(i=1\) corresponds to a binomial distribution with size 2 [that is, the observation is in the set \({0,1,2}\)]; and \(m_2=3\) means that \(i=2\) corresponds to a binomial with size 3 [ie the set \({0,1,2,3}\)].
Now we need some observations:
R> a <- matrix(c(1,0,0, 1,0,0, 1,1,1, 2,3,1, 2,0,1),5,3,byrow=T)
R> a
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 1 0 0
[3,] 1 1 1
[4,] 2 3 1
[5,] 2 0 1
In matrix a, the first observation, viz c(1,0,0) is
interpreted as \(x_1=1,x_2=0,x_3=0\). Thus, because
\(x_i+z_i=m_i\), we have \(z_1=1,z_2=3,z_3=1\). Now
we can create an object of class MB, using function MB():
R> mx <- MB(a, m, letters[1:3])
The third argument gives names to the observations corresponding to the
columns of a. The values of \(m_1, m_2, m_3\) may
be extracted using getM():
R> getM(mx) a b c 2 3 1 R>
The getM() function returns a named vector, with names
given as the third argument to MB().
Now we illustrate the print method:
R> mx
a na b nb c nc
[1,] 1 1 0 3 0 1
[2,] 1 1 0 3 0 1
[3,] 1 1 1 2 1 0
[4,] 2 0 3 0 1 0
[5,] 2 0 0 3 1 0
R>
See how the columns are in pairs: the first pair total 2 (because \(m_1=2\)), the second pair total 3 (because \(m_2=3\)), and the third pair total 1 (because \(m_3=1\)). Each pair of columns has only a single degree of freedom, because \(m_i\) is known.
Also observe how the column names are in pairs. The print method puts
these in place. Take the first two columns. These are named
‘a’ and ‘na’: this is intented to mean
‘a’ and ‘not a’.
We can now coerce to a gunter_MB:
R> (gx <- gunter(mx)) $tbl a b c 1 0 0 0 2 1 0 0 3 2 0 0 [snip] 24 2 3 1 $d [1] 0 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 $m a b c 2 3 1
Take the second line of the element tbl of gx, as an
example. This reads c(1,0,0) corresponding to the observations
of a,b,c respectively, and the second line of element d
[“d” for “data”], viz 2, shows that this
observation occurred twice (and in fact these were the first two lines
of a).
Now we can coerce object mx to an array:
R> (ax <- as.array(mx)) , , c = 0 b a 0 1 2 3 0 0 0 0 0 1 0 0 2 0 2 0 0 0 0 , , c = 1 b a 0 1 2 3 0 0 1 0 0 1 0 0 0 0 2 1 1 0 0 >
(actually, ax is an Oarray object). The location of an
element in ax corresponds to an observation of abc, and
the entry corresponds to the number of times that observation was made.
For example, ax[1,2,0]=2 shows that c(1,2,0) occurred
twice (the first two lines of a).
The Lindsey Poisson device is applicable: see help(danaher) for
an application to the bivariate case and help(Lindsey) for an
example where a table is created from scratch.
Author(s)
Robin K. S. Hankin
See Also
Examples
a <- matrix(c(1,0,0, 1,0,0, 1,1,1, 2,3,1, 2,0,1),5,3,byrow=TRUE)
m <- c(2,3,1)
mx <- MB(a, m, letters[1:3]) # mx is of class 'MB'; column headings
# mean "a" and "not a".
ax <- as.array(mx)
gx <- gunter(ax)
ax2 <- as.array(gx)
data(danaher)
summary(Lindsey_MB(danaher))