5
$\begingroup$

This R script produces a deficit of p-values < 0.1 for small sample sizes of n < 10. Can anyone explain why this is the case? If this is an R bug it could have some impact. Note: One-sample z-tests do have uniform p-values for small sample sizes.

m <- 10000
n <- 3
p.value <- rep(m, 0)

for (i in 1:m) {
  x <- rnorm(n, mean= 0, sd= 1)    
  y <- rnorm(n, mean= 0, sd= 1)    

  p.value[i] <- t.test(x, y, alt= "two.sided")$p.value 
} # for

par(mfrow= c(1,1))
hist(p.value, breaks= 20, xaxs="i", yaxs="i", col="skyblue", prob= F, las=T)   # appears uniform

abline(h= m/20, col= "red",  lty=2)
abline(v= 0.05, col= "cornflowerblue")
$\endgroup$
6
  • 1
    $\begingroup$ What do you mean with a deficit? Can you point to a source regarding the uniform distribution that you expect? $\endgroup$
    – Gijs
    Commented Oct 27, 2017 at 13:59
  • $\begingroup$ Yes, the histogram bars near 0 are consistently about 25% smaller in height than the expected uniform distribution requires. Run it and you will see. I expect a uniform distribution since the null hypothesis is true by the simulation generation of x and y being the same. $\endgroup$ Commented Oct 27, 2017 at 14:02
  • 1
    $\begingroup$ If you set n to a higher value the problem goes away at least here so I suspect the deficit is caused by that. $\endgroup$
    – mdewey
    Commented Oct 27, 2017 at 14:30
  • 5
    $\begingroup$ You are using the wrong version of the t test for your situation: you need to include the argument var.equal=TRUE. Please consult the manual page for more information. (It's still interesting to observe that the default t test in R is biased for small sample sizes--but that's not necessarily a problem.) +1 for a good question. $\endgroup$
    – whuber
    Commented Oct 27, 2017 at 14:33
  • 3
    $\begingroup$ Without the option var.equal=TRUE, the t-test is not "exact" (Welch approximation of degrees of freedom). $\endgroup$ Commented Oct 27, 2017 at 14:33

1 Answer 1

10
$\begingroup$

This isn't a bug in R.

Welch-Satterthwaite type t-tests (the default two sample t-test in R) don't actually have a t-distribution.

The t-with-fractional-d.f. you get is an approximation to the null distribution.

The Welch-Satterthwaite tests work well in a variety of situations, but even when all the assumptions hold the null distribution of p-values will be somewhat non-uniform (this will impact significance levels; you won't have quite the significance level you were aiming for).

There are effectively 3 parameters that control the null distribution -- the ratio of population variances, and the two sample sizes. The test uses an approximation to make it just a function of a single parameter (the Welch-Satterthwaite d.f.).

For some choices of variance ratio and sample-size ratio the distribution of p-values will tend to be somewhat skewed to lower values and for other choices it will tend to be skewed a bit to higher values.

This will tend to be more noticeable at small sample sizes, but occurs quite generally.

It's possible to use simulation at your specific n's and variance ratio rather than the t-approximation to get better control of significance levels and so more accurate p-values, if that's necessary. However, if your sample sizes are equal (as it looks like they are in your simulation), an equal-variance t-test has little problem with control of significance level even when the variances are unequal, so that may actually be a reasonable default choice when you have equal sample sizes.

$\endgroup$
1
  • $\begingroup$ Thanks Glen_b. My question has been answered. I needed to specify var.equal=TRUE $\endgroup$ Commented Oct 31, 2017 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.