What’s the chance of getting a sequential pair on two rolls of a die (eg, a 3 then a 4 counts, but a 4 then a 3 does not). (Hint: you can calculate this manually if you like, by counting up the sample space and finding the fraction of that sample space that consists of ordered pairs.)
5/6^2## [1] 0.1388889
2/3*.05## [1] 0.03333333
(tibble::tribble(
~Test,~Disease,~Not.Disease,~Totals,
"+","95","4995","5090",
"-","5","94905","94910",
"","100","99900","100000"
))## # A tibble: 3 x 4
## Test Disease Not.Disease Totals
## <chr> <chr> <chr> <chr>
## 1 + 95 4995 5090
## 2 - 5 94905 94910
## 3 100 99900 100000
(.95*.001)/0.0509## [1] 0.01866405
(tibble::tribble(
~Test,~Disease,~Not.Disease,~Totals,
"+","95","49995","50090",
"-","5","949905","949910",
"","100","999900","1000000"
))## # A tibble: 3 x 4
## Test Disease Not.Disease Totals
## <chr> <chr> <chr> <chr>
## 1 + 95 49995 50090
## 2 - 5 949905 949910
## 3 100 999900 1000000
(.95*.0001)/0.05009## [1] 0.001896586
You have a 20-sided die. Using sample, roll it 1000 times and count the number of rolls that are 10 or less.
onek <- sample(1:20,1000,replace=T)
sum(onek <= 10)## [1] 497
Generate a histogram using ggplot of 10,000 draws from a uniform distribution between 2 and 7.
unif.hist <- as.data.frame(runif(10000,min=2,max=7))
ggplot(data=unif.hist,mapping = aes(x=unif.hist))+
geom_histogram(fill='white',color='red')+
xlab("X")+
ylab("P(X)")+
ggtitle("Graph of Uniform Distribution 2<x<7")+
theme(plot.title = element_text(hjust = 0.5))Try to write down the equation for this probability density function. \(f(x)=\left\{_{0\text{ for }x<2\text{ or }x>7}^{\frac{1}{b-a}\text{ for }2 \leq x \geq7} \right\}\)
What is the probability that a draw from this distribution will be between 1.5 and 3.2?
sum(unif.hist>1.5&unif.hist<3.2)/10000## [1] 0.2402
punif(3.2,min=2,max=7)-punif(1.5,min=2,max=7)## [1] 0.24
Using R’s cdf for the binomial, what is the probability of getting 500 or fewer “20”s when rolling your 20-sided die 10,000 times. Looking back at 2a, what proportion of your rolls were actually 20s?
pbinom(500,size=10000,prob=(1/20),lower.tail=T)## [1] 0.511895
sum(onek == 20)/1000## [1] 0.045
Using rbinom, roll a 100-sided die 100 times and report the total number of 7s you get.
hdie <- rbinom(1:100,100,1/100)
sum(hdie == 7)## [1] 0
You are a klutz, and the average number of times you drop your pencil in a day is 1. Using the poisson functions in R, what’s the chance of dropping your pencil two or more times in a day? (Hint: calculate the chance of dropping it one or fewer times, and then take 1 minus that.)
ppois(1,1,lower.tail=F)## [1] 0.2642411
1-ppois(1,1)## [1] 0.2642411
Because he is lazy, your teacher has assigned grades for an exam at random, and to help hide his deception he has given the fake grades a normal distribution with a mean of 70 and a standard deviation of 10. What is the chance your exam got a score of 85 or above? What is the chance you got a score between 50 and 60?
# an 85 or above
pnorm(84.99,mean=70,sd=10,lower.tail = F)## [1] 0.06693682
# between 50 & 60
pnorm(60,mean=70,sd=10,lower.tail = T)-pnorm(50,mean=70,sd=10,lower.tail = T)## [1] 0.1359051