Skip to content

Commit

Permalink
Merge branch 'nessie' of https://github.com/JuliaSurv/NetSurvival.jl
Browse files Browse the repository at this point in the history
…into nessie
  • Loading branch information
rimhajal committed May 16, 2024
2 parents 0de4cb5 + 31441dc commit 35b9b36
Showing 1 changed file with 3 additions and 48 deletions.
51 changes: 3 additions & 48 deletions src/Nessie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct Nessie
expected_life_time::Float64
grid::Vector{Float64}
function Nessie(T, Δ, age, year, rate_preds, ratetable)
annual_grid = 0:365.241:maximum(T)
annual_grid = 0:RateTables.RT_DAYS_IN_YEAR:maximum(T)
exp_spl_size = zeros(length(annual_grid))
exp_life_time = 0.0
for i in eachindex(age)
Expand All @@ -13,7 +13,7 @@ struct Nessie
end
exp_life_time += expectation(Lᵢ)
end
return new(exp_spl_size, exp_life_time / 365.241 / length(age), annual_grid)
return new(exp_spl_size, exp_life_time / RateTables.RT_DAYS_IN_YEAR / length(age), annual_grid)
end
end

Expand All @@ -38,51 +38,6 @@ function nessie(args...)
return lt, r
end


# Maybe not necessary ? No need to clutter the interface too much..
expected_life_time(x::Nessie) = x.expected_life_time
expected_sample_size(x::Nessie) = x.expected_sample_size




# function old_Nessie(formula::FormulaTerm, df::DataFrame, rt::RateTables.AbstractRateTable)
# formula_applied = apply_schema(formula,schema(df))
# rate_predictors = String.([RateTables.predictors(rt)...])

# nms = StatsModels.termnames(formula_applied.rhs)
# if isa(nms, String)
# pred_names = [nms]
# else
# pred_names = nms
# end

# times = sort(unique(floor.(df.time ./ 365.241)))
# times = unique([0.0; times])

# times_d = times .* 365.241

# new_df = groupby(df, pred_names)
# povp = zeros(nrow(unique(df[!,pred_names])))
# sit = zeros(length(times))
# num_pop = zeros(nrow(unique(df[!,pred_names])), length(times))

# for i in 1:nrow(unique(df[!,pred_names]))
# for j in 1:nrow(new_df[i])
# Tᵢ = searchsortedlast(times_d, new_df[i].time[j])
# rate_preds = select(new_df[i],rate_predictors)
# rtᵢ = rt[rate_preds[j,:]...]
# Λₚ = 0.0

# for m in 1:Tᵢ
# λₚ = daily_hazard(rtᵢ, new_df[i].age[j] + times_d[m], new_df[i].year[j] + times_d[m])
# ∂Λₚ = λₚ * 365.241
# Λₚ += ∂Λₚ
# Sₚ = exp(-Λₚ)
# num_pop[i,m] += Sₚ
# sit[m] += (1-Sₚ) / λₚ
# end
# end
# povp[i] = mean(sit ./ 365.241)
# end
# return num_pop, povp
# end

0 comments on commit 35b9b36

Please sign in to comment.