Computed Parameters
derive_param_computed
admiralpy.derive_param_computed.derive_param_computed(dataset, by_vars, parameters, set_values_to, filter_add=None, keep_nas=False)
Add a parameter computed from the analysis values of other parameters.
For each group defined by by_vars, a new record is created that
contains the derived parameter. The analysis values of other parameters
are made available under the name <variable>_<PARAMCD>
(e.g. AVAL_SYSBP).
Mirrors derive_param_computed() from the admiral R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataFrame
|
Input BDS dataset. Must contain |
required |
by_vars
|
list of str
|
Variables that uniquely identify the group for which the new record
is created (e.g. |
required |
parameters
|
list of str
|
|
required |
set_values_to
|
dict
|
Mapping of
Example:: |
required |
filter_add
|
str or callable
|
Condition applied to |
None
|
keep_nas
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Input dataset with the new parameter record appended. Variables not
specified in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> import pandas as pd
>>> from admiralpy import derive_param_computed
>>> advs = pd.DataFrame({
... "USUBJID": ["P01", "P01", "P01", "P01"],
... "AVISIT": ["BASELINE", "BASELINE", "WEEK 2", "WEEK 2"],
... "PARAMCD": ["SYSBP", "DIABP", "SYSBP", "DIABP"],
... "AVAL": [120.0, 80.0, 118.0, 78.0],
... })
>>> derive_param_computed(
... advs,
... by_vars=["USUBJID", "AVISIT"],
... parameters=["SYSBP", "DIABP"],
... set_values_to={
... "AVAL": lambda w: (w["AVAL_SYSBP"] + 2 * w["AVAL_DIABP"]) / 3,
... "PARAMCD": "MAP",
... "PARAM": "Mean Arterial Pressure (mmHg)",
... },
... )
Source code in admiralpy/derive_param_computed.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |