# Section 3: Power and sample size calculations

This section describes how to calculate necessary sample size or power for a study comparing two groups on either a measurement outcome variable (through the independent sample t-test) or a categorical outcome variable (through the chi-square test of independence).

## 3.1 Comparing means between groups

The power.t.test( ) function will calculate either the sample size needed to achieve a particular power (if you specify the difference in means, the standard deviation, and the required power) or the power for a particular scenario (if you specify the sample size, difference in means, and standard deviation).

The input for the function is:

• n – the sample size in each group
• delta – the difference between the means of the two populations
• sd – the standard deviation
• power – the desired power, as a proportion (between 0 and 1)

To find the required sample size to achieve a specified power, specify delta, sd, and power. To find the power for a specified scenario, specify n, delta, and sd. R assumes you are testing at the two-tailed p=.05 level; you can over-ride these defaults by including sig.level=xx or 'alternative='one.sided'.

Finding required sample size:

>power.t.test(delta=.25,sd=0.7,power=.80)

Two-sample t test power calculation

n = 124.0381

delta = 0.25

sd = 0.7

sig.level = 0.05

power = 0.8

alternative = two.sided

NOTE: n is number in *each* group

Finding power:

> power.t.test(n=50,delta=.25,sd=0.7)

Two-sample t test power calculation

n = 50

delta = 0.25

sd = 0.7

sig.level = 0.05

power = 0.4239677

alternative = two.sided

NOTE: n is number in *each* group

## 3.2 Comparing proportions between groups

The power.prop.test( ) function in R calculates required sample size or power for studies comparing two groups on a proportion through the chi-square test. The input for the function is:

• n – sample size in each group
• p1 – the underlying proportion in group 1 (between 0 and 1)
• p2 – the underlying proportion in group 2 (between 0 and 1)
• power – the power of the test

To find the necessary sample size, specify p1, p2, and power. To find the power for a particular situation, specify n, p1, and p2. R assumes you are testing at the two-tailed p=.05 level; you can over-ride these defaults by including sig.level=xx or 'alternative='one.sided'.

Examples:

Finding power:

> power.prop.test(n=100,p1=.2,p2=.1)

Two-sample comparison of proportions power calculation

n = 100

p1 = 0.2

p2 = 0.1

sig.level = 0.05

power = 0.5081911

alternative = two.sided

NOTE: n is number in *each* group

Finding necessary sample size:

> power.prop.test(p1=.2,p2=.1,power=.8)

Two-sample comparison of proportions power calculation

n = 198.9634

p1 = 0.2

p2 = 0.1

sig.level = 0.05

power = 0.8

alternative = two.sided

NOTE: n is number in *each* group