Formulas used for the Probability Review
Answers to Probability review
hotdog<-read.table("/Users/Leland/Desktop/Stat 200/hotdog.txt", header=T, sep="\t")
head(hotdog)
## TYPE CALORIES SODIUM
## 1 beef 186 495
## 2 beef 181 477
## 3 beef 176 425
## 4 beef 149 322
## 5 beef 184 482
## 6 beef 190 587
hotdognohead<-read.table("/Users/Leland/Desktop/Stat 200/hotdog.txt", sep="\t")
head(hotdognohead)
## V1 V2 V3
## 1 TYPE CALORIES SODIUM
## 2 beef 186 495
## 3 beef 181 477
## 4 beef 176 425
## 5 beef 149 322
## 6 beef 184 482
hotdog<-read.table("/Users/Leland/Desktop/Stat 200/hotdog.txt", header=T, sep="\t")
head(hotdog)
## TYPE CALORIES SODIUM
## 1 beef 186 495
## 2 beef 181 477
## 3 beef 176 425
## 4 beef 149 322
## 5 beef 184 482
## 6 beef 190 587
boxplot(hotdog$SODIUM~hotdog$TYPE)
aggregate(hotdog$CALORIES, by=list(hotdog$TYPE), FUN=summary)
## Group.1 x.Min. x.1st Qu. x.Median x.Mean x.3rd Qu. x.Max.
## 1 beef 111.0 140.5 152.5 156.8 177.2 190.0
## 2 meat 107.0 139.0 153.0 158.7 179.0 195.0
## 3 poultry 86.0 102.0 129.0 122.5 143.0 170.0
sample(1:6, size=4, replace=T) #repeat several times.
## [1] 1 1 3 6
result<-matrix(0, nrow=3000, ncol=4) #creates an empty container
for(i in 1:3000){result[i,]<-sample(1:6, size=4, replace=T)}
head(result)
## [,1] [,2] [,3] [,4]
## [1,] 5 2 6 6
## [2,] 5 2 4 1
## [3,] 1 2 2 3
## [4,] 2 3 4 1
## [5,] 1 3 4 3
## [6,] 2 3 6 4
row.sum<-rowSums(result)
head(row.sum)
## [1] 19 12 8 10 11 15
result$SumOfRolls<-row.sum
## Warning in result$SumOfRolls <- row.sum: Coercing LHS to a list
betterresult<-data.frame(result) #save the matrix into a dataframe, this will allow you to store the row.sum vector into the dataframe without using the transform command
betterresult$SumOfRolls<-row.sum
FreqTable<-table(betterresult$SumOfRolls)
FreqTable
##
## 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
## 1 12 29 44 96 116 177 247 283 349 310 320 300 243 177 139 70 57
## 22 23 24
## 20 8 2
#There is no function for finding the mode, so we need to use a little hack
MostProbableRoll<-names(FreqTable)[FreqTable == max(FreqTable)]
LeastProbableRoll<-names(FreqTable)[FreqTable == min(FreqTable)]
hist(betterresult$SumOfRolls,ylab = 'SumofRolls', main = 'Frequency of sum of 4 die rolls')
MostProbableRoll
## [1] "13"
and the least likely roll was
LeastProbableRoll
## [1] "4"
A continued) the probability of the most likely roll would be…, the probability of the least likely roll would be…
max(FreqTable)/3000
## [1] 0.1163333
min(FreqTable)/3000
## [1] 0.0003333333