This is a graded in-class assignment. Show all your work in R Markdown files. Submit compiled Word files only.

  1. Patients arrive at the doctor’s office according to Poisson distribution with \(\lambda = 2\)/hour.

    1. What is the probability of getting less than or equal to 2 patients within 2 hours?
    2. Suppose each arriving patient has 50% chance to bring a person to accompany. There are 10 seats in the waiting room. At least many hours should pass that there is at least 50% probability that the waiting room is filled with patients and their relatives?

Solution

  1. \(P(X\le 2|\lambda t = 2)= \sum_{i=0}^2 \dfrac{e^{-\lambda t}(\lambda t)^i}{i!}\)
    #cdf of poisson
    ppois(2,lambda=2*2)
## [1] 0.2381033
  1. First let's define the problem. Define \(n_p\) as the number of patients and \(n_c\) is the number of company. We want \(n_p + n_c \ge 10\) with probability 50% or higher for a given \(t^*\). Or to paraphrase, we want \(n_p + n_c \le 9\) w.p. 50% or lower.

    What is \(n_c\) affected by? \(n_p\). It is actually a binomial distribution problem. \(P(n_c = i|n_p) = \binom{n_p}{i} (0.5)^i*(0.5)^{n_p-i}\). It is even better if we use cdf \(P(n_c \le k|n_p) = \sum_{i=0}^{k} \binom{n_p}{i} (0.5)^i*(0.5)^{n_p-i}\).

    We know the arrival of the patients is distributed with poisson. So, \(P(n_p = j|\lambda t^*) = \dfrac{e^{-\lambda t}(\lambda t)^j}{j!}\). So \(P(j + k \le N) = \sum_{a=0}^j P(n_p = a|\lambda t^*)*P(n_c \le N-a | n_p = a)\). Remember it is always \(n_c \le n_p\).

    #Let's define a function
    calculate_probability<-function(N=9,t_star=1,lambda=2){
        #N is the max desired number of patients
        the_prob<-0
        for(n_p in 0:N){
            the_prob <- the_prob + dpois(n_p,lambda=lambda*t_star)*pbinom(q=min(N-n_p,n_p),size=n_p,prob=0.5)
        }

        return(the_prob)

    }

    #Try different t_stars so probability is below 0.5
    calculate_probability(t_star=2)
## [1] 0.8631867
    calculate_probability(t_star=3)
## [1] 0.5810261
    calculate_probability(t_star=3.3)
## [1] 0.4905249
  1. Two friends (A and B) agree to meet on 4:00 PM. A usually arrives between 5 minutes early and 5 minutes late. B usually arrives between 5 minutes early and 15 minutes late. Their times of arrival are independent from each other.

    1. What is the probability that B arrives definitely later than A?
    2. What is the expected time that A waits B?
    3. What is the probability that both meet early?

Solution

  1. \(P(B > 5) = \dfrac{5 - (-5)}{15 - (-5)} = 1/2\)
  2. \(E[B] - E[A] = 5 - 0 = 5\)
  3. \(P(B < 0, A < 0) = P(B < 0) P(A < 0) = 5/20 * 5/10 = 1/8\)
  1. There are three computers, which provides answers to questions with speed according to exponential distribution with means (\(1/\lambda\)) 6, 4 and 3 per hour, respectively. What is the probability that at least one machine provides an answer within the first hour?

Solution

\[P(X < x) = 1 - e^{-\lambda x}\]

\[P(X > x) = e^{-\lambda x}\]

The solution is 1 - no machine provides an answer within the hour \(1 - P(X_1 > 1, X_2 > 1, X_3 > 1)\).

\[1 - P(X_1 > 1, X_2 > 1, X_3 > 1) = 1 - e^{-\lambda_1 - \lambda_2 - \lambda_3}\]

    1 - pexp(1,rate=3+4+6)
## [1] 0.000002260329
  1. A pack of flour contains 1 kg of flour. Though a flour pouring machine has a standard deviation of 50 gr.

    1. What is the probability that a randomly selected package contains between 925-1075 grams of flour?
    2. If a proper flour package should contain between 1000-x and 1000+x grams of flour, what should x be that 80% of the packages are deemed proper?
    3. Your customer strictly declared that 95% of the packages should contain at least 1000 grams of flour, so you should adjust the mean value. What should be the new mean value?

Solution

We have \(\mu = 1000,\ \sigma = 50\). Define \(\Phi(.)\) as the cdf of the standard normal distribution.

  1. \(\Phi(\dfrac{1075-1000}{50})-\Phi(\dfrac{925-1000}{50})\)
  2. Find an x that \(\Phi(\dfrac{1075-1000}{50})-\Phi(\dfrac{925-1000}{50}) = 0.8\) approximately. The answer is more like how many standard deviations. We can find it by searching for a quantile of \(\alpha=(1-0.8)/2 = 0.1\). Then find the \(y\) \(\Phi(y)=1-\alpha\). \(y = 1.282\) so reverse the procedure from standard normal to N(\(\mu = 1000,\ \sigma = 50\)) by \(y * \sigma\) to find \(x\).
  3. Your \(\Phi(\dfrac{1000 - \mu}{50}) = 0.05\). The quantile value for 0.05 is -1.645. So, 1000 - 50*(-1.645) = 1082.25.
#a
pnorm(1075,mean=1000,sd=50)-pnorm(925,mean=1000,sd=50)
## [1] 0.8663856
#b
qnorm(0.9,sd=50)
## [1] 64.07758
#c
1000-qnorm(0.05,sd=50)
## [1] 1082.243
  1. Suppose the the pdf of a random variable \(x\) is \(f(x) = \dfrac{a}{(1-x)^0.5}\) for \(0 < x < 1\) and \(0\) for other values of x.
  1. Find the constant \(a\) and sketch pdf with R.

Integral of \(f(x)\) should be 1. So \(\int_0^1 f(x) dx = a*(-2(1-x)^{1/2})|_0^1 = 2a\). Then \(a = 1/2\).

plot(seq(0,1,by=0.01),0.5*(1-seq(0,1,by=0.01))^0.5)

  1. Find cdf value of F(X < 1/4).

Use the same integral \(\int_0^{1/4} f(x) dx = -(1-x)^1/2 dx = 1 - (3/4)^(1/2) = 0.134\)