increment: Increment and decrement operators

incrementR Documentation

Increment and decrement operators

Description

Syntactic sugar for incrementing and decrementing likelihood functions

Usage

inc(H, val = 1)
dec(H, val = 1)
trial(winners,players,val=1)

Arguments

H

A hyper2 object

winners, players

Numeric or character vectors specifying the winning team and the losing team

val

Numeric

Details

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

> H <- hyper2(list("b",c("a","b"),"c",c("b","c")),c(2,4,3,5))
> H
a * (a + b)^4 * b^2 * (b + c)^5 * 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). Alternatively we could use magrittr pipes:

H[c("a","b")] %<>% `+`(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 convenience function trial() takes this one step further and increments the ‘winning team’ and decrements the bracket containing all players. The winners are expected to be players.

> trial(c("a","b"),c("a","b","c"))
> (a + b) * (a + b + c)^-1

Using trial() in this way ensures that the powers sum to zero.

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

Author(s)

Robin K. S. Hankin

Examples

data(chess)

## Now suppose we observe an additional match, in which Topalov beats
## Anand.  To incorporate this observation into the LF:



trial("a",c("a","b"))

chess <- chess + trial("Topalov",c("Topalov","Anand"))

hyper2 documentation built on June 22, 2024, 9:57 a.m.