Helper function to create a list with random draws or whenever a series of functions needs to be called. Can be implemented within pick_val_v
.
pick_psa.Rd
Helper function to create a list with random draws or whenever a series of functions needs to be called. Can be implemented within pick_val_v
.
Details
This function can be used to pick values for the PSA within pick_val_v.
The function will ignore NA items within the respective parameter (see example below).
If an element in f is NA (e.g., a non PSA input) then it will return NA as its value
This feature is convenient when mixing distributions with different number of arguments, e.g., rnorm
and rgengamma
.
While it's slightly lower than individually calling each function, it makes the code easier to read and more transparent
Examples
params <- list(
param=list("a","b"),
dist=list("rlnorm","rnorm"),
n=list(4,1),
a=list(c(1,2,3,4),1),
b=list(c(0.5,0.5,0.5,0.5),0.5),
dsa_min=list(c(1,2,3,4),2),
dsa_max=list(c(1,2,3,4),3)
)
pick_psa(params[["dist"]],params[["n"]],params[["a"]],params[["b"]])
#> [[1]]
#> [1] 4.252388 7.641946 18.516493 36.101879
#>
#> [[2]]
#> [1] 1.938253
#>
#It works with functions that require different number of parameters
params <- list(
param=list("a","b","c"),
dist=list("rlnorm","rnorm","rgengamma"),
n=list(4,1,1),
a=list(c(1,2,3,4),1,0),
b=list(c(0.5,0.5,0.5,0.5),0.5,1),
c=list(NA,NA,0.2),
dsa_min=list(c(1,2,3,4),2,1),
dsa_max=list(c(1,2,3,4),3,3)
)
pick_psa(params[["dist"]],params[["n"]],params[["a"]],params[["b"]],params[["c"]])
#> [[1]]
#> [1] 3.987722 12.061015 38.895964 31.191468
#>
#> [[2]]
#> [1] 1.2573
#>
#> [[3]]
#> [1] 3.813397
#>
#Can be combined with multiple type of functions and distributions if parameters are well located
params <- list(
param=list("a","b","c","d"),
dist=list("rlnorm","rnorm","rgengamma","draw_tte"),
n=list(4,1,1,1),
a=list(c(1,2,3,4),1,0,"norm"),
b=list(c(0.5,0.5,0.5,0.5),0.5,1,1),
c=list(NA,NA,0.2,0.5),
c=list(NA,NA,NA,NA), #NA arguments will be ignored
dsa_min=list(c(1,2,3,4),2,1,0),
dsa_max=list(c(1,2,3,4),3,3,2)
)