JuliaActuary / MortalityTables.jl

Easily Reference and use Actuarial Mortality Tables
https://juliaactuary.github.io/MortalityTables.jl/stable
Other
28 stars 10 forks source link

Using models with data #118

Closed PharmCat closed 2 years ago

PharmCat commented 2 years ago

Is it possible to use models with survival data and get likelihood estimates?

alecloudenback commented 2 years ago

For sure! I will try to create an example this weekend by combining this package with, e.g, LsqFit.jl

PharmCat commented 2 years ago

For sure! I will try to create an example this weekend by combining this package with, e.g, LsqFit.jl

Hi! I made an example, is my approach correct? (or maybe linearization need)

import LsqFit
using MortalityTables, Plots

data = [
1 0.99
2 0.98
3 0.95
4 0.9
5 0.8
6 0.65
7 0.5
8 0.38
9 0.25
10 0.2
11 0.1
12 0.05
13 0.02
14 0.01]

plot(data[:,1], data[:,2])
@. model(x, p) = survival(MortalityTables.Weibull(;m = p[1],σ = p[2]), x)
mfit = LsqFit.curve_fit(model, data[:,1], data[:,2], [1.0, 1.0])
plot!(data[:,1], model(data[:,1], mfit.param))
alecloudenback commented 2 years ago

Looks good to me!

image

alecloudenback commented 2 years ago

@PharmCat are you okay if I close this issue? Also, do you mind if I use this example in the documentation or the JuliaActuary.org website?

PharmCat commented 2 years ago

Also, do you mind if I use this example in the documentation or the JuliaActuary.org website?

Hi! I made some examples here: https://gist.github.com/PharmCat/fe1e64a2241aa35d3a3fa925989c3784 Of course, if you want, you can use it :) One thing... for data with censored values I used Weibull from Distributions for ML estimate (#3). Is it possible to make something like this with MortalityTables (Because MortalityTables includes more models)?

are you okay if I close this issue?

OK)

alecloudenback commented 2 years ago

One thing... for data with censored values I used Weibull from Distributions for ML estimate (#3). Is it possible to make something like this with MortalityTables (Because MortalityTables includes more models)?

Sorry, can you clarify what you mean here? I'm not sure that the link is pointing to the right issue.