Bits & Flames bitsandflames/fyron

Cohort And Analysis Reference

Cohort construction, preprocessing, descriptive tables, statistical tests, effects, bootstrap intervals, and phenotype rules.

For workflow context, see Cohort And Analysis module guide.

Functions And Classes

fyron.cohort.tables.build_survival_columns

Build standard survival `time and event` columns from date fields.

Import path: fyron.cohort.tables.build_survival_columns

python
build_survival_columns(df: pd.DataFrame, *, start_col: str, end_col: str, event_col: str, time_col: str = 'time', event_out_col: str = 'event') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort table containing start, end, and event columns.
start_colyesstrBaseline or index-date column where follow-up begins.
end_colyesstrEndpoint or censoring column where follow-up ends.
event_colyesstrExisting column indicating whether the event occurred.
time_colnostr'time'Name of the output duration column.
event_out_colnostr'event'Name of the output event-indicator column.

Returns

pandas.DataFrame - Copy of `df with duration and event columns appended. Negative durations raise a ValueError`.

See also: Cohort And Analysis module guide.

fyron.cohort.tables.build_time_to_event_endpoint

Build time-to-event columns from index, event, and censor dates.

Import path: fyron.cohort.tables.build_time_to_event_endpoint

python
build_time_to_event_endpoint(df: pd.DataFrame, *, index_date_col: str, event_date_col: str, censor_date_col: str, time_col: str = 'time', event_col: str = 'event', endpoint_date_col: str = 'endpoint_date', endpoint_source_col: str = 'endpoint_source', time_unit: TimeUnit = 'days', require_endpoint: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort table with one row per patient or analysis unit.
index_date_colyesstrStart date for follow-up, such as diagnosis, baseline CT, or treatment start.
event_date_colyesstrDate of the event of interest. Missing values are treated as censored.
censor_date_colyesstrLast known follow-up or administrative censoring date.
time_colnostr'time'Name of the output follow-up duration column.
event_colnostr'event'Name of the output binary event-indicator column.
endpoint_date_colnostr'endpoint_date'Name of the output column storing the selected event or censoring date.
endpoint_source_colnostr'endpoint_source'Name of the output column storing `"event", "censor", or "missing"`.
time_unitnoTimeUnit'days'Unit for the computed follow-up time: `"days", "weeks", "months", or "years"`.
require_endpointnoboolTrueIf True, rows without both event and censor dates raise an error.

Returns

pandas.DataFrame - Copy of `df` with time, event, endpoint date, and endpoint source columns.

See also: Cohort And Analysis module guide.

fyron.cohort.tables.cohort_profile

Create a compact audit table for a patient-level cohort.

Import path: fyron.cohort.tables.cohort_profile

python
cohort_profile(df: pd.DataFrame, *, id_col: str = 'patient_id', endpoint_cols: Sequence[str] | None = None, group_col: str | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort table to profile.
id_colnostr'patient_id'Patient or analysis-unit identifier.
endpoint_colsnoSequence[str] or NoneNoneOptional binary or numeric endpoint columns to summarize.
group_colnostr or NoneNoneOptional subgroup column for distribution checks.

Returns

pandas.DataFrame - Rows named by `metric` with values useful for cohort review.

See also: Cohort And Analysis module guide.

fyron.cohort.tables.join_cohort_tables

Join feature and outcome tables on a patient identifier.

Import path: fyron.cohort.tables.join_cohort_tables

python
join_cohort_tables(features: pd.DataFrame, outcomes: pd.DataFrame, *, on: str = 'patient_id', how: str = 'inner', validate: str = 'one_to_one') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
featuresyespd.DataFramePatient-level predictors (must include `on`).
outcomesyespd.DataFramePatient-level outcomes (must include `on`).
onnostr'patient_id'Join key column name.
hownostr'inner'Merge strategy passed to :meth:pandas.DataFrame.merge.
validatenostr'one_to_one'Merge validation (e.g. `one_to_one`) to catch duplicate keys.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.cohort.tables.validate_cohort_table

Validate a cohort DataFrame for analysis-ready use.

Import path: fyron.cohort.tables.validate_cohort_table

python
validate_cohort_table(df: pd.DataFrame, *, required_columns: Sequence[str], id_column: str | None = 'patient_id', allow_duplicate_ids: bool = False) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort table with one row per patient, lesion, study, or other declared analysis unit.
required_columnsyesSequence[str]Column names that must be present before the cohort can be used downstream.
id_columnnostr or None'patient_id'Optional identifier column used to detect missing or duplicate analysis units. Pass `None` to skip identifier checks.
allow_duplicate_idsnoboolFalseIf False, duplicate values in `id_column raise a ValueError`.

Returns

pandas.DataFrame - The original input DataFrame, unchanged, when all validation checks pass.

See also: Cohort And Analysis module guide.

fyron.dataframe.add_code_indicators

Add binary indicator columns for selected clinical codes.

Import path: fyron.dataframe.add_code_indicators

python
add_code_indicators(df: pd.DataFrame, code_col: str, codes: Sequence[Any] | Mapping[str, Sequence[Any]], *, sep: str = ';', prefix: str = 'code_', normalize: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing a code column.
code_colyesstrColumn with one or more codes per row.
codesyesSequence[Any] or Mapping[str, Sequence[Any]]Either a sequence of codes or a mapping from output names to code lists.
sepnostr';'Delimiter between multiple codes in one cell.
prefixnostr'code_'Prefix used for generated indicator columns.
normalizenoboolTrueIf True, normalize both input and target codes before matching.

Returns

pandas.DataFrame - Copy of `df` with binary indicator columns.

See also: Cohort And Analysis module guide.

fyron.dataframe.add_date_difference

Add a date-difference feature from two DataFrame columns.

Import path: fyron.dataframe.add_date_difference

python
add_date_difference(df: pd.DataFrame, start_col: str, end_col: str, output_col: str, *, unit: TimeUnit = 'days', absolute: bool = False, allow_negative: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing start and end date columns.
start_colyesstrStart date column.
end_colyesstrEnd date column.
output_colyesstrName of the created numeric difference column.
unitnoTimeUnit'days'Output unit: `"days", "weeks", "months", or "years"`.
absolutenoboolFalseIf True, store absolute differences.
allow_negativenoboolTrueIf False, raise when a non-missing negative interval is computed.

Returns

pandas.DataFrame - Copy of `df` with the created difference column.

See also: Cohort And Analysis module guide.

fyron.dataframe.add_icd10_disease_groups

Add broad ICD-10 disease-group indicator columns.

Import path: fyron.dataframe.add_icd10_disease_groups

python
add_icd10_disease_groups(df: pd.DataFrame, icd_col: str, *, sep: str = ';', prefix: str = 'icd10_group_', summary_col: str = 'icd10_groups', count_col: str = 'n_icd10_groups', groups: Sequence[str] | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing an ICD-10 code column.
icd_colyesstrColumn with one or more ICD-10 codes per row.
sepnostr';'Delimiter between multiple codes in one cell.
prefixnostr'icd10_group_'Prefix for generated binary indicator columns.
summary_colnostr'icd10_groups'Output column containing human-readable disease groups.
count_colnostr'n_icd10_groups'Output column containing the number of disease groups per row.
groupsnoSequence[str] or NoneNoneOptional explicit disease-group order. Defaults to Fyron's built-in broad ICD-10 groups.

Returns

pandas.DataFrame - Copy of `df` with binary disease-group indicators and summary columns.

See also: Cohort And Analysis module guide.

fyron.dataframe.add_ops_categories

Add broad German OPS procedure-category indicator columns.

Import path: fyron.dataframe.add_ops_categories

python
add_ops_categories(df: pd.DataFrame, ops_col: str, *, sep: str = ';', prefix: str = 'ops_category_', summary_col: str = 'ops_categories', count_col: str = 'n_ops_categories', categories: Sequence[str] | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing an OPS code column.
ops_colyesstrColumn with one or more OPS codes per row.
sepnostr';'Delimiter between multiple codes in one cell.
prefixnostr'ops_category_'Prefix for generated binary indicator columns.
summary_colnostr'ops_categories'Output column containing human-readable OPS categories.
count_colnostr'n_ops_categories'Output column containing the number of OPS categories per row.
categoriesnoSequence[str] or NoneNoneOptional explicit category order. Defaults to Fyron's broad OPS groups.

Returns

pandas.DataFrame - Copy of `df` with binary OPS category indicators and summary columns.

See also: Cohort And Analysis module guide.

fyron.dataframe.add_time_window_flag

Flag rows where a date falls within a window around an index date.

Import path: fyron.dataframe.add_time_window_flag

python
add_time_window_flag(df: pd.DataFrame, date_col: str, index_date_col: str, output_col: str, *, before: float | None = None, after: float | None = None, unit: TimeUnit = 'days') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing event and index date columns.
date_colyesstrDate to test against the index date.
index_date_colyesstrIndex/reference date column.
output_colyesstrName of the created binary flag column.
beforenofloat or NoneNoneMaximum time before the index date allowed in the window.
afternofloat or NoneNoneMaximum time after the index date allowed in the window.
unitnoTimeUnit'days'Window unit: `"days", "weeks", "months", or "years"`.

Returns

pandas.DataFrame - Copy of `df` with an integer 0/1 window flag column.

See also: Cohort And Analysis module guide.

fyron.dataframe.age_at_date

Add age in years at a reference date.

Import path: fyron.dataframe.age_at_date

python
age_at_date(df: pd.DataFrame, birth_date_col: str, reference_date_col: str, *, output_col: str = 'age_years') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing birth and reference dates.
birth_date_colyesstrDate-of-birth column.
reference_date_colyesstrDate column where age should be calculated, such as diagnosis or index date.
output_colnostr'age_years'Name of the created age column.

Returns

pandas.DataFrame - Copy of `df` with age in years.

See also: Cohort And Analysis module guide.

fyron.dataframe.classify_icd10

Classify one ICD-10 code into a broad disease group.

Import path: fyron.dataframe.classify_icd10

python
classify_icd10(code: Any) -> str | None

Parameters

ParameterRequiredTypeDefaultDescription
codeyesAnyICD-10 code such as `"C34", "I50.1", or "Z51"`.

Returns

str or None - Broad disease group name, `"Other"` for malformed non-empty codes, or None for missing values.

See also: Cohort And Analysis module guide.

fyron.dataframe.classify_icd10_string

Classify a delimited ICD-10 code string into disease groups.

Import path: fyron.dataframe.classify_icd10_string

python
classify_icd10_string(value: Any, *, sep: str = ';') -> set[str]

Parameters

ParameterRequiredTypeDefaultDescription
valueyesAnyScalar cell containing one or more ICD-10 codes.
sepnostr';'Delimiter between codes.

Returns

set[str] - Disease groups present in the code string.

See also: Cohort And Analysis module guide.

fyron.dataframe.classify_ops

Classify one German OPS code into a broad procedure category.

Import path: fyron.dataframe.classify_ops

python
classify_ops(code: Any) -> str | None

Parameters

ParameterRequiredTypeDefaultDescription
codeyesAnyOPS code such as `"1-620", "3-20", "5-541", or "8-980"`.

Returns

str or None - Broad OPS category, `"Other"` for malformed non-empty codes, or None for missing values.

See also: Cohort And Analysis module guide.

fyron.dataframe.classify_ops_string

Classify a delimited OPS code string into broad procedure categories.

Import path: fyron.dataframe.classify_ops_string

python
classify_ops_string(value: Any, *, sep: str = ';') -> set[str]

Parameters

ParameterRequiredTypeDefaultDescription
valueyesAnyScalar cell containing one or more OPS codes.
sepnostr';'Delimiter between codes.

Returns

set[str] - OPS categories present in the code string.

See also: Cohort And Analysis module guide.

fyron.dataframe.date_difference

Calculate a date difference in days, weeks, months, or years.

Import path: fyron.dataframe.date_difference

python
date_difference(start: Any, end: Any, *, unit: TimeUnit = 'days', absolute: bool = False) -> pd.Series

Parameters

ParameterRequiredTypeDefaultDescription
startyesAnyStart date scalar or array-like value.
endyesAnyEnd date scalar or array-like value.
unitnoTimeUnit'days'Output unit: `"days", "weeks", "months", or "years"`.
absolutenoboolFalseIf True, return absolute differences.

Returns

pandas.Series - Numeric difference in the requested unit.

See also: Cohort And Analysis module guide.

fyron.dataframe.explode_code_column

Explode a delimited clinical code column into one row per code.

Import path: fyron.dataframe.explode_code_column

python
explode_code_column(df: pd.DataFrame, code_col: str, *, sep: str = ';', output_col: str = 'code', keep_empty: bool = False) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame containing a delimited code column.
code_colyesstrColumn with one or more codes per row.
sepnostr';'Delimiter between codes.
output_colnostr'code'Name of the exploded output code column.
keep_emptynoboolFalseIf True, keep rows without codes and set `output_col` to missing.

Returns

pandas.DataFrame - Exploded DataFrame with one row per parsed code.

See also: Cohort And Analysis module guide.

fyron.dataframe.icd10_group_prevalence

Summarize ICD-10 disease-group indicator prevalence.

Import path: fyron.dataframe.icd10_group_prevalence

python
icd10_group_prevalence(df: pd.DataFrame, *, group_cols: Sequence[str] | None = None, prefix: str = 'icd10_group_') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame with ICD-10 group indicator columns.
group_colsnoSequence[str] or NoneNoneOptional explicit indicator columns. If omitted, columns with `prefix` are used.
prefixnostr'icd10_group_'Prefix used to discover indicator columns.

Returns

pandas.DataFrame - Prevalence table with group, column, patient count, and percent.

See also: Cohort And Analysis module guide.

fyron.dataframe.normalize_code

Normalize one clinical code value for matching.

Import path: fyron.dataframe.normalize_code

python
normalize_code(value: Any, *, uppercase: bool = True, remove_spaces: bool = True, remove_dots: bool = False) -> str | None

Parameters

ParameterRequiredTypeDefaultDescription
valueyesAnyRaw code value such as an ICD-10, OPS, medication, or local registry code.
uppercasenoboolTrueIf True, convert the returned code to uppercase.
remove_spacesnoboolTrueIf True, remove whitespace within the code.
remove_dotsnoboolFalseIf True, remove dots from the code.

Returns

str or None - Normalized code string, or None for missing/empty values.

See also: Cohort And Analysis module guide.

fyron.dataframe.ops_category_prevalence

Summarize OPS procedure-category indicator prevalence.

Import path: fyron.dataframe.ops_category_prevalence

python
ops_category_prevalence(df: pd.DataFrame, *, category_cols: Sequence[str] | None = None, prefix: str = 'ops_category_') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameDataFrame with OPS category indicator columns.
category_colsnoSequence[str] or NoneNoneOptional explicit indicator columns. If omitted, columns with `prefix` are used.
prefixnostr'ops_category_'Prefix used to discover indicator columns.

Returns

pandas.DataFrame - Prevalence table with category, column, patient count, and percent.

See also: Cohort And Analysis module guide.

fyron.dataframe.split_code_string

Split one cell containing one or more clinical codes.

Import path: fyron.dataframe.split_code_string

python
split_code_string(value: Any, *, sep: str = ';', normalize: bool = True) -> list[str]

Parameters

ParameterRequiredTypeDefaultDescription
valueyesAnyScalar value containing one or more codes, usually separated by semicolons.
sepnostr';'Delimiter used between codes.
normalizenoboolTrueIf True, normalize each code with :func:normalize_code.

Returns

list[str] - Ordered list of non-empty codes.

See also: Cohort And Analysis module guide.

fyron.descriptive.analysis.compare_descriptive_groups

Compare descriptive variables across groups with explicit statistical tests.

Import path: fyron.descriptive.analysis.compare_descriptive_groups

python
compare_descriptive_groups(df: pd.DataFrame, *, group_col: str, numeric: Sequence[str] | None = None, categorical: Sequence[str] | None = None, include_smd: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort or analysis table.
group_colyesstrColumn defining comparison groups.
numericnoSequence[str] or NoneNoneNumeric variables to compare. If omitted, numeric columns are selected automatically.
categoricalnoSequence[str] or NoneNoneCategorical variables to compare. If omitted, remaining non-numeric columns are selected automatically.
include_smdnoboolTrueIf True, include standardized mean difference summaries.

Returns

pandas.DataFrame - One row per variable with variable type, test result fields, p-value, optional SMD, and error text when a comparison cannot be computed.

See also: Cohort And Analysis module guide.

fyron.descriptive.analysis.create_table_one

Create a table-one style long table with optional p-values.

Import path: fyron.descriptive.analysis.create_table_one

python
create_table_one(df: pd.DataFrame, *, group_col: str | None = None, numeric: Sequence[str] | None = None, categorical: Sequence[str] | None = None, include_smd: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort table to describe.
group_colnostr or NoneNoneOptional group column such as treatment arm, cohort, split, or outcome.
numericnoSequence[str] or NoneNoneNumeric variables to include. If omitted, numeric columns are selected automatically.
categoricalnoSequence[str] or NoneNoneCategorical variables to include. If omitted, non-numeric columns are selected automatically.
include_smdnoboolTrueIf True and `group_col` is provided, include standardized mean difference values.

Returns

pandas.DataFrame - Long Table 1 style output with variable, level, group, formatted summary, and optional p-value, SMD, and test columns.

See also: Cohort And Analysis module guide.

fyron.descriptive.analysis.describe_categorical

Describe categorical variables with counts and percentages.

Import path: fyron.descriptive.analysis.describe_categorical

python
describe_categorical(df: pd.DataFrame, *, columns: Sequence[str] | None = None, group_col: str | None = None, include_missing: bool = True, digits: int = 1) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort or analysis table.
columnsnoSequence[str] or NoneNoneCategorical columns to summarize. If omitted, non-numeric columns are selected automatically.
group_colnostr or NoneNoneOptional grouping column for stratified summaries.
include_missingnoboolTrueInclude missing values as an explicit `"<missing>"` level.
digitsnoint1Decimal places used for percentages.

Returns

pandas.DataFrame - Long table with group, variable, level, count, and percent columns.

See also: Cohort And Analysis module guide.

fyron.descriptive.analysis.describe_numeric

Describe numeric variables with n, missing, mean, SD, median, IQR, and range.

Import path: fyron.descriptive.analysis.describe_numeric

python
describe_numeric(df: pd.DataFrame, *, columns: Sequence[str] | None = None, group_col: str | None = None, digits: int = 2) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort or analysis table.
columnsnoSequence[str] or NoneNoneNumeric columns to summarize. If omitted, numeric columns are selected automatically.
group_colnostr or NoneNoneOptional grouping column for stratified summaries.
digitsnoint2Decimal places used for rounded numeric summaries.

Returns

pandas.DataFrame - Long table with one row per variable and group containing count, missingness, mean, standard deviation, median, quartiles, and range.

See also: Cohort And Analysis module guide.

fyron.descriptive.analysis.summarize_endpoint

Summarize endpoint counts, event rates, and optional follow-up time.

Import path: fyron.descriptive.analysis.summarize_endpoint

python
summarize_endpoint(df: pd.DataFrame, *, event_col: str, time_col: str | None = None, group_col: str | None = None, digits: int = 2) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort table containing endpoint and optional follow-up columns.
event_colyesstrBinary or numeric event-indicator column where nonzero values count as events.
time_colnostr or NoneNoneOptional duration/follow-up column to summarize.
group_colnostr or NoneNoneOptional grouping column for stratified endpoint summaries.
digitsnoint2Decimal places used for percentages and follow-up summaries.

Returns

pandas.DataFrame - One row per group with sample size, event count, event rate, and optional median/min/max follow-up.

See also: Cohort And Analysis module guide.

fyron.phenotyping.rules.combine_phenotypes

Combine patient-level phenotype tables with an any/all rule.

Import path: fyron.phenotyping.rules.combine_phenotypes

python
combine_phenotypes(tables: Sequence[pd.DataFrame], *, patient_col: str = 'patient_id', strategy: CombineStrategy = 'any', phenotype_name: str = 'combined') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
tablesyesSequence[pd.DataFrame]See signature.
patient_colnostr'patient_id'See signature.
strategynoCombineStrategy'any'See signature.
phenotype_namenostr'combined'See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.phenotyping.rules.define_code_phenotype

Define a phenotype from diagnosis/procedure/code rows.

Import path: fyron.phenotyping.rules.define_code_phenotype

python
define_code_phenotype(df: pd.DataFrame, code_col: str, codes: Sequence[Any], *, patient_col: str = 'patient_id', date_col: str | None = None, phenotype_name: str = 'phenotype', code_system_col: str | None = None, code_systems: Sequence[Any] | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
code_colyesstrSee signature.
codesyesSequence[Any]See signature.
patient_colnostr'patient_id'See signature.
date_colnostr or NoneNoneSee signature.
phenotype_namenostr'phenotype'See signature.
code_system_colnostr or NoneNoneSee signature.
code_systemsnoSequence[Any] or NoneNoneSee signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.phenotyping.rules.define_lab_threshold_phenotype

Define a phenotype from numeric lab/measurement thresholds.

Import path: fyron.phenotyping.rules.define_lab_threshold_phenotype

python
define_lab_threshold_phenotype(df: pd.DataFrame, value_col: str, threshold: float, *, direction: ThresholdDirection = '>=', patient_col: str = 'patient_id', date_col: str | None = None, phenotype_name: str = 'phenotype') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
value_colyesstrSee signature.
thresholdyesfloatSee signature.
directionnoThresholdDirection'>='See signature.
patient_colnostr'patient_id'See signature.
date_colnostr or NoneNoneSee signature.
phenotype_namenostr'phenotype'See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.phenotyping.rules.define_medication_exposure

Define medication exposure from medication name/code rows.

Import path: fyron.phenotyping.rules.define_medication_exposure

python
define_medication_exposure(df: pd.DataFrame, medication_col: str, medications: Sequence[Any], *, patient_col: str = 'patient_id', start_col: str | None = None, end_col: str | None = None, phenotype_name: str = 'exposure') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
medication_colyesstrSee signature.
medicationsyesSequence[Any]See signature.
patient_colnostr'patient_id'See signature.
start_colnostr or NoneNoneSee signature.
end_colnostr or NoneNoneSee signature.
phenotype_namenostr'exposure'See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.phenotyping.rules.phenotype_summary

Summarize phenotype prevalence overall or by group.

Import path: fyron.phenotyping.rules.phenotype_summary

python
phenotype_summary(df: pd.DataFrame, phenotype_col: str, *, patient_col: str = 'patient_id', group_col: str | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
phenotype_colyesstrSee signature.
patient_colnostr'patient_id'See signature.
group_colnostr or NoneNoneSee signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.encoding.apply_categorical_encoder

Apply a fitted Fyron categorical encoder.

Import path: fyron.preprocessing.encoding.apply_categorical_encoder

python
apply_categorical_encoder(df: pd.DataFrame, encoder: dict[str, Any]) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
encoderyesdict[str, Any]See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.encoding.encode_categorical

Fit and apply a categorical encoder to one DataFrame.

Import path: fyron.preprocessing.encoding.encode_categorical

python
encode_categorical(df: pd.DataFrame, **kwargs: Any) -> tuple[pd.DataFrame, dict[str, Any]]

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
kwargsyesAnySee signature.

Returns

tuple[pd.DataFrame, dict[str, Any]]

See also: Cohort And Analysis module guide.

fyron.preprocessing.encoding.fit_categorical_encoder

Fit a deterministic one-hot encoder specification.

Import path: fyron.preprocessing.encoding.fit_categorical_encoder

python
fit_categorical_encoder(df: pd.DataFrame, *, columns: Sequence[str] | None = None, drop_first: bool = False, rare_min_count: int | None = None, rare_label: str = '__rare__') -> dict[str, Any]

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
columnsnoSequence[str] or NoneNoneSee signature.
drop_firstnoboolFalseSee signature.
rare_min_countnoint or NoneNoneSee signature.
rare_labelnostr'__rare__'See signature.

Returns

dict[str, Any]

See also: Cohort And Analysis module guide.

fyron.preprocessing.encoding.summarize_encoding_plan

Summarize categorical levels before one-hot encoding.

Import path: fyron.preprocessing.encoding.summarize_encoding_plan

python
summarize_encoding_plan(df: pd.DataFrame, *, columns: Sequence[str] | None = None, max_levels: int = 20) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
columnsnoSequence[str] or NoneNoneSee signature.
max_levelsnoint20See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.imputation.apply_imputer

Apply a fitted Fyron imputer to a DataFrame.

Import path: fyron.preprocessing.imputation.apply_imputer

python
apply_imputer(df: pd.DataFrame, imputer: dict[str, Any]) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
imputeryesdict[str, Any]See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.imputation.fit_imputer

Fit a lightweight imputation specification on a training DataFrame.

Import path: fyron.preprocessing.imputation.fit_imputer

python
fit_imputer(df: pd.DataFrame, *, numeric: Sequence[str] | None = None, categorical: Sequence[str] | None = None, strategy_numeric: NumericStrategy = 'median', strategy_categorical: CategoricalStrategy = 'most_frequent', fill_value_numeric: float = 0.0, fill_value_categorical: str = '__missing__', add_missing_indicators: bool = False) -> dict[str, Any]

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
numericnoSequence[str] or NoneNoneSee signature.
categoricalnoSequence[str] or NoneNoneSee signature.
strategy_numericnoNumericStrategy'median'See signature.
strategy_categoricalnoCategoricalStrategy'most_frequent'See signature.
fill_value_numericnofloat0.0See signature.
fill_value_categoricalnostr'__missing__'See signature.
add_missing_indicatorsnoboolFalseSee signature.

Returns

dict[str, Any]

See also: Cohort And Analysis module guide.

fyron.preprocessing.imputation.impute_dataframe

Fit and apply an imputer to one DataFrame.

Import path: fyron.preprocessing.imputation.impute_dataframe

python
impute_dataframe(df: pd.DataFrame, **kwargs: Any) -> tuple[pd.DataFrame, dict[str, Any]]

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
kwargsyesAnySee signature.

Returns

tuple[pd.DataFrame, dict[str, Any]]

See also: Cohort And Analysis module guide.

fyron.preprocessing.imputation.summarize_imputation_plan

Summarize columns and strategies before fitting an imputer.

Import path: fyron.preprocessing.imputation.summarize_imputation_plan

python
summarize_imputation_plan(df: pd.DataFrame, *, numeric: Sequence[str] | None = None, categorical: Sequence[str] | None = None, strategy_numeric: NumericStrategy = 'median', strategy_categorical: CategoricalStrategy = 'most_frequent') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
numericnoSequence[str] or NoneNoneSee signature.
categoricalnoSequence[str] or NoneNoneSee signature.
strategy_numericnoNumericStrategy'median'See signature.
strategy_categoricalnoCategoricalStrategy'most_frequent'See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.qc.compare_train_test_balance

Compare simple train/test distributions for leakage and split sanity checks.

Import path: fyron.preprocessing.qc.compare_train_test_balance

python
compare_train_test_balance(train: pd.DataFrame, test: pd.DataFrame, *, columns: Sequence[str] | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
trainyespd.DataFrameSee signature.
testyespd.DataFrameSee signature.
columnsnoSequence[str] or NoneNoneSee signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.qc.detect_potential_leakage

Flag column names that may encode outcomes, labels, or post-index information.

Import path: fyron.preprocessing.qc.detect_potential_leakage

python
detect_potential_leakage(columns: Sequence[str] | pd.DataFrame, *, outcome_keywords: Sequence[str] = ('event', 'death', 'survival', 'outcome', 'label', 'target'), time_keywords: Sequence[str] = ('followup', 'follow_up', 'last', 'end_date', 'post', 'af...) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
columnsyesSequence[str] or pd.DataFrameSee signature.
outcome_keywordsnoSequence[str]('event', 'death', 'survival', 'outcome', 'label', 'target')See signature.
time_keywordsnoSequence[str]('followup', 'follow_up', 'last', 'end_date', 'post', 'af...See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.qc.feature_matrix_report

Summarize feature-matrix quality before modeling.

Import path: fyron.preprocessing.qc.feature_matrix_report

python
feature_matrix_report(X: pd.DataFrame, y: Sequence[Any] | pd.Series | None = None, *, rare_threshold: float = 0.01, leakage_keywords: Sequence[str] = ('event', 'death', 'survival', 'outcome', 'label', 'target')) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
Xyespd.DataFrameFeature matrix with one column per candidate predictor.
ynoSequence[Any] or pd.Series or NoneNoneOptional labels used only for target count metadata.
rare_thresholdnofloat0.01Binary features with a minority-class frequency below this value are flagged.
leakage_keywordsnoSequence[str]('event', 'death', 'survival', 'outcome', 'label', 'target')Column-name fragments that suggest outcome or post-index leakage.

Returns

pandas.DataFrame - One row per feature with dtype, missingness, uniqueness, constant, rare-binary, and leakage-name flags.

See also: Cohort And Analysis module guide.

fyron.preprocessing.qc.find_duplicate_ids

Return rows whose patient identifier appears more than once.

Import path: fyron.preprocessing.qc.find_duplicate_ids

python
find_duplicate_ids(df: pd.DataFrame, *, id_col: str = 'patient_id') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
id_colnostr'patient_id'See signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.qc.summarize_categorical_levels

Summarize counts and percentages for categorical columns.

Import path: fyron.preprocessing.qc.summarize_categorical_levels

python
summarize_categorical_levels(df: pd.DataFrame, *, columns: Sequence[str] | None = None, max_levels: int = 20, include_missing: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
columnsnoSequence[str] or NoneNoneSee signature.
max_levelsnoint20See signature.
include_missingnoboolTrueSee signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.preprocessing.qc.summarize_missingness

Summarize missing values by column, optionally within groups.

Import path: fyron.preprocessing.qc.summarize_missingness

python
summarize_missingness(df: pd.DataFrame, *, columns: Sequence[str] | None = None, group_col: str | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameSee signature.
columnsnoSequence[str] or NoneNoneSee signature.
group_colnostr or NoneNoneSee signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.statistics.bootstrap.BootstrapResult

Result for one bootstrapped statistic.

Import path: fyron.statistics.bootstrap.BootstrapResult

python
BootstrapResult()

Parameters

No parameters documented.

Returns

Class constructor.

See also: Cohort And Analysis module guide.

Public Methods

fyron.statistics.bootstrap.BootstrapResult.to_dict

See the signature and linked module guide for context.

Import path: fyron.statistics.bootstrap.BootstrapResult.to_dict

python
BootstrapResult.to_dict(self, *, include_distribution: bool = False) -> dict[str, Any]

Parameters

ParameterRequiredTypeDefaultDescription
include_distributionnoboolFalseSee signature.

Returns

dict[str, Any]

See also: Cohort And Analysis module guide.

fyron.statistics.bootstrap.bootstrap_binary_classification_metrics

Bootstrap common binary classification metrics.

Import path: fyron.statistics.bootstrap.bootstrap_binary_classification_metrics

python
bootstrap_binary_classification_metrics(y_true: Sequence[Any], y_pred: Sequence[Any], y_prob: Sequence[Any] | None = None, *, metrics: Sequence[str] | None = None, pos_label: Any = 1, n_rounds: int = 1000, alpha: float = 0.05, random_state: int | None = None, drop_invalid: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
y_trueyesSequence[Any]See signature.
y_predyesSequence[Any]See signature.
y_probnoSequence[Any] or NoneNoneSee signature.
metricsnoSequence[str] or NoneNoneSee signature.
pos_labelnoAny1See signature.
n_roundsnoint1000See signature.
alphanofloat0.05See signature.
random_statenoint or NoneNoneSee signature.
drop_invalidnoboolTrueSee signature.

Returns

pd.DataFrame

See also: Cohort And Analysis module guide.

fyron.statistics.bootstrap.bootstrap_metric

Bootstrap an arbitrary metric over one or more aligned arrays.

Import path: fyron.statistics.bootstrap.bootstrap_metric

python
bootstrap_metric(*arrays: Sequence[Any], metric_func: MetricFunc, metric_name: str | None = None, n_rounds: int = 1000, alpha: float = 0.05, random_state: int | None = None, drop_invalid: bool = True, **metric_kwargs: Any) -> BootstrapResult

Parameters

ParameterRequiredTypeDefaultDescription
arraysyesSequence[Any]See signature.
metric_funcyesMetricFuncSee signature.
metric_namenostr or NoneNoneSee signature.
n_roundsnoint1000See signature.
alphanofloat0.05See signature.
random_statenoint or NoneNoneSee signature.
drop_invalidnoboolTrueSee signature.
metric_kwargsyesAnySee signature.

Returns

BootstrapResult

See also: Cohort And Analysis module guide.

fyron.statistics.bootstrap.bootstrap_summary

Bootstrap a one-sample summary statistic such as mean or median.

Import path: fyron.statistics.bootstrap.bootstrap_summary

python
bootstrap_summary(values: Sequence[Any], *, statistic: SummaryStatistic | Callable[[Any], float] = 'mean', n_rounds: int = 1000, alpha: float = 0.05, random_state: int | None = None) -> BootstrapResult

Parameters

ParameterRequiredTypeDefaultDescription
valuesyesSequence[Any]See signature.
statisticnoSummaryStatistic or Callable[[Any], float]'mean'See signature.
n_roundsnoint1000See signature.
alphanofloat0.05See signature.
random_statenoint or NoneNoneSee signature.

Returns

BootstrapResult

See also: Cohort And Analysis module guide.

fyron.statistics.comparison.bootstrap_auc_difference

Bootstrap the paired AUC difference between two models.

Import path: fyron.statistics.comparison.bootstrap_auc_difference

python
bootstrap_auc_difference(y_true: Sequence[Any], prob_a: Sequence[Any], prob_b: Sequence[Any], *, pos_label: Any = 1, n_rounds: int = 1000, alpha: float = 0.05, random_state: int | None = None, drop_invalid: bool = True) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
y_trueyesSequence[Any]Ground-truth binary labels.
prob_ayesSequence[Any]Predicted probabilities or scores from model A.
prob_byesSequence[Any]Predicted probabilities or scores from model B on the same samples.
pos_labelnoAny1Label treated as the positive class.
n_roundsnoint1000Number of bootstrap resamples.
alphanofloat0.05Two-sided confidence interval width, where `0.05` gives 95% intervals.
random_statenoint or NoneNoneOptional random seed for reproducible resampling.
drop_invalidnoboolTrueIf True, skip bootstrap rounds that contain only one class.

Returns

pandas.DataFrame - One-row table with AUC for both models, paired AUC difference, bootstrap confidence interval, requested rounds, valid rounds, dropped rounds, and alpha.

See also: Cohort And Analysis module guide.

fyron.statistics.comparison.mcnemar_test

Run McNemar's paired test for two classifiers.

Import path: fyron.statistics.comparison.mcnemar_test

python
mcnemar_test(y_true: Sequence[Any], pred_a: Sequence[Any], pred_b: Sequence[Any], *, exact: bool = False) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
y_trueyesSequence[Any]Ground-truth class labels.
pred_ayesSequence[Any]Predicted class labels from model A.
pred_byesSequence[Any]Predicted class labels from model B on the same samples.
exactnoboolFalseIf True, use the exact binomial version; otherwise use the continuity corrected chi-square approximation.

Returns

pandas.DataFrame - One-row table with the test name, statistic, p-value, total sample size, discordant-pair counts, and exact-test flag.

See also: Cohort And Analysis module guide.

fyron.statistics.correction.adjust_p_values

Adjust p-values for multiple testing and return a review table.

Import path: fyron.statistics.correction.adjust_p_values

python
adjust_p_values(p_values: Sequence[Any], *, method: PValueCorrectionMethod = 'fdr_bh', alpha: float = 0.05) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
p_valuesyesSequence[Any]Sequence of raw p-values. Missing values are preserved.
methodnoPValueCorrectionMethod'fdr_bh'Correction method: `"fdr_bh"/Benjamini-Hochberg, "bonferroni", "holm", or "none"`.
alphanofloat0.05Significance level used to compute the rejected flag.

Returns

pandas.DataFrame - One row per p-value with raw p-value, adjusted p-value, rank, rejected flag, correction method, and alpha.

See also: Cohort And Analysis module guide.

fyron.statistics.correction.p_value_correction_table

Append adjusted p-values and rejection flags to a result DataFrame.

Import path: fyron.statistics.correction.p_value_correction_table

python
p_value_correction_table(df: pd.DataFrame, *, p_col: str = 'p_value', method: PValueCorrectionMethod = 'fdr_bh', alpha: float = 0.05) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameResult table containing one raw p-value column, for example a regression, correlation, or feature-screening table.
p_colnostr'p_value'Name of the column containing raw p-values.
methodnoPValueCorrectionMethod'fdr_bh'Multiple-testing correction method. Use `"fdr_bh" for Benjamini-Hochberg FDR, "bonferroni", "holm", or "none"`.
alphanofloat0.05Significance threshold used to compute the `rejected` flag.

Returns

pandas.DataFrame - Copy of `df with p_adjusted, p_rank, rejected, p_adjust_method, and alpha` columns appended.

See also: Cohort And Analysis module guide.

fyron.statistics.effects.cliffs_delta

Return Cliff's delta for ordinal/non-parametric two-group comparisons.

Import path: fyron.statistics.effects.cliffs_delta

python
cliffs_delta(group_a: Sequence[Any], group_b: Sequence[Any]) -> float

Parameters

ParameterRequiredTypeDefaultDescription
group_ayesSequence[Any]See signature.
group_byesSequence[Any]See signature.

Returns

float

See also: Cohort And Analysis module guide.

fyron.statistics.effects.cohens_d

Return Cohen's d for two independent numeric groups.

Import path: fyron.statistics.effects.cohens_d

python
cohens_d(group_a: Sequence[Any], group_b: Sequence[Any]) -> float

Parameters

ParameterRequiredTypeDefaultDescription
group_ayesSequence[Any]See signature.
group_byesSequence[Any]See signature.

Returns

float

See also: Cohort And Analysis module guide.

fyron.statistics.effects.cramers_v

Return Cramer's V for a contingency table.

Import path: fyron.statistics.effects.cramers_v

python
cramers_v(table: Sequence[Sequence[Any]]) -> float

Parameters

ParameterRequiredTypeDefaultDescription
tableyesSequence[Sequence[Any]]See signature.

Returns

float

See also: Cohort And Analysis module guide.

fyron.statistics.effects.odds_ratio_ci

Return odds ratio and Wald confidence interval for a 2x2 table.

Import path: fyron.statistics.effects.odds_ratio_ci

python
odds_ratio_ci(table: Sequence[Sequence[Any]], *, alpha: float = 0.05, correction: float = 0.5) -> dict[str, float]

Parameters

ParameterRequiredTypeDefaultDescription
tableyesSequence[Sequence[Any]]See signature.
alphanofloat0.05See signature.
correctionnofloat0.5See signature.

Returns

dict[str, float]

See also: Cohort And Analysis module guide.

fyron.statistics.effects.risk_ratio_ci

Return risk ratio and Wald confidence interval for a 2x2 table.

Import path: fyron.statistics.effects.risk_ratio_ci

python
risk_ratio_ci(table: Sequence[Sequence[Any]], *, alpha: float = 0.05, correction: float = 0.5) -> dict[str, float]

Parameters

ParameterRequiredTypeDefaultDescription
tableyesSequence[Sequence[Any]]See signature.
alphanofloat0.05See signature.
correctionnofloat0.5See signature.

Returns

dict[str, float]

See also: Cohort And Analysis module guide.

fyron.statistics.effects.standardized_mean_difference

Return SMD for numeric values or binary categorical proportions.

Import path: fyron.statistics.effects.standardized_mean_difference

python
standardized_mean_difference(group_a: Sequence[Any], group_b: Sequence[Any], *, categorical: bool = False) -> float

Parameters

ParameterRequiredTypeDefaultDescription
group_ayesSequence[Any]See signature.
group_byesSequence[Any]See signature.
categoricalnoboolFalseSee signature.

Returns

float

See also: Cohort And Analysis module guide.

fyron.statistics.qc.correlation_pvalue_table

Return pairwise correlations, p-values, and optional adjusted p-values.

Import path: fyron.statistics.qc.correlation_pvalue_table

python
correlation_pvalue_table(df: pd.DataFrame, columns: Sequence[str], *, method: str = 'spearman', p_adjust: str | None = 'fdr_bh') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameAnalysis table containing numeric variables.
columnsyesSequence[str]Variables for pairwise correlation testing.
methodnostr'spearman'Correlation method, typically `"spearman" or "pearson"`.
p_adjustnostr or None'fdr_bh'Optional multiple-testing correction method. Pass `None` to keep only raw p-values.

Returns

pandas.DataFrame - Pairwise table with variable names, method, correlation coefficient, p-value, sample size, and optional adjusted p-value columns.

See also: Cohort And Analysis module guide.

fyron.statistics.qc.missingness_by_group_table

Summarize missingness overall and by group for manuscript supplements.

Import path: fyron.statistics.qc.missingness_by_group_table

python
missingness_by_group_table(df: pd.DataFrame, *, group_col: str, columns: Sequence[str] | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameCohort or feature table to audit.
group_colyesstrColumn defining groups such as cohort, center, split, or endpoint status.
columnsnoSequence[str] or NoneNoneColumns to summarize. If omitted, all columns except `group_col` are included.

Returns

pandas.DataFrame - Long table with variable, group, row count, missing count, and missing percent.

See also: Cohort And Analysis module guide.

fyron.statistics.qc.normality_table

Run normality tests for multiple columns and return one table.

Import path: fyron.statistics.qc.normality_table

python
normality_table(df: pd.DataFrame, columns: Sequence[str], *, method: str = 'shapiro') -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameAnalysis table containing numeric columns to test.
columnsyesSequence[str]Column names to test.
methodnostr'shapiro'Normality test passed to `normality_test. The default is "shapiro"`.

Returns

pandas.DataFrame - One row per variable with test name, statistic, p-value, non-missing sample size, and an error column when a test could not be computed.

See also: Cohort And Analysis module guide.

fyron.statistics.qc.outlier_table

Flag numeric outliers by IQR fences and return one summary row per column.

Import path: fyron.statistics.qc.outlier_table

python
outlier_table(df: pd.DataFrame, columns: Sequence[str], *, method: str = 'iqr', iqr_multiplier: float = 1.5) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameAnalysis table containing numeric variables.
columnsyesSequence[str]Numeric columns to inspect.
methodnostr'iqr'Outlier method. Currently only `"iqr"` is supported.
iqr_multipliernofloat1.5Multiplier for the IQR fence, commonly `1.5`.

Returns

pandas.DataFrame - One row per variable with non-missing count, outlier count, outlier percent, lower fence, and upper fence.

See also: Cohort And Analysis module guide.

fyron.statistics.regression.fit_linear_regression_table

Fit an ordinary least-squares model and return a manuscript table.

Import path: fyron.statistics.regression.fit_linear_regression_table

python
fit_linear_regression_table(df: pd.DataFrame, *, outcome_col: str, covariates: Sequence[str], add_intercept: bool = True, alpha: float = 0.05, p_adjust: str | None = None) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameAnalysis table containing the outcome and covariate columns.
outcome_colyesstrNumeric continuous outcome column.
covariatesyesSequence[str]Predictor columns. Categorical columns are dummy encoded with the first level dropped.
add_interceptnoboolTrueIf True, include an intercept row in the model and output table.
alphanofloat0.05Two-sided confidence interval width, where `0.05` gives 95% intervals.
p_adjustnostr or NoneNoneOptional multiple-testing correction method applied to non-intercept p-values, such as `"fdr_bh", "bonferroni", or "holm"`.

Returns

pandas.DataFrame - One row per model term with beta estimate, standard error, confidence interval, test statistic, p-value, sample size, model name, outcome, and formula.

See also: Cohort And Analysis module guide.

fyron.statistics.regression.fit_logistic_regression_table

Fit a binary logistic regression model and return OR/CI/p-value rows.

Import path: fyron.statistics.regression.fit_logistic_regression_table

python
fit_logistic_regression_table(df: pd.DataFrame, *, outcome_col: str, covariates: Sequence[str], add_intercept: bool = True, alpha: float = 0.05, p_adjust: str | None = None, max_iter: int = 1000) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameAnalysis table containing a binary outcome and covariate columns.
outcome_colyesstrBinary outcome column coded as `0 and 1`.
covariatesyesSequence[str]Predictor columns. Categorical columns are dummy encoded with the first level dropped.
add_interceptnoboolTrueIf True, include an intercept row in the model and output table.
alphanofloat0.05Two-sided confidence interval width, where `0.05` gives 95% intervals.
p_adjustnostr or NoneNoneOptional multiple-testing correction method applied to non-intercept p-values.
max_iternoint1000Maximum optimizer iterations for the logistic likelihood fit.

Returns

pandas.DataFrame - One row per model term with odds ratio, log-odds estimate, standard error, confidence interval, z statistic, p-value, sample size, model name, outcome, and formula.

See also: Cohort And Analysis module guide.

fyron.statistics.regression.vif_table

Return variance inflation factors for covariates after dummy encoding.

Import path: fyron.statistics.regression.vif_table

python
vif_table(df: pd.DataFrame, covariates: Sequence[str]) -> pd.DataFrame

Parameters

ParameterRequiredTypeDefaultDescription
dfyespd.DataFrameAnalysis table containing the covariate columns.
covariatesyesSequence[str]Predictor columns to inspect for multicollinearity. Categorical columns are dummy encoded before VIF calculation.

Returns

pandas.DataFrame - Table with one row per encoded term and columns `term, vif, and n`.

See also: Cohort And Analysis module guide.

fyron.statistics.tests.StatisticalTestResult

Named result returned by Fyron statistical tests.

Import path: fyron.statistics.tests.StatisticalTestResult

python
StatisticalTestResult()

Parameters

No parameters documented.

Returns

Class constructor.

See also: Cohort And Analysis module guide.

Public Methods

fyron.statistics.tests.StatisticalTestResult.to_dict

See the signature and linked module guide for context.

Import path: fyron.statistics.tests.StatisticalTestResult.to_dict

python
StatisticalTestResult.to_dict(self) -> dict[str, Any]

Parameters

No parameters documented.

Returns

dict[str, Any]

See also: Cohort And Analysis module guide.

fyron.statistics.tests.categorical_test

Run a chi-square or Fisher exact test on a contingency table.

Import path: fyron.statistics.tests.categorical_test

python
categorical_test(table: Sequence[Sequence[Any]], *, method: CategoricalMethod = 'auto') -> StatisticalTestResult

Parameters

ParameterRequiredTypeDefaultDescription
tableyesSequence[Sequence[Any]]See signature.
methodnoCategoricalMethod'auto'See signature.

Returns

StatisticalTestResult

See also: Cohort And Analysis module guide.

fyron.statistics.tests.compare_multiple_groups

Compare three or more numeric groups with ANOVA or Kruskal-Wallis.

Import path: fyron.statistics.tests.compare_multiple_groups

python
compare_multiple_groups(groups: Sequence[Sequence[Any]], *, method: MultiGroupMethod = 'auto') -> StatisticalTestResult

Parameters

ParameterRequiredTypeDefaultDescription
groupsyesSequence[Sequence[Any]]See signature.
methodnoMultiGroupMethod'auto'See signature.

Returns

StatisticalTestResult

See also: Cohort And Analysis module guide.

fyron.statistics.tests.compare_two_groups

Compare two numeric groups.

Import path: fyron.statistics.tests.compare_two_groups

python
compare_two_groups(group_a: Sequence[Any], group_b: Sequence[Any], *, paired: bool = False, method: TwoGroupMethod = 'auto', alternative: Alternative = 'two-sided', equal_var: bool = False) -> StatisticalTestResult

Parameters

ParameterRequiredTypeDefaultDescription
group_ayesSequence[Any]See signature.
group_byesSequence[Any]See signature.
pairednoboolFalseSee signature.
methodnoTwoGroupMethod'auto'See signature.
alternativenoAlternative'two-sided'See signature.
equal_varnoboolFalseSee signature.

Returns

StatisticalTestResult

See also: Cohort And Analysis module guide.

fyron.statistics.tests.correlation_test

Test association between two numeric variables.

Import path: fyron.statistics.tests.correlation_test

python
correlation_test(x: Sequence[Any], y: Sequence[Any], *, method: CorrelationMethod = 'spearman', alternative: Alternative = 'two-sided') -> StatisticalTestResult

Parameters

ParameterRequiredTypeDefaultDescription
xyesSequence[Any]See signature.
yyesSequence[Any]See signature.
methodnoCorrelationMethod'spearman'See signature.
alternativenoAlternative'two-sided'See signature.

Returns

StatisticalTestResult

See also: Cohort And Analysis module guide.

fyron.statistics.tests.normality_test

Test whether a numeric vector is compatible with a normal distribution.

Import path: fyron.statistics.tests.normality_test

python
normality_test(values: Sequence[Any], *, method: Literal['shapiro', 'normaltest'] = 'shapiro') -> StatisticalTestResult

Parameters

ParameterRequiredTypeDefaultDescription
valuesyesSequence[Any]See signature.
methodnoLiteral['shapiro', 'normaltest']'shapiro'See signature.

Returns

StatisticalTestResult

See also: Cohort And Analysis module guide.