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

Add support for etas attached to idata #1092

Merged
merged 7 commits into from
Jul 17, 2023
Merged

Add support for etas attached to idata #1092

merged 7 commits into from
Jul 17, 2023

Conversation

kylebaron
Copy link
Collaborator

@kylebaron kylebaron commented Jul 12, 2023

Add on to #1037 ; etasrc can now be

  • idata
  • idata.all

Re-using all of the get_etas() code.

Checklist

  • Update devtran to accept etasrc = "idata" or etasrc = "idata.all"
  • Make sure get_etas() works with idata object; one minor change to fill out Startrow for idata sets.
  • Add tests
  • Documentation

Discovered a bug when implementing #1092 where ETA was missed if it was in the first column of the data set. Please see #1095 for the fix.

@kylebaron kylebaron added this to the v1.1.0 milestone Jul 12, 2023
@kylebaron kylebaron requested a review from kyleam July 15, 2023 13:44
Copy link
Contributor

@kyleam kyleam left a comment

Choose a reason for hiding this comment

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

Re-using all of the get_etas() code.

That worked out cleanly. Looks good to me.

for(int j = 0; j < n_eta; ++j) {
if(eta_location[j] > 0) {
if(eta_location[j] >= 0) {
Copy link
Contributor

@kyleam kyleam Jul 15, 2023

Choose a reason for hiding this comment

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

I was confused at why this would be necessary for the idata change. I reverted it (on top of c64ac9a) and tests still pass.

Looking more closely at the existing upstream code, eta_location is the result of std::find on the eta labels, so 0-based. By not considering j = 0, it mishandles an eta column if it's the first column. So this is relevant for data too and is an independent fix for a bug from gh-1037. Okay.

Fwiw here's a regression test that fails without the > to >= equal change:

test_that("etasrc works with ETA in first column", {
  mod <- param(mod, mode = 0)

  data <- expand.ev(amt = 100, ID = seq(4), cmt = 1)
  data <- mutate(data, ETA1 = rev(ID) / 10)
  data <- expand_observations(data, times = seq(5))
  data <- mutate(data, cmt = 0)

  set.seed(9812)
  expect_identical(
    mrgsim(mod, data, etasrc = "data"),
    mrgsim(mod, select(data, "ETA1", everything()), etasrc = "data")
  )
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks; yes, I discovered this when creating the tests for this PR. I should have created another PR or at least written it up in the message. I'm going to revert this change and make it clean in a new PR in case this comes up in the future.

Copy link
Collaborator

@FelicienLL FelicienLL left a comment

Choose a reason for hiding this comment

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

Thanks Kyle for providing this so fast. It should make things much easier and flexible. The code looks good to me.

@kylebaron kylebaron merged commit d8d9929 into main Jul 17, 2023
@kylebaron kylebaron deleted the eta-src-idata branch July 17, 2023 14:05
@kylebaron kylebaron mentioned this pull request Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants