Time for action - calculating outcomes from regression models

With our necessary assumptions decided upon, the simplest way to predict the outcome of a particular scenario is to plug relevant numbers into a regression model and calculate the result. Suppose we want to estimate the rating of an ambush attack when we know only the number of Shu soldiers that we will engage.

  1. Open R and set your working directory, as follows:
    > #set the R working directory
    > #replace the sample location with one that is relevant to you
    > setwd("/Users/johnmquick/rBeginnersGuide/")
    
  2. Load the Chapter 6 workspace. It contains the sample models, as well as our assumed variables:
    > #load the chapter six workspace
    > load("rBeginnersGuide_Ch_06_ReadersCopy.RData")
    
  3. Calculate the rating of an ambush attack in which the Shu forces engage 5,000 soldiers:
    > #what is the predicted rating of an ambush attack in which
    the Shu forces engage 5000 soldiers?
    >#ambush model: Rating = 56 + 44 * execution - 1.97 * duration
    + 0.0018 * Shu soldiers - 0.00082 * Wei soldiers
    > 56 + 44 * probabilitySuccessAmbush - 1.97 *
    meanDurationAmbush + 0.0018 * 5000 - 0.00082 * (5000 *
    ratioWeiShuSoldiersAmbush)
    [1] 52.746
    

Our calculated rating of 53 falls well below our threshold of 80 and suggests that the Shu army would have roughly an equal chance of winning or losing in this battle scenario.

What just happened?

We just employed the simplest, but most time consuming, method for predicting outcomes from our regression models. Let us make this process more efficient by creating a custom function in R that automatically calculates a solution when we provide the known values.

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

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