[R] optimize function help!!

From: <emir.toktar_at_computer.org>
Date: Mon, 21 Jul 2008 16:35:27 -0300


Dear R users,

Im trying to optimize simultaneously two binomials inequalities used to acceptance sampling, which are nonlinear solution, so there is no simple direct solution.
The 'n' represents the sample size and the 'c' an acceptance number or maximum number of defects (nonconforming) in sample size.

The objective is to obtain the smallest value of 'n' (sample size) satisfying both inequalities:

      (1-alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta

--> where p1 and p2 are probabilities (Consumer and Producer risks);

Considering that the 'n' and 'c' values are integer variables, it is commonly not possible to derive an OC curve including the both (p1,1-alpha) and (p2,beta) points. Some adjacency compromise is commonly required, achieved by searching a more precise OC curve with respect to one of the points.

Im using Mathematica 6 but it is a Trial, so I would like use R intead (better, I need it)!
In Mathematica I call a parameter called restriction:   

  // fucntion name "findOpt" and parameters...

  restriction = (1 - alpha) <= CDF[BinomialDistribution[sample_n, p1], c] &&

           betha >= CDF[BinomialDistribution[sample_n, p2], c] &&
   		     0 < alpha < alphamax && 0 < betha < bethamax && 
           1 < sample_n <= lot_Size &&
           0 <= c < amostra   && 
           p1 < p2 < p2max ;
   

   fcost = sample_n/lot_Size;    

  result = NMinimize[{fcost, restriction}, {sample_n, c, alpha, betha, p2max},

            Method -> "NelderMead", AccuracyGoal -> 10];

  example:

          findOpt[0.005, 1000, 0.05, 0.05, 0.04] ==> and I got the return of values of; "n", "c",
  alpha and betha, computed.

	{0.514573, {alpha$74 -> 0.0218683, sample_n$74 -> 155.231, 
	  betha$74 -> 0.05, c$74 -> 2, p2$74 -> 0.04}}
  

  .:. Note that Im using lot_Size because I'm using hypergeomtric in some situations...   

  Using R, I would define the "pbinom(c, n, prob)" given only the minimum and maximum values to "n" and "c" and limits to p1 and p2 probabilities (Consumer and Producer).

The optimize I could define only using the p1 point, because the "n" and "c" values, are integers and I couldnt run the example like in mathematica.     

Could anyone help me   

Thank you very much.

Emir Toktar
emir.toktar_at_computer.org



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 22 Jul 2008 - 08:43:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Jul 2008 - 09:32:03 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive