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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Analysis of variance 323factors, all three of these model <strong>for</strong>mulas are equivalent:fl+f2+f1:f2, f1*f2, and(f1+f2)^2.To proceed, we save the model with an interaction and then use anova () to comparenested models.> Im.int=1m(x ~ car * driver)> 1m.add=1m(x ~ car + driver)> anova(lm.add,1m.int)Analysis of Variance TableModel 1: x ~ car + driverModel 2: x ~ car * driverRes.Df RSS Df Sum of Sq F Pr(>F)1 14 1.3142 12 1.280 2 0.034 0.16 0.85The large p-value is consistent with Figure 11.7, indicating no interaction.■ Example 11.10: Factors in movie enjoyment The proprietors of a movie housewant to maximize their customers’ movie-going experience. In particular, they want toknow whether either eating popcorn or sitting in more com<strong>for</strong>table seats makes adifference in customer enjoyment. They randomly assign 16 people equally to the fourpossible combinations and then ask them to rate the same movie on a 0–100 scale. Thedata is in Table 11.6.The data is entered in with> x = scan()1:92 80 80 78 63 65 65 69 60 59 57 51 60 58 52 6517:Read 16 itemsTable 11.6 Factors affecting movie enjoyment> Seat=factor(rep(c("Good","Bad"),c(8,8)))> Popcorn=factor(rep(rep(c("Y","N"),c(4,4)), 2))seat type good badpopcorn yes 92 80 80 78 60 59 57 51no 63 65 65 69 60 58 52 65We can check our numbers using xtabs() and ftable(). First we add a variable to keep thedata from being summed. ‡> replicate = rep(1:4,4)> ftable(xtabs(x ~ Popcorn + Seat + replicate))replicate 1 2 3 4Popcorn SeatN Bad 60 58 52 65Good 63 65 65 69Y Bad 60 59 57 51Good 92 80 80 78

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

Saved successfully!

Ooh no, something went wrong!