aboutsummaryrefslogtreecommitdiff
path: root/docs/dev/reference
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2021-08-04 16:37:52 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2021-08-04 16:37:52 +0200
commit51fab94230e926cec690dc455964bd797a97b7c7 (patch)
treee737a267d121034ea232d5aa8fdea2fad8bc9007 /docs/dev/reference
parent1bef803fc9d83989352f1b029d83e66918a0e58a (diff)
Improve AIC table in vignette
Diffstat (limited to 'docs/dev/reference')
-rw-r--r--docs/dev/reference/Rplot001.pngbin70653 -> 1011 bytes
-rw-r--r--docs/dev/reference/dimethenamid_2018.html26
-rw-r--r--docs/dev/reference/mkinmod.html4
-rw-r--r--docs/dev/reference/nlmixr.mmkin.html26
-rw-r--r--docs/dev/reference/plot.mixed.mmkin.html4
-rw-r--r--docs/dev/reference/saem.html34
-rw-r--r--docs/dev/reference/summary.nlmixr.mmkin.html8
-rw-r--r--docs/dev/reference/summary.saem.mmkin.html10
8 files changed, 56 insertions, 56 deletions
diff --git a/docs/dev/reference/Rplot001.png b/docs/dev/reference/Rplot001.png
index 48f53a2a..17a35806 100644
--- a/docs/dev/reference/Rplot001.png
+++ b/docs/dev/reference/Rplot001.png
Binary files differ
diff --git a/docs/dev/reference/dimethenamid_2018.html b/docs/dev/reference/dimethenamid_2018.html
index c893da63..a77cf0f4 100644
--- a/docs/dev/reference/dimethenamid_2018.html
+++ b/docs/dev/reference/dimethenamid_2018.html
@@ -295,7 +295,7 @@ specific pieces of information in the comments.</p>
#&gt; M31 ~ add(sigma_low_M31) + prop(rsd_high_M31)
#&gt; })
#&gt; }
-#&gt; &lt;environment: 0x555559bfc940&gt;</div><div class='input'><span class='co'># The focei fit takes about four minutes on my system</span>
+#&gt; &lt;environment: 0x555559ac3820&gt;</div><div class='input'><span class='co'># The focei fit takes about four minutes on my system</span>
<span class='fu'><a href='https://rdrr.io/r/base/system.time.html'>system.time</a></span><span class='op'>(</span>
<span class='va'>f_dmta_nlmixr_focei</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_dmta_mkin_tc</span>, est <span class='op'>=</span> <span class='st'>"focei"</span>,
control <span class='op'>=</span> <span class='fu'>nlmixr</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/foceiControl.html'>foceiControl</a></span><span class='op'>(</span>print <span class='op'>=</span> <span class='fl'>500</span><span class='op'>)</span><span class='op'>)</span>
@@ -303,7 +303,7 @@ specific pieces of information in the comments.</p>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:02
#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:04
#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:01
-#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:09
+#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:08
#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:07
#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:07
#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; [====|====|====|====|====|====|====|====|====|====] 0:00:00
@@ -324,12 +324,12 @@ specific pieces of information in the comments.</p>
#&gt; <span style='text-decoration: underline;'>|.....................| o9 | o10 |...........|...........|</span>
#&gt; calculating covariance matrix
#&gt; done</div><div class='output co'>#&gt; <span class='message'>Calculating residuals/tables</span></div><div class='output co'>#&gt; <span class='message'>done</span></div><div class='output co'>#&gt; <span class='warning'>Warning: initial ETAs were nudged; (can control by foceiControl(etaNudge=., etaNudge2=))</span></div><div class='output co'>#&gt; <span class='warning'>Warning: last objective function was not at minimum, possible problems in optimization</span></div><div class='output co'>#&gt; <span class='warning'>Warning: S matrix non-positive definite</span></div><div class='output co'>#&gt; <span class='warning'>Warning: using R matrix to calculate covariance</span></div><div class='output co'>#&gt; <span class='warning'>Warning: gradient problems with initial estimate and covariance; see $scaleInfo</span></div><div class='output co'>#&gt; user system elapsed
-#&gt; 227.223 8.444 235.624 </div><div class='input'><span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span><span class='op'>(</span><span class='va'>f_dmta_nlmixr_focei</span><span class='op'>)</span>
+#&gt; 232.621 14.126 246.850 </div><div class='input'><span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span><span class='op'>(</span><span class='va'>f_dmta_nlmixr_focei</span><span class='op'>)</span>
</div><div class='output co'>#&gt; nlmixr version used for fitting: 2.0.4
#&gt; mkin version used for pre-fitting: 1.0.5
#&gt; R version used for fitting: 4.1.0
-#&gt; Date of fit: Thu Jul 29 11:45:46 2021
-#&gt; Date of summary: Thu Jul 29 11:45:46 2021
+#&gt; Date of fit: Wed Aug 4 15:53:54 2021
+#&gt; Date of summary: Wed Aug 4 15:53:54 2021
#&gt;
#&gt; Equations:
#&gt; d_DMTA/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
@@ -350,7 +350,7 @@ specific pieces of information in the comments.</p>
#&gt;
#&gt; Degradation model predictions using RxODE
#&gt;
-#&gt; Fitted in 235.457 s
+#&gt; Fitted in 246.669 s
#&gt;
#&gt; Variance model: Two-component variance function
#&gt;
@@ -489,11 +489,11 @@ specific pieces of information in the comments.</p>
<span class='va'>f_dmta_saemix</span> <span class='op'>&lt;-</span> <span class='fu'><a href='saem.html'>saem</a></span><span class='op'>(</span><span class='va'>f_dmta_mkin_tc</span>, test_log_parms <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
<span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 11:45:47 2021"
+#&gt; [1] "Wed Aug 4 15:53:55 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:04:25 2021"</div><div class='output co'>#&gt; user system elapsed
-#&gt; 1185.594 0.028 1185.687 </div><div class='input'>
+#&gt; [1] "Wed Aug 4 16:12:40 2021"</div><div class='output co'>#&gt; user system elapsed
+#&gt; 1192.021 0.064 1192.182 </div><div class='input'>
<span class='co'># nlmixr with est = "saem" is pretty fast with default iteration numbers, most</span>
<span class='co'># of the time (about 2.5 minutes) is spent for calculating the log likelihood at the end</span>
<span class='co'># The likelihood calculated for the nlmixr fit is much lower than that found by saemix</span>
@@ -506,13 +506,13 @@ specific pieces of information in the comments.</p>
<span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>With est = 'saem', a different error model is required for each observed variableChanging the error model to 'obs_tc' (Two-component error for each observed variable)</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; 1: 98.3427 -3.5148 -3.3187 -3.7728 -2.1163 -2.8457 0.9482 -2.8064 -2.7412 -2.8745 2.7912 0.6805 0.8213 0.8055 0.8578 1.4980 2.9309 0.2850 0.2854 0.2850 4.0990 0.3821 3.5349 0.6537 5.4143 0.0002 4.5093 0.1905
#&gt; 500: 97.8277 -4.3506 -4.0318 -4.1520 -3.0553 -3.5843 1.1326 -2.0873 -2.0421 -2.0751 0.2960 1.2515 0.2531 0.3807 0.7928 0.8863 6.5211 0.1433 0.1082 0.3353 0.8960 0.0470 0.7501 0.0475 0.9527 0.0281 0.7321 0.0594</div><div class='output co'>#&gt; <span class='message'>Calculating covariance matrix</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>Calculating -2LL by Gaussian quadrature (nnodes=3,nsd=1.6)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; [1] "CMT"</div><div class='output co'>#&gt; <span class='message'>Calculating residuals/tables</span></div><div class='output co'>#&gt; <span class='message'>done</span></div><div class='output co'>#&gt; user system elapsed
-#&gt; 809.956 4.286 156.438 </div><div class='input'><span class='fu'>traceplot</span><span class='op'>(</span><span class='va'>f_dmta_nlmixr_saem</span><span class='op'>$</span><span class='va'>nm</span><span class='op'>)</span>
+#&gt; 813.299 3.736 151.935 </div><div class='input'><span class='fu'>traceplot</span><span class='op'>(</span><span class='va'>f_dmta_nlmixr_saem</span><span class='op'>$</span><span class='va'>nm</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='error'>Error in traceplot(f_dmta_nlmixr_saem$nm): could not find function "traceplot"</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/r/base/summary.html'>summary</a></span><span class='op'>(</span><span class='va'>f_dmta_nlmixr_saem</span><span class='op'>)</span>
</div><div class='output co'>#&gt; nlmixr version used for fitting: 2.0.4
#&gt; mkin version used for pre-fitting: 1.0.5
#&gt; R version used for fitting: 4.1.0
-#&gt; Date of fit: Thu Jul 29 12:08:09 2021
-#&gt; Date of summary: Thu Jul 29 12:08:09 2021
+#&gt; Date of fit: Wed Aug 4 16:16:18 2021
+#&gt; Date of summary: Wed Aug 4 16:16:18 2021
#&gt;
#&gt; Equations:
#&gt; d_DMTA/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
@@ -533,7 +533,7 @@ specific pieces of information in the comments.</p>
#&gt;
#&gt; Degradation model predictions using RxODE
#&gt;
-#&gt; Fitted in 156.17 s
+#&gt; Fitted in 151.67 s
#&gt;
#&gt; Variance model: Two-component variance function
#&gt;
diff --git a/docs/dev/reference/mkinmod.html b/docs/dev/reference/mkinmod.html
index 5db8e719..ac7c2daa 100644
--- a/docs/dev/reference/mkinmod.html
+++ b/docs/dev/reference/mkinmod.html
@@ -344,7 +344,7 @@ Evaluating and Calculating Degradation Kinetics in Environmental Media</p>
parent <span class='op'>=</span> <span class='fu'>mkinsub</span><span class='op'>(</span><span class='st'>"SFO"</span>, <span class='st'>"m1"</span>, full_name <span class='op'>=</span> <span class='st'>"Test compound"</span><span class='op'>)</span>,
m1 <span class='op'>=</span> <span class='fu'>mkinsub</span><span class='op'>(</span><span class='st'>"SFO"</span>, full_name <span class='op'>=</span> <span class='st'>"Metabolite M1"</span><span class='op'>)</span>,
name <span class='op'>=</span> <span class='st'>"SFO_SFO"</span>, dll_dir <span class='op'>=</span> <span class='va'>DLL_dir</span>, unload <span class='op'>=</span> <span class='cn'>TRUE</span>, overwrite <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
-</div><div class='output co'>#&gt; <span class='message'>Copied DLL from /tmp/Rtmpjz6gts/filefa69f342e9d9d.so to /home/jranke/.local/share/mkin/SFO_SFO.so</span></div><div class='input'><span class='co'># Now we can save the model and restore it in a new session</span>
+</div><div class='output co'>#&gt; <span class='message'>Copied DLL from /tmp/RtmpKZJMFk/file179ba717d15c81.so to /home/jranke/.local/share/mkin/SFO_SFO.so</span></div><div class='input'><span class='co'># Now we can save the model and restore it in a new session</span>
<span class='fu'><a href='https://rdrr.io/r/base/readRDS.html'>saveRDS</a></span><span class='op'>(</span><span class='va'>SFO_SFO.2</span>, file <span class='op'>=</span> <span class='st'>"~/SFO_SFO.rds"</span><span class='op'>)</span>
<span class='co'># Terminate the R session here if you would like to check, and then do</span>
<span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'><a href='https://pkgdown.jrwb.de/mkin/'>mkin</a></span><span class='op'>)</span>
@@ -393,7 +393,7 @@ Evaluating and Calculating Degradation Kinetics in Environmental Media</p>
#&gt; })
#&gt; return(predicted)
#&gt; }
-#&gt; &lt;environment: 0x55556283eae8&gt;</div><div class='input'>
+#&gt; &lt;environment: 0x555559c54f78&gt;</div><div class='input'>
<span class='co'># If we have several parallel metabolites</span>
<span class='co'># (compare tests/testthat/test_synthetic_data_for_UBA_2014.R)</span>
<span class='va'>m_synth_DFOP_par</span> <span class='op'>&lt;-</span> <span class='fu'>mkinmod</span><span class='op'>(</span>
diff --git a/docs/dev/reference/nlmixr.mmkin.html b/docs/dev/reference/nlmixr.mmkin.html
index b7dfb9ca..99a7ad14 100644
--- a/docs/dev/reference/nlmixr.mmkin.html
+++ b/docs/dev/reference/nlmixr.mmkin.html
@@ -4501,7 +4501,7 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>k_A1=rx_expr_11;</span>
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[4]+THETA[4])));</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 5.801 0.369 6.185</span></div><div class='input'><span class='va'>f_nlmixr_fomc_sfo_focei_const</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_const</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 5.723 0.414 6.136</span></div><div class='input'><span class='va'>f_nlmixr_fomc_sfo_focei_const</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_const</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
#&gt; <span class='message'>rx_expr_6~ETA[1]+THETA[1];</span>
@@ -4550,7 +4550,7 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>beta=exp(rx_expr_8);</span>
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 7.136 0.414 7.548</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_const</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_const</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 6.874 0.399 7.27</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_const</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_const</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
#&gt; <span class='message'>rx_expr_6~ETA[1]+THETA[1];</span>
@@ -4607,10 +4607,10 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>g=1/(rx_expr_20);</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 15.76 0.429 16.19</span></div><div class='input'>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 14.83 0.382 15.21</span></div><div class='input'>
<span class='co'># Variance by variable is supported by 'saem' and 'focei'</span>
<span class='va'>f_nlmixr_fomc_sfo_saem_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"saem"</span><span class='op'>)</span>
-</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 1.311 0.125 1.436</span></div><div class='input'><span class='va'>f_nlmixr_fomc_sfo_focei_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
+</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 1.22 0.146 1.365</span></div><div class='input'><span class='va'>f_nlmixr_fomc_sfo_focei_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
#&gt; <span class='message'>rx_expr_6~ETA[1]+THETA[1];</span>
@@ -4659,8 +4659,8 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>beta=exp(rx_expr_8);</span>
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 6.969 0.428 7.395</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_saem_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"saem"</span><span class='op'>)</span>
-</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 1.38 0.122 1.504</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 6.6 0.416 7.016</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_saem_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"saem"</span><span class='op'>)</span>
+</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 1.551 0.126 1.673</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_obs</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
#&gt; <span class='message'>rx_expr_6~ETA[1]+THETA[1];</span>
@@ -4717,7 +4717,7 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>g=1/(rx_expr_19);</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 15.48 0.348 15.82</span></div><div class='input'>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 15.24 0.429 15.67</span></div><div class='input'>
<span class='co'># Identical two-component error for all variables is only possible with</span>
<span class='co'># est = 'focei' in nlmixr</span>
<span class='va'>f_nlmixr_fomc_sfo_focei_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
@@ -4771,7 +4771,7 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>beta=exp(rx_expr_8);</span>
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 8.84 0.482 9.319</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 8.644 0.416 9.058</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
#&gt; <span class='message'>rx_expr_6~ETA[1]+THETA[1];</span>
@@ -4830,12 +4830,12 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>g=1/(rx_expr_21);</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 19.56 0.433 19.99</span></div><div class='input'>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 18.76 0.426 19.18</span></div><div class='input'>
<span class='co'># Two-component error by variable is possible with both estimation methods</span>
<span class='co'># Variance by variable is supported by 'saem' and 'focei'</span>
<span class='va'>f_nlmixr_fomc_sfo_saem_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"saem"</span>,
error_model <span class='op'>=</span> <span class='st'>"obs_tc"</span><span class='op'>)</span>
-</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 0.817 0.016 0.834</span></div><div class='input'><span class='va'>f_nlmixr_fomc_sfo_focei_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span>,
+</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 0.757 0.072 0.829</span></div><div class='input'><span class='va'>f_nlmixr_fomc_sfo_focei_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"FOMC-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span>,
error_model <span class='op'>=</span> <span class='st'>"obs_tc"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
@@ -4887,9 +4887,9 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>beta=exp(rx_expr_8);</span>
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 8.572 0.437 9.008</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_saem_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"saem"</span>,
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 8.417 0.388 8.803</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_saem_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"saem"</span>,
error_model <span class='op'>=</span> <span class='st'>"obs_tc"</span><span class='op'>)</span>
-</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 0.866 0.032 0.897</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span>,
+</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_A1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 0.82 0.035 0.857</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_focei_obs_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_tc</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span>, est <span class='op'>=</span> <span class='st'>"focei"</span>,
error_model <span class='op'>=</span> <span class='st'>"obs_tc"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(A1);</span>
@@ -4949,7 +4949,7 @@ obtained by fitting the same model to a list of datasets using <a href='mkinfit.
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>g=1/(rx_expr_19);</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 19.34 0.349 19.69</span></div><div class='input'>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_A1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 17.61 0.452 18.06</span></div><div class='input'>
<span class='fu'><a href='https://rdrr.io/r/stats/AIC.html'>AIC</a></span><span class='op'>(</span>
<span class='va'>f_nlmixr_sfo_sfo_focei_const</span><span class='op'>$</span><span class='va'>nm</span>,
<span class='va'>f_nlmixr_fomc_sfo_focei_const</span><span class='op'>$</span><span class='va'>nm</span>,
diff --git a/docs/dev/reference/plot.mixed.mmkin.html b/docs/dev/reference/plot.mixed.mmkin.html
index 8962ce1c..746a8640 100644
--- a/docs/dev/reference/plot.mixed.mmkin.html
+++ b/docs/dev/reference/plot.mixed.mmkin.html
@@ -296,10 +296,10 @@ corresponding model prediction lines for the different datasets.</p></td>
</div><div class='img'><img src='plot.mixed.mmkin-2.png' alt='' width='700' height='433' /></div><div class='input'>
<span class='va'>f_saem</span> <span class='op'>&lt;-</span> <span class='fu'><a href='saem.html'>saem</a></span><span class='op'>(</span><span class='va'>f</span>, transformations <span class='op'>=</span> <span class='st'>"saemix"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:13:54 2021"
+#&gt; [1] "Wed Aug 4 16:21:52 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:02 2021"</div><div class='input'><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_saem</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:22:00 2021"</div><div class='input'><span class='fu'><a href='https://rdrr.io/r/graphics/plot.default.html'>plot</a></span><span class='op'>(</span><span class='va'>f_saem</span><span class='op'>)</span>
</div><div class='img'><img src='plot.mixed.mmkin-3.png' alt='' width='700' height='433' /></div><div class='input'>
<span class='va'>f_obs</span> <span class='op'>&lt;-</span> <span class='fu'><a href='mmkin.html'>mmkin</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/list.html'>list</a></span><span class='op'>(</span><span class='st'>"DFOP-SFO"</span> <span class='op'>=</span> <span class='va'>dfop_sfo</span><span class='op'>)</span>, <span class='va'>ds</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span>, error_model <span class='op'>=</span> <span class='st'>"obs"</span><span class='op'>)</span>
<span class='va'>f_nlmix</span> <span class='op'>&lt;-</span> <span class='fu'>nlmix</span><span class='op'>(</span><span class='va'>f_obs</span><span class='op'>)</span>
diff --git a/docs/dev/reference/saem.html b/docs/dev/reference/saem.html
index 0334e0e1..620173b2 100644
--- a/docs/dev/reference/saem.html
+++ b/docs/dev/reference/saem.html
@@ -288,27 +288,27 @@ using <a href='mmkin.html'>mmkin</a>.</p>
state.ini <span class='op'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span>parent <span class='op'>=</span> <span class='fl'>100</span><span class='op'>)</span>, fixed_initials <span class='op'>=</span> <span class='st'>"parent"</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
<span class='va'>f_saem_p0_fixed</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent_p0_fixed</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:07 2021"
+#&gt; [1] "Wed Aug 4 16:22:05 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:08 2021"</div><div class='input'>
+#&gt; [1] "Wed Aug 4 16:22:06 2021"</div><div class='input'>
<span class='va'>f_mmkin_parent</span> <span class='op'>&lt;-</span> <span class='fu'><a href='mmkin.html'>mmkin</a></span><span class='op'>(</span><span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span><span class='op'>(</span><span class='st'>"SFO"</span>, <span class='st'>"FOMC"</span>, <span class='st'>"DFOP"</span><span class='op'>)</span>, <span class='va'>ds</span>, quiet <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
<span class='va'>f_saem_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent</span><span class='op'>[</span><span class='st'>"SFO"</span>, <span class='op'>]</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:11 2021"
+#&gt; [1] "Wed Aug 4 16:22:08 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:12 2021"</div><div class='input'><span class='va'>f_saem_fomc</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent</span><span class='op'>[</span><span class='st'>"FOMC"</span>, <span class='op'>]</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:22:10 2021"</div><div class='input'><span class='va'>f_saem_fomc</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent</span><span class='op'>[</span><span class='st'>"FOMC"</span>, <span class='op'>]</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:12 2021"
+#&gt; [1] "Wed Aug 4 16:22:10 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:14 2021"</div><div class='input'><span class='va'>f_saem_dfop</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent</span><span class='op'>[</span><span class='st'>"DFOP"</span>, <span class='op'>]</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:22:12 2021"</div><div class='input'><span class='va'>f_saem_dfop</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent</span><span class='op'>[</span><span class='st'>"DFOP"</span>, <span class='op'>]</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:15 2021"
+#&gt; [1] "Wed Aug 4 16:22:12 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:18 2021"</div><div class='input'>
+#&gt; [1] "Wed Aug 4 16:22:16 2021"</div><div class='input'>
<span class='co'># The returned saem.mmkin object contains an SaemixObject, therefore we can use</span>
<span class='co'># functions from saemix</span>
<span class='kw'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='op'>(</span><span class='va'>saemix</span><span class='op'>)</span>
@@ -357,10 +357,10 @@ using <a href='mmkin.html'>mmkin</a>.</p>
<span class='va'>f_mmkin_parent_tc</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/stats/update.html'>update</a></span><span class='op'>(</span><span class='va'>f_mmkin_parent</span>, error_model <span class='op'>=</span> <span class='st'>"tc"</span><span class='op'>)</span>
<span class='va'>f_saem_fomc_tc</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin_parent_tc</span><span class='op'>[</span><span class='st'>"FOMC"</span>, <span class='op'>]</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:21 2021"
+#&gt; [1] "Wed Aug 4 16:22:19 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:27 2021"</div><div class='input'><span class='fu'><a href='https://rdrr.io/pkg/saemix/man/compare.saemix.html'>compare.saemix</a></span><span class='op'>(</span><span class='va'>f_saem_fomc</span><span class='op'>$</span><span class='va'>so</span>, <span class='va'>f_saem_fomc_tc</span><span class='op'>$</span><span class='va'>so</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:22:24 2021"</div><div class='input'><span class='fu'><a href='https://rdrr.io/pkg/saemix/man/compare.saemix.html'>compare.saemix</a></span><span class='op'>(</span><span class='va'>f_saem_fomc</span><span class='op'>$</span><span class='va'>so</span>, <span class='va'>f_saem_fomc_tc</span><span class='op'>$</span><span class='va'>so</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'>Likelihoods calculated by importance sampling</span></div><div class='output co'>#&gt; AIC BIC
#&gt; 1 467.7096 464.9757
#&gt; 2 469.6831 466.5586</div><div class='input'>
@@ -381,15 +381,15 @@ using <a href='mmkin.html'>mmkin</a>.</p>
<span class='co'># four minutes</span>
<span class='va'>f_saem_sfo_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin</span><span class='op'>[</span><span class='st'>"SFO-SFO"</span>, <span class='op'>]</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:31 2021"
+#&gt; [1] "Wed Aug 4 16:22:27 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:36 2021"</div><div class='input'><span class='va'>f_saem_dfop_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:22:32 2021"</div><div class='input'><span class='va'>f_saem_dfop_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>saem</span><span class='op'>(</span><span class='va'>f_mmkin</span><span class='op'>[</span><span class='st'>"DFOP-SFO"</span>, <span class='op'>]</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:36 2021"
+#&gt; [1] "Wed Aug 4 16:22:33 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:14:46 2021"</div><div class='input'><span class='co'># We can use print, plot and summary methods to check the results</span>
+#&gt; [1] "Wed Aug 4 16:22:42 2021"</div><div class='input'><span class='co'># We can use print, plot and summary methods to check the results</span>
<span class='fu'><a href='https://rdrr.io/r/base/print.html'>print</a></span><span class='op'>(</span><span class='va'>f_saem_dfop_sfo</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Kinetic nonlinear mixed-effects model fit by SAEM
#&gt; Structural model:
@@ -432,8 +432,8 @@ using <a href='mmkin.html'>mmkin</a>.</p>
</div><div class='output co'>#&gt; saemix version used for fitting: 3.1.9000
#&gt; mkin version used for pre-fitting: 1.0.5
#&gt; R version used for fitting: 4.1.0
-#&gt; Date of fit: Thu Jul 29 12:14:46 2021
-#&gt; Date of summary: Thu Jul 29 12:14:46 2021
+#&gt; Date of fit: Wed Aug 4 16:22:43 2021
+#&gt; Date of summary: Wed Aug 4 16:22:43 2021
#&gt;
#&gt; Equations:
#&gt; d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
@@ -448,7 +448,7 @@ using <a href='mmkin.html'>mmkin</a>.</p>
#&gt;
#&gt; Model predictions using solution type analytical
#&gt;
-#&gt; Fitted in 9.987 s using 300, 100 iterations
+#&gt; Fitted in 10.143 s using 300, 100 iterations
#&gt;
#&gt; Variance model: Constant variance
#&gt;
diff --git a/docs/dev/reference/summary.nlmixr.mmkin.html b/docs/dev/reference/summary.nlmixr.mmkin.html
index f0131701..70a71683 100644
--- a/docs/dev/reference/summary.nlmixr.mmkin.html
+++ b/docs/dev/reference/summary.nlmixr.mmkin.html
@@ -258,12 +258,12 @@ nlmixr authors for the parts inherited from nlmixr.</p>
quiet <span class='op'>=</span> <span class='cn'>TRUE</span>, error_model <span class='op'>=</span> <span class='st'>"tc"</span>, cores <span class='op'>=</span> <span class='fl'>5</span><span class='op'>)</span>
<span class='va'>f_saemix_dfop_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>mkin</span><span class='fu'>::</span><span class='fu'><a href='saem.html'>saem</a></span><span class='op'>(</span><span class='va'>f_mmkin_dfop_sfo</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:14:50 2021"
+#&gt; [1] "Wed Aug 4 16:22:46 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:15:03 2021"</div><div class='input'><span class='va'>f_nlme_dfop_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>mkin</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_mmkin_dfop_sfo</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:22:59 2021"</div><div class='input'><span class='va'>f_nlme_dfop_sfo</span> <span class='op'>&lt;-</span> <span class='fu'>mkin</span><span class='fu'>::</span><span class='fu'><a href='https://rdrr.io/pkg/nlme/man/nlme.html'>nlme</a></span><span class='op'>(</span><span class='va'>f_mmkin_dfop_sfo</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='warning'>Warning: Iteration 4, LME step: nlminb() did not converge (code = 1). PORT message: false convergence (8)</span></div><div class='output co'>#&gt; <span class='warning'>Warning: Iteration 6, LME step: nlminb() did not converge (code = 1). PORT message: false convergence (8)</span></div><div class='input'><span class='va'>f_nlmixr_dfop_sfo_saem</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_dfop_sfo</span>, est <span class='op'>=</span> <span class='st'>"saem"</span><span class='op'>)</span>
-</div><div class='output co'>#&gt; <span class='message'>With est = 'saem', a different error model is required for each observed variableChanging the error model to 'obs_tc' (Two-component error for each observed variable)</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_m1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 1.464 0.114 1.576</span></div><div class='input'><span class='co'># The following takes a very long time but gives</span>
+</div><div class='output co'>#&gt; <span class='message'>With est = 'saem', a different error model is required for each observed variableChanging the error model to 'obs_tc' (Two-component error for each observed variable)</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'>→ generate SAEM model</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='error'>Error in configsaem(model = model, data = dat, inits = inits, mcmc = .mcmc, ODEopt = .ODEopt, seed = .seed, distribution = .dist, DEBUG = .DEBUG, addProp = .addProp, tol = .tol, itmax = .itmax, type = .type, powRange = .powRange, lambdaRange = .lambdaRange): covariate(s) not found: f_parent_to_m1</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 1.383 0.12 1.503</span></div><div class='input'><span class='co'># The following takes a very long time but gives</span>
<span class='va'>f_nlmixr_dfop_sfo_focei</span> <span class='op'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/pkg/nlmixr/man/nlmixr.html'>nlmixr</a></span><span class='op'>(</span><span class='va'>f_mmkin_dfop_sfo</span>, est <span class='op'>=</span> <span class='st'>"focei"</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> parameter labels from comments are typically ignored in non-interactive mode</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BBBB;'>ℹ</span> Need to run with the source intact to parse comments</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ creating full model...</span></div><div class='output co'>#&gt; <span class='message'>→ pruning branches (<span style='color: #262626; background-color: #DADADA;'>`if`</span>/<span style='color: #262626; background-color: #DADADA;'>`else`</span>)...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ loading into <span style='color: #0000BB;'>symengine</span> environment...</span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ calculate jacobian</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate sensitivities</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(f)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ calculate ∂(R²)/∂(η)</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in inner model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in EBE model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling inner model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ finding duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ optimizing duplicate expressions in FD model...</span></div><div class='output co'>#&gt; </div><div class='output co'>#&gt; <span class='message'>→ compiling EBE model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>→ compiling events FD model...</span></div><div class='output co'>#&gt; <span class='message'> </span></div><div class='output co'>#&gt; <span class='message'><span style='color: #00BB00;'>✔</span> done</span></div><div class='output co'>#&gt; <span class='message'>Model:</span></div><div class='output co'>#&gt; <span class='message'>cmt(parent);</span>
#&gt; <span class='message'>cmt(m1);</span>
@@ -323,7 +323,7 @@ nlmixr authors for the parts inherited from nlmixr.</p>
#&gt; <span class='message'>f_parent=1/(1+exp(-(ETA[3]+THETA[3])));</span>
#&gt; <span class='message'>g=1/(rx_expr_21);</span>
#&gt; <span class='message'>tad=tad();</span>
-#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_m1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 19.62 0.431 20.06</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/r/stats/AIC.html'>AIC</a></span><span class='op'>(</span><span class='va'>f_nlmixr_dfop_sfo_saem</span><span class='op'>$</span><span class='va'>nm</span>, <span class='va'>f_nlmixr_dfop_sfo_focei</span><span class='op'>$</span><span class='va'>nm</span><span class='op'>)</span>
+#&gt; <span class='message'>dosenum=dosenum();</span></div><div class='output co'>#&gt; <span class='message'>Needed Covariates:</span></div><div class='output co'>#&gt; <span class='message'>[1] "f_parent_to_m1" "CMT" </span></div><div class='output co'>#&gt; <span class='error'>Error in (function (data, inits, PKpars, model = NULL, pred = NULL, err = NULL, lower = -Inf, upper = Inf, fixed = NULL, skipCov = NULL, control = foceiControl(), thetaNames = NULL, etaNames = NULL, etaMat = NULL, ..., env = NULL, keep = NULL, drop = NULL) { set.seed(control$seed) .pt &lt;- proc.time() RxODE::.setWarnIdSort(FALSE) on.exit(RxODE::.setWarnIdSort(TRUE)) loadNamespace("n1qn1") if (!RxODE::rxIs(control, "foceiControl")) { control &lt;- do.call(foceiControl, control) } if (is.null(env)) { .ret &lt;- new.env(parent = emptyenv()) } else { .ret &lt;- env } .ret$origData &lt;- data .ret$etaNames &lt;- etaNames .ret$thetaFixed &lt;- fixed .ret$control &lt;- control .ret$control$focei.mu.ref &lt;- integer(0) if (is(model, "RxODE") || is(model, "character")) { .ret$ODEmodel &lt;- TRUE if (class(pred) != "function") { stop("pred must be a function specifying the prediction variables in this model.") } } else { .ret$ODEmodel &lt;- TRUE model &lt;- RxODE::rxGetLin(PKpars) pred &lt;- eval(parse(text = "function(){return(Central);}")) } .square &lt;- function(x) x * x .ret$diagXformInv &lt;- c(sqrt = ".square", log = "exp", identity = "identity")[control$diagXform] if (is.null(err)) { err &lt;- eval(parse(text = paste0("function(){err", paste(inits$ERROR[[1]], collapse = ""), "}"))) } .covNames &lt;- .parNames &lt;- c() .ret$adjLik &lt;- control$adjLik .mixed &lt;- !is.null(inits$OMGA) &amp;&amp; length(inits$OMGA) &gt; 0 if (!exists("noLik", envir = .ret)) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ssAtol &lt;- rep(control$ssAtol, length(RxODE::rxModelVars(model)$state)) .ssRtol &lt;- rep(control$ssRtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = (control$derivMethod == 2L), pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, interaction = (control$interaction == 1L), only.numeric = !.mixed, run.internal = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol .ssAtol &lt;- c(.ssAtol, rep(control$ssAtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssAtol))) .ssRtol &lt;- c(.ssRtol, rep(control$ssRtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.ssRtol))) .ret$control$rxControl$ssAtol &lt;- .ssAtol .ret$control$rxControl$ssRtol &lt;- .ssRtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { if (.ret$noLik) { .atol &lt;- rep(control$atol, length(RxODE::rxModelVars(model)$state)) .rtol &lt;- rep(control$rtol, length(RxODE::rxModelVars(model)$state)) .ret$model &lt;- RxODE::rxSymPySetupPred(model, pred, PKpars, err, grad = FALSE, pred.minus.dv = TRUE, sum.prod = control$sumProd, theta.derivs = FALSE, optExpression = control$optExpression, run.internal = TRUE, only.numeric = TRUE, addProp = control$addProp) if (!is.null(.ret$model$inner)) { .atol &lt;- c(.atol, rep(control$atolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.atol))) .rtol &lt;- c(.rtol, rep(control$rtolSens, length(RxODE::rxModelVars(.ret$model$inner)$state) - length(.rtol))) .ret$control$rxControl$atol &lt;- .atol .ret$control$rxControl$rtol &lt;- .rtol } .covNames &lt;- .parNames &lt;- RxODE::rxParams(.ret$model$pred.only) .covNames &lt;- .covNames[regexpr(rex::rex(start, or("THETA", "ETA"), "[", numbers, "]", end), .covNames) == -1] colnames(data) &lt;- sapply(names(data), function(x) { if (any(x == .covNames)) { return(x) } else { return(toupper(x)) } }) .lhs &lt;- c(names(RxODE::rxInits(.ret$model$pred.only)), RxODE::rxLhs(.ret$model$pred.only)) if (length(.lhs) &gt; 0) { .covNames &lt;- .covNames[regexpr(rex::rex(start, or(.lhs), end), .covNames) == -1] } if (length(.covNames) &gt; 0) { if (!all(.covNames %in% names(data))) { message("Model:") RxODE::rxCat(.ret$model$pred.only) message("Needed Covariates:") nlmixrPrint(.covNames) stop("Not all the covariates are in the dataset.") } message("Needed Covariates:") print(.covNames) } .extraPars &lt;- .ret$model$extra.pars } else { .extraPars &lt;- NULL } } .ret$skipCov &lt;- skipCov if (is.null(skipCov)) { if (is.null(fixed)) { .tmp &lt;- rep(FALSE, length(inits$THTA)) } else { if (length(fixed) &lt; length(inits$THTA)) { .tmp &lt;- c(fixed, rep(FALSE, length(inits$THTA) - length(fixed))) } else { .tmp &lt;- fixed[1:length(inits$THTA)] } } if (exists("uif", envir = .ret)) { .uifErr &lt;- .ret$uif$ini$err[!is.na(.ret$uif$ini$ntheta)] .uifErr &lt;- sapply(.uifErr, function(x) { if (is.na(x)) { return(FALSE) } return(!any(x == c("pow2", "tbs", "tbsYj"))) }) .tmp &lt;- (.tmp | .uifErr) } .ret$skipCov &lt;- c(.tmp, rep(TRUE, length(.extraPars))) .ret$control$focei.mu.ref &lt;- .ret$uif$focei.mu.ref } if (is.null(.extraPars)) { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA))) } else { .nms &lt;- c(sprintf("THETA[%s]", seq_along(inits$THTA)), sprintf("ERR[%s]", seq_along(.extraPars))) } if (!is.null(thetaNames) &amp;&amp; (length(inits$THTA) + length(.extraPars)) == length(thetaNames)) { .nms &lt;- thetaNames } .ret$thetaNames &lt;- .nms .thetaReset$thetaNames &lt;- .nms if (length(lower) == 1) { lower &lt;- rep(lower, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { print(inits$THTA) print(lower) stop("Lower must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (length(upper) == 1) { upper &lt;- rep(upper, length(inits$THTA)) } else if (length(lower) != length(inits$THTA)) { stop("Upper must be a single constant for all the THETA lower bounds, or match the dimension of THETA.") } if (!is.null(.extraPars)) { .ret$model$extra.pars &lt;- eval(call(control$diagXform, .ret$model$extra.pars)) if (length(.ret$model$extra.pars) &gt; 0) { inits$THTA &lt;- c(inits$THTA, .ret$model$extra.pars) .lowerErr &lt;- rep(control$atol[1] * 10, length(.ret$model$extra.pars)) .upperErr &lt;- rep(Inf, length(.ret$model$extra.pars)) lower &lt;- c(lower, .lowerErr) upper &lt;- c(upper, .upperErr) } } if (is.null(data$ID)) stop("\"ID\" not found in data") if (is.null(data$DV)) stop("\"DV\" not found in data") if (is.null(data$EVID)) data$EVID &lt;- 0 if (is.null(data$AMT)) data$AMT &lt;- 0 for (.v in c("TIME", "AMT", "DV", .covNames)) { data[[.v]] &lt;- as.double(data[[.v]]) } .ret$dataSav &lt;- data .ds &lt;- data[data$EVID != 0 &amp; data$EVID != 2, c("ID", "TIME", "AMT", "EVID", .covNames)] .w &lt;- which(tolower(names(data)) == "limit") .limitName &lt;- NULL if (length(.w) == 1L) { .limitName &lt;- names(data)[.w] } .censName &lt;- NULL .w &lt;- which(tolower(names(data)) == "cens") if (length(.w) == 1L) { .censName &lt;- names(data[.w]) } data &lt;- data[data$EVID == 0 | data$EVID == 2, c("ID", "TIME", "DV", "EVID", .covNames, .limitName, .censName)] .w &lt;- which(!(names(.ret$dataSav) %in% c(.covNames, keep))) names(.ret$dataSav)[.w] &lt;- tolower(names(.ret$dataSav[.w])) if (.mixed) { .lh &lt;- .parseOM(inits$OMGA) .nlh &lt;- sapply(.lh, length) .osplt &lt;- rep(1:length(.lh), .nlh) .lini &lt;- list(inits$THTA, unlist(.lh)) .nlini &lt;- sapply(.lini, length) .nsplt &lt;- rep(1:length(.lini), .nlini) .om0 &lt;- .genOM(.lh) if (length(etaNames) == dim(.om0)[1]) { .ret$etaNames &lt;- .ret$etaNames } else { .ret$etaNames &lt;- sprintf("ETA[%d]", seq(1, dim(.om0)[1])) } .ret$rxInv &lt;- RxODE::rxSymInvCholCreate(mat = .om0, diag.xform = control$diagXform) .ret$xType &lt;- .ret$rxInv$xType .om0a &lt;- .om0 .om0a &lt;- .om0a/control$diagOmegaBoundLower .om0b &lt;- .om0 .om0b &lt;- .om0b * control$diagOmegaBoundUpper .om0a &lt;- RxODE::rxSymInvCholCreate(mat = .om0a, diag.xform = control$diagXform) .om0b &lt;- RxODE::rxSymInvCholCreate(mat = .om0b, diag.xform = control$diagXform) .omdf &lt;- data.frame(a = .om0a$theta, m = .ret$rxInv$theta, b = .om0b$theta, diag = .om0a$theta.diag) .omdf$lower &lt;- with(.omdf, ifelse(a &gt; b, b, a)) .omdf$lower &lt;- with(.omdf, ifelse(lower == m, -Inf, lower)) .omdf$lower &lt;- with(.omdf, ifelse(!diag, -Inf, lower)) .omdf$upper &lt;- with(.omdf, ifelse(a &lt; b, b, a)) .omdf$upper &lt;- with(.omdf, ifelse(upper == m, Inf, upper)) .omdf$upper &lt;- with(.omdf, ifelse(!diag, Inf, upper)) .ret$control$nomega &lt;- length(.omdf$lower) .ret$control$neta &lt;- sum(.omdf$diag) .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) lower &lt;- c(lower, .omdf$lower) upper &lt;- c(upper, .omdf$upper) } else { .ret$control$nomega &lt;- 0 .ret$control$neta &lt;- 0 .ret$xType &lt;- -1 .ret$control$ntheta &lt;- length(lower) .ret$control$nfixed &lt;- sum(fixed) } .ret$lower &lt;- lower .ret$upper &lt;- upper .ret$thetaIni &lt;- inits$THTA .scaleC &lt;- double(length(lower)) if (is.null(control$scaleC)) { .scaleC &lt;- rep(NA_real_, length(lower)) } else { .scaleC &lt;- as.double(control$scaleC) if (length(lower) &gt; length(.scaleC)) { .scaleC &lt;- c(.scaleC, rep(NA_real_, length(lower) - length(.scaleC))) } else if (length(lower) &lt; length(.scaleC)) { .scaleC &lt;- .scaleC[seq(1, length(lower))] warning("scaleC control option has more options than estimated population parameters, please check.") } } .ret$scaleC &lt;- .scaleC if (exists("uif", envir = .ret)) { .ini &lt;- as.data.frame(.ret$uif$ini)[!is.na(.ret$uif$ini$err), c("est", "err", "ntheta")] for (.i in seq_along(.ini$err)) { if (is.na(.ret$scaleC[.ini$ntheta[.i]])) { if (any(.ini$err[.i] == c("boxCox", "yeoJohnson", "pow2", "tbs", "tbsYj"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 1 } else if (any(.ini$err[.i] == c("prop", "add", "norm", "dnorm", "logn", "dlogn", "lnorm", "dlnorm"))) { .ret$scaleC[.ini$ntheta[.i]] &lt;- 0.5 * abs(.ini$est[.i]) } } } for (.i in .ini$model$extraProps$powTheta) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- 1 } .ini &lt;- as.data.frame(.ret$uif$ini) for (.i in .ini$model$extraProps$factorial) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i] + 1)) } for (.i in .ini$model$extraProps$gamma) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- abs(1/digamma(.ini$est[.i])) } for (.i in .ini$model$extraProps$log) { if (is.na(.ret$scaleC[.i])) .ret$scaleC[.i] &lt;- log(abs(.ini$est[.i])) * abs(.ini$est[.i]) } for (.i in .ret$logitThetas) { .b &lt;- .ret$logitThetasLow[.i] .c &lt;- .ret$logitThetasHi[.i] .a &lt;- .ini$est[.i] if (is.na(.ret$scaleC[.i])) { .ret$scaleC[.i] &lt;- 1 * (-.b + .c) * exp(-.a)/((1 + exp(-.a))^2 * (.b + 1 * (-.b + .c)/(1 + exp(-.a)))) } } } names(.ret$thetaIni) &lt;- sprintf("THETA[%d]", seq_along(.ret$thetaIni)) if (is.null(etaMat) &amp; !is.null(control$etaMat)) { .ret$etaMat &lt;- control$etaMat } else { .ret$etaMat &lt;- etaMat } .ret$setupTime &lt;- (proc.time() - .pt)["elapsed"] if (exists("uif", envir = .ret)) { .tmp &lt;- .ret$uif$logThetasList .ret$logThetas &lt;- .tmp[[1]] .ret$logThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasList .ret$logitThetas &lt;- .tmp[[1]] .ret$logitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListLow .ret$logitThetasLow &lt;- .tmp[[1]] .ret$logitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$logitThetasListHi .ret$logitThetasHi &lt;- .tmp[[1]] .ret$logitThetasHiF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasList .ret$probitThetas &lt;- .tmp[[1]] .ret$probitThetasF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListLow .ret$probitThetasLow &lt;- .tmp[[1]] .ret$probitThetasLowF &lt;- .tmp[[2]] .tmp &lt;- .ret$uif$probitThetasListHi .ret$probitThetasHi &lt;- .tmp[[1]] .ret$probitThetasHiF &lt;- .tmp[[2]] } else { .ret$logThetasF &lt;- integer(0) .ret$logitThetasF &lt;- integer(0) .ret$logitThetasHiF &lt;- numeric(0) .ret$logitThetasLowF &lt;- numeric(0) .ret$logitThetas &lt;- integer(0) .ret$logitThetasHi &lt;- numeric(0) .ret$logitThetasLow &lt;- numeric(0) .ret$probitThetasF &lt;- integer(0) .ret$probitThetasHiF &lt;- numeric(0) .ret$probitThetasLowF &lt;- numeric(0) .ret$probitThetas &lt;- integer(0) .ret$probitThetasHi &lt;- numeric(0) .ret$probitThetasLow &lt;- numeric(0) } if (exists("noLik", envir = .ret)) { if (!.ret$noLik) { .ret$.params &lt;- c(sprintf("THETA[%d]", seq_along(.ret$thetaIni)), sprintf("ETA[%d]", seq(1, dim(.om0)[1]))) .ret$.thetan &lt;- length(.ret$thetaIni) .ret$nobs &lt;- sum(data$EVID == 0) } } .ret$control$printTop &lt;- TRUE .ret$control$nF &lt;- 0 .est0 &lt;- .ret$thetaIni if (!is.null(.ret$model$pred.nolhs)) { .ret$control$predNeq &lt;- length(.ret$model$pred.nolhs$state) } else { .ret$control$predNeq &lt;- 0L } .fitFun &lt;- function(.ret) { this.env &lt;- environment() assign("err", "theta reset", this.env) while (this.env$err == "theta reset") { assign("err", "", this.env) .ret0 &lt;- tryCatch({ foceiFitCpp_(.ret) }, error = function(e) { if (regexpr("theta reset", e$message) != -1) { assign("zeroOuter", FALSE, this.env) assign("zeroGrad", FALSE, this.env) if (regexpr("theta reset0", e$message) != -1) { assign("zeroGrad", TRUE, this.env) } else if (regexpr("theta resetZ", e$message) != -1) { assign("zeroOuter", TRUE, this.env) } assign("err", "theta reset", this.env) } else { assign("err", e$message, this.env) } }) if (this.env$err == "theta reset") { .nm &lt;- names(.ret$thetaIni) .ret$thetaIni &lt;- setNames(.thetaReset$thetaIni + 0, .nm) .ret$rxInv$theta &lt;- .thetaReset$omegaTheta .ret$control$printTop &lt;- FALSE .ret$etaMat &lt;- .thetaReset$etaMat .ret$control$etaMat &lt;- .thetaReset$etaMat .ret$control$maxInnerIterations &lt;- .thetaReset$maxInnerIterations .ret$control$nF &lt;- .thetaReset$nF .ret$control$gillRetC &lt;- .thetaReset$gillRetC .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillRet &lt;- .thetaReset$gillRet .ret$control$gillDf &lt;- .thetaReset$gillDf .ret$control$gillDf2 &lt;- .thetaReset$gillDf2 .ret$control$gillErr &lt;- .thetaReset$gillErr .ret$control$rEps &lt;- .thetaReset$rEps .ret$control$aEps &lt;- .thetaReset$aEps .ret$control$rEpsC &lt;- .thetaReset$rEpsC .ret$control$aEpsC &lt;- .thetaReset$aEpsC .ret$control$c1 &lt;- .thetaReset$c1 .ret$control$c2 &lt;- .thetaReset$c2 if (this.env$zeroOuter) { message("Posthoc reset") .ret$control$maxOuterIterations &lt;- 0L } else if (this.env$zeroGrad) { message("Theta reset (zero gradient values); Switch to bobyqa") RxODE::rxReq("minqa") .ret$control$outerOptFun &lt;- .bobyqa .ret$control$outerOpt &lt;- -1L } else { message("Theta reset (ETA drift)") } } } if (this.env$err != "") { stop(this.env$err) } else { return(.ret0) } } .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- 1 while (inherits(.ret0, "try-error") &amp;&amp; control$maxOuterIterations != 0 &amp;&amp; .n &lt;= control$nRetries) { message(sprintf("Restart %s", .n)) .ret$control$nF &lt;- 0 .estNew &lt;- .est0 + 0.2 * .n * abs(.est0) * stats::runif(length(.est0)) - 0.1 * .n .estNew &lt;- sapply(seq_along(.est0), function(.i) { if (.ret$thetaFixed[.i]) { return(.est0[.i]) } else if (.estNew[.i] &lt; lower[.i]) { return(lower + (.Machine$double.eps)^(1/7)) } else if (.estNew[.i] &gt; upper[.i]) { return(upper - (.Machine$double.eps)^(1/7)) } else { return(.estNew[.i]) } }) .ret$thetaIni &lt;- .estNew .ret0 &lt;- try(.fitFun(.ret)) .n &lt;- .n + 1 } if (inherits(.ret0, "try-error")) stop("Could not fit data.") .ret &lt;- .ret0 if (exists("parHistData", .ret)) { .tmp &lt;- .ret$parHistData .tmp &lt;- .tmp[.tmp$type == "Unscaled", names(.tmp) != "type"] .iter &lt;- .tmp$iter .tmp &lt;- .tmp[, names(.tmp) != "iter"] .ret$parHistStacked &lt;- data.frame(stack(.tmp), iter = .iter) names(.ret$parHistStacked) &lt;- c("val", "par", "iter") .ret$parHist &lt;- data.frame(iter = .iter, .tmp) } if (.mixed) { .etas &lt;- .ret$ranef .thetas &lt;- .ret$fixef .pars &lt;- .Call(`_nlmixr_nlmixrParameters`, .thetas, .etas) .ret$shrink &lt;- .Call(`_nlmixr_calcShrinkOnly`, .ret$omega, .pars$eta.lst, length(.etas$ID)) .updateParFixed(.ret) } else { .updateParFixed(.ret) } if (!exists("table", .ret)) { .ret$table &lt;- tableControl() } if (control$calcTables) { .ret &lt;- addTable(.ret, updateObject = "no", keep = keep, drop = drop, table = .ret$table) } .ret})(data = dat, inits = .FoceiInits, PKpars = .pars, model = .mod, pred = function() { return(nlmixr_pred) }, err = uif$error, lower = uif$focei.lower, upper = uif$focei.upper, fixed = uif$focei.fixed, thetaNames = uif$focei.names, etaNames = uif$eta.names, control = control, env = env, keep = .keep, drop = .drop): Not all the covariates are in the dataset.</span></div><div class='output co'>#&gt; <span class='message'>Timing stopped at: 18.43 0.422 18.87</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/r/stats/AIC.html'>AIC</a></span><span class='op'>(</span><span class='va'>f_nlmixr_dfop_sfo_saem</span><span class='op'>$</span><span class='va'>nm</span>, <span class='va'>f_nlmixr_dfop_sfo_focei</span><span class='op'>$</span><span class='va'>nm</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='error'>Error in AIC(f_nlmixr_dfop_sfo_saem$nm, f_nlmixr_dfop_sfo_focei$nm): object 'f_nlmixr_dfop_sfo_saem' not found</span></div><div class='input'><span class='fu'><a href='https://rdrr.io/pkg/saemix/man/summary-methods.html'>summary</a></span><span class='op'>(</span><span class='va'>f_nlmixr_dfop_sfo_sfo</span>, data <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
</div><div class='output co'>#&gt; <span class='error'>Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'summary': object 'f_nlmixr_dfop_sfo_sfo' not found</span></div><div class='input'><span class='co'># }</span>
diff --git a/docs/dev/reference/summary.saem.mmkin.html b/docs/dev/reference/summary.saem.mmkin.html
index aeb08d12..08e3c8f8 100644
--- a/docs/dev/reference/summary.saem.mmkin.html
+++ b/docs/dev/reference/summary.saem.mmkin.html
@@ -260,15 +260,15 @@ saemix authors for the parts inherited from saemix.</p>
quiet <span class='op'>=</span> <span class='cn'>TRUE</span>, error_model <span class='op'>=</span> <span class='st'>"tc"</span>, cores <span class='op'>=</span> <span class='fl'>5</span><span class='op'>)</span>
<span class='va'>f_saem_dfop_sfo</span> <span class='op'>&lt;-</span> <span class='fu'><a href='saem.html'>saem</a></span><span class='op'>(</span><span class='va'>f_mmkin_dfop_sfo</span><span class='op'>)</span>
</div><div class='output co'>#&gt; Running main SAEM algorithm
-#&gt; [1] "Thu Jul 29 12:15:32 2021"
+#&gt; [1] "Wed Aug 4 16:23:26 2021"
#&gt; ....
#&gt; Minimisation finished
-#&gt; [1] "Thu Jul 29 12:15:44 2021"</div><div class='input'><span class='fu'><a href='https://rdrr.io/pkg/saemix/man/summary-methods.html'>summary</a></span><span class='op'>(</span><span class='va'>f_saem_dfop_sfo</span>, data <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
+#&gt; [1] "Wed Aug 4 16:23:38 2021"</div><div class='input'><span class='fu'><a href='https://rdrr.io/pkg/saemix/man/summary-methods.html'>summary</a></span><span class='op'>(</span><span class='va'>f_saem_dfop_sfo</span>, data <span class='op'>=</span> <span class='cn'>TRUE</span><span class='op'>)</span>
</div><div class='output co'>#&gt; saemix version used for fitting: 3.1.9000
#&gt; mkin version used for pre-fitting: 1.0.5
#&gt; R version used for fitting: 4.1.0
-#&gt; Date of fit: Thu Jul 29 12:15:45 2021
-#&gt; Date of summary: Thu Jul 29 12:15:45 2021
+#&gt; Date of fit: Wed Aug 4 16:23:39 2021
+#&gt; Date of summary: Wed Aug 4 16:23:39 2021
#&gt;
#&gt; Equations:
#&gt; d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
@@ -283,7 +283,7 @@ saemix authors for the parts inherited from saemix.</p>
#&gt;
#&gt; Model predictions using solution type analytical
#&gt;
-#&gt; Fitted in 13.372 s using 300, 100 iterations
+#&gt; Fitted in 12.54 s using 300, 100 iterations
#&gt;
#&gt; Variance model: Two-component variance function
#&gt;

Contact - Imprint