title: Fitting a curve to weibull distribution in R using nls
body: <p>I am trying to fit this data to a weibull distribution:</p>
  
  <p>My <code>x</code> and <code>y</code> variables are:</p>
  
  <pre><code>y &lt;- c(1, 1, 1, 4, 7, 20, 7, 14, 19, 15, 18, 3, 4, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1)
  x &lt;- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24)
  </code></pre>
  
  <p>The plot looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/MgmaN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MgmaN.png" alt="enter image description here"></a></p>
  
  <p>I am looking for something like this:
  <a href="https://i.stack.imgur.com/ags7T.png" rel="nofollow noreferrer">fitted plot</a></p>
  
  <p>and I want to fit a weibull curve to it. I am using the nls function in R like this:</p>
  
  <pre><code>nls(y ~ ((a/b) * ((x/b)^(a-1)) * exp(- (x/b)^a)))
  </code></pre>
  
  <p>This function always throws up an error saying:</p>
  
  <pre><code>Error in numericDeriv(form[[3L]], names(ind), env) : 
    Missing value or an infinity produced when evaluating the model
  In addition: Warning message:
  In nls(y ~ ((a/b) * ((x/b)^(a - 1)) * exp(-(x/b)^a))) :
    No starting values specified for some parameters.
  Initializing ‘a’, ‘b’ to '1.'.
  Consider specifying 'start' or using a selfStart model
  </code></pre>
  
  <p>So first I tried different starting values without any success. I cannot understand how to make a "good" guess at the starting values.
  Then I went with the <code>SSweibull(x, Asym, Drop, lrc, pwr)</code> function which is a selfStart function. Now the SSWeibull function expects values for Asym,Drop,lrc and pwr and I don't have any clue as to what those values might be.</p>
  
  <p>I would appreciate if someone could help me figure out how to proceed.</p>
  
  <p>Background of the data: I have taken some data from bugzilla and my "y" variable is number of bugs reported in a particular month and "x" variable is the month number after release.</p>