Baseline & Change
derive_var_base
admiralpy.derive_var_baseline.derive_var_base(dataset, by_vars, source_var='AVAL', new_var='BASE', filter_add=None)
Derive a baseline variable in a BDS dataset.
For each group defined by by_vars, the baseline record is identified
(by default the record where ABLFL == "Y"). The value of
source_var from that record is then merged back to all records in the
group as new_var.
Mirrors derive_var_base() from the admiral R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataFrame
|
Input dataset. Must contain the columns specified in |
required |
by_vars
|
list of str
|
Grouping variables that uniquely identify each subject/parameter
combination (e.g. |
required |
source_var
|
str
|
Column from which to extract the baseline value. Default is |
'AVAL'
|
new_var
|
str
|
Name of the new baseline column. Default is |
'BASE'
|
filter_add
|
str or callable
|
Condition used to identify baseline records.
|
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input dataset with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If more than one baseline record exists per |
Examples:
>>> import pandas as pd
>>> from admiralpy import derive_var_base
>>> df = pd.DataFrame({
... "USUBJID": ["P01", "P01", "P01"],
... "PARAMCD": ["WEIGHT", "WEIGHT", "WEIGHT"],
... "AVAL": [80.0, 80.8, 81.4],
... "ABLFL": ["Y", None, None],
... })
>>> derive_var_base(df, by_vars=["USUBJID", "PARAMCD"])
Source code in admiralpy/derive_var_baseline.py
derive_var_chg
admiralpy.derive_var_baseline.derive_var_chg(dataset)
Derive change from baseline (CHG) in a BDS dataset.
CHG is calculated as AVAL - BASE.
Mirrors derive_var_chg() from the admiral R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataFrame
|
Input dataset. Must contain |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input dataset with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import pandas as pd
>>> from admiralpy import derive_var_chg
>>> df = pd.DataFrame({
... "USUBJID": ["P01", "P01"],
... "PARAMCD": ["WEIGHT", "WEIGHT"],
... "AVAL": [80.0, 82.0],
... "BASE": [80.0, 80.0],
... })
>>> derive_var_chg(df)
Source code in admiralpy/derive_var_baseline.py
derive_var_pchg
admiralpy.derive_var_baseline.derive_var_pchg(dataset)
Derive percent change from baseline (PCHG) in a BDS dataset.
PCHG is calculated as (AVAL - BASE) / abs(BASE) * 100. When
BASE is zero the result is NaN (not a number).
Mirrors derive_var_pchg() from the admiral R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataFrame
|
Input dataset. Must contain |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input dataset with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import pandas as pd
>>> from admiralpy import derive_var_pchg
>>> df = pd.DataFrame({
... "USUBJID": ["P01", "P01"],
... "PARAMCD": ["WEIGHT", "WEIGHT"],
... "AVAL": [80.0, 82.0],
... "BASE": [80.0, 80.0],
... })
>>> derive_var_pchg(df)