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 301> SSE=(5–1)*var(may)+(5–1)*var(sep)+(5–1)*var(dec)> SSE[1] 586720> F.obs=(SST/(3–1)) / (SSE/(15–3))> pf(F.obs,3–1,15–3,lower.tail=FALSE)[1] 0.2094We get a p-value that is not significant. Despite the graphical evidence, the differencescan be explained by sampling variation. ■11.1.1 <strong>Using</strong> R’s model <strong>for</strong>mulas to specify ANOVA modelsThe calculations <strong>for</strong> analysis of variance need not be so complicated, as R has functionsto compute the values desired. These functions use model <strong>for</strong>mulas. If x stores all thedata and f is a factor indicating which group the data value belongs to, thenx~frepresents the statistical modelX ij =µ i +ε ij .In Chapter 4 we remarked that the default behavior <strong>for</strong> plot() of the model <strong>for</strong>mula x ~ fwas to make a boxplot. This is because this graphic easily allows <strong>for</strong> comparison ofcenters <strong>for</strong> multiple samples. The strip chart in Figure 11.1 is good <strong>for</strong> a small data set,but the boxplot is preferred when there are larger data sets.11.1.2 <strong>Using</strong> oneway.test() to per<strong>for</strong>m ANOVAThe function oneway. test() is used asoneway test(x~f, data=…, var.equal=FALSE)As with the t.test function, the argument var. equal=is set to TRUE if appropriate. Bydefault it is FALSE.Be<strong>for</strong>e using oneway. test() with our example of caloric intake, we put the data intothe appropriate <strong>for</strong>m: a data vector containing the values and a factor indicating thesample the corresponding value is from. This can be done using stack().> d = stack(list(may=may,sep=sep,dec=dec)) # need names<strong>for</strong> list> names(d) # stack returns twovariables[1] "values" "ind"> oneway.test(values ~ ind, data=d, var.equal=TRUE)One-way analysis of meansdata: values and indF = 1.786, num df = 2, denom df = 12, p-value = 0.2094We get the same p-value as in our previous calculation, but with much less ef<strong>for</strong>t.

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

Saved successfully!

Ooh no, something went wrong!