JuliaStats / Survival.jl

Survival analysis in Julia
MIT License
73 stars 22 forks source link

Evaluating estimators #53

Open ya0 opened 1 year ago

ya0 commented 1 year ago

I have been using kaplan meier estomators and wrote a small function to evaluate the estimator at any timepoint. I have used this to generate statistics or diagnostic plots.

function evaluate(km_fit::KaplanMeier, t::Real)
    time_points = km_fit.events.time
    survival = km_fit.survival
    if t <= time_points[1]
        return 1
    else
        id = findlast(x -> x <= t, time_points) 
        return survival[id]
    end
end

@ararslan if you think this is a usefull feature i can create pull request. I have not looked at the Nelson Aalen estimator but maybe something similar can be done / in general for the nonparametric estimator type.

ararslan commented 1 year ago

Nice idea! The functionality seems worthwhile to have but I wonder if it would make sense to define it as a method of getindex or even of the object itself. So with km = KaplanMeier(...) and a time t, that would be km[t] or km(t), respectively. What are your thoughts on that?

ya0 commented 1 year ago

Yes that would look nice, as in https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects