Skip to content

Instantly share code, notes, and snippets.

@batpigandme
Last active May 15, 2018 21:28
Show Gist options
  • Select an option

  • Save batpigandme/4f4b9403572bcefc342eee2658ce34aa to your computer and use it in GitHub Desktop.

Select an option

Save batpigandme/4f4b9403572bcefc342eee2658ce34aa to your computer and use it in GitHub Desktop.
PopED traceback

PopED

traceback

16: stop("Discrete value supplied to continuous scale", call. = FALSE)
15: scales::train_continuous(x, self$range)
14: f(..., self = self)
13: self$range$train(x)
12: f(..., self = self)
11: self$train(df[[aesthetic]])
10: f(..., self = self)
9: scale$train_df(df = df)
8: FUN(X[[i]], ...)
7: lapply(scales$scales, function(scale) scale$train_df(df = df))
6: FUN(X[[i]], ...)
5: lapply(data, scales_train_df, scales = npscales)
4: ggplot_build.ggplot(x)
3: ggplot_build(x)
2: print.ggplot(x)
1: function (x, ...) 
   UseMethod("print")(x)

reprex

system.file("examples", package="PopED")
#> [1] "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/PopED/examples"
library(PopED)
set.seed(1234)
ff <- function(model_switch,xt,parameters,poped.db){
  with(as.list(parameters),{
    N = floor(xt/TAU)+1
    y=(DOSE*Favail/V)*(KA/(KA - CL/V)) * 
      (exp(-CL/V * (xt - (N - 1) * TAU)) * (1 - exp(-N * CL/V * TAU))/(1 - exp(-CL/V * TAU)) - 
         exp(-KA * (xt - (N - 1) * TAU)) * (1 - exp(-N * KA * TAU))/(1 - exp(-KA * TAU)))  
    return(list( y=y,poped.db=poped.db))
  })
}
sfg <- function(x,a,bpop,b,bocc){
  parameters=c( V=bpop[1]*exp(b[1]),
                KA=bpop[2]*exp(b[2]),
                CL=bpop[3]*exp(b[3]),
                Favail=bpop[4],
                DOSE=a[1],
                TAU=a[2])
}
feps <- function(model_switch,xt,parameters,epsi,poped.db){
  returnArgs <- ff(model_switch,xt,parameters,poped.db) 
  y <- returnArgs[[1]]
  poped.db <- returnArgs[[2]]
  
  y = y*(1+epsi[,1])+epsi[,2]
  
  return(list(y=y,poped.db=poped.db)) 
}
poped.db <- create.poped.database(ff_fun=ff,
                                  fg_fun=sfg,
                                  fError_fun=feps,
                                  bpop=c(V=72.8,KA=0.25,CL=3.75,Favail=0.9), 
                                  notfixed_bpop=c(1,1,1,0),
                                  d=c(V=0.09,KA=0.09,CL=0.25^2), 
                                  sigma=c(0.04,5e-6),
                                  notfixed_sigma=c(1,0),
                                  m=2,
                                  groupsize=20,
                                  a=list(c(DOSE=20,TAU=24),c(DOSE=40, TAU=24)),
                                  maxa=c(DOSE=200,TAU=24),
                                  mina=c(DOSE=0,TAU=24),
                                  xt=c( 1,2,8,240,245),
                                  minxt=c(0,0,0,240,240),
                                  maxxt=c(10,10,10,248,248),
                                  bUseGrouped_xt=TRUE)
plot_model_prediction(poped.db, model_num_points=500, IPRED=T)
#> Don't know how to automatically pick scale for object of type NULL. Defaulting to continuous.
#> Error: Discrete value supplied to continuous scale

Example from docs works...

## Warfarin example from software comparison in:
## Nyberg et al., "Methods and software tools for design evaluation 
##   for population pharmacokinetics-pharmacodynamics studies", 
##   Br. J. Clin. Pharm., 2014. 

library(PopED)

## find the parameters that are needed to define from the structural model ff.PK.1.comp.oral.md.CL

## -- parameter definition function 
## -- names match parameters in function ff
sfg <- function(x,a,bpop,b,bocc){
  parameters=c(CL=bpop[1]*exp(b[1]),
               V=bpop[2]*exp(b[2]),
               KA=bpop[3]*exp(b[3]),
               Favail=bpop[4],
               DOSE=a[1])
  return(parameters) 
}

## -- Define initial design  and design space
poped.db <- create.poped.database(ff_file="ff.PK.1.comp.oral.sd.CL",
                                  fg_file="sfg",
                                  fError_file="feps.prop",
                                  bpop=c(CL=0.15, V=8, KA=1.0, Favail=1), 
                                  notfixed_bpop=c(1,1,1,0),
                                  d=c(CL=0.07, V=0.02, KA=0.6), 
                                  sigma=0.01,
                                  groupsize=32,
                                  xt=c( 0.5,1,2,6,24,36,72,120),
                                  minxt=0,
                                  maxxt=120,
                                  a=70)


