Search code examples
rnls

Trouble applying NLS in R


I'm trying to apply a non-linear regression model for protein binding in R.

Data are as follows:

data$WT
 [1] 107.194364  95.986477  87.511449  74.028678  67.733609
 [6]  52.117508  38.486519  24.197712  15.854248   8.641564
[11]   5.965327   2.871084

data$So
 [1] 2.0000000 1.0000000 0.5000000 0.2500000 0.2000000 0.1000000
 [7] 0.0500000 0.0250000 0.0125000 0.0062500 0.0031250 0.0015625

Model is:

bindmod <- nls(WT ~
(Ase* ((Kd+So+0.03)- sqrt((Kd+So+0.03)^2 - 4*So*0.03)/2)/So)
, data = data, start = list(Kd = 0.03, Ase = 2000))

On trying to fit this error appears:

Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model In addition: Warning message: In sqrt((Kd + So + 0.03)^2 - 4 * So * 0.03) : NaNs produced

The value of this term within the square root should not be negative with the values present, however, so I don't understand why it is producing NaNs. Is this something to do with the estimation process?

Any help would be much appreciated, thank you.

George


Solution

  • You are not specifying the lower/upper bounds, so when kd and soare so that (Kd+So+0.03)^2 - 4*So*0.03 is being negative, the sqrt produces NaNs. Try setting both the lower/upperbounds _and_ thealgorithm`:

      nls(WT ~ (Ase* ((Kd+So+0.03) - sqrt((Kd+So+0.03)^2 - 4*So*0.03)   /   2) / So ),
          data = data,
          start = list(Kd = 0.03, Ase = 2000),
          lower = list(kd=0.01, Ase=  0.01 ),
          algorithm = "port")