ehrapy.tools.ols

Contents

ehrapy.tools.ols#

ehrapy.tools.ols(edata, var_names=None, formula=None, *, missing='none', use_feature_types=False, layer=None)[source]#

Create an Ordinary Least Squares (OLS) Model from a formula and the data object.

See https://www.statsmodels.org/stable/generated/statsmodels.formula.api.ols.html#statsmodels.formula.api.ols

Parameters:
  • edata (EHRData | AnnData) – Central data object.

  • var_names (list[str] | None, default: None) – A list of var names indicating which columns are for the OLS model.

  • formula (str | None, default: None) – The formula specifying the model.

  • use_feature_types (bool, default: False) – If True, the feature types in the data objects .var are used.

  • missing (Literal['none', 'drop', 'raise'] | None, default: 'none') – Available options are ‘none’, ‘drop’, and ‘raise’. If ‘none’, no nan checking is done. If ‘drop’, any observations with nans are dropped. If ‘raise’, an error is raised.

  • layer (str | None, default: None) – The layer to use.

Return type:

OLS

Returns:

The OLS model instance.

Examples

>>> import ehrdata as ed
>>> import ehrapy as ep
>>> edata = ed.dt.mimic_2()
>>> formula = "tco2_first ~ pco2_first"
>>> var_names = ["tco2_first", "pco2_first"]
>>> ols = ep.tl.ols(edata, var_names, formula, missing="drop")