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 48variation. Just adding these values gives a value of 0, as terms cancel. A remedy is to addthe squared deviationsIf there is a lot of spread in the data, then this sum will be relatively large; if there isnot much spread, it will be relatively small. Of course, this sum can be large because n islarge, not just because there is much spread. We take care of that by dividing our sum bya scale factor. If we divided by n we would have the “average squared deviation.” It isconventional, though, to divide by n−1, producing the sample variance:We will see that many of the statistics we consider can be analyzed this way: one piecethat intuitively makes sense and a divisor that allows us to compare the statistic amongdifferent data sets.The sample standard deviation is the square root of the variance. It has theadvantage of having the same units as the mean. However, the interpretation remains:large values indicate more spread.The sample variance and standard deviationFor a numeric data set x 1 , x 2 , …, x n , the sample variance is defined by(2.3)The sample standard deviation is the square root of the sample variance:(2.4)The sample variance is computed in R using the var() function, the sample standarddeviation with the sd() function.To illustrate on the test-scores data:> test.scores = c(80,85,75,77,87,82,88)> test.scores.b = c(100,90,50,57,82,100,86)> mean(test.scores)[1] 82> mean(test.scores.b) # means are similar[1] 80.71> n = length(test.scores)# compute directly> (1/(n−1)) * sum( (test.scores − mean(test.scores))^2)[1] 24.67> var(test.scores) # built-in var function[1] 24.67

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

Saved successfully!

Ooh no, something went wrong!