# Simulation of computers failing and heading to the repair shop. # FUNCTION TO SIMULATE N COMPUTERS. Each computer might have a memory failure # or a processor failure. Failures of memory and processor are independent, # and occur with probabilities specified by the arguments. The computer will # be in the repair shop if it has either sort of failure. The result returned # is a list with elements called mem.fail, proc.fail, and in.shop, which are # TRUE/FALSE vectors with one element for each computer. simulate.computers = function (n, pr.mem.fail, pr.proc.fail) { mem.fail = runif(n) < pr.mem.fail proc.fail = runif(n) < pr.proc.fail in.shop = mem.fail | proc.fail list (mem.fail=mem.fail, proc.fail=proc.fail, in.shop=in.shop) } # FUNCTION TO FIND CONDITIONAL PROBABILITIES. Given information on simulated # computers, this function find the conditional probability that a computer has # a memory failure given that it is in the repair shop, and the conditional # probability that it has a memory failure given that it is in the repair shop # and has a processor failure. The argument is the matrix of data on simulated # computers from sim.computers. Value returned is a list containing the two # conditional probabilities. find.cond.prob = function (sim) { list ( mem.fail.given.in.shop = mean (sim$mem.fail [sim$in.shop]), mem.fail.given.in.ship.and.proc.fail = mean (sim$mem.fail [sim$in.shop & sim$proc.fail]) ) }