> ## 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.

# Run an Analysis

> Learn how to analyze 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="Run an Analysis"
  description="Learn how to analyze your experiment."
  steps={[
{
  name: "Run the Analysis",
  text: "To run an analysis, send a POST request to the analysis endpoint with both the analysis plan and the data:",
},
{
  name: "Create the Analysis Data",
  text: "When you've set up the analysis plan, you only have to add the data for analysis. The format must match what you specified in the analysis plan. For your crash metric, you have two days of data. The data for your hypothesis looks like: Your consumption data is for the whole period, and looks like:",
},
]}
/>

In this section, you go through the steps to run an analysis. You set up the request for the following example where you analyze an experiment with two metrics: a crash metric used as a guardrail that you analyze sequentially, and a consumption metric that you analyze once. To go through this tutorial you need to first [create an analysis plan](./create-analysis-plan).

## Run the Analysis

To run an analysis, send a POST request to the analysis endpoint with both the analysis plan and the data:

```bash theme={null}
curl -X POST "https://stats.confidence.dev/v1/analysis:run" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "plan": { ... },
    "data": { ... }
  }'
```

## Create the Analysis Data

When you've set up the analysis plan, you only have to add the data for analysis. The format must match what you specified in the analysis plan.

For your crash metric, you have two days of data. The data for your hypothesis looks like:

```json theme={null}
{
  "id": "crashes",
  "segments": [
    {
      "dimensions": {},
      "groups": [
        {
          "group": "control",
          "data": {
            "gstZTest": {
              "summary": {
                "data": [
                  {
                    "timeLabel": "2020-01-01",
                    "value": {
                      "mean": 2,
                      "variance": 2.282828,
                      "count": 100
                    }
                  },
                  {
                    "timeLabel": "2020-01-02",
                    "value": {
                      "mean": 1.99,
                      "variance": 2.291357,
                      "count": 200
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "group": "treatment",
          "data": {
            "gstZTest": {
              "summary": {
                "data": [
                  {
                    "timeLabel": "2020-01-01",
                    "value": {
                      "mean": 2.95,
                      "variance": 2.45202,
                      "count": 100
                    }
                  },
                  {
                    "timeLabel": "2020-01-02",
                    "value": {
                      "mean": 2.97,
                      "variance": 2.702613,
                      "count": 200
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  ]
}
```

Your consumption data is for the whole period, and looks like:

```json theme={null}
{
  "id": "consumption",
  "segments": [
    {
      "dimensions": {},
      "groups": [
        {
          "group": "control",
          "data": {
            "zTest": {
              "summary": {
                "mean": 0.25,
                "variance": 0.1893939,
                "count": 100
              }
            }
          }
        },
        {
          "group": "treatment",
          "data": {
            "zTest": {
              "summary": {
                "mean": 0.3133333,
                "variance": 0.2165996,
                "count": 150
              }
            }
          }
        }
      ]
    }
  ]
}
```

This completes the data needed for your analysis. See the API reference for full request and response examples.
