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

Error When Adding Random Slopes #290

Closed
bryorsnef opened this issue Feb 25, 2020 · 5 comments · Fixed by #331
Closed

Error When Adding Random Slopes #290

bryorsnef opened this issue Feb 25, 2020 · 5 comments · Fixed by #331
Assignees
Labels

Comments

@bryorsnef
Copy link

bryorsnef commented Feb 25, 2020

I'm trying to fit a model with two grouping factors and one covariate. One has many levels (more than 20,000) and one has only a few hundred. There are ~70,000 data. I'm getting an error whenever I add a random slope of the covariate by the factor with 200 levels. The models fits without issues if I exclude random slopes.

ERROR: MethodError: rmulΛ!(::BlockedSparse{Float64,2,1}, ::ReMat{Float64,1}) is ambiguous. Candidates:
  rmulΛ!(A::M, B::ReMat{T,1}) where {T, M<:AbstractArray{T,2}} in MixedModels at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/remat.jl:391
  rmulΛ!(A::BlockedSparse{T,S,P}, B::ReMat{T,P}) where {T, S, P} in MixedModels at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/remat.jl:405
Possible fix, define
  rmulΛ!(::Union{M<:BlockedSparse{T,S,1}, M<:BlockedSparse{T,S,1}, M<:(BlockedSparse{T,S,1} where S)}, ::Union{ReMat{T,1}, ReMat{T,1}, ReMat{T,1}})

Stacktrace:
 [1] updateL!(::LinearMixedModel{Float64}) at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/linearmixedmodel.jl:678
 [2] #fit!#38(::Bool, ::Bool, ::typeof(fit!), ::LinearMixedModel{Float64}) at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/linearmixedmodel.jl:251
 [3] (::StatsBase.var"#kw##fit!")(::NamedTuple{(:verbose, :REML),Tuple{Bool,Bool}}, ::typeof(fit!), ::LinearMixedModel{Float64}) at ./none:0
 [4] #fit#35(::Array{Any,1}, ::Dict{Symbol,Any}, ::Bool, ::Bool, ::typeof(fit), ::Type{LinearMixedModel}, ::StatsModels.FormulaTerm{StatsModels.Term,Tuple{StatsModels.Term,StatsModels.FunctionTerm{typeof(|),var"#25#27",(:Item,)},StatsModels.FunctionTerm{typeof(|),var"#26#28",(:FreqZipfUS, :Subject)}}}, ::NamedTuple{(:RT, :FreqZipfUS, :Subject, :Item),Tuple{CSV.Column{Float64,Float64},CSV.Column{Union{Missing, Float64},Union{Missing, Float64}},CategoricalArray{Int64,1,UInt32,Int64,CategoricalValue{Int64,UInt32},Union{}},CategoricalArray{String,1,UInt32,String,CategoricalString{UInt32},Union{}}}}) at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/linearmixedmodel.jl:116
 [5] (::StatsBase.var"#kw##fit")(::NamedTuple{(:wts, :contrasts, :verbose, :REML),Tuple{Array{Any,1},Dict{Symbol,Any},Bool,Bool}}, ::typeof(fit), ::Type{LinearMixedModel}, ::StatsModels.FormulaTerm{StatsModels.Term,Tuple{StatsModels.Term,StatsModels.FunctionTerm{typeof(|),var"#25#27",(:Item,)},StatsModels.FunctionTerm{typeof(|),var"#26#28",(:FreqZipfUS, :Subject)}}}, ::NamedTuple{(:RT, :FreqZipfUS, :Subject, :Item),Tuple{CSV.Column{Float64,Float64},CSV.Column{Union{Missing, Float64},Union{Missing, Float64}},CategoricalArray{Int64,1,UInt32,Int64,CategoricalValue{Int64,UInt32},Union{}},CategoricalArray{String,1,UInt32,String,CategoricalString{UInt32},Union{}}}}) at ./none:0
 [6] #fit#34(::Array{Any,1}, ::Dict{Symbol,Any}, ::Bool, ::Bool, ::typeof(fit), ::Type{LinearMixedModel}, ::StatsModels.FormulaTerm{StatsModels.Term,Tuple{StatsModels.Term,StatsModels.FunctionTerm{typeof(|),var"#25#27",(:Item,)},StatsModels.FunctionTerm{typeof(|),var"#26#28",(:FreqZipfUS, :Subject)}}}, ::DataFrame) at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/linearmixedmodel.jl:110
 [7] fit(::Type{LinearMixedModel}, ::StatsModels.FormulaTerm{StatsModels.Term,Tuple{StatsModels.Term,StatsModels.FunctionTerm{typeof(|),var"#25#27",(:Item,)},StatsModels.FunctionTerm{typeof(|),var"#26#28",(:FreqZipfUS, :Subject)}}}, ::DataFrame) at /home/bryor/.juliapro/JuliaPro_v1.3.1-1/packages/MixedModels/qyKOf/src/linearmixedmodel.jl:110
 [8] top-level scope at REPL[32]:1
@palday
Copy link
Member

palday commented Feb 26, 2020

I know what's going wrong, but won't get a chance to fix it until probably next week.

In the meantime, can you give me the output of:

model = LinearMixedModel(@formula(your_formula_here), your_data_here)
describeblocks(model)

Alternatively, if you are able to share your data, even privately, that would be a great help in checking that I get the fix right. :)

@palday palday self-assigned this Feb 26, 2020
@palday palday added the bug label Feb 26, 2020
@palday palday added this to the MixedModels 3.0 milestone Feb 26, 2020
@bryorsnef
Copy link
Author

I can share the data.

julia_test.txt

@palday
Copy link
Member

palday commented Feb 26, 2020

Cool, thanks, can you share your formula too? :) I'm guessing Y ~ X + (1|F1) (1|F2)? And there seem to be missing values in X -- am I parsing the file correctly?

@bryorsnef
Copy link
Author

bryorsnef commented Feb 26, 2020

Yup. The missing values in X are genuine.

Y ~ X + (1|F1) + (1|F2) works fine.
Y ~ X + (1 + X|F1) + (1|F2) throws the error.

@dmbates dmbates mentioned this issue Jul 10, 2020
@palday
Copy link
Member

palday commented Jul 10, 2020

@bryorsnef can you install the rankUpdate branch and see if that fixes your problem?

You can install development versions with:

julia>] add MixedModels#rankUpdate

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

Successfully merging a pull request may close this issue.

2 participants