StatsCalculators.com

Sample Size & Power Analysis Calculator

Created:October 19, 2024
Last Updated:March 17, 2025

This Sample Size & Power Analysis Calculator helps you determine the optimal sample size needed for your study and analyze statistical power. Whether you're comparing means, proportions, or multiple groups, this calculator will help ensure your research has adequate statistical power to detect meaningful effects.

Calculator

Parameters

Range: 0.1 to 2 (standard deviations)

Sample Size Calculation Results

n =

Power vs Sample Size

Power vs Effect Size

Notes:

  • Effect size interpretations vary by field and context
  • For mean difference tests, effect size is in standard deviation units
  • Power of 80% (0.8) is typically considered adequate
  • Significance level of 5% (0.05) is conventional in many fields
  • The power curve shows how the statistical power changes with different effect sizes
  • Larger sample sizes can detect smaller effect sizes with the same power

Learn More: Sample Size Formulas, Examples, and R Code

Why Sample Size Matters in Research?

What is Statistical Power?

Statistical power is the probability that your study will correctly detect an effect when there is one. Failing to do so results in a Type II error.

A power of 0.8 (or 80%) is typically considered adequate, indicating there is a 20% chance of overlooking a real effect.

The Importance of Sample Size

Sample size calculation is a crucial step in research design and hypothesis testing. It helps you:

  • Ensure your study has adequate statistical power to detect meaningful effects
  • Avoid wasting resources on studies that are too large
  • Maintain ethical standards by not using too few or too many participants
  • Make informed decisions about resource allocation

Warning: Conducting a study with inadequate sample size can lead to:

  • False negatives (Type II errors) - failing to detect real effects
  • Unreliable results and wasted resources
  • Inability to draw meaningful conclusions

A/B Testing Example

Scenario: Website Conversion Rate

You're testing a new button design and want to detect a 2% increase in conversion rate (from 10% to 12%).

Without proper sample size calculation:

Too Small (100 visitors/group)
  • Control: 10 conversions (10%)
  • Test: 12 conversions (12%)
  • Result: Not statistically significant despite real effect
Proper Size (2000 visitors/group)
  • Control: 200 conversions (10%)
  • Test: 240 conversions (12%)
  • Result: Can detect the real difference

Required Calculations

For this example, we need:

  • Significance level: α = 0.05
  • Power: 1-β = 0.80
  • Baseline rate: p₁ = 0.10
  • Expected rate: p₂ = 0.12
  • Effect size: |p₂ - p₁| = 0.02

Input these values into the calculator and it will give you 3841 samples per group.

Common Mistakes to Avoid

Underpowered Studies

  • Unable to detect meaningful effects
  • Waste of time and resources
  • Inconclusive results
  • Potential ethical issues

Overpowered Studies

  • Excessive resource usage
  • Detection of trivial effects
  • Unnecessary participant burden
  • Inflated costs

Best Practices

  • Always calculate sample size before starting data collection
  • Consider practical significance, not just statistical significance
  • Account for potential dropout or missing data
  • Document your sample size calculations and assumptions
  • Consider conducting a pilot study if parameters are unknown

Sequential Testing and Early Stopping

While traditional sample size calculation is crucial, modern A/B testing platforms often use sequential testing approaches:

Sequential Analysis

  • Continuously monitor results
  • Stop early if effect is clear
  • Adjust for multiple looks
  • More efficient use of resources

Required Adjustments

  • Use adjusted significance levels
  • Account for peeking
  • Consider false discovery rate
  • Monitor effect size stability

Key Takeaway

Whether using traditional fixed-sample approaches or modern sequential methods, proper planning of sample size and monitoring procedures is essential for valid and reliable results.

How to Calculate Sample Size for Different Tests?

Two-Sample Mean Difference

For comparing two independent means, the sample size per group is:

n=2(zα/2+zβ)2d2n = \frac{2(z_{\alpha/2} + z_{\beta})^2}{d^2}

where:

  • zα/2z_{\alpha/2}: Critical value for Type I error rate (1.96 for α = 0.05)
  • zβz_{\beta}: Critical value for Type II error rate (0.84 for power = 0.80)
  • dd: Cohen's d (standardized effect size) = (μ₁ - μ₂)/σ
Note: For unequal group sizes with allocation ratio r = n₂/n₁:
n1=2(zα/2+zβ)2(1+1/r)d2n_1 = \frac{2(z_{\alpha/2} + z_{\beta})^2(1 + 1/r)}{d^2}n2=r×n1n_2 = r \times n_1

