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

Correctly handle EVID4 doses at steady state with lag time #1262

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion inst/maintenance/unit/test-alag.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2013 - 2019 Metrum Research Group
# Copyright (C) 2013 - 2025 Metrum Research Group
#
# This file is part of mrgsolve.
#
Expand Down Expand Up @@ -97,3 +97,21 @@ test_that("ss dose with lag time issue-484", {
out2 <- mrgsim_d(mod,data2) %>% slice(-c(1,2))
expect_identical(out1,out2)
})

test_that("EVID 1 or 4 at SS with lag time are identical", {
ev1 <- ev(amt = 100, ii = 24, ss = 1, LAG = 10)
ev4 <- mutate(ev1, evid = 4)

out1 <- mrgsim_e(mod, ev1, recsort = 3, output = "df")
out4 <- mrgsim_e(mod, ev4, recsort = 3, output = "df")

expect_identical(out1, out4)

ev1a <- mutate(ev1, addl = 3, LAG = 5)
ev4a <- mutate(ev4, addl = 3, LAG = 5)

out1a <- mrgsim_e(mod, ev1a, recsort = 3, output = "df")
out4a <- mrgsim_e(mod, ev4a, recsort = 3, output = "df")

expect_identical(out1a, out4a)
})
1 change: 1 addition & 0 deletions mrgsolve.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 0063b92e-a050-4fd7-986e-be62f57eb1b1

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
4 changes: 2 additions & 2 deletions src/datarecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ void datarecord::implement(odeproblem* prob) {
case 8: // replace
prob->y(eq_n, Amt);
break;
case 4:
case 4: // dose and reset; reset only if non-ss
if(!Armed) break;
if(this->ss()==0) {
for(int i=0; i < prob->neq(); ++i) {
prob->y(i,0.0);
Expand All @@ -200,7 +201,6 @@ void datarecord::implement(odeproblem* prob) {
}
prob->init_call(Time);
}
if(!Armed) break;
if(Rate > 0) {
this->evid(5);
} else {
Expand Down
12 changes: 8 additions & 4 deletions src/devtran.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,19 +548,23 @@ Rcpp::List DEVTRAN(const Rcpp::List parin,
// Checking
if(!this_rec->is_lagged()) {

if(prob.alag(this_cmtn) > mindt && this_rec->is_dose()) { // there is a valid lagtime
// there is a valid lag time
if(prob.alag(this_cmtn) > mindt && this_rec->is_dose()) {
if(this_rec->ss() > 0) {
this_rec->steady(&prob, a[i], solver);
tfrom = tto;
this_rec->ss(0);
}
// We already advanced to ss
// Lagged dose and all subsequent should be vanilla EVID=1 doses
this_rec->ss(0);
rec_ptr newev = NEWREC(*this_rec);
if(newev->evid()==4) {
newev->evid(1);
}
newev->pos(__ALAG_POS);
newev->phantom_rec();
newev->lagged();
newev->time(this_rec->time() + prob.alag(this_cmtn));
newev->ss(0);
insert_record(a[i], j, newev, put_ev_first);
newev->schedule(a[i], maxtime, put_ev_first, NN, prob.alag(this_cmtn));
this_rec->unarm();
Expand Down
Loading