[R] optim(.. ,"SANN",..)

lloyd barcza floydeon at yahoo.com
Fri Nov 20 00:05:19 CET 2009


I have a problem using optim, so I am hoping someone can help me out with it:

Suppose I have the list:

list(D,R,P)
[[1]]
   V1 V2 V3 V4
1   0  1  0  1
2   1  1  0  0
3   1  0  1  0
4   0  0  1  1
5   0  1  0  1
6   1  1  0  0
7   1  0  1  0
8   0  0  1  1
9   1  0  1  0
10  0  0  1  1

[[2]]
 [1]   23   85   12   73   23   24   25   56   78 1200

[[3]]
      V1
1     25
2     80
3     15
4     60
5     56
6     15
7     20
8     70
9     45
10 12000

and the strange function fr which I want to maximise:

fr<-function(x){y<-x*D
C<-apply(t(apply(y,1,function(c){c[c>0]})),1,prod)
R2<-R*C
w<-R2[R2<P]
g<-sum(w)
return(g)}

v<-c(1,1,1,1,1,1,1,1,1,1)

res <- optim(v, fr, method="SANN",
              control=list(maxit=200, temp=20,v))

I get the following error:
Error in prod(..., na.rm = na.rm) : invalid 'type' (list) of argument

I'm not sure if its because this function is too disjoint to be opimised using SANN or I am not using optim properly. 

Any help or suggestions would be appreciated.

Thanks




More information about the R-help mailing list