Implement yli.logit_then_regress
This commit is contained in:
parent
5cd04c3f6c
commit
78944c7966
@ -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():
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user