Probability and Counting

Most probability calculations require basic calculations.  However, counting problems can be completed more effectively using the commands explained below.

Factorials

To calculate n! we will use the factorial command.

Example: How many ways can a list of 5 items be arranged?

The answer is 5! = 120, which can be calculated as follows.

> factorial(5)
[1] 120

Combinations

To calculate combinations we will use the choose(n,k) command.  With this command we have two arguments.  More specifically, k represents the number of items we will be selecting from a group of n items.

Example: There are 11 members on the board of directors for the Acme Rocket company.  If they must choose an subcommittee of four different members, how many different subcommittees are possible?

For this problem we need to calculate 11C4.

> choose(11, 4)
[1] 330

Permutations

R does not have a specific command for calculating permutations. If we want to calculate permutations we will need to start with the choose command, and adjust it manually.

Note that nP= n!(n-r)! = n!(n-r)! · r!r! = n!r!·(n-r)! · r! = nCr · r!

Using this formula we can now calculate permutations.

Example: There are 11 members on the board of directors for the Acme Rocket company.  If they must elect a chairperson, first vice chairperson, second vice chairperson, and secretary how many different slates of candidates are possible?

For this problem we need to calculate 11P4.

> choose(11, 4)*factorial(4)
[1] 7920

No comments:

Post a Comment