[R] optimization setup

Paul Smith phhs80 at gmail.com
Fri May 30 19:23:43 CEST 2008


On Fri, May 30, 2008 at 12:04 PM, threshold <r.kozarski at gmail.com> wrote:
> Thanks for all your replies and sorry for a negligence in my examples. They
> are very simplified to reflect very roughly the structure of the case I deal
> with, which is too complicated to be quoted here.
>
> What I deal with is:
> 1) 'theta' which is vector with length 2, being known to me (eg.
> theta=c(1,2))
> 2) 'x' which represents my empirical data (I know as well),
> 3) 'theta1' is a vector with length 2 I don't know, which suppose to
> minimize my objective function f3 (see below)
>
> Here come the structure of the functions:
> f1<-function(theta, theta1)
> {theta[1]+theta[2]+theta1[1]}
>
> f2<-function(theta, x, theta1)
> {f1(theta, theta1)*exp(x)*theta1[2]}
>
> function to be optimized with respect to theta1:
> f3<-function(theta1)
> {f1(theta, theta1)-f2(theta,x,theta1)}
>
> Again, I know vector 'theta' and 'x', and I look for (vector) 'theta1' which
> minimize f3
>
> Question are:
> 1) whether, given the case I deal with, the functions I provided are
> specified correctly. If not what is the correct form?
> 2) how should I write my optim function with starting values for theta1
> equal to 1.1 and 2.1. What I did was:
> optim(par=c(1.1, 2.1), f3) but it did not work well with error message:
> Error in f1(theta, theta1) : argument "theta1" is missing, with no default

If x is a vector, then your function f2 is not a real function; f2
returns a vector (and not a scalar). Optim does not optimize vectorial
functions.

Paul



More information about the R-help mailing list