Skip to content

Commit

Permalink
Adding placeholder for example data, fix bug in coeftable with one pr…
Browse files Browse the repository at this point in the history
…edictor
  • Loading branch information
alexpkeil1 committed Sep 15, 2023
1 parent 5fadd17 commit 8fbce96
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ m2d = fit(PHModel, @formula(Surv(entertime, exittime, death) ~ x + z1 + z2), tab
## Kaplan-Meier estimator of the cumulative risk/survival
```{julia}
res = kaplan_meier(int, outt, d)
confint(res, method="lognlog")
plot(res)
```

## Competing risk analysis with Aalen-Johansen estimator of the cumulative risk/survival

```{julia}
function dgm_comprisk(; n = 100, rng = MersenneTwister())
z = rand(rng, n) .* 5
x = rand(rng, n) .* 5
Expand Down
2 changes: 1 addition & 1 deletion src/coxmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function StatsBase.coeftable(m::M; level::Float64 = 0.95) where {M<:AbstractPH}
end
#rown = ["b$i" for i = 1:size(op)[1]]
rown = coefnames(m)
rown = length(rown) > 1 ? rown : [rown]
rown = typeof(rown)<:AbstractVector ? rown : [rown]
StatsBase.CoefTable(op, head, rown, pcol, zcol)
end

Expand Down
15 changes: 15 additions & 0 deletions src/example_data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
using LSurvival
heartdata = survivaldata("heart")
ft = coxph(@formula(Surv(start, stop, event)~surgery), heartdata);
"""
function survivaldata(kwargs...)
data = Dict(
"heart" => (start = [0,0,0,1,0,36,0,0,0,51,0,0,0,12,0,26,0,0,17,0,37,0,0,28,0,0,20,0,0,18,0,8,0,12,0,3,0,83,0,25,0,0,0,71,0,0,16,0,0,17,0,51,0,23,0,0,46,0,19,0,4.5,0,2,0,41,0,58,0,0,0,0,1,0,2,0,21,0,0,36,0,83,0,32,0,0,41,0,0,10,0,67,0,0,21,0,78,0,3,0,0,0,27,0,33,0,12,0,0,57,0,3,0,10,0,5,0,31,0,4,0,27,0,5,0,0,46,0,0,210,0,67,0,26,0,6,0,0,32,0,37,0,0,8,0,60,0,31,0,139,0,160,0,0,310,0,28,0,4,0,2,0,13,0,21,0,96,0,0,38,0,0,0], stop = [50,6,1,16,36,39,18,3,51,675,40,85,12,58,26,153,8,17,81,37,1387,1,28,308,36,20,43,37,18,28,8,1032,12,51,3,733,83,219,25,1800,1401,263,71,72,35,16,852,16,17,77,51,1587,23,1572,12,46,100,19,66,4.5,5,2,53,41,1408,58,1322,3,2,40,1,45,2,996,21,72,9,36,1142,83,980,32,285,102,41,188,3,10,61,67,942,149,21,343,78,916,3,68,2,69,27,842,33,584,12,78,32,57,285,3,68,10,670,5,30,31,620,4,596,27,90,5,17,2,46,545,21,210,515,67,96,26,482,6,445,428,32,80,37,334,5,8,397,60,110,31,370,139,207,160,186,340,310,340,28,265,4,165,2,16,13,180,21,131,96,109,21,38,39,31,11,6], event = [1,1,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,0,1,0,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,0,1,0,1,1,0,1,1,0,1,0,0,1,0,1,0,0,0,1,1,1,0,0,0,1,0,1,1,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,1,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,1,1,0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,1], age = [-17.1553730321697,3.83572895277207,6.29705681040383,6.29705681040383,-7.73716632443532,-7.73716632443532,-27.2142368240931,6.59548254620123,2.86926762491444,2.86926762491444,-2.65023956194388,-0.837782340862425,-5.49760438056126,-5.49760438056126,-0.0191649555099218,-0.0191649555099218,5.1937029431896,6.57357973990418,6.57357973990418,6.0123203285421,6.0123203285421,5.81519507186858,1.44832306639288,1.44832306639288,-27.668720054757,8.84873374401095,8.84873374401095,11.1238877481177,7.27994524298425,7.27994524298425,-4.6570841889117,-4.6570841889117,-5.21560574948666,-5.21560574948666,10.3572895277207,10.3572895277207,3.80013689253936,3.80013689253936,-14.776180698152,-14.776180698152,-17.4647501711157,-39.2142368240931,6.02327173169062,6.02327173169062,2.43394934976044,-3.08829568788501,-3.08829568788501,6.88569472963724,16.4079397672827,16.4079397672827,0.903490759753595,0.903490759753595,-7.44695414099932,-7.44695414099932,-4.53388090349076,0.925393566050651,0.925393566050651,13.5003422313484,13.5003422313484,-6.52977412731006,-6.52977412731006,2.51882272416153,2.51882272416153,0.481861738535251,0.481861738535251,-2.69678302532512,-2.69678302532512,-11.5592060232717,-4.60780287474333,-5.42094455852156,-11.8165639972622,-11.8165639972622,0.610540725530456,0.610540725530456,-0.90075290896646,-0.90075290896646,8.03559206023272,-11.3456536618754,-11.3456536618754,-2.11362080766598,-2.11362080766598,0.733744010951405,0.733744010951405,-6.75154004106776,-0.657084188911703,-0.657084188911703,-0.208076659822041,4.45448323066393,4.45448323066393,-9.25667351129363,-9.25667351129363,-6.73511293634497,0.0164271047227942,0.0164271047227942,-6.61738535249829,-6.61738535249829,1.05407255304586,1.05407255304586,4.56399726214921,-8.64613278576318,-15.3401779603012,-15.3401779603012,0.815879534565369,0.815879534565369,3.29363449691992,3.29363449691992,5.21286789869952,-28.4490075290897,-28.4490075290897,-2.75975359342916,-2.75975359342916,-0.0109514031485318,-0.0109514031485318,5.00205338809035,5.00205338809035,-0.591375770020534,-0.591375770020534,-21.2731006160164,-21.2731006160164,8.33127994524298,8.33127994524298,-18.8336755646817,-18.8336755646817,4.18069815195072,4.0848733744011,4.0848733744011,-6.88843258042436,0.703627652292951,0.703627652292951,5.782340862423,5.782340862423,-1.55509924709104,-1.55509924709104,4.89253935660506,4.89253935660506,-18.798083504449,5.30869267624914,5.30869267624914,-5.28131416837783,-5.28131416837783,-0.0191649555099218,0.919917864476389,0.919917864476389,-1.74674880219028,-1.74674880219028,6.362765229295,6.362765229295,3.04722792607803,3.04722792607803,4.03285420944559,4.03285420944559,-0.40520191649555,-3.01711156741958,-3.01711156741958,-0.249144421629019,-0.249144421629019,-4.15879534565367,-4.15879534565367,-7.71800136892539,-7.71800136892539,-21.3497604380561,-21.3497604380561,-24.3832991101985,-24.3832991101985,-19.3702943189596,-19.3702943189596,1.83436002737851,-12.9390828199863,-12.9390828199863,1.51676933607118,-7.60848733744011,-8.68446269678302], year = [0.123203285420945,0.254620123203285,0.265571526351814,0.265571526351814,0.490075290896646,0.490075290896646,0.607802874743327,0.700889801505818,0.780287474332649,0.780287474332649,0.835044490075291,0.856947296372348,0.862422997946612,0.862422997946612,0.87337440109514,0.87337440109514,0.9637234770705,0.969199178644764,0.969199178644764,0.971937029431896,0.971937029431896,0.991101984941821,1.07049965776865,1.07049965776865,1.07597535934292,1.08692676249144,1.08692676249144,1.13347022587269,1.3305954825462,1.3305954825462,1.3388090349076,1.3388090349076,1.46201232032854,1.46201232032854,1.52772073921971,1.52772073921971,1.56605065023956,1.56605065023956,1.57426420260096,1.57426420260096,1.58247775496235,1.59069130732375,1.68377823408624,1.68377823408624,1.78507871321013,1.88364134154689,1.88364134154689,1.89459274469541,1.91101984941821,1.91101984941821,2.1574264202601,2.1574264202601,2.19849418206708,2.19849418206708,2.30800821355236,2.507871321013,2.507871321013,2.56536618754278,2.56536618754278,2.5927446954141,2.5927446954141,2.63381245722108,2.63381245722108,2.64750171115674,2.64750171115674,2.8829568788501,2.8829568788501,2.88843258042437,3.05817932922656,3.16495550992471,3.26351813826146,3.26351813826146,3.27720739219713,3.27720739219713,3.34017796030116,3.34017796030116,3.34839151266256,3.37577002053388,3.37577002053388,3.37577002053388,3.37577002053388,3.47707049965777,3.47707049965777,3.564681724846,3.75085557837098,3.75085557837098,3.75085557837098,3.854893908282,3.854893908282,3.9233401779603,3.9233401779603,3.95071868583162,3.97809719370294,3.97809719370294,3.99452429842574,3.99452429842574,4.13141683778234,4.13141683778234,4.17522245037645,4.18891170431212,4.19712525667351,4.19712525667351,4.33675564681725,4.33675564681725,4.42984257357974,4.42984257357974,4.46817248459959,4.47638603696099,4.47638603696099,4.51745379876797,4.51745379876797,4.66803559206023,4.66803559206023,4.71184120465435,4.71184120465435,4.80492813141684,4.80492813141684,4.87063655030801,4.87063655030801,4.94729637234771,4.94729637234771,4.96646132785763,4.96646132785763,4.99657768651609,5.01026694045174,5.01026694045174,5.01574264202601,5.09240246406571,5.09240246406571,5.16632443531828,5.16632443531828,5.18275154004107,5.18275154004107,5.28405201916496,5.28405201916496,4.08487337440109,5.31690622861054,5.31690622861054,5.33333333333333,5.33333333333333,5.35249828884326,5.4154688569473,5.4154688569473,5.47022587268994,5.47022587268994,5.48939082819986,5.48939082819986,5.51129363449692,5.51129363449692,5.51403148528405,5.51403148528405,5.53319644079398,5.57152635181383,5.57152635181383,5.77686516084873,5.77686516084873,5.95482546201232,5.95482546201232,5.97672826830938,5.97672826830938,6.00958247775496,6.00958247775496,6.14373716632443,6.14373716632443,6.20396988364134,6.20396988364134,6.23408624229979,6.39561943874059,6.39561943874059,6.41752224503765,6.47227926078029,-0.0492813141683778], surgery = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,0,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0], transplant = [0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,0,0], id = [1,2,3,3,4,4,5,6,7,7,8,9,10,10,11,11,12,13,13,14,14,15,16,16,17,18,18,19,20,20,21,21,22,22,23,23,24,24,25,25,26,27,28,28,29,30,30,31,32,32,33,33,34,34,35,36,36,37,37,38,38,39,39,40,40,41,41,42,43,44,45,45,46,46,47,47,48,49,49,50,50,51,51,52,53,53,54,55,55,56,56,57,58,58,59,59,60,60,61,62,63,63,64,64,65,65,66,67,67,68,68,69,69,70,70,71,71,72,72,73,73,74,74,75,76,76,77,78,78,79,79,80,80,81,81,82,83,83,84,84,85,86,86,87,87,88,88,89,89,90,90,91,92,92,93,93,94,94,95,95,96,96,97,97,98,98,99,100,100,101,102,103])

)
data[kwargs...]
end


13 changes: 7 additions & 6 deletions src/plot_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ end
Recipe for cox-model based risk curves
```julia
using Plots, LSurvival
res = z, x, outt, d, event, weights = LSurvival.dgm_comprisk(MersenneTwister(123123), 100)
using Plots, LSurvival, Random, StatsBase
res = z, x, outt, d, event, wts = LSurvival.dgm_comprisk(MersenneTwister(123123), 100)
X = hcat(z, x)
int = zeros(length(d)) # no late entry
ft1 = fit(PHModel, X, int, outt, d .* (event .== 1))
ft2 = fit(PHModel, X, int, outt, d .* (event .== 2))
ft1 = fit(PHModel, X, int, outt, d .* (event .== 1), wts=wts)
ft2 = fit(PHModel, X, int, outt, d .* (event .== 2), wts=wts)
c = risk_from_coxphmodels([ft1, ft2], pred_profile = mean(X, dims=1))
plot(c)
Expand Down Expand Up @@ -253,7 +253,8 @@ dat2 = (
)
fte = coxph(@formula(Surv(enter, exit, status)~x), dat2)
coxinfluence(fte, type="jackknife")
coxinfluence(fte, type="jackknife", par=1)
coxinfluence!(fte, type="dfbeta", color=:red, par=1)
```
"""
Expand All @@ -274,7 +275,7 @@ coxinfluence(fte, type="jackknife")
label --> type
markesize --> 2
markeralpha --> 0.5
id, res
id, res[:,par]
end
@series begin
seriestype := :hline
Expand Down

0 comments on commit 8fbce96

Please sign in to comment.