vasishth/bayescogsci

n choose k

Closed this issue · 3 comments

Early in Section 1.4, the book says the R function choose(n,k) is defined for positive integers n and k. However, the figures show the need to allow k=0, and in fact R will allow nonnegative integers in both arguments. (I just checked.) Please consider changing this single word.

That seems weird; but the R help for choose does say that the function is defined for all real numbers. This seems needlessly confusion to me (to return 0 for choose(-10.2,-3.1)

?choose

The functions choose and lchoose return binomial coefficients and the logarithms of their absolute values. Note that choose(n, k) is defined for all real numbers

n and integer

k. For


1
k≥1 it is defined as

(


1
)

(



+
1
)
/

!
n(n−1)⋯(n−k+1)/k!, as
1
1 for

0
k=0 and as
0
0 for negative

k. Non-integer values of k are rounded to an integer, with a warning.
choose(*, k) uses direct arithmetic (instead of [l]gamma calls) for small k, for speed and accuracy reasons. Note the function combn (package utils) for enumeration of all possible combinations.

For n>0, the usual intuitive interpretation for choose(n,0) makes sense: there is exactly one possible outcome when you choose no items at all from a collection of n things. This degenerate case is relevant when discussing binomial distributions, because there is a nonzero probability of getting 0 successes in n trials, and the usual formula gets this right. The one-word change I suggest is all we need in the text.

I think the rest may be simply a software-design issue. The identity $n! = \int_0^\infty t^n e^{-t} dt$ is valid for every integer $n\ge0$, and the right side has a well-defined value for every real number $n>-1$. I'm guessing that the folks behind R have opted to give the defining expression the largest possible domain, and offloaded to the users of R the responsibility for making sure their inputs carry the meanings the users expect.

fixed