Chapter 5. Assessing the Situation

With our data prepared for analysis, we can now consider the potential combat options available to the Shu army. Ultimately, you have the responsibility to use these data to make practical and meaningful decisions about future courses of action. To achieve success, you will need to fully consider the situation and form a sound basis for reasoned decision-making. This requires you to build upon the techniques that we practiced in Chapter 4 and to explore new ones in R.

In this chapter, we will focus on assessing the information that is available to us and using it to weigh potential decisions. By the end of this chapter, you will be able to:

  • Use multi-argument and variable-argument functions to perform calculations
  • Create predictive models using regression analysis
  • Consider the statistical and practical significance of your analyses

Time for action - making an initial inference from our data

In Chapter 4, we saved our R workspace for the first time. As you saw in the previous chapter, we can use the load(file) function to continue where we left off.

You also created variables to hold the mean number of soldiers engaged for the Shu and Wei forces, based on historical data from 120 battles between the kingdoms. Let us make an initial inference about these values:

  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 5 workspace. It contains the information that we generated in Chapter 4 and will continue to work on in this chapter:
    > #load the chapter 5 workspace
    > load("rBeginnersGuide_Ch_05_ReadersCopy.RData")
    > #verify the contents of the workspace
    >ls()
    
  3. Display the mean number of Shu and Wei soldiers engaged in past battles. We saved these values into variables in the previous chapter.
    > #mean number of Shu soldiers engaged in battle
    > meanSoldiersShu
    [1] 21035.83
    > #mean number of Wei soldiers engaged in battle
    > meanSoldiersWei
    [1] 21937.5
    
  4. Calculate the ratio of mean Wei soldiers to Shu soldiers and save it to a new variable named meanSoldierRatioWeiShu. Then display the result:
    > #ratio of mean Wei soldiers to Shu soldiers
    > meanSoldierRatioWeiShu <- meanSoldiersWei / meanSoldiersShu
    > #display the contents of meanSoldierRatioWeiShu
    > meanSoldierRatioWeiShu
    [1] 1.042863
    
  5. Predict the number of Wei soldiers that would engage in combat if the Shu prepared 100,000 soldiers for battle:
    > #how many Wei soldiers would we expect to engage in battle if our Shu forces numbered 100,000?
    > 100000 * meanSoldierRatioWeiShu
    [1] 104286.3
    

What just happened?

After preparing R, we used our historic battle data to calculate the ratio of the mean Wei soldiers engaged in past conflicts to the mean number of Shu soldiers. The ratio value of 1.04 suggests that the Wei army brings roughly 4% more soldiers into battle than Shu does on average. We can use this ratio in our predictions and plans for future battles. In general, we expect the Shu army to be outnumbered regardless of the conflict. Inferences like this one may have implications for the combat strategies that we choose to employ.

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

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