18 1. Summarizing Data Sepal.Width 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 Figure 1.10. A scatterplot made with xyplot(Sepal.Length∼Sepal.Width,iris). For each case they noted the race of the defendant and whether or not the death penalty was imposed. We can use R to cross tabulate this data for us: intro-deathPenalty01 xtabs(~Penalty+Victim,data=deathPenalty) Victim Penalty Black White Death 6 30 Not 106 184 Perhaps you are surprised that white defendants are more likely to receive the death penalty. It turns out that there is more to the story. The researchers also recorded the race of the victim. If we make a new table that includes this information, we see something interesting. intro-deathPenalty02 xtabs(~Penalty+Defendant+Victim, + data=deathPenalty) , , Victim = Black Defendant Penalty Black White Death 6 0 Not 97 9 , , Victim = White Defendant Penalty Black White Death 11 19 Not 52 132 Sepal.Width 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 ●● ●● ●● ●● setosa 2.0 2.5 3.0 3.5 4.0 4.5 ●● ●●● ●● ●● ●●● versicolor 2.0 2.5 3.0 3.5 4.0 4.5 ●● ●● ●● ●●● ●● ●● virginica Sepal.Width 5 6 7 8 2.0 2.5 3.0 3.5 4.0 4.5 setosa versicolor virginica L Figure 1.11. The output of xyplot(Sepal.Length∼Sepal.Width|Species,iris) and xyplot(Sepal.Length∼Sepal.Width,groups=Species,iris,auto.key=TRUE). Sepal.Length Sepal.Length Sepal.Length
Previous Page Next Page