[solved]-Using R Language E Read Divided Therd Sum Therd Q38997190
using r language 
![(f) When you execute command herdſtherd==1] youll get a display of cows that been tested positive. Inside the bracket the in](https://media.cheggcdn.com/media/50d/s1024x216/50d584be-754b-4d4a-abff-4ecd1d40a6d0/phpjSgI2Y.png)
for e it should be read as divided by therd not bysum(therd)
Homework 2: Bayes Simulation. We’ll now simulate the test diagnostic using a herd of cattle. The setup is like the previous problem. A blood test that is 98% effective. Generate a herd of 1000 cows. herd=floor(runif(1000)>.95) Since runif() is a random number 0 to 1 setting inequality >.95 will ”infect” 5% of cows. floor() function converts FALSE, TRUE output to integer 0 (healthy) or 1 (infected.) Now create in script function test() test <-function(x){ for (i in 1:length(x)){ if (x[i]==0) x[i]=floor(runif (1)>.98) else x[i]=floor(runif (1)<.98)} return(x) This will test cows using .98 percent accuracy. So that sick cow is tested positive 98% of the time but also healthy cows will be tested as positive 2% of the time. (a) Execute herd and you’ll see the herd values. Most will be zero for healthy and some will be 1 for infected. (b) Execute sum(herd). This will sum up values of herd for the total number of infected cows. Is it consistent with 5% infected? (c) Test the cows with command therd-test (herd) contains test results for the herd. (d) Count number of test positiv cows sum(therd). Why is the test positive herd bigger that actual number of infected cows? (e) Calculate the percent of test positive cows that have disease. sum(herd & therd)/sum(therd). Note, & is AND logic that returns 1 if both inputs are 1. Does your answer agree with theoretical calculation? Try using bigger herd to get better approximations. (f) When you execute command herdſtherd==1] you’ll get a display of cows that been tested positive. Inside the bracket the index indicates to display only cows that tested positive. How many of those are false positives? Is this test any good ? Why? (g) What command would you use to count false negatives? That is infected cows that have tested negative. (h) What changes would you make to improve the test to make it 90% accurate? Do it! Show transcribed image text Homework 2: Bayes Simulation. We’ll now simulate the test diagnostic using a herd of cattle. The setup is like the previous problem. A blood test that is 98% effective. Generate a herd of 1000 cows. herd=floor(runif(1000)>.95) Since runif() is a random number 0 to 1 setting inequality >.95 will ”infect” 5% of cows. floor() function converts FALSE, TRUE output to integer 0 (healthy) or 1 (infected.) Now create in script function test() test .98) else x[i]=floor(runif (1)
Expert Answer
Answer to using r language for e it should be read as divided by therd not by sum(therd)… . . .
OR

