Professional Documents
Culture Documents
pdf
(relevant text pages)
Ch7
install.packages("combinat")
library(combinat)
install.packages("gtools")
library(gtools)
install.packages("prob")
library(prob)
library(combinat)
library(gtools)
library(prob)
# combinations {gtools}
combinations(3,2,letters[1:3])
combinations(3,2,letters[1:3],repeats=TRUE)
permutations(3,2,letters[1:3])
permutations(3,2,letters[1:3],repeats=TRUE)
permutations
permutations(3,2,repeats=TRUE)
permutations(3,2)
permutations(3,2,4:6)
x=4:6
permutations(3,2,x)
combinations
combinations(3,2)
combinations(3,2,1:3)
combinations(3,2,1:3,repeats=TRUE)
7.3
#
urnsamples(x,
Case1:
with replacement (repetitions allowed) and order matters
x=1:3
urnsamples(x,
# n^2
expand.grid(x,x)
urnsamples(x,
# n^n
expand.grid(x,x,x)
expand.grid(LETTERS[1:3],LETTERS[1:3])
# expand.grid(LETTERS[1:3],LETTERS[1:3],LETTERS[1:3])
=======================================================================
Case2
# without replacement (no repetitions) and order matters (PERMUTATIONS)
#
#
#
#
#
factorial(3)
# =6
factorial(4)
# = 24
4!
permutations(4,4,x)
# Consider a clearer case: permutations of A, B, C
x=c("A","B","C")
permutations(3,3,x)
# x=LETTERS[1:3]
# permutations(3,3,LETTERS[1:3])
Case3:
without replacement and order does not matter (COMBINATIONS)
page 218 indistinguishable objects
# n=5 r=2 (n-3)=3
n!/(n-r)!=20
x=c("A","A","A","A","B","B","B") # indistinguishable
urnsamples(x, size = 4, replace = FALSE, ordered = FALSE)
urnsamples(1:7, size = 4, replace = FALSE, ordered = FALSE)
# combn(7,4)
# combinations(7,4)
# combinations(7,4,8:14)
Definition:
four factorial
n factorial
1!=1
4!=1x2x3x4=24
In S-Plus the function
factorial
factorial(4)
[1] 24
factorial(0:4)
[1] 1 1 2 6 24
combinations expression (7.1) on pg 219 is
the function choose
choose(n,x)
choose(4,2)
[1] 6
choose(4,0:4)
In S-Plus
[1] 1 4 6 4 1
The permutations expression on pg 218
Expression
=
Expression
(a + b)4 = a4 + 4a3b + 6a2b2 + 4ab3 + b4
Expand
Pascals Triangle (pg 591 of text) is a triangle of coefficients that is based on the
binomial theorem.
It is formed by adding the two numbers directly above and placing 1s on the outer sides.
1
1
1
1
1
1
1
1
1
The binomial
36
2
3
5
6
21
84
1
3
10
15
28
1
4
10
20
35
56
126
15
35
70
6
21
56
126
1
7
28
84
1
8
36
Expand
Expression
Result
In general,
Expression
Result
Expression
Result