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

effects() wrapper throws error if an event has missing factor levels #157

Open
chsquare opened this issue Nov 30, 2023 · 4 comments
Open

Comments

@chsquare
Copy link

effects() tries to return the effects for a fully-crossed design. If a cell of the design is missing, i.e. design not fully crossed, effects() throws the error:
ERROR: KeyError: key "missingfactorlevel" not found

Instead of trying to return effects for the fully-crossed design of the factors specified in its input Dict, effects() should return only the effects actually present in the model.

@behinger
Copy link
Member

ah now get it. Thanks for reporting. I will check if this is our mistake or of Effects.jl :-)

@chsquare
Copy link
Author

chsquare commented Dec 1, 2023

It is possible to work around this. The event type that has the missing factor has to parameterised with a different factor that completely omits the missing level instead of with the original factor. effects() then returns effects for the fully-crossed design extrapolating to the cells introduced by crossing with this additional factor. From its output you have to select the correct effects for each event type.

@behinger
Copy link
Member

behinger commented Dec 4, 2023

mh ok, I tried to cook it up and noticed I missunderstood something.
Is your point that if you have a design with combinations like this:

condA condB
A A
A B
B A

(so not the full 2x2 design), and you run your model and calculate effects, that you get output for the full 2x2 design?

@chsquare
Copy link
Author

chsquare commented Dec 5, 2023

It's a bit more complicated. I have a design with two events. One event has the fully-crossed design (in my case 2 x 3). The other event has the same factors, just that the level for one of the factors doesn't make sense for that event, so for this other event the design is actually 2 x 2. I used the same model formula for both events 0 ~ factorA * factorB. Unfold works all fine, but then effects() shows the ERROR: KeyError: key "missingfactorlevel" not found. I'm working around that with two model formulas 0 ~ factorA * factorB for the event with the 2 x 3 design and 0 ~ factorA * factorB2 for the event with the 2 x 2 design. effects() finally returns the fully crossed design for all three factorA * factorB * factorB2 for both events and even comes up with values for the cells that don't make sense. These values appear to just be duplicates from other conditions. However, from that table I can simply select the cells that do make sense, so I guess that's fine. It would just be more convenient if effects() returned only model predictions for the factor-level combinations that are actually present in the data for each event. Let me know if you need more info!

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

No branches or pull requests

2 participants