10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Multivariate data 10310 Y N Y N Nany trends quickly. We would like to be able to summarize such data flexibly. We’veused the table() function to make two-way tables. We can use it here as well. Let’s lookat the relationship between having a cell phone and a car:> library(<strong>Using</strong>R) # once per session> attach(student.expenses)> names(student.expenses)[1] "cell.phone" "cable.tv" “dial.up" "cable.modem"[5] "car"> table(cell.phone,car)carcell.phone N YN 1 2Y 3 4In this small sample, almost all the students have at least one of the two, with both beingmost common.Three-way contingency tables (or, more generally, n-way contingency tables) showrelationships among three (or n) variables using tables. We fix the values of the extravariable(s) while presenting a two-way table <strong>for</strong> the main relationship. To investigatewhether paying <strong>for</strong> a cable modem affects the relationship between having a cell phoneand a car, we can use a three-way table.> table(cell.phone,car,cable.modem), , cable.modem = Ncarcell.phone N YN 1 2Y 2 3, , cable.modem = Ycarcell.phone N YN 0 0Y 1 1It appears that paying <strong>for</strong> a cable modem requires cutbacks elsewhere.The table() function uses the first two variables <strong>for</strong> the main tables and the remainingvariables to construct different tables <strong>for</strong> each combination of the variables. In this case,two other tables <strong>for</strong> the levels of cable. modem.Flattened contingency tablesThis type of in<strong>for</strong>mation is usually <strong>for</strong>matted differently to save space. In Table 4.2 thetables are set side-by-side, with the column headings layered to indicate the levels of theconditioning factor.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!