The problem is that optimize() has an optional argument "tol" which is
getting confused with the "t" argument in your function, since R tries to
do partial matching on function arguments. If you rename the t argument
to t1 (or anything except "to" or "tol") it will work (I think):
yield <- function(F,N0,M,t1,days,wt,st,st1) {
sum(wt*N0*exp(-(t1-1)*M-F*st1)*(st*F/(M+st*F))*(1-exp(-M-st*F)))
}
optimize(yield,interval=c(0,3),max=T,N0=15.4185,M=0.3,t1=t,
days=days,wt=wt,st=st,st1=st1)
On Wed, 17 Oct 2001, Han Lai wrote:
Hi,
I am trying to write a r-code that maximizes fish yield, which is
summing over a total of 11 months (t=c(1:11)) for one cohort. My code
looks like this:
t <- c(1:11)
days <- 30*t-15
yt <- 6.6*exp(log(12.3/6.6)*(days-126.3)/(189.5-126.3))
wt <- exp(log(0.250206)+2.14418*log(yt))
v0 <- 4; v1 <- 14
st <- (yt-v0)/(v1-v0); st[yt<=v0] <- 0; st[yt>=v1] <-1;
st1 <- cumsum(st)
yield <- function(F,N0,M,t,days,wt,st,st1) {
sum(wt*N0*exp(-(t-1)*M-F*st1)*(st*F/(M+st*F))*(1-exp(-M-st*F))) }
optimize(yield,interval=c(0,3),max=T,N0=15.4185,M=0.3,t=t,days=days,wt=wt,st=st,st1=st1)
Everything is o.k. untile the last one line, which gives the following
error message.
Error in sum(wt * N0 * exp(-(t - 1) * M - F * st1) * (st * F/(M + st *
:
Argument "t" is missing, with no default
Thanks in advance for your helps!
Cheers!
Han
Han-Lin.Lai at noaa.gov
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._