chjackson / flexsurv

The flexsurv R package for flexible parametric survival and multi-state modelling
http://chjackson.github.io/flexsurv/
55 stars 27 forks source link

Parameter output from non-convergent models? #88

Closed sbae closed 3 years ago

sbae commented 3 years ago

The second and third models are in fact the same, but they are showing different outputs. I guess this won't be a problem in convergent models, but I just wanted to bring this to your attention.

## Ovarian dataset
data(ovarian)
ov.m <- list()
ov.m[[1]] <- flexsurvreg(formula = Surv(futime, fustat) ~ 1, data = ovarian, dist="gengamma", anc=list(Q = ~resid.ds))
ov.m[[2]] <- flexsurvreg(formula = Surv(futime, fustat) ~ 1, data = ovarian, dist="gengamma", anc=list(shape = ~resid.ds, Q = ~resid.ds))
ov.m[[3]] <- flexsurvreg(formula = Surv(futime, fustat) ~ 1, data = ovarian, dist="gengamma", anc=list(Q = ~resid.ds, shape = ~resid.ds))

# ov.m2 and ov.m3 should be the same?
lapply(ov.m, FUN=coef)

The output is:

[[1]]
         mu       sigma           Q Q(resid.ds) 
 6.41026634  0.03214036 -6.91438291  3.57789725 

[[2]]
             mu           sigma               Q     Q(resid.ds) shape(resid.ds) 
     6.41080579      0.03196856     -6.91072484      0.00000000      3.57640002 

[[3]]
             mu           sigma               Q     Q(resid.ds) shape(resid.ds) 
     6.41080579      0.03196856     -6.91072484      3.57640002      0.00000000 
chjackson commented 3 years ago

Thanks for the report. There are two bugs in flexsurv here!

First problem is that flexsurvreg fails to give an error message when the wrong parameter names are put in anc. Here you put shape instead of sigma - note that gengamma.orig has a parameter called shape, but the parameters of gengamma are mu,sigma and Q.

But even if you had named the parameters correctly, the coefficients would have still been labelled wrongly, as you saw, when anc was not supplied in the conventional order.

I've fixed both these in the development version.

sbae commented 3 years ago

Thanks for your quick response! Using sigma solved the convergence issue. The updated dev version works correctly.