# 030. Sugar and density measurement structure

**Question:** How does density vary across residual-sugar bands within wine type?

## Result

The largest computed metric is 0.9981 for red / (5.0, 10.0]; the smallest is 0.9918 for white / (2.0, 5.0]. Metric: median_density (Source density units).

Bands are prespecified and sparse groups are excluded; density differences are not quality improvements.

![Sugar and density measurement structure](outputs/chart.png)

| wine_type | sugar_band | samples | median_density | p25 | p75 | group |
| --- | --- | --- | --- | --- | --- | --- |
| red | (0.0, 2.0] | 620 | 0.9962 | 0.9952 | 0.997 | red / (0.0, 2.0] |
| red | (2.0, 5.0] | 895 | 0.9971 | 0.9958 | 0.9983 | red / (2.0, 5.0] |
| red | (5.0, 10.0] | 73 | 0.9981 | 0.9972 | 0.999 | red / (5.0, 10.0] |
| white | (0.0, 2.0] | 1500 | 0.9919 | 0.9907 | 0.993 | white / (0.0, 2.0] |
| white | (10.0, 20.0] | 1175 | 0.9978 | 0.9968 | 0.9986 | white / (10.0, 20.0] |
| white | (2.0, 5.0] | 910 | 0.9918 | 0.9906 | 0.9936 | white / (2.0, 5.0] |
| white | (5.0, 10.0] | 1295 | 0.9949 | 0.9934 | 0.9958 | white / (5.0, 10.0] |

The chart shows 7 of 7 result rows; the table previews the first 7 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

Stratified median density and interquartile ranges.

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

Use measurement structure to check plausibility and collinearity in a laboratory model.

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/030-sugar-and-density-measurement-structure/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.
