[R] optimize function help!!

emir.toktar at computer.org emir.toktar at computer.org
Mon Jul 21 21:35:27 CEST 2008

Dear R users,

I´m 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

I´m 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,
            Method -> "NelderMead", AccuracyGoal -> 10];

  	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 I´m using lot_Size because I'm using hypergeomtric in some

  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 couldn´t run the example like in mathematica.
Could anyone help me 
Thank you very much.

Emir Toktar
emir.toktar at computer.org

More information about the R-help mailing list