Skip to content

Commit

Permalink
Add fix/test for 281 compile; Now test with data.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Mar 6, 2020
1 parent 3dd22f7 commit dac66e1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
10 changes: 5 additions & 5 deletions R/nlmixr.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ nlmixr_fit0 <- function(uif, data, est=NULL, control=list(), ...,
model <- uif$saem.model
inits = uif$saem.init
if (length(uif$saem.fixed)>0) {
nphi = attr(model$saem_mod, "nrhs")
m = cumsum(!is.na(matrix(inits$theta, byrow=T, ncol=nphi)))
fixid = match(uif$saem.fixed, t(matrix(m,ncol=nphi)))
nphi = attr(model$saem_mod, "nrhs")
m = cumsum(!is.na(matrix(inits$theta, byrow=T, ncol=nphi)))
fixid = match(uif$saem.fixed, t(matrix(m,ncol=nphi)))

names(inits$theta) = rep("", length(inits$theta))
names(inits$theta)[fixid] = "FIXED"
names(inits$theta) = rep("", length(inits$theta))
names(inits$theta)[fixid] = "FIXED"
}
cfg <- configsaem(model=model, data=dat, inits=inits,
mcmc=mcmc, ODEopt=ODEopt, seed=seed,
Expand Down
12 changes: 10 additions & 2 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -2624,8 +2624,16 @@ nlmixrUI.saem.fit <- function(obj){
RxODE::rxLoad(ode);
message("done.")
inPars <- obj$saem.inPars;
if (length(inPars) == 0) inPars <- NULL

if (length(inPars) == 0) {
inPars <- NULL
} else {
## Check for inPars in Covariates in RxODE model
.extra <- RxODE::rxModelVars(obj$rxode)
.extra <- intersect(obj$saem.all.covs, .extra$params)
if (length(.extra) > 0){
inPars <- c(inPars, .extra)
}
}
saem.fit <- gen_saem_user_fn(model=ode, obj$saem.pars, pred=obj$predSaem, inPars=inPars);
obj$env$saem.fit <- saem.fit;
return(obj$env$saem.fit);
Expand Down
53 changes: 53 additions & 0 deletions tests/testthat/test-281.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
context("Covs in SAEM covs and model, Issue #281")
library(nlmixr)
Lesion7 = function() {
ini({

temaxD = -0.05 # typical value of drug emax
tec50 = -0.04 # typical value of ec50
temaxT = -0.9 # typical value of emax for placebo effect as a function of time
tet50 = 6.64 # typical value of et50
tkin = -7.8
tslope = -1 # typical value of growth parameter
TRXslope = -0.1
tdelay = 7.15

eta.emaxD ~ 0.3
eta.emaxT ~ 0.3
eta.slope ~ 0.3
eta.delay ~ 0.3
add.err = .1 # add. residual variability
})
model({
Resp(0) = 1 # default Resp(0) = 0
emaxD = exp(temaxD + eta.emaxD)
ec50 = exp(tec50)
emaxT = exp(temaxT + eta.emaxT)
et50 = exp(tet50)

slope = exp(tslope + TRX*TRXslope + eta.slope)

delay = exp(tdelay + eta.delay)
kin = exp(tkin)
kout = kin
GAM = exp(1)/2 # Hill coef
C2 = centr/V;
CONC = (C2)^2

Stim1 = emaxT*(time)/(time+et50) ;
Stim2 = emaxD*(CONC^GAM)/(CONC^GAM+ec50^GAM);
Stim = Stim1 * ( 1 + TRX * Stim2 )

Delta = 1/(1 + exp(-20 * (time - delay)))
d/dt(depot) =-KA*depot;
d/dt(centr) = KA*depot - CL*C2;
d/dt(Resp) = kin * (1 + Delta * slope) - kout * (1 + Stim ) * Resp;

Resp ~ add(add.err)

})
}


tmp <- nlmixr(Lesion7)
expect_error(tmp$saem.model, NA)

0 comments on commit dac66e1

Please sign in to comment.