Example Calculation

Let's calculate the sample size needed to detect a medium effect size (d = 0.5) with 80% power at α = 0.05:

Step-by-step calculation:

  1. α = 0.05, so zα/2 = 1.96
  2. Power = 0.80, so zβ = 0.84
  3. Effect size d = 0.5
  4. Apply the formula:
    n=2(1.96+0.84)2(0.5)2=2(2.8)20.25=2×7.840.25=15.680.25=63.76n = \frac{2(1.96 + 0.84)^2}{(0.5)^2} = \frac{2(2.8)^2}{0.25} = \frac{2 \times 7.84}{0.25} = \frac{15.68}{0.25} = 63.76
  5. Round up to n = 64 subjects per group

R implementation

R
library(tidyverse)
library(pwr)

# Parameters
effect_size <- 0.5   # Cohen's d (medium effect)
sig_level <- 0.05    # Significance level (alpha)
power <- 0.8         # Desired power
type <- "two.sample" # Two-sample t-test

# Calculate sample size (equal group sizes)
result <- pwr.t.test(d = effect_size, 
                     sig.level = sig_level, 
                     power = power, 
                     type = type,
                     alternative = "two.sided")

# Print results
print(str_glue("Sample size per group: {ceiling(result$n)}"))

# For unequal group sizes with allocation ratio r = 2
r <- 2
n1 <- pwr.t.test(d = effect_size, 
                 sig.level = sig_level, 
                 power = power, 
                 type = type)$n * (1 + r) / (2 * r)
n2 <- r * n1
print(str_glue("Unequal groups (ratio 1:{r}):"))
print(str_glue("- Group 1 sample size: {ceiling(n1)}"))
print(str_glue("- Group 2 sample size: {ceiling(n2)}"))
print(str_glue("- Total sample size: {ceiling(n1) + ceiling(n2)}"))

Output:

     Two-sample t test power calculation 

              n = 63.76561
              d = 0.5
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: n is number in *each* group

Unequal groups (ratio 1:2):
- Group 1 sample size: 48
- Group 2 sample size: 96
- Total sample size: 144

Paired Difference Test

For paired samples, the required number of pairs is:

n=2(zα/2+zβ)2(1ρ)d2n = \frac{2(z_{\alpha/2} + z_{\beta})^2(1-\rho)}{d^2}

where:

  • ρ\rho: Correlation between paired measurements
  • dd: Effect size = (μ₁ - μ₂)/σ

Note: Higher correlation between pairs reduces the required sample size, making paired designs more efficient when correlation is strong.

Example Calculation

For a paired t-test with expected effect size d = 0.5, correlation ρ = 0.6, significance level α = 0.05, and power = 0.8:

n=2(1.96+0.84)2(10.6)0.52=2(2.8)2(0.4)0.25=6.2720.25=25.0926 pairsn = \frac{2(1.96 + 0.84)^2(1-0.6)}{0.5^2} = \frac{2(2.8)^2(0.4)}{0.25} = \frac{6.272}{0.25} = 25.09 \approx 26 \text{ pairs}

Therefore, we need 26 pairs of observations.

R Implementation

R
library(tidyverse)
library(pwr)

# Parameters
d <- 0.5           # Effect size (Cohen's d)
sig.level <- 0.05  # Significance level
power <- 0.8       # Desired power
rho <- 0.6         # Correlation between pairs

# Adjusted effect size for paired design
d_adj <- d / sqrt(2 * (1 - rho))

# Calculate sample size
result <- pwr.t.test(
  d = d_adj,
  sig.level = sig.level,
  power = power,
  type = "paired"
)
print(result)
print(str_glue("Sample size per group: {ceiling(result$n)}"))

Output:

     Paired t test power calculation 

              n = 27.0998
              d = 0.559017
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: n is number of *pairs*

Sample size per group: 28

Proportion Test

For comparing two proportions, the required sample size per group is:

n=2(zα/2+zβ)2h2n = \frac{2(z_{\alpha/2} + z_{\beta})^2}{h^2}

where:

  • hh: Cohen's h = 2arcsin(p1)2arcsin(p2)2\arcsin(\sqrt{p_1}) - 2\arcsin(\sqrt{p_2})
  • p1,p2p_1, p_2: Expected proportions in each group

