How Many Ways 5 Objects Can Be Selected With Replacement

365 Views Asked by At

Suppose I have the following set up:

  • There are 5 objects : A, B, C, D, E
  • The probability for each of these objects to be chosen is : 0.2, 0.3, 0.1, 0.3, 0.1
  • You want to pick 5 of these objects with replacement (e.g. ABACD, DDBCA, etc.)

I want to find out (exact solution):

  • All combinations that can be made from these 5 objects

In a previous question on a different Stackoverflow Community (https://stackoverflow.com/questions/71375997/creating-probability-trees-in-r), I learned how to enumerate all these combinations for this problem using the R programming language:

library(RcppAlgos)

# Probabilities
probs <- setNames(c(0.2, 0.3, 0.1, 0.3, 0.1), LETTERS[1:5])

# Generate permutations
perms <- permuteGeneral(names(probs), repetition = TRUE)

# Collapse permutations
perm_res <- do.call(paste, c(asplit(perms, 2), sep = ""))

# Replace with probability values and coerce to numeric
perms[] <- probs[perms]
class(perms) <- "numeric"

# Calculate products
res <- data.frame(perm_res, prob = exp(rowSums(log(perms))))

Based on this, it appears that there 3125 different combinations that can be made:

dim(res)
[1] 3125    2

My Question: What mathematical formula can be used to calculate this number 3125? And is there a general mathematical formula that can be used for "n" objects with with "m" choices with replacement? E.g. Picking 11 objects with replacement?

  • I know that this is not a "factorial" question, i.e. there are not 5! ways to choose these objects

  • I know that this question does not correspond to the power set, i.e. there are not 2^5 ways to choose these objects

  • I know that is not a typical combinatorics problem, i.e. I don't think this can be solved directly using "nCr"

Can someone please show me what mathematical formula can be used to determine this number 3125?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

You are choosing $5$ elements of a set of $5$. For the first element, there are $5$ possible outcomes. Because there is replacement, for the second element there are also $5$ possible outcomes, for the third the same, etc...

This results in $5\cdot 5\cdot 5\cdot 5\cdot 5 = 5^5=3125$ possible selections with replacement.

In general, if you are selecting with replacement $n$ elements of a set of $m$ elements, there are $m^n$ selections.