# 029. Chemistry associations with quality

**Question:** Which laboratory measurements have the strongest rank associations with quality within each wine type?

## Result

The largest computed metric is 0.4785 for red / alcohol; the smallest is -0.3806 for red / volatile_acidity. Metric: spearman_rho (Spearman correlation).

The table contains both types. Correlations do not adjust for other chemistry or multiple exploratory comparisons.

![Chemistry associations with quality](outputs/chart.png)

| feature | spearman_rho | absolute_rho | paired_rows | wine_type | association |
| --- | --- | --- | --- | --- | --- |
| alcohol | 0.4785 | 0.4785 | 1599 | red | red / alcohol |
| volatile_acidity | -0.3806 | 0.3806 | 1599 | red | red / volatile_acidity |
| sulphates | 0.3771 | 0.3771 | 1599 | red | red / sulphates |
| citric_acid | 0.2135 | 0.2135 | 1599 | red | red / citric_acid |
| total_sulfur_dioxide | -0.1967 | 0.1967 | 1599 | red | red / total_sulfur_dioxide |
| chlorides | -0.1899 | 0.1899 | 1599 | red | red / chlorides |
| density | -0.1771 | 0.1771 | 1599 | red | red / density |
| fixed_acidity | 0.1141 | 0.1141 | 1599 | red | red / fixed_acidity |
| free_sulfur_dioxide | -0.0569 | 0.0569 | 1599 | red | red / free_sulfur_dioxide |
| ph | -0.04367 | 0.04367 | 1599 | red | red / ph |
| residual_sugar | 0.03205 | 0.03205 | 1599 | red | red / residual_sugar |
| alcohol | 0.4404 | 0.4404 | 4898 | white | white / alcohol |
| density | -0.3484 | 0.3484 | 4898 | white | white / density |
| chlorides | -0.3145 | 0.3145 | 4898 | white | white / chlorides |

The chart shows 14 of 22 result rows; the table previews the first 14 in the analysis-defined order. [Download the full result table](outputs/results.csv). Numerical values are computed from the source; missing results stay unavailable.

## Method

Pairwise complete Spearman correlations stratified by wine type.

The study uses shared source preparation and reusable statistical routines. Its specific transformations are in [analysis.py](analysis.py), and common model/evaluation code is in [portfolio/methods.py](../../portfolio/methods.py). The [notebook](analysis.ipynb) executes the study and displays the saved results.

## Decision and limitations

Prioritize hypotheses for experiments while checking whether pooled relationships mask type differences.

Sensory scores are ordinal and concentrated in the middle. Producer and batch IDs are unavailable. Associations are not recipes for changing quality or evidence of market price. 

Related studies may share observations or holdouts. These are focused analytical studies, not independent replications or deployed business systems. Any model refinements informed by these results need new untouched evaluation data. No commercial impact is inferred from an association or backtest.

## Reproduce

From the repository root, after installing `requirements.txt`:

```powershell
python projects/029-chemistry-associations-with-quality/analysis.py
```

Source data are downloaded automatically if absent. Original archives are retained unchanged and checked by SHA-256. The cleaned cache normalizes column names; field-specific changes are visible in [data preparation](../../portfolio/data.py). Runtime evidence is in [receipt.json](outputs/receipt.json).

## Source

[Wine Quality](https://archive.ics.uci.edu/dataset/186/wine+quality), Cortez et al. (2009). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/wine.json) and [prepared-data audit](../../data/provenance/wine_prepared.json) record the downloaded files, field coverage and hashes.
