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 hyper2
Ops(e1, e2 = NULL)
# S3 method for hyper2
sum(x,...,na.rm=FALSE)
hyper2_add(e1,e2)
hyper2_sum_numeric(H,r)
Returns a hyper2
object or a Boolean.
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)
Robin K. S. Hankin
If two independent datasets have hyper2
objects H1
and
H2
, then the R 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).
chess2 <- hyper2(list("Kasparov","Karpov",c("Kasparov","Karpov")),c(2,3,-5))
chess + chess2
maxp(chess+chess2)
Run the code above in your browser using DataLab