Remove term from formula
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start by tracing formula construction and the existing Term and interaction operations shown in the issue, then compare them with the modelmatrix workaround. The work is done when a formula can subtract the Group term while retaining Time and the Time & Group interaction, with coverage for the mixed-model formula example.
Written by the indexing model from the issue text.
Description
In a A x B design, how do I remove one main effect and keep the other and the interaction term (e.g., remove Group main effect in Group (2) x Time (2) when I do not expect a group difference at pretest)?
I can add terms to a formula:
f1 = @formula y ~ 1 + Time + (1 | Subj);
f1 = f1.lhs ~ (f1.rhs + Term(:Time & :Group) )
m1 = fit(MixedModel, f1, dat; contrasts)
But how can I substract a term? For example, could this be implemented, too?
f2 = @formula y ~ 1 + Time + Group + Time & Group + (1 | Subj);
f2 = f2.lhs ~ (f2.rhs - Term(:Group) )
ERROR: MethodError: no method matching -(::Tuple{ConstantTerm{Int64}, Term, InteractionTerm{Tuple{…}}, FunctionTerm{typeof(|), Vector{…}}}, ::Term)
The function - exists, but no method is defined for this combination of argument types.
One workaround is to extract terms from a fitted model matrix and then assemble the needed ones to a new formula:
f3 = @formula y ~ 1 + Group*Time + (1 | Subj);
m3 = fit(MixedModel, f3, dat; contrasts)
mm3 = modelmatrix(m3)
dat.T = mm3[:, 3];
dat.TxG = mm3[:, 4];
f4 = @formula y ~ 1 + T + TxG + (1 | Subj);
m4 = fit(MixedModel, f4, dat; contrasts)
However, this becomes very cumbersome with many terms nested under the first one. Or is there a simple loop to assemble a formula selectively from the model matrix? Adding a subtraction method would be very helpful. Thank you.
- Dominant language
- Julia
- Stars
- 252
- Forks
- 36
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaStats/StatsModels.jl
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
JuliaStats/StatsModels.jl#328 · 1 comment ·
-
Cell mean coding?Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
JuliaStats/StatsModels.jl#351 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
JuliaStats/StatsModels.jl#329 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
JuliaStats/StatsModels.jl#316 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
JuliaStats/StatsModels.jl#310 ·
All issues in JuliaStats/StatsModels.jl
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaParallel/Hwloc.jl#93 ·
-
Affine transformations of `JohnsonSU` could return a `JohnsonSU`Possibly taken @devmotion claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaStats/Distributions.jl#2117 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
TomerAberbach/profiler-md#970 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
grame-cncm/faust#1409 ·
Maintainers usually reply within 1 day