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

Issue with covariate on scale parameter of Weibull ATF for weibull distribution #175

Closed sbihorel closed 10 months ago

sbihorel commented 11 months ago

Hi

While trying to fit a flexsurvreg model using a Weibull distribution and testing covariates on ancillary parameters, I stumbled what looks like a bug... Adding factor or character covariate on the scale parameter returns and error. Adding a numeric variable on scale does not. Since this is my first foray in parametric survival analysis, I'd like to know if I am doing things wrong or if there is indeed a bug

Reprex:

# Fitting a basic model works
fit1 <- flexsurvreg(Surv(recyrs, censrec) ~ group , data = bc, dist = 'weibull')
# Fitting the effect of group on shape works
fit2 <- flexsurvreg(Surv(recyrs, censrec) ~ group + shape(group), data = bc, dist = 'weibull')
# Fitting the effect of group on scale results in an error
fit3 <- flexsurvreg(Surv(recyrs, censrec) ~ group + scale(group), data = bc, dist = 'weibull')
# Fitting the effect of group on scale works
fit4 <- flexsurvreg(Surv(recyrs, censrec) ~ group + scale(rectime), data = bc, dist = 'weibull')

Thanks

chjackson commented 11 months ago

scale is the location parameter in the Weibull distribution, so by specifying Surv(recyrs, censrec) ~ group you have already placed the group covariate on this parameter. The parameter_name(covariate_name) syntax is for ancillary parameters such as shape, not location parameters. The behaviour of flexsurv is undefined when you put the name of a location parameter in this syntax.

Thanks for this report anyway - I shall leave it open, because ideally flexsurv should have given you an informative error or warning message to explain the problem.

sbihorel commented 10 months ago

Thanks for your feedback. That's really useful.

chjackson commented 10 months ago

A warning is now given in https://github.com/chjackson/flexsurv/commit/dd26c86391b6c9c69233383d857d09bc5ab56107