- Details
- Parent Category: Programming Assignments' Solutions
We Helped With This R Language Programming Assignment: Have A Similar One?

Category | Programming |
---|---|
Subject | R | R Studio |
Difficulty | College |
Status | Solved |
More Info | Statistics Homework Help Online |
Short Assignment Requirements
Assignment Description
IE 200: Engineering Statistics
Computing Assignment 3
1. Recall the following question from our lecture:
A laboratory blood test is 95% effective in detecting a certain disease when it is, in fact, present. However, the test also yields a “false positive” result for 1% of the healthy people tested. (That is, if a healthy person is tested, then, with probability 0.01, the test will imply he or she has the disease.) If 0.5% of the population actually has the disease, what is the probability a person has the disease given that the test result is positive?
a) Write a function that gives the probability of interest for the given rates of false positive, effectiveness and disease prevalence. Test your function to make sure that you get the correct probability as we calculated in class, i.e., 0.32.
myprob<-function(a,b,c) # This is the function that will calculate the probability of interest
{
(a*b)/((a*b)+(c*(1-b)))
}
answer1 <-myprob(a=0.95,b=0.005,c=0.01) # We use the function to find the answer
b) Use the function in part (a) to plot the probability of interest for prevalence levels 0—0.5, with the granularity (i.e., step size) of 0.001. Use the command plot and draw a line by setting type="l".
What can you say about the probability of interest at different prevalence levels? Comment on your observation.
c) Additional to the plot from part (b), add two lines of two different colors corresponding to the probability of interest when:
1. The effectiveness is 97.5% (i.e., its original 5% error rate is reduced by 50%).
2. The false positive rate is reduced by 50% to 0.5%.
You can use the command lines. Color line (1) in red and color line (2) in blue.
Which approach is more effective in improving the probability of interest for a low prevalence disease, (1) or (2) in part c above?
2. Consider problem 5 from HW 5.
A shipment of 7 television sets contains 2 defective sets. A hotel makes a random purchase of 3 of the sets. If X is the number of defective sets purchased by the hotel, find the probability distribution of X.
a) Write a generic function in R that can calculate the probability of interest for different values of X, for any number of good television sets, n, any number of defective television sets, m, and any number of sets that the hotel purchases, k. (For instance, in problem 5 from HW 5, n = 5, m = 2, k = 2 and hence for X = 1, the function needs to return 4/7.)
b) Use this function to find the expected value of random variable X, if n = 8, m = 6, k = 3.