12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

Comparing Two SamplesComparing groups is one of the most basic problems in statistics. If you wantto know if extra vitamins in the diet of cows is increasing their milk production, yougive the normal diet to a control group and extra vitamins to a test group, and thenyou compare the milk production in two groups. By comparing the mileagebetween cars with automatic gearboxes and those with manual gearboxes, you canfind out which one is the more economical option.Testing differencesR gives you two standard tests for comparing two groups with numerical data:the t-test with the t.test() function, and the Wilcoxon test with the wilcox.test()function. If you want to use the t.test() function, you first have to check, amongother things, whether both samples are normally distributed using any of themethods from the previous section. For the Wilcoxon test, this isn’t necessary.Carrying out a t-testLet’s take another look at the data of that beaver. If you want to know if theaverage temperature differs between the periods the beaver is active and inactive,you can do so with a simple command:> t.test(temp ~ activ, data=beaver2)Welch Two-Sample t-testdata: temp by activt = -18.5479, df = 80.852, p-value < 2.2e-16alternative hypothesis: true difference in means is not equal to 095 percent confidence interval:-0.8927106 -0.7197342sample estimates:mean in group 0 mean in group 137.09684 37.90306Normally, you can only carry out a t-test on samples for which the variancesare approximately equal. R uses Welch’s variation on the t-test, which correctsfor unequal variances.You get a whole lot of information here:

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

Saved successfully!

Ooh no, something went wrong!