Power Analysis
Power Analysis
February 2, 2017
Title Power Analysis in Experimental Design
Description Basic functions for power analysis and effect size calculation.
Version 0.2.1
Date 2017-02-02
Author Felix Yanhui Fan <[email protected]>
Maintainer Felix Yanhui Fan <[email protected]>
License GPL (>= 2)
RoxygenNote 5.0.1
NeedsCompilation no
Repository CRAN
Date/Publication 2017-02-02 17:38:08
R topics documented:
ES.anova.oneway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
ES.chisq.assoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
ES.chisq.gof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
ES.proportions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ES.t.one . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ES.t.paired . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
ES.t.two . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
power.anova.oneway . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
power.chisq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
power.plot.chisq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
power.proportions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
power.t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Index 14
1
2 ES.chisq.assoc
ES.anova.oneway Calculating effect size (Cohen’s f) of one-way anova for means with
equal observations in each group
Description
Calculating effect size (Cohen’s f) of one-way anova for means with equal observations in each
group
Usage
Arguments
Examples
set.seed(9);x=rnorm(50);y=rnorm(50)
z=rnorm(50);d=data.frame(x,y,z)
ES.anova.oneway(data=d)
ES.anova.oneway(sst=50,ssb=1)
Description
Usage
Arguments
See Also
ES.chisq.gof
Examples
counts <- matrix(c(225,125,85,95),nrow=2,byrow=TRUE)
ES.chisq.assoc(ct=counts)
p1 <- c(225,85,100)
p2 <- c(125,95,125)
p3 <- c(175,90,113)
counts <- cbind(p1,p2,p3)
ES.chisq.assoc(ct=counts)
ES.chisq.assoc(chisq=13.561,n=530,df=1,mindf=1)
ES.chisq.assoc(p=0.000231,n=530,df=1,mindf=1)
Description
Usage
Arguments
p1 a vector of frequencies or probabilities (alternative hypothesis). Frequencies
will be rescaled to probabilities automatically. An error is given if any entry of
p1 is negative.
p0 a vector of frequencies or probabilities of the same length of p1 (null hypoth-
esis). Frequencies will be rescaled to probabilities automatically. An error is
given if any entry of p0 is negative. Default value of p0 is a vector of 1/n with
length of n. n is the length of p1.
See Also
ES.chisq.assoc
Examples
ES.chisq.gof(p1=c(10,20,30,40))
ES.chisq.gof(p1=c(0.1,0.2,0.3,0.4))
ES.chisq.gof(p1=c(10,20,30,40),p0=c(0.2,0.3,0.3,0.2))
ES.chisq.gof(p1=c(10,20,30,40),p0=c(20,30,30,20))
ES.chisq.gof(p1=c(0.1,0.2,0.3,0.4),p0=c(0.2,0.3,0.3,0.2))
ES.chisq.gof(p1=c(0.1,0.2,0.3,0.4),p0=c(20,30,30,20))
Description
Compute effect size for a difference in proportions
Usage
ES.proportions(p1 = NULL, p2 = NULL, alternative = c("two.sided",
"one.sided"))
Arguments
p1 Proportion of sample one
p2 Proportion of sample two or a constant proportion
alternative The test is two sided or one sided
Examples
ES.proportions(0.65,0.45)
ES.proportions(0.25,0.05)
ES.t.one 5
Description
Calculating effect size (Cohen’s d) of one-sample t test
Usage
ES.t.one(m = NULL, sd = NULL, n = NULL, t = NULL, se = NULL,
df = NULL, mu = NULL, alternative = c("two.sided", "one.sided"))
Arguments
m mean of sample
sd standard deviation of sample
n number of observations
t t statistic
se standard error of sample 1
df degree of freedom
mu population mean
alternative The test is two sided or one sided
See Also
ES.t.two
ES.t.paired
Examples
## mean, sd and mu -> d
ES.t.one(m=-0.0938268,sd=0.9836668,mu=0)
Description
Usage
Arguments
See Also
ES.t.one
ES.t.two
Examples
## md, sd -> d
ES.t.paired(md=-0.08062384,sd=1.401886)
## md,se -> d
ES.t.paired(md=-0.08062384,se=0.1982566,n=50)
## t, df -> d
ES.t.paired(t=-0.4067,df=49)
## t, n -> d
ES.t.paired(t=-0.4067,n=50)
ES.t.two 7
Description
Calculating effect size (Cohen’s d) of independent two-sample t test
Usage
ES.t.two(m1 = NULL, m2 = NULL, sd1 = NULL, sd2 = NULL, n1 = NULL,
n2 = NULL, t = NULL, se1 = NULL, se2 = NULL, df = NULL,
alternative = c("two.sided", "one.sided"))
Arguments
m1 mean of sample 1
m2 mean of sample 2
sd1 standard deviation of sample 1
sd2 standard deviation of sample 2
n1 number of observations in sample 1
n2 number of observations in sample 2
t t statistic
se1 standard error of sample 1
se2 standard error of sample 2
df degree of freedom
alternative The test is two sided or one sided
See Also
ES.t.one
ES.t.paired
Examples
## mean, sd, n -> d
ES.t.two(m1=13.5,m2=5.5,sd1=4.1833,sd2=3.02765,n1=14,n2=10)
## t and n -> d
ES.t.two(n1=14,n2=10,t=5.4349)
## t, df and n -> d
ES.t.two(t = 5.4349, df = 21.982,n1=14,n2=10)
8 power.chisq
Description
Power calculations for balanced one-way analysis of variance tests
Usage
power.anova.oneway(groups = NULL, n = NULL, f = NULL, power = NULL,
sig.level = 0.05)
Arguments
groups Number of groups
n Number of observations (per group)
f Effect size, Cohen’s f
power power of study
sig.level significance level
See Also
ES.anova.oneway
Examples
power.anova.oneway(groups=4,n=20,f=0.28)
Description
Power calculations for chi-squared test
Usage
power.chisq(es = NULL, df = NULL, n = NULL, power = NULL,
sig.level = NULL)
power.plot.chisq 9
Arguments
See Also
ES.chisq.gof
ES.chisq.assoc
power.plot.chisq
Examples
## calculate power
power.chisq(es=0.16,df=1,n=530,sig.level=0.05)
## calculate sig.level
power.chisq(es=0.16,df=1,n=530,power=0.9576)
Description
Usage
Arguments
es effect size.
power power of study
df degree of freedom
sig.level significance level
allele in genetic association study, whether test allele or genotype
xlab a title for the x axis
ylab a title for the y axis
main an overall title for the plot
grid add grid lines or not
type "np": plot sample size vs. power; "ne": plot effevct size vs. sample size
See Also
power.chisq
Examples
## 'ne' type
### multiple effect size and multiple power
es=seq(from=0.1,to=0.5,by=0.1);
power=seq(from=0.7,to=0.9,by=0.1);
power.plot.chisq(es=es,power=power,df=1,sig.level=0.05,type="ne")
power.plot.chisq(es=es,power=power,df=1,sig.level=0.05,type="np")
Description
Power calculations for proportion tests (two-sided)
power.t 11
Usage
Arguments
Examples
## one sample
power.proportions(n=600,h=0.3,type="one")
Description
Usage
Arguments
es effect size.
n total number of observations/pairs
power power of study
sig.level significance level
ratio the ratio of sample size 1 to sample size 2. Only will be used when ’type’ is
"unequal".
type type of t test, must be one of "one","two" (default), "paired", or "unequal". "one"
means one sample t test, which test whether the population mean is equal to a
specified value. "two"/"unequal" means two sample (equal size/unequal size) t
test, which is used to ascertain how likely an observed mean difference between
two groups would be to occur by chance alone. "paired" means paired t-test
(also called the correlated t-test and the t-test for dependent means), which is
used to ascertain how likely the difference between two means that contain the
same (or matched) observations is to occur by chance alone.
alternative One- or two-sided test, must be one of "two.sided" (default), "left", "right"
See Also
ES.t.one
ES.t.two
ES.t.paired
Examples
## one sample two sided test, calculate power
power.t(es=0.2,n=60,sig.level=0.10,type="one",alternative="two.sided")
power.t(es=0.1,n=3000,sig.level=0.05,type="unequal",ratio=2,alternative="two.sided")
Index
ES.anova.oneway, 2, 8
ES.chisq.assoc, 2, 4, 9
ES.chisq.gof, 3, 3, 9
ES.proportions, 4
ES.t.one, 5, 6, 7, 12
ES.t.paired, 5, 6, 7, 12
ES.t.two, 5, 6, 7, 12
power.anova.oneway, 8
power.chisq, 8, 10
power.plot.chisq, 9, 9
power.proportions, 10
power.t, 11
14