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.

<strong>Using</strong> R <strong>for</strong> introductory statistics 322three onto one graphic, one of the factors is selected as the trace factor. Different lineswill be drawn <strong>for</strong> each level of this factor. Fix a level, <strong>for</strong> now, of the trace factor. Foreach level of the main factor, the mean of the data where both levels occur is plotted as apoint. These points are then connected with a line segment. Repeat <strong>for</strong> the other levels ofthe trace factor. If the line segments <strong>for</strong> each level of the trace factor are roughly parallel,then no interaction is indicated. If the lines differ dramatically, then an interaction isindicated.This graphic is made with the function interaction.plot(). The template isinteraction.plot(f, trace.factor, y, legend=TRUE)The response variable is stored in y, the f holds the main factor, and the other is in trace.factor. By default, a legend will be drawn indicating the levels of the trace factor.For our example, Figure 11.7 is made with the following commands. The linesegments are nearly parallel, indicating that no interaction is present.> interaction.plot(driver,car,x)Significance test <strong>for</strong> presence of interactionsTo test the hypothesis of no interaction <strong>for</strong>mally we can use the partial F-test. The nullhypothesis can be expressed as γ ij =0 in (11.8) or, <strong>for</strong> our car-and-driver example, asβ 5 =β 6 =0 from Equation (11.9). For our car-and-driver example, this is done by comparingthe models with and without interaction.Specifying an interaction in a model <strong>for</strong>mula An interaction can be specified indifferent ways in the model <strong>for</strong>mula. The symbol :, used as f1:f2, will introduce theinteraction terms <strong>for</strong> the two factors. Whereas *, as in f1*f2, willFigure 11.7 Interaction plot <strong>for</strong> carand-driverdata. The lines are nearlyparallel, indicating no interaction.introduce not only an interaction, but the main effects, f1+f2, as well. Finally, the powernotation, ^, as in (f1+f 2) ^2, will do the main effects and all possible interactions up toorder 2. This generalizes with higher powers and more terms. For our example with two

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

Saved successfully!

Ooh no, something went wrong!