Skip to content

Instantly share code, notes, and snippets.

@klpn
Last active April 1, 2017 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klpn/d7c91ccbe64b0b937bdecf9c9661fe02 to your computer and use it in GitHub Desktop.
Save klpn/d7c91ccbe64b0b937bdecf9c9661fe02 to your computer and use it in GitHub Desktop.
Create chart on incidence for all cancer and skin cancer vs age Sweden 2015, based on data from http://www.socialstyrelsen.se/statistik/statistikdatabas/cancer
age fall mall fskin mskin
0 0.0002006 0.0002459 0.0 0.0
5 9.22e-5 0.0001006 0.0 0.0
10 0.0001424 0.0001568 0.0 0.0
15 0.00022940000000000002 0.0002389 0.0 0.0
20 0.0003875 0.00036030000000000003 9.3e-6 0.0
25 0.0007676 0.0004501 9.2e-6 0.0
30 0.0011704 0.0007615 1.34e-5 0.0
35 0.0023091 0.0009373000000000001 2.02e-5 9.7e-6
40 0.0032355 0.0013991 3.74e-5 3.0299999999999998e-5
45 0.0047645 0.0021491 0.0001251 6.2e-5
50 0.0061757 0.0039536 0.0001795 0.00017120000000000001
55 0.0079353 0.007639 0.00032659999999999997 0.00029800000000000003
60 0.0112526 0.0132674 0.00047 0.0005868
65 0.014658800000000001 0.0201682 0.0008751999999999999 0.0012537
70 0.0189572 0.0267256 0.0015712 0.0026882
75 0.0204936 0.0326542 0.0024524 0.0045955
80 0.0221954 0.0363116 0.0037374 0.0074964
85 0.020561100000000002 0.0362248 0.0061103 0.013435899999999999
using DataFrames, PyPlot, PyCall
cinc = readtable("allskinsv15.csv")
PyDict(matplotlib["rcParams"])["axes.formatter.use_locale"] = true
plotarrs = [(cinc[:fall], "Kvinnor alla"); (cinc[:mall], "Män alla");
(cinc[:fskin], "Kvinnor hud"); (cinc[:mskin], "Män hud")]
fig = figure()
ax = fig[:add_subplot](111)
plotages = 20:5:85
for plotarr in plotarrs
ax[:plot](log(cinc[:age][5:18]), log(plotarr[1][5:18]), label = plotarr[2])
end
ax[:xaxis][:set_major_locator](plt[:FixedLocator](log(plotages)))
locs, labels = xticks()
xticks(locs, plotages, rotation = 90)
ax[:set_ylim](-10, -3)
ax[:set_title]("Cancerincidens Sverige 2015")
ax[:set_xlabel]("ålder")
ax[:set_ylabel]("log(incidens)")
ax[:legend]()
grid(1)
show()
#sexesplot(20, 85, "gavrblock") ger:
#http://static-dust.klpn.se/images/Sv15IncAllcancObsvsPredGavr.svg
#sexesplot(20, 95, "gompertz", "circ", 2014, false);ylim(-13,-1) ger:
#http://static-dust.klpn.se/images/Sv14MortCirkObssvsPredGomp.svg
using DataFrames, LifeTable, Mortchartgen, PyPlot, PyCall
cinc = readtable("allskinsv15.csv")
PyDict(matplotlib["rcParams"])["axes.formatter.use_locale"] = true
frames = Mortchartgen.load_frames()
sexes = Dict("f" => Dict("who" => 2, "column" => :fall, "alias" => "kvinnor", "col" => "b"),
"m" => Dict("who" => 1, "column" => :mall, "alias" => "män", "col" => "g"))
function sexesplot(sage, eage, func, cause = "cinc", year = 2015,
logx = true, plotsexes = keys(sexes), sagepr = sage, eagepr = eage)
fig = figure()
ax = fig[:add_subplot](111)
ax[:set_xlabel]("Ålder")
if cause == "cinc"
ax[:set_title]("Incidens cancer Sverige $year")
ax[:set_ylabel]("log(incidens)")
else
caalias = Mortchartgen.conf["causes"][cause]["alias"]["sv"]
ax[:set_title]("Mortalitet $caalias Sverige $year")
ax[:set_ylabel]("log(mortalitet)")
propfr = Mortchartgen.propplotframes(cause, "pop", frames, "sv")
end
xarr = sage:5:eage
xarrpr = sagepr:5:eagepr
if logx
plotx = log(xarr)
plotxpr = log(xarrpr)
ax[:xaxis][:set_major_locator](plt[:FixedLocator](plotxpr))
xticks(plotxpr, xarrpr, rotation = 90)
else
plotx = xarr
plotxpr = xarrpr
end
for sex in plotsexes
if cause == "cinc"
sagerow = Int(sage/5+1)
eagerow = Int(eage/5+1)
ycol = cinc[sexes[sex]["column"]][sagerow:eagerow]
else
sagerow = Int(sage/5+6)
eagerow = Int(eage/5+6)
mortfr = Mortchartgen.propgrp(propfr[:ca1frame], propfr[:ca2frame], sexes[sex]["who"],
4290, Mortchartgen.ageslice(sagerow, eagerow, false, "sv")[:agelist],
year, false, :variable)
ycol = mortfr[:value]
end
life = DataFrame(age = xarr, m = ycol)
sexdict = mortsurvfit(life, ones(size(life)[1]), func, "rate")
logy = log(life[:m])
logpreds = log(LifeTable.predict(xarrpr, sexdict))
ax[:plot](plotx, logy, "$(sexes[sex]["col"])o",
label = "$(sexes[sex]["alias"]) obs")
ax[:plot](plotxpr, logpreds, "$(sexes[sex]["col"])-",
label = "$(sexes[sex]["alias"]) pred $(func)")
end
ax[:legend]()
ylim(-12, -2)
grid(1)
show()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment