chjackson / flexsurv

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

Random effects/frailty models? #185

Open casasgomezuribarri opened 3 months ago

casasgomezuribarri commented 3 months ago

From the vignette:

flexsurv does not currently support shared frailty, clustered or random effects models.

Is there any workaround for this? I am working with a highly heterogeneous system, so my experiments have several technical replicates. I was using cluster() in the formula argument of my flexsurvreg model thinking it would do the job, but replicate is being treated as a main effect (significant...)

I want to account for the variation across replicates in my model, but I don't want to treat it as a main effect. Is there anything I can do?

chjackson commented 3 months ago

There's no technique in flexsurv to do random effects that I know of. There is other software that would support this class of model e.g. frailtypack in R, or Bayesian software such as Stan (e.g. starting from https://mc-stan.org/docs/2_18/stan-users-guide/censored-data.html to represent censoring, then building up your model piece by piece in Stan code).

Is your goal to adjust the variance of some estimate of interest to account for clustering? And your mention of cluster suggests you have tried survreg or coxph, but would prefer to use flexsurvreg? Then perhaps you could do something like this:

This would assume that the amount of variance inflation is independent of the baseline distribution. I'd expect this is a weak assumption, though I don't have practical experience with doing this.

casasgomezuribarri commented 3 months ago

Thanks for your suggestions, I'll explore them in detail.

For a bit of context: I prefer flexsurvreg because of the wider distribution options and the possibility of fitting parameters other than the location parameter. I want to use the gengamma distribution, and I want to explore the effect of my covariates on all three parameters, but clustering should not be overlooked for my system.

Can survreg fit ancillary parameters like flexsurvreg? In that case, I could try to parse the gengamma as a survreg.distributions-type list (see https://www.rdocumentation.org/packages/survival/versions/3.5-7/topics/survreg.distributions). Would that make sense?

I'll continue to explore my possibilities. Thanks again

chjackson commented 3 months ago

I'm not aware of any way of placing covariates on ancillary parameters in survreg, but it's not my package. Also I think the "location/scale" setup that survreg uses would be restricted to two-parameter distributions.