0

The following code generates 10000 t-tests on a custom distribution I have created.

> x <- replicate(10000,{  
  t.test(rcn(20,.25,25), mu=0, alternative="greater")
  })

I am constructing an empirical level of significance and so I am interested in the number of test-statistics that are greather than the critical value of the respective t-distribution, which is 1.729 (for a t-distribution with 19 degrees of freedom).

How can I select (and count) these test-statistics here? The ratio of their number over 10000, the total number of simulations, will give me my empirical level of significance.

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
JohnK
  • 1,019
  • 3
  • 14
  • 30
  • please make your example reproducible by giving the definition of `rcn`. – Beasterfield Jan 13 '14 at 14:59
  • @Beasterfield My question stands for any distribution. How do I select the t-tests that have some identical characteristic amongst thousands? Thank you. – JohnK Jan 13 '14 at 15:06
  • 1
    I understood that, but then you could have chosen a distribution function from `stats` giving people the opportunity to just copy past your code. Please see [How to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Beasterfield Jan 13 '14 at 15:15

1 Answers1

1

You can directly access the test statistic of each t.test in replicate. For example:

x <- replicate(10000, {
 t.test(rcn(20,.25,25), mu=0, alternative="greater")$statistic
})

This returns a vector of t-values.

You can compare it with your critical value and count the TRUEs:

crit <- 1.729
sum(x > crit)
Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168