title: Defining a distribution for survival::survreg()
body: <p>I try to fit a survreg model using the gamma distribution. </p>
  
  <p>Following <code>?survreg.distributions</code> I defined my custom distribution like this:</p>
  
  <pre><code>gamma &lt;- list(name = 'gamma',
            parms = c(2,2),
            init = function(x, weights, ...){
              c(median(x), mad(x))
            },
            density = function(x, parms){
              shape &lt;- parms[1]
              scale &lt;- parms[2]
              cbind(pgamma(x, shape=shape, scale=scale),
                    1-pgamma(x, shape=shape, scale=scale),
                    dgamma(x, shape=shape, scale=scale),
                    (shape-1)/x - 1/scale,
                    (shape-1)*(shape-2)/x^2 - 2*(shape-1)/(x*scale) + 1/scale^2)
            },
            quantile = function(p, parms) {
              qgamma(p, shape=parms[1], scale=parms[2])
            },
            deviance = function(...) stop('deviance residuals not defined')
  )
  </code></pre>
  
  <p>However I can't get it to run:</p>
  
  <pre><code>require(survival)
  survreg(Surv(log(time), status) ~ ph.ecog + sex, lung, dist=gamma)
  #Error in coxph.wtest(t(x) %*% (wt * x), c((wt * eta + weights * deriv$dg) %*%  : 
  #  NA/NaN/Inf in foreign function call (arg 3)
  </code></pre>
  
  <p>The error comes from some C-Code but I think it is generated much earlier...</p>
  
  <p>Any hints/suggestions/alternatives to survreg?</p>