ehrapy.tools.ols#

ehrapy.tools.ols(adata, var_names=None, formula=None, missing='none')[source]#

Create a Ordinary Least Squares (OLS) Model from a formula and AnnData.

See https://www.statsmodels.org/stable/generated/statsmodels.formula.api.ols.html#statsmodels.formula.api.ols Internally use the statsmodel to create a OLS Model from a formula and dataframe.

Parameters:
  • adata (AnnData) – The AnnData object for the OLS model.

  • var_names (Optional[list[str]]) – A list of var names indicating which columns are for the OLS model.

  • formula (Optional[str]) – The formula specifying the model.

  • missing (Optional[Literal['none', 'drop', 'raise']]) – 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. Default is ‘none’.

Return type:

OLS

Returns:

The OLS model instance.

Examples

>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> formula = 'tco2_first ~ pco2_first'
>>> var_names = ['tco2_first', 'pco2_first']
>>> ols = ep.tl.ols(adata, var_names, formula, missing = 'drop')