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 256with n=25 <strong>for</strong> normal, uni<strong>for</strong>m, t, andexponential datacan be constructed with test statistic D. Large values of D support the alternativehypothesis.In R, this test is implemented in the function ks.test(). Its usage follows this pattern:ks.test(x, y=“name”, …)ZThe variable x stores the data. The argument y= is used to set the family name of thedistribution in H 0 . It has a character value of “name” containing the “p” function thatreturns the c.d.f. <strong>for</strong> the family (e.g., “pnorm” or “pt”). The…argument allows thespecification of the assumed parameter values. These depend on the family name and arespecified as named arguments, as in mean= 1, sd= 1. The parameter values should not beestimated from the data, as this affects the sampling distribution of D.If we have two i.i.d. independent samples X 1 , …, X n and Y 1 , …, Y m , from twocontinuous distributions F X and F Y , then a significance test ofH 0 :F X =F Y , H A :F X ≠F Ycan be constructed with a similar test statistic:In this case, the ks.test() can be used asks.test(x,y)where x and y store the data.We illustrate with some simulated data.> x = rnorm(100,mean=5, sd=2)> ks.test(x,"pnorm",mean=0,sd=2) # "wrong" parametersOne-sample Kolmogorov-Smirnov testdata: xD = 0.7578, p-value = < 2.2e-16alternative hypothesis: two.sided> ks.test(x,"pnorm",mean=5,sd=2) # correct populationparameters...D = 0.1102, p-value = 0.1759...> x = runif(100, min=0, max=5)> ks.test(x,"punif",min=0,max=6) # "wrong" parameters...D = 0.1669, p-value = 0.007588...> ks.test(x,"punif",min=0,max=5) # correct populationparameters...

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

Saved successfully!

Ooh no, something went wrong!