-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show R^2 and F-statistic for regression models #225
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ export | |
SeqDiffCoding, | ||
HypothesisCoding, | ||
ContrastsCoding, | ||
|
||
coefnames, | ||
setcontrasts!, | ||
formula, | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -133,7 +133,7 @@ const TableModels = Union{TableStatisticalModel, TableRegressionModel} | |||||||||||
@delegate TableRegressionModel.model [StatsBase.modelmatrix, | ||||||||||||
StatsBase.residuals, StatsBase.response, | ||||||||||||
StatsBase.predict, StatsBase.predict!, | ||||||||||||
StatsBase.cooksdistance] | ||||||||||||
StatsBase.cooksdistance, fstatistic] | ||||||||||||
StatsBase.predict(m::TableRegressionModel, new_x::AbstractMatrix; kwargs...) = | ||||||||||||
predict(m.model, new_x; kwargs...) | ||||||||||||
# Need to define these manually because of ambiguity using @delegate | ||||||||||||
|
@@ -193,6 +193,22 @@ function StatsBase.coeftable(model::TableModels; kwargs...) | |||||||||||
ct | ||||||||||||
end | ||||||||||||
|
||||||||||||
_show_fit_stats(io::IO, model::TableModels) = nothing | ||||||||||||
|
||||||||||||
function _show_fit_stats(io::IO, model::TableRegressionModel) | ||||||||||||
try | ||||||||||||
println("R²: ", round(r2(model), sigdigits=4), | ||||||||||||
"\t Adjusted R²: ", round(adjr2(model), sigdigits=4)) | ||||||||||||
|
||||||||||||
fstat = fstatistic(model) | ||||||||||||
println(io, fstat) | ||||||||||||
Comment on lines
+203
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nalimilan what if adding a print API to StatsAPI so packages can implement their own printing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xgdgsc every package is free to implement |
||||||||||||
catch e | ||||||||||||
if !(isa(e, MethodError) && (e.f == r2 || e.f == adjr2 || e.f == fstatistic)) | ||||||||||||
rethrow(e) | ||||||||||||
end | ||||||||||||
end | ||||||||||||
end | ||||||||||||
|
||||||||||||
# show function that delegates to coeftable | ||||||||||||
function Base.show(io::IO, model::TableModels) | ||||||||||||
println(io, typeof(model)) | ||||||||||||
|
@@ -202,6 +218,7 @@ function Base.show(io::IO, model::TableModels) | |||||||||||
try | ||||||||||||
println(io,"Coefficients:") | ||||||||||||
show(io, coeftable(model)) | ||||||||||||
_show_fit_stats(io, model) | ||||||||||||
catch e | ||||||||||||
if isa(e, MethodError) || isa(e, ErrorException) && occursin("coeftable is not defined", e.msg) | ||||||||||||
show(io, model.model) | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should ensure that 4 digits are always used, and that "Ajusted" is aligned with the value of the F-statistic on the next line.