[R] function optimization

2011-06-15 Thread navishkumarb
Hello 
I would like to optimize a function which is as follows. 


nc.adj - function(nc, G) {


  x = a + G + (b/(G^2 + (c - G)^2)) - nc
  return(x)
}

Can I just know how to get the optimized values of a,b,c for given G and nc
using optim/optimize function. 


--
View this message in context: 
http://r.789695.n4.nabble.com/function-optimization-tp3600099p3600099.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] function optimization

2011-02-06 Thread garciap

Dear all,

this is my first time, and just begin to use R. But I've a question about
optimization using optimx library. It could sound stupid by I'm a bit
affraid with the problem, because anything I try, anything Error. 
The procedure was:
optimx(par=10,71,1,fn=(Prey*Provisioning)/Risk, control=list(maximize))

well the problem lies in the initial value parameters, again and again, R
tells me that it is not possible to optimize the function at this values,
even though these are real estimations.

Any suggestion?

Pablo
-- 
View this message in context: 
http://r.789695.n4.nabble.com/function-optimization-tp3263244p3263244.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] function optimization

2011-02-06 Thread Ben Bolker
garciap garciap at usal.es writes:


 this is my first time, and just begin to use R. But I've a question about
 optimization using optimx library. It could sound stupid by I'm a bit
 affraid with the problem, because anything I try, anything Error. 
 The procedure was:
 optimx(par=10,71,1,fn=(Prey*Provisioning)/Risk, control=list(maximize))
 
 well the problem lies in the initial value parameters, again and again, R
 tells me that it is not possible to optimize the function at this values,
 even though these are real estimations.
 

  I'm afraid there are quite a few things wrong with your approach.

* parameters need to be a **numeric vector** (e.g. c(10,71,1)) rather
than characters
* you haven't defined a function that takes the vector of parameters
as an argument and returns a goodness-of-fit measure or other objective
function value.  This is the biggest problem
(the rest are just basic misunderstandings of R syntax, easily corrected).
* if you want the function to maximize you need control=list(maximize=TRUE).
* I think you have not given us exactly the command you entered. If I enter
what you have typed above, the unmatched quotation mark before 'maximize'
means that R doesn't even accept my command: it gives me a 'continuation
character' (+) telling me that it is waiting for further input.  It's very
important to specify *exactly* the commands you typed; cutting and pasting
from the R session (or better, keeping a script file and copying from there)
is a good way to ensure this.

  I would suggest that you work carefully through the examples
in the optimx help page, making sure that you understand them
(or if you get totally stuck there, you can post to the help list
with a *specific* question about what you haven't understood).
I might also recommend that you try starting with the optim()
help page, which is a little bit simpler than the optimx() page.
optimx has better optimization routines, but for getting a basic
understanding of how R does optimization optim() should suffice.

  Don't forget to read the posting guide before you come back with
more questions.

  good luck,
   Ben Bolker

__
R-help@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.