> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate Required Sample Size

> Learn how to calculate the required sample size for your experiment.

export const HowToSchema = ({name, description, steps = []}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "HowTo",
    name,
    description
  };
  if (steps.length > 0) {
    schema.step = steps.map((s, i) => ({
      "@type": "HowToStep",
      position: i + 1,
      name: typeof s === "string" ? s : s.name,
      text: typeof s === "string" ? s : s.text || s.name
    }));
  }
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<HowToSchema
  name="Calculate Required Sample Size"
  description="Learn how to calculate the required sample size for your experiment."
  steps={[
{
  name: "Configure the experiment",
  text: "Configure the experiment with your treatments, audience, and metrics.",
},
{
  name: "Open the sample size calculator",
  text: "In the Required sample size section on the right sidebar, click the top-right widget icon.",
},
{
  name: "Click Calculate",
  text: "Click Calculate on the widget to calculate the required sample size.",
},
{
  name: "Review the results",
  text: "When the calculation finishes, the widget displays a results table and a progress chart. The results table shows the following columns for each metric: The Days needed, Expected samples, and progress charts are beta features. Contact experimentation-cs@spotify.com if you don't see them. - Days needed: The estimated number of days to reach the required sample size. - Required samples: The sample size needed to achieve the configured level of power. - Expected samples: The projected total samples based on historical exposure rates. - Mean: The estimated mean of the metric from historical data. - Variance: The estimated variance of the metric from historical data. The widget header shows the maximum days needed across all metrics. The progress chart above the table visualizes the estimated progress toward 100% of the required sample size for each metric over time. A vertical dashed line marks the current planned runtime. You can expand individual metric rows to view a per-metric chart that shows the expected and required sample sizes over time.",
},
{
  name: "Select the exposure source type",
  text: "Choose one of the following: - Assignments: Use all existing assignments available in your assignment table, or filter these on assignments from specific flags - Previous experiment: Use exposure from a previous experiment",
},
{
  name: "Filter assignments (optional)",
  text: "If you selected Assignments, you can filter assignments on flags to only include a cohort of users similar to those in your upcoming experiment.",
},
]}
/>

The [sample size calculator](../experiments/sample-size-calculator) helps you plan the length and size of an experiment by calculating what sample size you need to achieve the requested level of power.

<Note>
  When calculating the required sample size for an experiment, Confidence looks at historical data for the metrics in the experiment. There needs to be at least 14 days (plus the aggregation window and exposure offsets) of historical data for the metric. For example, if you have a metric with a 7-day aggregation window and a 7-day exposure offset, you need at least 28 days of historical data.
</Note>

## Calculate the Required Sample Size

<Steps>
  <Step title="Configure the experiment">
    Configure the experiment with your treatments, audience, and metrics.
  </Step>

  <Step title="Open the sample size calculator">
    In the **Required sample size** section on the right sidebar, click the top-right widget icon.
  </Step>

  <Step title="Click Calculate">
    Click **Calculate** on the widget to calculate the required sample size.
  </Step>

  <Step title="Review the results">
    When the calculation finishes, the widget displays a results table and a
    progress chart. The results table shows the following columns for each
    metric:

    <Tip>
      The **Days needed**, **Expected samples**, and progress charts are beta
      features. Contact
      [experimentation-cs@spotify.com](mailto:experimentation-cs@spotify.com)
      if you don't see them.
    </Tip>

    * **Days needed**: The estimated number of days to reach the required
      sample size.
    * **Required samples**: The sample size needed to achieve the configured
      level of power.
    * **Expected samples**: The projected total samples based on historical
      exposure rates.
    * **Mean**: The estimated mean of the metric from historical data.
    * **Variance**: The estimated variance of the metric from historical data.

    The widget header shows the maximum days needed across all metrics. The
    progress chart above the table visualizes the estimated progress toward
    100% of the required sample size for each metric over time. A vertical
    dashed line marks the current planned runtime.

    You can expand individual metric rows to view a per-metric chart that
    shows the expected and required sample sizes over time.
  </Step>
</Steps>

## Define the Exposure Source

The exposure source is the source of the data used to calculate the mean and variance of the metrics.

<Steps>
  <Step title="Select the exposure source type">
    Choose one of the following:

    * **Assignments**: Use all existing assignments available in your assignment table, or filter these on assignments from specific flags
    * **Previous experiment**: Use exposure from a previous experiment
  </Step>

  <Step title="Filter assignments (optional)">
    If you selected **Assignments**, you can [filter assignments on flags](./filter-assignments-for-sample-size) to only include a cohort of users similar to those in your upcoming experiment.
  </Step>
</Steps>

## Adjust the Required Sample Size

If the required sample size is too large compared to the available population, you can either try to expand the population or reduce the required sample size.

To reduce the required sample size, you can do one or more of the following:

* **Increase Alpha setting**: Alpha is the probability of a false positive. A higher alpha requires a smaller sample size, but means the risk of finding significance when there really is no effect increases.

* **Lower Power setting**: Power is the probability of a true positive. The higher the power, the lower the probability of a false negative. A lower power requires a smaller sample size, but lowers the chance of finding a true effect. Lower power also increases the risk of sign and magnitude errors (type S and type M errors). In general, a too low power makes it hard to reproduce the results of an experiment.

* **Increase metric MDEs and NIMs**: The MDE and NIM are the effect sizes that you and your stakeholders care about. The larger the MDE and NIM, the smaller the required sample size.

## Related Resources

<CardGroup cols={2}>
  <Card title="Sample Size Calculator Reference" href="/docs/experiments/sample-size-calculator">
    Deep dive into sample size calculations
  </Card>

  <Card title="Power Analysis" href="/docs/experiments/design/power">
    Understand statistical power
  </Card>

  <Card title="Effect Sizes" href="/docs/experiments/design/effect-sizes">
    Learn about MDE and NIM settings
  </Card>

  <Card title="Filter Assignments" href="/docs/how-to-guides/filter-assignments-for-sample-size">
    Improve sample size estimates
  </Card>
</CardGroup>
