[R] optim error

From: <keunhchoi_at_gmail.com>
Date: Sat, 31 May 2008 19:07:55 -0800


I saw a similar question but I still don't fully understand how to implement optim.
Can someone help me out with this?
Thanks. Keun-Hyung

> vol<-rep(c(0.03, 0.5, 2, 4, 8, 16, 32), 3)
> time<-rep(c(2,4,8),each=7)
> p.mated<-c(0.47, 0.48, 0.43, 0.43, 0.26, 0.23, "null", 0.68, 0.62, 0.64,
0.58, 0.53, 0.47,
+ 0.24, 0.8, 0.79, 0.71, 0.56, 0.74, 0.8, 0.47)
> eury<-as.data.frame(cbind(vol, time, p.mated))
> eury<-eury[-7,]; eury

    vol time p.mated

1  0.03    2    0.47
2   0.5    2    0.48
3     2    2    0.43
4     4    2    0.43
5     8    2    0.26
6    16    2    0.23
8  0.03    4    0.68
9   0.5    4    0.62
10    2    4    0.64
11    4    4    0.58
12    8    4    0.53
13   16    4    0.47
14   32    4    0.24
15 0.03    8     0.8
16  0.5    8    0.79
17    2    8    0.71

18 4 8 0.56
19 8 8 0.74
20 16 8 0.8
21 32 8 0.47
>
> p0<- c(f=0.87, b=0.1, c=150)
> eury.fit <- function (f, time, vol)
+ {
+             f<-p[1]; b<-p[2]; c<-p[3]
+             p.mated = p[1] * ( (1 -
exp(-p[2]*time))-(p[2]/(p[2]-(p[3]/vol)))
+                            * (exp(-p[3]/vol*time)-exp(-p[2]*time)))
+ }
> eury.opt<- optim(p0, fn=eury.fit, NULL, method = "BFGS", hessian = TRUE)
Error in fn(par, ...) : argument "time" is missing, with no default

        [[alternative HTML version deleted]]



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 Mon 02 Jun 2008 - 04:13:24 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 Mon 02 Jun 2008 - 07:30:38 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