title: R nls singular gradient
body: <p>I've tried searching the other threads on this topic but none of the fixes are working for me. I have the results of a natural experiment and I want to show the number of consecutive occurrences of an event fit an exponential distribution. My R shell is pasted below</p>
  
  <pre><code>f &lt;- function(x,a,b) {a * exp(b * x)}
  &gt; x
   [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
  [26] 26 27
  &gt; y
   [1] 1880  813  376  161  100   61   31    9    8    2    7    4    3    2    0
  [16]    1    0    0    0    0    0    1    0    0    0    0    1
  &gt; dat2
      x    y
  1   1 1880
  2   2  813
  3   3  376
  4   4  161
  5   5  100
  6   6   61
  7   7   31
  8   8    9
  9   9    8
  10 10    2
  11 11    7
  12 12    4
  13 13    3
  14 14    2
  &gt; fm &lt;- nls(y ~ f(x,a,b), data = dat2, start = c(a=1, b=1)) 
  Error in numericDeriv(form[[3L]], names(ind), env) : 
    Missing value or an infinity produced when evaluating the model
  &gt; fm &lt;- nls(y ~ f(x,a,b), data = dat2, start = c(a=7, b=-.5)) 
  Error in nls(y ~ f(x, a, b), data = dat2, start = c(a = 7, b = -0.5)) : 
    singular gradient
  &gt; fm &lt;- nls(y ~ f(x,a,b), data = dat2, start = c(a=7,b=-.5),control=nls.control(maxiter=1000,warnOnly=TRUE,minFactor=1e-5,tol=1e-10),trace=TRUE) 
  4355798 :   7.0 -0.5
  Warning message:
  In nls(y ~ f(x, a, b), data = dat2, start = c(a = 7, b = -0.5),  :
    singular gradient
  </code></pre>
  
  <p>Please forgive the bad formatting, first post here. x contains bins of a histogram, y contains the number of occurrences of each bin in that histograms. dat2 cuts off at 14 since the 0 count bins would throw off the exponential regression, and I really only need to fit those first 14. Those bins which have counts beyond 14 I have biological reason to believe they are special.
  The issue I initially got was infinity, which I don't get since none of the values are 0. After giving decent starting values as suggested by a different post here I get the singular gradient error. The only other posts I saw with that had more variables, I tried increasing the number of iterations but that did not succeed. Any help is appreciated.
  A</p>