suplist.Rd
Basic functionality for lists of hyper2
objects, allowing the
user to concatenate independent observations which are themselves
composite objects such as returned by ggrl()
.
Objects of class suplist
, here interpreted as
a list of possible likelihood functions (who should be added)
In the sum()
method, objects to be summed;
na.rm
is currently ignored
A list of hyper2
objects
A suplist
object is a list of hyper2
objects. Each
element is a hyper2
object that is consistent with an
incomplete rank observation \(R\); the list elements are exclusive
and exhaustive for \(R\). If S
is a suplist
object,
and S=list(H1,H2,...,Hn)
where the Hi
are hyper2
objects, then
\(\mbox{Prob}(p|H_1)+\cdots+\mbox{Prob}(p|H_n)\).
This is because the elements of a suplist
object are disjoint
alternatives.
It is incorrect to say that a likelihood function \(\mathcal{L}_S(p)\) for \(p\) is the sum of separate likelihood functions. This is incorrect because the arbitrary multiplicative constant messes up the math, for example we might have \(\mathcal{L}_{H_1}(p)=C_1\mathrm{Prob}(p|H_1)\) and \(\mathcal{L}_{H_2}(p)=C_2\mathrm{Prob}(p|H_2)\) and indeed \(\mathcal{L}_{{H_1}\cup H_2}(p)=C_{12}\left(\mathrm{Prob}(p|H_1)+\mathrm{Prob}(p|H_2)\right)\) but
$$\mathcal{L}_{H_1}(p)+\mathcal{L}_{H_2}(p) \neq C_1\mathrm{Prob}(p|H_1)+C_2\mathrm{Prob}(p|H_2)$$
(the right hand side is meaningless).
Functions suplist_add()
and sum.suplist()
implement
“S1+S2
” as the support function for independent
observations S1
and S2
. The idea is that the support
functions “add” in the following sense. If
S1=list(H1,...,Hr)
and S2=list(I1,...,Is)
where
Hx,Ix
are hyper2
objects, then the likelihood function
for “S1+S2
” is the likelihood function for S1
followed by (independent) S2
. Formally
$$ \mbox{Prob}(p|S_1+S_2) = \left( \mbox{Prob}(p|H_1) +\cdots+ \mbox{Prob}(p|H_r) \right)\cdot\left( \mbox{Prob}(p|I_1) +\cdots+ \mbox{Prob}(p|I_s) \right)$$
$$ \log\mbox{Prob}(p|S_1+S_2) = \log\left( \mbox{Prob}(p|H_1) +\cdots+ \mbox{Prob}(p|H_r) \right)+\log\left( \mbox{Prob}(p|I_1) +\cdots+ \mbox{Prob}(p|I_s) \right)$$
However, S1+S2
is typically a large and unwieldy object, and
can be very slow to evaluate. These functions are here because they
provide slick package idiom.
The experimental lsl
mechanism furnishes an alternative
methodology which is more computationally efficient at the expense of
a non-explicit likelihood function. It is not clear at present (2022)
which of the two systems is better.
Returns a suplist
object.
W <- hyper2(pnames=letters[1:5])
W1 <- ggrl(W, 'a', letters[2:3],'d') # 2-element list
W2 <- ggrl(W, 'e', letters[1:3],'d') # 6-element list
W3 <- ggrl(W, 'c', letters[4:5],'a') # 2-element list
# likelihood function for independent observations W1,W2,W3:
W1+W2+W3 # A 2*6*2=24-element list
#> [[1]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c + d)^-2 * c^3 * (c +
#> d)^-2 * d * e^2)
#>
#> [[2]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c + d)^-2 * (b + d)^-1
#> * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[3]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c + d)^-2 * (b + d)^-1
#> * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[4]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c + d)^-2 * (b + d)^-2
#> * c^3 * d * e^2)
#>
#> [[5]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c +
#> d)^-1 * c^3 * (c + d)^-2 * d * e^2)
#>
#> [[6]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[7]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 *
#> (b + c + d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[8]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 *
#> (b + c + d)^-1 * (b + d)^-1 * c^3 * d * e^2)
#>
#> [[9]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[10]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-2 * c^3 * d * e^2)
#>
#> [[11]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 *
#> (b + c + d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[12]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * (a + e)^-1 * b^2 *
#> (b + c + d)^-1 * (b + d)^-1 * c^3 * d * e^2)
#>
#> [[13]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c + d)^-2 * c^3 * (c +
#> d)^-2 * d * e^2)
#>
#> [[14]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c + d)^-2 * (b + d)^-1
#> * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[15]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c + d)^-2 * (b + d)^-1
#> * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[16]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d +
#> e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c + d)^-2 * (b + d)^-2
#> * c^3 * d * e^2)
#>
#> [[17]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * c^3 * (c + d)^-2 * d * e^2)
#>
#> [[18]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[19]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-2 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[20]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + c + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-2 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-1 * c^3 * d * e^2)
#>
#> [[21]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[22]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-1 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-2 * c^3 * d * e^2)
#>
#> [[23]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-2 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * c^3 * (c + d)^-1 * d * e^2)
#>
#> [[24]]
#> log(a^2 * (a + b + c + d)^-2 * (a + b + c + d + e)^-1 * (a + b + d)^-1
#> * (a + c + d + e)^-1 * (a + d)^-2 * (a + d + e)^-1 * b^2 * (b + c +
#> d)^-1 * (b + d)^-1 * c^3 * d * e^2)
#>
#> attr(,"class")
#> [1] "list" "suplist"
like_single_list(equalp(W),W1+W2+W3)
#> [1] 0.0003472222
if (FALSE) dotchart(maxplist(W1+W1+W3),pch=16) # \dontrun{} # takes a long time
a <- lsl(list(W1,W2,W3),4:6) # observe W1 four times, W2 five times and W3 six times
loglik_lsl(equalp(W),a,log=TRUE)
#> [1] -39.82773