Time for action - model deployment

Having selected the optimal model for predicting the outcome of our fire attack strategy, it is time to put that model to practical use. We can use it to predict the outcomes of various fire attack strategies and to identify one or more strategies that are likely to lead to victory. Subsequently, we need to ensure that our winning strategies are logistically sound and viable. Once we strike a balance between our designed strategy and our practical constraints, we will arrive at the best course of action for the Shu forces.

Recall from Chapter 6 that we set a rating value of 80 as our minimum threshold. As such, we will only consider a strategy adequate if it yields a rating of 80 or higher when all variables have been entered into our model.

In the case of our fire attack regression model, we know that to achieve our desired rating value, we must assume successful execution. We also know the number of Wei soldiers housed at the target city. Consequently, our major constraints are the number of Shu soldiers that we choose to engage in battle and the duration of the attack. We will assume a moderate attack duration.

Subsequently, we can rearrange our regression equation to solve for the number of Shu soldiers engaged and then represent it as a custom function in R:

  1. Use the coef(object) function to isolate the independent variables in our regression model:
    > #use the coef(object) function to extract the coefficients
    from a regression model
    > #this will make it easier to rearrange our equation by
    allowing us to focus only on these values
    > coef(lmFireRating_ExecutionDurationShuWeiInteraction)
    
    Time for action - model deployment
  2. Rewrite the fire attack regression equation to solve for the number of Shu soldiers engaged in battle:
    > #rewrite the regression equation to solve for the number of
    Shu soldiers engaged in battle
    > #original equation: rating = 37 + 56 * execution - 1.24 *
    duration - 0.00000013 * soldiers interaction
    > #rearranged equation: Shu soldiers = (rating - 37 + 56 *
    execution + 1.24 * duration) / (0.00000013 * -
    Wei soldiers engaged)
    
  3. Use the function() command to create a custom R function to solve for the number of Shu soldiers engaged in battle, given the desired rating, execution, duration, and number of WeiSoldiers:
    > #use function() to create a custom function in R
    > #the function() command follows this basic format:
    + function(argument1, argument2,... argumenti) { equation }
    > #custom function that solves for the maximum number of Shu
    soldiers that can be deployed, given the desired rating,
    execution, duration, and number of Wei soldiers
    > functionFireShuSoldiers <- function(rating, execution,
    duration, WeiSoldiers) {
    + (rating - 37 - 56 * execution +
    + 1.24 * duration) /
    + (0.00000013 * - WeiSoldiers)
    + }
    
  4. Use the custom function to solve for the number of Shu soldiers that can be deployed, given a rating of 80, duration of 7, success of 1.0, and 10,000 WeiSoldiers:
    > #solve for the number of Shu soldiers that can be deployed
    given a result of 80, duration of 7, success of 1.0, and
    15,000 WeiSoldiers
    > functionFireShuSoldiers(80, 1.0, 7, 10000)
    [1] 3323.077
    

Our regression model suggests that to achieve a rating of 80, our minimum threshold, we should deploy 3,323 Shu soldiers. However, from looking at the data in our fire attack subset, a force between 2,500 and 5,000 soldiers has not been previously used to launch a fire attack. Further, four past successful fire attacks on 7,500 to 12,000 Wei soldiers have deployed only 1,000 to 2,500 Shu soldiers. What would happen to our predicted rating value if we were to deploy 2,500 Shu soldiers instead of 3,323?

  1. Create a custom function to solve for the rating of battle when execution, duration, and number of ShuSoldiers and WeiSoldiers are known:
    > #custom function that solves for rating of battle, given the
    execution, duration, number of Shu soldiers, and number of Wei
    soldiers
    > functionFireRating <- function(execution, duration,
    ShuSoldiers, WeiSoldiers) {
    + 37 + 56 * execution -
    + 1.24 * duration -
    + 0.00000013 * (ShuSoldiers * WeiSoldiers)
    + }
    
  2. Use the custom function to solve for the rating of battle, given successful execution, a 7-day duration, 2,500 Shu soldiers, and 10,000 Wei soldiers:
    > What would happen to our rating value if we were to deploy
    2,500 Shu soldiers instead of 3,323?
    > functionFireRating(1.0, 7, 2500, 10000)
    [1] 81.07
    > #Is the 1.07 increase in our predicted chances for victory
    worth the practical benefits derived from deploying 2,500
    soldiers?
    

