if (FALSE) {
## Example with only the generator function
# Define random parameter list
my_randoms <- list(
act.rate = param_random(c(0.25, 0.5, 0.75)),
tx.prob = function() rbeta(1, 1, 2),
stratified.test.rate = function() c(
rnorm(1, 0.05, 0.01),
rnorm(1, 0.15, 0.03),
rnorm(1, 0.25, 0.05)
)
)
# Parameter model with fixed and random parameters
param <- param.net(inf.prob = 0.3, random.params = my_randoms)
# Below, `tx.prob` is set first to 0.3 then assigned a random value using
# the function from `my_randoms`. A warning notifying of this overwrite is
# therefore produced.
param <- param.net(tx.prob = 0.3, random.params = my_randoms)
# Parameters are drawn automatically in netsim by calling the function
# within netsim_loop. Demonstrating draws here but this is not used by
# end user.
paramDraw <- generate_random_params(param, verbose = TRUE)
paramDraw
## Addition of the `param.random.set` `data.frame`
# This function will generate sets of correlated parameters
generate_correlated_params <- function() {
param.unique <- runif(1)
param.set.1 <- param.unique + runif(2)
param.set.2 <- param.unique * rnorm(3)
return(list(param.unique, param.set.1, param.set.2))
}
# Data.frame set of random parameters :
correlated_params <- t(replicate(10, unlist(generate_correlated_params())))
correlated_params <- as.data.frame(correlated_params)
colnames(correlated_params) <- c(
"param.unique",
"param.set.1_1", "param.set.1_2",
"param.set.2_1", "param.set.2_2", "param.set.2_3"
)
# Define random parameter list with the `param.random.set` element
my_randoms <- list(
act.rate = param_random(c(0.25, 0.5, 0.75)),
param.random.set = correlated_params
)
# Parameter model with fixed and random parameters
param <- param.net(inf.prob = 0.3, random.params = my_randoms)
# Parameters are drawn automatically in netsim by calling the function
# within netsim_loop. Demonstrating draws here but this is not used by
# end user.
paramDraw <- generate_random_params(param, verbose = TRUE)
paramDraw
}
Run the code above in your browser using DataLab