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

Feature: interactions in random effects #169

Merged
merged 10 commits into from
Dec 5, 2022

Conversation

seabbs
Copy link
Collaborator

@seabbs seabbs commented Nov 30, 2022

This PR adds support for interactions on the right-hand side of random effects (i.e (1 + month | day_of_week:age_group). This should result in a model with an independent random effect for each age group on the day of the week and random slopes on the month drawn from separate hyper distributions for each age group.

This feature is motivated by #152 where we need to be able to specify independent random effects for each group easily in order to reproduce the current default model. There may also be other use cases in the future.

Potentially this syntax is not ideal and/or there are other work around to this feature that I am not aware of.

I have added:

  • Functionality to support random effect interactions
  • An example in the documentation of enw_formula showcasing this functionality
  • A test for enw_formula that produces a snapshot. I have confirmed this snapshot has the desired design matrix structure.
  • A test checking that multiple interactions fail with a meaningful error (needed as this is more complex to implement and so is not yet in place).
  • A news item highlighting this change.

I have also checked that none of the other functionality has been impacted by reviewing our other tests.

To test out the new functionality see below:

obs <- enw_filter_report_dates(
  germany_covid19_hosp[location == "DE"][
    age_group %in% c("00+", "05-14", "15-34")
  ],
  remove_days = 10
)
obs <- enw_filter_reference_dates(obs, include_days = 10)
pobs <- enw_preprocess_data(obs, by = c("age_group", "location"))
data <- pobs$metareference[[1]]

enw_formula(~ 1 + (1 + month | day_of_week:age_group), data)

@seabbs seabbs marked this pull request as ready for review November 30, 2022 11:40
@codecov-commenter
Copy link

codecov-commenter commented Nov 30, 2022

Codecov Report

❗ No coverage uploaded for pull request base (develop@08ddfc6). Click here to learn what that means.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             develop     #169   +/-   ##
==========================================
  Coverage           ?   88.33%           
==========================================
  Files              ?       14           
  Lines              ?     1363           
  Branches           ?        0           
==========================================
  Hits               ?     1204           
  Misses             ?      159           
  Partials           ?        0           
Impacted Files Coverage Δ
R/formula-tools.R 97.08% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@seabbs
Copy link
Collaborator Author

seabbs commented Nov 30, 2022

@epinowcast/developers if anyone has time to review this that would be appreciated. There will be another formula based PR coming shortly to support optional intercepts needed by #152.

Copy link
Collaborator Author

@seabbs seabbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (self-review)

@seabbs seabbs merged commit 8d60c59 into develop Dec 5, 2022
@seabbs seabbs deleted the feature-interactions-in-random-effects branch December 5, 2022 10:44
seabbs added a commit that referenced this pull request Dec 5, 2022
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 this pull request may close these issues.

2 participants