title: singular gradient error with nls in r; how do I know if its the code or the data?
body: <p>I'm trying to run a non linear regression on this data: </p>
  
  <pre><code>Flux&lt;-c(192.09536, 199.47616, 137.63245, 133.60358, -89.28360, -23.17639, -27.14659, 107.25287,  52.72565, NA, 167.43277, 113.59047)
  Par&lt;-c(4.166667e-01, 4.347826e-02, 4.583333e-01, 1.845833e+02, 1.122688e+03, 1.059048e+03, 6.384000e+02, 3.326087e+02, 7.094762e+02, 4.180000e+02, 3.953333e+02, 3.998636e+02)
  Obs&lt;-c(1,2,3,4,5,6,7,8,9,10,11,12)
  curve1&lt;-data.frame(Flux, Par, Obs)
  curve1&lt;-do.call("cbind", curve1)
  </code></pre>
  
  <p>This is the first model I tried, which has worked on some other similar datasets:</p>
  
  <pre><code>model1 &lt;- nls(Flux~b*Par/(c+Par)-a, data = curve1, start=list(a=180,
                                                            b=-200, c=800))
  </code></pre>
  
  <p>However for this data model1 gives:</p>
  
  <pre><code>Error in nls(Flux ~ b * Par/(c + Par) - a, data = curve1, start =
      list(a = 180, : singular gradient
  </code></pre>
  
  <p>I thought this might be because my starting parameters are wrong so I tried to turn it into a self starting model (I've also tried lots of different starting parameters):</p>
  
  <pre><code>model2&lt;-with(curve1, nls(Flux~SSasymp(Par, a, b, c)))
  </code></pre>
  
  <p>This gives the same error. 
  However I think I have used SSasymp wrong in this case because it fits incorrect curves to data which I am able to fit model1 to.
  I think this is because I've confused R about a, b and c (?). I've read that when using SSasymp: 
  b is 'the horizontal asymptote (a) -the response when x is 0' 
  while c is the rate constant.</p>
  
  <p>In my original equation in model1 b is the horizontal asymptote, c is the rate constant and a is the response when x is 0.</p>
  
  <p>If I try to write a self starting model to reflect this:</p>
  
  <pre><code>model3&lt;-with(curve1, nls(Flux~SSasymp(Par, b, (b-a), c)))
  </code></pre>
  
  <p>I get this error:
      In addition: Warning message:
      In nls(Flux ~ SSasymp(Par, b, (b - a), c)) :
        No starting values specified for some parameters.
      Initializing ‘a’ to '1.'.
      Consider specifying 'start' or using a selfStart model</p>
  
  <p>I am looking for advice on 
  1) Is model1 not working because of an error in my code/incorrect starting parameters <strong>or because the model just doesn't fit the data</strong>?</p>
  
  <p>If the latter is the case, is there a way to force R to do its best to fit a non-linear model to it anyway? Ecologically, this should really be a saturating curve.</p>
  
  <p>2) Can I/How do I fit my equation into a self-starting model? Have I just fundamentally misunderstood how to use SSasymp?</p>
  
  <p>Any help is very much appreciated. Apologies if I haven't explained or formatted this very well, this is my first post and I'm not an experienced R user or statistician! </p>