Closed mat194 closed 1 month ago
Hi Matteo,
At this point, this is expected behavior. In result$model
, the covariate values are both available in the dataset and passed as $params
parameters to rxode2. However, only the values in the first row of the data set are passed as parameters by poso_simu_pop()
. Two situations can be seen:
$params
(this is the case for WT, or DIAL in your example)When you extend the number of observations with results$model$time <- seq(0, 48, by = 0.1)
, rxode2 has no CLCREAT values to use for the additional times. In this case, the CLCREAT value of $params
is used, i.e. the initial value of the dataset.
To work around this problem, the interpolated values of the covariates can be calculated separately as in poso_estim_map()
, using the internal function posologyr:::extrapol_cov()
:
if(return_model){
et_poso <- rxode2::as.et(object$tdm_data)
et_poso$clearSampling()
et_poso$add.sampling(seq(dat$TIME[1],
dat$TIME[length(dat$TIME)]+1,
by=.1))
--- snip---
if(!no_covariates){
covar_mat <- sapply(object$covariates,FUN=extrapol_cov,dat=dat,
covar=object$covariates,
interpol_approx="constant",
f=ifelse(object$interpolation == "nocb",1,0),
event_table=et_poso)
et_poso <- cbind(et_poso,covar_mat)
}
estim_map$model <- rxode2::rxSolve(object$ppk_model,et_poso,
c(object$theta,estim_map$eta),
covsInterpolation = interpolation)
estim_map$event <- data.table::data.table(et_poso)
}
Currently, only poso_estim_map()
does this. It would be sensible to extend this behavior to the other estimation functions (including poso_estim_sir()
).
Note that if the initial CLCREAT value had not been passed to rxode2 as a parameter by poso_simu_pop()
, the line results$model$time <- seq(0, 48, by = 0.1)
would have failed with a warning that CLCREAT was missing, since rxode2 does not interpolate covariate values between two observations in this case.
The previous commit 2de19d6 broke the workflow described in the a_priori_dosing vignette, which relies on having all covariates as $params
in the model.
Edit: fixed in ba7565f
Now poso_simu_pop()
outputs a model with extrapolated values of all the covariates, from the first to the last event recorded in the dataset. This model can be easily plotted.
When expanding (or changing in any way) the time sequence, the models falls back to the covariate values in $params
(i.e. the first recorded values).
Hi Matteo,
I had to revert the changes made to poso_simu_pop()
as they were causing several issues. However, the new function poso_replace_et()
enables updating a model with events from a new rxode2 event table, while accounting for and interpolating any covariates or inter-occasion variability.
You can now add doses or observations without losing information about covariates:
# convert your dataset to an event table
et_vanco <- rxode2::as.et(df_patient)
# change it to your needs
new_scenario<- et_vanco$add.sampling(seq(0, 48, by = 0.1))
# update the model from poso_simu_pop() using this new scenario
poso_replace_et(target_model = results$model,
prior_model = mod_vancomycin_Goti2018,
event_table = new_scenario)
Got it! Read the tread on the github. All clear!
Dott Matteo Morra Specializzando Malattie Infettive UNIVR
Il giorno gio 12 set 2024 alle ore 13:52 Cyril Leven < @.***> ha scritto:
Hi Matteo, I had to revert the changes made to poso_simu_pop() as they were causing several issues. However, the new function poso_replace_et() enables updating a model with events from a new rxode2 event table, while accounting for and interpolating any covariates or inter-occasion variability.
You can now add doses or observations without losing information about covariates:
convert your dataset to an event tableet_vanco <- rxode2::as.et(df_patient)
change it to your needsnew_scenario<- et_vanco$add.sampling(seq(0, 48, by = 0.1))
update the model from poso_simu_pop() using this new scenario
poso_replace_et(target_model = results$model, prior_model = mod_vancomycin_Goti2018, event_table = new_scenario)
— Reply to this email directly, view it on GitHub https://github.com/levenc/posologyr/issues/53#issuecomment-2346080279, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVLOAKF3QPUVZDYVY2ROAFTZWF6ARAVCNFSM6AAAAABNDK6F3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBWGA4DAMRXHE . You are receiving this because you authored the thread.Message ID: @.***>
Hi Cyril,
Here the code and the results I get using the Goti model
The values of CLCREAT in the result$model are as expected
With an appropriate number of estimated parameters is
But when the time sequence is expanded the first only the first values are carried forward
As the result is