| Posted on September 10, 2013 @ 07:25:00 AM by  Paul Meagher 
In my previous blog, I showed how to construct a nice decision tree for a decision 
about how much nitrogen to apply to a crop.  In this blog, I want to advance our thinking about decision trees in two ways:
 
Show how expected returns can be calculated using PHP.Discuss the issue of how detailed we should get when constructing a decision tree. Computing Expected Return
In my blog titled Computing Expected Values I referred you to a video tutorial 
on how to calculate expected values.  In this blog, I will implement that calculation in a PHP script.  Implementing the calculation 
programmatically allows us to see what types of data structures need to be defined and how they looped over in order to compute 
expected returns.  We need a data structure to represent our actions (i.e., a $nitrogenarray), our 
events (i.e., a$weather), our outcomes (i.e., a$payoffsmatrix), and to store the expected returns 
that are computed for each action option (i.e., an$EVarray).   With these basic elements in place we can 
compute our expected values in a straightforward manner as illustrated in the code below: 
 
The output of this script looks like this:
 
 
Array
(
    [lo] => 6900
    [med] => 7900
    [hi] => 8900
)
These are the expected returns for low, medium, and high levels of nitrogen application and correspond to the expect returns that 
appeared in the decision tree appearing in my last blog.
 Levels of Detail
The decision tree we have constructed to represent a nitrogen application decision is vague in many of its details and, as such, 
would be difficult to use for the purposes of making an actual decision about whether to apply nitrogen or not.
 
Our biggest omission is to just talk about an "expected return" without talking specifically about whether this is expected 
revenue, expected profit, or expected utility.  If our payoffs are expected revenue amounts then our decision tree is not going to 
be that useful because it hides the costs involved.  For this reason, the expected profit would be a better value to compute as 
our "payoffs" rather than expected revenues.  Theoretically, an even better value to compute would be the expected utility 
associated with each action option but that is a tricky value to compute because it depends on subjective factors and more complex
formulas.  For this reason, we can be satisfied if we can at least compute expected profits for each decision option.
 
Another omission in our decision tree is any discussion of the costs associated with each proposed action.  In order to compute
such costs we must get detailed about the when, where, and how of applying nitrogen.  We also need to estimate the price 
of nitrogen at the time of application.  If we have already purchased our nitrogen then this would simplify our calculations.
Other costs include the cost of fuel to apply our nitrogen.  We also need to be specific about what crop we are applying our 
nitrogen to.  In order to compute expected profits we would need to compute some other costs associated with planting, 
cultivating, and harvesting the crop per acre so that these can be subtracted from the overall revenue generated to compute 
our expected profits.
 
Our nitrogen application decision is impacted by weather which we have characterized as poor, average, or good.  This is also 
not very precise and would need to be specified in more detail.  Weather could specifically mean rainfall amounts in the spring 
phase of the year.  
 
Once we get very specific about costs and what our variables specifically refer to, then our decision tree would provide better 
guidance on how to act.  The visual depiction of a decision as a decision tree helps to organize our research efforts but it 
omits much of the research work that will have gone into making the decision tree useful and realistic. 
 |