Ops.hyper2.Rd
Allows arithmetic operators “+
”, “*
” and
comparison operators “==
” and “!=
”, to be
used for hyper2 objects.
Specifically, H1 + H2
implements addition of two log-likelihood
functions, corresponding to incorporation of additional independent
observational data; and n*H1
implements H1+H1+...+H1
,
corresponding to repeated independent observations of the same data.
There are no unary operations for this class.
# S3 method for class 'hyper2'
Ops(e1, e2 = NULL)
# S3 method for class 'hyper2'
sum(x,...,na.rm=FALSE)
hyper2_add(e1,e2)
hyper2_sum_numeric(H,r)
Objects of class hyper2
, here interpreted as
hyperdirichlet distributions
In the sum()
method, objects to be summed;
na.rm
is currently ignored
In function hyper2_sum_numeric()
, object H
is
a hyper2
object and r
is a length-one real vector (a
number)
If two independent datasets have hyper2
objects H1
and
H2
, then package idiom for combining these would be H1+H2
;
the additive notation “+
” corresponds to addition of the
support (or multiplication of the likelihood). So hyper2
objects are better thought of as support functions than likelihood
functions; this is reflected in the print method which explicitly
wraps the likelihood function in a “log()
”.
Idiom H1-H1
returns H1 + (-1)*H2
, useful for investigating
the difference between likelihood functions arising from two different
observations, or different probability models. An example is given in
inst/soling.Rmd
.
Testing for equality is not straightforward for two implementation
reasons. Firstly, the object itself is stored internally as a
stl
map
, which does not store keys in any particular
order; and secondly, the stl
set
class is used for the
brackets. A set does not include information about the order of its
elements; neither does it admit repeated elements. See examples.
Function hyper2_sum_numeric()
is defined so that idiom like
icons["L"] + 5
works as expected. This means that
icons["L"] <- icons["L"] + 3
and icons["L"] %<>%inc(3)
work (without this, one has to type icons["L"] <-
powers(icons["L"]) + 3
, which sucks).
Raising a hyper2
object to a power returns an error.
Returns a hyper2
object or a Boolean.
chess2 <- hyper2(list("Kasparov","Karpov",c("Kasparov","Karpov")),c(2,3,-5))
chess + chess2
#> log(Anand^36 * (Anand + Karpov)^-35 * (Anand + Topalov)^-35 * Karpov^25
#> * (Karpov + Kasparov)^-5 * (Karpov + Topalov)^-18 * Kasparov^2 *
#> Topalov^30)
maxp(chess+chess2)
#> Anand Karpov Kasparov Topalov
#> 0.2909338 0.2185857 0.1456525 0.3448280