A permutation with replacement is an ordered selection in which an element may appear more than once. Order matters, and each selection remains available for later positions. section 9.4
Identify the structure before calculating:
- Treat the selections as permutations when changing their order changes the meaning. section 9.4
- Allow replacement when the same value or element can be selected again. section 9.4
- For n possible values and r positions, calculate the number of possibilities as n^r. section 9.4
NBA rest-day pairings
Compare the home and away teams’ prior days off. The pair (2, 1) differs from (1, 2), because home and road positions matter. The pair (2, 2) is valid because both teams may have the same number of days off. With five possible values, 0 through 4, and two positions, there are 5^2 = 25 ordered possibilities. section 9.4 section 20.5
n = 5
r = 2
permutationsCount = n^r
paste0("The permuation count equals: ", permutationsCount)
## [1] "The permuation count equals: 25"
Compute the total directly in R with n = 5 and r = 2; the result is 25. section 9.4
nrow(permutations(n = 5, r = 2, repeats.allowed = TRUE)) ## [1] 25
Generate the same count with permutations() by enabling repeats.allowed = TRUE. section 9.4
permutations(n = 5, r = 2, repeats.allowed = TRUE) - 1 ## [,1] [,2] ## [1,] 0 0 ## [2,] 0 1 ## [3,] 0 2 ## [4,] 0 3 ## [5,] 0 4 ## [6,] 1 0 ## [7,] 1 1 ## [8,] 1 2 ## [9,] 1 3 ## [10,] 1 4 ## [11,] 2 0 ## [12,] 2 1 ## [13,] 2 2 ## [14,] 2 3 ## [15,] 2 4 ## [16,] 3 0 ## [17,] 3 1 ## [18,] 3 2 ## [19,] 3 3 ## [20,] 3 4 ## [21,] 4 0 ## [22,] 4 1 ## [23,] 4 2 ## [24,] 4 3 ## [25,] 4 4
Inspect all 25 ordered pairs, including repeated pairs such as (0, 0), (1, 1), and (4, 4). section 9.4

