leaspy.models.lme

Classes

LMEModel

LMEModel is a benchmark model that fits and personalize a linear mixed-effects model.

Module Contents

class LMEModel(name, with_random_slope_age=True, **kwargs)[source]

Bases: leaspy.models.stateless.StatelessModel

LMEModel is a benchmark model that fits and personalize a linear mixed-effects model.

The model specification is the following:

\[y_{ij} = fixed_{intercept} + random_{intercept_i} + (fixed_{slopeAge} + random_{slopeAge_i}) * age_{ij} + \epsilon_{ij}\]
with:
  • \(y_{ij}\): value of the feature of the i-th subject at his j-th visit,

  • \(age_{ij}\): age of the i-th subject at his j-th visit.

  • \(\epsilon_{ij}\): residual Gaussian noise (independent between visits)

Warning

This model must be fitted on one feature only (univariate model).

TODO? add some covariates in this very simple model.

Parameters:
namestr

The model’s name.

**kwargs
Model hyperparameters:
  • with_random_slope_age : bool (default True).

Attributes:
namestr

The model’s name.

is_initializedbool

True if the model is initialized, False otherwise.

with_random_slope_agebool (default True)

Has the LME a random slope for subject’s age? Otherwise it only has a random intercept per subject.

featureslist of str

List of the model features.

Warning

LME has only one feature.

dimensionint

Will always be 1 (univariate).

parametersdict
Contains the model parameters. In particular:
  • ages_meanfloat

    Mean of ages (for normalization).

  • ages_stdfloat

    Std-dev of ages (for normalization).

  • fe_paramsnp.ndarray of float

    Fixed effects.

  • cov_renp.ndarray

    Variance-covariance matrix of random-effects.

  • cov_re_unscaled_invnp.ndarray

    Inverse of unscaled (= divided by variance of noise) variance-covariance matrix of random-effects. This matrix is used for personalization to new subjects.

  • noise_stdfloat

    Std-dev of Gaussian noise.

  • bse_fe, bse_renp.ndarray of float

    Standard errors on fixed-effects and random-effects respectively (not used in Leaspy).

Parameters:
  • name (str)

  • with_random_slope_age (Optional[bool])

See also

LMEFitAlgorithm
LMEPersonalizeAlgorithm
with_random_slope_age = True
dimension = 1

Number of features.

Returns:
int, optional

The dimension of the model, or None if not initialized.

property hyperparameters: DictParamsTorch

Dictionary of values for model hyperparameters.

Return type:

DictParamsTorch

compute_individual_trajectory(timepoints, individual_parameters)[source]

Compute scores values at the given time-point(s) given a subject’s individual parameters.

Parameters:
timepointsarray-like of ages (not normalized)

Timepoints to compute individual trajectory at.

individual_parametersdict
Individual parameters:
  • random_intercept

  • random_slope_age (if with_random_slope_age == True)

Returns:
torch.Tensor of float

The individual trajectories. The shape of the tensor is (n_individuals == 1, n_tpts == len(timepoints), n_features == 1).

Parameters:
Return type:

Tensor