Closed ZhonghuiHuang closed 5 months ago
This should work is the development version of nlmixr2est. I'm assuming you are not using it. There is a note about how fixing was changed in that version.
If you are using the development nlmixr2 let me know and I will look into this further. Otherwise I will continue working toward releasing this on CRAN.
If you want an explanation of the differences I can also provide one for you.
Best,
Matt
On Mon, May 20, 2024, 10:35 PM Zhonghui Huang @.***> wrote:
Hi @mattfidler https://github.com/mattfidler,
I tried to introduce covariate models with fixed power values by fix() function in the ini block, however, I find that the fix() function might not work if we use saem not focei, I attached my test results here by using the theo_sd dataset.
Test 1. Covariate model format: ( covwt<- fix(0.01) and use covwt lwt, where lwt = log(theo_sd2$WT/70)) by saem Test 2. Covariate model format: ( covwt<- fix(0.75) and use covwtlwt, where lwt = log(theo_sd2$WT/70)) by saem Test 3. Covariate model format: ( covwt<- fix(100) and use covwt*lwt, where lwt = log(theo_sd2$WT/70)) by saem
Test 4. Covariate model format: ( covwt<- fix(0.01) and use covwt lwt, where lwt = log(theo_sd2$WT/70)) by focei Test 5. Covariate model format: ( covwt<- fix(0.75) and use covwtlwt, where lwt = log(theo_sd2$WT/70)) by focei Test 6. Covariate model format: ( covwt<- fix(100) and use covwt*lwt, where lwt = log(theo_sd2$WT/70)) by focei
Test1-3 shared totally same parameter estimates in each iteration, and share the same final parameter estimate results. But they shouldnt be same given the different setting of power, especially the first and third are extreme values.
However, apparently, focei can work. When focei was used in test 4, test 5 and test 6, we can see the change of parameter estimates between iterations and the model estimate results are also different.
So, if we would like to introduce a fixed allometric scalling with a power of 0.75 and 1 and also choose saem, currently, my option is to write the equation directly in the model block, e.g.,
cl <- exp(tcl + eta.cl http://eta.cl + 0.75 log(WT/70)) cl<-exp(tcl + eta.cl http://eta.cl) (WT/70) ^0.75**
(BTW, cl=exp(tcl+eta.cl+lwt*0.75),lwt = log(theo_sd2$WT/70)), also doesnt work for me) But still hope the fix function can work then can see the fixed values in the nlmixr2 output.
Test1. Use fix() function to introduce a fixed covariate model, extreme power 0.01
Use fix() function to introduce a fixed covariate model> #==============================================================================#> > library(nlmixr2)> theo_sd2<-theo_sd> theo_sd2$lwt<-log(theo_sd2$WT/70)> > ## The basic model consists of an ini block that has initial estimates> one.compartment <- function() {+ ini({+ tka <- log(1.57); label("Ka")+ tcl <- log(2.72); label("Cl")+ tv <- log(31.5); label("V")+ covwt<- fix(0.01);+ + eta.ka ~ 0.6+ eta.cl ~ 0.3+ eta.v ~ 0.1+ add.sd <- 0.7+ })+ # and a model block with the error specification and model specification+ model({+ ka <- exp(tka + eta.ka)+ cl <- exp(tcl + eta.cl + covwtlwt)+ v <- exp(tv + eta.v)+ d/dt(depot) <- -ka depot+ d/dt(center) <- ka depot - cl / v center+ cp <- center / v+ cp ~ add(add.sd)+ })+ }> > ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate> fit0<- nlmixr2(one.compartment, theo_sd2, est="saem", saemControl(print=10,seed = 1234))
→ loading into symengine environment... → pruning branches (
if
/else
) of saem model... ✔ done → finding duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00→ optimizing duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ doneparams: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd001: 0.426017 1.083247 3.539728 0.592610 0.285000 0.095000 2.408191 010: 0.501829 0.967554 3.476164 0.410733 0.179621 0.059874 0.731773 020: 0.454941 1.014119 3.459420 0.346308 0.107546 0.035849 0.705265 030: 0.477338 0.995463 3.474201 0.394533 0.069945 0.021464 0.704248 040: 0.439342 1.028859 3.449393 0.431745 0.085687 0.016491 0.681260 050: 0.380047 1.066219 3.426244 0.415438 0.077686 0.010803 0.707764 060: 0.412688 1.004636 3.438032 0.424521 0.091897 0.012759 0.706832 070: 0.452603 1.009378 3.463855 0.360588 0.075677 0.017905 0.703528 080: 0.370318 1.046738 3.420545 0.397710 0.081115 0.015644 0.711544 090: 0.460203 1.023362 3.449975 0.440390 0.071412 0.023928 0.693081 100: 0.450080 1.018632 3.455627 0.415294 0.067890 0.022319 0.687304 110: 0.455493 1.027576 3.441667 0.445716 0.075984 0.016721 0.674659 120: 0.468103 1.016301 3.451920 0.452389 0.075484 0.018345 0.685905 130: 0.471006 0.991160 3.469804 0.360780 0.074823 0.023260 0.711663 140: 0.437146 1.012946 3.446918 0.418566 0.063419 0.029043 0.685813 150: 0.486432 0.992229 3.473682 0.399591 0.063687 0.027025 0.697351 160: 0.482319 1.013383 3.462588 0.413951 0.092843 0.021622 0.678935 170: 0.503791 1.027372 3.468940 0.483595 0.058152 0.020509 0.689687 180: 0.439974 1.007908 3.454167 0.371606 0.074960 0.014613 0.678929 190: 0.427293 1.037723 3.439008 0.374604 0.062022 0.013980 0.692228 200: 0.440119 1.040741 3.458134 0.355890 0.074055 0.013313 0.721150 210: 0.452073 1.020168 3.446681 0.385688 0.072180 0.015044 0.700821 220: 0.447489 1.020724 3.448970 0.383226 0.073030 0.015859 0.699757 230: 0.444974 1.020360 3.447842 0.384076 0.073989 0.015420 0.700211 240: 0.445238 1.022240 3.447344 0.383898 0.074468 0.015518 0.702492 250: 0.442763 1.023440 3.447074 0.384727 0.073796 0.015493 0.700587 260: 0.444879 1.022585 3.447789 0.388161 0.072947 0.015804 0.699259 270: 0.442805 1.021528 3.446868 0.393174 0.072693 0.016076 0.697323 280: 0.447570 1.018403 3.448971 0.394812 0.073098 0.015982 0.697241 290: 0.451412 1.015877 3.450195 0.391768 0.072871 0.016015 0.697483 300: 0.449270 1.015384 3.450110 0.391312 0.071840 0.016510 0.697923 310: 0.447051 1.015763 3.449151 0.389408 0.072454 0.016442 0.697973 320: 0.449876 1.014353 3.449954 0.391474 0.072775 0.016388 0.698833 330: 0.451111 1.013431 3.450882 0.391544 0.072851 0.016440 0.698968 340: 0.450308 1.014217 3.450329 0.392854 0.072530 0.016576 0.699140 350: 0.448806 1.014773 3.449905 0.392169 0.072751 0.016395 0.699271 360: 0.449157 1.015164 3.449856 0.391511 0.072889 0.016301 0.699652 370: 0.447701 1.015830 3.449027 0.393459 0.072397 0.016491 0.699513 380: 0.448015 1.015419 3.449165 0.394348 0.072100 0.016563 0.699113 390: 0.447556 1.015096 3.449327 0.394829 0.071962 0.016632 0.698792 400: 0.448474 1.014165 3.449721 0.395529 0.071723 0.016774 0.698800 410: 0.448255 1.014056 3.449827 0.393472 0.071843 0.016773 0.699147 420: 0.448896 1.014260 3.450057 0.393950 0.072037 0.016694 0.699327 430: 0.449246 1.014099 3.450090 0.393667 0.071786 0.016717 0.699200 440: 0.449055 1.013679 3.450186 0.391934 0.071733 0.016784 0.699169 450: 0.449796 1.013347 3.450530 0.393240 0.071856 0.016882 0.699053 460: 0.450259 1.013232 3.450704 0.393598 0.071889 0.016968 0.698976 470: 0.450742 1.012861 3.451049 0.393049 0.072178 0.016902 0.698485 480: 0.451073 1.012971 3.451105 0.393940 0.071809 0.016975 0.698098 490: 0.450468 1.013045 3.451226 0.393096 0.071582 0.017017 0.698059 500: 0.450520 1.013017 3.451320 0.392231 0.071404 0.017024 0.698030 Calculating covariance matrix [====|====|====|====|====|====|====|====|====|====] 0:00:00
→ loading into symengine environment... → pruning branches (
if
/else
) of saem model... ✔ done → finding duplicate expressions in saem predOnly model 0... [====|====|====|====|====|====|====|====|====|====] 0:00:00→ finding duplicate expressions in saem predOnly model 1... [====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem predOnly model 1... [====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 2... [====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done → Calculating residuals/tables ✔ done → compress origData in nlmixr2 object, save 7056 → compress phiM in nlmixr2 object, save 82136 → compress parHistData in nlmixr2 object, save 13888 → compress saem0 in nlmixr2 object, save 30864> print(fit0) ── nlmixr² SAEM OBJF by FOCEi approximation ──
Gaussian/Laplacian Likelihoods: AIC(fit0) or fit0$objf etc. FOCEi CWRES & Likelihoods: addCwres(fit0)
── Time (sec fit0$time): ──
setup covariance saem table compress otherelapsed 0.000658 0.005003 1.944 0.034 0.017 0.581339
── Population Parameters (fit0$parFixed or fit0$parFixedDf): ──
Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%tka Ka 0.451 0.191 42.4 1.57 (1.08, 2.28) 69.3 -0.609% tcl Cl 1.01 0.0844 8.33 2.75 (2.33, 3.25) 27.2 4.13% tv V 3.45 0.0448 1.3 31.5 (28.9, 34.4) 13.1 9.48% covwt 0.01 FIXED FIXED 0.01 add.sd 0.698 0.698
Covariance Type (fit0$covMethod): linFim No correlations in between subject variability (BSV) matrix Full BSV covariance (fit0$omega) or correlation (fit0$omegaR; diagonals=SDs) Distribution stats (mean/skewness/kurtosis/p-value) available in fit0$shrink Censoring (fit0$censInformation): No censoring
── Fit Data (object fit0 is a modified tibble): ──# A tibble: 132 × 20 ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v cp depot center ka cl v tad dosenum lwt
1 1 0 0.74 0 0.74 0 0.74 1.06 0.104 -0.482 -0.0740 0 320. 0 1.74 1.70 29.3 0 1 0.1292 1 0.25 2.84 3.25 -0.414 3.83 -0.987 -1.41 0.104 -0.482 -0.0740 3.83 207. 112. 1.74 1.70 29.3 0.25 1 0.1293 1 0.57 6.57 5.83 0.741 6.75 -0.176 -0.252 0.104 -0.482 -0.0740 6.75 119. 198. 1.74 1.70 29.3 0.57 1 0.129# ℹ 129 more rows# ℹ Use `print(n = ...)` to see more rows *Test2. Use fix() function to introduce a fixed covariate model, 0.75* > > library(nlmixr2)> theo_sd2<-theo_sd> theo_sd2$lwt<-log(theo_sd2$WT/70)> > ## The basic model consists of an ini block that has initial estimates> one.compartment <- function() {+ ini({+ tka <- log(1.57); label("Ka")+ tcl <- log(2.72); label("Cl")+ tv <- log(31.5); label("V")+ covwt<- fix(0.75);+ + eta.ka ~ 0.6+ eta.cl ~ 0.3+ eta.v ~ 0.1+ add.sd <- 0.7+ })+ # and a model block with the error specification and model specification+ model({+ ka <- exp(tka + eta.ka)+ cl <- exp(tcl + eta.cl + covwt*lwt)+ v <- exp(tv + eta.v)+ d/dt(depot) <- -ka * depot+ d/dt(center) <- ka * depot - cl / v * center+ cp <- center / v+ cp ~ add(add.sd)+ })+ }> > ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate> fit <- nlmixr2(one.compartment, theo_sd2, est="saem", saemControl(print=10,seed = 1234)) → loading into symengine environment... → pruning branches (`if`/`else`) of saem model... ✔ done → finding duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → optimizing duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00 ✔ doneparams: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd001: 0.426017 1.083247 3.539728 0.592610 0.285000 0.095000 2.408191 010: 0.501829 0.967554 3.476164 0.410733 0.179621 0.059874 0.731773 020: 0.454941 1.014119 3.459420 0.346308 0.107546 0.035849 0.705265 030: 0.477338 0.995463 3.474201 0.394533 0.069945 0.021464 0.704248 040: 0.439342 1.028859 3.449393 0.431745 0.085687 0.016491 0.681260 050: 0.380047 1.066219 3.426244 0.415438 0.077686 0.010803 0.707764 060: 0.412688 1.004636 3.438032 0.424521 0.091897 0.012759 0.706832 070: 0.452603 1.009378 3.463855 0.360588 0.075677 0.017905 0.703528 080: 0.370318 1.046738 3.420545 0.397710 0.081115 0.015644 0.711544 090: 0.460203 1.023362 3.449975 0.440390 0.071412 0.023928 0.693081 100: 0.450080 1.018632 3.455627 0.415294 0.067890 0.022319 0.687304 110: 0.455493 1.027576 3.441667 0.445716 0.075984 0.016721 0.674659 120: 0.468103 1.016301 3.451920 0.452389 0.075484 0.018345 0.685905 130: 0.471006 0.991160 3.469804 0.360780 0.074823 0.023260 0.711663 140: 0.437146 1.012946 3.446918 0.418566 0.063419 0.029043 0.685813 150: 0.486432 0.992229 3.473682 0.399591 0.063687 0.027025 0.697351 160: 0.482319 1.013383 3.462588 0.413951 0.092843 0.021622 0.678935 170: 0.503791 1.027372 3.468940 0.483595 0.058152 0.020509 0.689687 180: 0.439974 1.007908 3.454167 0.371606 0.074960 0.014613 0.678929 190: 0.427293 1.037723 3.439008 0.374604 0.062022 0.013980 0.692228 200: 0.440119 1.040741 3.458134 0.355890 0.074055 0.013313 0.721150 210: 0.452073 1.020168 3.446681 0.385688 0.072180 0.015044 0.700821 220: 0.447489 1.020724 3.448970 0.383226 0.073030 0.015859 0.699757 230: 0.444974 1.020360 3.447842 0.384076 0.073989 0.015420 0.700211 240: 0.445238 1.022240 3.447344 0.383898 0.074468 0.015518 0.702492 250: 0.442763 1.023440 3.447074 0.384727 0.073796 0.015493 0.700587 260: 0.444879 1.022585 3.447789 0.388161 0.072947 0.015804 0.699259 270: 0.442805 1.021528 3.446868 0.393174 0.072693 0.016076 0.697323 280: 0.447570 1.018403 3.448971 0.394812 0.073098 0.015982 0.697241 290: 0.451412 1.015877 3.450195 0.391768 0.072871 0.016015 0.697483 300: 0.449270 1.015384 3.450110 0.391312 0.071840 0.016510 0.697923 310: 0.447051 1.015763 3.449151 0.389408 0.072454 0.016442 0.697973 320: 0.449876 1.014353 3.449954 0.391474 0.072775 0.016388 0.698833 330: 0.451111 1.013431 3.450882 0.391544 0.072851 0.016440 0.698968 340: 0.450308 1.014217 3.450329 0.392854 0.072530 0.016576 0.699140 350: 0.448806 1.014773 3.449905 0.392169 0.072751 0.016395 0.699271 360: 0.449157 1.015164 3.449856 0.391511 0.072889 0.016301 0.699652 370: 0.447701 1.015830 3.449027 0.393459 0.072397 0.016491 0.699513 380: 0.448015 1.015419 3.449165 0.394348 0.072100 0.016563 0.699113 390: 0.447556 1.015096 3.449327 0.394829 0.071962 0.016632 0.698792 400: 0.448474 1.014165 3.449721 0.395529 0.071723 0.016774 0.698800 410: 0.448255 1.014056 3.449827 0.393472 0.071843 0.016773 0.699147 420: 0.448896 1.014260 3.450057 0.393950 0.072037 0.016694 0.699327 430: 0.449246 1.014099 3.450090 0.393667 0.071786 0.016717 0.699200 440: 0.449055 1.013679 3.450186 0.391934 0.071733 0.016784 0.699169 450: 0.449796 1.013347 3.450530 0.393240 0.071856 0.016882 0.699053 460: 0.450259 1.013232 3.450704 0.393598 0.071889 0.016968 0.698976 470: 0.450742 1.012861 3.451049 0.393049 0.072178 0.016902 0.698485 480: 0.451073 1.012971 3.451105 0.393940 0.071809 0.016975 0.698098 490: 0.450468 1.013045 3.451226 0.393096 0.071582 0.017017 0.698059 500: 0.450520 1.013017 3.451320 0.392231 0.071404 0.017024 0.698030 Calculating covariance matrix [====|====|====|====|====|====|====|====|====|====] 0:00:00 → loading into symengine environment... → pruning branches (`if`/`else`) of saem model... ✔ done → finding duplicate expressions in saem predOnly model 0... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → finding duplicate expressions in saem predOnly model 1... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → optimizing duplicate expressions in saem predOnly model 1... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → finding duplicate expressions in saem predOnly model 2... [====|====|====|====|====|====|====|====|====|====] 0:00:00 ✔ done → Calculating residuals/tables ✔ done → compress origData in nlmixr2 object, save 7056 → compress phiM in nlmixr2 object, save 94688 → compress parHistData in nlmixr2 object, save 13888 → compress saem0 in nlmixr2 object, save 30896> print(fit) ── nlmixr² SAEM OBJF by FOCEi approximation ── Gaussian/Laplacian Likelihoods: AIC(fit) or fit$objf etc. FOCEi CWRES & Likelihoods: addCwres(fit) ── Time (sec fit$time): ── setup covariance saem table compress otherelapsed 0.000618 0.003003 1.911 0.035 0.018 0.510379 ── Population Parameters (fit$parFixed or fit$parFixedDf): ── Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%tka Ka 0.451 0.191 42.4 1.57 (1.08, 2.28) 69.3 -0.609% tcl Cl 1.01 0.0844 8.33 2.75 (2.33, 3.25) 27.2 4.13% tv V 3.45 0.0448 1.3 31.5 (28.9, 34.4) 13.1 9.48% covwt 0.75 FIXED FIXED 0.75 add.sd 0.698 0.698 Covariance Type (fit$covMethod): linFim No correlations in between subject variability (BSV) matrix Full BSV covariance (fit$omega) or correlation (fit$omegaR; diagonals=SDs) Distribution stats (mean/skewness/kurtosis/p-value) available in fit$shrink Censoring (fit$censInformation): No censoring ── Fit Data (object fit is a modified tibble): ──# A tibble: 132 × 20 ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v cp depot center ka cl v tad dosenum lwt 1 1 0 0.74 0 0.74 0 0.74 1.06 0.104 -0.482 -0.0740 0 320. 0 1.74 1.87 29.3 0 1 0.1292 1 0.25 2.84 3.25 -0.410 3.82 -0.984 -1.41 0.104 -0.482 -0.0740 3.82 207. 112. 1.74 1.87 29.3 0.25 1 0.1293 1 0.57 6.57 5.81 0.758 6.73 -0.163 -0.234 0.104 -0.482 -0.0740 6.73 119. 197. 1.74 1.87 29.3 0.57 1 0.129 *Test 3. Use fix() function to introduce a fixed covariate model, use an extreme value, 100* > library(nlmixr2)> theo_sd2<-theo_sd> theo_sd2$lwt<-log(theo_sd2$WT/70)> > > ## The basic model consists of an ini block that has initial estimates> one.compartment <- function() {+ ini({+ tka <- log(1.57); label("Ka")+ tcl <- log(2.72); label("Cl")+ tv <- log(31.5); label("V")+ covwt<- fix(100);+ + eta.ka ~ 0.6+ eta.cl ~ 0.3+ eta.v ~ 0.1+ add.sd <- 0.7+ })+ # and a model block with the error specification and model specification+ model({+ ka <- exp(tka + eta.ka)+ cl <- exp(tcl + eta.cl + covwt*lwt)+ v <- exp(tv + eta.v)+ d/dt(depot) <- -ka * depot+ d/dt(center) <- ka * depot - cl / v * center+ cp <- center / v+ cp ~ add(add.sd)+ })+ }> > ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate> fit2<- nlmixr2(one.compartment, theo_sd2, est="saem", saemControl(print=10,seed = 1234)) → loading into symengine environment... → pruning branches (`if`/`else`) of saem model... ✔ done → finding duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → optimizing duplicate expressions in saem model... [====|====|====|====|====|====|====|====|====|====] 0:00:00 ✔ doneparams: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd001: 0.426017 1.083247 3.539728 0.592610 0.285000 0.095000 2.408191 010: 0.501829 0.967554 3.476164 0.410733 0.179621 0.059874 0.731773 020: 0.454941 1.014119 3.459420 0.346308 0.107546 0.035849 0.705265 030: 0.477338 0.995463 3.474201 0.394533 0.069945 0.021464 0.704248 040: 0.439342 1.028859 3.449393 0.431745 0.085687 0.016491 0.681260 050: 0.380047 1.066219 3.426244 0.415438 0.077686 0.010803 0.707764 060: 0.412688 1.004636 3.438032 0.424521 0.091897 0.012759 0.706832 070: 0.452603 1.009378 3.463855 0.360588 0.075677 0.017905 0.703528 080: 0.370318 1.046738 3.420545 0.397710 0.081115 0.015644 0.711544 090: 0.460203 1.023362 3.449975 0.440390 0.071412 0.023928 0.693081 100: 0.450080 1.018632 3.455627 0.415294 0.067890 0.022319 0.687304 110: 0.455493 1.027576 3.441667 0.445716 0.075984 0.016721 0.674659 120: 0.468103 1.016301 3.451920 0.452389 0.075484 0.018345 0.685905 130: 0.471006 0.991160 3.469804 0.360780 0.074823 0.023260 0.711663 140: 0.437146 1.012946 3.446918 0.418566 0.063419 0.029043 0.685813 150: 0.486432 0.992229 3.473682 0.399591 0.063687 0.027025 0.697351 160: 0.482319 1.013383 3.462588 0.413951 0.092843 0.021622 0.678935 170: 0.503791 1.027372 3.468940 0.483595 0.058152 0.020509 0.689687 180: 0.439974 1.007908 3.454167 0.371606 0.074960 0.014613 0.678929 190: 0.427293 1.037723 3.439008 0.374604 0.062022 0.013980 0.692228 200: 0.440119 1.040741 3.458134 0.355890 0.074055 0.013313 0.721150 210: 0.452073 1.020168 3.446681 0.385688 0.072180 0.015044 0.700821 220: 0.447489 1.020724 3.448970 0.383226 0.073030 0.015859 0.699757 230: 0.444974 1.020360 3.447842 0.384076 0.073989 0.015420 0.700211 240: 0.445238 1.022240 3.447344 0.383898 0.074468 0.015518 0.702492 250: 0.442763 1.023440 3.447074 0.384727 0.073796 0.015493 0.700587 260: 0.444879 1.022585 3.447789 0.388161 0.072947 0.015804 0.699259 270: 0.442805 1.021528 3.446868 0.393174 0.072693 0.016076 0.697323 280: 0.447570 1.018403 3.448971 0.394812 0.073098 0.015982 0.697241 290: 0.451412 1.015877 3.450195 0.391768 0.072871 0.016015 0.697483 300: 0.449270 1.015384 3.450110 0.391312 0.071840 0.016510 0.697923 310: 0.447051 1.015763 3.449151 0.389408 0.072454 0.016442 0.697973 320: 0.449876 1.014353 3.449954 0.391474 0.072775 0.016388 0.698833 330: 0.451111 1.013431 3.450882 0.391544 0.072851 0.016440 0.698968 340: 0.450308 1.014217 3.450329 0.392854 0.072530 0.016576 0.699140 350: 0.448806 1.014773 3.449905 0.392169 0.072751 0.016395 0.699271 360: 0.449157 1.015164 3.449856 0.391511 0.072889 0.016301 0.699652 370: 0.447701 1.015830 3.449027 0.393459 0.072397 0.016491 0.699513 380: 0.448015 1.015419 3.449165 0.394348 0.072100 0.016563 0.699113 390: 0.447556 1.015096 3.449327 0.394829 0.071962 0.016632 0.698792 400: 0.448474 1.014165 3.449721 0.395529 0.071723 0.016774 0.698800 410: 0.448255 1.014056 3.449827 0.393472 0.071843 0.016773 0.699147 420: 0.448896 1.014260 3.450057 0.393950 0.072037 0.016694 0.699327 430: 0.449246 1.014099 3.450090 0.393667 0.071786 0.016717 0.699200 440: 0.449055 1.013679 3.450186 0.391934 0.071733 0.016784 0.699169 450: 0.449796 1.013347 3.450530 0.393240 0.071856 0.016882 0.699053 460: 0.450259 1.013232 3.450704 0.393598 0.071889 0.016968 0.698976 470: 0.450742 1.012861 3.451049 0.393049 0.072178 0.016902 0.698485 480: 0.451073 1.012971 3.451105 0.393940 0.071809 0.016975 0.698098 490: 0.450468 1.013045 3.451226 0.393096 0.071582 0.017017 0.698059 500: 0.450520 1.013017 3.451320 0.392231 0.071404 0.017024 0.698030 Calculating covariance matrix [====|====|====|====|====|====|====|====|====|====] 0:00:00 → loading into symengine environment... → pruning branches (`if`/`else`) of saem model... ✔ done → finding duplicate expressions in saem predOnly model 0... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → finding duplicate expressions in saem predOnly model 1... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → optimizing duplicate expressions in saem predOnly model 1... [====|====|====|====|====|====|====|====|====|====] 0:00:00 → finding duplicate expressions in saem predOnly model 2... [====|====|====|====|====|====|====|====|====|====] 0:00:00 ✔ done → Calculating residuals/tables ✔ done → compress origData in nlmixr2 object, save 7056 → compress phiM in nlmixr2 object, save 139544 → compress parHistData in nlmixr2 object, save 13888 → compress saem0 in nlmixr2 object, save 30928> print(fit2) ── nlmixr² SAEM OBJF by FOCEi approximation ── Gaussian/Laplacian Likelihoods: AIC(fit2) or fit2$objf etc. FOCEi CWRES & Likelihoods: addCwres(fit2) ── Time (sec fit2$time): ── setup covariance saem table compress otherelapsed 0.000639 0.005003 1.893 0.032 0.016 0.519358 ── Population Parameters (fit2$parFixed or fit2$parFixedDf): ── Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%tka Ka 0.451 0.191 42.4 1.57 (1.08, 2.28) 69.3 -0.609% tcl Cl 1.01 0.0844 8.33 2.75 (2.33, 3.25) 27.2 4.13% tv V 3.45 0.0448 1.3 31.5 (28.9, 34.4) 13.1 9.48% covwt 100 FIXED FIXED 100 add.sd 0.698 0.698 Covariance Type (fit2$covMethod): linFim No correlations in between subject variability (BSV) matrix Full BSV covariance (fit2$omega) or correlation (fit2$omegaR; diagonals=SDs) Distribution stats (mean/skewness/kurtosis/p-value) available in fit2$shrink Censoring (fit2$censInformation): No censoring ── Fit Data (object fit2 is a modified tibble): ──# A tibble: 132 × 20 ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v cp depot center ka cl v tad dosenum lwt 1 1 0 0.74 0 0.74 0 0.74 1.06 0.104 -0.482 -0.0740 0 320. 0 1.74 648497. 29.3 0 1 0.1292 1 0.25 2.84 0.000323 2.84 0.000556 2.84 4.07 0.104 -0.482 -0.0740 0.000556 207. 0.0163 1.74 648497. 29.3 0.25 1 0.1293 1 0.57 6.57 0.000195 6.57 0.000318 6.57 9.41 0.104 -0.482 -0.0740 0.000318 119. 0.00933 1.74 648497. 29.3 0.57 1 0.129# ℹ 129 more rows *Test4. Use fix() function to introduce a fixed covariate model, run by FOCEI* > library(nlmixr2)> theo_sd2<-theo_sd> theo_sd2$lwt<-log(theo_sd2$WT/70)> > ## The basic model consists of an ini block that has initial estimates> one.compartment <- function() {+ ini({+ tka <- log(1.57); label("Ka")+ tcl <- log(2.72); label("Cl")+ tv <- log(31.5); label("V")+ covwt<- fix(0.01);+ + eta.ka ~ 0.6+ eta.cl ~ 0.3+ eta.v ~ 0.1+ add.sd <- 0.7+ })+ # and a model block with the error specification and model specification+ model({+ ka <- exp(tka + eta.ka)+ cl <- exp(tcl + eta.cl + covwt*lwt)+ v <- exp(tv + eta.v)+ d/dt(depot) <- -ka * depot+ d/dt(center) <- ka * depot - cl / v * center+ cp <- center / v+ cp ~ add(add.sd)+ })+ }> > ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate> fit3 <- nlmixr2(one.compartment, theo_sd2, est="focei", foceiControl(print=10,seed = 1234))Key: U: Unscaled Parameters; X: Back-transformed parameters; G: Gill difference gradient approximationF: Forward difference gradient approximationC: Central difference gradient approximationM: Mixed forward and central difference gradient approximationUnscaled parameters for Omegas=chol(solve(omega));Diagonals are transformed, as specified by foceiControl(diagXform=)|-----+---------------+-----------+-----------+-----------+-----------+-----------+-----------+-----------|| #| Objective Fun | tka | tcl | tv | add.sd | o1 | o2 | o3 || 10| 122.02628 | -0.9784 | -0.6251 | 0.9768 | -0.8380 | -0.3995 | 0.1663 | 0.3299 || U| 122.02628 | 0.4726 | 1.009 | 3.427 | 0.6943 | 1.186 | 1.770 | 2.028 || X| 122.02628 | 1.604 | 2.743 | 30.78 | 0.6943 | 1.186 | 1.770 | 2.028 || F| Forward Diff. | -0.3764 | 1.979 | 14.59 | 19.36 | -1.889 | -5.481 | -6.625 || 20| 117.40915 | -0.9623 | -0.6467 | 1.019 | -0.8353 | -0.2340 | 0.2912 | 1.147 || U| 117.40915 | 0.4888 | 0.9874 | 3.469 | 0.6982 | 1.244 | 1.863 | 2.488 || X| 117.40915 | 1.630 | 2.684 | 32.12 | 0.6982 | 1.244 | 1.863 | 2.488 || 30| 117.12000 | -0.9426 | -0.6200 | 1.016 | -0.8331 | -0.2607 | 0.3311 | 1.251 || U| 117.12 | 0.5085 | 1.014 | 3.466 | 0.7013 | 1.235 | 1.892 | 2.546 || X| 117.12 | 1.663 | 2.757 | 32.00 | 0.7013 | 1.235 | 1.892 | 2.546 || F| Forward Diff. | 0.08544 | -1.469 | -0.06992 | 12.16 | -1.051 | -1.599 | -1.055 || 40| 116.83087 | -0.9818 | -0.6218 | 1.008 | -0.8379 | -0.2491 | 0.3738 | 1.409 || U| 116.83087 | 0.4692 | 1.012 | 3.458 | 0.6944 | 1.239 | 1.924 | 2.635 || X| 116.83087 | 1.599 | 2.752 | 31.75 | 0.6944 | 1.239 | 1.924 | 2.635 || F| Forward Diff. | -5.067 | -0.9498 | -0.7960 | 0.3804 | -0.2611 | 0.07740 | -0.1536 || 50| 116.78891 | -0.9863 | -0.6232 | 1.011 | -0.8371 | -0.2257 | 0.3941 | 1.469 || U| 116.78891 | 0.4648 | 1.011 | 3.461 | 0.6956 | 1.247 | 1.939 | 2.669 || X| 116.78891 | 1.592 | 2.748 | 31.83 | 0.6956 | 1.247 | 1.939 | 2.669 |calculating covariance matrix [====|====|====|====|====|====|====|====|====|====] 0:00:00 done → Calculating residuals/tables ✔ done → compress origData in nlmixr2 object, save 7056 → compress parHistData in nlmixr2 object, save 6400> print(fit3) ── nlmixr² FOCEi (outer: nlminb) ── OBJF AIC BIC Log-likelihood Condition#(Cov) Condition#(Cor)FOCEi 116.7875 373.3872 393.5669 -179.6936 63.01769 4.138121 ── Time (sec fit3$time): ── setup optimize covariance table compress otherelapsed 0.000659 0.222847 0.222848 0.022 0.008 1.186646 ── Population Parameters (fit3$parFixed or fit3$parFixedDf): ── Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%tka Ka 0.464 0.226 48.7 1.59 (1.02, 2.48) 71.5 2.83% tcl Cl 1.01 0.368 36.4 2.75 (1.34, 5.65) 27.1 5.05% tv V 3.46 0.0581 1.68 31.9 (28.4, 35.7) 14.1 11.1% covwt 0.01 FIXED FIXED 0.01 add.sd 0.695 0.695 Covariance Type (fit3$covMethod): r,s No correlations in between subject variability (BSV) matrix Full BSV covariance (fit3$omega) or correlation (fit3$omegaR; diagonals=SDs) Distribution stats (mean/skewness/kurtosis/p-value) available in fit3$shrink Information about run found (fit3$runInfo): • gradient problems with initial estimate and covariance; see $scaleInfo • ETAs were reset to zero during optimization; (Can control by foceiControl(resetEtaP=.)) • initial ETAs were nudged; (can control by foceiControl(etaNudge=., etaNudge2=)) Censoring (fit3$censInformation): No censoring Minimization message (fit3$message): relative convergence (4) ── Fit Data (object fit3 is a modified tibble): ──# A tibble: 132 × 23 ID TIME DV PRED RES WRES IPRED IRES IWRES CPRED CRES CWRES eta.ka eta.cl eta.v depot center ka cl v tad dosenum lwt 1 1 0 0.74 0 0.74 1.06 0 0.74 1.06 0 0.74 1.06 0.0865 -0.476 -0.0924 320. 0 1.73 1.71 29.0 0 1 0.1292 1 0.25 2.84 3.26 -0.419 -0.221 3.85 -1.01 -1.45 3.21 -0.374 -0.173 0.0865 -0.476 -0.0924 207. 112. 1.73 1.71 29.0 0.25 1 0.1293 1 0.57 6.57 5.82 0.748 0.297 6.79 -0.215 -0.310 5.77 0.805 0.288 0.0865 -0.476 -0.0924 119. 197. 1.73 1.71 29.0 0.57 1 0.129# ℹ 129 more rows# ℹ Use `print(n = ...)` to see more rows *Test5. Use fix() function to introduce a fixed covariate model, run by FOCEI* > library(nlmixr2)> theo_sd2<-theo_sd> theo_sd2$lwt<-log(theo_sd2$WT/70)> > ## The basic model consists of an ini block that has initial estimates> one.compartment <- function() {+ ini({+ tka <- log(1.57); label("Ka")+ tcl <- log(2.72); label("Cl")+ tv
Thanks for this, Matt. It seems that I might have missed some important changes related to the fix() function. I am currently using version nlmixr2est_2.2.1 and I think not the development version.
I just downloaded the version from the link https://github.com/nlmixr2/nlmixr2. Now it is nlmixr2est_2.2.2.
I re-run the test 3 by the method fix() or the method of writing the equation in the model block directly. However, the two methods still have the different results.
When I compared the test1, test2, and test3, although they have different estimates for each iteration, but for the final estimates still look weird.
BTW, I find that even though introduce the fixed values by writing them in the model block part, it seems that it still can not recognise this covariate part. (see the last running)
Test by fix()
> # Use fix() function to introduce a fixed covariate model
> #==============================================================================#
>
> library(nlmixr2)
> theo_sd2<-theo_sd
> theo_sd2$lwt<-log(theo_sd2$WT/70)
>
> ## The basic model consists of an ini block that has initial estimates
> one.compartment <- function() {
+ ini({
+ tka <- log(1.57); label("Ka")
+ tcl <- log(2.72); label("Cl")
+ tv <- log(31.5); label("V")
+ covwt<- fix(100);
+
+ eta.ka ~ 0.6
+ eta.cl ~ 0.3
+ eta.v ~ 0.1
+ add.sd <- 0.7
+ })
+ # and a model block with the error specification and model specification
+ model({
+ ka <- exp(tka + eta.ka)
+ cl <- exp(tcl + eta.cl + covwt*lwt)
+ v <- exp(tv + eta.v)
+ d/dt(depot) <- -ka * depot
+ d/dt(center) <- ka * depot - cl / v * center
+ cp <- center / v
+ cp ~ add(add.sd)
+ })
+ }
>
> ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate
> fit0<- nlmixr2(one.compartment, theo_sd2, est="saem", saemControl(print=10,seed = 1234))
→ loading into symengine environment...
→ pruning branches (`if`/`else`) of saem model...
✔ done
→ finding duplicate expressions in saem model...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem model...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done
ℹ calculate uninformed etas
ℹ done
params: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd
001: 0.477828 1.193181 3.540865 0.670440 0.285000 0.095000 2.481478
010: 0.292654 1.028709 3.448012 0.422544 0.179621 0.059874 0.933184
020: 0.323250 1.034565 3.450468 0.283349 0.107546 0.035849 0.916087
030: 0.246572 1.054546 3.427015 0.215741 0.073231 0.021464 0.941825
040: 0.318623 1.016192 3.446312 0.203425 0.102279 0.013531 0.930611
050: 0.306921 1.035205 3.419254 0.178160 0.094455 0.009659 0.949698
060: 0.302847 1.034192 3.439183 0.190345 0.088840 0.009287 0.930402
070: 0.158354 1.087708 3.392367 0.163758 0.095002 0.006958 0.962190
080: 0.206919 1.056692 3.384905 0.175308 0.106538 0.006629 0.938224
090: 0.191478 1.090443 3.387805 0.173272 0.104424 0.004217 1.012654
100: 0.180740 1.061290 3.386322 0.198120 0.100856 0.002525 0.986812
110: 0.226212 1.059082 3.397850 0.131918 0.094245 0.001512 0.978183
120: 0.222577 1.046371 3.394035 0.119858 0.104147 0.002234 0.999379
130: 0.277805 1.022893 3.411632 0.171890 0.099733 0.002498 0.986380
140: 0.283586 1.039799 3.424476 0.167609 0.092812 0.002218 0.997360
150: 0.274284 1.043454 3.414263 0.168871 0.097009 0.001328 0.982148
160: 0.230462 1.026334 3.420953 0.131201 0.087466 0.000195 0.979443
170: 0.273266 1.075862 3.420299 0.131135 0.103608 0.000009 1.001441
180: 0.245780 1.063286 3.419879 0.128046 0.099804 0.000001 1.006117
190: 0.216001 1.034339 3.420092 0.114310 0.118541 0.000000 1.003514
200: 0.253627 1.049436 3.420128 0.174959 0.105073 0.000000 1.015432
210: 0.255694 1.056685 3.420090 0.136155 0.106506 0.000000 0.999045
220: 0.260126 1.063046 3.420106 0.139685 0.105550 0.000000 0.997727
230: 0.257461 1.066594 3.420107 0.134702 0.105844 0.000000 1.000530
240: 0.259031 1.067806 3.420104 0.136643 0.104647 0.000000 1.001298
250: 0.258266 1.066537 3.420109 0.136939 0.105046 0.000000 1.000931
260: 0.261152 1.067458 3.420108 0.140161 0.104162 0.000000 1.001839
270: 0.260442 1.066688 3.420105 0.139443 0.104525 0.000000 1.002944
280: 0.260585 1.064669 3.420105 0.139201 0.103765 0.000000 1.003522
290: 0.258679 1.063775 3.420106 0.138193 0.104272 0.000000 1.003738
300: 0.260142 1.063758 3.420104 0.136631 0.103811 0.000000 1.005334
310: 0.259159 1.062201 3.420104 0.136082 0.104012 0.000000 1.005397
320: 0.258316 1.062221 3.420103 0.136665 0.104797 0.000000 1.005239
330: 0.258113 1.061457 3.420102 0.136990 0.104696 0.000000 1.005648
340: 0.257967 1.061214 3.420100 0.136521 0.104603 0.000000 1.005232
350: 0.258260 1.060210 3.420102 0.135753 0.104737 0.000000 1.005202
360: 0.258343 1.060389 3.420103 0.135007 0.104337 0.000000 1.006109
370: 0.258453 1.060952 3.420103 0.134979 0.103830 0.000000 1.006387
380: 0.259189 1.061577 3.420102 0.135175 0.103788 0.000000 1.006229
390: 0.258053 1.062530 3.420102 0.134875 0.103206 0.000000 1.006215
400: 0.258103 1.062867 3.420102 0.134570 0.102965 0.000000 1.005832
410: 0.258408 1.063553 3.420102 0.134745 0.103117 0.000000 1.005668
420: 0.258646 1.063520 3.420101 0.134828 0.102980 0.000000 1.005966
430: 0.259338 1.063837 3.420101 0.134394 0.102878 0.000000 1.005849
440: 0.259558 1.063128 3.420101 0.133850 0.103012 0.000000 1.005851
450: 0.259898 1.063583 3.420101 0.134048 0.103276 0.000000 1.005723
460: 0.260194 1.063084 3.420100 0.133697 0.103539 0.000000 1.005708
470: 0.260328 1.063400 3.420101 0.133547 0.103554 0.000000 1.005936
480: 0.259993 1.063039 3.420100 0.133441 0.103508 0.000000 1.005716
490: 0.260034 1.063393 3.420100 0.133158 0.103441 0.000000 1.006034
500: 0.259039 1.063518 3.420101 0.133086 0.103074 0.000000 1.006433
Calculating covariance matrix
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ loading into symengine environment...
→ pruning branches (`if`/`else`) of saem model...
✔ done
→ finding duplicate expressions in saem predOnly model 0...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 1...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem predOnly model 1...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 2...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done
→ Calculating residuals/tables
✔ done
→ compress origData in nlmixr2 object, save 7056
→ compress phiM in nlmixr2 object, save 96968
→ compress parHistData in nlmixr2 object, save 15032
→ compress saem0 in nlmixr2 object, save 32704
> print(fit0)
── nlmixr² SAEM OBJF by FOCEi approximation ──
Gaussian/Laplacian Likelihoods: AIC(fit0) or fit0$objf etc.
FOCEi CWRES & Likelihoods: addCwres(fit0)
── Time (sec fit0$time): ──
setup covariance saem table compress other
elapsed 0.000594 0.003003 1.399 0.042 0.015 0.495403
── Population Parameters (fit0$parFixed or fit0$parFixedDf): ──
Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
tka Ka 0.259 0.132 51.1 1.3 (1, 1.68) 37.7 5.59%
tcl Cl 1.06 0.104 9.81 2.9 (2.36, 3.55) 33.0 3.59%
tv V 3.42 0.0353 1.03 30.6 (28.5, 32.8) 0.0140 93.7%
covwt 100 FIXED FIXED 100
add.sd 1.01 1.01
Covariance Type (fit0$covMethod): linFim
No correlations in between subject variability (BSV) matrix
Full BSV covariance (fit0$omega) or correlation (fit0$omegaR; diagonals=SDs)
Distribution stats (mean/skewness/kurtosis/p-value) available in fit0$shrink
Censoring (fit0$censInformation): No censoring
── Fit Data (object fit0 is a modified tibble): ──
# A tibble: 132 × 20
ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v cp depot center ka cl v tad dosenum lwt
<fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 0 0.74 0 0.74 0 0.74 0.735 0.306 -0.560 0 0 320. 0 1.76 631253. 30.6 0 1 0.129
2 1 0.25 2.84 0.000271 2.84 0.000575 2.84 2.82 0.306 -0.560 0 0.000575 206. 0.0176 1.76 631253. 30.6 0.25 1 0.129
3 1 0.57 6.57 0.000179 6.57 0.000327 6.57 6.53 0.306 -0.560 0 0.000327 117. 0.0100 1.76 631253. 30.6 0.57 1 0.129
# ℹ 129 more rows
# ℹ Use `print(n = ...)` to see more rows
Test by writing equations directly
> library(nlmixr2)
> theo_sd2<-theo_sd
> theo_sd2$lwt<-log(theo_sd2$WT/70)
>
>
> ## The basic model consists of an ini block that has initial estimates
> one.compartment <- function() {
+ ini({
+ tka <- log(1.57); label("Ka")
+ tcl <- log(2.72); label("Cl")
+ tv <- log(31.5); label("V")
+
+ eta.ka ~ 0.6
+ eta.cl ~ 0.3
+ eta.v ~ 0.1
+ add.sd <- 0.7
+ })
+ # and a model block with the error specification and model specification
+ model({
+ ka <- exp(tka + eta.ka)
+ cl <- exp(tcl + eta.cl + 100*log(WT/70))
+ v <- exp(tv + eta.v)
+ d/dt(depot) <- -ka * depot
+ d/dt(center) <- ka * depot - cl / v * center
+ cp <- center / v
+ cp ~ add(add.sd)
+ })
+ }
>
> ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate
> fit2 <- nlmixr2(one.compartment, theo_sd2, est="saem", saemControl(print=10,seed = 1234))
→ loading into symengine environment...
→ pruning branches (`if`/`else`) of saem model...
✔ done
→ finding duplicate expressions in saem model...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem model...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
ℹ calculate uninformed etas
ℹ done
params: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd
001: 0.541049 1.189280 3.595308 0.699685 0.334352 0.095000 4.360819
010: 1.091139 -0.279231 3.857157 0.534374 0.940725 0.059874 3.427737
020: 1.078629 -1.317274 3.956749 0.376343 1.496260 0.035849 3.382416
030: 1.379304 -2.333378 3.979332 0.271158 1.114484 0.021464 3.460328
040: 1.653405 -2.219497 3.987032 0.307459 1.286101 0.012851 3.425515
050: 1.577192 -3.473459 3.962689 0.225542 1.350979 0.008083 3.453118
060: 1.495148 -3.244201 4.002577 0.135961 0.985821 0.005072 3.453910
070: 1.236473 -3.536271 3.952975 0.081405 0.954875 0.003139 3.438820
080: 1.369645 -3.484134 3.932342 0.183567 1.240920 0.002863 3.422521
090: 1.169906 -2.843945 3.942733 0.143885 1.171111 0.001714 3.400523
100: 1.350510 -3.189847 3.917577 0.137945 1.383477 0.001113 3.427547
110: 1.340560 -3.330845 3.937518 0.111150 1.276906 0.000697 3.428717
120: 1.236081 -2.824423 3.936742 0.156344 1.065217 0.000460 3.417418
130: 1.153045 -3.050418 3.946562 0.124032 0.720460 0.000290 3.416935
140: 1.278409 -2.790372 3.957290 0.079323 1.027322 0.000177 3.415058
150: 1.357766 -2.241478 3.956627 0.050972 1.930102 0.000106 3.411749
160: 1.379078 -2.764414 3.958938 0.024346 0.483274 0.000005 3.413350
170: 1.324860 -2.905747 3.958476 0.002247 0.131395 0.000000 3.413593
180: 1.329250 -3.060441 3.958518 0.001344 0.024744 0.000000 3.411552
190: 1.324304 -3.070617 3.958508 0.000291 0.009484 0.000000 3.413938
200: 1.319287 -3.085275 3.958507 0.000177 0.003296 0.000000 3.410360
210: 1.316734 -3.082293 3.958507 0.000144 0.002614 0.000000 3.410616
220: 1.316608 -3.081747 3.958507 0.000136 0.002480 0.000000 3.410466
230: 1.316814 -3.081074 3.958507 0.000129 0.002373 0.000000 3.410493
240: 1.316771 -3.080273 3.958507 0.000124 0.002399 0.000000 3.410495
250: 1.316734 -3.080104 3.958507 0.000122 0.002337 0.000000 3.410489
260: 1.316821 -3.079676 3.958507 0.000120 0.002332 0.000000 3.410439
270: 1.316847 -3.079566 3.958507 0.000120 0.002311 0.000000 3.410437
280: 1.316877 -3.080039 3.958507 0.000118 0.002317 0.000000 3.410411
290: 1.316803 -3.080501 3.958507 0.000119 0.002290 0.000000 3.410422
300: 1.316893 -3.080379 3.958507 0.000119 0.002290 0.000000 3.410444
310: 1.316859 -3.080243 3.958507 0.000118 0.002270 0.000000 3.410407
320: 1.316837 -3.080306 3.958507 0.000118 0.002286 0.000000 3.410400
330: 1.316833 -3.080296 3.958507 0.000118 0.002276 0.000000 3.410420
340: 1.316870 -3.080143 3.958507 0.000117 0.002243 0.000000 3.410441
350: 1.316943 -3.080200 3.958507 0.000116 0.002232 0.000000 3.410456
360: 1.316999 -3.080280 3.958507 0.000116 0.002216 0.000000 3.410463
370: 1.317007 -3.080210 3.958507 0.000115 0.002193 0.000000 3.410458
380: 1.317010 -3.080152 3.958507 0.000114 0.002174 0.000000 3.410447
390: 1.317012 -3.080136 3.958507 0.000114 0.002177 0.000000 3.410455
400: 1.317012 -3.079937 3.958507 0.000112 0.002170 0.000000 3.410462
410: 1.316992 -3.079850 3.958507 0.000112 0.002157 0.000000 3.410461
420: 1.317012 -3.079914 3.958507 0.000113 0.002145 0.000000 3.410476
430: 1.317029 -3.079956 3.958507 0.000113 0.002138 0.000000 3.410480
440: 1.317045 -3.080024 3.958507 0.000112 0.002134 0.000000 3.410482
450: 1.317038 -3.080034 3.958507 0.000112 0.002126 0.000000 3.410478
460: 1.317056 -3.080011 3.958507 0.000112 0.002120 0.000000 3.410475
470: 1.317094 -3.079996 3.958507 0.000112 0.002118 0.000000 3.410487
480: 1.317052 -3.079887 3.958507 0.000111 0.002115 0.000000 3.410482
490: 1.317040 -3.079826 3.958507 0.000110 0.002111 0.000000 3.410488
500: 1.317007 -3.079736 3.958507 0.000110 0.002097 0.000000 3.410487
Calculating covariance matrix
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ loading into symengine environment...
→ pruning branches (`if`/`else`) of saem model...
✔ done
→ finding duplicate expressions in saem predOnly model 0...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 1...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem predOnly model 1...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 2...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
→ Calculating residuals/tables
✔ done
→ compress origData in nlmixr2 object, save 7056
→ compress phiM in nlmixr2 object, save 156832
→ compress parHistData in nlmixr2 object, save 16936
→ compress saem0 in nlmixr2 object, save 32920
> print(fit2)
── nlmixr² SAEM OBJF by FOCEi approximation ──
Gaussian/Laplacian Likelihoods: AIC(fit2) or fit2$objf etc.
FOCEi CWRES & Likelihoods: addCwres(fit2)
── Time (sec fit2$time): ──
setup covariance saem table compress other
elapsed 0.000843 0.005003 2.68 0.085 0.019 0.752154
── Population Parameters (fit2$parFixed or fit2$parFixedDf): ──
Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
tka Ka 1.32 0.451 34.2 3.73 (1.54, 9.03) 1.05 95.1%
tcl Cl -3.08 0.748 24.3 0.046 (0.0106, 0.199) 4.58 94.9%
tv V 3.96 0.0741 1.87 52.4 (45.3, 60.6) 0.000120 97.0%
add.sd 3.41 3.41
Covariance Type (fit2$covMethod): linFim
No correlations in between subject variability (BSV) matrix
Full BSV covariance (fit2$omega) or correlation (fit2$omegaR; diagonals=SDs)
Distribution stats (mean/skewness/kurtosis/p-value) available in fit2$shrink
Censoring (fit2$censInformation): No censoring
── Fit Data (object fit2 is a modified tibble): ──
# A tibble: 132 × 20
ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v cp depot center ka cl v tad dosenum WT
<fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 0 0.74 0 0.74 0 0.74 0.217 0.000423 -0.00121 0 0 320. 0 3.73 17517. 52.4 0 1 79.6
2 1 0.25 2.84 0.0271 2.81 0.0271 2.81 0.825 0.000423 -0.00121 0 0.0271 126. 1.42 3.73 17517. 52.4 0.25 1 79.6
3 1 0.57 6.57 0.00820 6.56 0.00821 6.56 1.92 0.000423 -0.00121 0 0.00821 38.1 0.430 3.73 17517. 52.4 0.57 1 79.6
Test by writing fixed values in the model block
> library(nlmixr2)
> theo_sd2<-theo_sd
> theo_sd2$lwt<-log(theo_sd2$WT/70)
> ## The basic model consists of an ini block that has initial estimates
> one.compartment <- function() {
+ ini({
+ tka <- log(1.57); label("Ka")
+ tcl <- log(2.72); label("Cl")
+ tv <- log(31.5); label("V")
+
+ eta.ka ~ 0.6
+ eta.cl ~ 0.3
+ eta.v ~ 0.1
+ add.sd <- 0.7
+ })
+ # and a model block with the error specification and model specification
+ model({
+ covwt<-100;
+ ka <- exp(tka + eta.ka)
+ cl <- exp(tcl + eta.cl + covwt*lwt)
+ v <- exp(tv + eta.v)
+ d/dt(depot) <- -ka * depot
+ d/dt(center) <- ka * depot - cl / v * center
+ cp <- center / v
+ cp ~ add(add.sd)
+ })
+ }
>
> ## The fit is performed by the function nlmixr/nlmixr2 specifying the model, data and estimate
> fit3<- nlmixr2(one.compartment, theo_sd2, est="saem", saemControl(print=10,seed = 1234))
→ loading into symengine environment...
→ pruning branches (`if`/`else`) of saem model...
✔ done
→ finding duplicate expressions in saem model...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem model...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
ℹ calculate uninformed etas
ℹ done
params: tka tcl tv V(eta.ka) V(eta.cl) V(eta.v) add.sd
001: 0.477828 1.193181 3.540865 0.670440 0.285000 0.095000 2.481478
010: 0.292654 1.028709 3.448012 0.422544 0.179621 0.059874 0.933184
020: 0.323250 1.034565 3.450468 0.283349 0.107546 0.035849 0.916087
030: 0.246572 1.054546 3.427015 0.215741 0.073231 0.021464 0.941825
040: 0.318623 1.016192 3.446312 0.203425 0.102279 0.013531 0.930611
050: 0.306921 1.035205 3.419254 0.178160 0.094455 0.009659 0.949698
060: 0.302847 1.034192 3.439183 0.190345 0.088840 0.009287 0.930402
070: 0.158354 1.087708 3.392367 0.163758 0.095002 0.006958 0.962190
080: 0.206919 1.056692 3.384905 0.175308 0.106538 0.006629 0.938224
090: 0.191478 1.090443 3.387805 0.173272 0.104424 0.004217 1.012654
100: 0.180740 1.061290 3.386322 0.198120 0.100856 0.002525 0.986812
110: 0.226212 1.059082 3.397850 0.131918 0.094245 0.001512 0.978183
120: 0.222577 1.046371 3.394035 0.119858 0.104147 0.002234 0.999379
130: 0.277805 1.022893 3.411632 0.171890 0.099733 0.002498 0.986380
140: 0.283586 1.039799 3.424476 0.167609 0.092812 0.002218 0.997360
150: 0.274284 1.043454 3.414263 0.168871 0.097009 0.001328 0.982148
160: 0.230462 1.026334 3.420953 0.131201 0.087466 0.000195 0.979443
170: 0.273266 1.075862 3.420299 0.131135 0.103608 0.000009 1.001441
180: 0.245780 1.063286 3.419879 0.128046 0.099804 0.000001 1.006117
190: 0.216001 1.034339 3.420092 0.114310 0.118541 0.000000 1.003514
200: 0.253627 1.049436 3.420128 0.174959 0.105073 0.000000 1.015432
210: 0.255694 1.056685 3.420090 0.136155 0.106506 0.000000 0.999045
220: 0.260126 1.063046 3.420106 0.139685 0.105550 0.000000 0.997727
230: 0.257461 1.066594 3.420107 0.134702 0.105844 0.000000 1.000530
240: 0.259031 1.067806 3.420104 0.136643 0.104647 0.000000 1.001298
250: 0.258266 1.066537 3.420109 0.136939 0.105046 0.000000 1.000931
260: 0.261152 1.067458 3.420108 0.140161 0.104162 0.000000 1.001839
270: 0.260442 1.066688 3.420105 0.139443 0.104525 0.000000 1.002944
280: 0.260585 1.064669 3.420105 0.139201 0.103765 0.000000 1.003522
290: 0.258679 1.063775 3.420106 0.138193 0.104272 0.000000 1.003738
300: 0.260142 1.063758 3.420104 0.136631 0.103811 0.000000 1.005334
310: 0.259159 1.062201 3.420104 0.136082 0.104012 0.000000 1.005397
320: 0.258316 1.062221 3.420103 0.136665 0.104797 0.000000 1.005239
330: 0.258113 1.061457 3.420102 0.136990 0.104696 0.000000 1.005648
340: 0.257967 1.061214 3.420100 0.136521 0.104603 0.000000 1.005232
350: 0.258260 1.060210 3.420102 0.135753 0.104737 0.000000 1.005202
360: 0.258343 1.060389 3.420103 0.135007 0.104337 0.000000 1.006109
370: 0.258453 1.060952 3.420103 0.134979 0.103830 0.000000 1.006387
380: 0.259189 1.061577 3.420102 0.135175 0.103788 0.000000 1.006229
390: 0.258053 1.062530 3.420102 0.134875 0.103206 0.000000 1.006215
400: 0.258103 1.062867 3.420102 0.134570 0.102965 0.000000 1.005832
410: 0.258408 1.063553 3.420102 0.134745 0.103117 0.000000 1.005668
420: 0.258646 1.063520 3.420101 0.134828 0.102980 0.000000 1.005966
430: 0.259338 1.063837 3.420101 0.134394 0.102878 0.000000 1.005849
440: 0.259558 1.063128 3.420101 0.133850 0.103012 0.000000 1.005851
450: 0.259898 1.063583 3.420101 0.134048 0.103276 0.000000 1.005723
460: 0.260194 1.063084 3.420100 0.133697 0.103539 0.000000 1.005708
470: 0.260328 1.063400 3.420101 0.133547 0.103554 0.000000 1.005936
480: 0.259993 1.063039 3.420100 0.133441 0.103508 0.000000 1.005716
490: 0.260034 1.063393 3.420100 0.133158 0.103441 0.000000 1.006034
500: 0.259039 1.063518 3.420101 0.133086 0.103074 0.000000 1.006433
Calculating covariance matrix
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ loading into symengine environment...
→ pruning branches (`if`/`else`) of saem model...
✔ done
→ finding duplicate expressions in saem predOnly model 0...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 1...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ optimizing duplicate expressions in saem predOnly model 1...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
→ finding duplicate expressions in saem predOnly model 2...
[====|====|====|====|====|====|====|====|====|====] 0:00:00
✔ done
using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
→ Calculating residuals/tables
✔ done
→ compress origData in nlmixr2 object, save 7056
→ compress phiM in nlmixr2 object, save 96968
→ compress parHistData in nlmixr2 object, save 15032
→ compress saem0 in nlmixr2 object, save 30848
> print(fit3)
── nlmixr² SAEM OBJF by FOCEi approximation ──
Gaussian/Laplacian Likelihoods: AIC(fit3) or fit3$objf etc.
FOCEi CWRES & Likelihoods: addCwres(fit3)
── Time (sec fit3$time): ──
setup covariance saem table compress other
elapsed 0.000669 0.005003 1.594 0.072 0.024 0.748328
── Population Parameters (fit3$parFixed or fit3$parFixedDf): ──
Parameter Est. SE %RSE Back-transformed(95%CI) BSV(CV%) Shrink(SD)%
tka Ka 0.259 0.132 51.1 1.3 (1, 1.68) 37.7 5.59%
tcl Cl 1.06 0.104 9.81 2.9 (2.36, 3.55) 33.0 3.59%
tv V 3.42 0.0353 1.03 30.6 (28.5, 32.8) 0.0140 93.7%
add.sd 1.01 1.01
Covariance Type (fit3$covMethod): linFim
No correlations in between subject variability (BSV) matrix
Full BSV covariance (fit3$omega) or correlation (fit3$omegaR; diagonals=SDs)
Distribution stats (mean/skewness/kurtosis/p-value) available in fit3$shrink
Censoring (fit3$censInformation): No censoring
── Fit Data (object fit3 is a modified tibble): ──
# A tibble: 132 × 20
ID TIME DV PRED RES IPRED IRES IWRES eta.ka eta.cl eta.v cp depot center ka cl v tad dosenum lwt
<fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 0 0.74 0 0.74 0 0.74 0.735 0.306 -0.560 0 0 320. 0 1.76 631253. 30.6 0 1 0.129
2 1 0.25 2.84 0.000271 2.84 0.000575 2.84 2.82 0.306 -0.560 0 0.000575 206. 0.0176 1.76 631253. 30.6 0.25 1 0.129
3 1 0.57 6.57 0.000179 6.57 0.000327 6.57 6.53 0.306 -0.560 0 0.000327 117. 0.0100 1.76 631253. 30.6 0.57 1 0.129
# ℹ 129 more rows
# ℹ Use `print(n = ...)` to see more rows
Ok. I will look into this a bit more.
In Test 1 the model is correct, and the data are correct
Browse[1]> summary(attr(model$saem_mod, "rx"))
rxode2 2.1.3 model named rx_b349f90a5826c36de418ea2ed3275a7b model (✔ ready).
DLL: /tmp/RtmppBWijc/rxode2/rx_b349f90a5826c36de418ea2ed3275a7b__.rxd/rx_b349f90a5826c36de418ea2ed3275a7b_.so
NULL
Calculated Variables:
[1] "rx_pred_"
── rxode2 Model Syntax ──
rxode2({
param(tka, tcl, tv, lwt)
cmt(depot)
cmt(center)
rx_expr_0 ~ exp(tka)
d/dt(depot) = -rx_expr_0 * depot
d/dt(center) = rx_expr_0 * depot - exp(0.01 * lwt + tcl -
tv) * center
rx_pred_ = exp(-tv) * center
cmt(cp)
dvid(3)
})
Browse[1]> summary(data$data)
ID TIME DV lwt
Min. : 1.00 Min. : 0.000 Min. : 0.000 Min. :-0.248461
1st Qu.: 3.75 1st Qu.: 0.595 1st Qu.: 2.877 1st Qu.:-0.096674
Median : 6.50 Median : 3.530 Median : 5.275 Median : 0.007117
Mean : 6.50 Mean : 5.895 Mean : 4.960 Mean :-0.014581
3rd Qu.: 9.25 3rd Qu.: 9.000 3rd Qu.: 7.140 3rd Qu.: 0.060514
Max. :12.00 Max. :24.650 Max. :11.400 Max. : 0.210492
Test 2:
Browse[1]> summary(attr(model$saem_mod, "rx"))
rxode2 2.1.3 model named rx_99295d5b043d911bb7fe0bc81d03f48e model (✔ ready).
DLL: /tmp/RtmppBWijc/rxode2/rx_99295d5b043d911bb7fe0bc81d03f48e__.rxd/rx_99295d5b043d911bb7fe0bc81d03f48e_.so
NULL
Calculated Variables:
[1] "rx_pred_"
── rxode2 Model Syntax ──
rxode2({
param(tka, tcl, tv, lwt)
cmt(depot)
cmt(center)
rx_expr_0 ~ exp(tka)
d/dt(depot) = -rx_expr_0 * depot
d/dt(center) = rx_expr_0 * depot - exp(0.75 * lwt + tcl -
tv) * center
rx_pred_ = exp(-tv) * center
cmt(cp)
dvid(3)
})
Browse[1]> summary(data$data)
ID TIME DV lwt
Min. : 1.00 Min. : 0.000 Min. : 0.000 Min. :-0.248461
1st Qu.: 3.75 1st Qu.: 0.595 1st Qu.: 2.877 1st Qu.:-0.096674
Median : 6.50 Median : 3.530 Median : 5.275 Median : 0.007117
Mean : 6.50 Mean : 5.895 Mean : 4.960 Mean :-0.014581
3rd Qu.: 9.25 3rd Qu.: 9.000 3rd Qu.: 7.140 3rd Qu.: 0.060514
Max. :12.00 Max. :24.650 Max. :11.400 Max. : 0.210492
Browse[1]> summary(attr(model$saem_mod, "rx"))
rxode2 2.1.3 model named rx_d16f7a3ffa6387512bd32817cd981e1d model (✔ ready).
DLL: /tmp/RtmppBWijc/rxode2/rx_d16f7a3ffa6387512bd32817cd981e1d__.rxd/rx_d16f7a3ffa6387512bd32817cd981e1d_.so
NULL
Calculated Variables:
[1] "rx_pred_"
── rxode2 Model Syntax ──
rxode2({
param(tka, tcl, tv, lwt)
cmt(depot)
cmt(center)
rx_expr_0 ~ exp(tka)
d/dt(depot) = -rx_expr_0 * depot
d/dt(center) = rx_expr_0 * depot - exp(100 * lwt + tcl -
tv) * center
rx_pred_ = exp(-tv) * center
cmt(cp)
dvid(3)
})
Browse[1]> summary(data$data)
ID TIME DV lwt
Min. : 1.00 Min. : 0.000 Min. : 0.000 Min. :-0.248461
1st Qu.: 3.75 1st Qu.: 0.595 1st Qu.: 2.877 1st Qu.:-0.096674
Median : 6.50 Median : 3.530 Median : 5.275 Median : 0.007117
Mean : 6.50 Mean : 5.895 Mean : 4.960 Mean :-0.014581
3rd Qu.: 9.25 3rd Qu.: 9.000 3rd Qu.: 7.140 3rd Qu.: 0.060514
Max. :12.00 Max. :24.650 Max. :11.400 Max. : 0.210492
Since this is not to do with the model but how saem
is run, I am transferring this to nlmixr2est
This was fixed in b8c7292f9f3310bfcada5e331a008820291e0d6c
Thank you @ZhonghuiHuang for reporting.
Here is the reprex for the fix; You can see in the ka
traceplots that the parameter search does not proceed identically. You can also see the final population parameter estimates are in fact different.
library(nlmixr2)
#> Loading required package: nlmixr2data
theo_sd2 <- nlmixr2data::theo_sd
theo_sd2$lwt<-log(theo_sd2$WT/70)
# The basic model consists of an ini block that has initial estimates
one.compartment <- function() {
ini({
tka <- log(1.57); label("Ka")
tcl <- log(2.72); label("Cl")
tv <- log(31.5); label("V")
covwt<- fix(0.01)
eta.ka ~ 0.6
eta.cl ~ 0.3
eta.v ~ 0.1
add.sd <- 0.7
})
model({
ka <- exp(tka + eta.ka)
cl <- exp(tcl + eta.cl + covwt*lwt)
v <- exp(tv + eta.v)
d/dt(depot) <- -ka * depot
d/dt(center) <- ka * depot - cl / v * center
cp <- center / v
cp ~ add(add.sd)
})
}
fit0 <- nlmixr2(one.compartment, theo_sd2, est="saem",
saemControl(print=0,seed = 1234))
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> ℹ calculate uninformed etas
#> ℹ done
#> rxode2 2.1.3 using 8 threads (see ?getRxThreads)
#> no cache: create with `rxCreateCache()`
#> Calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem predOnly model 0...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 2...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 7056
#> → compress phiM in nlmixr2 object, save 61968
#> → compress parHistData in nlmixr2 object, save 13872
#> → compress saem0 in nlmixr2 object, save 29488
fit1 <- one.compartment %>%
ini({covwt<- fix(0.75)}) %>%
nlmixr2(., theo_sd2, est="saem",
saemControl(print=0,seed = 1234))
#> Warning: trying to fix 'covwt', but already fixed
#> ℹ change initial estimate of `covwt` to `0.75`
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> ℹ calculate uninformed etas
#> ℹ done
#> Calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem predOnly model 0...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 2...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 7056
#> → compress phiM in nlmixr2 object, save 62664
#> → compress parHistData in nlmixr2 object, save 14008
#> → compress saem0 in nlmixr2 object, save 21464
fit2 <- one.compartment %>%
ini({covwt<- fix(100)}) %>%
nlmixr2(., theo_sd2, est="saem",
saemControl(print=0,seed = 1234))
#> Warning: trying to fix 'covwt', but already fixed
#> ℹ change initial estimate of `covwt` to `100`
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem model...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> ℹ calculate uninformed etas
#> ℹ done
#> Calculating covariance matrix
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → loading into symengine environment...
#> → pruning branches (`if`/`else`) of saem model...
#> ✔ done
#> → finding duplicate expressions in saem predOnly model 0...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → optimizing duplicate expressions in saem predOnly model 1...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> → finding duplicate expressions in saem predOnly model 2...
#> [====|====|====|====|====|====|====|====|====|====] 0:00:00
#> ✔ done
#> using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
#> → Calculating residuals/tables
#> ✔ done
#> → compress origData in nlmixr2 object, save 7056
#> → compress phiM in nlmixr2 object, save 156832
#> → compress parHistData in nlmixr2 object, save 16952
#> → compress saem0 in nlmixr2 object, save 24608
traceplot(fit0)
traceplot(fit1)
traceplot(fit2)
print(fit0$theta)
#> tka tcl tv covwt add.sd
#> 0.4531826 1.0156547 3.4496090 0.0100000 0.6960903
print(fit1$theta)
#> tka tcl tv covwt add.sd
#> 0.4463475 1.0329945 3.4460929 0.7500000 0.6982099
print(fit2$theta)
#> tka tcl tv covwt add.sd
#> 1.317007 -3.079736 3.958507 100.000000 3.410487
Created on 2024-05-22 with reprex v2.1.0
Hi @mattfidler,
I tried to introduce covariate models with fixed power values by fix() function in the ini block, however, I find that the fix() function might not work if we use saem not focei, I attached my test results here by using the theo_sd dataset.
Test 1. Covariate model format: ( covwt<- fix(0.01) and use covwtlwt, where lwt = log(theo_sd2$WT/70)) by saem Test 2. Covariate model format: ( covwt<- fix(0.75) and use covwtlwt, where lwt = log(theo_sd2$WT/70)) by saem Test 3. Covariate model format: ( covwt<- fix(100) and use covwt*lwt, where lwt = log(theo_sd2$WT/70)) by saem
Test 4. Covariate model format: ( covwt<- fix(0.01) and use covwtlwt, where lwt = log(theo_sd2$WT/70)) by focei Test 5. Covariate model format: ( covwt<- fix(0.75) and use covwtlwt, where lwt = log(theo_sd2$WT/70)) by focei Test 6. Covariate model format: ( covwt<- fix(100) and use covwt*lwt, where lwt = log(theo_sd2$WT/70)) by focei
Test1-3 shared totally same parameter estimates in each iteration, and share the same final parameter estimate results. But they shouldnt be same given the different setting of power, especially the first and third are extreme values.
However, apparently, focei can work. When focei was used in test 4, test 5 and test 6, we can see the change of parameter estimates between iterations and the model estimate results are also different.
So, if we would like to introduce a fixed allometric scalling with a power of 0.75 and 1 and also choose saem, currently, my option is to write the equation directly in the model block, e.g.,
cl <- exp(tcl + eta.cl + 0.75 log(WT/70)) cl<-exp(tcl + eta.cl) (WT/70) ^0.75
(BTW, cl=exp(tcl+eta.cl+lwt*0.75),lwt = log(theo_sd2$WT/70)), also doesnt work for me) But still hope the fix function can work then can see the fixed values in the nlmixr2 output.
Test1. Use fix() function to introduce a fixed covariate model, extreme power 0.01
Test2. Use fix() function to introduce a fixed covariate model, 0.75
Test 3. Use fix() function to introduce a fixed covariate model, use an extreme value, 100
Test4. Use fix() function to introduce a fixed covariate model, run by FOCEI
Test5. Use fix() function to introduce a fixed covariate model, run by FOCEI
Test6. Use fix() function to introduce a fixed covariate model with a extreme power 100, run by FOCEI