[R] invalid arguments RUNIF

From: Yasin Hajizadeh <yasin_reservoir_at_yahoo.com>
Date: Tue, 17 Jun 2008 05:53:41 -0700 (PDT)


  Hi all
  I would be grateful you can help me with my problem.   I try to run an optimization code . in one line I have runif in order to sample the PDF. I get this error while i run it.    

  Error in runif(1, f$d[[n.of.u.vars + n.of.o.vars + j]][[2]][1], f$d[[n.of.u.vars + :   invalid arguments    

  Here is a part of that code:        

  # initialize random numeber generator
  if (seed>0) set.seed(seed)
    # set parameters
  e.abs <- e
  e.rel <- e
  max.value <- f$opt
  eval <- 0
  last.impr <- max.eval;
  nl <- matrix(NA,k,k-1)
  iteration <- 0
    # separate unordered and ordered from continuous variables   range.u <- vector()
  range.o <- vector()

  n.of.x.vars <- 0
  n.of.o.vars <- 0
  n.of.u.vars <- 0

  for (i in f$d) {
    if (i[[1]]=="u") {
      range.u <- c(range.u, length(i[[2]]))
      n.of.u.vars <- n.of.u.vars + 1

}

    if (i[[1]]=="o") {
      range.o <- c(range.o, length(i[[2]]))
      n.of.o.vars <- n.of.o.vars + 1

}

    if (i[[1]]=="x") {
      n.of.x.vars <- n.of.x.vars + 1
}

  }
   # initialize variables
  max.u <- rep(NA,n.of.u.vars)
  max.o <- rep(NA,n.of.o.vars)
  max.X <- rep(NA,n.of.x.vars)
  max.y <- -Inf
    p.X <- vector()

  p.u <- vector()
  p.o <- vector()
  p <- data.frame(v=numeric(),sd=numeric(),gr=numeric());     # randomly choose the starting population   # (but based on the data given in the function definition)   for (i in 1:k) {
    if (n.of.u.vars>0) {
      U <- vector()
      for (j in 1:n.of.u.vars) {
        U <- c(U, sample(range.u[j],1))       
      }
      U <- t(U)

}

    else U <- NULL
    if (n.of.o.vars>0) {
      O <- vector()
      for (j in 1:n.of.o.vars) {
        O <- c(O, sample(range.o[j],1))       
      }
      O <- t(O)

}

    X <- vector()
    for (j in 1:n.of.x.vars) {
      X <- c(X, runif(1,f$d[[n.of.u.vars+n.of.o.vars+j]][[2]][1],
        f$d[[n.of.u.vars+n.of.o.vars+j]][[2]][2]))

}


    X <- t(X)    

  Many Thanks    

  Yasin   

       
	[[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 Tue 17 Jun 2008 - 13:18:22 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 Tue 17 Jun 2008 - 13:30:40 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