By using 2,500 soldiers, our rating value increased to 81, which is slightly above our threshold of confidence for victory. Here, we have encountered a classic dilemma for the data analyst. On one hand, our data model tells us that it is safe to use 3,323 soldiers. On the other, our knowledge of war strategy and past outcomes tells us that a number between 1,000 and 2,500 would be sufficient. Essentially, we have to identify the practical benefits or detriments from deploying a certain number of soldiers. In this case, we are inclined to think that it is beneficial to deploy fewer than 3,323, but more than 1,000. The exact number is a matter of debate and uncertainty that deserves serious consideration. It is always the strategist's challenge to weigh both the practical and statistical benefits of potential decisions. On that note, let us consider the logistics of our proposed fire attack. Our plan is to deploy 2,500 Shu soldiers over a period of 7 days to attack 10,000 Wei soldiers who are stationed 225 miles away.

  1. Create a custom function that calculates the gold cost of our fire attack strategy:
    > #custom function that calculates the gold cost of our
    strategy, given the number of Shu soldiers deployed, the
    distance of the target city, and the proposed duration of
    battle.
    > functionGoldCost <- function(ShuSoldiers, distance, duration)
    + {
    + ShuSoldiers * (distance / 100 + 2 * (duration / 30))
    + }
    
  2. Use the custom function to calculate the gold cost of our fire attack strategy:
    > #gold cost of fire attack that deploys 2,500 Shu soldiers
    a distance of 225 miles for a period of 7 days
    > functionGoldCost(2500, 225, 7)
    [1] 6791.667
    
  3. Calculate the number of provisions needed for our fire attack strategy:
    > #provisions required by our fire attack strategy
    > #consumption per 30 days is equal to the number of soldiers deployed
    > 2500 * (7/30)
    [1] 583.3333
    
  4. Determine whether the fire attack strategy is viable given our resource limitations:
    > #our gold cost of 6,792 is well below our allotment of 1,000,000
    > #our required provisions of 583 are well below our allotment of 1,000,000
    > #our 2,500 soldiers account for only 1.25% of our total army personnel
    > #yes, the fire attack strategy is viable given our resource constraints
    

What just happened?

We successfully used our optimal regression model to refine our battle strategy and test its viability in light of our practical resource constraints. Custom functions were used to calculate the number of soldiers necessary to yield our desired outcome, the performance rating given the parameters of our plan, and the overall gold cost of our strategy. In determining the number of soldiers to engage in our fire attack, we encountered a common occurrence whereby our data models conflicted with our practical understanding of the world. Subsequently, we had to use our expertise as data analysts to balance the consequences between the two and arrive at a sound conclusion. We then assessed the overall viability of our strategy and determined it to be sufficient in consideration of our resource allotments.

Note

For a more detailed discussion of the techniques used in this segment, refer to the Logistical Considerations section of Chapter 6.

coef(object)

Prior to rewriting our regression equation and converting it into a custom function, we executed the coef(object) command on our model. The coef(object) function, when executed on a regression model, has the effect of extracting and displaying its independent variables (or coefficients). By isolating these components, we were able to easily visualize our model's equation:

> coef(lmFireRating_ExecutionDurationShuWeiInteraction)
coef(object)

In contrast, the summary(object) function contains much more information than we need for this purpose, thus making it potentially confusing and difficult to locate our variables. This can be seen in the following:

> lmFireRating_ExecutionDurationShuWeiInteraction_Summary
coef(object)

Hence, in circumstances where we only care to see the independent variables in our model, the coef(object) function can be more effective than summary(object).

Pop quiz

  1. Under which of the following circumstances might you use the coef(object) function instead of summary(object)?

    a. You want to know the practical significance of the model's variables.

    b. You want to know the statistical significance of the model's variables.

    c. You want to know the model's regression equation.

    d. You want to know the formula used to generate the model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.60.220