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

unintuitive behavior with multiple terms with same grouping factor #268

Closed
kleinschmidt opened this issue Feb 16, 2020 · 2 comments · Fixed by #269
Closed

unintuitive behavior with multiple terms with same grouping factor #268

kleinschmidt opened this issue Feb 16, 2020 · 2 comments · Fixed by #269

Comments

@kleinschmidt
Copy link
Member

Currently, if you have a formula like y ~ 1 + (1|G) + (0+A|G) where A is a categorical variable with n levels, then you'll generate 1 variance term for the random intercept, and n terms for A, leading to an overparametrized model. This may not be what you want; listing these as separate terms is a way to indicate that you want to zero out the correlation terms between the random intercept and the random slopes for A, and you end up changing the number of variance terms (relative to the (1+A|G) formula).

This can be fixed by changing the way that the schema is applied. Currently, a fresh StatsModels.FullRank schema is prepared for every random effect term, meaning that the 0+A is treated as independent from the 1. An alternative approach would be to add yet another level of schema wrapping (which I'll prepare a PR for), which stores one FullRank schema for each grouping variable and applies it across multiple terms. But this is a breaking change and may require changing how amalgamate works as well. It's tested here:

MixedModels.jl/test/pls.jl

Lines 277 to 290 in c87e8d1

# combining [ReMat{T,S1}, ReMat{T,S2}] for S1 ≠ S2
slpcat = categorical!(deepcopy(slp), [:days])
fm_cat = LMM(@formula(reaction ~ 1 + days + (1|subj) + (0 + days|subj)), slpcat)
@test fm_cat isa LMM
σρ = fit!(fm_cat).σρs
@test σρ isa NamedTuple
@test isone(length(σρ))
@test first(keys(σρ)) == :subj
@test keys(σρ.subj) == (, )
@test length(σρ.subj) == 2
@test length(first(σρ.subj)) == 11
@test length(σρ.subj.ρ) == 55
@test iszero(σρ.subj.ρ[46])
@test σρ.subj.ρ[46] === -0.0

@palday
Copy link
Member

palday commented Jul 10, 2020

@kleinschmidt Have you had time to implement this?

@kleinschmidt
Copy link
Member Author

not beyond what's in #269, which IIRC needs some love to work with amalgamate but maybe that's changed in the mean time?

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