FelicienLL / mapbayr

Easy Maximum A Posteriori Bayesian Estimation of PK parameters in R.
21 stars 2 forks source link

error code #188

Closed PLLS closed 1 year ago

PLLS commented 1 year ago

Hi! I am trying to run "mapbayr" to perform maximum a posteriori Bayesian estimation. To begin with, I am practicing with the example at:

https://github.com/FelicienLL/mapbayr/blob/develop/README.md

As I try to run: my_est <- mapbayest(my_model, data = my_data)

I can't keep going on as I find the following error: Error in unique.default(x, nmax = nmax) : unique() applies only to vectors

The following versions are installed in my PC:

R 4.0.5 mapbayr (0.9.0) mrgsolve (1.0.6) (Rtools is also installed) And also: dplyr (1.1.0), ggplot2 (3.4.1), magrittr (2.0.3), progress (1.2.2), purrr (1.01), rlang (1.0.6), stringr (1.5.0), tidyr (1.3.0).

Has anyone had the same problem? how did you solve it?

Any help would be much appreciated!! Thank you very much! Pilar

FelicienLL commented 1 year ago

Hi @PLLS, Hard to see what is wrong from here, this error message is really unspecific. Could you try to post a reprex (https://reprex.tidyverse.org/) so that I'm sure of what is going on? A reprex is a self-contained bit of code that I can copy and paste to make sure that I execute the exact same code as you do (i.e. so that I'm sure of what are the objects my_model and my_data that you are using). Thanks

PLLS commented 1 year ago

Hi Felicien,

I send the reprex in case it can be of help.

library(mapbayr)
#> 
#> Attaching package: 'mapbayr'
#> The following object is masked from 'package:stats':
#> 
#>     filter
library(mrgsolve)
#> 
#> Attaching package: 'mrgsolve'
#> 
#> The following object is masked from 'package:stats':
#> 
#>     filter
code <- "
$PARAM @annotated
TVCL:  0.9 : Clearance
TVV1: 10.0 : Central volume
V2  : 10.0 : Peripheral volume of distribution
Q   :  1.0 : Intercompartmental clearance

ETA1: 0 : Clearance (L/h)
ETA2: 0 : Central volume (L)

$PARAM @annotated @covariates
BW : 70 : Body weight (kg)

$OMEGA 0.3 0.3
$SIGMA
0.05 // proportional
0.1 // additive

$CMT @annotated
CENT  : Central compartment (mg/L)[ADM, OBS]
PERIPH: Peripheral compartment ()

$TABLE
double DV = (CENT/V1) *(1 + EPS(1)) + EPS(2);

$MAIN
double CL = TVCL * exp(ETA1 + ETA(1)) * pow(BW / 70, 1.2) ;
double V1 = TVV1 * exp(ETA2 + ETA(2)) ;
double K12 = Q / V1  ;
double K21 = Q / V2  ;
double K10 = CL / V1 ;

$ODE
dxdt_CENT   =  K21 * PERIPH - (K10 + K12) * CENT ;
dxdt_PERIPH =  K12 * CENT - K21 * PERIPH ;

$CAPTURE DV CL
"
my_model <- mcode("Example_model", code)
#> Building Example_model ...
#> done.
my_data <- data.frame(ID = 1, time = c(0,6,15,24), evid = c(1, rep(0,3)), cmt = 1, amt = c(100, rep(0,3)), 
                      rate = c(20, rep(0,3)), DV = c(NA, 3.9, 1.1, 2), mdv = c(1,0,0,1), BW = 90)
my_est <- mapbayest(my_model, data = my_data)
#> Error in unique.default(x, nmax = nmax): unique() puede ser aplicada solamente a vectores

Created on 2023-02-28 with reprex v2.0.2

Thank you very much !! Pilar

FelicienLL commented 1 year ago

Hi, sorry I still can't reproduce this. Could you run sessionInfo() ?

FelicienLL commented 1 year ago

I see that you are working with R 4.0.5. Although I cannot see a specific reason why this version of R would not work, you may want to try a more recent version of R. Could you try an update to R 4.2.2 for instance ? Thanks.

PLLS commented 1 year ago

Hi Felicien,

Finally I installed R.42.2 and reinstalled the proper rtools version and it works properly! Ready to run mapbayest with my model! Thanks a lot Pilar

FelicienLL commented 1 year ago

Glad to hear that. Let me know if you need help for your project. Félicien