Implement yli.logit_then_regress

This commit is contained in:
RunasSudo 2022-10-16 02:31:37 +11:00
parent 5cd04c3f6c
commit 78944c7966
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 16 additions and 1 deletions

View File

@ -18,7 +18,7 @@ from .bayes_factors import bayesfactor_afbf
from .config import config
from .distributions import beta_oddsratio, beta_ratio, hdi, transformed_dist
from .io import pickle_read_compressed, pickle_read_encrypted, pickle_write_compressed, pickle_write_encrypted
from .regress import PenalisedLogit, regress, vif
from .regress import PenalisedLogit, logit_then_regress, regress, vif
from .sig_tests import anova_oneway, chi2, mannwhitney, pearsonr, ttest_ind
def reload_me():

View File

@ -462,6 +462,21 @@ def regress(
exp
)
def logit_then_regress(model_class, df, dep, formula, *, nan_policy='warn', **kwargs):
"""Perform logistic regression, then use parameters as start parameters for desired regression"""
# Check for/clean NaNs
# Do this once here so we only get 1 warning
df = df[[dep] + cols_for_formula(formula, df)]
df = check_nan(df, nan_policy)
# Perform logistic regression
logit_result = regress(sm.Logit, df, dep, formula, **kwargs)
logit_params = logit_result.raw_result.params
# Perform desired regression
return regress(model_class, df, dep, formula, start_params=logit_params, **kwargs)
# -----------------------------
# Penalised logistic regression