Rearranging Mississippi

How many distinct ways can all the letters in MISSISSIPPI be arranged to form a new word?

Before we answer this, let’s do something simpler; the number of ways of arranging the word CAT. It can form CAT, CTA, TCA, TAC, ACT, and ATC; in six ways.

We can also use the permutation formula to arrive at the same. Why permutation? Well, the order matters here, or else it would have been only one combination possible. So, 3P3 = 3!/0! = 3! = 3 x 2 x 1 = 6.

MISSISSIPPI

There are 11 letters in the word MISSISSIPPI. So it is 11!. But some of the letters are the same. There are four Is, four Ss and two Ps in it. You don’t want multiple-count the repeated ones. The way to avoid it is to divide the original permutations (11!) with the respective repeated permutations. So the required value is

11!/(4!4!2!) = 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4! /(4! x 4 x 3 x 2 x 1 x 2 x 1)

= 11 x 10 x 9 x 7 x 5 = 34650.

Rearranging Mississippi Read More »

In a 5-card hand – Counting

We evaluated three card probabilities in the previous post. It is important to verify the calculations, well, by actually counting the occurrences by shuffling it a million times and drawing five cards. But first, build the deck:

suits <- c("Diamonds", "Spades", "Hearts", "Clubs")
face <- c("Jack", "Queen", "King")
numb <- c("Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten")
face_card <- expand.grid(Face = face, Suit = suits)
face_card <- paste(face_card$Face, face_card$Suit)

numb_card <- expand.grid(Numb = numb, Suit = suits)
numb_card <- paste(numb_card$Numb, numb_card$Suit)

Aces <- paste("Ace", suits) 

deck <- c(Aces, numb_card, face_card)

Four face cards

itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 5, replace = FALSE, prob = rep(1/52, 52))  

dr <- sum(str_detect(draw, "Queen|King|Jack"))

if(dr == 4){
  counter <- 1
}else{ counter <- 0}

})

mean(shuff)

The answer turns out to be: 0.007548

Three cards are kings

itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 5, replace = FALSE, prob = rep(1/52, 52))  

dr <- sum(str_detect(draw, "King"))

if(dr == 3 ){
  counter <- 1
}else{ counter <- 0}

})

mean(shuff)
0.001717

All five cards are hearts

itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 5, replace = FALSE, prob = rep(1/52, 52))  

dr <- sum(str_detect(draw, "Hearts"))

if(dr == 5 ){
  counter <- 1
}else{ counter <- 0}

})

mean(shuff)
0.00048

In a 5-card hand – Counting Read More »

In a 5-card hand

In a 5-card hand, what is the probability of getting four face cards?

It is a 52-card deck, and it has 12 face cards. That means there are 40 non-face cards. The required combination should include five cards, in which four of which are going to be face cards and one of them is going to be a non-face card.

Since the order in which they come doesn’t matter, we use combinations. So the answer is

Out of the 12 face cards, we choose four and out of the 40 other cards, we choose 1, divided by all possible combinations, i.e. out of the 52 cards, choose 5.

12C4 x 40C1 / 52C5 = 0.00076

Three cards are kings

Out of the 4 kings, we choose three kings and out of the 48 other cards, we choose 1 non-king

P = 4C3 x 48C2 / 52C5 = 0.001736

All five cards are hearts

P = 13C5 / 52C5 = 0.000495

In a 5-card hand Read More »

Summary Statistics of Linear Transformations

Here are the summary statistics for 31 daily high temperatures of a location in degrees Fahrenheit. What are the corresponding numbers in degrees Celcius?

Mean86.6oF
Median87.3oF
Standard Deviation5.2oF
Variance27.04oF

Central tendency and variability during transformations

A few exercises before try and estimate the answer.

A few exercises before try and estimate the answer. Consider three numbers, 5,6,7. The mean, median, standard deviation and variance o the collection are 6, 6, 1 and 1.

Now add 3 to each and find the summary statistics:

The new set is 8, 9, and 10 and the summary is 9, 9, 1, 1. The mean and median of the new set are just 3 more than the original, and the variance and the standard deviations are unchanged.

Multiply each by 4 and the summary statistics:

The new set is 20, 24, and 28 and the summary is 24, 24, 4, 16. The mean and median of the new set a4 times the original, and the variance is 4 times and the standard deviation is 42 times.

