The assignment is:
Search for the the “Factorial” operator in R.
Create a new R Markdown file.
Demonstrate you understanding of how to use the Factorial operator by applying to an example you saw in the videos.
Using commands in R, determine the probability of rolling different combinations of two different faces on dice, assuming the dice are fair. What is the most common outcome. What is/are the least common outcomes.
Using concepts from the video on the binomial distribution, if you roll two dice 10 times, what is the probability rolling a number (i.e., combination of the two die) higher than 8?
Save your file and submit. Make sure to add comments in the file to explain your work.
I like that you’re calling on previous experience in R, but what you’re trying to calculate isn’t aligned with what the question is asking. Take a look at your final outcome and double check that it sounds like what you would expect the result of 10, two-dice rolls to be. Additionally, your application of pbinom isn’t entirely correct. We’re looking at 10 total rolls, not 12, and 8 or more is the desired value, not the frequency of desired outcomes we’re looking for. I’d recommend simplifying your approach to so that you can double check that things make sense as you approach a final result.
Below, I will be expanding on the chair example in the khan academy video, let’s take the scenario that there are 5 seats at a table, how many configurations are there for 10 people to sit at that table?
# DEMONSTRATION OF UNDERSTANDING ON USING FACTORIAL OPERATOR
#without factorial operator
possibilitiesOne <- 10 * 9 * 8 * 7 * 6 *5 * 4 * 3 * 2* 1
#with factorial operator
possibilitiesTwo <- factorial(10)
Using commands in R, determine the probability of rolling different combinations of two different faces on dice, assuming the dice are fair. What is the most common outcome. What is/are the least common outcomes.
diceOne <- c(1,2,3,4,5,6)
diceTwo <- c(1,2,3,4,5,6)
#expand.grid is a function that creates a data frame with all combinations with the two vectors I have supplied it
allCombos <- expand.grid(diceOne = diceOne, diceTwo = diceTwo)
#Making a new column that adds all the combinations
allCombos$sum <- allCombos$diceOne + allCombos$diceTwo
#making sum column its own vector
sumCount <- allCombos$sum
#making table to count occurrences
tableSums <- table(allCombos$sum)
# Most Common Sum
mostCommonSum <- mfv(sumCount)
#least common sum
print(tableSums)
##
## 2 3 4 5 6 7 8 9 10 11 12
## 1 2 3 4 5 6 5 4 3 2 1
cat("The most common sum is", mostCommonSum, "and the least common sums are 2 and 12.")
## The most common sum is 7 and the least common sums are 2 and 12.
Using concepts from the video on the binomial distribution, if you roll two dice 10 times, what is the probability rolling a number (i.e., combination of the two die) higher than 8?
# # turning table into dataframe
# sumDF <- as.data.frame(tableSums)
#
# # making a vector of just the frequencies
# justSumsFreqs<- sumDF$Freq
#
# #getting sum of frequencies that rolls you an 8 or higher
# eightPlus <- sum(justSumsFreqs[7:11])
#
# #getting the total sum of frequencies
# totalFreq <- sum(justSumsFreqs)
#
# #getting the probability of getting eight or higher
# probEightPlus <- eightPlus/totalFreq
#eightAndMore <- dbinom( 7, size = 10, prob = probEightPlus)
#percentageOfEightAndMore <- eightAndMore * 100
#cat("The probability of rolling a sum of Eight or more is",percentageOfEightAndMore, "%")
#### RESUBMISSION WORK ######
# x = dbinom(k, n, p)
# K is vector of 1 to 10 because "probability rolling A number" means that a success could be a sum of 8 once or many times
k <- c(1:10)
#n is number of trials
n <- 10
# you can roll 2,3,4,5,6,7,8,9,10,11, or 12
#out of those 11 numbers, only 4 are greater than 8
p <- (4/11)
x <- dbinom(k,n,p)
#x is a vector of probabilities of each success quantity
#so to get the total probability of rolling a combo greater than 8 at least once in 10 trials, you sum all the probabilities together.
totalProb <- sum(x)*100
cat("The probability of rolling a combinitation higher than 8 in 10 trails is", totalProb)
## The probability of rolling a combinitation higher than 8 in 10 trails is 98.91094
resources used: https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/expand.grid https://www.geeksforgeeks.org/a-guide-to-dbinom-pbinom-qbinom-and-rbinom-in-r/