# Using expand.grid to create a dataframe of all possible combinations from all 3 die
outcomes <- expand.grid(d1=1:6, d2=1:6, d3=1:6)
dim(outcomes)
## [1] 216 3
There are a total of 216 possible outcomes, now lets find out how many of those add to 12.
# Using rowSums and length functions to add up the sums of each row, and return the count of those that equal 12
outcomes12 <- length(which(rowSums(outcomes) == 12))
outcomes12
## [1] 25
Now we can dived the count of outcomes whose sum add is 12 (outcomes12), by the total number of outcomes (outcomes) to calculate the probability
outcomes12/nrow(outcomes)
## [1] 0.1157407
The probability of rolling a sum of 12 on three rolls of six-sided dice is 0.1157
# creating a matrix that shows the Gender and Residence of Customers
table <- matrix(
data = c(200, 300, 200, 100, 100, 200, 200, 100, 200, 100),
nrow = 5,
ncol = 2,
byrow = TRUE
)
rownames(table) <- c("Apartmemt", "Dorm", "With Parent(s)", "Sorority/Fraternity House", "Other")
colnames(table) <- c("Males", "Females")
table
## Males Females
## Apartmemt 200 300
## Dorm 200 100
## With Parent(s) 100 200
## Sorority/Fraternity House 200 100
## Other 200 100
First we will add the marginal probabilities to our matrix
# To find the total count
total_count <- sum(table)
# Probability of each row and column
row_prob <- rowSums(table) / total_count
col_prob <- colSums(table) / total_count
#add these to our data matrix
table_prob <- cbind(table, row_prob)
table_prob <- rbind(table_prob, c(col_prob, sum(row_prob)))
table_prob
## Males Females row_prob
## Apartmemt 200.0000000 300.0000000 0.2941176
## Dorm 200.0000000 100.0000000 0.1764706
## With Parent(s) 100.0000000 200.0000000 0.1764706
## Sorority/Fraternity House 200.0000000 100.0000000 0.1764706
## Other 200.0000000 100.0000000 0.1764706
## 0.5294118 0.4705882 1.0000000
From the matrix we created above, we see there is 0.1765 chance that a customer is a male or female and lives in ‘Other’
#Creating a deck of 52 cards
card_deck <- 52
# Diving the deck by 4 to get the count of card that are diamonds
diamond_cards <- card_deck / 4
# removing the first card drawn that was a diamond
new_card_deck <- card_deck - 1
new_diamond_cards <- diamond_cards - 1
# Calculating the probability of choosing a diamond card as the second card drawn
diamond_card_prob <- new_diamond_cards / new_card_deck
diamond_card_prob
## [1] 0.2352941
There is a 0.2353 chance that a diamond card is drawn as the second card, if the first card, drawn without replacement, was a diamond
We will use the permutations formula with out repeats n! / (n-r)!
# Setting our variables
n <- 20
r <- 10
# Plugging them into our equation n! / (n-r)!
possible_lineups <- factorial(n) / factorial(n-r)
possible_lineups
## [1] 670442572800
There are 670,442,572,800 possible lineups.
We will use the multiplication rule of Counting for this
tv <- 20 #20 tvs
sss <- 20 #20 surround sound systems
dvdp <- 18 #18 dvd players
diff_theaters <- tv * sss * dvdp
diff_theaters
## [1] 7200
There are 7200 different home theater systems you can build.
We will use the Factorial rule of counting for this
factorial(10)
## [1] 3628800
There are 3628800 different ways the doctor could visit the 10 patients.
coin_toss <- 2^7 # 2 sides, 7 tosses
dice_roll <- 6^3 # 6 sides, 3 tosses
card_draw <- factorial(52) / (factorial(4) * factorial(52-4)) # choosing 4 cards from 52 without replacement
total_outcomes <- coin_toss * dice_roll * card_draw
card_draw
## [1] 270725
total_outcomes
## [1] 7485004800
There are 7,485,004,800 possible outcomes.
# Assigning variables
men <- 4
women <- 4
# Calculate possible outcomes
seating_combo <- factorial(men - 1)* factorial(women)
seating_combo
## [1] 144
There are 144 possible seating arrangements
We will use Bayes` Theorem to solve this.
# B = positive, A1 = User, A2 = not a user
# g should be read as given, ex. BgA1 should be read as B given A1
BgA1 <- 0.95 # Someone will test positive 95% of the time given they are a user
A1 <- 0.03 # 3% of the population are users
BgA2 <- 1 - 0.99 # someone will test negative 99% of the time if they are not a user
A2 <- 0.97 # population who are not users
# plug into Bayes` Theorem
A1gB <- (BgA1 * A1)/((BgA1 * A1) + (BgA2 * A2))
A1gB
## [1] 0.7460733
The probability is 0.7461
This is similar to the Monty Hall Probability Problem, so we will solve it as such
# with 3 pancakes in the hat to start, each pancake has 1/3 chance in being picked
gg <- 1/3 #golden both side
bg <- 1/3 #golden one side, brown one side
bb <- 1/3 #brown both sides
# We pull a pancake and now we know one side is brown, we can remove gg
probability_brown <- bg + bb
probability_brown
## [1] 0.6666667
There is a probability of .6667 the other side will be brown.