Calculating Sample Size in R (Means)

Below is a video tutorial showing how to calculate the sample size for tests on a mean.  This shows how to conduct both single-sample and two-sample tests as well as single-sided and two-sided tests.  Below the video is the syntax used in the video.



#################################################
### 
###  Determining sample size in R.
###
###  Testing Ho: mu = 15
###          Ha: mu > 15
###  
###  Power power = 0.9
###  Population stdev stdv = 2.32
###  Difference delta = 2.5
###
###  Significance level sig.level = 0.01
###

power.t.test( power = 0.9,               # Power
              delta = 2.5,               # Difference between mu and xbar
              sd = 2.32,                 # Standard Deviation
              sig.level = 0.01,          # Significance level
              type = "one.sample",       # Type of study
              alternative = "one.sided"  # Type of test
             )

###################################################
###  For a two sided two sample test.
###  Testing Ho: mu1 = mu2
###          Ha: mu1 <> mu2

power.t.test( power = 0.95,              # Power
              delta = 1.6,               # mu1 - mu2
              sd = 2.14,                 # Standard Deviation
              sig.level = 0.02,          # Significance level
              type = "two.sample",       # Type of study
              alternative = "two.sided"  # Type of test
             )

1 comment:

  1. hi, what about the dropout rate, how to add it there ? also how to do it for cross over ?

    ReplyDelete