Fpower2: F-Distribution Power Calculation

Description Usage Arguments Value Author(s) Examples

View source: R/Fpower2.R

Description

Calculates the power for a two-way ANOVA

Usage

1
Fpower2(alpha,nlev,nreps,Delta,sigma)

Arguments

alpha

input - significance level of the F-test.

nlev

input - vector of length two containing the number of levels of the factors.

nreps

input - the the number of replicates in each combination of factor levels.

Delta

input - the size of a practical difference in two marginal factor level means.

sigma

input - the standard deviation of the experimental error.

Value

probability of exceeding fcrit(alpha, nu1,nu2) with the non-central F-distribution with nu1 and nu2 degrees of freedom and noncentrality parameter nc

Author(s)

John Lawson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
power <- Fpower2(.05, nlev = c(4,4), nreps=2, Delta= 1, sigma=.32)

rmin <- 2 # smallest number of replicates
rmax <- 4 # largest number of replicates
alpha <- .05
sigma <- .32
Delta <- 1.0
nlev <- c(4,4)
nreps <- c(rmin:rmax)
result <- Fpower2(alpha, nlev, nreps, Delta, sigma)
options(digits = 5)
result


## The function is currently defined as
Fpower2<-function(alpha=NULL, nlev=NULL,nreps=NULL, Delta=NULL, sigma=NULL)
{
##### Power Calculation for two way ANOVA ###########
# Argument list
# alpha the significance level of the test.
# nlev vector containing the number of levels of the factors. 
# nreps the number of replicates in each combination of factor levels.
# Delta the size of a practical difference in two marginal factor level means.
# sigma the standard deviation of the experimental error.
############################################################
if (is.null(alpha)|is.null(nlev)|is.null(nreps)|is.null(Delta)|is.null(sigma))
  stop("you must supply alpha, nlev, nreps, Delta and sigma")
if(length(nlev)<2)
  stop ("nlev must be a two component vecto containing levels of the 1st and 2nd factors")
a <- nlev[1]
b <- nlev[2]
cssb <- (Delta^2)/2
ncb <- a*(nreps*cssb)/(sigma^2)
cssa<-(Delta^2)/2
nca<- b*(nreps*cssa)/(sigma^2)
dfa<- a-1
dfb<- b-1
df2<-(nreps-1)*b*a
powera <- 1-pf(Fcrit(alpha,dfa,df2),dfa,df2,nca)
powerb <- 1-pf(Fcrit(alpha,dfb,df2),dfa,df2,nca)
result <-cbind(nreps,df2,powera,powerb)
}

Example output

     alpha a b nreps Delta sigma  powera  powerb
[1,]  0.05 4 4     2     1  0.32 0.99838 0.99838
[2,]  0.05 4 4     3     1  0.32 1.00000 1.00000
[3,]  0.05 4 4     4     1  0.32 1.00000 1.00000

daewr documentation built on March 13, 2021, 3:01 a.m.