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

# PCA

> Principal Component Analysis. Find the directions of maximum variance and detect outliers in your spectra.

PCA (Principal Component Analysis) is the workhorse of spectroscopy exploration. It rotates your high-dimensional spectra into a new set of axes called **principal components**, ordered by how much variance they explain. PC1 is the direction of largest variance, PC2 the next largest (orthogonal to PC1), and so on.

PCA is useful for:

* Spotting **outliers** before training a model
* Visualizing whether your samples form **natural groups**
* Reducing dimensionality for downstream methods (e.g., feeding into K-Means)
* Understanding **which wavelengths matter most** via loadings

## Configuring a PCA run

In the **Configure run** card on the analysis detail page, select **PCA**.

<Frame>
  <img src="https://mintcdn.com/chemolytic/Z4NdeoejDDDPqHhB/images/screenshots/explorer/pca-config.png?fit=max&auto=format&n=Z4NdeoejDDDPqHhB&q=85&s=179f6b1a8670e9de126a7185589bd96b" alt="PCA configuration showing method selection, run name input, and max components slider" width="1714" height="1196" data-path="images/screenshots/explorer/pca-config.png" />
</Frame>

### Parameters

| Parameter          | Default | Range   | Description                                                                          |
| ------------------ | ------- | ------- | ------------------------------------------------------------------------------------ |
| **Max components** | 10      | 2 to 50 | The maximum number of principal components to compute. Higher = more detail, slower. |

The actual "best" number of components is chosen automatically based on the cumulative variance explained.

### Run name

Auto-generated as a friendly two-word name (e.g., "bold-cloud"). Override it with anything descriptive.

Click **Launch run** to start. The run appears in the runs list with status "Queueing", then "Analysing", then "Done" when complete.

## Reading the results

Click a completed run to open its detail page.

<Frame>
  <img src="https://mintcdn.com/chemolytic/Z4NdeoejDDDPqHhB/images/screenshots/explorer/pca-results.png?fit=max&auto=format&n=Z4NdeoejDDDPqHhB&q=85&s=7eadce5bf507ffffdb106f2d84d8e18b" alt="PCA run detail showing scree plot, scores plot, loadings, and outlier detection" width="1714" height="1196" data-path="images/screenshots/explorer/pca-results.png" />
</Frame>

### Dimensionality (scree plot)

Bar chart showing the **explained variance** of each component, with a line for the cumulative variance.

The text below the chart shows the **suggested number of components** and the cumulative variance at that count (e.g., "Suggested: 4 components · 92.3% variance").

<Tip>
  Look for the "elbow" in the bar chart. Components past the elbow add little variance and probably represent noise. The suggested number tries to capture the elbow automatically.
</Tip>

### Scores plot

Scatter plot of your samples projected onto the principal components. Each point is one spectrum.

| Control       | Description                                              |
| ------------- | -------------------------------------------------------- |
| **X axis**    | Pick which PC is on the horizontal axis (PC1 by default) |
| **Y axis**    | Pick which PC is on the vertical axis (PC2 by default)   |
| **Colour by** | Color points by a property to spot correlations          |

When you colour by a property:

* **Continuous** properties produce a blue → red gradient (low to high)
* **Categorical** properties use a fixed palette (one color per category)

<Tip>
  If samples cluster in the scores plot when coloured by a property, that property is correlated with spectral variance. This is a strong signal that you can build a model for it.
</Tip>

### Loadings plot

Line chart showing how much each wavelength contributes to a given component.

Pick which PC to view from the dropdown. Peaks and troughs in the loadings indicate the wavelengths that drive that component's variance. If PC1's loadings have a strong peak at, say, 1450 nm, that wavelength is dominant in the largest source of variance in your data.

### Outlier detection (T² vs Q residuals)

Scatter plot with **Hotelling T²** on the x-axis and **Q residuals** on the y-axis. Each point is a spectrum. Two threshold lines (red) mark statistical limits.

| Region                 | Meaning                                                |
| ---------------------- | ------------------------------------------------------ |
| Inside both thresholds | Normal sample                                          |
| Above Q threshold      | Spectrum has unusual features the model didn't capture |
| Right of T² threshold  | Spectrum is at the extremes of the modelled space      |
| Above both             | Strong outlier candidate                               |

<Frame>
  <img src="https://mintcdn.com/chemolytic/Z4NdeoejDDDPqHhB/images/screenshots/explorer/pca-qt.png?fit=max&auto=format&n=Z4NdeoejDDDPqHhB&q=85&s=a672b4c0e42375e9a4ad6a3362d1e2ac" alt="PCA run detail showing scree plot, scores plot, loadings, and outlier detection" width="1714" height="1196" data-path="images/screenshots/explorer/pca-qt.png" />
</Frame>

Points are coloured:

* **Green**: inside both thresholds
* **Orange**: one threshold exceeded
* **Red**: both thresholds exceeded

The badge above the chart shows the count of outliers vs total samples.

<Tip>
  Click an outlier to identify which sample it is. Investigate the original spectrum and the lab notes for that sample. Common causes: contaminated sample, instrument error during measurement, wrong sample loaded by mistake.
</Tip>

## Iterating

PCA results often suggest changes:

| Observation                            | What to try next                                |
| -------------------------------------- | ----------------------------------------------- |
| Strong outliers                        | Archive those spectra, run again                |
| First component captures most variance | Try a stronger preprocessing (SNV, derivatives) |
| No structure visible in scores         | Add more samples or check property coverage     |
| Property gradient visible              | You're ready to try an experiment               |

Each new run is saved alongside the others in the same analysis. Use [Comparing runs](/explorer/comparing-runs) to put multiple runs side by side.
