0

I encountered an error message as above when I tried to optimize few parameters in a function, I've tried to shrink the range of parameter values but the error still exits. Could you kindly tell me what would be the cause of such error? BTW, I actually reproduced the same error message when I use GA package of MCGA. Many thanks! code:

c<-1
e<-2
f<-3
g<-4
posneg.ratio <- function(x) {
lambda_a<-x[1]
lambda_b<-c(x[2],x[3])
lambda_c<-x[4]
random_effect<-factor_comp (lambda_a,lambda_b,lambda_c,e,f,g)
m<-random_effect$factor_a$b1
pos<-abs(sum(m > 0])
neg<-abs(sum(m < 0])
n<-neg/pos 
return(n)
}
lower = c(0.5,0.09,0.05,7)
upper = c(0.9,0.2,0.1,12)
DEoptim(posneg.ratio,lower,upper)
Hao
  • 59
  • 6
  • Please provide an example of the problem: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Mikko Dec 19 '13 at 06:42
  • Why not try to `debug` and find out where does the error come from? Without a reproducible example, it is impossible to give you a solution. – alittleboy Dec 19 '13 at 06:59
  • Ok, this is a start. Add `library(DEoptim)` at the beginning of the code. In general it is a good practice trying to run the code from a clean workspace (no additional packages installed) to see whether it works for others. What is `factor_comp` function? Is it from a package or your own function? Also you have a mistake in brackets of `abs(sum(m > 0]))` – Mikko Dec 19 '13 at 11:05

1 Answers1

0

Thank you all the answers, the error actually came from my function definition of function*(x)*, the x messed up with one of the variable of x defined in rest of the function, my bad, when I changed to function(xe) and xe[1], xe[2]... the error disappears. This is also a good lesson for me not to define any varaible with "x", "y", "z", "n" those commonly used names.

Hao
  • 59
  • 6