# [R] formula for nls

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jan 23 23:35:37 CET 2008

```On Jan 23, 2008 3:44 PM, Jarek Jasiewicz <jarekj at amu.edu.pl> wrote:
> Gabor Grothendieck wrote:
> > Try port algorithm.  Please provide complete reproducible code and data
> > when posting.
> >
> >
> >> y <- 1/(x <- 1:5)
> >> nls(y~k/x^n, start=list(k=1, n=1), algorithm = "port")
> >>
> > Nonlinear regression model
> >   model:  y ~ k/x^n
> >    data:  parent.frame()
> > k n
> > 1 1
> >  residual sum-of-squares: 0
> >
> > Algorithm "port", convergence message: both X-convergence and relative
> > convergence (5)
> >
> >
> >
> thanks, but unfortunaltly not work
>
> here data and problem:
>
> tmp=data.frame(t=c(0,40,100,330,950,15200),
> h=c(0.362,0.278,0.218,0.169,0.139,0.024))
> fm=formula(t~    tr+    (ts-tr)/    ((1+    (a*h)^n)^(1-(1/n))))
> start=list(a=0.05, n=1.5, ts=0.5, tr=0.05)
>
> p=nls(fm, data=tmp,start=start, algorithm = "port")
> ------
> Error in numericDeriv(form[[3]], names(ind), env, ifelse(internalPars <  :
>        Missing value or an infinity produced when evaluating the model
>

This is a completely different problem!  Note that:

- presumably a and n > 0 but that has not been specified
- the problem is singular near n = 1 which is not allowed
- its  linear in two parameters

grid a and n and then solve the other two with lm at
each iteration.  That may be enough to solve it or at
least get starting values which might keep it away from
the problem regions.

```