## Solution to Tasks of L02
rm(list=ls())
##==========================================================
## 1. Some board games use tetrahedral dice that have four faces and that are labeled from 1 to 4.
## Estimate the probabilities to get the following results, after throwing one die:
## a) 4, i.e. f (x=4)
## b) more than 2, i.e. f (x>2)
1/4
1/4 + 1/4
##==========================================================
## 2. In a large population, 16% of the people are left-handed. In a random sample of 10 people find:
## a) probability that exactly 2 are left-handed
## b) probability that fewer than 2 (i.e. 0 or 1) are left-handed
p=0.16
n=10
dbinom(2,n,p)
pbinom(1,n,p) ## or sum(dbinom(0:1,n,p))
##==========================================================
## 3. From the past experience you know that the probability of a successful implantation of
## human glioblastoma into a mouse brain is 60% (so called xenograft experiment).
## The ethical committee asks you to present the clear proof of a minimal number of animals needed for the study.
## a) Estimate the probability to have at least 3 successful implantations in a group of 5 mice.
## b) How many mice should you take to be >90% sure that you get 3 or more mice with a xenograft tumor?
p=0.6
n=5
sum(dbinom(3:n,n,p))
for (n in 5:10)
cat("n=",n,"P(x>=3)=",sum(dbinom(3:n,n,p)),"\n")
##==========================================================
## 4. Lots of 20 components are checked by a company. The procedure for sampling the lot is to select 5 components
## at random and to reject the lot if a defective one is found. Assume the specific lot has r = 3 defectives.
## a) What is the probability that exactly 1 defective is found in the sample?
## b) What is the probability that a lot with r = 3 defective is rejected?
## c) What is the probability that a lot with r = 10 defective is rejected?
N=20
n=5
r=3
dhyper(1,r,N-r,n)
sum(dhyper(1:min(r,n),r,N-r,n))
sum(dhyper(1:min(10,n),10,N-10,n))
##==========================================================
## 5. An ichthyologist studying the spoonhead sculpin catches specimens in a
## large bag seine that she trolls through the lake. She knows from many years
## experience that on averages she will catch 2 fish per trolling.
## a) Draw distribution for the number of fishes after trolling.
## b) What is the probability of having no fish (x = 0)?
## c) What is the probability of having less than 4 fishes (x < 4)?
## d) What is the probability of having more than 1 fish (x > 1)?
## Hint: do not forget that Poisson distribution has no limitation for the maximal number of events. In principle, the ichthyologist can get 100 fishes in one trolling... but with a very small probability.
mu = 2
x = 0:10
fx = dpois(x,mu)
fx
barplot(fx, names.arg=x)
dpois(0,mu)
sum(dpois(0:3,mu))
1-sum(dpois(0:1,mu))
##==========================================================
## 6. In an area of heavy infestation, gypsy moths lay egg clusters on trees with a mean
## number of clusters per tree equal to 3. Identify the distribution and calculate the
## probability that a randomly chosen tree has
## a) no egg clusters;
## b) at least 1 egg cluster.
mu = 3
dpois(0,mu)
1-dpois(0,mu)
##==========================================================
## 7. You are counting Rana temporaria in a forest. On average, you know that
## you can find 6 frogs per hour. What is the probability to find no frogs in
## the next 20 minutes?
mu = 6 * 20 / 60
dpois(0,mu)