[R] fitting log function: errors using nls and nlxb
Prof J C Nash (U30A)
nashjc at uottawa.ca
Wed Jul 10 16:55:42 CEST 2013
This reply only addresses the NaN in Jacobian matter. I believe it is a
result of getting a perfect fit (0 sum of squares). I have amended the
r-forge version of nlmrt package in routines nlfb and nlxb and did not
get the error running Elizabeth's example. This only answers the
software issue, of course, not the statistical one.
Use the version of nlmrt from the SCM repository on
https://r-forge.r-project.org/R/?group_id=395
or email me for a tarball of this.
JN
On 13-07-10 06:00 AM, r-help-request at r-project.org wrote:
> On Mon, Jul 8, 2013 at 9:27 PM, Elizabeth Webb
> <webb.elizabeth.e at gmail.com>wrote:
>> >Hi-
>> >I am trying to fit a log function to my data, with the ultimate goal of
>> >finding the second derivative of the function. However, I am stalled on
>> >the first step of fitting a curve.
>> >
>> >When I use the following code:
>> >FG2.model<-(nls((CO2~log(a*Time)+b), start=setNames(coef(lm(CO2 ~
>> >log(Time), data=FG2)), c("a", "b")),data=FG2))
>> >I get the following error:
>> >Error in numericDeriv(form[[3L]], names(ind), env) :
>> > Missing value or an infinity produced when evaluating the model
>> >In addition: Warning messages:
>> >1: In min(x) : no non-missing arguments to min; returning Inf
>> >2: In max(x) : no non-missing arguments to max; returning -Inf
>> >3: In log(a * Time) : NaNs produced
>> >4: In log(a * Time) : NaNs produced
>> >
>> >When I fit the curve in Plot and use the coefficients as starting values:
>> >start=c(a=68,b=400)
>> >FG2.model<-(nls((CO2~log(a*Time)+b), start=start,data=FG2))
>> >I get the following error:
>> >Error in nls((CO2 ~ log(a * Time) + b), start = start, data = FG2) :
>> > singular gradient
>> >In addition: Warning messages:
>> >1: In min(x) : no non-missing arguments to min; returning Inf
>> >2: In max(x) : no non-missing arguments to max; returning -Inf
>> >
>> >So then when I substituded nlxb for nls in the above two models, I got this
>> >error:
>> >Error in nlxb((CO2 ~ log(a * Time) + b), start = start, data = FG2) :
>> > NaN in Jacobian
>> >
More information about the R-help
mailing list