Skip to content

Commit

Permalink
Merge pull request #144 from nlmixr2/poped-examples-tp
Browse files Browse the repository at this point in the history
Poped examples tp
  • Loading branch information
mattfidler authored Oct 29, 2024
2 parents 2c70390 + 2754fa4 commit ea93629
Show file tree
Hide file tree
Showing 24 changed files with 1,372 additions and 33 deletions.
52 changes: 52 additions & 0 deletions R/writeLines.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Function to write tree scructure for folders

# Install fs package if not already installed
if (!requireNamespace("fs", quietly = TRUE)) {
install.packages("fs")
}

# Load the fs package


# Define a function to get and save the folder tree with symbols
save_folder_tree_with_symbols <- function(path = ".", output_file = "folder_tree.txt") {
library(fs)
# Use fs::dir_tree to create the folder tree and get individual lines
folder_tree <- dir_tree(path, recurse = TRUE)

# Define a function to add symbols based on depth
add_symbols <- function(lines) {
result <- c()
depth <- 0

for (i in seq_along(lines)) {
# Calculate the depth based on the number of slashes in the path
depth <- sum(strsplit(lines[i], "/")[[1]] != "")

# Determine if it's a file or folder and if it's the last in its group
is_last <- (i == length(lines)) ||
(sum(strsplit(lines[i + 1], "/")[[1]] != "") <= depth)

# Add appropriate symbols for the depth level
prefix <- ifelse(depth > 1, paste0(strrep("", depth - 2), ifelse(is_last, "└─ ", "├─ ")), "")

result <- c(result, paste0(prefix, basename(lines[i])))
}
return(result)
}

# Create a visual representation of the folder tree with symbols
visual_tree <- add_symbols(folder_tree)

# Print the visual folder tree to the console
cat(visual_tree, sep = "\n")

# Save the visual folder tree to a text file
writeLines(visual_tree, output_file)
}

# Call the function on the

save_folder_tree_with_symbols(path = here::here("SCRIPTS"), output_file = "folder_tree_SCRIPTS.txt")
save_folder_tree_with_symbols(path = here::here("ANALYSES"), output_file = "folder_tree_ANALYSES.txt")
save_folder_tree_with_symbols(path = here::here("DATASETS"), output_file = "folder_tree_DATASETS.txt")
229 changes: 229 additions & 0 deletions inst/poped/PopED_output_summary_D_cont_opt_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
PopED Results

2024-10-24 00:44:14.791373

==============================================================================
Model description : PopED model

Model Sizes :
Number of individual model parameters g[j] : Ng = 10
Number of population model fixed parameters bpop[j] : Nbpop = 8
Number of population model random effects parameters b[j] : Nb = 8

Typical Population Parameters:
bpop[1]: 3.908
bpop[2]: -2.188
bpop[3]: 0.558
bpop[4]: -0.1864
bpop[5]: 2.261
bpop[6]: 0.2105
bpop[7]: 3.708
bpop[8]: -0.7089

Between Subject Variability matrix D (variance units)
0.0625 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0625 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0625 0.0000 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0625 0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0625 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0625 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0625 0.0000
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0625

Diagonal Elements of D [sqrt(param)]:
D[1,1]: 0.0625 [ 0.25]
D[2,2]: 0.0625 [ 0.25]
D[3,3]: 0.0625 [ 0.25]
D[4,4]: 0.0625 [ 0.25]
D[5,5]: 0.0625 [ 0.25]
D[6,6]: 0.0625 [ 0.25]
D[7,7]: 0.0625 [ 0.25]
D[8,8]: 0.0625 [ 0.25]

Residual Unexplained Variability matrix SIGMA (variance units) :
0.00927944 0.00000000 0.00000000 0.00000000
0.00000000 0.00100000 0.00000000 0.00000000
0.00000000 0.00000000 0.02246920 0.00000000
0.00000000 0.00000000 0.00000000 0.00100000

Diagonal Elements of SIGMA [sqrt(param)]:
SIGMA[1,1]: 0.009279 [0.09633]
SIGMA[2,2]: 0.001 [0.03162]
SIGMA[3,3]: 0.02247 [0.1499]
SIGMA[4,4]: 0.001 [0.03162]

==============================================================================
Experiment description (design and design space)