Transformation of oF to oC

The relationship (which is a linear transformation is)

C = (5/9) x (F – 32)

C = -(160/9) + (5/9) F

Applying what we learned earlier,

Mean in oC = -(160/9) + (5/9) x 86.6 = 30.3
Median in oC = -(160/9) + (5/9) x 87.3 = 30.7
Standard deviation in oC = (5/9) x 5.2 = 2.89
Variance in oC = (5/9)2 x 5.22 = 8.35

Linear Transformations: jbstatistics

Summary Statistics of Linear Transformations Read More »

Geometric Distribution

One in five cars in the city is green. What is the probability that the fifth car is the first green car?

We already know we can solve this problem using the negative binomial distribution function. But there is a special one for these types – where the arrival time of the first in question. That is the geometric distribution. The formal expression of the probability that the first occurrence of success requires k independent trials, each with success probability p is

\\ P(X = k) = p * (1-p)^{k-1}

To answer the question in the beginning, we substitute p = 0.20 (one in fifth), car number = 5; the required probability is (0.2)*(1-0.2)4 = 0.08192

The R code for the same calculation is

dgeom(4, prob = 0.2, log = FALSE)

The below geometric distribution chart shows the probability of seeing the first green car in precisely 1, 2, 3, etc. rolls, up to 30.

Geometric Distribution Read More »

Discrete Probability Distributions 

We have seen a few discrete probability distributions by now. Today we summarise them and find the relationships and the differences. The following are considered here:

Bernoulli distribution

The Bernoulli distribution is the distribution of the number of successes on a single Bernoulli trial. In a Bernoulli trial, you either get a success (1) or a failure (0). Therefore, a Bernoulli random variable can take either zero or one. E.g., if a coin is tossed once, what is the probability that it comes up heads?

Binomial distribution

When you carry out multiple Bernoulli trials, we get into a Binomial distribution. E.g., if I toss a coin ten times, what is the probability of getting exactly four heads? So, you can already conclude that the Bernoulli distribution is a special case of the binomial distribution with one trial.

Geometric distribution

The geometric distribution is the distribution of the number of Bernoulli trials to get the first success. E.g., if a coin is tossed repeatedly, what is the probability that the first head comes on the fifth trial?

Negative binomial distribution

A general case of the geometric distribution is the negative binomial distribution. It is the distribution of the number of trials needed to get a certain number of successes in repeated independent Bernoulli trials. E.g., if a coin is tossed repeatedly, what is the probability that the third head comes on the tenth trial?

Hypergeometric distribution

The hypergeometric distribution is similar to the binomial distribution but without replacement, or the trials are not independent. E.g., if five cards are drawn from a deck without replacement, what is the probability of getting two spades?

Poisson distribution

It is the distribution of the number of events in a given duration if those are occurring randomly and independently. What is the probability of having exactly three shark attacks on a particular beach this year? The Poisson distribution is approximated to a binomial distribution if the number of trials is large and the probability is small.

Reference

Overview of Some Discrete Probability Distributions: jbstatistics

Discrete Probability Distributions  Read More »

Negative Binomial Distribution

A fair coin is tossed repeatedly. What is the chance of getting 3rd head on the 10th toss?

You may notice the difference here; it is not asking for the probability of getting three heads in 10 tosses, which can be done using a binomial distribution. This one belongs to the negative binomial distribution.

Let each trial has a probability of success p (and failure 1−p). We follow this sequence until r successes occur.

The probability of observing the s success after having f failures (i.e., the success specified for the [s+f]th trial) is s+f-1Cf x ps x qf

The present problem

\frac{9!}{2! 7!} * (0.5)^3 * (1-0.5)^7 = 0.035

or the R – code

toss_number <- 10
success <- 3
failure <- toss_number - success
dnbinom(failure, success, prob = 0.5)
0.035

Here is the distribution of probabilities of success at each milestone.

Binomial and negative binomial

The key difference between the two is: in the binomial distribution, the number of trials is fixed and the number of successes is a random variable. Whereas in the negative binomial distribution, the opposite is true, viz. the number of successes is fixed and the number of trials is a random variable.

Negative Binomial Distribution Read More »

The Big “But” Fallacy

