[R] Trouble with optim on a specific problem

Liviu Andronic landronimirc at gmail.com
Tue Jun 16 18:15:18 CEST 2009


Hello,

On 6/16/09, Stu @ AGS <stu at agstechnet.com> wrote:
> Thanks for your response!
>  No, my basic equation does not use matrices at all.  It takes scalar values and returns a scalar.
>
Not quite. Taking the example above, if you run the following:
> with(observs , {1*x1*x2^2*x3^3})
[1] 0.000e+00 4.267e+16 8.910e+15 2.293e+17 4.308e+16 1.207e+18

you get a vector 6x1. I may be wrong, but I would expect optim() or
any other optimiser (nlminb, etc.) to expect that the objective
function returns a 1x1 value. In my specific example, I arbitrarily
chose values for the parameters: c[1]=1,c[2]=2,c[3]=3.


>  What I am trying to accomplish is to find the "best-fit" coefficients to the equation as follows:
>  y ~ c1 * x1 * x2^c2 * x3^c3
>  where y, x1, x2, and x3 are observed data and c1, c2, and c3 are regression coefficients.
>
Here I'm slightly confused. If it is a regression that you are trying
to do, and it seems non-linear, perhaps ?nls could help. I tried nls
with your data, but it ended up with an error:

> nls( y ~ c1 * x1 * x2^c2 * x3^c3, data=observs, start=list(c1=0.66, c2=0.999, c3 = 0.064))
Error in numericDeriv(form[[3]], names(ind), env) :
  Missing value or an infinity produced when evaluating the model


Best,
Liviu




More information about the R-help mailing list