Skip to content

Commit

Permalink
fix empty design
Browse files Browse the repository at this point in the history
  • Loading branch information
behinger committed Mar 21, 2024
1 parent 92387a0 commit 3b3c81e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions ext/UnfoldMixedModelsExt/condense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ This function reorders a MixedModels.tidyσs output, according to the formula an
"""
function reorder_tidyσs(t, f)
@debug typeof(f)
#@debug typeof(f)
# get the order from the formula, this is the target
f_order = random_effect_groupings(f) # formula order
@debug f_order
#@debug f_order
f_order = vcat(f_order...)
@debug f_order
#@debug f_order

# find the fixefs
fixef_ix = isnothing.(f_order)
Expand Down
27 changes: 15 additions & 12 deletions src/condense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ StatsModels.coef(mf::LinearModelFit) = mf.estimate
coefs = extract_coef_info(coefsRaw, 2)
#colnames_basis_raw = get_colnames_basis(formulas(uf))# this is unconverted basisfunction basis,
colnames_basis = extract_coef_info(coefsRaw, 3) # this is converted to strings!
#eventnames = extract_coef_info(coefsRaw, 1)
basisnames = extract_coef_info(coefsRaw, 1)
@debug coefs
@debug colnames_basis

Expand All @@ -52,21 +52,24 @@ StatsModels.coef(mf::LinearModelFit) = mf.estimate


designkeys = collect(first.(design(uf)))
if length(designkeys) == 1
# in case of 1 event, repeat it by ncoefs
eventnames = repeat([designkeys[1]], length(coefs))
else
eventnames = []
sizehint!(eventnames, length(chan_rep))
for (ix, evt) in enumerate(designkeys)
push!(
eventnames,
repeat([evt], size(modelmatrices(designmatrix(uf))[ix], 2))...,
)
if design(uf) != [:empty => ()]
basiskeys = [b.name for b in last.(last.(design(uf)))]

eventnames =
Array{Union{eltype(designkeys),eltype(basiskeys)}}(undef, length(basisnames))
for (b, d) in zip(basiskeys, designkeys)
eventnames[basisnames.==b] .= d
end
else
@warn "No design found, falling back to basisnames instead of eventnames"
eventnames = basisnames
end
eventnames_rep = permutedims(repeat(eventnames, 1, nchan), [2, 1])

@debug "length before make_long_df" length(coefs_rep) length(chan_rep) length(
eventnames_rep,
)
@debug nchan, size.(modelmatrices(designmatrix(uf)), 2), length(designkeys)

return make_long_df(
uf,
Expand Down
7 changes: 5 additions & 2 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function renderable(obj::BasisFunction; title = "::BasisFunction")
show(
IOContext(io, :limit => true, :displaysize => (40, 40)),
"text/plain",
kernel(obj, 0.5),
kernel(obj, 0),
)

s = String(take!(io))
Expand Down Expand Up @@ -111,7 +111,10 @@ print design in a beautiful way
function Base.show(io::IO, design::Vector{<:Pair{<:Any,<:Tuple}})
basisList = []
for (first, second) in design
push!(basisList, Panel(first * "=>" * "($(second[1]),$(second[2]))", fit = false))
push!(
basisList,
Panel(string(first) * "=>" * "($(second[1]),$(second[2]))", fit = false),
)
end
print(io, Term.grid(basisList))
end
Expand Down

0 comments on commit 3b3c81e

Please sign in to comment.