#Probability- Show your Work in R
library(rmarkdown)
library(tinytex)
library(knitr)
two.dice <- function(){
dice <- sample(1:6, size = 2, replace = TRUE)
return(sum(dice))
}
two.dice()
## [1] 5
replicate(n = 3, expr = two.dice())
## [1] 9 8 8
dice.sum <- function(n.dice){
dice <- sample(1:6, size = n.dice, replace = TRUE)
return(sum(dice))
}
replicate(3, dice.sum(2))
## [1] 5 5 4
my.dice.sum <- function (n.side){
dice <- sample(1:n.sides, size=n.dice, replace = TRUE)
return(sum(dice))
}
s <- 6
n1 <-2
n <- 3
probability1 <- (1/s)^n1
probability <- (1/s)^n
print(probability1)
## [1] 0.02777778
print(probability)
## [1] 0.00462963
The probability of rolling a set of dice and getting a twelve is 0.0278. The probability of rolling three times six-sided dice and getting a twelve is 0.0046.
maleother <- 200
femaleother <- 100
total <- 1700
prob <- (maleother/total) + (femaleother/total)
print(prob)
## [1] 0.1764706
The probability that a customer is male and lives in “Other” or is female and lives in “Other” is 0.176
remaining <- 52-1
probdiamond <- 12/remaining
print(probdiamond)
## [1] 0.2352941
The probability of drawing a second diamond, after the first card drawn was a diamond, without replacement, is 0.235
int <- as.integer(readline(prompt = "Please enter a number"))
## Please enter a number
facto <- 1
facto <- factorial(int)
print(facto)
## [1] NA
ft1 <- factorial(20)
ft2 <- factorial(10)
print(ft1/ft2)
## [1] 670442572800
The amount of lineups that are possible are 6.704426e+12 or 670442572800.
tv <- 20
sss <- 20
dvd <- 18
theatersystems <- tv*sss*dvd
print(theatersystems)
## [1] 7200
There is a possibility to build up to 7200 different home theater systems.
d <- 10:1
rounds <- numeric(length = length(d))
for (i in seq_along(d)) {
rounds[i]<-d[i]
}
rounds
## [1] 10 9 8 7 6 5 4 3 2 1
prod(rounds)
## [1] 3628800
The amount of different ways that a doctor can visit 10 patients in the morning rounds would be 3628800.
coinflip <- 2^7
dice <- 6^3
card <- 52*51*50*49
coinflip*dice*card
## [1] 179640115200
There are 179640115200 different outcome that are possible from this situation.
int <- as.integer(readline(prompt = "Please enter a number"))
## Please enter a number
facto <- 1
facto <- factorial(int)
print(facto)
## [1] NA
ftm <- factorial(3)
ftw <- factorial(4)
print(ftw *ftm)
## [1] 144
There are a total of 144 ways for the men and women to be arranged in the round table.
#Probaility of a User
au <- .03
#Probability of a Non-User
anu <- .97
#Probability (+|User)
bGivena <- .95
#Probability (+|Non User)
bGivenNota<- .05
#Bayes
aGivenb <- (bGivena*au)/((bGivena*au)+(bGivenNota*anu))
print(aGivenb)
## [1] 0.3701299
The probability of a person who tests positive being a user is 0.3701.
gg <- 1/3
gb <- 1/3
bb <- 1/3
probabilityofoneb <- 1/3 + 1/3
print(probabilityofoneb)
## [1] 0.6666667
The probability of having one side being brown is 0.67.