[R] nls
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Aug 15 15:50:26 CEST 2006
On Tue, 15 Aug 2006, Peter Dalgaard wrote:
> Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
>
> > You problem is x^c for x = 0. If you intended only c > 1, try a starting
> > value meeting that condition (but it seems that the optimal c is about
> > 0.27 is you increase x slightly).
>
> Surely you mean c > 0.
I did.
> > nls(1/y ~ a+b*x^exp(c), start=list(a=1.16122,b=0.01565,c=0))
> Nonlinear regression model
> model: 1/y ~ a + b * x^exp(c)
> data: parent.frame()
> a b c
> 0.9944025 0.1953168 -1.1495206
> residual sum-of-squares: 0.03303464
> > nls(1/y ~ a+b*x^c, start=list(a=1.16122,b=0.01565,c=exp(-1.1)))
> Nonlinear regression model
> model: 1/y ~ a + b * x^c
> data: parent.frame()
> a b c
> 0.9944026 0.1953165 0.3167891
> residual sum-of-squares: 0.03303464
>
> (but even setting c=exp(-1) triggers the error; there could be cause
> for robustifying the nls algorithm)
Well, there is an option to use a bounded-region algorithm, e.g.
x <- c(0,5,10,15,20,25,30)
y <- c(1.00000,0.82000,0.68000,0.64000,0.66667,0.68667,0.64000)
nls(1/y ~ a+b*x^c, start=list(a=1.16122,b=0.01565,c=1), trace=TRUE,
algorithm="port", lower=c(-Inf, -Inf, 0), upper=rep(Inf, 3))
works.
>
> > Why have you used ~~ ? (Maybe because despite being asked not to, you
> > sent HTML mail?)
> >
> > On Tue, 15 Aug 2006, Xiaodong Jin wrote:
> >
> > > Is there anyway to change any y[i] value (i=2,...6) to make following NLS workable?
> > >
> > > x <- c(0,5,10,15,20,25,30)
> > > y <- c(1.00000,0.82000,0.68000,0.64000,0.66667,0.68667,0.64000)
> > > lm(1/y ~~ x)
> > > nls(1/y ~~ a+b*x^c, start=list(a=1.16122,b=0.01565,c=1), trace=TRUE)
> > >
> > > #0.0920573 : 1.16122 0.01565 1.00000
> > > #Error in numericDeriv(form[[3]], names(ind), env) :
> > > # Missing value or an infinity produced when evaluating the model
> > >
> > >
> > > ---------------------------------
> > >
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> > >
> >
> > --
> > Brian D. Ripley, ripley at stats.ox.ac.uk
> > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> > University of Oxford, Tel: +44 1865 272861 (self)
> > 1 South Parks Road, +44 1865 272866 (PA)
> > Oxford OX1 3TG, UK Fax: +44 1865 272595
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.
> >
>
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list