Cohen's h Effect Size Guidelines:

  • Small: h = 0.2
  • Medium: h = 0.5
  • Large: h = 0.8

Example Calculation

Let's calculate the sample size needed to detect a difference between proportions p₁ = 0.6 and p₂ = 0.4 with 80% power at α = 0.05:

h=2arcsin(0.6)2arcsin(0.4)=2(0.8861)2(0.6847)=1.77221.3694=0.4027h = 2\arcsin(\sqrt{0.6}) - 2\arcsin(\sqrt{0.4}) = 2(0.8861) - 2(0.6847) = 1.7722 - 1.3694 = 0.4027n=2(1.96+0.84)2(0.4027)2=2(2.8)20.1622=15.680.1622=96.6997n = \frac{2(1.96 + 0.84)^2}{(0.4027)^2} = \frac{2(2.8)^2}{0.1622} = \frac{15.68}{0.1622} = 96.69 \approx 97

R implementation

R
library(tidyverse)
library(pwr)

# Parameters
p1 <- 0.6          # Proportion in group 1
p2 <- 0.4          # Proportion in group 2
sig_level <- 0.05  # Significance level (alpha)
power <- 0.8       # Desired power

# Calculate effect size (Cohen's h)
h <- 2 * asin(sqrt(p1)) - 2 * asin(sqrt(p2))
print(str_glue("Cohen's h = {round(h, 4)}"))

# Calculate sample size
result <- pwr.2p.test(h = h, 
                     sig.level = sig_level, 
                     power = power)

# Print results
print(result)
print(str_glue("Sample size per group: {ceiling(result$n)}"))

Output:

Cohen's h = 0.027

     Difference of proportion power calculation for binomial distribution (arcsine transformation) 

              h = 0.4027158
              n = 96.79194
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: same sample sizes

Sample size per group: 97

One-Way ANOVA

For one-way ANOVA with k groups, the sample size per group is:

n = \ rac{(z_{\alpha/2} + z_{\eta})^2 \cdot 2}{f^2 \cdot k}

where:

  • ff: Cohen's f effect size = η2/(1η2)\sqrt{\eta^2/(1-\eta^2)}
  • kk: Number of groups
  • η2\eta^2: Proportion of variance explained
  • zα/2z_{\alpha/2}: Critical value for significance level α\alpha (two-tailed)
  • z_{\eta}: Critical value for power 1 - \eta

Note:

This formula provides an approximation of the sample size for a one-way ANOVA. For more accurate results, especially when dealing with small effect sizes or complex designs, it is recommended to use specialized software (e.g., G*Power, R, Python, or our calculator above).

Cohen's f Effect Size Guidelines:

  • Small: f = 0.10
  • Medium: f = 0.25
  • Large: f = 0.40

Example Calculation

Let's calculate the sample size needed for a one-way ANOVA with 3 groups, a medium effect size (f = 0.25), 80% power, and α = 0.05:

n=(1.96+0.84)22(0.25)23=8.820920.06253=83.626784n = \frac{(1.96 + 0.84)^2 \cdot 2}{(0.25)^2 \cdot 3} = \frac{8.8209 \cdot 2}{0.0625 \cdot 3} = 83.6267 \approx 84

Therefore, we need approximately 84 subjects per group, for a total of 252 subjects.

R implementation

R
library(pwr)

# Parameters
groups <- 3         # Number of groups
f <- 0.25           # Cohen's f (medium effect size)
sig_level <- 0.05   # Significance level (alpha)
power <- 0.8        # Desired power

# Calculate sample size
result <- pwr.anova.test(k = groups, 
                         f = f, 
                         sig.level = sig_level, 
                         power = power)

# Print results
print(result)
print(paste("Total sample size:", ceiling(result$n) * groups))

Output:

     Balanced one-way analysis of variance power calculation 

              k = 3
              n = 52.3966
              f = 0.25
      sig.level = 0.05
          power = 0.8

NOTE: n is number in each group

Total sample size: 159

Related Calculators

Support Us with a Citation

Help us keep our calculators free! If you've found this tool valuable for your work or studies, please consider citing us using one of the formats below. Each citation helps us grow and continue providing free resources. 🙏

StatsCalculators Team. (2025). Sample Size & Power Analysis Calculator. StatsCalculators. Retrieved April 4, 2025 from https://www.statscalculators.com/calculators/hypothesis-testing/sample-size-and-power-analysis-calculator