Problem 1

Bayes Theorem: \[ P(A|B) = \frac{P(B|A)P(A)}{P(B)}\]

P_positive_hiv = 0.96
P_hiv = 0.001
P_positive_nonhiv = 1 - 0.98
P_nonhiv = 1 - P_hiv

P = (P_positive_hiv * P_hiv) / ((P_positive_hiv * P_hiv) + (P_positive_nonhiv * P_nonhiv))
P
## [1] 0.04584527

According to the theorem the probility the person has HIV is 4%.

Since we know the prevalence is 0.1% we can determine how many people are likely to test postive we can estimate what the cost will be.

tested = 100000
prevelance = 0.001

positive_cost = 100000 * (tested*prevelance)
negative_cost = 1000 * (tested *(1 - prevelance))

positive_cost + negative_cost
## [1] 109900000

Problem 2

Now we will need to use the binomial formula

2 inspections in 24 months.

p = 0.05
x = 2
n = 24
n_f = factorial(n)
x_f = factorial(x)
nx_f = factorial(n-x)

P = (n_f / (x_f*nx_f)) * ((p^x) * (1-p)^(n-x))
P
## [1] 0.2232381

To determine the probability we use the function pbinom which takes the area under the curve for us. Setting lower.tail to false gives us the are right of the curve. So its a 34% chance.

pbinom(1, 24, 0.05, lower.tail = FALSE)
## [1] 0.3391827

Now since its lower than 2 we can just set the lower.tail to true to show us the area to the left of the curve. Which gives a 66% chance to have fewer than 2 inspections in 24 months.

pbinom(1, 24, 0.05, lower.tail = TRUE)
## [1] 0.6608173

Mean: 1.2 standard deviation: 1.55

mean = n*p
sdev = sqrt(n*p*x)

c(mean, sdev)
## [1] 1.200000 1.549193

Problem 3

Here we use the function dpois. It returns a 0.8% chance of 3 arriving in an hour.

dpois(3, 10)
## [1] 0.007566655

Now we will use the function ppois. This will give us the distribution. We use 11 becasue that is more than 10 lower.tail = FALSE because we want more than 10 not 10 or less.

ppois(11, 10, lower.tail = FALSE)
## [1] 0.3032239

On average 80 patients would visit. The standard deviation is 3.

mean = 10
stdev = sqrt(mean)
total_patients = mean*8
c(stdev, total_patients)
## [1]  3.162278 80.000000

On average combined the family practices would be able to handle 72 patients a day. This means we are missing 8 patients that would normally come. I would recommend staffing up each practice to be able to handle 27 patients, because that will come out to 81 patients.

capacity = 24 * 3
capacity
## [1] 72

Problem 4

Here we use a function called dhyper. This gives us a 7% chance that he innocently picked 5 nurses for the trip.

dhyper(5,15,15,6)
## [1] 0.07586207

Here we use the function E(X)=KM/N. This returns 3. Which makes sense because half are nurses so half that are sent should be nurses.

E = (6*15)/30
E
## [1] 3

This means 3 non nurses should have went.

Problem 5

There is a 70% probability the person is serious car crash in the year. I would not drive there.

pgeom(1200,0.001)
## [1] 0.6992876

With 15 months the probability jumps to 78%.

hours = (1200 / 12) * 15
pgeom(hours, 0.001, lower.tail=TRUE)
## [1] 0.7772602

Here we use E = 1/p. The expected number of hours is 1000

E=1/0.001
E
## [1] 1000

Around a 3% chance.

pgeom(1300, 0.001) - pgeom(1200, 0.001)
## [1] 0.02863018

Problem 6

There is a 2% chance the generator will fail 3 or more times in 1000 hours.

ppois(3, 1, lower.tail = FALSE)
## [1] 0.01898816

The expected value is: 1

Problem 7

Since it’s uniform distribution we can take 10/30 to find the probability of waiting under 10 minutes. So it’s a 67% chance he will wait over 10 minutes.

Since he has already waiting 10 minutes we take 5/20 to calculate the probability of waiting another 5 minutes which is 20%.

Problem 8

We can assumed the expected failure time is 10 years since that’s what the manufacturer stated. Standard deviation is 0.1.

stdv = 1/10
stdv
## [1] 0.1

55% chance the machine fails in 8 years.

pexp(8,0.1)
## [1] 0.550671

8% chance the machine fails within the next 2 years

pexp(10, 0.1) - pexp(8,0.1)
## [1] 0.08144952