

Dear R users,
I´m trying to optimize simultaneously two binomials inequalities (used in
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:
(1alpha) <= 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,1alpha)
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:
/* function 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 < 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?
// (1alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta
It was used "betha" parameter name to avoid the 'beta' function used in
Mathematica...
findS < function(p1='numeric', lot_size='numeric', alphamax='numeric',
bethamax ='numeric', p2max ='numeric')
{
(1  alpha) <= pbinom(c, sample_n, p1) && betha >= pbinom(c,
sample_n, p2)
&& 0 < alpha < alphamax && 0 < betha < bethamax
&& 1 < sample_n <= lot_Size && 0 <= c < lot_size
&& p1 < p2 < p2max ;
}
Parameters:
p1=0.005,
lot_size=1000,
alphamax=0.05,
bethamax =0.05,
p2max = 0.04
Minimize results should return/printing the following values:
sample_n, (minimal sample size)
c , (critical level of defectives)
alpha , (producer's risk)
betha , (consumer's risk)
p2max (consumer's probability p2)
Could one help me understand how can desing the optimize nonlinear function
using R for two binomials or point me some tips?
Thanks in advance.
EToktar
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


I saw your post on 7/29, and I have not seen a reply, so I will
attempt a response to the question at the start of your email:
obtain the smallest value of 'n' (sample size)
satisfying both inequalities:
(1alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta,
where alpha, p1, p2, and beta are given, and I assume that 'c' is also given, though that's not perfectly clear to me.
Since 'n' is an integer, standard optimizers like optim and nlm are not really appropriate. This sounds like integer programming. RSiteSearch('integer programming', 'fun') just produced 138 hits for me. You might find something useful there.
However, before I tried that, I'd try simpler things first. Consider for example the following:
c. < 5
# I used 'c.' not 'c', because 'c' is the name of a function in R.
alpha < .05
beta < .8
p1 < .2
p2 < .9
n < c.:20
p.1 < pbinom(c., n, p1)
p.2 < pbinom(c., n, p2)
good < (((1alpha) <= p.1) & (p.2 <= beta))
min(n[good])
op < par(mfrow=c(2, 1))
plot(n, p.1)
abline(h=1alpha)
plot(n, p.2)
abline(h=beta)
par(op)
In this case, n = 6 satisfies both inequalities, though n = 15 does not. If min(n[good]) = Inf either no solution exists or you need to increase the upper bound of your search range for 'n'.
If you'd like more help, PLEASE do read the posting guide ' http://www.Rproject.org/postingguide.html' and provide commented, minimal, selfcontained, reproducible code.
Hope this helps.
Spencer Graves
[hidden email] wrote:
> Dear R users,
>
> I´m trying to optimize simultaneously two binomials inequalities (used in
> 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:
>
> (1alpha) <= 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,1alpha)
> 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:
>
> /* function 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 < 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?
>
> // (1alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta
> It was used "betha" parameter name to avoid the 'beta' function used in
> Mathematica...
>
>
> findS < function(p1='numeric', lot_size='numeric', alphamax='numeric',
> bethamax ='numeric', p2max ='numeric')
> {
> (1  alpha) <= pbinom(c, sample_n, p1) && betha >= pbinom(c,
> sample_n, p2)
> && 0 < alpha < alphamax && 0 < betha < bethamax
> && 1 < sample_n <= lot_Size && 0 <= c < lot_size
> && p1 < p2 < p2max ;
> }
>
> Parameters:
> p1=0.005,
> lot_size=1000,
> alphamax=0.05,
> bethamax =0.05,
> p2max = 0.04
>
>
> Minimize results should return/printing the following values:
> sample_n, (minimal sample size)
> c , (critical level of defectives)
> alpha , (producer's risk)
> betha , (consumer's risk)
> p2max (consumer's probability p2)
>
>
> Could one help me understand how can desing the optimize nonlinear function
> using R for two binomials or point me some tips?
>
>
> Thanks in advance.
>
> EToktar
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Just a quick follow up to Spencer's post, you might want to look at the
AcceptanceSampling package on CRAN:
http://cran.rproject.org/web/packages/AcceptanceSampling/index.htmlHTH,
Marc Schwartz
on 08/05/2008 09:00 AM Spencer Graves wrote:
> I saw your post on 7/29, and I have not seen a reply, so I will
> attempt a response to the question at the start of your email:
> obtain the smallest value of 'n' (sample size)
> satisfying both inequalities:
> (1alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta,
> where alpha, p1, p2, and beta are given, and I assume that 'c' is also
> given, though that's not perfectly clear to me.
> Since 'n' is an integer, standard optimizers like optim and nlm
> are not really appropriate. This sounds like integer programming.
> RSiteSearch('integer programming', 'fun') just produced 138 hits for
> me. You might find something useful there.
> However, before I tried that, I'd try simpler things first.
> Consider for example the following:
> c. < 5
> # I used 'c.' not 'c', because 'c' is the name of a function in R.
> alpha < .05
> beta < .8
> p1 < .2
> p2 < .9
> n < c.:20
> p.1 < pbinom(c., n, p1)
> p.2 < pbinom(c., n, p2)
>
> good < (((1alpha) <= p.1) & (p.2 <= beta))
> min(n[good])
>
> op < par(mfrow=c(2, 1)) plot(n, p.1)
> abline(h=1alpha)
> plot(n, p.2)
> abline(h=beta)
> par(op)
>
> In this case, n = 6 satisfies both inequalities, though n = 15
> does not. If min(n[good]) = Inf either no solution exists or you need
> to increase the upper bound of your search range for 'n'.
> If you'd like more help, PLEASE do read the posting guide
> ' http://www.Rproject.org/postingguide.html' and provide commented,
> minimal, selfcontained, reproducible code.
>
> Hope this helps. Spencer Graves
>
> [hidden email] wrote:
>> Dear R users,
>>
>> I´m trying to optimize simultaneously two binomials inequalities (used in
>> 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:
>> (1alpha) <= 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,1alpha)
>> 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:
>>
>> /* function 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 < 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?
>>
>> // (1alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <= beta
>> It was used "betha" parameter name to avoid the 'beta' function used in
>> Mathematica...
>>
>>
>> findS < function(p1='numeric', lot_size='numeric', alphamax='numeric',
>> bethamax ='numeric', p2max ='numeric')
>> {
>> (1  alpha) <= pbinom(c, sample_n, p1) && betha >= pbinom(c,
>> sample_n, p2)
>> && 0 < alpha < alphamax && 0 < betha < bethamax && 1 <
>> sample_n <= lot_Size && 0 <= c < lot_size
>> && p1 < p2 < p2max ;
>> }
>>
>> Parameters:
>> p1=0.005, lot_size=1000, alphamax=0.05, bethamax
>> =0.05, p2max = 0.04
>>
>>
>> Minimize results should return/printing the following values:
>> sample_n, (minimal sample size)
>> c , (critical level of defectives)
>> alpha , (producer's risk)
>> betha , (consumer's risk)
>> p2max (consumer's probability p2)
>>
>>
>> Could one help me understand how can desing the optimize nonlinear
>> function
>> using R for two binomials or point me some tips?
>>
>>
>> Thanks in advance.
>>
>> EToktar
>>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks Mr. Graves for your support.
> I saw your post on 7/29, and I have not seen a reply,
> so I will attempt a response to the question at the start of
> your email:
>
> obtain the smallest value of 'n' (sample size) satisfying
> both inequalities:
>
> (1alpha) <= pbinom(c, n, p1) && pbinom(c,
> n, p2) <= beta,
>
> where alpha, p1, p2, and beta are given, and I assume that
> 'c' is also given, though that's not perfectly clear to me.
Ok, the 'c' starts from 0 and the limit was sptipulate to lot size limit
(N). When the c value is increased, the OC curve is shifted to the right.
I'm using the lot size concept because the hypergeometric accetance model
that I'm using too.
>
> Since 'n' is an integer, standard optimizers like
> optim and nlm are not really appropriate. This sounds like
> integer programming. RSiteSearch('integer programming',
> 'fun') just produced 138 hits for me. You might find
> something useful there.
Thanks, I'm searching...
>
> However, before I tried that, I'd try simpler things
> first. Consider for example the following:
>
> c. < 5
> # I used 'c.' not 'c', because 'c' is the name of a function in R.
> alpha < .05
> beta < .8
> p1 < .2
> p2 < .9
>
> n < c.:20
> p.1 < pbinom(c., n, p1)
> p.2 < pbinom(c., n, p2)
>
> good < (((1alpha) <= p.1) & (p.2 <= beta))
> min(n[good])
>
> op < par(mfrow=c(2, 1))
> plot(n, p.1)
> abline(h=1alpha)
> plot(n, p.2)
> abline(h=beta)
> par(op)
>
> In this case, n = 6 satisfies both inequalities,
> though n = 15 does not. If min(n[good]) = Inf either no
> solution exists or you need to increase the upper bound of
> your search range for 'n'.
I did an interactive method before, but not using an R optimizer method.
findN < function(N, p2, beta, c.)
{ for (ss in c.:N) ## 'j' is the sample size value
if (pbinom(c., ss, p2) <= beta) return (ss);
return (N); # bad search, limit is the lot size N
}
findC < function(N, p1, Alpha, c., k)
{ for (d in c.:N)#'i' is the quantile value (defective)
if (pbinom(d, k, p1) >= Alpha) return(d);
return(N); # bad search, limit is the lot size N
}
recur.binom < function(N, p1, p2, alpha, beta)
{
c. < 0; k < 0; conf.level < (1  alpha)
while (1) {
k < findN(N, p2, beta, c.);
if (pbinom(c., k, p1) >= conf.level) break
else c. < findC(N, p1, conf.level, c., k); }
cat(paste(" Acceptance Number 'c' : ", c. ," Sample number 'k' : ",
k,"\n"));
cat(paste(" Confidence Level=",pbinom(c., k, p1) * 100,"%\n"));
prob < seq(0.0001,0.15,by=0.001);
Pb < pbinom(c., k, prob);
plot(prob, Pb, type='l');
}
recur.binom(N = 600, p1 = 0.01, p2 = 0.08, alpha = 0.05, beta = 0.05)
Sample number 'k' : 77 Acceptance Number 'c' : 2
Confidence Level= 95.76 %
I'll trying modified this case and use your suggestion, perhaps changing the
p2 definition(Consumer option) as the maximum value and not fixed value used
in my example, the same to alpha and beta values, giving a more flexible
model to optimize.
>
> If you'd like more help, PLEASE do read the posting
> guide ' http://www.Rproject.org/postingguide.html' and
> provide commented, minimal, selfcontained, reproducible code.
>
> Hope this helps.
> Spencer Graves
>
Ok, this was my first post. My apologise for the inconvenient.
Thank you very much!!
Etoktar
+55 (21) 91121847
[hidden email]
[hidden email]
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Dear Marc,
I'd been used the acceptance sampling but it is not possible to minimize
given that problem. It fits very well to calculate, but it's necessary have
an acceptance plan defined to assess the probabilities (p1,p2) and consumer
and producer risks...
Thank you for the tips.
EToktar
> Original Message
> From: Marc Schwartz [mailto: [hidden email]]
> Sent: Tuesday, August 05, 2008 1:12 PM
> To: Spencer Graves
> Cc: [hidden email]; [hidden email]
> Subject: Re: [R] optimize simultaneously two binomials
> inequalities using nlm( ) or optim( )
>
> Just a quick follow up to Spencer's post, you might want to
> look at the AcceptanceSampling package on CRAN:
>
> http://cran.rproject.org/web/packages/AcceptanceSampling/index.html>
> HTH,
>
> Marc Schwartz
>
>
> on 08/05/2008 09:00 AM Spencer Graves wrote:
> > I saw your post on 7/29, and I have not seen a reply,
> so I will
> > attempt a response to the question at the start of your email:
> > obtain the smallest value of 'n' (sample size) satisfying both
> > inequalities:
> > (1alpha) <= pbinom(c, n, p1) && pbinom(c, n,
> p2) <= beta,
> > where alpha, p1, p2, and beta are given, and I assume that
> 'c' is also
> > given, though that's not perfectly clear to me.
> > Since 'n' is an integer, standard optimizers like
> optim and nlm
> > are not really appropriate. This sounds like integer programming.
> > RSiteSearch('integer programming', 'fun') just produced 138
> hits for
> > me. You might find something useful there.
> > However, before I tried that, I'd try simpler things first.
> > Consider for example the following:
> > c. < 5
> > # I used 'c.' not 'c', because 'c' is the name of a function in R.
> > alpha < .05
> > beta < .8
> > p1 < .2
> > p2 < .9
> > n < c.:20
> > p.1 < pbinom(c., n, p1)
> > p.2 < pbinom(c., n, p2)
> >
> > good < (((1alpha) <= p.1) & (p.2 <= beta))
> > min(n[good])
> >
> > op < par(mfrow=c(2, 1)) plot(n, p.1)
> > abline(h=1alpha)
> > plot(n, p.2)
> > abline(h=beta)
> > par(op)
> >
> > In this case, n = 6 satisfies both inequalities,
> though n = 15
> > does not. If min(n[good]) = Inf either no solution exists
> or you need
> > to increase the upper bound of your search range for 'n'.
> > If you'd like more help, PLEASE do read the posting guide
> > ' http://www.Rproject.org/postingguide.html' and provide
> commented,
> > minimal, selfcontained, reproducible code.
> >
> > Hope this helps. Spencer Graves
> >
> > [hidden email] wrote:
> >> Dear R users,
> >>
> >> I´m trying to optimize simultaneously two binomials inequalities
> >> (used in 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:
> >> (1alpha) <= 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,1alpha)
> >> 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:
> >>
> >> /* function 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 < 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?
> >>
> >> // (1alpha) <= pbinom(c, n, p1) && pbinom(c, n, p2) <=
> beta It was
> >> used "betha" parameter name to avoid the 'beta' function used in
> >> Mathematica...
> >>
> >>
> >> findS < function(p1='numeric', lot_size='numeric',
> >> alphamax='numeric', bethamax ='numeric', p2max ='numeric') {
> >> (1  alpha) <= pbinom(c, sample_n, p1) && betha >= pbinom(c,
> >> sample_n, p2)
> >> && 0 < alpha < alphamax && 0 < betha < bethamax
> && 1 <
> >> sample_n <= lot_Size && 0 <= c < lot_size
> >> && p1 < p2 < p2max ;
> >> }
> >>
> >> Parameters:
> >> p1=0.005, lot_size=1000, alphamax=0.05, bethamax
> >> =0.05, p2max = 0.04
> >>
> >>
> >> Minimize results should return/printing the following values:
> >> sample_n, (minimal sample size)
> >> c , (critical level of defectives)
> >> alpha , (producer's risk)
> >> betha , (consumer's risk)
> >> p2max (consumer's probability p2)
> >>
> >>
> >> Could one help me understand how can desing the optimize nonlinear
> >> function using R for two binomials or point me some tips?
> >>
> >>
> >> Thanks in advance.
> >>
> >> EToktar
> >>
______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

