From fb182b0cfa9387fac860051a98f4ac30417243b0 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Mon, 18 Dec 2017 19:36:45 +0000 Subject: [PATCH] added show cox test --- src/cox.jl | 8 ++++++-- test/runtests.jl | 25 ++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cox.jl b/src/cox.jl index 5573044..65c0e12 100644 --- a/src/cox.jl +++ b/src/cox.jl @@ -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.β diff --git a/test/runtests.jl b/test/runtests.jl index 95e36f2..eb0ecd9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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