Prediction of Swedish mortality pattern using my MortParamsPlot
using MortParamsPlot, PyPlot | |
import YAML | |
obsyrs = 1999:2013 | |
predyrs = 2018:5:2033 | |
af = 0 | |
ages = 35:5:95 | |
country = 4290 | |
circcomb = ["ihd";"circnonihd"] | |
predcauses = ["tum";circcomb] | |
lota = LongTable() | |
mgendir = expanduser("~/mortchartgen/") | |
conf = YAML.load_file(joinpath(mgendir, "chartgen.yaml")) | |
methalias = Dict("curve_fit" => "regression dödstal", "svd" => "Lee\u2013Carter") | |
function ObsPredDict(sex, method = "curve_fit") | |
pattern = PredictMortalityPattern(lota, sex, ages, af, predcauses, | |
country, obsyrs, predyrs, method) | |
pred_circ = PredictCauseLife(pattern, circcomb) | |
pred_tum = PredictCauseLife(pattern, ["tum"]) | |
obs_circ = ObsCauseLife(lota, sex, ages, af, "circ", country, [obsyrs[end]]) | |
obs_tum = ObsCauseLife(lota, sex, ages, af, "tum", country, [obsyrs[end]]) | |
return Dict(:pattern => pattern, :pred_circ => pred_circ, :pred_tum => pred_tum, | |
:obs_circ => obs_circ, :obs_tum => obs_tum, :method => method) | |
end | |
function ObsPredPlot(opdict) | |
ages = opdict[:obs_circ][:caframes][end][:age] | |
sexalias = conf["sexes"][opdict[:pattern][:sex]]["alias"] | |
ctryalias = conf["countries"][country]["alias"] | |
plt[:plot](ages, opdict[:obs_circ][:caframes][end][:f], "d", | |
label = string("obs cirk $(obsyrs[end])")) | |
plt[:plot](ages, opdict[:obs_tum][:caframes][end][:f], "d", | |
label = string("obs tum $(obsyrs[end])")) | |
for i in 1:size(predyrs, 1) | |
plt[:plot](ages, opdict[:pred_circ][:caframes][i][:f], | |
label = string("pred cirk $(predyrs[i])")) | |
plt[:plot](ages, opdict[:pred_tum][:caframes][i][:f], | |
label = string("pred tum $(predyrs[i])")) | |
end | |
plt[:legend](loc="upper left", ncol = 2, framealpha = 0.5, | |
prop = Dict(:size => "small")) | |
plt[:title](string("Förutsägelse dödsorsaker $(sexalias) $(ctryalias)", | |
" $(methalias[opdict[:method]])")) | |
plt[:xlabel]("Uppnådd ålder") | |
plt[:ylabel]("Andel") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment