Rather than plugging in values to calculate the outcome of a specific scenario, suppose that we instead choose to determine the resources necessary to realize a desired result. In other words, a different way to approach the challenge of developing a successful battle plan is to set our required outcome, say a Rating
of 80, and then solve for the number of soldiers or other resources needed to achieve that outcome. We can make this process possible through the use of custom functions.
The following procedure describes how to determine the amount of resources needed to achieve a Rating
of 80 in our ambush regression model:
> #rearrange the ambush model to solve for the number of Shu soldiers engaged > #original ambush model: Rating = 56 + 44 * execution - 1.97 * duration + 0.0018 * Shu soldiers - 0.00082 * Wei soldiers > #ambush model solved for Shu soldiers: (Rating - 56 - 44 * execution + 1.97 * duration + .0.00082 * Wei soldiers) / 0.0018
> #convert the rearranged ambush model equation into a custom function > functionAmbushShuSoldiers <- function(rating, execution, duration, WeiSoldiers) { + (rating - 56 - 44 * execution + + 1.97 * duration + + 0.00082 * WeiSoldiers) / + 0.0018 + }
> #how many Shu soldiers must be engaged in an ambush attack against 10,000 Wei soldiers to bring our rating to 80? > functionAmbushShuSoldiers(80, probabilitySuccessAmbush, meanDurationAmbush, 10000) [1] 20551.11 > #how many Shu soldiers must be engaged in an ambush attack against 10,000 Wei soldiers to bring our rating to 80 if we are certain of successful execution? > functionAmbushShuSoldiers(80, 1, meanDurationAmbush, 10000) [1] 8328.889
Each of our regression equations can be rearranged in the same manner as our ambush model. By solving for the number of Shu soldiers in our combat models, we can calculate the amount of resources that our army must expend in specific situations. This approach allows us to focus on determining the amount of resources required to achieve our desired outcomes.
We again employed the function()
command to create a custom function based on one of our regression models. This activity represented a resource-focused approach to predicting the outcomes of potential battle situations.
Use the function()
command to create resource-focused custom functions for each of the remaining battle methods head to head, surround, and fire. Save these custom functions into new R variables, named appropriately for the data variable that you focused on. For example, our ambush function in the previous activity solved for the number of Shu soldiers engaged and thus was named functionAmbushShuSoldiers
. Afterwards, test each of your functions using hypothetical battle data.