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.

<strong>Using</strong> R <strong>for</strong> introductory statistics 258D = 0.2125, p-value = 0.001456alternative hypothesis: two.sided9.3.2 The Shapiro-Wilk test <strong>for</strong> normalityThe Kolmogorov-Smirnov test <strong>for</strong> a univariate data set works when the distribution in thenull hypothesis is fully specified prior to our looking at the data. In particular, anyassumptions on the values <strong>for</strong> the parameters should not depend on the data, as this canchange the sampling distribution. Figure 9.5 shows the sampling distribution of theKolmogorov-Smirnov statistic <strong>for</strong> Normal(0, 1) data and the sampling distribution of theKolmogorov-Smirnov statistic <strong>for</strong> the same data when the sample values of and s areused <strong>for</strong> the parameters of the normal distribution (instead of 0 and 1). The figure wasgenerated with this simulation:> res.1 res.2 = c()> <strong>for</strong>(i in 1:500) {+ x = rnorm(25)+ res.1[i] = ks.test(x,pnorm)$statistic+ res.2[i] = ks.test(x,pnorm,mean(x),sd(x))$statistic+}> plot(density(res.1),main="K-S sampling distribution”)> lines(density(res.2),lty=2)(To retrieve just the value of the test statistic from the output of ks.test() we takeadvantage of the fact that its return value is a list with one component named statisticcontaining the desired value. This is why the syntax ks. test (…) $statistic is used.)Figure 9.5 The sampling distribution<strong>for</strong> the Kolmogorov-Smirnovstatistic when the parameters areestimated (dashed line) and whennot

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

Saved successfully!

Ooh no, something went wrong!