# [R] Use of nls command

Peter.Watkins@foodscience.afisc.csiro.au Peter.Watkins at foodscience.afisc.csiro.au
Tue Apr 23 06:23:48 CEST 2002

Hello.

I am trying to do a non-linear fit using the 'nls' command.

The data that I'm using is as follows
pH     k
1 3.79 34.21
2 4.14 25.85
3 4.38 20.45
4 4.57 15.61
5 4.74 12.42
6 4.92  9.64
7 5.11  7.30
8 5.35  5.15
9 5.67  3.24

with a transformation of pH to H <- 10^-pH

When using the nls command for a set of parameters - a, b and c, I receive
two sets of errors:

> ba.nls <- nls( k ~ a/(1+(H/b)) +c*(H/b)/(1+(H/b)), data = obs, start =
list( a= 1, b = 1, c = 2), trace = TRUE )
2579.16 :  1 1 2
1266.912 :   8.041114e+00 -1.811360e+08 -1.809427e+08
1243.136 :  8.237232e+00 2.304521e+15 2.269853e+15
Error in nls(k ~ a/(1 + (H/b)) + c * (H/b)/(1 + (H/b)), data = obs, start =
list(a = 1,  :
step factor 0.000488281 reduced below `minFactor' of 0.000976563

> ba.nls <- nls( k ~ a/(1+(H/b)) +c*(H/b)/(1+(H/b)), data = obs, start =
list( a= 5, b = 1, c = 2), trace = TRUE )
1724.262 :  5 1 2
Error in nls(k ~ a/(1 + (H/b)) + c * (H/b)/(1 + (H/b)), data = obs, start =
list(a = 5,  :

I suspect that my initial set of starting values are the problem but I'm