The big but fallacy involves starting with a generally accepted statement only to negate it at the end with a but. An example is: “Yes, it is wrong to hurt animals, but this time it was different (as I was hungry!)”.

The fallacy is closely related to what is known as the “special pleading”. Here, the ‘but’ gives the ‘special’ exception from the generally accepted rules or ethics.

The Big “But” Fallacy Read More »

A pair of Aces from Four Cards

There are four cards – ace of spades, ace of clubs, ten of spades and seven of clubs.

A♠; A♣; 10♠; 7♣

If I draw two random cards, what is the probability that I get two aces, given?
1. At least one of them is an ace
2. One card is an ace of spades

The problem can be solved in different ways, but we choose, as usual, the Bayes’ rule.

At least one of them is an ace

\\ P(AA|A_{At1}) = \frac{P(A_{At1}|AA) * P(AA)}{P(A_{At1}|AA) * P(AA) + P(A_{At1}|AA^n)* P(AA^n)}

Estimating each parameter:
Probability of at least one Ace, given two aces, P(AAt1|AA) = 1
Probability of picking two aces, P(AA) = 1/6 (there are six ways of arranging four cards into pairs)
Probability of at least one Ace, given NOT two aces, P(AAt1|AAn) = 4/5
Probability of NOT picking two aces, P(AAn) = 5/6 [P(AA) + P(AAn) = 1]
Substituting the values,

\\ P(AA|A_{At1}) = \frac{1/6}{1/6 + (4/5)*(5/6)} = \frac{1}{1+4} = \frac{1}{5}

One card is an ace of spades

\\ P(AA|A_{Asp}) = \frac{P(A_{Asp}|AA) * P(AA)}{P(A_{Asp}|AA) * P(AA) + P(A_{Asp}|AA^n)* P(AA^n)}

Probability of Ace of Spades, given two aces, P(AAsp|AA) = 1
Probability of picking two aces, P(AA) = 1/6 (there are six ways of arranging four cards into pairs)
Probability of Ace of Spades, given NOT two aces, P(AAsp|AAn) = 2/5
Probability of NOT picking two aces, P(AAn) = 5/6 [P(AA) + P(AAn) = 1]
Substituting the values,

\\ P(AA|A_{Asp}) = \frac{1/6}{1/6 + (2/5)*(5/6)} = \frac{1}{1+2} = \frac{1}{3}

R Simulation

cards <- c("Ace of Spades", "Ace of Clubs", "Ten of Spades", "Seven of Clubs")

itr <- 100000

shuff <- replicate(itr, {
draw <- sample(cards, 2, replace = FALSE, prob = rep(1/4, 4)) 

if(any(str_detect(draw, "Ace of Spades"))) {
  if(all(str_detect(draw, "Ace"))){counter <- "A"}
  else{counter <- "B"}
}
else{counter <- "C"}
})

sum(shuff == "A") / (sum(shuff == "A") + sum(shuff == "B"))

A pair of Aces from Four Cards Read More »

Cards from a Deck

If you draw cards from a well-shuffled deck of cards, what is the probability that you get an Ace of Hearts and a black card?

There are two different probabilities this can happen.

  1. An ace of hearts followed by a black card
  2. A black card followed by an ace of hearts

The probability for 1) is (1/52) x (26/51) and for 2) is (26/52) x (1/51). Add them up: (2 x 26)/(51 x 52) = 1/51

If you want to verify the results, you may shuffle the deck a million times and count:

suits <- c("Diamonds", "Spades", "Hearts", "Clubs")
face <- c("Jack", "Queen", "King")
numb <- c("Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten")
face_card <- expand.grid(Face = face, Suit = suits)
face_card <- paste(face_card$Face, face_card$Suit)

numb_card <- expand.grid(Numb = numb, Suit = suits)
numb_card <- paste(numb_card$Numb, numb_card$Suit)

Aces <- paste("Ace", suits) 

deck <- c(Aces, numb_card, face_card)
itr <- 1000000

shuff <- replicate(itr, {
draw <- sample(deck, 2, replace = FALSE, prob = rep(1/52, 52)) 

dr <- "Ace Hearts" %in% draw & (any(str_detect(draw, "Spades|Clubs")))

if(dr == TRUE){
  counter <- 1
}else{ 
counter <- 0
}

})

mean(shuff)

Cards from a Deck Read More »