Syntactic sugar for incrementing and decrementing likelihood functions. Useful for constructs such as H[c("a", "b")] %<>% inc().

inc(H, val = 1)
dec(H, val = 1)

Arguments

H

A hyper2 object

val

Numeric

Details

A very frequent operation is to increment a single term in a hyper2 object. If


>  H <- hyper2(list("a", c("a","b"), "c", c("a","b","c")), c(1:3,-6))
>  H
log( a * (a + b + c)^-6 * b^2 * c^3)

Suppose we wish to increment the power of a+b. We could do:


H[c("a","b")] <- H[c("a","b")] + 1

(see the discussion of hyper2_sum_numeric at Ops.hyper2.Rd; also vignette zeropower). Alternatively we could use magrittr pipes:


H[c("a","b")] %<>% add(1)

But inc and dec furnish convenient idiom to accomplish the same thing:


H[c("a","b")] %<>% inc

Functions inc and dec default to adding or subtracting 1, but other values can be supplied:


H[c("a","b")] %<>% inc(3)

Or even


H[c("a","b")] %<>% inc(H["a"])

The deprecated convenience function trial() uses this idiom; see pick.Rd. Using trial() in this way ensures that the powers sum to zero (unlike inc() and dec().

The inc and dec operators and the pick() function are used in inst/kka.Rmd.

Frankly inc() and dec() don't do anything that magrittr:add() and magrittr:subtract() don't (except have a default value of 1 (which is surprisingly useful)).

Author

Robin K. S. Hankin

Examples


(H <- hyper2(list("a",c("a","b"),c("a","b","c")),c(1,1,-2)))
#> log( a * (a + b) * (a + b + c)^-2)
H["a"] 
#> Warning: powers have nonzero sum
#> log( a)
H[c("a","x")] 
#> log()
H
#> log( a * (a + b) * (a + b + c)^-2)

## Better: H %<>% inc(beats("a","x"))