Compute Functions
compute_age_years
admiralpy.compute.compute_age_years(age, age_unit)
Convert age values from the specified time unit to years.
Mirrors compute_age_years() from the admiral R package. Underlying
computations assume 365.25 days per year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
age
|
float, list, or pd.Series
|
Age values to convert. |
required |
age_unit
|
str, list, or pd.Series
|
Time unit(s) for the age values. May be a single string (applied to
all values) or a sequence of strings (one per age value). Values are
case-insensitive. Permitted values: |
required |
Returns:
| Type | Description |
|---|---|
float or Series
|
Age value(s) in years. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any unit value is not a recognised time unit. |
ValueError
|
If |
Examples:
>>> from admiralpy import compute_age_years
>>> compute_age_years(age=24, age_unit="months")
2.0027...
>>> compute_age_years(age=[240, 360, 480], age_unit="months")
[20.027..., 30.041..., 40.055...]
>>> compute_age_years(age=[10, 520, 3650], age_unit=["years", "weeks", "days"])
[10.0, 9.993..., 9.993...]
Source code in admiralpy/compute.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
compute_bmi
admiralpy.compute.compute_bmi(height, weight)
Compute Body Mass Index (BMI).
BMI = weight / (height / 100) ** 2
Mirrors compute_bmi() from the admiral R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
float, list, or pd.Series
|
Height in centimetres (cm). |
required |
weight
|
float, list, or pd.Series
|
Weight in kilograms (kg). |
required |
Returns:
| Type | Description |
|---|---|
float or Series
|
BMI in kg/m². Returns |
Examples:
>>> from admiralpy import compute_bmi
>>> compute_bmi(height=170, weight=75)
25.95...
>>> import pandas as pd
>>> compute_bmi(height=pd.Series([170, 180]), weight=pd.Series([75, 90]))
0 25.95...
1 27.77...
dtype: float64
Source code in admiralpy/compute.py
compute_bsa
admiralpy.compute.compute_bsa(height, weight, method='mosteller')
Compute Body Surface Area (BSA).
Mirrors compute_bsa() from the admiral R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
float, list, or pd.Series
|
Height in centimetres (cm). |
required |
weight
|
float, list, or pd.Series
|
Weight in kilograms (kg). |
required |
method
|
str
|
Formula to use. One of:
|
'mosteller'
|
Returns:
| Type | Description |
|---|---|
float or Series
|
BSA in m². Returns |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from admiralpy import compute_bsa
>>> compute_bsa(height=170, weight=75)
1.876...
>>> compute_bsa(height=170, weight=75, method="dubois")
1.862...