Metadata-Version: 2.4
Name: rwt-height
Version: 0.1.0
Summary: Roche-Wainer-Thissen (RWT) adult height prediction from the published quarterly tables
Author: Javad Dehghani MD (Pediatric Orthopedic Surgeon)
Maintainer: Javad Dehghani MD (Pediatric Orthopedic Surgeon)
License-Expression: MIT
Project-URL: Reference article, https://publications.aap.org/pediatrics/article/56/6/1026/78714/The-RWT-Method-for-the-Prediction-of-Adult-Stature
Keywords: adult height,bone age,growth,pediatrics,Roche-Wainer-Thissen
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# rwt-height

`rwt-height` is a small, dependency-free implementation of the
Roche–Wainer–Thissen (RWT) method for predicting stature at age 18.

Developed and maintained by **Javad Dehghani MD (Pediatric Orthopedic
Surgeon)**.

It uses the quarterly coefficients published in Tables I and II of:

> Roche AF, Wainer H, Thissen D. The RWT Method for the Prediction of Adult
> Stature. *Pediatrics*. 1975;56(6):1026–1033.

## Status

This is an alpha implementation intended for reproducible research and
clinician-reviewed decision support. It is not a medical device and must not be
used as the sole basis for diagnosis or treatment.

## Installation

```bash
pip install rwt-height
```

Verify the installation:

```bash
python -c "import rwt_height; print(rwt_height.__version__)"
```

For local development:

```bash
python -m pip install -e .
```

## Quick start

```python
from rwt_height import predict_rwt

result = predict_rwt(
    sex="male",
    chronological_age_years=6 + 3 / 12,
    height_cm=108.7,
    weight_kg=17.4,
    midparent_height_cm=169.0,
    skeletal_age_years=5.4,  # Decimal years as reported in the RWT example
)

print(f"Predicted stature at 18: {result.predicted_height_at_18_cm:.1f} cm")
# Predicted stature at 18: 168.8 cm
```

This reproduces the worked example in the article. Using the coefficients
rounded in the published table, the unrounded result is 168.8395 cm.

## Age format: decimal years

Both chronological age and skeletal age must be supplied in **decimal years**.
Convert years and months as follows:

```python
chronological_age = 6 + 3 / 12  # 6 years 3 months = 6.25 years
skeletal_age = 5 + 4 / 12       # 5 years 4 months = 5.333... years
```

Do not enter `5.4` to mean 5 years 4 months. A decimal age of `5.4` means
5 years and 4.8 months.

## Complete example

```python
from rwt_height import calculate_midparent_stature, predict_rwt

mps = calculate_midparent_stature(
    mother_height_cm=160.0,
    father_height_cm=178.0,
)

result = predict_rwt(
    sex="male",
    chronological_age_years=6 + 3 / 12,
    height_cm=108.7,
    height_measurement="recumbent",
    weight_kg=17.4,
    midparent_height_cm=mps,
    skeletal_age_years=5 + 5 / 12,
    coefficient_method="linear",
    add_post_18_increment=True,
)

print(f"Predicted stature at 18: {result.predicted_height_at_18_cm:.1f} cm")
print(f"Post-18 adjusted estimate: {result.post_18_adjusted_height_cm:.1f} cm")

for warning in result.warnings:
    print("Warning:", warning)
```

## Inputs

| Parameter | Meaning | Unit / accepted values |
| --- | --- | --- |
| `sex` | Sex-specific RWT table | `"male"` or `"female"` |
| `chronological_age_years` | Age used to select coefficients | Decimal years |
| `height_cm` | Current recumbent length or standing height | cm |
| `height_measurement` | Type of height measurement | `"recumbent"` or `"standing"` |
| `weight_kg` | Current nude weight in the original method | kg |
| `midparent_height_cm` | Unadjusted mean of measured parental heights | cm |
| `skeletal_age_years` | Hand/wrist skeletal age | Decimal years |
| `coefficient_method` | Selection between quarterly rows | `"linear"` or `"nearest"` |
| `add_post_18_increment` | Add the historical median post-18 increment | `True` or `False` |

The function uses recumbent length by default. If only standing height is
available, request the conversion described in the article:

```python
result = predict_rwt(
    sex="female",
    chronological_age_years=10 + 7 / 12,
    height_cm=140.2,
    height_measurement="standing",
    weight_kg=34.5,
    midparent_height_cm=165.0,
    skeletal_age_years=10 + 1 / 12,
)
```

`result.recumbent_length_used_cm` will then equal standing height + 1.25 cm.

## Reading the result

`predict_rwt()` returns a `PredictionResult` object:

