Cost Benefit Analysis of Pre-screening Widgets for Faults before they Fail I want to build a model that determines whether to pre-screen my widgets for defects.  If I do pre-screen, it costs a fixed amount per check and I resolve the problem 100% of the time.  If I don't pre-screen, its cost will be the cost of fixing the problem, plus the cost of materials for expired inventory.  I have a whole bunch of variables that impact whether a defect will occur in each particular widget, but if it does occur and I didn't pre-screen it, it will definitely result in a fixed repair cost and a variable expired inventory cost based on cost of materials.  For each widget, I need to know if the expected cost of the defect exceeds or is less than the cost of pre-screening.
Things I know:


*

*A - Cost of pre-screening

*B - Model to Predict Whether it will fail - based on test data - of ones
it says it won't have a defect, it is right 98.5% of the time (false negatives).

*C -Model to Predict expected cost of Raw Materials for each widget produced

*D - % of repairs that will be successful and result in no expired inventory cost

*E - Fixed Cost of Repairs


Therefore, I should screen if:
A - B*(E+C*D) > 0
I have all of these pieces, but I don't know how to build this into a model.
Anyone with R or Stata skills, I would appreciate being pointed in the direction of a good package to use for building this model.
 A: Considering my predilection for R, I am going to do something unlikely: I would advise you not to use R or any other program.  If you agree to the principle that the production should be done correctly, I think you would agree with the principle that determining the inspection criteria and the inspection itself should be as simple as possible (but you can call it a "decision tree" to justify your title):  
Question 1: Is the supply of your part stable?
A1 == NO. Considering a type of widget: if the supply of this widget is not in a state of control, strongly consider 100% inspection (Deming, 1986).  DONE.
A1 == YES.  OK. . . 
Question 2: Does the cost of testing outweigh the cost of not testing? 
If the supply of this part is in control, you can adopt an all-or-nothing testing strategy (Deming, 1986), given:
p   = [historic] average percent defective [from] incoming lots of parts 
      (e.g. received 100 widgets Friday, 3 defective; p = 3%).  
      Remember: stable process exists! 
k   = cost to inspect one part
l   = cost to dismantle, repair, reassemble, and test an assembly that 
      fails because a defective part was put into the production line.
k/l = break even quality, or break-even point (always between 0 and 1)

A2 == NO. If p > k/l inspect 100%.  You will save money with each inspection by preventing expensive mistakes further down the production line.  DONE.
A2 == YES. If p < k/l inspect 0%.  You will lose money with each inspection by spending valuable time inspecting parts that are most likely acceptable.  DONE.
The statistical proof of this is "exceedingly simple," but involves a chart which I might attempt to reproduce later if I'm feeling ambitious.  I would encourage you to find a copy of the text which I created this answer from:

Deming, W. E. (1986). Out of the Crisis (Ch 15). Cambridge, MA: MIT 
  Center for Advanced Engineering Study.

