[R] Re: Four-parameter logistic [was Re: Info]
Douglas Bates
bates at stat.wisc.edu
Wed Jul 16 16:39:11 CEST 2003
Spencer Graves <spencer.graves at pdf.com> writes:
> On 7/11, I replied to one of your earlier posts on this problem wiht
> the following:
>
>
> chemYield <-
> function(a, x)(a[1]+(a[3]-a[2])/(1+exp(-a[2]*(x-a[4]))
>
> This can be used in "optim" but not "nls". Mimicking an example in
> the documentation for "nls" (package nls), I suspect the following
> should work:
>
>
> yield.fit <- nls( y ~ a + (c.-a)/(1+exp(-b*(x-m))),
> data = yield.data.frame,
> start = list( a= 0, c.=2, b= 1, m=4 ),
> trace = TRUE )
>
> where "y" and "x" are columns of "yield.data.frame. [Note: I suggest
> you avoid using reserved words like "c": "c" is a function in R. R
> is smart enough to distinguish between a function "c" and a
> non-function object in many contexts. However, I try to avoid relying
> on this. Note that here I changed your "c" to "c.".]
>
>
> Have you tried something like these two? I suggest you try
> them both with a very simple toy example with 4 or 5 observations. If
> you can't get both of them to work, please submit the data with your
> failed attempts and the resulting error message(s). With that detail,
> someone else will likely be able to respond in seconds. Without it,
> we may no be able to help you. We've been at this almost a week and
> still do not have the problem solved largely because people like me
> are shooting in the dark: We can't figure out what you are missing,
> and you aren't providing enough detail to help us see the gap.
>
>
> hope this helps. spencer graves
Thanks for the reply Spencer. I would like to offer a few additional
comments, not in criticism but in the spirit in which you offer your
comments - to assist the community.
It is not a good idea to use nls to fit a four-parameter model to 4
data points. The relative offset convergence criterion used in nls
cannot be applied to cases with 0 degrees of freedom for residuals.
In simulating data for test fits by nls you must add noise to the
response. The relative offset convergence criterion used in nls will
not, in general, declare convergence on artificial 'perfect fit' data.
The author of nls does not regard this as a bug :-).
To get a reasonable fit of a four parameter logistic model you need
data across a wide range of x values. In particular you need data on
both the 'toe' of the curve and the 'shoulder' of the curve. A common
reason for failure to fit the four-parameter logistic is the
availability of data only on the 'toe' and the linear portion of
the curve. Without some data past the linear region you cannot
determine an upper asymptote and the two parameters written as m and a
in the above equation cannot be separately determined.
I would recommend using the 'plinear' algorithm in nls for this
model. Two of the four parameters are conditionally linear. Reducing
an optimization problem from four parameters to two parameters is a
big win.
The SSfpl self-starting model can relieve the user of the need to form
starting estimates. See
?SSfpl
and
example(SSfpl)
The SSfpl model uses a slightly different parameterization of the
model, which we (Don Watts and I) have found to be more stable than
the one given above. It can be difficult to estimate b in the above
formulation. We find it better to use a location-scale form of b and
m and to converge on the logarithm of scale parameter.
Successful use of nonlinear regression depends on understanding the
nature of the model and your data. In particular, I recommend
plotting the data before ever trying to fit any model. You may recall
that I go a little further than that in some courses and inform
students that if I catch them fitting models without plotting the data
first they will be in danger of failing the course. :-)
Thanks for your efforts in responding to many, many questions on this
list. I hope my comments are helpful.
More information about the R-help
mailing list