cellrank.ul.models.GAMR

class cellrank.ul.models.GAMR(adata, n_knots=5, distribution='gaussian', basis='cr', knotlocs='auto', offset='default', smoothing_penalty=1.0, **kwargs)[source]

Wrapper around R’s mgcv package for fitting Generalized Additive Models (GAMs).

Parameters
  • adata (anndata.AnnData) – Annotated data object.

  • n_knots (int) – Number of knots.

  • distribution (str) – Distribution family in rpy2.robjects.r, such as ‘gaussian’ or ‘nb’ for negative binomial. If ‘nb’, raw count data in adata .raw is always used.

  • basis (str) – Basis for the smoothing term. See here for valid options.

  • knotlocs (str) –

    Position of the knots. Can be one of the following:

    • ’auto’ - let mgcv handle the knot positions.

    • ’density’ - position the knots based on the density of the pseudotime.

  • offset (Union[ndarray, str, None]) – Offset term for the GAM. Only available when distribution='nb'. If ‘default’, it is calculated according to [Robinson10]. The values are saved in adata .obs['cellrank_offset']. If None, no offset is used.

  • smoothing_penalty (float) – Penalty for the smoothing term. The larger the value, the smoother the fitted curve.

  • **kwargs – Keyword arguments for gam.control. See here for reference.

Attributes

adata

Annotated data object.

conf_int

Array of shape (n_samples, 2) containing the lower and upper bounds of the confidence interval.

model

The underlying model.

prepared

Whether the model is prepared for fitting.

w

Filtered weights of shape (n_filtered_cells,) used for fitting.

w_all

Unfiltered weights of shape (n_cells,).

x

Filtered independent variables of shape (n_filtered_cells, 1) used for fitting.

x_all

Unfiltered independent variables of shape (n_cells, 1).

x_hat

Filtered independent variables used when calculating default confidence interval, usually same as x.

x_test

Independent variables of shape (n_samples, 1) used for prediction.

y

Filtered dependent variables of shape (n_filtered_cells, 1) used for fitting.

y_all

Unfiltered dependent variables of shape (n_cells, 1).

y_hat

Filtered dependent variables used when calculating default confidence interval, usually same as y.

y_test

Prediction values of shape (n_samples,) for x_test.

Methods

confidence_interval([x_test, level])

Calculate the confidence interval.

copy()

Return a copy of self.

default_confidence_interval([x_test])

Calculate the confidence interval, if the underlying model has no method for it.

fit([x, y, w])

Fit the model.

plot([figsize, same_plot, hide_cells, perc, …])

Plot the smoothed gene expression.

predict([x_test, key_added, level])

Run the prediction.

prepare(*args, **kwargs)

Prepare the model to be ready for fitting.

read(fname)

Deserialize self from a file.

write(fname[, ext])

Serialize self to a file.