Skip to content
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

Nested blocking vars with vector RT #452

Closed
palday opened this issue Dec 15, 2020 · 5 comments · Fixed by JuliaStats/StatsModels.jl#200
Closed

Nested blocking vars with vector RT #452

palday opened this issue Dec 15, 2020 · 5 comments · Fixed by JuliaStats/StatsModels.jl#200
Assignees

Comments

@palday
Copy link
Member

palday commented Dec 15, 2020

These two formulae should give the same model:

julia> fnested = @formula(Thickness ~ 1 + Source + (1+Source|Lot/Wafer))
FormulaTerm
Response:
  Thickness(unknown)
Predictors:
  1
  Source(unknown)
  (Source,Lot,Wafer)->(1 + Source) | Lot / Wafer

julia> f = @formula(Thickness ~ 1 + Source + (1+Source|Lot) + (1+Source|Lot&Wafer))
FormulaTerm
Response:
  Thickness(unknown)
Predictors:
  1
  Source(unknown)
  (Source,Lot)->(1 + Source) | Lot
  (Source,Lot,Wafer)->(1 + Source) | Lot & Wafer

But fnested fails in construction due to schema problems. I don't think we ever tested the nested RE stuff on a model with a random slope:

julia> fit(MixedModel, fnested, MixedModels.dataset(:oxide))
ERROR: MethodError: no method matching +(::Tuple{InterceptTerm{true},CategoricalTerm{DummyCoding,String,1}}, ::Tuple{RandomEffectsTerm,RandomEffectsTerm})
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:538
  +(::MutableArithmetics.Zero, ::Any) at /home/XXX/.julia/packages/MutableArithmetics/0tlz5/src/rewrite.jl:52
  +(::Tuple{Vararg{Union{AbstractTerm, Tuple{Vararg{AbstractTerm,N}} where N},N}} where N, ::AbstractTerm) at /home/XXX/.julia/packages/StatsModels/cpRh6/src/terms.jl:404
  ...
Stacktrace:
 [1] +(::InterceptTerm{true}, ::CategoricalTerm{DummyCoding,String,1}, ::Tuple{RandomEffectsTerm,RandomEffectsTerm}) at ./operators.jl:538
 [2] sum(::Tuple{InterceptTerm{true},CategoricalTerm{DummyCoding,String,1},Tuple{RandomEffectsTerm,RandomEffectsTerm}}) at ./tuple.jl:396
 [3] apply_schema(::Tuple{ConstantTerm{Int64},Term,FunctionTerm{typeof(|),var"#107#109",(:Source, :Lot, :Wafer)}}, ::MixedModels.MultiSchema{StatsModels.FullRank}, ::Type{T} where T) at /home/XXX/Work/MixedModels.jl/src/schema.jl:30
 [4] apply_schema(::FormulaTerm{Term,Tuple{ConstantTerm{Int64},Term,FunctionTerm{typeof(|),var"#107#109",(:Source, :Lot, :Wafer)}}}, ::StatsModels.Schema, ::Type{LinearMixedModel}) at /home/XXX/Work/MixedModels.jl/src/schema.jl:53
 [5] LinearMixedModel(::FormulaTerm{Term,Tuple{ConstantTerm{Int64},Term,FunctionTerm{typeof(|),var"#107#109",(:Source, :Lot, :Wafer)}}}, ::NamedTuple{(:Source, :Lot, :Wafer, :Site, :Thickness),Tuple{Arrow.DictEncoded{String,UInt32,SentinelArrays.ChainedVector{String,Arrow.List{String,Int32,Array{UInt8,1}}}},Arrow.DictEncoded{String,UInt32,SentinelArrays.ChainedVector{String,Arrow.List{String,Int32,Array{UInt8,1}}}},Arrow.DictEncoded{String,UInt32,SentinelArrays.ChainedVector{String,Arrow.List{String,Int32,Array{UInt8,1}}}},Arrow.DictEncoded{String,UInt32,SentinelArrays.ChainedVector{String,Arrow.List{String,Int32,Array{UInt8,1}}}},Arrow.Primitive{Float64,Array{Float64,1}}}}; contrasts::Dict{Symbol,Any}, wts::Array{Any,1}) at /home/XXX/Work/MixedModels.jl/src/linearmixedmodel.jl:67

Originally posted by @palday in #447 (comment)

@palday
Copy link
Member Author

palday commented Dec 15, 2020

@kleinschmidt Assigning this to us in a separate issue so that both of us think about it when we get a free minute. 😄

@kleinschmidt
Copy link
Member

I think the underlying issue here is actually the 1 + Source in the FIXED
effects, I think that's a StatsModels bug...

@palday
Copy link
Member Author

palday commented Dec 17, 2020

Woops.

@kleinschmidt
Copy link
Member

Yeah, with these extra methods it's fine:

Base.:+(as::TupleTerm, bs::TupleTerm) = (as..., bs...)
Base.:+(a::AbstractTerm, b::AbstractTerm) = (a, b)

(We already had the ones for the other two combinations but not these for some
reason).

At some point I was working on an alternative implementation that didn't rely on
tuples of terms as the representation of a "multi term" but obviously lost track
of that...

@palday
Copy link
Member Author

palday commented Dec 17, 2020

Cool. Then I'll give you the joy of closing this issue when the fix is merged upstream. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants