diff --git a/Index.Rmd b/Index.Rmd index 1b89291..3a63691 100644 --- a/Index.Rmd +++ b/Index.Rmd @@ -323,62 +323,72 @@ knitr::write_bib(c(.packages(), ```{r child="Seminar_Schedule.Rmd"} ``` -```{r child="Seminar_01_Experiential.Rmd"} -``` - ```{r child="Lecture_02_Decision_Analysis.Rmd"} ``` -```{r child="Seminar_02_R_RStudio_1.Rmd"} -``` -```{r child="Lecture_03_Define_Decision.Rmd"} -``` -```{r child="Seminar_03_R_RStudio_2.Rmd"} -``` + + -```{r child="Lecture_04_Case_Studies.Rmd"} -``` -```{r child="Seminar_04_RMarkdown.Rmd"} -``` + + + + -```{r child="Lecture_05_Participatory_Methods.Rmd"} -``` -```{r child="Seminar_05_Git_Github.Rmd"} -``` + + -```{r child="Lecture_06_Decision_Models.Rmd"} -``` -```{r child="Seminar_06_Model_Programming.Rmd"} -``` + + -```{r child="Lecture_07_calibration_lecture.Rmd"} -``` -```{r child="Seminar_07_calibration_seminar.Rmd"} -``` + + -```{r child="Lecture_08_Forecasts.Rmd"} -``` -```{r child="Seminar_08_models_seminar.Rmd"} -``` + + -```{r child="Lecture_08_01_Practical_Schiffers.Rmd"} -``` + + -```{r child="Lecture_09_Bayesian_Thinking.Rmd"} -``` -```{r child="Seminar_09_forecast_seminar.Rmd"} -``` + + -```{r child="Lecture_10_Analyst_Profile.Rmd"} -``` -```{r child="Seminar_10_Functions.Rmd"} -``` + + -```{r child="Lecture_11_Communicating.Rmd"} -``` -```{r child="Seminar_11_Writing.Rmd"} -``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ```{r child="Impressum.Rmd"} ``` diff --git a/Index.html b/Index.html index beecedb..0d4d874 100644 --- a/Index.html +++ b/Index.html @@ -331,14 +331,14 @@
Lecture | +Lecture | Date | Materials | Reading | @@ -346,108 +346,82 @@|
---|---|---|---|---|---|
1 | -Friday, April 14, 2023 | +1 | +Wednesday, April 10, 2024 | Introduction | Watch: Sir Ken Robinson / Hans Rosling (optional) |
2 | -Friday, April 21, 2023 | +2 | +Friday, April 12, 2024 | Decision Analysis Overview | Hubbard (2014) (Chapter 1. The Challenge of Intangibles) |
3 | -Friday, April 28, 2023 | +3 | +Wednesday, April 17, 2024 | Defining a Decision | Howard and Abbas (2015) (Chapter 1. Introduction to Quality Decision Making) |
4 | -Friday, May 5, 2023 | +4 | +Friday, April 19, 2024 | Decision Analysis Case Studies | Shepherd et al. (2015) |
5 | -Friday, May 12, 2023 | +5 | +Wednesday, April 24, 2024 | Participatory Methods | Luedeling and Shepherd (2016) |
6 | -Friday, May 19, 2023 | +6 | +Friday, April 26, 2024 | Building Decision Models | Do, Luedeling, and Whitney (2020) |
7 | -Friday, May 26, 2023 | -Calibrating -experts | -Kahneman and Egan (2011) -(Chapter 1) | -||
8 | -Friday, June 9, 2023 | +7 | +Friday, May 3, 2024 | Using Models to Create Forecasts | Tetlock and Gardner (2015) (Chapter 1. An Optimistic Skeptic) |
Practical | -Friday, June 16, 2023 | -Models with -Dr. Schiffers | -Build models | -||
9 | -Friday, June 23, 2023 | +8 | +Wednesday, May 8, 2024 | Bayesian Thinking | Bertsch McGrayne (2011) (Chapter 1. Causes in the Air) |
10 | -Friday, June 30, 2023 | +9 | +Friday, May 10, 2024 | +Calibrating +experts | +Kahneman and Egan (2011) +(Chapter 1) | +
10 | +Friday, May 17, 2024 | Profile of a Decision Analyst | Savage and Markowitz (2009) (Chapter 1) | ||
11 | -Friday, July 7, 2023 | -Communicating Decision -Support | -TBA | -||
12 | -Date TBA | -Group presentations | -Present | -||
13 | -Date TBA | -Group presentations continued | -Present | -
Week | +Week | Date | Materials | Assignment | @@ -470,138 +444,114 @@|
---|---|---|---|---|---|
1 | -Friday, April 14, 2023 | +1 | +Wednesday, May 28, 2024 | Group Work Overview | Install R and Rstudio |
2 | -Friday, April 21, 2023 | +2 | +Friday, May 31, 2024 | Using R and RStudio | Share R scripts (part 1) |
3 | -Friday, April 28, 2023 | +3 | +Wednesday, June 5, 2024 | Using R and RStudio continued | Share R scripts (part 2) |
4 | -Friday, May 5, 2023 | +4 | +Friday, June 7, 2024 | Using RMarkdown | Share Rmarkdown file |
5 | -Friday, May 12, 2023 | +5 | +Wednesday, June 12, 2024 | Using git and Github | Start a Github repo |
6 | -Friday, May 19, 2023 | +6 | +Friday, June 14, 2024 | Model Programming | Share R scripts (part 3) |
7 | -Friday, May 26, 2023 | +7 | +Wednesday, June 19, 2024 | Calibration training | Participate in calibration training |
8 | -Friday, June 9, 2023 | +8 | +Friday, June 21, 2024 | +Model +functions | +Share updated model | +
9 | +Wednesday, June 26, 2024 | Value of information | Share R scripts (part 3) | ||
Practical | -Friday, June 16, 2023 | -Models with -Dr. Schiffers | -Share initial models | -||
9 | -Friday, June 23, 2023 | +10 | +Friday, June 28, 2024 | +Communicating Decision +Support | ++ |
11 | +Wednesday, July 03, 2024 | Model forecasts | Share initial forecasts | ||
10 | -Friday, June 30, 2023 | -Model -functions | -Share updated model | -||
11 | -Friday, July 7, 2023 | +12 | +Friday, July 5, 2024 | Citation Management | Join Zotero Group |
12 | -Date TBA | +13 | +Wednesday, July 10, 2024 | +Guest Lecture | ++ |
14 | +Friday, July 12, 2024 | +Consultation | ++ | ||
15 | +Wednesday, July 17, 2024 | Groups present / discuss final model | -Prepare final model | +Present | |
13 | -Date TBA | +16 | +Friday, July 19, 2024 | Presentations continued | Present |
Welcome to the first seminar of Decision Analysis and -Forecasting for Agricultural Development.
-You should already be familiar with the idea that we intend to have -group work form a major part of this course. If you have not already it -is important that you choose a group to work with and begin to think -about a topic (ideally an agricultural decision) that you intend to work -on through this course. In this seminar we will share the general -motivation behind the experiential nature of this course and talk about -effective group work techniques and tools. The lecture in week three Defining a decision will provide a -detailed exploration of how decisions are defined / steps we may need to -go through to help decision makers define decisions.
-Feel free to bring up any questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-To see an example of the result we will be aiming to create see the -paper by Do, Luedeling, and Whitney (2020) -and the associated supplementary -materials.
-The first step in getting ready for the work of this course is to -install and run R (R Core Team 2023) and RStudio.
-For some expert advice on how to name and organize your projects and -files please scroll through Danielle Navarro’s Project -Structure slides.
-Welcome to the second seminar of Decision Analysis and -Forecasting for Agricultural Development. Feel free to bring up -any questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-Remember that this is an experiential course and will be based -largely on work from your side that is supported by us, rather than -passive learning where we deliver content. In order to work with us in -this course you will need to have some basic tools.
-You should already have installed R and RStudio. If not, please check -out the tools we use in this course. If you -already have R and RStudio loaded then you should be able to follow -parts our R tutorial. Please follow [Data Wrangling Part 1]((https://agtools.app/learning_r/#section-data-wrangling-part-1) -and [Data Wrangling Part 2]((https://agtools.app/learning_r/#section-data-wrangling-part-2) -portions of the tutorial. Share the results of your work with the -‘ggplot2’ ‘diamonds’ data (Wickham, Chang, et al. -2023) after you have worked through these materials.
- - -
-
The following videos cover some of the challenges that researchers -and agricultural development experts face when attempting to define -decisions. Please watch the videos and answer the questions that -follow.
-Think about the following questions and jot down your thoughts.
-Think of challenges you may encounter when trying to do -credible, salient and legitimate research -(all of which decision analysts should aim to achieve).
-This video outlines the background for quality decision making, -closely following Howard and Abbas (2015). -At the end of the video please take some time to sketch out some -thoughts about a decision that you will be working on for the -experiential part of this course. You can find the slides for the first -three parts of the lecture here.
-This week you will all read Howard and Abbas -(2015) (Chapter 1. Introduction to Quality Decision Making). One -group will lead a discussion on the reading.
-You should already have installed R and RStudio. If not, please check
-out the tools we use in this course. If you
-already have R and RStudio loaded then you should be able to follow this
-Data
-Visualization section of the R tutorial. Share the results of your
-work with a data set of your choice (i.e. ggplot2
-diamonds
data (Wickham, Chang, et
-al. 2023)) after you have worked through these materials.
If you run the code usethis::use_blank_slate()
in your
-console it will set your RStudio preference to NEVER
-save or restore .RData
on exit or on startup, which is a
-lifestyle choice endorsed by many excellent researchers like Jenny Bryan.
Welcome to lecture 4 of Decision Analysis and Forecasting for
-Agricultural Development. In this lecture we will follow three
-case studies and use the #lecture-04-case-studies
Slack
-channel and Zoom meeting to follow up. This will allow us all to have a
-chance to see your progress, provide feedback. As always, your
-engagement and sharing is appreciated. It will be encouraging to others
-to see activity from colleagues. Feel free to bring up any questions or
-concerns in the Slack or to Dr. Cory
-Whitney or the course tutor.
Please take a few minutes to watch these short videos and do the -associated exercises before our meeting.
-The following videos introduce some decision analysis case studies. -Please watch the videos and answer the questions that follow.
-The city of Wajir in Northern Kenya has lacks a reliable supply of -clean drinking water and sanitation. To improve the situation, plans are -being considered to construct a water pipeline from Habaswein over 100 -km away (Luedeling and Leeuw 2014; Luedeling et -al. 2015). Watch the following video to learn more.
- -Now try to answer the following questions:
-This video shows the study Rojas et al. -(2021) conducted in Chile for assessing the profitability of -implementing plastic covers in sweet cherry orchards to protect the -fruits from hazardous weather events.
- - -Based on the question above, think about and write down two to three -positive and negative implications of using the method we used to define -the decision.
-The data and scripts for this study are also available online (Fernandez et al. 2021).
-RMarkdown: overview
-Now let’s check out Rmarkdown, a powerful tool -that allows making fancy reports, websites etc. out of our R code (Allaire et al. (2023)). You’re already looking -at an example, by the way. This website was produced with Rmarkdown (and -it wasn’t hard at all)!
- - -Here are the -slides and the -html file generated in the video.
-To run this you will need to load library(rmarkdown)
and library(knitr
)
https://rmarkdown.rstudio.com/authoring_basics.html
-https://bookdown.org/yihui/rmarkdown/r-code.html
- - Open an
-Rmarkdown file and knit.
Now we’re equipped with all the basic tools for this course. We’ll -start using them pretty soon. Throughout the course you’ll find -occasional references to your RMarkdown file. This is supposed to be -produced with Rmarkdown, with subsequent versions of it stored on -Github.
-The following video outlines some of the tools that can be used in -participatory modeling. Watch the video and answer the questions that -follow.
- -The following video covers some definitions, methods and tools and a -case study related to stakeholder management in decision analysis. -Please watch the videos and answer the questions that follow. These will -be helpful in determining which tools/techniques you might use to -identify stakeholders in your decision analysis process.
- - - -Plot stakeholders’ experience, availability and expertise in decision
-analysis with the ggplot2
ggrepel
-ggthemes
libraries (Wickham, Chang,
-et al. 2023; Slowikowski 2023; Arnold 2023). Use the stakeholder
-data set from our git repository. To run this on your machine, save this
-raw csv file as .csv
to your local .RProj
-directory. Then use
-stakeholder<-read.csv("stakeholder.csv")
to load the
-data to your R environment and save it as stakeholder
.
ggplot(data = stakeholder, aes(x = Experience,
- y = Availability,
- label = stakeholders,
- color = Expertise)) +
- geom_point(aes(shape=Gender)) +
- xlab("Relevant Experience") +
-
- #label names of stakeholders and expand space to show full names
- scale_x_continuous(labels = paste(seq(0, 5, by = 1)),
- breaks = seq(0, 5, by = 1),
- limits = c(0, 5),
- expand = c(0, 1)) +
- scale_y_continuous(labels = paste(seq(0, 5, by = 1)),
- breaks = seq(0, 5, by = 1),
- limits = c(0, 5),
- expand = c(0, 1)) +
- theme(plot.margin = unit(c(1, 1, 1, 1), "cm")) +
- theme(legend.position = "none") +
-
-# Create line to categorize stakeholders
- geom_hline(yintercept=2.5, color="white", size=2) +
- geom_vline(xintercept=2.5, color="white", size=2) +
+
+References
+
+
-
-Learn more about using names and overlapped
-values.
-
This week you will read Shepherd et al. -(2015). One of the members of each of your groups will present -the results of this reading.
-Liberating -Structures by Keith McCandless (and others)
Reed, M. S. et al. (2009) ‘Who’s in and why? A typology of -stakeholder analysis methods for natural resource management’, Journal -of Environmental Management, 90(5), pp. 1933–1949. doi: -10.1016/j.jenvman.2009.01.001.
Welcome to the fourth seminar of Decision Analysis and -Forecasting for Agricultural Development. All your programming -and project work for this course should take place in the git -environment and this seminar is intended to show you how to make that -happen. Feel free to bring up any questions or concerns in the Slack or -to Dr. Cory -Whitney or the course tutor.
-Now we look at the programming version control environment git and the interface github, which we use to share our scripts -and changes to our work.
- -Install Git & join Github (if you have not already):
-Important note for Windows users: when you download
-Git, it may be installed into your Program Files
directory
-by default. This often causes issues later. The general recommendation
-is to choose a different directory for installing,
-i.e. C:/Users/username/bin/
. Once Git is installed, open
-RStudio, and go to Tools > Global Options
, select
-Git/SVN
, and then enter or select the path for your Git
-executable.
Some useful tips on getting these running from our friends
-University of Zurich http://www.geo.uzh.ch/microsite/reproducible_research/post/rr-rstudio-git/
Nathan Stephens, a very helpful R blogger
-https://support.rstudio.com/hc/en-us/articles/200532077-Version-Control-with-Git-and-SVN
Start simple with your own repository only and work on it alone. -Share your profile and link to a repository you made in the Slack -channel for this seminar. Soon you will start to collaborate on -something in git. For the project part of this course your team will -work in a collective repository and work together to generate the final -working project model and report.
-We can use the options from htmlpreview.github.io
to
-show the results of any of our html output work that is stored in our
-git repository.
To do that just preface the path for the html file with
-http://htmlpreview.github.io/?
.
For example the slides for this seminar can be found in the
-CWWhitney/teaching_git
repository.
The full path is:
-https://github.com/CWWhitney/teaching_git/blob/master/R_Git_GitHub.html
and the link to this to be viewed directly as a web page is: http://htmlpreview.github.io/?https://github.com/CWWhitney/teaching_git/blob/master/R_Git_GitHub.html
-Best -practices for using Git from deepsource.io. Note that we break rule -number five when we share the html files in the Git repository. That can -be our secret.
Watch the ‘What is GitHub’ video from the GitHub developers
- -Welcome to lecture 6 of Decision Analysis and Forecasting for -Agricultural Development. We will walk through brief examples -and offer the scripts. Feel free to bring up any questions or concerns -in the Slack, to Dr. Cory -Whitney or to the course tutor.
-Decision-makers often wish to have a quantitative basis for their -decisions. However,‘hard data’ is often missing or unattainable for many -important variables, which can paralyze the decision-making processes or -lead decision-makers to conclude that large research efforts are needed -before a decision can be made. That is, many variables decision makers -must consider cannot be precisely quantified, at least not without -unreasonable effort. The major objective of (prescriptive) decision -analysis is to support decision-making processes faced with this -problem. Following the principles of Decision Analysis can allow us to -make forecasts of decision outcomes without precise numbers, as long as -probability distributions describing the possible values for all -variables can be estimated.
-The decisionSupport
package implements this as a Monte
-Carlo simulation, which generates a large number of plausible system
-outcomes, based on random numbers for each input variable that are drawn
-from user-specified probability distributions. This approach is useful
-for determining whether a clearly preferable course of action can be
-delineated based on the present state of knowledge without the need for
-further information. If the distribution of predicted system outcomes
-does not imply a clearly preferable decision option, variables
-identified as carrying decision-relevant uncertainty can then be
-targeted by decision-supporting research. This approach is explained in
-more detail below and in the model
-programming seminar.
In this portion of the course we hope to introduce you to the methods -and inspire you to follow a few important guidelines in the process of -model building. One of the key aspects of model building has to do with -making a solid business case for the model before programming.
- -Another important guideline is to start simple then move on to other -steps. This ensures that you always have a working model at each of the -steps in the process, i.e. starting with a skateboard rather than a car -part as in this example from MetaLab.
-Before you start developing the decision model (an R function), open
-R and download and load the decisionSupport
package.
install.packages("decisionSupport")
-library(decisionSupport)
-The mcSimulation
function from the
-decisionSupport
package can be applied to conduct decision
-analysis (Luedeling et al. 2023). The
-function requires three inputs:
estimate
of the joint probability distribution of
-the input variables. These specify the names and probability
-distributions for all variables used in the decision model. These
-distributions aim to represent the full range of possible values for
-each component of the model.model_function
that predicts decision outcomes based
-on the variables named in a separate data table. This R function is
-customized by the user to address a particular decision problem to
-provide the decision analysis model.numberOfModelRuns
indicating the number of times to run
-the model function.These inputs are provided as arguments to the
-mcSimulation
function, which conducts a Monte Carlo
-analysis with repeated model runs based on probability distributions for
-all uncertain variables. The data table and model are customized to fit
-the particulars of a specific decision.
estimate
To support the model building process we design an input table to
-store the estimate
values. The table is stored locally as
-example_decision_inputs.csv
and contains many of the basic
-values for the analysis. This table contains all the input variables
-used in the model. Their distributions are described by 90% confidence
-intervals, which are specified by lower (5% quantile) and upper (95%
-quantile) bounds, as well as the shape of the distribution. This example
-uses four different distributions:
const
– a constant valuenorm
– a normal distributiontnorm_0_1
– a truncated normal distribution that can
-only have values between 0 and 1 (useful for probabilities; note that 0
-and 1, as well as numbers outside this interval are not permitted as
-inputs)posnorm
– a normal distribution truncated at 0 (only
-positive values allowed)For a full list of possible distributions, type
-?random.estimate1d
in your R console. When specifying
-confidence intervals for truncated distributions, note that
-approximately 5% of the random values should ‘fit’ within the truncation
-interval on either side. If there is not enough space, the function will
-generate a warning (usually it will still work, but the inputs may not
-look like you intended them to).
We have provided default distributions for all the variables used
-here, but feel free to make adjustments by editing the .csv file in a
-spreadsheet program. You can download the ‘example_decision_inputs.csv’
-here and save it as a .csv file locally (from your web browser try: File
-> Save page as). In this example it is stored in the ‘data’ folder.
-Once you have downloaded the data you can run
-example_decision_inputs <- read.csv("data/example_decision_inputs.csv")
-in your console to make the following code work on your machine. Note
-that the input table that can be written or read from a .csv file and
-calculated with the estimate_read_csv
function or converted
-to the correct format with the as.estimate
function.
model_function
The decision model is coded as an R function which takes in the -variables provided in the data table and generates a model output, such -as the Net Present Value.
-Here we define a simple model function that we call
-example_decision_model
. It calculates profits as benefits
-minus costs and arbitrarily adds 500 to the result to arrive at
-final_profits
. This simple example shows us how to use
-function
, the results of which can be applied elsewhere.
-The most basic way to apply the library is to use the
-mcSimulation
function to run our
-example_decision_model
. Here we run it 100 times using
-inputs from the example_decision_inputs.csv
table.
Update this model by adding additional_benefits
, one of
-the variables from the example_decision_inputs
data, to
-replace the 500 that was arbitrarily added to the profit and changing
-the number of model runs to 700.
example_decision_model <- function(x, varnames){
- profit <- benefits-costs
-
- final_profits <- profit + 500
-
- return(final_profits)
-
-}
+# load the data (use write.csv for data created in RMD)
+stakeholder <- read.csv("data/stakeholder.csv")
+input_estimates <- read.csv("data/input_estimates.csv")
+example_decision_inputs <- read.csv("data/example_decision_inputs.csv")
+input_table <- read.csv("data/example_input_table.csv")
+hail_estimates <- read.csv("data/hail_estimates.csv")
-mcSimulation(estimate = as.estimate(example_decision_inputs),
- model_function = example_decision_model,
- numberOfModelRuns = 100,
- functionSyntax = "plainNames")
-
-example_decision_model <- function(x, varnames){
-
- profit <- benefits-costs
-
- final_profits <- profit + additional_benefits
-
- return(final_profits)
-
-}
+###### chile function #######
-mcSimulation(estimate = as.estimate(example_decision_inputs),
- model_function = example_decision_model,
- numberOfModelRuns = 700,
- functionSyntax = "plainNames")
-Now we have a simulation of possible outcomes. In the model programming seminar this -week we will go into more detail on the options for assessment of the -results of simulations and on visualization of the results.
-Note that this example was constructed for clarity and not for speed.
-Speed considerations are not very important when we only run a process
-once, but since in the Monte Carlo simulation all delays are multiplied
-by numberOfModelRuns
(e.g. 10,000), they can sometimes add
-up to substantial time losses. Even with highly efficient coding, Monte
-Carlo simulations can take a while when dealing with complex
-decisions.
The objective of the procedures used in the
-decisionSupport
package is to make it easier for analysts
-to produce decision-relevant information that adequately reflects the
-imperfect nature of the information we usually have. Adding
-probabilistic elements to a simulation adds substantial value to an
-analysis. Mostly, it avoids making spurious assumptions, replacing
-uncertainty with ‘best bets’ and producing results that do not reflect
-the knowledge limitations that make decision-making so challenging. More
-information on all this is contained in the decisionSupport
-manual, especially under welfareDecisionAnalysis
.
Whitney et al. (2018) -‘Probabilistic decision tools for determining impacts of agricultural -development policy on household nutrition’.
Ruett, Whitney, and Luedeling -(2020) ‘Model-based evaluation of management options in -ornamental plant nurseries’
Welcome to the sixth seminar of Decision Analysis and
-Forecasting for Agricultural Development. In this seminar we
-will look into different options for model programming in the
-R
programming environment (R Core
-Team 2023). In case you have not already installed R
-and RStudio
you may want to go back to the Using R and Rstudio seminar and follow the
-instructions there. Feel free to bring up any questions or concerns in
-the Slack or to Dr. Cory
-Whitney or the course tutor.
We have just learned about the processes and methods of generating Decision Models. Now we can explore
-some of the packages that we commonly use in R
. The main
-package that our team uses for simulations is the
-decisionSupport
. In order to use the standard tools for
-running these models in the R environment you will need to load the
-decisionSupport
library. Use the
-install.packages
function,
-i.e. install.packages("decisionSupport")
.
library(decisionSupport)
-In this example, we show how we can transform a simple impact pathway -into code for estimating profit distributions.
-We use the mermaid
function from the
-DiagrammeR
library to create the graphical impact pathway
-(Iannone 2023).
Run the code below and then add an additional cost to the graph
-called Management cost
(try to do this on your own but feel
-free to look to the solution
to see one way to do
-this).
mermaid("graph LR
- Y(Yield)-->I(Income); linkStyle 0 stroke:green, stroke-width:1.5px
- M(Market price)-->I; linkStyle 1 stroke: green, stroke-width:1.5px
- I-->F(Final result); linkStyle 2 stroke: green, stroke-width:1.5px
- CL(Labor cost)-->F; linkStyle 3 stroke: red, stroke-width:1.5px")
-
-mermaid("graph LR
- Y(Yield)-->I(Income); linkStyle 0 stroke:green, stroke-width:1.5px
- M(Market price)-->I; linkStyle 1 stroke: green, stroke-width:1.5px
- I-->F(Final result); linkStyle 2 stroke: green, stroke-width:1.5px
- CL(Labor cost)-->F; linkStyle 3 stroke: red, stroke-width:1.5px
- CM(Management cost)-->F; linkStyle 4 stroke: red, stroke-width:1.5px")
-The LR
argument in the mermaid
function
-specifies that the plot will go from left to right. Try and change this
-to TD
.
Use the style
options in mermaid
to change
-the arrow widths to 2px
and the node colors to red for
-costs and green for benefits. You will need to break the line and put
-the linkStyle
on a new line to add the color to the
-node.
mermaid("graph LR
- Y(Yield)-->I(Income); linkStyle 0 stroke:green, stroke-width:1px
- M(Market price)-->I; linkStyle 1 stroke: green, stroke-width:1px
- I-->F(Final result); linkStyle 2 stroke: green, stroke-width:1px
- CL(Labor cost)-->F; linkStyle 3 stroke: red, stroke-width:1px
- CM(Management cost)-->F; linkStyle 4 stroke: red, stroke-width:1px")
-
-mermaid("graph TB
- Y(Yield)-->I(Income); style I fill:green
- linkStyle 0 stroke:green, stroke-width:2px
- M(Market price)-->I; linkStyle 1 stroke: green, stroke-width:2px
- I-->F(Final result); linkStyle 2 stroke: green, stroke-width:2px
- CL(Labor cost)-->F; style CL fill:red
- linkStyle 3 stroke: red, stroke-width:2px
- CM(Management cost)-->F; style CM fill:red
- linkStyle 4 stroke: red, stroke-width:2px")
-That was just one of many ways to generate impact pathways. To see -more options see the Decision -Analysis Overview lecture materials.
-Here we generate an input table to feed the model function. Update
-this with your new management cost variable in the graphical impact
-pathway. Call your new variable "Management_cost"
, make the
-lower bound 100
and the upper bound 2000
, make
-the distribution "posnorm"
, make the label
-"Management cost (USD/ha)"
and make the description
-"Management costs in a normal season"
.
input_estimates <- data.frame(variable = c("Yield", "Market_price", "Labor_cost"),
- lower = c(6000, 3, 500),
- median = NA,
- upper = c(14000, 8, 1000),
- distribution = c("posnorm", "posnorm", "posnorm"),
- label = c("Yield (kg/ha)", "Price (USD/kg)", "Labor cost (USD/ha)"),
- Description = c("Yield in a sweet cherry farm under normal conditions",
- "Price of sweet cherry in a normal season",
- "Labor costs in a normal season"))
-
-input_estimates
-
-input_estimates <- data.frame(variable = c("Yield", "Market_price", "Labor_cost", "Management_cost"),
- lower = c(6000, 3, 500, 100),
- median = NA,
- upper = c(14000, 8, 1000, 2000),
- distribution = c("posnorm", "posnorm", "posnorm", "posnorm"),
- label = c("Yield (kg/ha)", "Price (USD/kg)", "Labor cost (USD/ha)", "Management cost (USD/ha)"),
- Description = c("Yield in a sweet cherry farm under normal conditions",
- "Price of sweet cherry in a normal season",
- "Labor costs in a normal season",
- "Management costs in a normal season"))
-
-input_estimates
-Here we use the mcSimulation
function from the
-decisionSupport
package to implement a model (Luedeling et al. 2023). The model function that
-describes the graphical impact pathway. Add a new line of code that
-summarizes the Labor_cost
and Management_cost
-into overall_costs
, then subtract these from the
-income
to calculate final_result
.
model_function <- function(){
-
- # Estimate the income in a normal season
- income <- Yield * Market_price
-
- # Estimate the final results from the model
- final_result <- income - Labor_cost
-
- # Generate the list of outputs from the Monte Carlo simulation
- return(list(final_result = final_result))
-}
-
-# Run the Monte Carlo simulation using the model function
-example_mc_simulation <- mcSimulation(estimate = as.estimate(input_estimates),
- model_function = model_function,
- numberOfModelRuns = 800,
- functionSyntax = "plainNames")
-
-example_mc_simulation
-
-model_function <- function(){
-
- # Estimate the income in a normal season
- income <- Yield * Market_price
-
- overall_costs <- Labor_cost + Management_cost
-
- # Estimate the final results from the model
- final_result <- income - overall_costs
-
- # Generate the list of outputs from the Monte Carlo simulation
+# create the model function
+model_function <- function(){
+ income <- Yield * Market_price
+ overall_costs <- Labor_cost + Management_cost
+ final_result <- income - overall_costs
return(list(final_result = final_result))
}
-# Run the Monte Carlo simulation using the model function
-example_mc_simulation <- mcSimulation(estimate = as.estimate(input_estimates),
+# Run the Monte Carlo simulation using the model function ####
+example_mc_simulation <- mcSimulation(estimate = as.estimate(input_estimates),
model_function = model_function,
- numberOfModelRuns = 800,
- functionSyntax = "plainNames")
-
-example_mc_simulation
-Here we show the results of a Monte Carlo simulation (800 model runs) -for estimating the profits in sweet cherry orchards.
-Change the plot to a histogram by using the method
-argument in the plot_distributions
function.
plot_distributions(mcSimulation_object = example_mc_simulation,
- vars = "final_result",
- method = "boxplot_density",
- old_names = "final_result",
- new_names = "Outcome distribution for profits")
-
-plot_distributions(mcSimulation_object = example_mc_simulation,
- vars = "final_result",
- method = "hist_simple_overlay",
- old_names = "final_result",
- new_names = "Outcome distribution for profits")
-make_variables
You could simply start further developing the decision model now, but
-since the model function will be designed to make use of variables
-provided to it externally (random numbers drawn according to the
-information in the data table), you will need to define sample values
-for all variables, if you want to test pieces of the function code
-during the development process. This can be done manually, but it’s more
-easily accomplished with the following helper function
-make_variables
:
make_variables <- function(est,n=1)
-{ x<-random(rho=est, n=n)
+ numberOfModelRuns = 100,
+ functionSyntax = "plainNames")
+###### make variables function #######
+# make variables
+make_variables <- function(est,n=1)
+{ x<-random(rho=est, n=n)
for(i in colnames(x)) assign(i,
as.numeric(x[1,i]),envir=.GlobalEnv)
-}
-
-This function is not included in the decisionSupport
-package, because it places the desired variables in the global
-environment. This is not allowed for functions included in packages on
-R’s download servers.
Applying make_variables
and as.estimate
to
-the data table (with default setting n=1
) generates one
-random number for each variable, which then allows you to easily test
-the code you are developing. Try running this function on your code as
-you build the decision function. This allows for testing the values
-within a model rather than running the full model.
Run the make_variables
and as.estimate
on
-the input_estimates
input table that we created and then
-calculate the result of Labor_cost + Management_cost
given
-a single random value for these variables. Note that each time
-you run this code it generates a new random draw and produces a
-different number from within the range for the variables in the input
-table.
make_variables(as.estimate(input_estimates))
+}
-Market_price
-
-make_variables(as.estimate(input_estimates))
+# suppress warnings
+options(warn = - 1)
+
+###### burkina function #######
+# second decision function
+example_decision_function <- function(x, varnames){
-Labor_cost + Management_cost
-Once you have followed and run the code above on your machine it is a
-good time to look through the outline of these procedures in the
-decisionSupport
vignette on the CRAN called ‘Applying
-the mcSimulation function in decisionSupport’ (Fernandez, Whitney, and Luedeling 2021). This
-will show you how the tools can be applied for comparing decision
-outcomes. It runs a Monte-Carlo-based selection of sedimentation
-management strategies for a reservoir in the Upper Volta River Basin of
-Burkina Faso (Lanzanova et al. 2019). Tip:
-If you want to play with this code you can find the Rmarkdown
-file and the estimate
-table in the decisionSupport
GitHub repository.
Taken together, all these outputs allow an evaluation of the -plausible range of net benefits that can be expected to arise from the -decision. They provide a recommendation on which decision option should -be preferred, and an appraisal of which input variables are responsible -for most of the variation in the output distribution.
-Listen to this interview on Alex Andorra’s podcast ‘Learning Bayesian -Statistics’, How -to use Bayes in industry, with Colin Carroll
- - - - -Welcome to lecture 7 of Decision Analysis and Forecasting for -Agricultural Development. Feel free to bring up any questions -or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-The following videos tell you something about a method which is -frequently used in our group to get reliable values for the input tables -from our stakeholders. Please watch the videos and answer the questions -that follow.
-Watch the video and do the awareness test!
- -Have a look at Terry Heick’s Cognitive -Bias codex.
-Welcome to the sixth seminar of Decision Analysis and -Forecasting for Agricultural Development. This week we will be -going through the materials that were mentioned in the Calibrating experts lecture.
-Your work for this this seminar is to review materials from Lecture 7 -on the methods of calibration and prepare to be subjected to the -calibration process.
-To prepare please load the required calibration sheets from our -shared Slack work space.
-After this session please consider the inputs that will be necessary -for your own model and prepare the input table and formulate questions -for eliciting calibrated estimates from your colleagues and/or any -experts that you have identified for your team’s model.
-Sign in to GuidedTrack -calibration training to get your confidence intervals results.
-Sign in to the Prediction -Book to ‘Find out just how sure you should be, and get better at -being only as sure as the facts justify’.
-What do you think about the idea of taking estimates as values -for the impact models?
What do you think about the method of calibration training as -presented? Do you have suggestions how to change or improve it?
Can you think of further cognitive biases and how to deal with -them?
Welcome to lecture 8 of Decision Analysis and Forecasting for -Agricultural Development. We will walk through brief examples -and offer the scripts. Feel free to bring up any questions or concerns -in the Slack or to Dr. Cory -Whitney or the course tutor.
-In this lecture we will build on what we learned in the Decision Models lecture and the Model programming seminar to learn -more about how to generate useful forecasts for communicating model -results. We will implement another Monte Carlo simulation.
-In the Model programming
-seminar we generated a model called example_mc_simulation
.
-As a quick refresher change the plot of the results of that model from
-boxplot_density
to smooth_simple_overlay
by
-using the method
argument in the
-plot_distributions
function.
plot_distributions(mcSimulation_object = example_mc_simulation,
- vars = "final_result",
- method = "boxplot_density",
- old_names = "final_result",
- new_names = "Outcome distribution for profits")
-
-plot_distributions(mcSimulation_object = example_mc_simulation,
- vars = "final_result",
- method = "smooth_simple_overlay",
- old_names = "final_result",
- new_names = "Outcome distribution for profits")
-First let’s look at a case study on agroforestry interventions in -Northwest Vietnam (Do, Luedeling, and Whitney -2020).
- -Since the model inputs are uncertain variables, there is always a -chance that the decision turns out to be wrong. Gathering new data to -inform the decision, will lead to (on average) better decisions. But how -much better? Is it worth the measuring effort? What if we not only -measure but even manipulate the model inputs? These -concepts are informally known as “value of clairvoyance” and “value of -wizardry”. Please watch the following lecture by Johannes Kopton and -enter the magical world of decision analysis:
- -Technically we assess the possibility of making the wrong decision -with a payoff matrix \(Rij\) with the -row index \(i\) describing a choice and -the column index \(j\) describing a -random variable that the decision maker does not yet have knowledge of, -that has probability \(pj\) of being in -state \(j\). If the decision maker has -to choose \(i\) without knowing the -value of \(j\), the best choice is the -one that maximizes the expected value:
-\({\mbox{EMV}}=\max _{i}\sum -_{j}p_{j}R_{ij}\)
-where \(\sum _{j}p_{j}R_{ij}\) is -the expected payoff for action \(i\) -i.e. the expectation value, and \({\mbox{EMV}}=\max _{i}\) is choosing the -maximum of these expectations for all available actions.
-However, with perfect knowledge of \(j\), the decision maker would choose a -value of \(i\) that optimizes the -expectation for that specific \(j\). -Therefore, the expected value given perfect information is
-\({\mbox{EV}}|{\mbox{PI}}=\sum -_{j}p_{j}(\max _{i}R_{ij})\)
-where \(p_{j}\) is the probability -that the system is in state \(j\), and -\(R_{ij}\) is the pay-off if one -follows action \(i\) while the system -is in state \(j\). Here \((\max_{i}R_{ij})\) indicates the best -choice of action \(i\) for each state -\(j\).
-The expected value of perfect information is the difference between -these two quantities,
-\({\mbox{EVPI}}={\mbox{EV}}|{\mbox{PI}}-{\mbox{EMV}}\)
-This difference describes, in expectation, how much larger a value -the decision maker can hope to obtain by knowing \(j\) and picking the best \(i\) for that \(j\), as compared to picking a value of -\(i\) before \(j\) is known. Since \(EV|PI\) is necessarily greater than or -equal to \(EMV\), \(EVPI\) is always non-negative.
-Projection to Latent Structures (PLS), also sometimes known as -Partial Least Squares regression is a multivariate statistical technique -that can deal with multiple collinear dependent and independent -variables (Wold, Sjöström, and Eriksson -2001). It can be used as another means to assess the outcomes of -a Monte Carlo model. Read more in ‘A Simple Explanation -of Partial Least Squares’ by Kee Siong Ng.
-Variable Importance in Projection (VIP) scores estimate the -importance of each variable in the projection used in a PLS mode. VIP is -a parameter used for calculating the cumulative measure of the influence -of individual \(X\)-variables on the -model. For a given PLS dimension, \(a\), the squared PLS weight \((W_a^2\) of that term is multiplied by the -explained sum of squares (\(SS\)) of -that \(PLS\) dimension; and the value -obtained is then divided by the total explained \(SS\) by the PLS model and multiplied by the -number of terms in the model. The final \(VIP\) is the square root of that -number.
-\(VIP_{PLS} = K\times -(\frac{[\sum_{a=1}^{A}(W_{a}^{2} \times -SSY_{comp,a})]}{SSY_{cum}})\)
-Technically, VIP is a weighted combination overall components of the -squared PLS weights (\(Wa\)), where -\(SSY_{comp,a}\) is the sum of squares -of \(Y\) explained by component \(a\), \(A\) -is the total number of components, and \(K\) is the total number of variables. The -average VIP is equal to 1 because the \(SS\) of all VIP values is equal to the -number of variables in \(X\). A -variable with a VIP Score close to or greater than 1 (one) can be -considered important in given model. The input is a PLS model and the -output is a set of column vectors equal in length to the number of -variables included in the model. See Galindo-Prieto, Eriksson, and Trygg (2014) for a -detailed description of variations of VIP analysis.
-In the seminar we will go into detail abut how to calculate PLS and
-the VIP with the built-in functions of the decisionSupport
-package.
Welcome to the lecture on Bayesian modeling with me, Dr. Katja
-Schiffers. Although we mainly implement these methods in our group
-for decision analysis, we do not want to withhold the Bayesian Modeling
-approaches from you. Originally, I prepared this introduction for a
-seminar on the analysis of experimental data, so the focus is more on
-comparing frequentist and Bayesian statistics than on decision models.
-In this lecture we will use the brms
package and use the
-#lecture_08_01_practical
Slack channel to follow up. This
-will allow us all to have a chance to see your progress, provide
-feedback. As always, your engagement and sharing is appreciated. It will
-be encouraging to others to see activity from colleagues. Feel free to
-bring up any questions or concerns in Slack or to Dr. Cory
-Whitney or the course tutor.
The following text heavily relies on a very well-written article “Short -introduction to Bayesian statistics with R for ornithologists” -(2016) by Fränzi Korner-Nievergelt & Ommo Hüppop in ‘Die -Vogelwarte’. At the end of the lecture, you will know
-No introduction to Bayesian statistics is complete without Bayes’ -theorem. Thomas Bayes was an English clergyman, philosopher, and -statistician who, in 1763 published a manuscript entitled “An essay -towards solving a problem in the doctrine of chances.” In this work, he -describes how, based on existing knowledge and additional observations -X, the probability can be calculated that a hypothesis -H is true:
-\[P(H|X) = \frac -{P(X|H)×P(H)}{P(X)}\]
-In words, the probability (P) that the hypothesis is true, given the -observed data (P(H|X), a-posteriori knowledge), is -equal to the probability of observing the data, assuming the hypothesis -is true (P(X|H), likelihood), times the prior -probability that the hypothesis is true before observing the data (P(H), -a-priori knowledge or prior), divided -by the probability of observing the data regardless of any assumptions -about the hypothesis (P(X), normalization constant).
-It is important to note that hypotheses are expressed as parameter -values. For example, if our hypothesis is that the mean of a dependent -variable is greater under treatment A than under treatment B, we would -calculate the probability for the parameter mean(A) - mean(B) and obtain -the probability that it is greater than zero.
-In Bayesian statistics, this idea is used to combine prior knowledge -from experts/literature (P(H)) with the information contained in newly -collected data X to generate the updated a-posteriori knowledge. We also -see that as a result, we obtain the probability of our hypothesis. This -is much more digestible and closer to our “normal” way of thinking than -interpreting a p-value: “The probability of finding data as -extreme as this or more extreme, if the null hypothesis is -true.”
-Excursion: Probability distributions
-To represent probabilities, such as prior knowledge, probability -distributions are used. In the following figure, you can see such a -probability distribution: the higher the density, the more likely the -parameter value plotted on the x-axis. The total area under the curve -always adds up to 1 (exactly some parameter value must always be -true).
- -So how do we calculate this probability? Unfortunately, it’s usually -not as straightforward as it seems. While we can usually calculate the -likelihood (this is also done in frequentist statistics to determine the -parameter values of our models) and establish our a-priori knowledge -through a probability distribution, things get tricky with the P(X) -part, the probability of the data, at least once we no longer have very -simple models. To do this, we would have to integrate the probability of -the data over all possible parameter values, and this is often not -possible. Fortunately, this problem can be overcome with a simulation -technique developed in the 1980s and 1990s:
-MCMC methods can approximate probability distributions (in this case, -P(H|X)) that cannot be analytically computed. The most intuitive and -quite ingenious explanation I found for this is by Michael Franke on his -Github page at https://michael-franke.github.io/intro-data-analysis/Ch-03-03-estimation-algorithms.html. -Here are some parts of it:
-How the Apples Get to the Trees
-Every year in spring, Mother Nature sends out her children to -distribute apples on the apple trees. For each tree, the number of -apples should be proportional to the number of leaves: Giant Ralph with -twice as many leaves as Skinny Daniel should also have twice as many -apples in the end. So if there are a total of \(n_a\) apples, and \(L(t)\) is the number of leaves on tree -\(t\), each tree should receive \(A(t)\) apples.
-\[A(t) = \frac {L(t)}{\sum -L(t')}n_a\]
-The problem is that Mother Nature cannot calculate \(\sum L(t')\) (the normalization -constant), so she doesn’t know how many leaves all the trees have -together.
-The children (Markov chains) can count, however. They can’t visit all -the trees and they can’t remember the numbers for very long, but they -can do it for two trees at a time. Here’s what they do: they each start -at a random tree (parameter value), already put an apple in it, count -the leaves \(L(t_1)\) there and then -look for a nearby tree from which they can also count the leaves \(L(t_2)\) (the denominator of our -distribution). If the number of leaves in the second tree is higher, -they will definitely go there and put an apple in it. If it’s lower, -they will only go there with a probability of \(L(t_2)/L(t_1)\) and put an apple there. -They keep walking back and forth between the trees, and in the end, the -apples are roughly evenly distributed. The frequency of visits by the -children has therefore approximated the desired distribution (which -Mother Nature couldn’t calculate)!
-MCMC methods do the same thing: an MCMC chain randomly draws values
-for the model parameters and computes
-Result1 = Likelihood of the data * Prior for them
. Then it
-draws values randomly around the first ones and computes
-Result2 = Likelihood of the data * Prior for them
. If
-Result2
is higher than Result1
, it jumps there
-and draws new parameter values from there. If Result2
is
-lower, it only jumps there with a probability of
-Result2/Result1
. Then, values are drawn randomly again, and
-so on. In the following figure, successful jumps are represented by blue
-arrows and rejected jumps by green arrows.
If this process is continued long enough, the distribution of the -blue dots approaches the posterior probability distribution of the -parameters that we want: We have combined a priori knowledge with the -information contained in the newly collected data to successfully obtain -posterior knowledge!
-We need to decide which chicken breed we want to keep in our orchard. -We already have 3 Kraienköppe and 6 Niederrheiner. We prefer the -Niederrheiner because they are less aggressive, but the Kraienköppe seem -to have a slightly higher egg-laying performance. Is it really advisable -to choose Kraienköppe because of this tendency?
-1: Definition of the A-priori-probability -distribution
-We inquire about the egg production of the two breeds and learn that
-Niederrheiners lay between 190 and 210 eggs per year, while Kraienkoppes
-lay between 200 and 220. Accordingly, we formulate our prior probability
-distributions using the brms
package:
library(brms)
To get the brms
library to work as expected you may need
-the latest rstan
and StanHeaders
. Run
-install.packages("rstan")
.
-install.packages("StanHeaders")
. You may also need to set
-up the connection with these libraries with
-options(mc.cores = parallel::detectCores())
and
-rstan_options(auto_write = TRUE)
.
We define 2 normal distributions using the function set_prior, -one with a mean of 200 and a standard deviation of 1.5, and another with -a mean of 210 and a standard deviation of 1.5. We specify under ‘coef’ -which parameters in the model that we later formulate these priors -belong to.
-priors <- c(set_prior("normal(200, 5)", coef = "rasseN"), set_prior("normal(210, 5)", coef = "rasseK"))
Plot them, to get a feeling of the priors:
-curve(dnorm(x, 200, 5), from = 170, to = 230, xlab="egg production", ylab="density")
2. Collecting new data
-Now we report our own observations of the egg-laying performance of -the 3 Kraienköppe and 6 Niederrheiners from the previous year:
-rasse <- c("K", "K", "K", "N", "N", "N", "N", "N", "N")
ll <- c(225, 222, 221, 219, 219, 216, 221, 218, 217)
daten <- data.frame(rasse=rasse, ll=ll)
3. Combining the prior distribution with the data to obtain -the posterior distribution
-To estimate the posterior distribution, we use the ‘brm’ function of
-the brms
package. As we know from other evaluations, we
-first formulate our model, namely that the egg-laying performance
-ll
depends on the breed. The -1
in the model
-formula causes the model to estimate the mean egg-laying performance for
-both breeds rather than just the mean for the first breed and the
-difference to it. Under data
, we enter our own collected
-data and under prior
, we define the above priors. The
-silent
argument determines how much information is output
-to the console when the MCMC chains start running. Depending on the
-complexity of the model, these simulations can take several seconds or
-minutes.
Make the model
-legeleistung <- brms::brm(formula = ll ~ rasse -1, data = daten , prior = priors, silent = 2)
4. Interpretation
-The above code has performed the MCMC simulation and we can now -examine the posterior distributions for the laying performance of the -chicken breeds:
-Print the summary summary(legeleistung)
The summary first shows us our inputs and some information about the -Markov chains. Most interesting to us are, of course, the estimates for -rasseK and rasseN and their credibility intervals. As you can see, the -confidence intervals overlap: the lower value of rasseK (l-95%) is about -218, which is smaller than the upper value (u-95%) of about 219 for -rasseN, which lays fewer eggs.
-Sigma is the estimated standard deviation of the assumed normal -distribution and is less relevant to us here.
-plot(legeleistung)
In the figure, the results are even easier to interpret. On the left, -you can see the a-posteriori distributions for both breeds (note that -the x-axes of the top two distributions are not aligned). To the right -of that are the dynamics of the Markov chains.
-From the a-posteriori distributions, we could now also calculate the -exact probability that the egg-laying performance really is different. -However, since we have already seen that the credibility intervals -overlap, we stick to our preference for the Niederrheiners, even though -it is not ruled out that they lay a few eggs less.
-Frequentist | -Bayesian | -
---|---|
Probability of data, in relation to hypothesis | -only yes/no answer | -
Confidence interval: in which interval do we expect 95% of the means -of further random samples of the same sample size | -Credibility interval: in which range of values does the true -population mean lie with a probability of 95% | -
Assumption that there is one ‘true’ value, but -observations lead to a distribution | -Assumption that the observed values are true and have an intrinsic -variance | -
The easier interpretability of Bayesian analyses is best illustrated -by the following figure:
-An uncritical frequentist approach would result in: “The effect in -group/treatment A and E is significant, so we will use the tested -fertilizer for those groups. There seems to be no effect in the other -groups.”
-However, there is an important effect in group B as well, and even -though the effect in group E is statistically significant, the effect -size on yield is so small that it probably does not make economic sense -to fertilize additionally.
-The results of the Bayesian analysis (i.e., the probabilities for the -hypothesis that there is an effect) much more directly reflect these -interpretations.
-Welcome to lecture 9 of Decision Analysis and Forecasting for -Agricultural Development. Feel free to bring up any questions -or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-Please watch the video and answer the multiple choice questions -below.
- - -Summarize for yourself the difference between the frequentist and the -Bayesian approach to knowledge generation. Which one do you feel more -comfortable about? Are you ready to become a Bayesian?
-Welcome to ninth seminar of Decision Analysis and Forecasting -for Agricultural Development.Feel free to bring up any -questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-In our seminar meeting each group will present the decision and -proposed impact pathway model that they will be programming for the rest -of the course.
-Review the process in the Models lecture.
-We have already built some simple models in the Decision Models lecture and the Model programming seminar. Now we
-can explore another simple model with decisionSupport
.
Let’s use the graph.formula
function from the
-igraph
library again (Csardi and
-Nepusz 2006). This time to create the graphical impact pathway of
-an investment into hail nets. Add another factor called ‘Discount’ that
-impacts the Net Present Value (NPV) value.
hail_path <- graph.formula(HailNet -+ Yield,
- HailNet -+ Cost,
- HailEvent -+ Yield,
- Yield -+ MarketPrice,
- MarketPrice -+ NPV,
- Cost -+ NPV)
-
-plot(hail_path)
-
-hail_path <- graph.formula(HailNet -+ Yield,
- HailNet -+ Cost,
- HailEvent -+ Yield,
- Yield -+ MarketPrice,
- MarketPrice -+ NPV,
- Cost -+ NPV,
- Discount -+ NPV)
-
-plot(hail_path)
-That was just one of many ways to generate visual impact pathways. To -see more options see the Decision -Analysis Overview lecture materials.
-Here we generate an input table to feed the model function. Update
-this with your new management cost variable in the graphical impact
-pathway. Call your new variable "p_hail"
, make the lower
-bound 0.02
and the upper bound 0.2
, make the
-distribution "posnorm"
, make the label
-"% chance hail"
and make the description
-"Probability of a hail storm"
.
hail_estimates <- data.frame(variable = c("yield",
- "var_CV",
- "initial_investment",
- "price"),
- lower = c(6000, 20, 500, 5),
- median = NA,
- upper = c(14000, 20, 1000, 80),
- distribution = c("posnorm",
- "const",
- "posnorm",
- "posnorm"),
- label = c("Yield (kg/ha)",
- "Coefficient of variation",
- "Investment cost (USD)",
- "Market price (EUR/kg)"),
- Description = c("Yield under normal conditions",
- "Coefficient of variation (measure of relative variability)",
- "Investment cost",
- "Market price achieved for yields (EUR/kg)"))
-
-hail_estimates
-
-hail_estimates <- data.frame(variable = c("yield",
- "var_CV",
- "initial_investment",
- "price",
- "p_hail"),
- lower = c(6000, 20, 500, 5, 0.02),
- median = NA,
- upper = c(14000, 20, 1000, 80, 0.2),
- distribution = c("posnorm",
- "const",
- "posnorm",
- "posnorm",
- "posnorm"),
- label = c("Yield (kg/ha)",
- "Coefficient of variation",
- "Investment cost (USD)",
- "Market price (EUR/kg)",
- "% chance hail"),
- Description = c("Yield under normal conditions",
- "Coefficient of variation (measure of relative variability)",
- "Investment cost",
- "Market price achieved for yields (EUR/kg)",
- "Probability of a hail storm"))
-
-hail_estimates
-Here we create a function following the graphical impact pathway and
-using the inputs above to calculate the Net Present Value for the
-investment in hail nets. We use the vv()
function from the
-decisionSupport
package to add more variation over time
-(Luedeling et al. 2023). We also use the
-chance_event()
function to calculate a
-hail_adjusted_yield
for losses when there is hail.
hail_function <- function(){
-
-# use vv() to add variability to the
-# random draws of yield and of price
-# over a 20 year simulation
-yields <- vv(var_mean = yield,
- var_CV = var_CV,
+yields <- vv(var_mean = yield,
+ var_CV = var_CV,
n = 20)
-prices <- vv(var_mean = price,
- var_CV = var_CV,
+prices <- vv(var_mean = price,
+ var_CV = var_CV,
n = 20)
-# use rep() to simulate the initial_investment
+# use 'rep' to simulate the investment
# only in the first year (assuming the net lasts 20 years)
-invest_costs <- c(initial_investment, rep(0, 19))
+invest_costs <- c(initial_investment, rep(0, 19))
-# use p_hail in the chance_event()
-# to adjust yield for probability of hail
-# assuming no yield at all in the event of hail
-hail_adjusted_yield <- chance_event(chance = p_hail,
+# use 'chance_event' to adjust yield for potential hail
+hail_adjusted_yield <- chance_event(chance = p_hail,
value_if = 0,
value_if_not = yield,
n = 20)
# calculate profit without net
-profit_no_net <- hail_adjusted_yield*prices
+profit_no_net <- hail_adjusted_yield*prices
# calculate profit with the net
-profit_with_net <- (yields*prices)-invest_costs
+profit_with_net <- (yields*prices)-invest_costs
-# use 'discount' to calculate net present value
-# 'discount_rate' is expressed in percent
-NPV_no_net <- discount(profit_no_net, discount_rate = 5, calculate_NPV = TRUE)
-NPV_net <- discount(profit_with_net, discount_rate = 5, calculate_NPV = TRUE)
+# use 'discount' to calculate net present value
+# 'discount_rate' is expressed in percent
+NPV_no_net <- discount(profit_no_net, discount_rate = 5, calculate_NPV = TRUE)
+NPV_net <- discount(profit_with_net, discount_rate = 5, calculate_NPV = TRUE)
-# calculate the overall NPV of the decision (do - don't do)
-NPV_decision <- NPV_net-NPV_no_net
+# calculate the overall NPV of the decision (do - don't do)
+NPV_decision <- NPV_net-NPV_no_net
return(list(NPV_no_net = NPV_no_net,
- NPV_net = NPV_net,
+ NPV_net = NPV_net,
NPV_decision = NPV_decision))
-}
-
-We can use the mcSimulation()
function from the
-decisionSupport
package to implement a model (Luedeling et al. 2023).
# Run the Monte Carlo simulation using the model function
-hail_mc_simulation <- mcSimulation(estimate = as.estimate(hail_estimates),
- model_function = hail_function,
- numberOfModelRuns = 200,
- functionSyntax = "plainNames")
-
-hail_mc_simulation
-
-Here we show the results of a Monte Carlo simulation (200 model runs) -for estimating the comparative profits with and without hail nets.
-plot_distributions(mcSimulation_object = hail_mc_simulation,
- vars = c("NPV_no_net", "NPV_net"),
- method = 'smooth_simple_overlay',
- base_size = 7)
-
-Calculate Value of Information (VoI) analysis with the Expected Value -of Perfect Information (EVPI). As we learned in Lecture 8 on forecasts, EVPI helps us -determine if more research will be helpful in understanding the expected -change in the value of a decision outcome through reducing uncertainty -on a given variable.
-Use the function data.frame()
to transform the x and y
-outputs of the mcSimulation()
function results for EVPI
-calculation. We use the multi_EVPI()
function to calculate
-the EVPI for multiple independent variables. For the first_out_var
-argument we choose NPV_decision
from the input table since
-this is the first output variable (the only variable) and will the
-subject of the EVPI.
# subset the outputs from the mcSimulation function (y)
-# to run the multi_EVPI only on the variables that the we want
-# (i.e. the NPV_decision)
-mcSimulation_table_hail <- data.frame(hail_mc_simulation$x,
- hail_mc_simulation$y[3])
-
-evpi_hail <- multi_EVPI(mc = mcSimulation_table_hail,
- first_out_var = "NPV_decision")
-
-We use the function plot_evpi()
on the results from
-multi_EVPI()
to plot the Expected Value of Perfect
-Information (EVPI). Here we show the results with the standard settings.
-The length of the bars is equal to EVPI.
plot_evpi(evpi_hail, decision_vars = "NPV_decision")
-
-Once you have followed and run the code above on your machine it is a -good time to look through the outline of these procedures in the example -by Lanzanova et al. (2019) called ‘Sediment -management in a reservoir in Burkina Faso’. It runs a -Monte-Carlo-based selection of sedimentation management strategies for a -reservoir in the Upper Volta River Basin of Burkina Faso (Lanzanova et al. 2019).
-Tip: If you want to play with this code you can find the Rmarkdown -file and the estimate -table in the GitHub repository.
-Follow Chelsea -Parlett Pelleriti’s Bayesian statistics work
-Listen to the ‘Learning -Bayesian Statistics’ podcast
- - -Welcome to lecture 10 of Decision Analysis and Forecasting -for Agricultural Development. Feel free to bring up any -questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-Those who work in Decision Analysis must be able to do a number of -diverse jobs from the facilitation and integration of ideas into models -and also in programming these models. In the following short lecture you -will learn about the skills that are particularly important for -integration of knowledge, facilitation of knowledge -gathering processes and for programming decision models. Please -watch the video and answer the multiple choice questions below.
- - -This week we will read and discuss Chapter 1 of ‘The Flaw of -Averages’ by Savage and Markowitz -(2009).
--Savage, Sam L., and Harry M. Markowitz. The Flaw of Averages: Why We -Underestimate Risk in the Face of Uncertainty. John Wiley & Sons, -2009.
-Sam Savage’s article The Flaw of -Averages in the Harvard Business Review.
-Welcome to the tenth seminar of Decision Analysis and -Forecasting for Agricultural Development.Feel free to bring up -any questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-In this seminar we will go over some of the functions that are useful
-for building parts of our models in the decisionSupport
-package.
Many variables vary over time and it may not be desirable to ignore
-this variation in time series analyses. The vv
function
-produces time series that contain variation from a specified mean and a
-desired coefficient of variation. A trend can be added to this time
-series.
The arguments for the vv
function include:
var_mean
, which is the mean of the variable to be
-variedvar_CV
, which is the desired coefficient of variation
-(in percent)n
, which is the integer; number of values to
-producedistribution
, which is the probability distribution for
-the introducing variation. This is currently only implemented for normal
-distributionsabsolute_trend
, which is the absolute increment in the
-var_mean
in each time step. Defaults to NA
,
-which means no such absolute value trend is present. If both absolute
-and relative trends are specified, only original means are usedrelative_trend
, which is the relative trend in the
-var_mean
in each time step (in percent). Defaults to
-NA
, which means no such relative value trend is present. If
-both absolute and relative trends are specified, only original means are
-usedlower_limit
, which is the lowest possible value for
-elements of the resulting vectorupper_limit
, which is the upper possible value for
-elements of the resulting vectorNote that only one type of trend can be specified. If neither of the -trend parameters are NA, the function uses only the original means
-The function produces a vector of n
numeric values,
-representing a variable time series, which initially has the mean
-var_mean
, and then increases according to the specified
-trends. Variation is determined by the given coefficient of variation
-var_CV
.
Create a vector with the vv
function and plot with the
-base R plot
function.
# reduce var_CV to 5 and change n to 40. Name the output 'valvar' and plot with base R
-vv(var_mean = 100,
- var_CV = 10,
- n = 30)
-
-valvar <- vv(var_mean = 100,
- var_CV = 5,
- n = 40)
-
-plot(valvar)
-Use the absolute_trend
argument and plot with the base R
-plot
function.
# reduce var_mean to 50 and make absolute_trend 10. Name the output 'valvar' and plot with base R
-vv(var_mean = 100,
- var_CV = 10,
- n = 30,
- absolute_trend = 5)
-
-valvar <- vv(var_mean = 50,
- var_CV = 10,
- n = 30,
- absolute_trend = 10)
-
-plot(valvar)
-Use the relative_trend
argument and plot with the base R
-plot
function.
# reduce var_CV to 5 and change n to 40. Name the output 'valvar' and plot with base R
-vv(var_mean = 100,
- var_CV = 10,
- n = 30,
- relative_trend = 5)
-
-valvar <- vv(var_mean = 100,
- var_CV = 5,
- n = 40,
- relative_trend = 5)
-
-plot(valvar)
-In many simulations, certain events can either occur or not, and -values for dependent variables can depend on which of the cases occurs. -This function randomly simulates whether events occur and returns output -values accordingly. The outputs can be single values or series of -values, with the option of introducing artificial variation into this -dataset.
-The arguments for the chance_event
function include:
chance
, which is the probability that the risky event
-will occur (between 0 and 1)value_if
, which is the output value in case the event
-occurs. This can be either a single numeric value or a numeric vector.
-Defaults to 1.value_if_not
, which is the output value in case the
-event does not occur. This can be either a single numeric value or a
-numeric vector. If it is a vector, it must have the same length as
-value_if
n
, which is the number of times the risky event is
-simulated. This is ignored if length(value_if)>1
.CV_if
, which is the coefficient of variation for
-introducing randomness into the value_if data set. This defaults to 0
-for no artificial variation. See documentation for the vv
-function for details. CV_if_not
, which is the coefficient
-of variation for introducing randomness into the value_if_not data set.
-This defaults to the value for CV_if.
See documentation for
-the vv
function for details.one_draw
, which is the boolean coefficient indicating
-if event occurrence is determined only once (TRUE
) with
-results applying to all elements of the results vector, or if event
-occurrence is determined independently for each element
-(FALSE
is the default).The chance_event
function provides a numeric vector of
-length n
, containing outputs of a probabilistic simulation
-that assigns value_if
if the event occurs, or
-value_if_not
if is does not occur (both optionally with
-artificial variation).
# decrease the chance and value_if by half and repeat 20 times. Name the output 'chancevar' and plot with base R
-chance_event(chance = 0.5,
- value_if = 6,
- n = 10)
-
-chancevar <- chance_event(chance = 0.25,
- value_if = 3,
- n = 20)
-
-plot(chancevar)
-Use the value_if_not
and CV_if
-arguments.
# make the chance 10 percent, the value_if 5 and the value_if_not 20, repeat 100 times and reduce the coefficient of variation by half. Name the output 'chancevar' and plot with base R.
-chance_event(chance = 0.5,
- value_if = 1,
- value_if_not = 5,
- n = 10,
- CV_if = 20)
-
-chancevar <- chance_event(chance = 0.1,
- value_if = 5,
- value_if_not = 20,
- n = 100,
- CV_if = 10)
-
-plot(chancevar)
-Yields of trees or other perennial plants have to be simulated in -order to predict the outcomes of many interventions. Unlike annual -crops, however, trees normally yield nothing for a few years after -planting, following which yields gradually increase until they reach a -tree-specific maximum. This is simulated with this function, which -assumes that a Gompertz function is a good way to describe this (based -on the general shape of the curve, not on extensive research…). The -function assumes that yields remain at the maximum level, once this is -reached. For long simulations, this may not be a valid assumption! The -function parameters are estimated based on yield estimates for two -points in time, which the user can specify. They are described by a year -number and by a percentage of the maximum yield that is attained at that -time.
-The arguments for the gompertz_yield
function
-include:
max_harvest
, which is the maximum harvest from the tree
-(in number of fruits, kg or other units)time_to_first_yield_estimate
, which is the year (or
-other time unit) number, for which the first yield estimate is provided
-by first_yield_estimate_percent
time_to_second_yield_estimate
, which is the year (or
-other time unit) number, for which the second yield estimate is provided
-by second_yield_estimate_percent
first_yield_estimate_percent
percentage of the maximum
-yield that is attained in the year (or other time unit) given by
-time_to_first_yield_estimate
second_yield_estimate_percent
percentage of the maximum
-yield that is attained in the year (or other time unit) given by
-time_to_second_yield_estimate
n_years
, which is the number of years to run the
-simulationvar_CV
, which is the coefficient indicating how much
-variation should be introduced into the time series. If this is one
-numeric value, then this value is used for all variables. The default is
-0, for a time series with no artificially introduced variation. See
-description of the vv
function for more details on
-this.no_yield_before_first_estimate
, which is the boolean
-variable indicating whether yields before the time unit indicated by
-time_to_first_yield_estimate
should be 0.The function provides a vector of n_years
numeric
-values, describing the simulated yield of the perennial. This starts at
-0 and, if the simulation runs for a sufficient number of years,
-approaches max_harvest.
If var_CV>0
, this
-time series includes artificial variation.
# create a vector where the maximum harvest is 500, which is achieved in 10 years (i.e. 100% by the second yield estimate)
-gompertz_yield(max_harvest = 1000,
- time_to_first_yield_estimate = 5,
- first_yield_estimate_percent = 10,
- time_to_second_yield_estimate = 15,
- second_yield_estimate_percent = 90,
- n_years = 30)
-
-gompertz_yield(max_harvest = 500,
- time_to_first_yield_estimate = 5,
- first_yield_estimate_percent = 10,
- time_to_second_yield_estimate = 10,
- second_yield_estimate_percent = 100,
- n_years = 30)
-In the seminar you will provide the updated version of your decision -model.
-To add correlation to your model visit the Adding -correlations to Decision Analysis models vignette.
-Welcome to lecture 11 of Decision Analysis and Forecasting -for Agricultural Development. Feel free to bring up any -questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-The results of a Monte Carlo model are not always easy to interpret -and to communicate about. One important step in communicating these -often very large data sets is with good visualization. In previous -lectures and seminars we have covered the basics of plotting the -distributions of model results for comparisons between decision options. -In this lecture we will build on what we learned in the Decision Models lecture and the Model programming seminar to learn -more about how to generate useful plots for communicating model -results.
-In the Model programming
-seminar we generated a model called example_mc_simulation
.
-As a quick refresher change the plot of the results of that model from
-hist_simple_overlay
to boxplot_density
by
-using the method
argument in the
-plot_distributions
function.
plot_distributions(mcSimulation_object = example_mc_simulation,
- vars = "final_result",
- method = "hist_simple_overlay",
- old_names = "final_result",
- new_names = "Outcome distribution for profits")
-
-plot_distributions(mcSimulation_object = example_mc_simulation,
- vars = "final_result",
- method = "boxplot_density",
- old_names = "final_result",
- new_names = "Outcome distribution for profits")
-We can use the compound_figure
function to create a
-simple compound figure of model results and analyses of a binary
-decision (do or do not do). The figure includes the distribution of the
-expected outcome, the expected cashflow, as well as the variable
-importance and the value of information.
# Create the estimate object:
-
-cost_benefit_table <- data.frame(label = c("Revenue", "Costs"),
- variable = c("revenue", "costs"),
- distribution = c("norm", "norm"),
- lower = c(100, 500),
- median = c(NA, NA),
- upper = c(10000, 5000))
-
-# (a) Define the model function without name for the return value:
-
-profit1 <- function() {
- Decision <- revenue - costs
- cashflow <- rnorm(rep(revenue, 20))
- return(list(Revenues = revenue,
- Costs = costs,
- cashflow = cashflow,
- Decision = Decision))
-}
-
-compound_figure(model = profit1,
-input_table = cost_benefit_table,
-decision_var_name = "Decision",
-cashflow_var_name = "cashflow",
-model_runs = 1e2,
-distribution_method = 'smooth_simple_overlay')
-
-Here we demonstrate a few more various graphical options to visualize
-uncertainty intervals of outcomes of Monte Carlo simulations. We create
-a data set of yield distributions of three different farming practices
-and use the function mcmc_intervals()
from the
-bayesplot
library to plot the data set (Gabry and Mahr 2022).
test <- data.frame("practice 1" = rnorm(n = 1000, mean = 8, sd = 1.5),
- "practice 2" = rnorm(n = 1000, mean = 7, sd = 1),
- "practice 3" = rnorm(n = 1000, mean = 5, sd = 0.5))
-
-
-color_scheme_set("red")
-mcmc_intervals(test,prob = 0.5,prob_outer = 0.9,point_est = "median")
-
-Do the same with the with mcmc_areas()
function from the
-bayesplot
library (Gabry and Mahr
-2022).
test <- data.frame("practice 1" = rnorm(n = 1000, mean = 8, sd = 1.5),
- "practice 2" = rnorm(n = 1000, mean = 7, sd = 1),
- "practice 3" = rnorm(n = 1000, mean = 5, sd = 0.5))
-
-color_scheme_set("blue")
-
-mcmc_areas(test,prob = 0.9,point_est = "median")
-
-We can also use geom_density()
in ggplot2
to
-compare the spread of different distributions (Wickham, Chang, et al. 2023):
test <- data.frame("practice 1" = rnorm(n = 1000, mean = 8, sd = 1.5),
- "practice 2" = rnorm(n = 1000, mean = 7, sd = 1),
- "practice 3" = rnorm(n = 1000, mean = 5, sd = 0.5))
-
-stacked_test <- stack(test)
-
-ggplot(stacked_test,
- aes(x=values,group=ind,fill=ind )) +
- geom_density(colour=NA,alpha=.5) +
- ylab("Probability density") +
- xlab("Yield")
-
-Use ggplot2
geom_histogram()
function to
-show the histogram of the data in comparison:
test <- data.frame("practice 1" = rnorm(n = 1000, mean = 8, sd = 1.5),
- "practice 2" = rnorm(n = 1000, mean = 7, sd = 1),
- "practice 3" = rnorm(n = 1000, mean = 5, sd = 0.5))
-
-stacked_test <- stack(test)
-
-ggplot(stacked_test,aes(x=values))+
- geom_histogram(data=subset(stacked_test,ind =='practice.1'),
- aes(fill = ind), alpha = 0.5, bins = 150) +
- geom_histogram(data=subset(stacked_test,ind == 'practice.2'),
- aes(fill = ind), alpha = 0.5, bins = 150) +
- geom_histogram(data=subset(stacked_test,ind == 'practice.3'),
- aes(fill = ind), alpha = 0.5, bins = 150)
-
-The plot_cashflow
function from the
-decisionSupport
package (Luedeling
-et al. 2023) creates a cashflow plot of the returned list of
-related outputs from the mcSimulation
function using
-ggplot2 (Wickham, Chang, et al. 2023). The
-function automatically defines quantiles (5 to 95% and 25 to 75%) as
-well as a value for the median.
# Plotting the cashflow:
-
-# Create the estimate object (for multiple options):
-
-variable = c("revenue_option1", "costs_option1", "n_years",
- "revenue_option2", "costs_option2")
-distribution = c("norm", "norm", "const", "norm", "norm")
-lower = c(10000, 5000, 20, 8000, 500)
-upper = c(100000, 50000, 20, 80000, 30000)
-
-costBenefitEstimate <- as.estimate(variable, distribution, lower, upper)
-
-# Define the model function without name for the return value:
-
-profit1 <- function(x) {
-
-cashflow_option1 <- vv(revenue_option1 - costs_option1, n = n_years, var_CV = 100)
-cashflow_option2 <- vv(revenue_option2 - costs_option2, n = n_years, var_CV = 100)
-
-return(list(Revenues_option1 = revenue_option1,
- Revenues_option2 = revenue_option2,
- Costs_option1 = costs_option1,
- Costs_option2 = costs_option2,
- Cashflow_option_one = cashflow_option1,
- Cashflow_option_two = cashflow_option2))
-}
-
-# Perform the Monte Carlo simulation:
-
-predictionProfit1 <- mcSimulation(estimate = costBenefitEstimate,
- model_function = profit1,
- numberOfModelRuns = 10000,
- functionSyntax = "plainNames")
-
-
-# Plot the cashflow distribution over time
-
-plot_cashflow(mcSimulation_object = predictionProfit1, cashflow_var_name = "Cashflow_option_one",
- x_axis_name = "Years with intervention",
- y_axis_name = "Annual cashflow in USD",
- color_25_75 = "green4", color_5_95 = "green1",
- color_median = "red")
-
-Plot the cashflow with panels to compare the cashflow distribution -over time for multiple decision options:
-# Plotting the cashflow:
-
-# Create the estimate object (for multiple options):
-
-variable = c("revenue_option1", "costs_option1", "n_years",
- "revenue_option2", "costs_option2")
-distribution = c("norm", "norm", "const", "norm", "norm")
-lower = c(10000, 5000, 10, 8000, 500)
-upper = c(100000, 50000, 10, 80000, 30000)
-
-costBenefitEstimate <- as.estimate(variable, distribution, lower, upper)
-
-# Define the model function without name for the return value:
-
-profit1 <- function(x) {
-
-cashflow_option1 <- vv(revenue_option1 - costs_option1, n = n_years, var_CV = 100)
-cashflow_option2 <- vv(revenue_option2 - costs_option2, n = n_years, var_CV = 100)
-
-return(list(Revenues_option1 = revenue_option1,
- Revenues_option2 = revenue_option2,
- Costs_option1 = costs_option1,
- Costs_option2 = costs_option2,
- Cashflow_option_one = cashflow_option1,
- Cashflow_option_two = cashflow_option2))
-}
-
-# Perform the Monte Carlo simulation:
-
-predictionProfit1 <- mcSimulation(estimate = costBenefitEstimate,
- model_function = profit1,
- numberOfModelRuns = 10000,
- functionSyntax = "plainNames")
-
-plot_cashflow(mcSimulation_object = predictionProfit1,
- cashflow_var_name = c("Cashflow_option_one", "Cashflow_option_two"),
- x_axis_name = "Years with intervention",
- y_axis_name = "Annual cashflow in USD",
- color_25_75 = "green4", color_5_95 = "green1",
- color_median = "red",
- facet_labels = c("Option 1", "Option 2"))
-
-This week we will read and discuss chapter four of Hubbard’s ‘How To -Measure Anything’.
-Hubbard, Douglas W. How To Measure Anything: Finding the Value of -Intangibles in Business. 2nd ed. Vol. Second Edition. Hoboken, New -Jersey: John Wiley & Sons, 2014.
-Here we use R’s built in OrchardSprays
data to run the
-example from the tidyverse
Violin
-plot examples (Wickham 2023b).
ggplot(OrchardSprays, aes(y = decrease, x = treatment, fill = treatment))+
- geom_violin() +
- geom_boxplot(width = 0.1) +
- theme(legend.position = "none")
-
-A variation on the example from edav using the
-ggridges
library (Wilke
-2022).
ggplot(OrchardSprays,
- aes(x=decrease,y = treatment,fill = treatment)) +
- geom_density_ridges_gradient(scale=2) +
- theme_ridges() +
- theme(legend.position = "none")
-
-More examples on the rdrr.io
CRAN
-website.
To see more options for plotting high dimensional data visit the High -Domensional Data vignette.
-Welcome to the eleventh seminar of Decision Analysis and -Forecasting for Agricultural Development. Feel free to bring up -any questions or concerns in the Slack or to Dr. Cory -Whitney or the course tutor.
-In this seminar we will build on some of the things we learned in the -Using RMarkdown seminar. We will use Rmarkdown (Allaire et al. 2023) to create a report on our -R code.
-To run this you will need to load library(rmarkdown)
and
-library(knitr
).
Find the RMD file and bib files referenced in the video in the RMarkdown_template -Git repository.
-RMarkdown_options.png
----
. The language within these marks is known as YAML and
-sets the general layout and format of your document.In case of repeated formatting in different code chunks we can use
-the knitr
opts.label
option to reuse what we
-wrote and avoid repetition (Xie (2023)).
-Following the Don’t
-Repeat Yourself (DRY) principle.
You can host your html files in your github repository with the
-htmlpreview.github.io
tools.
The website hosting the raw html file for this course is:
-http://htmlpreview.github.io/?https://github.com/CWWhitney/Decision_Analysis_Course/blob/main/Index.html
This works with the htmlpreview.github.io
by taking
-adding http://htmlpreview.github.io/?
to the first part of
-the link to the html file in an open access github repository
-https://github.com/CWWhitney/Decision_Analysis_Course/blob/main/Index.html
.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +} +###### Run HAIL Risk model ####### +hail_mc_simulation <- mcSimulation(estimate = as.estimate(hail_estimates), + model_function = hail_function, + numberOfModelRuns = 100, + functionSyntax = "plainNames") - - - +###### HAIL Risk evpi ####### +mcSimulation_table_hail <- data.frame(hail_mc_simulation$x, + hail_mc_simulation$y[3]) - - - +evpi_hail <- multi_EVPI(mc = mcSimulation_table_hail, + first_out_var = "NPV_decision") - - -