Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think if you know the combination of parameters to be used for each model, then it is better to create a data frame of model names and parameters as shown below</p> <pre><code># create a data frame with model names and parameters # NOTE: i am assuming all models have equal number of parameters # if they are unequal, then store as list of models model = c('default', 'mymodel'); parm1 = c(0.5, 0.75); parm2 = c(1, 2); models.df = data.frame(model, parm1, parm2) </code></pre> <p>You can now simulate any of the models by passing it as an argument to your mySimulation function. I have used a dummy simulation example, which you can replace with your code.</p> <pre><code># function to run simulation based on model name mySimulation = function(model = 'default'){ # find row corresponding to model of interest mod.row = match(model, models.df$model) # extract parameters corresponding to model parms = models.df[mod.row, -1] # run dummy simulation of drawing normal random variables sim.df = rnorm(100, mean = parms[,1], sd = parms[,2]) return(sim.df) } </code></pre> <p>If you now want to run all your simulations in one step, you can use the excellent <code>plyr</code> package and invoke</p> <pre><code>library(plyr) sim.all = ldply(models.df$model, mySimulation) </code></pre> <p>If each of your simulations returns unequal number of values then you can use the function <code>llply</code> instead of <code>ldply</code>. </p> <p>If you provide more information about the return values of your simulation and details on what it does, this code can be easily tweaked to get what you want.</p> <p>Let me know if this works</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload