Hi, does the shapiro wilk test in R-1.3.0 work correctly? Maybe it does, but can anybody tell me why the following sample doesn't give "W = 1" and "p-value = 1": R> x<-1:9/10;x [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 R> shapiro.test(qnorm(x)) Shapiro-Wilk normality test data: qnorm(x) W = 0.9925, p-value = 0.9986 I can't imagine a sample being more "normal" than this. Furthermore, the Kolmogorov-Smirnov test gives a p-value of 1. R> ks.test(qnorm(x),"pnorm",mean=0,sd=1) One-sample Kolmogorov-Smirnov test data: qnorm(x) D = 0.1, p-value = 1 alternative hypothesis: two.sided Can someone explain this please, Ralf -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> -----Original Message----- > From: Ralf Goertz [mailto:R.Goertz at psych.uni-frankfurt.de] > Sent: Monday, 2 July 2001 10:48 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Shapiro-Wilk test > > Hi, > > does the shapiro wilk test in R-1.3.0 work correctly? Maybe it does, butcan> anybody tell me why the following sample doesn't give "W = 1" and > "p-value = 1": > > R> x<-1:9/10;x > [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 > R> shapiro.test(qnorm(x)) > > Shapiro-Wilk normality test > > data: qnorm(x) > W = 0.9925, p-value = 0.9986 > > I can't imagine a sample being more "normal" than this. Furthermore, the > Kolmogorov-Smirnov test gives a p-value of 1.Even though the expected probability content between any two consecutive order statistics is 1/(n+1), the *expected* values of the order statistics themselves are not the percentiles. You can get a more "normal" looking sample by choosing one where the values are the normal scores. qnorm(ppoints(n)) gives a pretty good approximation to these:> shapiro.test(qnorm(1:9/10))Shapiro-Wilk normality test data: qnorm(1:9/10) W = 0.9925, p-value = 0.9986> shapiro.test(qnorm(ppoints(9)))Shapiro-Wilk normality test data: qnorm(ppoints(9)) W = 0.9965, p-value = 1>So the Shapiro-Wilk test is really a check to see if the order statistics depart significantly from *their* expectation under the normality hypothesis.> R> ks.test(qnorm(x),"pnorm",mean=0,sd=1) > > One-sample Kolmogorov-Smirnov test > > data: qnorm(x) > D = 0.1, p-value = 1 > alternative hypothesis: two.sided > > Can someone explain this please,The two tests are testing slightly different aspects of normality. (At least that's my guess...)> Ralf >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.-> r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html> Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 2 Jul 2001, Ralf Goertz wrote:> does the shapiro wilk test in R-1.3.0 work correctly? Maybe it does, but can > anybody tell me why the following sample doesn't give "W = 1" and > "p-value = 1": > > R> x<-1:9/10;x > [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 > R> shapiro.test(qnorm(x)) > > Shapiro-Wilk normality test > > data: qnorm(x) > W = 0.9925, p-value = 0.9986 > > I can't imagine a sample being more "normal" than this. Furthermore, the > Kolmogorov-Smirnov test gives a p-value of 1.Well, both I and the Shapiro-Wilk test can. That sample has too short tails:> f <- function(a) shapiro.test(qnorm((a+0:8)/(8+2*a))) > f(1)Shapiro-Wilk normality test data: qnorm((a + 0:8)/(8 + 2 * a)) W = 0.9925, p-value = 0.9986> f(0.2)Shapiro-Wilk normality test data: qnorm((a + 0:8)/(8 + 2 * a)) W = 0.9998, p-value = 1 (Values less than 1 are normally used in Q-Q plots. For example> ppoints(9)[1] 0.06756757 0.17567568 0.28378378 0.39189189 0.50000000 0.60810811 0.71621622 [8] 0.82432432 0.93243243 corresponds to a = 5/8.)> > R> ks.test(qnorm(x),"pnorm",mean=0,sd=1) > > One-sample Kolmogorov-Smirnov test > > data: qnorm(x) > D = 0.1, p-value = 1 > alternative hypothesis: two.sidedActually> ks.test(qnorm(x),"pnorm",mean=0,sd=1)$p[1] 0.9999907> a <- 0.2 > ks.test(qnorm((a + 0:8)/(8 + 2 * a)),"pnorm",mean=0,sd=1)$p[1] 0.9999999> Can someone explain this please,Tail sensitivity varies between tests, and K-S is notoriously insensitive.>From the FAQ:If a command does the wrong thing, that is a bug. But be sure you know for certain what it ought to have done. If you aren't familiar with the command, or don't know for certain how the command is supposed to work, then it might actually be working right. Rather than jumping to conclusions, show the problem to someone who knows for certain. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._