scenario_mc | R Documentation |
This function is a wrapper around the mc_Simulation
function that facilitates
implementation of scenarios. The standard mc_Simulation
function only allows
specifying one set of estimates (i.e. distribution, lower and upper bounds) for each random
variable. This is inconvenient when we want to run simulations for heterogeneous populations
that include subsets with particular characteristics, e.g. small and large farms. It may
then make sense to specify separate distributions for input variables for each of the subsets.
The scenario_mc
function facilitates this.
scenario_mc(
base_estimate,
scenarios,
model_function,
...,
numberOfModelRuns = NA,
randomMethod = "calculate",
functionSyntax = "data.frameNames",
relativeTolerance = 0.05,
verbosity = 0
)
base_estimate |
|
scenarios |
|
model_function |
|
... |
Optional arguments of |
numberOfModelRuns |
The number of times to run the model function. This doesn't need to be
provided when the |
randomMethod |
|
functionSyntax |
|
relativeTolerance |
|
verbosity |
|
See documentation of the mc_Simulation
function.
An object of class mcSimulation
, which is a list
with elements:
$x
data.frame
containing the sampled x -
(input) values which are generated
from base_estimate
and possibly modified by scenarios
. To identify the scenario, the scenario name is provided in the
scenario
column.
$y
data.frame
containing the simulated y -
(output) values, i.e. the model
function values for x
.The return of the decision model function may include the
assignment of names for the output variables, e.g. like this:
profit <- function(x){ revenue - costs return(list(Revenue = revenue, Costs = cost)) }
mcSimulation
, print.mcSimulation
, summary.mcSimulation
, hist.mcSimulation
, estimate
, random.estimate
### define a model_function
profit<-function(x)
{profit<-benefit_1+benefit_2-cost_1-cost_2
return(Profit=profit)}
### define a base_estimate, to be used when no other information is provided
# through the scenario data.frame
base_estimate<-as.estimate(variable=c("cost_1","cost_2","benefit_1","benefit_2"),
distribution=c("norm","posnorm","norm","posnorm"),
lower=c(40,10,50,30),
upper=c(100,200,300,100))
### define a scenario data.frame, which will override values in the base_estimate
scenarios<-data.frame(Variable=c("Runs","cost_1","cost_1","cost_1","cost_2","cost_2",
"benefit_1","benefit_1","benefit_2"),
param=c("x","lower","upper","distribution","lower","upper",
"lower","upper","lower"),
Scenario_1=c(100,40,70,"posnorm",30,90,20,35,10),
Scenario_2=c(50,100,200,"norm",10,40,35,75,5),
Scenario_3=c(10,400,750,"norm",400,600,30,70,60))
### run a simulation
results<-scenario_mc(base_estimate, scenarios, model_function=profit,
functionSyntax="plainNames")
### plot and inspect results
hist(results)
summary(results)
print(results)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.