Number of individuals: 100
Number of groups (individuals with same design): 2
Number of individuals per group:
Group 1: 50
Group 2: 50
Number of samples per group:
Number of discrete experimental variables: 0
Number of model covariates: 2

Initial Sampling Schedule
Group 1: Model 1: 0.02 0.25 1 3 10
Group 1: Model 2: 0.02 0.25 1 3 10
Group 2: Model 1: 1 7 15 28 42
Group 2: Model 2: 1 7 15 28 42

Minimum allowed sampling values
Group 1: Model 1: 0.02 0.25 1 3 10
Group 1: Model 2: 0.02 0.25 1 3 10
Group 2: Model 1: 1 7 15 28 42
Group 2: Model 2: 1 7 15 28 42

Maximum allowed sampling values
Group 1: Model 1: 0.02 0.25 1 3 10
Group 1: Model 2: 0.02 0.25 1 3 10
Group 2: Model 1: 1 7 15 28 42
Group 2: Model 2: 1 7 15 28 42

Covariates:
Group 1: 1 : 300
Group 2: 2 : 10000

===============================================================================
Initial design evaluation

Initial OFV = 138.56

Efficiency criterion [usually defined as OFV^(1/npar)] = 2203.41

Initial design
expected relative standard error
(%RSE, rounded to nearest integer)
Parameter Values RSE_0
tvc 3.91 1
tk10 -2.19 2
tk12 0.558 8
tk21 -0.186 24
tvm 2.26 2
tkmc 0.21 48
tk03 3.71 1
tk30 -0.709 7
d_eta.vc 0.0625 17
d_eta.k10 0.0625 32
d_eta.k12 0.0625 28
d_eta.k21 0.0625 32
d_eta.vm 0.0625 25
d_eta.kmc 0.0625 102
d_eta.k03 0.0625 21
d_eta.k30 0.0625 32
sig_var_eps1 0.00928 11
sig_var_eps3 0.0225 18

==============================================================================
Criterion Specification

OFV calculation for FIM: 4
1=Determinant of FIM,
4=log determinant of FIM,
6=determinant of interesting part of FIM (Ds)

Approximation method: 0
0=FO,
1=FOCE,
2=FOCEI,
3=FOI

Fisher Information Matrix type: 1
0=Full FIM,
1=Reduced FIM,
2=weighted models,
3=Loc models,
4=reduced FIM with derivative of SD of sigma as pfim,
5=FULL FIM parameterized with A,B,C matrices & derivative of variance,
6=Calculate one model switch at a time, good for large matrices,
7=Reduced FIM parameterized with A,B,C matrices & derivative of variance

Design family: 1
D-family design (1) or
ED-family design (0)
(with or without parameter uncertainty)

==============================================================================
Optimization of design parameters

* Optimize Sampling Schedule

*******************************
Initial Value
OFV(mf) = 138.56
*******************************

RS - It. : 5 OFV : 138.56
RS - It. : 10 OFV : 138.56
RS - It. : 15 OFV : 138.56
RS - It. : 20 OFV : 138.56
RS - It. : 25 OFV : 138.56
RS - It. : 30 OFV : 138.56
RS - It. : 35 OFV : 138.56
RS - It. : 40 OFV : 138.56
RS - It. : 45 OFV : 138.56
RS - It. : 50 OFV : 138.56
RS - It. : 55 OFV : 138.56
RS - It. : 60 OFV : 138.56
RS - It. : 65 OFV : 138.56
RS - It. : 70 OFV : 138.56
RS - It. : 75 OFV : 138.56
RS - It. : 80 OFV : 138.56
RS - It. : 85 OFV : 138.56
RS - It. : 90 OFV : 138.56
RS - It. : 95 OFV : 138.56
RS - It. : 100 OFV : 138.56
RS - It. : 105 OFV : 138.56
RS - It. : 110 OFV : 138.56
RS - It. : 115 OFV : 138.56
RS - It. : 120 OFV : 138.56
RS - It. : 125 OFV : 138.56
RS - It. : 130 OFV : 138.56
RS - It. : 135 OFV : 138.56
RS - It. : 140 OFV : 138.56
RS - It. : 145 OFV : 138.56
RS - It. : 150 OFV : 138.56
RS - It. : 155 OFV : 138.56
RS - It. : 160 OFV : 138.56
RS - It. : 165 OFV : 138.56
RS - It. : 170 OFV : 138.56
RS - It. : 175 OFV : 138.56
RS - It. : 180 OFV : 138.56
RS - It. : 185 OFV : 138.56
RS - It. : 190 OFV : 138.56
RS - It. : 195 OFV : 138.56
RS - It. : 200 OFV : 138.56
RS - It. : 205 OFV : 138.56
RS - It. : 210 OFV : 138.56
RS - It. : 215 OFV : 138.56
RS - It. : 220 OFV : 138.56
RS - It. : 225 OFV : 138.56
RS - It. : 230 OFV : 138.56
RS - It. : 235 OFV : 138.56
RS - It. : 240 OFV : 138.56
RS - It. : 245 OFV : 138.56
RS - It. : 250 OFV : 138.56
RS - It. : 255 OFV : 138.56
RS - It. : 260 OFV : 138.56
RS - It. : 265 OFV : 138.56
RS - It. : 270 OFV : 138.56
RS - It. : 275 OFV : 138.56
RS - It. : 280 OFV : 138.56
RS - It. : 285 OFV : 138.56
RS - It. : 290 OFV : 138.56
RS - It. : 295 OFV : 138.56
RS - It. : 300 OFV : 138.56

