Skip to content

Commit

Permalink
added show cox test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Vertechi committed Dec 18, 2017
1 parent 16e20a9 commit fb182b0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 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
25 changes: 14 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,23 @@ end
outcome = coxph(@formula(event ~ fin+age+race+wexp+mar+paro+prio), rossi; tol = 1e-8)
outcome_coefmat = coeftable(outcome)

@test sprint(show, outcome) == """
StatsModels.DataFrameRegressionModel{Survival.CoxModel{Float64},Array{Float64,2}}
regressor_matrix = Array(rossi[[:fin, :age, :race, :wexp, :mar, :paro, :prio]])
event_vector = rossi[:event]

Formula: event ~ fin + age + race + wexp + mar + paro + prio
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|)
fin -0.379422 0.191379 -1.98256 0.0474
age -0.0574377 0.0219995 -2.61087 0.0090
race 0.3139 0.307993 1.01918 0.3081
wexp -0.149796 0.212224 -0.705837 0.4803
mar -0.433704 0.381868 -1.13574 0.2561
paro -0.0848711 0.195757 -0.433554 0.6646
prio 0.0914971 0.0286485 3.19378 0.0014
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
Expand Down

0 comments on commit fb182b0

Please sign in to comment.