| Attribute | Meaning |
| --- | --- |
| `predicted_height_at_18_cm` | Primary RWT estimate of stature at age 18 |
| `post_18_adjusted_height_cm` | Optional estimate after adding 0.8 cm for males or 0.6 cm for females |
| `estimate_cm` | Adjusted result when requested; otherwise the age-18 result |
| `recumbent_length_used_cm` | Length actually entered into the RWT equation |
| `coefficients` | Coefficients used in the calculation |
| `warnings` | Calculation-specific warnings, such as interpolation or standing-height conversion |

Example:

```python
print(result.predicted_height_at_18_cm)
print(result.coefficients)
print(result.warnings)
```

## Model

For a coefficient set selected by sex and chronological age:

```text
H18 = beta_RL * RL
    + beta_W  * W
    + beta_MPS * MPS
    + beta_SA * SA
    + beta_0
```

Where:

- `H18`: predicted stature at age 18 in cm
- `RL`: recumbent length in cm
- `W`: nude weight in kg
- `MPS`: raw average of the measured maternal and paternal statures in cm
- `SA`: skeletal age in years

The article reports median post-18 increments of 0.8 cm for boys and 0.6 cm for
girls. Set `add_post_18_increment=True` to receive that separately as
`result.post_18_adjusted_height_cm`.

## Midparent stature

RWT uses the unadjusted arithmetic mean of the two measured parental statures,
not the sex-adjusted target-height formula:

```python
from rwt_height import calculate_midparent_stature

mps = calculate_midparent_stature(
    mother_height_cm=160.0,
    father_height_cm=178.0,
)
# 169.0
```

## Choosing coefficients

The published article provides coefficients every three months. The original
continuous polynomial functions were not printed in the article.

- `coefficient_method="linear"` (default) linearly interpolates each
  coefficient between adjacent published rows. This is a package-level
  approximation, not the unpublished RWT polynomial.
- `coefficient_method="nearest"` uses the closest published quarterly row.
  Exact halfway ties use the younger row.

You can inspect the selected coefficients:

```python
from rwt_height import get_coefficients

coefficients = get_coefficients(
    sex="male",
    chronological_age_years=6.25,
    method="nearest",
)
print(coefficients.beta_rl)
```

Supported chronological-age ranges are 1.0–16.0 years for males and 1.0–14.0
years for females, matching the published tables.

## Handling invalid inputs

Invalid sex, age range, measurement type, non-finite values, and non-positive
anthropometric measurements raise `RWTInputError`:

```python
from rwt_height import RWTInputError, predict_rwt

try:
    result = predict_rwt(
        sex="male",
        chronological_age_years=17,
        height_cm=170,
        weight_kg=60,
        midparent_height_cm=175,
        skeletal_age_years=16,
    )
except RWTInputError as error:
    print(error)
```

## Common mistakes

- Use decimal years, not a `years.months` notation.
- RWT midparent stature is the raw parental mean; do not use the
  sex-adjusted target-height formula.
- Specify `height_measurement="standing"` when the measurement is standing
  height. Otherwise the package assumes recumbent length.
- `linear` interpolation is an approximation between the published quarterly
  rows, not the original unpublished continuous polynomial.
- `post_18_adjusted_height_cm` is `None` unless
  `add_post_18_increment=True`.

## Important limitations

- The method was developed from longitudinal observations of healthy white
  children from southwestern Ohio and evaluated in historical white cohorts.
  Calibration and generalizability to other ancestries, countries, eras,
  growth disorders, and treated children may be limited.
- The original skeletal-age input was the median of Greulich–Pyle
  bone-specific hand/wrist ages. A single overall Greulich–Pyle atlas rating is
  commonly available clinically but is not exactly the same input.
- The paper advises against prediction when more than half of the hand/wrist
  bones have reached adult status. This package cannot infer that condition
  from a single numerical skeletal age.
- The estimate is stature at age 18. The optional sex-specific post-18
  increment is a historical median, not an individualized prediction.
- The paper shows approximate error bounds graphically; it does not publish
  sufficient numerical values for this package to claim a validated prediction
  interval.
- The coefficients are rounded to three decimals in the published tables, so
  results may differ slightly from calculations made with the original
  continuous functions.

## Development

Run the test suite:

```bash
python -m unittest discover -s tests -v
```

Build a wheel:

```bash
python -m pip wheel . --no-deps --no-build-isolation --wheel-dir dist
```

## Data provenance and licensing

The coefficient CSV is a transcription of Tables I and II in the cited
article. The source page is recorded in every row. Please cite the original RWT
article when using the method in research.

The Python source code is released under the MIT License. The license applies
to this software implementation and does not replace the citation or usage
terms of the source publication.
