Add "reduced" parameter for IntervalCensoredCox
This commit is contained in:
parent
7746ca275e
commit
3c22fe4197
@ -103,6 +103,7 @@ def regress(
|
|||||||
nan_policy='warn',
|
nan_policy='warn',
|
||||||
exposure=None,
|
exposure=None,
|
||||||
method=None, maxiter=None, start_params=None,
|
method=None, maxiter=None, start_params=None,
|
||||||
|
reduced=None,
|
||||||
bool_baselevels=False, exp=None
|
bool_baselevels=False, exp=None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -123,6 +124,7 @@ def regress(
|
|||||||
:param method: See statsmodels *model.fit*
|
:param method: See statsmodels *model.fit*
|
||||||
:param maxiter: See statsmodels *model.fit*
|
:param maxiter: See statsmodels *model.fit*
|
||||||
:param start_params: See statsmodels *model.fit*
|
:param start_params: See statsmodels *model.fit*
|
||||||
|
:param reduced: See :meth:`yli.IntervalCensoredCox`
|
||||||
:param bool_baselevels: Show reference categories for boolean independent variables even if reference category is *False*
|
:param bool_baselevels: Show reference categories for boolean independent variables even if reference category is *False*
|
||||||
:type bool_baselevels: bool
|
:type bool_baselevels: bool
|
||||||
:param exp: Report exponentiated parameters rather than raw parameters, default (*None*) is to autodetect based on *model_class*
|
:param exp: Report exponentiated parameters rather than raw parameters, default (*None*) is to autodetect based on *model_class*
|
||||||
@ -149,6 +151,8 @@ def regress(
|
|||||||
fit_kwargs['maxiter'] = maxiter
|
fit_kwargs['maxiter'] = maxiter
|
||||||
if start_params is not None:
|
if start_params is not None:
|
||||||
fit_kwargs['start_params'] = start_params
|
fit_kwargs['start_params'] = start_params
|
||||||
|
if reduced is not None:
|
||||||
|
fit_kwargs['reduced'] = reduced
|
||||||
|
|
||||||
# Fit model
|
# Fit model
|
||||||
result = model_class.fit(dmatrices[0], dmatrices[1], **fit_kwargs)
|
result = model_class.fit(dmatrices[0], dmatrices[1], **fit_kwargs)
|
||||||
@ -689,7 +693,7 @@ class IntervalCensoredCox(RegressionModel):
|
|||||||
self.lambda_ = None
|
self.lambda_ = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fit(cls, data_dep, data_ind):
|
def fit(cls, data_dep, data_ind, *, reduced=False):
|
||||||
if len(data_dep.columns) != 2:
|
if len(data_dep.columns) != 2:
|
||||||
raise ValueError('IntervalCensoredCox requires left and right times')
|
raise ValueError('IntervalCensoredCox requires left and right times')
|
||||||
|
|
||||||
@ -703,13 +707,18 @@ class IntervalCensoredCox(RegressionModel):
|
|||||||
result.nevents = np.isfinite(data_dep.iloc[:, 1]).sum()
|
result.nevents = np.isfinite(data_dep.iloc[:, 1]).sum()
|
||||||
result.dof_model = len(data_ind.columns)
|
result.dof_model = len(data_ind.columns)
|
||||||
|
|
||||||
|
# Prepare arguments
|
||||||
|
intcox_args = [config.hpstat_path, 'intcox', '-', '--output', 'json']
|
||||||
|
if reduced:
|
||||||
|
intcox_args.append('--reduced')
|
||||||
|
|
||||||
# Export data to CSV
|
# Export data to CSV
|
||||||
csv_buf = io.StringIO()
|
csv_buf = io.StringIO()
|
||||||
data_dep.join(data_ind).to_csv(csv_buf, index=False)
|
data_dep.join(data_ind).to_csv(csv_buf, index=False)
|
||||||
csv_str = csv_buf.getvalue()
|
csv_str = csv_buf.getvalue()
|
||||||
|
|
||||||
# Run intcens binary
|
# Run intcens binary
|
||||||
proc = subprocess.run([config.hpstat_path, 'intcox', '-', '--output', 'json'], input=csv_str, stdout=subprocess.PIPE, stderr=None, encoding='utf-8', check=True)
|
proc = subprocess.run(intcox_args, input=csv_str, stdout=subprocess.PIPE, stderr=None, encoding='utf-8', check=True)
|
||||||
raw_result = json.loads(proc.stdout)
|
raw_result = json.loads(proc.stdout)
|
||||||
|
|
||||||
from IPython.display import clear_output
|
from IPython.display import clear_output
|
||||||
|
Loading…
Reference in New Issue
Block a user