In: Statistics and Probability
Use R Studio to solve this problem.
A simple electronic device consists of two components which have failure times which may be modeled as independent exponential random variables. The first component has a mean time to failure of 3 months, and the second has a mean time to failure of 6 months.
(a) If the electronic device will fail when either of the components fails, use 1000 random samples of the simulated electronic device to estimate the mean and variance of the time to failure for the device.
Hint: Using the appropriate distributions for failure time and appropriate means, generate 1000 samples of Y1 representing failure time of the first component and 1000 samples of Y2 representing failure time of the second component of the 1000 simulated electronic device. Under this scenario, the failure time of the device is the minimum value of Y1i , Y2i for the i th pair. Using this, calculate the mean and variance of the failure time of the device.
(b)If the electronic device will fail when both of the components fail, use 1000 random samples of the simulated electronic device to estimate the mean and variance of the time to failure for the device.
Hint: Under this scenario, the failure time of the device is the maximum value of Y1i , Y2i for the i th pair. Using this, calculate the mean and variance of the failure time of the device.
a) R code with comments
get this
b) R code with comments
get this
All code together is
------------------
#set the random seed for repeatability
set.seed(123)
#part a)
#set the number of samples
n<-1000
#draw n samples of failure times y1 for component 1
y1<-rexp(n,rate=1/3)
#draw n samples of failure times y2 for component 2
y2<-rexp(n,rate=1/6)
#failure time of the device is
y<-pmin(y1,y2)
#print the mean failure time of the device
sprintf('the estimated Mean failure time of the device is
%.4f',mean(y))
#print the variance of failure time of the device
sprintf('the estimated Variance of failure time of the device is
%.4f',var(y))
#part b)
#set the number of samples
n<-1000
#draw n samples of failure times y1 for component 1
y1<-rexp(n,rate=1/3)
#draw n samples of failure times y2 for component 2
y2<-rexp(n,rate=1/6)
#failure time of the device is
y<-pmax(y1,y2)
#print the mean failure time of the device
sprintf('the estimated Mean failure time of the device is
%.4f',mean(y))
#print the variance of failure time of the device
sprintf('the estimated Variance of failure time of the device is
%.4f',var(y))
----------------------