API of Underlying Functions
DataRow
RegressionTables.DataRow
— Typemutable struct DataRow{T<:AbstractRenderType} <: AbstractVector{String}
data::Vector
align::String
colwidths::Vector{Int}
print_underlines::Vector{Bool}
render::T
end
DataRow(x::DataRow) = x
(::Type{T})(x::DataRow) where {T<:AbstractRenderType} = DataRow(x.data, x.align, x.colwidths, x.print_underlines, T())
function DataRow(
data::Vector,
align,
colwidths,
print_underlines,
render::AbstractRenderType;
combine_equals=false
)
function DataRow(
data::Vector;
align="l" * "r" ^ (length(data) - 1),
colwidths=fill(0, length(data)),
print_underlines=zeros(Bool, length(data)),
render::AbstractRenderType=AsciiTable(),
combine_equals=false
)
DataRow forms the fundamental element of a RegressionTable. For a user, these can be passed as additional elements to group
or extralines
in regtable
. A DataRow is typed with an AbstractRenderType
, which controls how the DataRow is displayed. The default is AsciiTable
. The DataRow contains four other elements:
data::Vector
: The data to be displayed in the row. Can be individual elements (e.g., [1, 2, 3]) or pairs with a range (e.g., [1 => 1:2, 2 => 3:4]), or a combination of the two.align::String
: A string of ('l', 'r', 'c'), one for each element ofdata
, indicating that elements alignment.colwidths::Vector{Int}
: A vector of integers, one for each element ofdata
, indicating the width of the column. Can calculate the widths automatically usingcalc_widths
and update them withupdate_widths!
.print_underlines::Vector{Bool}
: A vector of booleans, one for each element ofdata
, indicating whether to print an underline under the element. This is useful for printing the header of a table.
DataRow is a subtype of AbstractVector{String}
. It implements getindex
and setindex!
, which allows changing of individual elements.
In most cases, it is not necessary to specify the render type for DataRow. While constructing a RegressionTable, the render type is changed to the render type of the RegressionTable.
Examples
julia> DataRow(["", "Group 1" => 2:3, "Group 2" => 4:5])
Group 1 Group 2
julia> DataRow(["", "Group 1", "Group 1", "Group 2", "Group 2"]; combine_equals=true)
Group 1 Group 2
julia> DataRow(["", "Group 1" => 2:3, "Group 2" => 4:5])
Group 1 Group 2
julia> DataRow([" ", "Group 1" => 2:3, "Group 2" => 4:5]; print_underlines=[false, false, true])
Group 1 Group 2
-------
julia> DataRow(["Group 0", "Group 1" => 2:3, "Group 2" => 4:5]; colwidths=[20, 20, 20], align="lcr", print_underlines=true)
Group 0 Group 1 Group 2
-------------------- -------------------- --------------------
julia> DataRow(["", "Group 1" => 2:3, "Group 2" => 4:5]; render=LatexTable())
& \multicolumn{2}{r}{Group 1} & \multicolumn{2}{r}{Group 2} \\
RegressionTable
RegressionTables.RegressionTable
— Typemutable struct RegressionTable{T<:AbstractRenderType} <: AbstractMatrix{String}
data::Vector{DataRow{T}}
align::String
render::T
breaks::Vector{Int}
colwidths::Vector{Int}
vertical_gaps::Vector{Int}
end
RegressionTable(header::Vector, body::Matrix, args...; vargs...)
RegressionTable(
header::Matrix,
body::Matrix,
render::T=AsciiTable();
breaks=[size(header, 1)],
align='l' * 'r' ^ (size(header, 2) - 1),
colwidths=fill(0, size(header, 2)),
header_align='l' * 'c' ^ (size(header, 2) - 1),
extralines::Vector = DataRow[]
) where T<:AbstractRenderType
The general container. This provides some general information about the table. The DataRow
handles the main printing, but this provides other necessary information, especially the break
field, which is used to determine where to put the lines (e.g., \midrule
in LaTeX).
data
: A vector ofDataRow
objects.align
: A string of characters, one for each column, indicating the alignment of the column. The characters arel
for left,c
for center, andr
for right.render
: The render type of the table. This must be the same as the render type of theDataRow
objects and is used for convenience.breaks
: A vector of integers, indicating where to put the lines (e.g.,\midrule
in LaTeX). When displayed, the break will be placed after the line number is printed (breaks = [5] will print a break after the 5th line is printed).colwidths
: A vector of integers, one for each column, indicating the width of the column. Can calculate the widths automatically usingcalc_widths
and update them withupdate_widths!
.vertical_gaps
: A vector of integers, indicating where to put vertical gaps in the table. These are places where two underlined cells are not connected. This is necessary for Excel integration.
The RegressionTable
is a subtype of the AbstractMatrix{String}
type (though this functionality is somewhat experimental). Importantly, this implements getindex
and setindex!
, which means individual elements of the table can be modified after its construction. See examples below. It also allows a RegressionTable
to be passed to a function that expects a matrix, for example, exporting to a DataFrame
DataFrames.jl would be DataFrame(Matrix(tab), :auto)
. Note that this will not keep multicolumn, unerlines, etc. information, but could be useful for exporting to other formats.
This type also has two convenience constructors which might be helpful if using this package to print summary statistics.
Example
julia> df = RDatasets.dataset("datasets", "iris");
julia> df = describe(df, :mean, :std, :q25, :median, :q75; cols=["SepalLength", "SepalWidth", "PetalLength", "PetalWidth"]);
julia> t = RegressionTables.RegressionTable(names(df), Matrix(df))
----------------------------------------------------
variable mean std q25 median q75
----------------------------------------------------
SepalLength 5.843 0.828 5.100 5.800 6.400
SepalWidth 3.057 0.436 2.800 3.000 3.300
PetalLength 3.758 1.765 1.600 4.350 5.100
PetalWidth 1.199 0.762 0.300 1.300 1.800
----------------------------------------------------
julia> t[1, 2] = "Mean of Variable";
julia> t[2, 3] = 0;
julia> RegressionTables.update_widths!(t); # necessary if a column gets longer
julia> t
---------------------------------------------------------------
variable Mean of Variable std q25 median q75
---------------------------------------------------------------
SepalLength 5.843 0 5.100 5.800 6.400
SepalWidth 3.057 0.436 2.800 3.000 3.300
PetalLength 3.758 1.765 1.600 4.350 5.100
PetalWidth 1.199 0.762 0.300 1.300 1.800
---------------------------------------------------------------
Render Types
RegressionTables.AbstractRenderType
— Typeabstract type AbstractRenderType end
The generic top level type for render types. Most defaults are set here unless there is a reason it needs to be set at a lower level. Subtypes are still abstract types and include AbstractAscii
, AbstractLatex
, and AbstractHtml
.
Ascii
RegressionTables.AbstractAscii
— Typeabstract type AbstractAscii <: AbstractRenderType end
The abstract type for most plain text rendering. Printing is defined using the AbstractAscii
, so new tables (with different defaults) can be created by subtyping AbstractAscii
with minimal effort.
RegressionTables.AsciiTable
— Typestruct AsciiTable <: AbstractAscii end
The main concrete type for AbstractAscii
. This is the default type used for plain text rendering.
Latex
RegressionTables.AbstractLatex
— Typeabstract type AbstractLatex <: AbstractRenderType end
The abstract type for most plain text rendering. Printing is defined using the AbstractLatex
, so new tables (with different defaults) can be created by subtyping AbstractLatex
with minimal effort.
RegressionTables.LatexTable
— Typestruct LatexTable <: AbstractLatex end
The main concrete type for AbstractLatex
. This type is used to create Latex tables.
RegressionTables.LatexTableStar
— Typestruct LatexTableStar <: AbstractLatex end
An alternative concrete type for AbstractLatex
. This type is used to create Latex tables that span the entire text width.
HTML
RegressionTables.AbstractHtml
— Typeabstract type AbstractHtml <: AbstractRenderType end
The abstract type for most plain text rendering. Printing is defined using the AbstractHtml
, so new tables (with different defaults) can be created by subtyping AbstractHtml
with minimal effort.
RegressionTables.HtmlTable
— Typestruct HtmlTable <: AbstractHtml end
The main concrete type for AbstractHtml
. This type is used to create HTML tables.
Coefficient Naming
RegressionTables.AbstractCoefName
— Typeabstract type AbstractCoefName end
These names largely mirror their equivalents in StatsModels.jl. The main difference here is that the names are always based on strings (instead of symbols). There are also several default functions that are resused (e.g., get
and replace
) to make relabeling coefficients easier.
AbstractCoefName simply acts as a parent type to the other types. The other types are:
CoefName
: forTerm
,ContinuousTerm
andFunctionTerm
InteractedCoefName
: forInteractionTerm
CategoricalCoefName
: forCategoricalTerm
InterceptCoefName
: forConstantTerm
Using the function get_coefname
will return the appropriate type for the term.
RegressionTables.get_coefname
— Functionget_coefname(x::AbstractTerm)::CoefName
get_coefname(x::Term)::CoefName
get_coefname(x::InteractionTerm)::InteractedCoefName
get_coefname(x::InterceptTerm{H})::InterceptCoefName
get_coefname(x::CategoricalTerm)::CategoricalCoefName
RegressionTables.CategoricalCoefName
— Typestruct CategoricalCoefName <: AbstractCoefName
name::String
level::String
end
Used to store the name of a coefficient for a CategoricalTerm
. The level
is the level of the categorical. In other words, the name
is the column name, the level
is the category within that column.
In a regression, the display of categorical terms is typically displayed as "name: level". You can change how the categorical term is "equal" by changing the categorical_equal
function. The default is ": ", but you can change: this by setting:
RegressionTables.categorical_equal(render::AbstractRenderType) = " = "
RegressionTables.categorical_equal(render::AbstractLatex) = " $=$ "
You can also change how the categorical term is displayed by changing the repr
function. The default is:
Base.repr(render::AbstractRenderType, x::RegressionTables.CategoricalCoefName; args...) =
"$(RegressionTables.value(x))$(RegressionTables.categorical_equal(render)) $(x.level)"
RegressionTables.CoefName
— Typestruct CoefName <: AbstractCoefName
name::String
end
Used to store the name of a coefficient. This is used for Term
, ContinuousTerm
and FunctionTerm
.
RegressionTables.FixedEffectCoefName
— Typestruct FixedEffectCoefName <: AbstractCoefName
name::AbstractCoefName
end
Used to store the name of a coefficient for a FixedEffectTerm
. The name
is the name of the fixed effect. This allows a suffix to be applied later.
RegressionTables.InteractedCoefName
— Typestruct InteractedCoefName <: AbstractCoefName
names::Vector
end
Used to store the different coefficient names that makes up an InteractionTerm. The internals of the vector are typically CoefName
, but can also be strings.
In a regression, each element of the vector is typically displayed as "name1 & name2 & ..." (in AsciiTables). The separator is set by interaction_combine
function, and the default varies based on AbstractRenderType
:
- For
AbstractAscii
, it defaults to" & "
- For
AbstractLaTeX
, it defaults to" $\times$ "
- For
AbstractHtml
, it defaults to" × "
You can change the separator by running:
RegressionTables.interaction_combine(render::$RenderType) = " & "
where $RenderType
is the type of the renderer you want to change. For example, to change the output in AbstractLaTeX
:
RegressionTables.interaction_combine(::AbstractLaTeX) = " \& "
You can control how interaction terms are displayed more generally by changing:
Base.repr(render::AbstractRenderType, x::RegressionTables.InteractedCoefName; args...) =
join(RegressionTables.value.(x), RegressionTables.interaction_combine(render))
See Customization of Defaults for more details.
RegressionTables.InterceptCoefName
— Typestruct InterceptCoefName <: AbstractCoefName end
Used as a simple indicator for the existence of an intercept term. This allows relabeling of the intercept in all cases by setting
RegressionTables.label(::InterceptCoefName) = "My Intercept"
See Customization of Defaults for more details.
RegressionTables.RandomEffectCoefName
— Typestruct RandomEffectCoefName <: AbstractCoefName
rhs::CoefName
lhs::AbstractCoefName
val::Float64
end
Used to store the name and the standard deviation of a coefficient for a RandomEffectTerm
from MixedModels.jl. The standard deviation is stored since that is often the useful information on the relationship between rhs and lhs.
Utility Functions
RegressionTables.calc_widths
— Functioncalc_widths(rows::Vector{DataRow{T}}) where {T<:AbstractRenderType}
Calculate the widths of each column in the table. For rows with multicolumn cells, the width of the multicolumn is divided evenly among the columns it spans.
RegressionTables.update_widths!
— Functionupdate_widths!(row::DataRow{T}, new_lengths=length.(repr.(T(), row.data))) where {T}
Updates the widths of each column in the row. If lengths are provided, then it should equate to the total number of columns in the table, not the number of elements in the row.
RegressionTables.value_pos
— Functionvalue_pos(nms, x::String)
Returns the position of the string x
in the vector of strings or AbstractCoefName
nms
.
Example
julia> import RegressionTables: CoefName, InterceptCoefName, InteractedCoefName, CategoricalCoefName, value_pos
julia> nms = ["coef1", CoefName("coef2"), InterceptCoefName(), InteractedCoefName(["coef3", "coef4"]), InteractedCoefName([CoefName("coef1"), CoefName("coef3")]), CategoricalCoefName("coef5", "10"), CategoricalCoefName("coef5", "20")];
julia> value_pos(nms, "coef1")
1:1
julia> value_pos(nms, "coef2")
2:2
julia> value_pos(nms, "coef3")
Int64[]
julia> value_pos(nms, "coef3 & coef4")
4:4
julia> value_pos(nms, "(Intercept)")
3:3
julia> value_pos(nms, "coef1 & coef3")
5:5
julia> value_pos(nms, "coef5: 10")
6:6
value_pos(nms, x::Int)
Checks that x
is a valid index for the vector of strings or AbstractCoefName
nms
and returns a range of x:x
value_pos(nms, x::UnitRange)
Checks that x
is a valid index for the vector of strings or AbstractCoefName
nms
and returns x
value_pos(nms, x::BitVector)
Returns a vector of indices where x
is true
, called by the regex version of value_pos
.
value_pos(nms, x::Regex)
Looks within each element of the vector nms
(which is either a string or an AbstractCoefName
) and returns a vector of indices where the regex x
is found.
Example
julia> import RegressionTables: CoefName, InterceptCoefName, InteractedCoefName, CategoricalCoefName, value_pos
julia> nms = ["coef1", CoefName("coef2"), InterceptCoefName(), InteractedCoefName(["coef3", "coef4"]), InteractedCoefName([CoefName("coef1"), CoefName("coef3")]), CategoricalCoefName("coef5", "10"), CategoricalCoefName("coef5", "20")];
julia> value_pos(nms, r"coef1") == [1, 5]
true
julia> value_pos(nms, r"coef[1-3]") == [1, 2, 4, 5]
true
julia> value_pos(nms, r"coef[1-3] & coef4") == [4]
true
julia> value_pos(nms, r" & ") == [4, 5]
true
julia> value_pos(nms, r"coef5") == [6, 7]
true
julia> value_pos(nms, r"coef5: 10") == [6]
true
value_pos(nms, x::Nothing)
Returns an empty vector, called by the regex and string version of value_pos
.
value_pos(nms, x::Symbol)
Expects a symbol of the form :last
or :end
and returns the last value of nms
, both are included for consistency with the Tuple
Example
julia> import RegressionTables: CoefName, InterceptCoefName, InteractedCoefName, CategoricalCoefName, value_pos
julia> nms = ["coef1", CoefName("coef2"), InterceptCoefName(), InteractedCoefName(["coef3", "coef4"]), InteractedCoefName([CoefName("coef1"), CoefName("coef3")]), CategoricalCoefName("coef5", "10"), CategoricalCoefName("coef5", "20")];
julia> value_pos(nms, :last)
7:7
julia> value_pos(nms, :end)
7:7
value_pos(nms, x::Tuple{Symbol, Int})
Expects a tuple of the form (:last, n)
or (:end, n)
. (:last, n)
returns the last n
values (1:5
with (:last, 2)
is 4:5
), while (:end, n)
returns the last index minus n
(1:5
with (:end, 2)
is 3
).
Example
julia> import RegressionTables: CoefName, InterceptCoefName, InteractedCoefName, CategoricalCoefName, value_pos
julia> nms = ["coef1", CoefName("coef2"), InterceptCoefName(), InteractedCoefName(["coef3", "coef4"]), InteractedCoefName([CoefName("coef1"), CoefName("coef3")]), CategoricalCoefName("coef5", "10"), CategoricalCoefName("coef5", "20")];
julia> value_pos(nms, (:last, 2))
6:7
julia> value_pos(nms, (:end, 2))
5:5
RegressionTables.combine_other_statistics
— Functioncombine_other_statistics(combine_other_statistics(
stats;
fill_val=missing,
print_fe_suffix=true,
fixedeffects=Vector{String}(),
labels=Dict{String, String}(),
transform_labels=Dict{String, String}(),
kwargs...
)
Takes vector of nothing or statistics and combines these into a single section. These stats should be a vector of pairs, so this function expects a vector of these vector pairs or nothing. The function will combine the pairs into a single matrix. The first matrix column is a list of unique names which are the first value of the pairs and the rest of the matrix is the last value of the pairs organized.
Arguments
stats
is aVector
ofVector{Pair}
ornothing
that should be combined.fill_val
defaults tomissing
but is the default value if the statistic is not present in that regression. For example, with fixed effects this defaults toFixedEffectValue(false)
if the fixed effect is not present in the regression.fixedeffects
is aVector
of fixed effects to include in the table. Defaults toVector{String}()
, which means all fixed effects are included. Can also be regex, integers or ranges to select which fixed effectsprint_fe_suffix
is aBool
that governs whether the fixed effects should be printed with a suffix. Defaults totrue
, which means the fixed effects will be printed as$X Fixed Effects
. Iffalse
, the fixed effects will just be the fixed effect ($X
).labels
is the labels from the mainregtable
, used to change the names of the names.transform_labels
is the transform_labels from the mainregtable
.kwargs
are any otherkwargs
passed toregtable
, allowing for flexible arguments for truly custom type naming.
RegressionTables.combine_statistics
— Functioncombine_statistics(tables, stats)
Takes a set of tables (RegressionModel
s) and a vector of AbstractRegressionStatistic
. The stats
argument can also be a pair of AbstractRegressionStatistic => String
, which uses the second value as the name of the statistic in the final table.
RegressionTables.build_nm_list
— Functionbuild_nm_list(nms, keep)
Takes the list of strings or AbstractCoefName
nms
and returns a subset of nms
that contains only the elements in keep
. Will also reorder the elements that are kept based on the order of keep
.
RegressionTables.reorder_nms_list
— Functionreorder_nms_list(nms, order)
Reorders the vector of strings or AbstractCoefName
nms
according to the order
provided. All elements of nms
are kept.
RegressionTables.drop_names!
— Functiondrop_names!(nms, to_drop)
Drops the elements of nms
that are in to_drop
. Does not reorder any other elements.
RegressionTables.add_blank
— Functionadd_blank(groups::Matrix, n)
add_blank(groups::Vector{Vector}, n)
Recursively checks whether the number of columns in groups
(or the length of the vector groups
) is less than n
, if so, add a blank column (or element) to the left of the matrix (first element of the vector).
This is used to make sure a provided piece of data is at least n
columns, fitting into the table.
RegressionTables.missing_vars
— Functionmissing_vars(table::RegressionModel, coefs::Vector)
Checks whether any of the coefficients in table
are not in coefs
, returns true
if so, false
otherwise.
RegressionTables.add_element!
— Functionadd_element!(row::DataRow, val, align_i, colwidth_i, print_underline_i, i)
Adds an element to the row and is only called when combine_equals=true
. This means that if the last element in the row is the same as the provided val
, then the last element is extended to include the new column.
add_element!(row::DataRow, val::Pair, align_i, colwidth_i, print_underline_i, i)
Adds an element to the row and is only called when combine_equals=true
. Since val
is a pair, is is simply added to the row as is, this allows for the creation of two multicolumn cells that have the same information but are separate.
RegressionTables.find_vertical_gaps
— Functionfind_vertical_gaps(data::Vector{DataRow{T}}) where T
Finds locations in a vector of DataRow
objects where there are vertical gaps. A "vertical gap" is a place where two underlined cells are not connected. If there is a gap, then there needs to be a space between the current column and the next column. This makes it unnecessary to have a final vertical gap since the table ends there.
RegressionTables.extra_cell_space
— Functionextra_cell_space(render::AbstractRenderType)
Used to add extra space to the cell and defaults to 0.
How Types are Displayed
This section describes how different types are displayed. Throughout this package, repr(T(), x)
where T
is a concrete type of AbstractRenderType
is used to convert something to a string. This allows two things.
- Since it is easy to create new
AbstractRenderType
s, it is possible to create customized displays for almost anyway situation - Since most things in this package are types, each can be customized
Base.repr
— FunctionBase.repr(render::AbstractRenderType, x; args...)
Will render x as a string
Base.repr(render::AbstractRenderType, x::Pair; args...)
By default, will render the first element of the pair according to the render type. In cases of AbstractLatex
or AbstractHtml
, uses the second element to determine number of columns to span.
Base.repr(render::AbstractRenderType, x::Int; args...)
By default, will render the integer with commas
Base.repr(render::AbstractRenderType, x::Float64; digits=default_digits(render, x), commas=true, str_format=nothing, args...)
By default, will render the float with commas and the default number of digits. If str_format
is specified, will use that instead of digits
and commas
Base.repr(render::AbstractRenderType, x::Nothing; args...)
By default, will render the nothing as an empty string
Base.repr(render::AbstractRenderType, x::Missing; args...)
By default, will render the missing as an empty string
Base.repr(render::AbstractRenderType, x::AbstractString; args...)
By default, will render the string as is
Base.repr(render::AbstractRenderType, x::Bool; args...)
By default, will render the boolean as "Yes" or ""
Base.repr(render::AbstractRenderType, x::AbstractRegressionStatistic; digits=default_digits(render, x), args...)
By default, will render the statistic with commas and the default number of digits
Base.repr(render::AbstractRenderType, x::AbstractR2; digits=default_digits(render, x), args...)
By default, will render the same as AbstractRegressionStatistic
Base.repr(render::AbstractRenderType, x::AbstractUnderStatistic; digits=default_digits(render, x), args...)
By default, will render with the default number of digits and surrounded by parentheses (1.234)
Base.repr(render::AbstractRenderType, x::ConfInt; digits=default_digits(render, x), args...)
By default, will render with the default number of digits and surrounded by parentheses (1.234, 5.678)
Base.repr(render::AbstractRenderType, x::CoefValue; digits=default_digits(render, x), args...)
By default, will render with the default number of digits and surrounded by parentheses and will call estim_decorator
for the decoration
Base.repr(render::AbstractRenderType, x::Type{V}; args...) where {V <: AbstractRegressionStatistic}
By default, will call the label
function related to the type
Base.repr(render::AbstractRenderType, x::Type{RegressionType}; args...)
By default, will call the label
function related to the RegressionType
Base.repr(render::AbstractRenderType, x::Tuple; args...)
By default, will render the tuple with spaces between the elements
Base.repr(render::AbstractRenderType, x::AbstractCoefName; args...)
By default, will render the name of the coefficient, also see Regression Statistics
Base.repr(render::AbstractRenderType, x::FixedEffectCoefName; args...)
By default, will render the coefficient and add " Fixed Effects"
as a suffix, also see Regression Statistics
Base.repr(render::AbstractRenderType, x::RandomEffectCoefName; args...)
By default, will render the coefficient and add the " Clustering"
function as a separator, also see Regression Statistics
Base.repr(render::AbstractRenderType, x::InteractedCoefName; args...)
By default, will render the coefficient and add the interaction_combine
function as a separator, also see Regression Statistics
Base.repr(render::AbstractRenderType, x::CategoricalCoefName; args...)
By default, will render the coefficient and add the categorical_equal
function as a separator, also see Regression Statistics
Base.repr(render::AbstractRenderType, x::InterceptCoefName; args...)
By default, will render the coefficient as (Intercept)
, also see Regression Statistics
Base.repr(render::AbstractRenderType, x::HasControls; args...)
By default, will render the same as Bool
("Yes" and "")
Base.repr(render::AbstractRenderType, x::RegressionNumbers; args...)
By default, will render the number in parentheses (e.g., "(1)", "(2)"...)
Base.repr(render::AbstractRenderType, x::Type{V}; args...) where {V <: HasControls}
By default, will call the label
function related to the type
Base.repr(render::AbstractRenderType, x::RegressionType; args...)
By default, will check if the RegressionType
is an instrumental variable regression and call the label
function related to the type. If it is an instrumental variable, will then call label_iv
, otherwise it will call the related distribution.
Base.repr(render::AbstractRenderType, x::D; args...) where {D <: UnivariateDistribution}
Will print the distribution as is (e.g., Probit
will be "Probit"), unless another function overrides this behavior (e.g., Normal
, InverseGaussian
, NegativeBinomial
)
Base.repr(render::AbstractRenderType, x::InverseGaussian; args...)
By default, will be "Inverse Gaussian"
Base.repr(render::AbstractRenderType, x::NegativeBinomial; args...)
By default, will be "Negative Binomial"
Base.repr(render::AbstractRenderType, x::Normal; args...)
By default, will call label_ols
Base.repr(render::AbstractRenderType, x::RandomEffectCoefName; args...)
How to render a RandomEffectCoefName
and defaults to the right hand side, then the separator, then the left hand side.
Base.repr(render::AbstractRenderType, x::FixedEffectValue; args...)
How to render a FixedEffectValue
and defaults to calling fe_value
Base.repr(render::AbstractRenderType, x::ClusterValue; args...)
How to render a ClusterValue
and defaults to how true
and false
is displayed.
If wanting to show the size of the clusters, run:
RegressionTables.repr(render::AbstractRenderType, x::ClusterValue; args...) = repr(render, value(x); args...)
Base.repr(render::AbstractRenderType, x::RandomEffectValue; args...)
How to render a RandomEffectValue
and defaults to calling another render function, dependent on the type of the value
New RegressionModel Types
This package is designed to be generally compatible with the RegressionModel abstraction. It has special conditions defined around four commonly used packages (FixedEffectModels.jl, GLM.jl, GLFixedEffectModels.jl and MixedModels.jl). It is possible to add new models to this list, either by creating an extension for this package or by creating the necessary items in an independent package.
For any new RegressionModel
, there may be a need to define the following functions for the package to work correctly. Many of these will work without any issues if following the StatsModels API, and many of the others are useful for customizing how the regression result is displayed. It is also possible to redefine how RegressionTables.AbstractRegressionStatistic
are displayed.
RegressionTables._formula
— Function_formula(x::RegressionModel)
Generally a passthrough for the formula
function from the StatsModels
package. Note tha the formula
function returns the FormulaSchema
.
This function is only used internally in the RegressionTables._responsename
and RegressionTables._coefnames
functions. Therefore, if the RegressionModel
uses those two functions without using formula
, this function is not necessary.
RegressionTables._responsename
— Function_responsename(x::RegressionModel)
Returns the name of the dependent variable in the regression model. The default is to return a parsed version of the left hand side of formula (RegressionTables._formula
), but if that is not available, then it will return the StatsAPI.responsename
function.
RegressionTables._coefnames
— Function_coefnames(x::RegressionModel)
Returns a vector of the names of the coefficients in the regression model. The default is to return a parsed version of the formula (RegressionTables._formula
), but if that is not available, then it will return the StatsAPI.coefnames
function.
RegressionTables._coef
— Function_coef(x::RegressionModel)
Returns a vector of the coefficients in the regression model. By default, is just a passthrough for the coef
function from the StatsModels
package.
RegressionTables._stderror
— Function_stderror(x::RegressionModel)
Returns a vector of the standard errors of the coefficients in the regression model. By default, is just a passthrough for the stderror
function from the StatsModels
package.
RegressionTables._dof_residual
— Function_dof_residual(x::RegressionModel)
Returns the degrees of freedom of the residuals in the regression model. By default, is just a passthrough for the dof_residual
function from the StatsModels
package.
RegressionTables._pvalue
— Function_pvalue(x::RegressionModel)
Returns a vector of the p-values of the coefficients in the regression model.
RegressionTables._islinear
— Function_islinear(x::RegressionModel)
Returns a boolean indicating whether the regression model is linear.
RegressionTables.other_stats
— Functionother_stats(rr::RegressionModel, s::Symbol)
Returns any other statistics to be displayed. This is used (if the appropriate extension is loaded) to display the fixed effects in a FixedEffectModel (or GLFixedEffectModel), clusters in those two, or Random Effects in a MixedModel. For other regressions, this returns nothing
.
RegressionTables.default_regression_statistics
— Methoddefault_regression_statistics(rr::RegressionModel)
Returns a vector of AbstractRegressionStatistic
objects. This is used to display the statistics in the table. This is customizable for each RegressionModel
type. The default is to return a vector of Nobs
and R2
.
RegressionTables.can_standardize
— Functioncan_standardize(x::RegressionModel)
Returns a boolean indicating whether the coefficients can be standardized. standardized coefficients are coefficients that are scaled by the standard deviation of the variables. This is useful for comparing the relative importance of the variables in the model.
This is only possible of the RegressionModel
includes the model matrix or the standard deviation of the dependent variable. If the RegressionModel
does not include either of these, then this function should return false
.
See also RegressionTables.standardize_coef_values
.
RegressionTables.standardize_coef_values
— Functionstandardize_coef_values(std_X, std_Y, val)
Standardizes the coefficients by the standard deviation of the variables. This is useful for comparing the relative importance of the variables in the model.
This function is only used if the RegressionTables.can_standardize
function returns true
.
Arguments
std_X::Real
: The standard deviation of the independent variable.std_Y::Real
: The standard deviation of the dependent variable.val::Real
: The value to be standardized (either the coefficient or the standard error).
If the standard deviation of the independent variable is 0, then the interpretation of the coefficient is how many standard deviations of the dependent variable away from 0 is the intercept. In this case, the function returns val / std_Y
.
Otherwise, the function returns val * std_X / std_Y
.
RegressionTables.RegressionType
— Typestruct RegressionType{T}
val::T
is_iv::Bool
end
The type of the regression. val
should be a distribution from the Distributions.jl package. is_iv
indicates whether the regression is an instrumental variable regression. The default label for the regression type is "Estimator". The labels for individual regression types (e.g., "OLS", "Poisson") can be set by running:
RegressionTables.label_ols(render::AbstractRenderType) = $name
RegressionTables.label_iv(render::AbstractRenderType) = $name
Or for individual distributions by running:
Base.repr(render::AbstractRenderType, x::$Distribution; args...) = $Name