#Clearing the global environment
rm(list = ls())
#load library
library(gtools)
sample_space = expand.grid(1:6, 1:6, 1:6) #We get 216 obvservations
#Summing the rows and counting the ones adding upto 12
sums = rowSums(sample_space, na.rm = FALSE)
desired = length(which(sums == 12))
# Calculating the total number of possible outcomes
total <- nrow(sample_space) #here, it is 216
# Calculating and rounding off the probability
probability <- desired / total
(round(probability, 4))
## [1] 0.1157
#Creating the database
customer_matrix <- matrix(c(200, 300, 200, 100, 100, 200, 200, 100, 200, 100), nrow = 5, byrow = TRUE)
rownames(customer_matrix) <- c("Apartment", "Dorm", "With parent(s)", "Sorority/Fraternity House", "Other")
colnames(customer_matrix) <- c("Males", "Females")
customer_matrix
## Males Females
## Apartment 200 300
## Dorm 200 100
## With parent(s) 100 200
## Sorority/Fraternity House 200 100
## Other 200 100
#Calculating the sums
location_m <- rowSums(customer_matrix)
gender_m <- colSums(customer_matrix)
male_other <- customer_matrix["Other", "Males"] / sum(gender_m)
# Calculate the probability that a customer is female and lives in 'Other'
female_other <- customer_matrix["Other", "Females"] / sum(gender_m)
# Calculate the combined probability
prob <- male_other + female_other
# Print the combined probability
(round(prob, 4))
## [1] 0.1765
# Total number of cards
total_cards = 52
# Total number of diamonds
diamonds = 13
# Probability of drawing a diamond on the first draw without replacement
probability1 <- diamonds / total_cards
# Probability of drawing a diamond on the second draw without replacement
probability2 <- (diamonds - 1) / (total_cards - 1)
(round(probability2, 4))
## [1] 0.2353
# Permutation without repeats since the question asked for different lineups (arrangement), rather than the ways the songs can be chosen.
total_songs = 20
selected_songs = 10
#Calculating total number of lineups
lineups = factorial(total_songs) / factorial (total_songs - selected_songs)
lineups
## [1] 670442572800
# Combination without repetition
(ht_sys = 20*20*18)
## [1] 7200
# Number of ways to visit his patients (permutation without repeats)
(factorial(10))
## [1] 3628800
# Number of outcomes for coin tosses
(coin = 2^7)
## [1] 128
# Number of outcomes for die rolls
(die = 6^3)
## [1] 216
# Number of outcomes for card draws (Combination of any four, without replacement)
(card = choose(52, 4))
## [1] 270725
# Number of different outcomes
(total = coin * die * card)
## [1] 7485004800
# Number of women
num_women = 4
# Number of men
num_men = 4
# Out of 4 men, one can be seated anywhere, however the other 3 need to be placed relatively. So the number of ways they can be seated is calculated by permutation, i.e, 3P3 = 3!
men_prob = factorial(num_men-1)
#Ways women can be seated is 4P4
women_prob = factorial(num_women)
#Total number of ways
(total = men_prob * women_prob)
## [1] 144
pos_user = 0.95 #P( + | User)
neg_user = 0.99 #P( - | Not User)
user = 0.03 #P(User)
#Bayesian formula:
#P(User | +) = P(+ | User) * P(User) / P(+)
#To find P(+):
#P(+ | User) * P(User) + P(+ | Not user) * P(Not User)
#where; P(+ | Not user) = P(1 - P( - | Not User))
#Therefore, calculating probability of total users testing positive
pos = (pos_user * user) + ((1-neg_user) * (1-user))
#Applying Bayesian formula:
user_pos = (pos_user * user) / pos
(round(user_pos, 4))
## [1] 0.7461
You have a hat in which there are three pancakes. One is
golden on both sides, one is
brown on both sides, and one is golden on one side and brown on the
other. You
withdraw one pancake and see that one side is brown. What is the
probability that the
other side is brown? Explain.
Explanation:
Out of the three pancakes, only two can have one brown side. As given in the question, the pancake chosen has one side brown, so to find the probability of the other side being brown in color, I have used conditional probability as shown below:
P (Both sides being brown | One side is brown) = P (Both sides are brown) / P (One side is brown
)
By calculating further, the total number of pancakes cancels out, giving:
P (Both sides being brown | One side is brown) = N (Both sides are brown) / N (One side is brown)
#Number of pancakes with one brown side
one_brown = 2
#Number of pancakes with two brown sides
two_brown = 1
#Probability of the other side being brown
(probability = two_brown / one_brown)
## [1] 0.5