mclements / rstpm2

An R package for generalised survival models
28 stars 11 forks source link

Use Surv objects directly #3

Open aghaynes opened 8 years ago

aghaynes commented 8 years ago

Dear Mark,

I've just had a course on the stata version of stpm2 and thought I'd look into the R version.

Not a problem per se, but something that would increase user friendliness and make rstpm2 more consistent with other packages would be to allow stpm2 to use Surv objects directly (as coxph etc do) rather than having to define it in the formula.

Thanks,

Alan

mclements commented 8 years ago

Alan,

This is a very interesting idea -- thank you. To be honest, I have never used a Surv object directly.

The current implementation allows for the linear predictor to depend on general functions of time -- and the default is to use the Surv formula to determine the time variable. Moreover, we use a time variable for left entry times for either left truncation and interval censoring when calculating some design matrices.

We could incorporate the Surv object provided the time variables are separately declared. This may take some time, as the current implementation parses the formula.

Sincerely, Mark.

On 01/23/2016 05:15 PM, aghaynes wrote:

Dear Mark,

I've just had a course on the stata version of stpm2 and thought I'd look into the R version

Not a problem per se, but something that would increase user friendliness and make rstpm2 more consistent with other packages would be to allow stpm2 to use Surv objects directly (as coxph etc do) rather than having to define it in the formula

Thanks,

Alan

— Reply to this email directly or view it on GitHubhttps://github.com/mclements/rstpm2/issues/3.

aghaynes commented 8 years ago

Hi Mark, I had a quick look into the Surv objects. I'd expected all of the information used in constructing the values to be stored within the object alwell...which they're not. Still something to think about though. If I find a little time I might fork your repo and have a play if you don't mind...? Thanks, Alan

mclements commented 8 years ago

Forks are encouraged - and pull requests more so! Thanks for looking into this. --- Mark

On 02/01/2016 02:32 PM, aghaynes wrote:

Hi Mark, I had a quick look into the Surv objects. I'd expected all of the information used in constructing the values to be stored within the object alwell...which they're not. Still something to think about though. If I find a little time I might fork your repo and have a play if you don't mind...? Thanks, Alan

— Reply to this email directly or view it on GitHubhttps://github.com/mclements/rstpm2/issues/3#issuecomment-177973003.

alexploner commented 6 years ago

Hi Mark,

I just ran into the same issue as Alan; just wanted to add that I find using Surv-objects directly in data analysis is good practice: generally, I will fit multiple models with the same outcome, and often enough I have different outcomes (all-cause mortality, some cause-specific mortality etc.) in the same analysis. Defining new variables "acmort" and "cs1mort" etc. is definitely easier to read and maintain than long Surv-definitions (e.g. for delayed entry) that only differ in the event variable, especially as calls to stpm2 can get rather long anyway due to extra arguments.

The easiest solution I could come up with is to override the existing Surv-function with a new variant in rstpm2 that generates an object of class, say, Survx (analogous to rstpm2::nsx) that of course inherits from class Surv, but has an extra call attribute: that would preserve the unevaluated call and allow identification of time variables, extra complexity could be hidden away (e.g. in lhs)... also, very old-skool R :-)

Just my 2c, alex