# [R] optimize simultaneously two binomials inequalities using nlm

From: <emir.toktar_at_gmail.com>
Date: Tue, 29 Jul 2008 16:40:58 -0300

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. Please, let me explain shortly the the problem and the question as following.

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 (AQL) and p2 (LTPD) are probabilities parameters (Consumer and Producer), the alpha and beta are conumer and producer risks, and finally, the 'n' represents the sample size and the 'c' an acceptance number or maximum number of defects (nonconforming) in sample size.

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.

I´m using Mathematica 6 but it is a Trial, so I would like use R intead (or better, I need it)!

To exemplify, In Mathematica I call the function using NMinimize passing the restriction 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 < lot_size
&&  p1 < p2 < p2max ;

fcost = 	sample_n/lot_Size;

```

result = NMinimize[{fcost, restriction}, {sample_n, c, alpha, betha, p2max}, Method -> "NelderMead", AccuracyGoal -> 10];

/* Calling the function findOpt */

findOpt[p1=0.005, lot_size=1000, alphamax=0.05, bethamax =0.05, p2max = 0.04]

/* and I got the return of values of; minimal "n", "c", "alpha", "betha" and
the "p2" or (LTPD) were computed */ {0.514573, {alpha\$74 -> 0.0218683, sample_n\$74 -> 155.231, betha\$74 -> 0.05, c\$74 -> 2, p2\$74 -> 0.04}}

Now, 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), similar on the example above.

I found some examples to optimize equations in R and some tips, but I not be able to define the sintaxe to use with that functions. Among the functions that could be used to resolve the problem presented, I found the function optim() that it is used for unconstrained optimization and the nlm() which is used for solving nonlinear unconstrained minimization problems. May I wrong, but the nlm() function would be appropriate to solve this problem, is it right?

Can I get a pointer to solve this problem using the nlm() function or where could I get some tips/example to help me, please?

Thank you very much.

EToktar

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 29 Jul 2008 - 20:43:08 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 29 Jul 2008 - 21:33:10 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.