title: Simlulating a t-test in R
body: <p>I am looking for a way to simulate the power of a simple t-test in different sample sizes. My idea is to generate 400 random normal distribution samples, each with mean 5 and variance 1,  and perform a t-test on each one concerning the hypothesis that the true mean is 4, i.e. the t-test would take the form:</p>
  
  <blockquote>
    <p>t=(mean(x)-4)*sqrt(n)/sd(x) # for each sample x which consists of n observations.</p>
  </blockquote>
  
  <p>For comparison I would like, the first 100 samples to consist of 10 observations, the next 100  ones of 100, the next 100 of 1000 and finally the last 100 of 5000, which I think is the upper limit. A t-test will have to be performed on each and every sample.</p>
  
  <p>Lastly, I would like to see on what percentage of each sample group- let's call them, n10,n100,n1000,n5000, depending on how many observations they comprise- my (false) hypothesis is rejected. </p>
  
  <p>Could you please help me write the corresponding R-code? I know the small commands but have trouble putting it all together. This is a nice exercise and hopefully I shall then be able to modify it a bit and use it for different purposes as well.</p>
  
  <p>Thank you in advance.</p>