[R] Help with nonlinear least squares regression curve fitting
Prof J C Nash (U30A)
nashjc at uottawa.ca
Thu Feb 26 14:07:12 CET 2015
Andrew's suggestion for Year is a help, but package nlmrt shows the
problem you are trying to solve is truly one where there is a Jacobian
singularity. (nlmrt produces the Jacobian singular values -- but read
the output carefully because these are placed for compact output as if
they correspond to parameters, which they do not).
Unfortunately, nlmrt tries to use analytic derivatives, and sign() is
not in the derivatives table for the double sigmoid. BTW, your function
has a typo. Do provide reproducible results. Here is what I did using
df <- read.csv("callaghan.csv")
fitmodeliq <- nlxb(Area ~ (-a*Year)*(Year + b), data = df,
fitmodelsig <- nlxb(Area~a/(1+exp(-(b+c*Year))), data=df,
fitmodelds <- nlxb(Area ~
start=list(a=1, b=1, c=1))
For information of readers, Duncan Murdoch and I have been working on
nls14 to replace/augment nls(), but we've a way to go yet before this is
ready for CRAN. Collaborators welcome.
On 15-02-26 06:00 AM, r-help-request at r-project.org wrote:
> Message: 24
> Date: Thu, 26 Feb 2015 07:26:50 +1100
> From: Andrew Robinson <A.Robinson at ms.unimelb.edu.au>
> To: Corey Callaghan <ccallaghan2013 at fau.edu>
> Cc: "R help \(r-help at r-project.org\)" <r-help at r-project.org>
> Subject: Re: [R] Help with nonlinear least squares regression curve
> <CAHyGmd6rrUC_AOBHRHw7babXnMzrSbi4b7ZJt0vN5LRWVW2HAw at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
> Finding starting values is a bit of a dark art. That said, there are steps
> you can take, but it may take time.
> First, I would scale Year so that it's not in the thousands! Experiment
> with subtracting 1980 or so. For specific advice, see inline.
> On Thu, Feb 26, 2015 at 3:03 AM, Corey Callaghan <ccallaghan2013 at fau.edu>
>> > The curves' functions that I want to test are in the code here (hopefully
>> > correctly):
>> > Inverse Quadratic Curve:
>> > fitmodel <- nls(Area ~ (-a*Year)*(Year + b), data = df, start=list(a=??,
>> > b=??, c=??))
> I would plot the data and a smooth spline, differentiate the curve
> function, identify some parameter values somewhere stable, and estimate
> some values by eye, or even predict them from the first derivative of the
> spline - spline.smooth will do this.
> Sigmodial Curve:
>> > fitmodel <- nls(Area~a/(1+exp(-(b+c*Year))), data=df, start=list(a=???,
>> > b=???, c=??))
> I'd use the highest value as a, fit spline as above then invert area at two
> times to get b and c.
> Double sigmoidal Curve:
>> > fitmodel <- nls(Area~a+2b(1/(1+exp(-abs(-c*Year+d)))-1/2)*sign(-c*Year+d),
>> > data=df, start=list(a=???, b=???, c=???)
> I'd use min(Area) as a, figure out b from the maximum (I guess 2b+a is the
> asymptote), and experiment with two values for year to retrieve c and d
> .... uniroot might help?
> -- Andrew Robinson Deputy Director, CEBRA, School of Biosciences Reader
> & Associate Professor in Applied Statistics Tel: (+61) 0403 138 955
> School of Mathematics and Statistics Fax: +61-3-8344 4599 University of
> Melbourne, VIC 3010 Australia Email: a.robinson at ms.unimelb.edu.au
> Website: http://www.ms.unimelb.edu.au/~andrewpr MSME:
> http://www.crcpress.com/product/isbn/9781439858028 FAwR:
> http://www.ms.unimelb.edu.au/~andrewpr/FAwR/ SPuR:
> http://www.ms.unimelb.edu.au/spuRs/ [[alternative HTML version deleted]]
More information about the R-help