>>>>> Rolf Turner >>>>> on Wed, 13 Mar 2019 09:38:24 +1300 writes:
> On 13/03/19 9:06 AM, Greg Snow wrote: > <SNIP> >> The only time I have seen t.test give a p-value of 1 is when the >> data mean exactly equals the null hypothesis mean and the alternative >> is the default of two.sided. > <SNIP> > Doesn't have to be *exact* equality. Just close! > E.g.: > set.seed(42) > x <- runif(10) > mew <- 0.63626 > mew==mean(x) # FALSE > t.test(x,mu=mew) Well, it *prints* as 1. But we've talked about *exact* above: > t.test(x,mu=mew)$p.value [1] 0.9999792 > getOption("digits") [1] 7 > mean(x) [1] 0.6362622 > print(mean(x), digits=14) [1] 0.63626220719889 > t.test(x,mu=0.6362622072)$p.value [1] 1 > 1 - t.test(x,mu=0.6362622072)$p.value [1] 1.049139e-11 > So even we get much closer to the mean, there's still a difference to one, even though even less visibly. And then if you go really really close to the mean, small accuracy loss in the pt() function will kick in, and you'll occasionally will be correct, Rolf ... but only if you move **much** much closer .... and in this case, it even seems not to happen at all: > mx <- mean(x) > mx - mx*(1 + 2^(-53+7e-15)) [1] -1.110223e-16 > 1 - t.test(x,mu=mx*(1 + 2^(-53+7e-15)))$p.value [1] 1.110223e-15 > Cheers, Martin > cheers, > Rolf > -- > Honorary Research Fellow > Department of Statistics > University of Auckland ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.