"""Data preparation, logistic fitting, prediction, and goodness-of-fit.""" from pathlib import Path import numpy as np from scipy.io import loadmat from ..data import get_data from .core import ( _sigmoid_stable, model_p, design_matrix, nll, llf, grad_nll, hess_nll, covariance, standard_errors, fit_newton, goodness_of_fit, fit_pack, trim_nc_by_value, fit_logistic_x, predict_curve_x, plot_overlay_two_panels_final, ) def load_dataset(project_root=None, percentile=95): """Load the thesis SUV predictor and binary outcome arrays.""" root = Path(project_root) if project_root else Path(__file__).resolve().parents[1] suv = loadmat(root / "suv_percentilesSLOthenUWM.mat") flags = loadmat(root / "flags_combined.mat") x, y = get_data(percentile, suv, flags) return np.asarray(x, float).ravel(), np.asarray(y, int).ravel() def prepare_full_trim(project_root=None, percentile=95, target=2.48122597, tol=0.05): """Return aligned FULL and TRIM datasets.""" x_full, y_full = load_dataset(project_root, percentile) x_trim, y_trim = trim_nc_by_value(x_full, y_full, target=target, tol=tol) return { "FULL": (x_full, y_full), "TRIM": (x_trim, y_trim), }