-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support rank deficiency and reduce dependency on Makie recipes (#86)
* start work on rank deficiency * initial pass at conversion to recipeless implementation * version and compat bump * Indexable * coefplot * ridgeplot * ridge2d * YAS * CI update * handle rank deficiency * add tests * YAS * fix a scope warning * eliminate progress message in precompilation
- Loading branch information
Showing
14 changed files
with
185 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "MixedModelsMakie" | ||
uuid = "b12ae82c-6730-437f-aff9-d2c38332a376" | ||
authors = ["Phillip Alday <[email protected]>", "Douglas Bates <[email protected]>", "contributors"] | ||
version = "0.3.28" | ||
version = "0.4.0" | ||
|
||
[deps] | ||
BSplineKit = "093aae92-e908-43d7-9660-e50ee39d5a0a" | ||
|
@@ -19,11 +19,11 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" | |
[compat] | ||
BSplineKit = "0.15, 0.16, 0.17" | ||
DataFrames = "1" | ||
Distributions = "0.21, 0.22, 0.23, 0.24, 0.25" | ||
Distributions = "0.25" | ||
KernelDensity = "0.6.3" | ||
Makie = "0.20" | ||
MixedModels = "4.14" | ||
PrecompileTools = "1" | ||
SpecialFunctions = "1, 2" | ||
StatsBase = "0.31, 0.32, 0.33, 0.34" | ||
julia = "1.8" | ||
StatsBase = "0.33, 0.34" | ||
julia = "1.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,59 @@ | ||
""" | ||
coefplot(x::MixedModel; | ||
conf_level=0.95, vline_at_zero=true, show_intercept=true, attributes...) | ||
coefplot(x::MixedModelBootstrap; | ||
conf_level=0.95, vline_at_zero=true, show_intercept=true, attributes...) | ||
coefplot(x::Union{MixedModel,MixedModelBootstrap}; kwargs...)::Figure | ||
coefplot!(fig::$(Indexable), x::Union{MixedModel,MixedModelBootstrap}; | ||
kwargs...) | ||
coefplot!(ax::Axis, Union{MixedModel,MixedModelBootstrap}; | ||
conf_level=0.95, vline_at_zero=true, show_intercept=true, attributes...) | ||
Create a coefficient plot of the fixed-effects and associated confidence intervals. | ||
!!! note | ||
This functionality is implemented using [Makie recipes](https://makie.juliaplots.org/v0.15.0/recipes.html) | ||
and thus there are also additional auto-generated methods for `coefplot` and `coefplot!` that may be useful | ||
when constructing more complex figures. | ||
Inestimable coefficients (coefficients removed by pivoting in the rank deficient case) are excluded. | ||
`attributes` are passed onto `scatter!` and `errorbars!`. | ||
The mutating methods return the original object. | ||
!!! note | ||
Inestimable coefficients (coefficients removed by pivoting in the rank deficient case) | ||
are excluded. | ||
""" | ||
function coefplot(x::Union{MixedModel,MixedModelBootstrap}; | ||
conf_level=0.95, | ||
vline_at_zero=true, | ||
show_intercept=true, | ||
attributes...) | ||
function coefplot(x::Union{MixedModel,MixedModelBootstrap}; show_intercept=true, kwargs...) | ||
# need to guarantee a min height of 150 | ||
fig = Figure(; size=(640, max(150, 75 * _npreds(x; show_intercept)))) | ||
ax = Axis(fig[1, 1]) | ||
pl = coefplot!(ax, x; conf_level, vline_at_zero, show_intercept, attributes...) | ||
return Makie.FigureAxisPlot(fig, ax, pl) | ||
coefplot!(fig, x; kwargs...) | ||
return fig | ||
end | ||
|
||
@recipe(CoefPlot, x) do scene | ||
return Attributes(; conf_level=0.95, vline_at_zero=true, show_intercept=true) | ||
"""$(@doc coefplot)""" | ||
function coefplot!(fig::Indexable, x::Union{MixedModel,MixedModelBootstrap}; kwargs...) | ||
ax = Axis(fig[1, 1]) | ||
coefplot!(ax, x; kwargs...) | ||
return fig | ||
end | ||
|
||
function Makie.plot!(ax::Axis, P::Type{<:CoefPlot}, allattrs::Makie.Attributes, x) | ||
plot = Makie.plot!(ax.scene, P, allattrs, x) | ||
"""$(@doc coefplot)""" | ||
function coefplot!(ax::Axis, x::Union{MixedModel,MixedModelBootstrap}; | ||
conf_level=0.95, | ||
vline_at_zero=true, | ||
show_intercept=true, | ||
attributes...) | ||
ci = confint_table(x, conf_level; show_intercept) | ||
y = nrow(ci):-1:1 | ||
xvals = ci.estimate | ||
xlabel = @sprintf "Estimate and %g%% confidence interval" conf_level * 100 | ||
|
||
attributes = merge((; xlabel), attributes) | ||
ax.xlabel = attributes.xlabel | ||
|
||
scatter!(ax, xvals, y; attributes...) | ||
errorbars!(ax, xvals, y, xvals .- ci.lower, ci.upper .- xvals; | ||
direction=:x, attributes...) | ||
vline_at_zero && vlines!(ax, 0; color=(:black, 0.75), linestyle=:dash) | ||
|
||
if haskey(allattrs, :title) | ||
ax.title = allattrs.title[] | ||
end | ||
if haskey(allattrs, :xlabel) | ||
ax.xlabel = allattrs.xlabel[] | ||
else | ||
ax.xlabel = @sprintf "Estimate and %g%% confidence interval" (allattrs.conf_level[] * | ||
100) | ||
end | ||
if haskey(allattrs, :ylabel) | ||
ax.ylabel = allattrs.ylabel[] | ||
end | ||
reset_limits!(ax) | ||
show_intercept = allattrs.show_intercept[] | ||
cn = _coefnames(x; show_intercept) | ||
nticks = _npreds(x; show_intercept) | ||
ax.yticks = (nticks:-1:1, cn) | ||
ylims!(ax, 0, nticks + 1) | ||
allattrs.vline_at_zero[] && vlines!(ax, 0; color=(:black, 0.75), linestyle=:dash) | ||
return plot | ||
end | ||
|
||
function Makie.plot!(plot::CoefPlot{<:Tuple{Union{MixedModel,MixedModelBootstrap}}}) | ||
model_or_boot, conf_level = plot[1][], plot.conf_level[] | ||
ci = confint_table(model_or_boot, conf_level) | ||
plot.show_intercept[] || filter!(:coefname => !=("(Intercept)"), ci) | ||
y = nrow(ci):-1:1 | ||
xvals = ci.estimate | ||
scatter!(plot, xvals, y) | ||
errorbars!(plot, xvals, y, xvals .- ci.lower, ci.upper .- xvals; direction=:x) | ||
|
||
return plot | ||
return ax | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f46a7df
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.
@JuliaRegistrator register
Release notes:
While this is technically a breaking release, most users should experience no breakage. Recipe support on Makie 0.20 seems to have some problems, which were foreshadowed in issues like #43. In order to fix this, the implementation of
coefplot
andridgeplot
was changed to no longer depend on the recipe system. Building on this change, the available methods and return types changed slightly:ridgeplot!
andcoefplot!
now return the mutated original objectridgeplot!
andcoefplot!
have support forFigure
,Axis
,GridPosition
andGridSubposition
.ridgeplot
andcoefplot
now return aFigure
(instead ofFigureAxisPlot
)Additionally, models with rank deficient fixed effects and corresponding bootstraps are now supported by
ridgeplot
andcoefplot
. The inestimable coefficients are removed from the display.f46a7df
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.
Registration pull request created: JuliaRegistries/General/103385
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: