Skip to content

Commit

Permalink
YAS
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Mar 22, 2024
1 parent e59788f commit b2cbf40
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/MixedModelsMakie.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export RanefInfo,
zetaplot!

# from https://github.com/MakieOrg/Makie.jl/issues/2992
const Indexable = Union{Makie.Figure,Makie.GridLayout,Makie.GridPosition,Makie.GridSubposition}
const Indexable = Union{Makie.Figure,Makie.GridLayout,Makie.GridPosition,
Makie.GridSubposition}

include("utilities.jl")
include("shrinkage.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/coefplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function coefplot!(ax::Axis, x::Union{MixedModel,MixedModelBootstrap};
xvals = ci.estimate
xlabel = @sprintf "Estimate and %g%% confidence interval" conf_level * 100

attributes = merge((;xlabel), attributes)
attributes = merge((; xlabel), attributes)
ax.xlabel = attributes.xlabel

scatter!(ax, xvals, y; attributes...)
errorbars!(ax, xvals, y, xvals .- ci.lower, ci.upper .- xvals;
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)

Expand Down
20 changes: 11 additions & 9 deletions src/ridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The mutating methods return the original object.
function ridgeplot(x::MixedModelBootstrap; show_intercept=true, kwargs...)
# need to guarantee a min height of 200
fig = Figure(; size=(640, max(200, 100 * _npreds(x; show_intercept))))
return ridgeplot!(fig, x,; show_intercept, kwargs...)
return ridgeplot!(fig, x; show_intercept, kwargs...)
end

"""$(@doc ridgeplot)"""
Expand All @@ -40,21 +40,23 @@ _color(p::Pair) = first(p)

"""$(@doc ridgeplot)"""
function ridgeplot!(ax::Axis, x::MixedModelBootstrap;
conf_level=0.95,
vline_at_zero=true,
show_intercept=true,
attributes...)
conf_level=0.95,
vline_at_zero=true,
show_intercept=true,
attributes...)
xlabel = if !ismissing(conf_level)
@sprintf "Normalized bootstrap density and %g%% confidence interval" (conf_level * 100)
@sprintf "Normalized bootstrap density and %g%% confidence interval" (conf_level *
100)
else
"Normalized bootstrap density"
end

if !ismissing(conf_level)
coefplot!(ax, x; conf_level, vline_at_zero, show_intercept, color=:black, attributes...)
coefplot!(ax, x; conf_level, vline_at_zero, show_intercept, color=:black,
attributes...)
end

attributes = merge((;xlabel, color=:black), attributes)
attributes = merge((; xlabel, color=:black), attributes)
band_attributes = merge(attributes, (; color=(_color(attributes.color), 0.3)))

ax.xlabel = attributes.xlabel
Expand All @@ -77,7 +79,7 @@ function ridgeplot!(ax::Axis, x::MixedModelBootstrap;
band!(ax, lower, upper; band_attributes...)
lines!(ax, upper; attributes...)
end

# check conf_level so that we don't double print
# if coefplot took care of it for us
if ismissing(conf_level)
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ g1 = fit(MixedModel,

rng = MersenneTwister(0)
x = rand(rng, 100)
data = (x = x, x2 = 1.5 .* x, y = rand(rng, [0,1], 100), z = repeat('A':'T', 5))
mr = @suppress fit(MixedModel, @formula(y ~ x + x2 + (1|z)), data; progress)
data = (x=x, x2=1.5 .* x, y=rand(rng, [0, 1], 100), z=repeat('A':'T', 5))
mr = @suppress fit(MixedModel, @formula(y ~ x + x2 + (1 | z)), data; progress)
br = parametricbootstrap(MersenneTwister(42), 500, mr; progress,
optsum_overrides=(; ftol_rel=1e-6))

Expand Down

0 comments on commit b2cbf40

Please sign in to comment.