Tidying Functions¶
circumplex.utils.tidying_functions
¶
Utility functions for data tidying and instrument scoring.
| FUNCTION | DESCRIPTION |
|---|---|
ipsatize |
Ipsatize item-level data by centering within individuals. |
score |
Score item-level data using a circumplex instrument. |
norm_standardize |
Standardize scale-level data using normative sample statistics. |
ipsatize
¶
ipsatize(data: DataFrame, items: Iterable[str | int], prefix: str = '', suffix: str = '_i', *, na_rm: bool = True, append: bool = True) -> pd.DataFrame
Ipsatize item-level data by centering within individuals.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame containing item-level data.
TYPE:
|
items
|
Tuple of column names corresponding to item-level data to ipsatize. |
prefix
|
Prefix to add to ipsatized column names, by default "".
TYPE:
|
suffix
|
Suffix to add to ipsatized column names, by default "".
TYPE:
|
na_rm
|
Whether to remove NAs when computing individual means, by default True.
TYPE:
|
append
|
Whether to append ipsatized columns to the original DataFrame, or return only the ipsatized columns, by default True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with ipsatized item-level data. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
ValueError
|
If any item in |
Source code in src/circumplex/utils/tidying_functions.py
score
¶
score(data: DataFrame, items: Iterable[str | int], instrument: Instrument | str, prefix: str = '', suffix: str = '', *, na_rm: bool = True, append: bool = True) -> pd.DataFrame
Score item-level data using a circumplex instrument.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame containing at least circumplex scales.
TYPE:
|
items
|
The variable names or column numbers for the variables in |
instrument
|
An instrument object from the package. To see the available
TYPE:
|
prefix
|
Prefix to add to scored column names, by default "".
TYPE:
|
suffix
|
Suffix to add to scored column names, by default "".
TYPE:
|
na_rm
|
Whether to remove NAs when computing individual means, by default True.
TYPE:
|
append
|
Whether to append scored columns to the original DataFrame, or return only the scored columns, by default True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with scored scale-level data. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
ValueError
|
If any item in |
Source code in src/circumplex/utils/tidying_functions.py
norm_standardize
¶
norm_standardize(data: DataFrame, instrument: Instrument | str, sample_id: int, scales: Iterable[str | int] | None = None, prefix: str = '', suffix: str = '_z', *, append: bool = True) -> pd.DataFrame
Standardize scale-level data using normative sample statistics.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
DataFrame containing scale-level data.
TYPE:
|
scales
|
Tuple of column names or indices corresponding to scale-level data to standardize. |
instrument
|
An instrument object from the package. To see the available
instruments, use
TYPE:
|
sample_id
|
The ID of the normative sample to use for standardization. |
prefix
|
Prefix to add to standardized column names, by default "".
TYPE:
|
suffix
|
Suffix to add to standardized column names, by default "_z".
TYPE:
|
append
|
Whether to append standardized columns to the original DataFrame, or return only the standardized columns, by default True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
DataFrame with standardized scale-level data. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
ValueError
|
If any scale in |