Week 7







1) Uniform Distribution


Let X1, X2, . . . , Xn be n mutually independent random variables, each of which is uniformly distributed on the integers from 1 to k. Let Y denote the minimum of the Xi’s. Find the distribution of Y .

Y <- integer(100)

k<-100

for (n in 1:k) {
  x<-floor(runif(n,1,k))
  Y[n]<-min(x)
}

plot(Y, ylab = "Y", xlab="n", main = "Min(runif(n,1,k)")


The above distribution can be described as tailing to zero quickly and leveling off. It does exhibit occassional outliers. This might be a good model for certain real life events that the bernoulli distributions below do not.




  1. Your organization owns a copier (future lawyers, etc.) or MRI (future doctors). This machine has a manufacturer’s expected lifetime of 10 years. This means that we expect one failure every ten years. (Include the probability statements and R Code for each part.).


  1. What is the probability that the machine will fail after 8 years?. Provide also the expected value and standard deviation. Model as a geometric. (Hint: the probability is equivalent to not failing during the first 8 years..)




Geometric



The geometric model evaluates the probability of first “success” on a given trial


# To answer the question, subtract the pgeom from 1. 

# pgeom returns the first success (machine fails) on trials 0 thru 8


n=8
p=.1

print(paste("Probability the machine fails after the 8th year is ", 1- pgeom(n, p)))
## [1] "Probability the machine fails after the 8th year is  0.387420489"
# this is the same as multiplying above by .1
print(paste("Probability the machine fails on the 9th year is ", dgeom(9, p)))
## [1] "Probability the machine fails on the 9th year is  0.0387420489"
print(paste("Standard Deviation = sqrt((1-p)/p^2) or ", sqrt((1-p)/(p^2)))) 
## [1] "Standard Deviation = sqrt((1-p)/p^2) or  9.48683298050514"
print(paste("Expected Value = 1/p or ", 1/p))
## [1] "Expected Value = 1/p or  10"


Heres the distribution…


plot(dgeom(x=seq(0,20), prob=.1), type = "s", xlab="Year", ylab = "P(1st Failure)", main = "Geometric PMF")


Exponential




n=8
lambda=.1

print(paste("Probability of failure anytime after 8 years is ", 1 - pexp(n,lambda)))
## [1] "Probability of failure anytime after 8 years is  0.449328964117222"
print(paste("Probability of failure on the 9th year is ", dexp(n,lambda)))
## [1] "Probability of failure on the 9th year is  0.0449328964117222"
# note  dexp(n,lambda) is the same as .1 * (1 - pexp(n,lambda)

print(paste("Standard Deviation = sqrt(1/lambda^2) or ",sqrt(1/lambda^2)))
## [1] "Standard Deviation = sqrt(1/lambda^2) or  10"
print(paste("Expected Value = 1/lambda ", 1/lambda))
## [1] "Expected Value = 1/lambda  10"


Heres the distribution…


plot(dexp(0:20, rate = .1), xlab="Year", ylab = "P(1st Failure)", type = "s", main = 'Exponential PMF')


Binomial






The Binomial PMF is mathematically related to the Geometric PMF (as well as the negative binomial).


All 3 use \(P(x)^r(1-P(X))^{n-r}\) and only differ in the way \({n \choose r}\) is applied.


# 8 of 8 years of "success" at .9 is the same as 0 of 8 years at .1, i thought 8 of 8 at .9 was more intuitive

r=8             
n=8
p=.9

print(paste("Probability of failure anytime after 8 years is ", dbinom(r, size=n, prob=p)))
## [1] "Probability of failure anytime after 8 years is  0.43046721"
print(paste("Probability of failure on the 9th year is ", .1 * dbinom(r, size=n, prob=p)))
## [1] "Probability of failure on the 9th year is  0.043046721"
print(paste("Standard Deviation = n * p * (1=p) or ", n*p*(1-p)))
## [1] "Standard Deviation = n * p * (1=p) or  0.72"
print(paste("Expected Value = n * p or ", n*p))
## [1] "Expected Value = n * p or  7.2"


Heres the distribution…


# note these 2 are equivalent...

plot(dbinom(0:20, size=0:20, prob=0.9), type = "s", ylab = "P(1st Failure)", main = "Binomial PMF")

# plot(dbinom(0, size=0:20, prob=0.1), type = "s", ylab = "P(1st Failure)", main = "Binomial PMF")




Poisson




The discrete Poisson PMF is mathematically related to the continuous Exponential PDF.


Whereas the other distributions in this homework infer an equal proability at every time slice, the Poisson distribution infers an increased likelihood that an event occurs around the time interval.



n=8
lambda=10

print(paste("Probability the machine fails after the 8th year is ", 1- ppois(n, lambda)))
## [1] "Probability the machine fails after the 8th year is  0.667180321249281"
print(paste("Probability the machine fails on the 9th year is ", dpois(n, lambda)))
## [1] "Probability the machine fails on the 9th year is  0.11259903214902"
print(paste("Standard Deviation = sqrt(lambda * t) or ", sqrt(lambda*n)))
## [1] "Standard Deviation = sqrt(lambda * t) or  8.94427190999916"
print(paste("Expected Value = lambda * t or ", lambda * n))
## [1] "Expected Value = lambda * t or  80"


Heres the distribution…


plot(dpois(0:20, lambda), type = "s", ylab = "P(1st Failure)", xlab="Year", main = "Poisson PMF")