Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions openavmkit/utilities/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,14 @@ def calc_r2(
results["coef_sign"].append(float("nan"))
continue # skip ill-posed models

# Skip non-numeric columns (e.g. string categoricals); .astype(float) would raise ValueError
if not pd.api.types.is_numeric_dtype(data[var]):
results["variable"].append(var)
results["r2"].append(float("nan"))
results["adj_r2"].append(float("nan"))
results["coef_sign"].append(float("nan"))
continue

X = sm.add_constant(data[var].astype(float), has_constant='add')

# Align y with X using the same filtered rows
Expand Down
Loading