*******************************
RS Results
OFV(mf) = 138.56

Optimized Sampling Schedule
Group 1: Model 1: 0.02 0.25 1 3 10
Group 1: Model 2: 0.02 0.25 1 3 10
Group 2: Model 1: 1 7 15 28 42
Group 2: Model 2: 1 7 15 28 42
*********************************

29 changes: 18 additions & 11 deletions inst/poped/ex.1.a.PK.1.comp.oral.md.intro.babelmixr2.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ f <- function() {
})
}

# minxt, maxxt
e <- et(list(c(0, 10),
c(0, 10),
c(0, 10),
c(240, 248),
c(240, 248))) %>%
as.data.frame()

#xt
# PopED xt equivalent
e$time <- c(1,2,8,240,245)


Expand All @@ -69,7 +68,6 @@ plot_model_prediction(babel.db, IPRED=T, DV=T, separate.groups=T, model_num_poin

evaluate_design(babel.db)


## original: > shrinkage(poped.db)
## # A tibble: 9 × 5
## d_V d_KA d_CL type group
Expand All @@ -86,40 +84,49 @@ evaluate_design(babel.db)
shrinkage(babel.db)

# Optimization of sample times

output <- poped_optim(babel.db, opt_xt =TRUE)
# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output <- poped_optim(babel.db, opt_xt =TRUE, parallel=TRUE)

# Evaluate optimization results
summary(output)

## From original
# V KA CL d_V d_KA d_CL
# 6.281944 7.726279 4.295908 32.416232 49.062880 26.363021
get_rse(output$FIM,output$poped.db)

plot_model_prediction(output$poped.db)


# Optimization of sample times and doses
output_2 <- poped_optim(output$poped.db, opt_xt =TRUE, opt_a = TRUE)
# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output_2 <- poped_optim(output$poped.db, opt_xt =TRUE, opt_a = TRUE, parallel = TRUE)

summary(output_2)

# From original
# V KA CL d_V d_KA d_CL
# 6.252332 7.547072 4.240929 32.205996 47.014629 25.684326
get_rse(output_2$FIM,output_2$poped.db)

plot_model_prediction(output_2$poped.db)


# Optimization of sample times with only integer time points in design space
# faster than continuous optimization in this case
babel.db.discrete <- create.poped.database(babel.db,discrete_xt = list(0:248))

output_discrete <- poped_optim(babel.db.discrete, opt_xt=T)

# Note: The parallel option does not work well with Windows machines at this moment.
# Please set parallel = FALSE if you are working on a Windows machine
output_discrete <- poped_optim(babel.db.discrete, opt_xt=T, parallel = TRUE)

summary(output_discrete)

# V KA CL d_V d_KA d_CL
# 6.331614 8.009220 4.297905 32.351741 51.795028 26.386514
get_rse(output_discrete$FIM,output_discrete$poped.db)

plot_model_prediction(output_discrete$poped.db)


# Efficiency of sampling windows
plot_efficiency_of_windows(output_discrete$poped.db, xt_windows=1)
Loading

0 comments on commit ea93629

Please sign in to comment.