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

Case weights are ignored by flexsurvspline when calculating knot locations #116

Closed mikesweeting closed 8 months ago

mikesweeting commented 2 years ago

If using weights with flexsurvspline and leaving location of the knots unspecified (i.e. using k=. instead) then the knot locations are chosen based on the unweighted log uncensored survival times. Maybe a minor issue but feels like they knot locations should also take account of the weights.

chjackson commented 2 years ago

Yes that would be reasonable. Calculating weighted quantiles though seems like a nontrivial problem with no standard implementation, judging from (https://aakinshin.net/posts/weighted-quantiles/) !

chjackson commented 8 months ago

This is now implemented in https://github.com/chjackson/flexsurv/commit/8dd7d86a1802bf3cdc714d6da6268862e81a0497 . It works by replicating the observed event times, in proportions defined by an integer approximation to the weights, to obtain a longer vector of event times, and then taking the quantiles. It's rough but good enough for the purpose I think.