loglik.Rd
Returns a log-likelihood for a given hyper2
or hyper3
object at a specific point in probability space
loglik(p, H, log = TRUE)
loglik_single(p,H,log=TRUE)
like_single_list(p,Lsub)
like_series(p,L,log=TRUE)
Function loglik()
is a straightforward likelihood function. It
can take a vector of length n=size(H)
or size(H)-1
. If
given the vector
\(p=\left(p_1,\ldots,p_{n-1}\right)\) it
appends the fillup value, and then returns returns the (log)
likelihood (names are discarded in this case). If given a vector
\(p=\left(p_1,\ldots,p_{n}\right)\) [notionally
summing to 1] it requires a named vector, and names must match those
of H
. The vector is reordered if necessary.
If p
is a matrix, the rows are interpreted as probability
points.
Function loglik_single()
is a helper function that takes a
single point in probability space. Functions
like_single_list()
and like_series()
are intended for
use with ggrl()
.
Likelihood is defined up to an arbitrary multiplicative constant. Log-likelihood (also known as support) is defined up to an arbitrary additive constant.
If function loglik()
is given a probability vector of length
n
, the vector must satisfy the unit sum constraint (up to a
small tolerance). Also, it must be a named vector with names
(collectively) equal to the pnames
of argument H
.
> pnames(chess)
[1] "Topalov" "Anand" "Karpov"
> loglik(c(Topalov=0.7,Anand=0.2,Karpov=0.1),chess)
[1] -69.45364
> loglik(c(Karpov=0.1,Topalov=0.7,Anand=0.2),chess) # identical, just a different order
[1] -69.45364
But if given a vector of length n-1
[e.g. the value of
indep()
], then the names are ignored and the entries are
interpreted as the BT strengths of pnames(H)[seq_len(n-1)]
:
> loglik(c(0.7,0.2),chess)
[1] -69.45364
> loglik(c(foo=0.7,bar=0.2),chess) # names are ignored
[1] -69.45364
(the above applies for H
a hyper2
or hyper3
object).
Empty brackets are interpreted consistently: that is, zero whatever the probability vector (although the print method is not perfect).
data(chess)
loglik(c(1/3,1/3),chess)
#> [1] -60.99695
loglik(rp(14,icons),icons)
#> [1] -184.3772 -184.3772 -184.3772 -184.3772 -184.3772 -184.3772 -184.3772
#> [8] -184.3772 -184.3772 -184.3772 -184.3772 -184.3772 -184.3772 -184.3772
if (FALSE) # takes too long
like_series(masterchef_maxp,masterchef)
like_series(indep(equalp(masterchef)),masterchef)
#> Error in UseMethod("pnames"): no applicable method for 'pnames' applied to an object of class "list"
# \dontrun{}
W <- hyper2(pnames=letters[1:6])
W1 <- ggrl(W, 'a', letters[2:5],'f') # 24-element list
W2 <- ggrl(W, c('a','b'), c('c','d'),c('e','f')) # 2^3=8 element list
like_single_list(rep(1/6,5),W1) # information from first observation
#> [1] 0.03333333
like_series(rep(1/6,5),list(W1,W2)) # information from both observations
#> [1] -7.901007
# hyper3 objects:
H3 <- ordervec2supp3(letters[c(1,2,3,3,2,1,2)])
loglik(c(a=1,b=2,c=3)/6,H3)
#> [1] -8.805875
loglik(c(a=1,c=3,b=2)/6,H3) # identical
#> [1] -8.805875