Skip to content

Commit

Permalink
Merge pull request #8 from piever/coverage
Browse files Browse the repository at this point in the history
Bring coverage to 100%
  • Loading branch information
ararslan committed Dec 30, 2017
2 parents efecd69 + 8e10d2a commit 8e22dac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/cox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ function StatsBase.coeftable(obj::CoxModel)
["Estimate", "Std.Error", "z value", "Pr(>|z|)"], ["x$i" for i in 1:length(β)], 4)
end

function Base.show(io::IO, obj::CoxModel)
println(io, "$(typeof(obj)):\n\nCoefficients:\n", coeftable(obj))
function Base.show(io::IO, model::CoxModel)
ct = coeftable(model)
println(io, "$(typeof(model))")
println(io)
println(io,"Coefficients:")
show(io, ct)
end

StatsBase.coef(obj::CoxModel) = obj.β
Expand Down
File renamed without changes.
21 changes: 20 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,32 @@ end


@testset "Cox" begin
filepath = joinpath(@__DIR__, "rossi.csv")
filepath = joinpath(@__DIR__, "data", "rossi.csv")
rossi = CSV.read(filepath)
rossi[:event] = EventTime.(rossi[:week],rossi[:arrest] .== 1)

outcome = coxph(@formula(event ~ fin+age+race+wexp+mar+paro+prio), rossi; tol = 1e-8)
outcome_coefmat = coeftable(outcome)

regressor_matrix = Array(rossi[[:fin, :age, :race, :wexp, :mar, :paro, :prio]])
event_vector = rossi[:event]

outcome_without_formula = coxph(regressor_matrix, event_vector)

@test sprint(show, outcome_without_formula) == """
Survival.CoxModel{Float64}
Coefficients:
Estimate Std.Error z value Pr(>|z|)
x1 -0.379416 0.191379 -1.98253 0.0474
x2 -0.0574299 0.0219988 -2.61059 0.0090
x3 0.31392 0.307995 1.01924 0.3081
x4 -0.14981 0.212226 -0.705898 0.4803
x5 -0.433724 0.38187 -1.13579 0.2560
x6 -0.0848615 0.195756 -0.433505 0.6646
x7 0.091521 0.0286469 3.1948 0.0014
"""

coef_matrix = ModelMatrix(ModelFrame(@formula(event ~ 0+fin+age+race+wexp+mar+paro+prio), rossi)).m
outcome_from_matrix = coxph(coef_matrix, rossi[:event]; tol = 1e-8, l2_cost = 0)
outcome_from_matrix32 = coxph(Float32.(coef_matrix), rossi[:event]; tol = 1e-5)
Expand Down

0 comments on commit 8e22dac

Please sign in to comment.