plot_model_prediction(poped.db,IPRED=TRUE,DV=TRUE)
#> Don't know how to automatically pick scale for object of type NULL. Defaulting to continuous.

Created on 2018-05-15 by the reprex package (v0.2.0).

Created on 2018-05-15 by the reprex package (v0.2.0).

`str(pop.db)`
List of 5
$ settings :List of 80
..$ poped_version :Classes 'package_version', 'numeric_version' hidden list of 1
.. ..$ : int [1:3] 0 3 2
..$ bLHS : num 1
..$ d_switch : num 1
..$ iApproximationMethod : num 0
..$ iFOCENumInd : num 1
..$ bUseRandomSearch : logi TRUE
..$ bUseStochasticGradient : logi TRUE
..$ bUseLineSearch : logi TRUE
..$ bUseExchangeAlgorithm : logi FALSE
..$ bUseBFGSMinimizer : logi FALSE
..$ iEDCalculationType : num 0
..$ BFGSConvergenceCriteriaMinStep : num 1e-08
..$ BFGSProjectedGradientTol : num 1e-04
..$ BFGSTolerancef : num 0.001
..$ BFGSToleranceg : num 0.9
..$ BFGSTolerancex : num 0.1
..$ parallel :List of 15
.. ..$ iCompileOption : num -1
.. ..$ strAdditionalMCCCompilerDependencies: chr ""
.. ..$ iUseParallelMethod : num 1
.. ..$ strExecuteName : chr "calc_fim.exe"
.. ..$ iNumProcesses : num 2
.. ..$ iNumChunkDesignEvals : num -2
.. ..$ strMatFileInputPrefix : chr "parallel_input"
.. ..$ strMatFileOutputPrefix : chr "parallel_output"
.. ..$ strExtraRunOptions : chr ""
.. ..$ dPollResultTime : num 0.1
.. ..$ strFunctionInputName : chr "function_input"
.. ..$ bParallelRS : logi FALSE
.. ..$ bParallelSG : logi FALSE
.. ..$ bParallelLS : logi FALSE
.. ..$ bParallelMFEA : logi FALSE
..$ hm1 : num 1e-05
..$ hlf : num 1e-05
..$ hlg : num 1e-05
..$ hm2 : num 1e-05
..$ hgd : num 1e-05
..$ hle : num 1e-05
..$ AbsTol : num 1e-06
..$ RelTol : num 1e-06
..$ bUseMemorySolver : logi FALSE
..$ solved_solutions : list()
.. ..- attr(*, "dim")= int [1:2] 0 0
..$ maxtime : num 248
..$ iFIMCalculationType : num 1
..$ rsit : num 300
..$ sgit : num 150
..$ intrsit : num 250
..$ intsgit : num 50
..$ maxrsnullit : num 50
..$ convergence_eps : num 1e-08
..$ rslxt : num 10
..$ rsla : num 10
..$ cfaxt : num 0.001
..$ cfaa : num 0.001
..$ EACriteria : num 1
..$ EAStepSize : num 0.01
..$ EANumPoints : logi FALSE
..$ EAConvergenceCriteria : num 1e-20
..$ ED_samp_size : num 45
..$ ED_diff_it : num 30
..$ ED_diff_percent : num 10
..$ ls_step_size : num 50
..$ ofv_calc_type : num 4
..$ iNumSearchIterationsIfNotLineSearch: num 1
..$ ourzero : num 1e-05
..$ rsit_output : num 5
..$ sgit_output : num 1
..$ ed_penalty_pointer : num[1, 0 ]
..$ modtit : chr "PopED model"
..$ exptit : chr "PopED model_exp$mat"
..$ opttit : chr "PopED model_opt$mat"
..$ bShowGraphs : logi FALSE
..$ use_logfile : logi FALSE
..$ output_file : chr "PopED_output_summary"
..$ output_function_file : chr "PopED_output_"
..$ optsw : num [1, 1:5] 0 0 0 0 0
..$ line_opta : num [1, 1:2] 1 1
..$ line_optx : num[1, 0 ]
..$ m1_switch : num 1
..$ m2_switch : num 1
..$ hle_switch : num 1
..$ gradff_switch : num 1
..$ gradfg_switch : num 1
..$ prior_fim : num[0 , 1]
..$ strIterationFileName : chr "PopED_current.R"
..$ user_data : list()
.. ..- attr(*, "dim")= int [1:2] 0 0
..$ bUseSecondOrder : logi FALSE
..$ bCalculateEBE : logi FALSE
..$ bGreedyGroupOpt : logi FALSE
..$ bEANoReplicates : logi FALSE
..$ run_file_pointer : num[1, 0 ]
..$ Engine :List of 2
.. ..$ Type : num 1
.. ..$ Version: chr "R version 3.4.3 (2017-11-30)"
..$ strOutputFilePath : chr "."
..$ strOutputFileName : chr "PopED_output_summary"
..$ strOutputFileExtension : chr ""
$ model :List of 5
..$ user_distribution_pointer: chr ""
..$ fg_pointer :function (x, a, bpop, b, bocc)
.. ..- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 8 10 1 8 1 1 10
.. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x1168fba30>
..$ auto_pointer : num[1, 0 ]
..$ ff_pointer :function (model_switch, xt, parameters, poped.db)
.. ..- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 7 9 1 7 1 1 9
.. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x1169c3ab0>
..$ ferror_pointer :function (model_switch, xt, parameters, epsi, poped.db)
.. ..- attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 9 9 1 9 1 1 9
.. .. .. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x11680d808>
$ design :List of 7
..$ xt : num [1:2, 1:5] 1 1 2 2 8 8 240 240 245 245
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:5] "obs_1" "obs_2" "obs_3" "obs_4" ...
..$ m : Named num 2
.. ..- attr(*, "names")= chr "n_grp"
..$ ni : int [1:2, 1] 5 5
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr "n_obs"
..$ model_switch: num [1:2, 1:5] 1 1 1 1 1 1 1 1 1 1
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:5] "obs_1" "obs_2" "obs_3" "obs_4" ...
..$ a : num [1:2, 1:2] 20 40 24 24
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:2] "DOSE" "TAU"
..$ groupsize : num [1:2, 1] 20 20
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr "n_id"
..$ x : num[1:2, 0 ]
$ design_space:List of 19
..$ maxa : num [1:2, 1:2] 200 200 24 24
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:2] "DOSE" "TAU"
..$ mina : num [1:2, 1:2] 0 0 24 24
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:2] "DOSE" "TAU"
..$ maxni : int [1:2, 1] 5 5
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr "n_obs"
..$ minni : int [1:2, 1] 5 5
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr "n_obs"
..$ maxtotni : int 10
..$ mintotni : int 10
..$ maxgroupsize : num [1:2, 1] 20 20
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr "n_id"
..$ mingroupsize : num [1:2, 1] 20 20
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr "n_id"
..$ maxtotgroupsize: num 40
..$ mintotgroupsize: num 40
..$ maxxt : num [1:2, 1:5] 10 10 10 10 10 10 248 248 248 248
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:5] "obs_1" "obs_2" "obs_3" "obs_4" ...
..$ minxt : num [1:2, 1:5] 1.0e-05 1.0e-05 1.0e-05 1.0e-05 1.0e-05 1.0e-05 2.4e+02 2.4e+02 2.4e+02 2.4e+02
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:5] "obs_1" "obs_2" "obs_3" "obs_4" ...
..$ bUseGrouped_a : logi FALSE
..$ bUseGrouped_xt : logi TRUE
..$ G_a : num [1:2, 1:2] 1 3 2 4
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:2] "DOSE" "TAU"
..$ G_xt : num [1:2, 1:5] 1 1 2 2 3 3 4 4 5 5
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "grp_1" "grp_2"
.. .. ..$ : chr [1:5] "obs_1" "obs_2" "obs_3" "obs_4" ...
..$ G_x : num[1:2, 0 ]
..$ bUseGrouped_x : logi FALSE
..$ discrete_x : list()
.. ..- attr(*, "dim")= int [1:2] 2 0
$ parameters :List of 22
..$ covdocc : num[1, 0 ]
..$ notfixed_covdocc : num[1, 0 ]
..$ notfixed_covsigma: num [1, 1] 0
..$ nbpop : num 4
..$ NumRanEff : num 3
..$ NumDocc : num 0
..$ NumOcc : num 0
..$ ng : int 6
..$ notfixed_docc : num[1, 0 ]
..$ notfixed_d : num [1, 1:3] 1 1 1
..$ notfixed_bpop : num [1:4] 1 1 1 0
..$ covd : num [1, 1:3] 0 0 0
..$ notfixed_covd : num [1, 1:3] 0 0 0
..$ b_global : num [1:3, 1] 0 0 0
..$ bocc_global :List of 1
.. ..$ : num[0 , 0 ]
.. ..- attr(*, "dim")= int [1:2] 1 1
..$ bpop : num [1:4, 1:3] 0 0 0 0 72.8 0.25 3.75 0.9 0 0 ...
..$ d : num [1:3, 1:3] 0 0 0 0.09 0.09 0.0625 0 0 0
..$ sigma : num [1:2, 1:2] 4e-02 0e+00 0e+00 5e-06
..$ docc : num[0 , 1:3]
..$ notfixed_sigma : num [1:2] 1 0
..$ ds_index : num [1, 1:7] 0 0 0 1 1 1 1
..$ param.pt.val :List of 4
.. ..$ bpop : num [1:4, 1] 72.8 0.25 3.75 0.9
.. ..$ d : num [1:3, 1:3] 0.09 0 0 0 0.09 0 0 0 0.0625
.. ..$ docc : num[0 , 0 ]
.. ..$ sigma: num [1:2, 1:2] 4e-02 0e+00 0e+00 5e-06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment