-
Notifications
You must be signed in to change notification settings - Fork 18
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
custom_statistics
: format and storing stats in regression object
#129
Comments
using Statistics, Formatting
comments = ["Baseline", "Preferred"]
means = [sprintf1("%0.6f",Statistics.mean(df.SepalLength[rr1.esample])), sprintf1("%0.6f",Statistics.mean(df.SepalLength[rr2.esample]))]
mystats = NamedTuple{(:comments, :means)}((comments, means))
RegressionTables.regtable(rr1, rr2; renderSettings = RegressionTables.asciiOutput(), regression_statistics = [:nobs, :r2],custom_statistics = mystats, labels = Dict("__LABEL_CUSTOM_STATISTIC_comments__" => "Specification", "__LABEL_CUSTOM_STATISTIC_means__" => "My custom mean") ) If you have an idea about what would be a good interface for the formatting of these additional statistics, let me know.
function mycustomstatistic(rr::RegressionModel)
return 3.141592 # or something that depends only on rr
end
mystats = NamedTuple{(:foo)}(mycustomstatistic)
RegressionTables.regtable(rr1, rr2; renderSettings = RegressionTables.asciiOutput(), custom_statistics = mystats) Let me know what you think. |
"pre"-formatting the statistics as strings is a convenient solution! For the 2nd issue, for my workflow, the ideal would be if It is a great suggestion to do this via a struct that includes |
Here is my code to wrap fixed effects model (linear and GL) to include statistics, and to then include them (with formatting) in a regression table. I'm sure that this can be much improved!
|
Looks neat! I'm wondering whether it would make sense to implement this as a new parametric type in RegressionTables.jl, something like this: struct AugmentedRegressionModel{T}
model::T
stats::Dict{Symbol, Union{String, Number}}
end The advantage would be that it could work out-of-the-box with any output model type, including anything that's implementing the StatsBase abstraction. That could be a neat way to override the estimated VCov matrix with some custom one as well... |
I find the
custom_statistics
option super helpful, for example for displaying the mean of the outcome variable, number of units (in a panel setting), etc.I have two questions on features that would make this easier to use for me:
custom_statistics
? Currently, I think they are all%0.3f
NamedTuple
. I currently define these stats after running my regression, and carry them alongside the regression object. It would be more convenient to store these stats in the regression object itself and tellregtable
what to print. Is this feasible? (I realize this might (also) be a question for the regression packages.)The text was updated successfully, but these errors were encountered: