Skip to content

Commit dc45b6a

Browse files
Show R^2 for regression models
1 parent 4af81b9 commit dc45b6a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "StatsModels"
22
uuid = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
3-
version = "0.6.22"
3+
version = "0.6.23"
44

55
[deps]
66
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"

src/StatsModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export
3131
SeqDiffCoding,
3232
HypothesisCoding,
3333
ContrastsCoding,
34-
34+
3535
coefnames,
3636
dropterm,
3737
setcontrasts!,

src/statsmodel.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const TableModels = Union{TableStatisticalModel, TableRegressionModel}
122122
StatsBase.stderror, StatsBase.vcov]
123123
@delegate TableRegressionModel.model [StatsBase.modelmatrix,
124124
StatsBase.residuals, StatsBase.response,
125-
StatsBase.predict, StatsBase.predict!,
125+
StatsBase.predict, StatsBase.predict!,
126126
StatsBase.cooksdistance]
127127
StatsBase.predict(m::TableRegressionModel, new_x::AbstractMatrix; kwargs...) =
128128
predict(m.model, new_x; kwargs...)
@@ -180,6 +180,12 @@ function StatsBase.coeftable(model::TableModels; kwargs...)
180180
ct
181181
end
182182

183+
_show_fit_stats(io::IO, model::TableModels) = nothing
184+
185+
function _show_fit_stats(io::IO, model::TableRegressionModel)
186+
println("R²: ", round(r2(model), sigdigits=4))
187+
end
188+
183189
# show function that delegates to coeftable
184190
function Base.show(io::IO, model::TableModels)
185191
try
@@ -189,7 +195,9 @@ function Base.show(io::IO, model::TableModels)
189195
println(io, model.mf.f)
190196
println(io)
191197
println(io,"Coefficients:")
192-
show(io, ct)
198+
println(io, ct)
199+
println(io)
200+
_show_fit_stats(io, model)
193201
catch e
194202
if isa(e, ErrorException) && occursin("coeftable is not defined", e.msg)
195203
show(io, model.model)

0 commit comments

Comments
 (0)