Calculating Power in R

Below you will find a YouTube video showing how to calculate the power of a test in R.  This gives the syntax for one-sided and two-sided tests as well as one-sample and two-sample tests on means.


Below is the code used in the video.


#################################################
### 
###  Determining power of a test in R.
###
###  Testing Ho: mu = 5
###          Ha: mu > 5
###  
###  Sample size n = 12
###
###  Sample mean xbar = 5.23
###  Sample stdev stdv = 1.32
###
###  Significance level sig.level = 0.01
###

power.t.test( n = 12,                    # Sample Size
              delta = 0.23,              # Difference between mu and xbar
              sd = 1.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( n = 15,                    # Sample Size
              delta = 1.6,               # xbar2 - xbar1
              sd = 2.14,                 # Standard Deviation
              sig.level = 0.02,          # Significance level
              type = "two.sample",       # Type of study
              alternative = "two.sided"  # Type of test
             )

No comments:

Post a Comment