a1 Use the multiplication rule to answer this question analytically.
We take 1/4 to the 7th because it doesn’t ask for the probability that they are all on a specific chromosome, only that they are on the same chromosome. So, the first can be on any (p=1), then the rest have 1/4 chance of being on that same one. Here is the answer:
(1/4)^7
## [1] 6.103516e-05
a2 Simulate the process
This is my simulation. The result is pretty similar to the calculated actual probability thanks to the large sample size (1 million).
c <- c(1,2,3,4)
sample(c,8,replace=TRUE)
## [1] 4 1 1 2 2 2 4 4
t <- replicate(1000000, length(unique(sample(c,8,replace=T))))
length(grep('1',t))/length(t)
## [1] 5.6e-05
b1 Use the multiplication rule to answer this question analytically
This is the probability that they would randomly line up in this order:
(1/8)*(1/7)*(1/6)*(1/5)*(1/4)*(1/3)*(1/2)*1
## [1] 2.480159e-05
b2 Simulate this process by replicating the sample function to test your math
Sampling the numbers 1-8 (choose 8) 1 million times and asking R how many of these samples are ordered:
##Making the function:
howMany <- function(obs, to.count){
true.false <- obs == to.count
num <- sum(true.false)
total <- length(obs)
prop <- num / total
return(c(y = num, n = total, p = prop))
}
##Simulating the situation:
hox.genes <- 1:8
samp <- replicate(1000000, is.ordered(sample(hox.genes,8)))
howMany(samp, "TRUE")
## y n p
## 0e+00 1e+06 0e+00
Combining 1a and 1b, what is the probability that all HOX genes are on the same Drosophila chromosome and in the order they are expressed?
The probability of both of these things occuring by chance is equal to [the probability of them all being on the same chromosome] * [the probability of them being ordered]…
(6.1035e-05)*(1/40320)
## [1] 1.513765e-09
The flour beetle, Tribolium castaneum, has 10 chromosomes, roughly equal in size, and it also has eight Hox genes. If the eight Hox genes were randomly distributed throughout the genome of the beetle, what is the probability that all eight would land on the same chromosome?
This is the probability that these 8 genes would end up on the same chromosome (The first one can be on any (p=1), then (p=0.1) for each of the remaining Hox genes to be on that same chromosome):
(1/10)^7
## [1] 1e-07
e1 Is the order and location of HOX genes in Tribolium dependent or independent of that in Drosophila? Explain.
The order and locations of HOX genes in these two different species are dependent due to their evolutionary relationship. The probability of these things both happening by chance in both species is miniscule, basically zero.
e2 Set up the math you need to ask the probability that all 8 HOX genes are on the same chromsome and in the same order in both Drosophila and Tribolium.
(pr[same chromosome in Drosophila] * pr[ordered in Drosophila] - pr[both of these things occuring in Drosophila]) * (pr[same chromosome in Triboium] * pr[ordered in Tribolium] - pr[both of these things occuring in Tribolium])
e3 What (if any) additional information do you need to answer this question?
You need to know if and how these factors are dependent on one another in order to account for this. If we are assuming they are indepedent, we need to know the probability of both occuring in each species.
What is the probability that it catches its first bug on its fourth try? [use math, not simulation]
0.8 is the chance of missing, so this is the probability that it misses the first 3 times and then gets the fly on the fourth try:
(0.8)*(0.8)*(0.8)*(0.2)
## [1] 0.1024
What is the probability that it catches its first bug after at least four failures, assuming that it keeps trying until it is successful? [use math, not simulation]
The probability that it misses at least four times before catching the bug is:
(0.8)*(0.8)*(0.8)*(0.8)
## [1] 0.4096
Now, use the sample() function to simulate this process.
c1 Do this once and ask if the flycatcher cathes a bug on its first try.
result <-c("fail","catch")
sample(result, 1,prob=c(0.8,0.2))
## [1] "catch"
c2 Use the replicate() function to do this one-hundred times and see how close your simulation matches your mathematical prediciton.
This is an estimate of the number of times the flycatcher will fail out of 100 attempts:
r <- replicate(100,sample(result,1,prob=c(0.8,0.2)))
sum(r=="fail")
## [1] 80
c3 Now use the replicate() function to do this ten-thousand times, and see how close this is to your math. Which one is closer? Why do you think this is?
This is an estimate of the number of times the flycatcher will fail out of 10,000 attempts:
m <- replicate(10000,sample(result, 1,replace=T,prob=c(0.8,0.2)))
sum(m=="fail")
## [1] 7986
The sample of 10,000 attempts is closer because it is a larger sample size and therefore a more accurate approximation of the true probability.
Use R to simulate your answer to 5B replicating many times. Make a histogram of the number of times that a bird catches a fly on its first, second, third, fourth, or after its fourth try. How does this compare to your answer to 5B?
result<- c("fail","catch")
attempts<-replicate(100, match("catch", sample(result,4,rep=T,prob=c(0.8,0.2))))
#setting NAs equal to 5 (in reality 5+)
attempts[is.na(attempts)] <- 5
hist(attempts, main="Catching Flies(n=100)",xlab="Attempt in which fly was caught- all greater than four grouped as '5'",col="blue")
#This is the proportion of times he caught it after 4 or more misses (n=100)
howMany(attempts,5)
## y n p
## 45.00 100.00 0.45
#Now a larger sample size
attempts2<-replicate(10000, match("catch",sample(result,4,rep=T,prob=c(0.8,0.2))))
attempts2[is.na(attempts2)] <- 5
hist(attempts2,main="Catching Flies (n=10000)",xlab="Attempt in which fly was caught (all greater than four grouped as '5'",col="blue")
#The proportion of times he caught it after 4 or more misses (n=10000)
howMany(attempts2,5)
## y n p
## 4.098e+03 1.000e+04 4.098e-01
What fraction of generals engaging in exactly five battles would be great by this definition? [use math]
The probability that a general engaging in 5 battles would win all 5 with these assumptions:
(0.5)^5
## [1] 0.03125
How does this compare to the fraction given by the general?
Assuming battles are won at random, he was accurate to say about 3% of generals are great if being great means winning 5 battles in a row since the true probability of this was 0.03125.
Use replicate() and sample() functions to build a histogram of the distribution of victories among 200 generals that all engaged in five indepednent battles.
This is my simulation and resulting histogram showing how many generals had each number of wins out of their five independent battles:
battle<-c("win","loss")
answer <- function(obs, to.count){
true.false <- obs == to.count
num <- sum(true.false)
return(y = num)
}
generals <- replicate(200, answer(sample(battle,5,rep=T),"win"))
hist(generals, xlab="Number of Wins", col="red")
The probability of a single mammogram returning a false positive is 0.05 because each event is independent so 10 times the probability of one false negative is the probability of getting at least one false positive out of ten [10*p = 0.5] so p=0.05
What proportion of families have (a1) zero ,
0.52*0.52
## [1] 0.2704
I decided to represent the genders numerically, so length function could be used to illustrate number of each gender in the family(0=boy,1=girl). This way the sum will be the number of girls in the family.
num<-0:1
a<-replicate(1000,sum(sample(num,replace=T,2,prob=c(0.52,0.48))))
#This is the proportion with zero girls
answer(a,0)/1000
## [1] 0.263
(a2) one,
2*0.52*0.48
## [1] 0.4992
answer(a,1)/1000
## [1] 0.52
or (a3) two girls?
0.48*0.48
## [1] 0.2304
answer(a,2)/1000
## [1] 0.217
What is the probability that a family has at least one boy?
1-(0.48*0.48)
## [1] 0.7696
(answer(a,1)+answer(a,0))/1000
## [1] 0.783
If the oldest child is a girl, what is the probability that the youngest child is a boy?
0.52
## [1] 0.52
Because these events are independent of one another, this is the same as the probability of any single child being a boy, 0.52
If at least one child is a boy, what is the probability that the other child is a boy? a girl?
#boy
0.52
## [1] 0.52
#girl
0.48
## [1] 0.48
Because these events are independent of one another, this is the same as the probability of any single child being the specified gender, 0.52 for boys and 0.48 for girls.