ada.long.cosinor — ADA 1.0.3 documentation

Skip to main content
`Ctrl`+`K`

# ada.long.cosinor

## Classes

`Antilogistic` | A class for fitting anti-logistic transform of a sine wave, with asymetric and unknown base period using nonlinear methods.
`Arctangent` | A class for fitting arctangent transform of a sine wave, with asymetric and unknown base period using nonlinear methods.
`CosinorResults` | A container for storing results of cosinor model fitting. Do not construct manually! Fit params gives access to the following:
`Hill` | A class for fitting Hill transform of a sine wave, with asymetric and unknown base period using nonlinear methods.
`Linear` | A class for fitting linear combination of harmonic sines of known base period to the data using Ordinary Least Squares.
`Nonlinear` | A class for fitting linear combination of harmonic sines of unknown base period to the data using nonlinear methods.
`Saw` | A class for fitting saw wave, possibly assymetric, of unknown base period to the data using nonlinear methods.

## Module Contents

class Antilogistic(test_periods=(16.0, 32.0), preprocessing=False, use_bootstrap=False)

  A class for fitting anti-logistic transform of a sine wave, with asymetric and unknown base period using nonlinear methods.

  test_periods
    Return type:

      list[float]

  Lower and upper bounds for fitting periods, in hours. Defaults to (16, 32).

  Type:

    Tuple[float, float]

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  preprocessing
    Return type:

      bool

  If true, data will be detrended and low-pass filtered before applying cosinor. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  use_bootstrap
    Return type:

      bool

  If true, significance of fitted amplitude will be assessed using bootstrap. Might take some time for high sampling frequencies. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  fit(data, ch_name=None)

    Fits the specified by the object curve to provided data.

    Parameters:

      - data (_ActiData) – Actigraphic data to be fitted with cosinor method.

      - ch_name (str | None, optional) – Channel to which curve will be fitted. If None, it will be to_score in case of Raw or Epoched data and score in case of ScoredShort data. Defaults to None.

    Returns:

      List of objects containing fitting results. It containes only 1 element.

    Return type:

      list[CosinorResults]

  property preprocessing: bool

    Whether preprocessing is applied.

    Return type:

      bool

  property test_periods: list[float]

    List of periods, that will be fitted to the data.

    Return type:

      list[float]

  property use_bootstrap: bool

    Whether bootstrap method is used to compute p-values of amplitudes.

    Return type:

      bool

class Arctangent(test_periods=(16, 32), preprocessing=False, use_bootstrap=False)

  A class for fitting arctangent transform of a sine wave, with asymetric and unknown base period using nonlinear methods.

  test_periods
    Return type:

      list[float]

  Lower and upper bounds for fitting periods, in hours. Defaults to (16, 32).

  Type:

    Tuple[float, float]

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  preprocessing
    Return type:

      bool

  If true, data will be detrended and low-pass filtered before applying cosinor. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  use_bootstrap
    Return type:

      bool

  If true, significance of fitted amplitude will be assessed using bootstrap. Might take some time for high sampling frequencies. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  fit(data, ch_name=None)

    Fits the specified by the object curve to provided data.

    Parameters:

      - data (_ActiData) – Actigraphic data to be fitted with cosinor method.

      - ch_name (str | None, optional) – Channel to which curve will be fitted. If None, it will be to_score in case of Raw or Epoched data and score in case of ScoredShort data. Defaults to None.

    Returns:

      List of objects containing fitting results. It containes only 1 element.

    Return type:

      list[CosinorResults]

  property preprocessing: bool

    Whether preprocessing is applied.

    Return type:

      bool

  property test_periods: list[float]

    List of periods, that will be fitted to the data.

    Return type:

      list[float]

  property use_bootstrap: bool

    Whether bootstrap method is used to compute p-values of amplitudes.

    Return type:

      bool

class CosinorResults(sine_params, period, amplitude, pvals, method, ch, preprocessing, id, generalized_params=None)

  A container for storing results of cosinor model fitting. Do not construct manually! Fit params gives access to the following:

  - base freq, n harmonic indexed from 1: dicts containing keys: period, amplitude, phase

  - amplitude: summary amplitude of fitted line

  - constant: MESOR

  - f-test: pvalue from F-test

  - bootstrap: pvalue from bootstrap or None

  - method: used model

  - preprocessing: whether it was used

  - channel: to which the model was fit

  Parameters:

    - sine_params (numpy.ndarray)

    - period (float)

    - amplitude (float)

    - pvals (Tuple[float, float | None])

    - method (str)

    - ch (str | None)

    - preprocessing (bool)

    - id (str)

    - generalized_params (dict | None)

  export(out_path)

    Save data (parameters of the model) to compressed generic file.

    Parameters:

      out_path (str) – Path to the out file.

  static load_file(path)

    Load model fitting results from .ada.long file (created via export method).

    Parameters:

      path (str) – Path to file.

    Returns:

      Object containing fitted model.

    Return type:

      CosinorResults

  plot(out_path, data)

    Plot the provided data together with fitted model.

    Parameters:

      - out_path (str | None) – Path to save the plot. If None, the plot will be opened in interactive window. Defaults to None.

      - data (_ActiData) – Data to which the model was fit.

  save_csv(out_path)

    Save parameters of fitted model to human-readable csv.

    Parameters:

      out_path (str) – Path to the out file.

  property fit_params: dict

    Parameters of the fitted model.

    Return type:

      dict

  property id: str

    ID of a recording to which long estimate was fit.

    Return type:

      str

class Hill(test_periods=(16, 32), preprocessing=False, use_bootstrap=False)

  A class for fitting Hill transform of a sine wave, with asymetric and unknown base period using nonlinear methods.

  test_periods
    Return type:

      list[float]

  Lower and upper bounds for fitting periods, in hours. Defaults to (16, 32).

  Type:

    Tuple[float, float]

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  preprocessing
    Return type:

      bool

  If true, data will be detrended and low-pass filtered before applying cosinor. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  use_bootstrap
    Return type:

      bool

  If true, significance of fitted amplitude will be assessed using bootstrap. Might take some time for high sampling frequencies. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  fit(data, ch_name=None)

    Fits the specified by the object curve to provided data.

    Parameters:

      - data (_ActiData) – Actigraphic data to be fitted with cosinor method.

      - ch_name (str | None, optional) – Channel to which curve will be fitted. If None, it will be to_score in case of Raw or Epoched data and score in case of ScoredShort data. Defaults to None.

    Returns:

      List of objects containing fitting results. It containes only 1 element.

    Return type:

      list[CosinorResults]

  property preprocessing: bool

    Whether preprocessing is applied.

    Return type:

      bool

  property test_periods: list[float]

    List of periods, that will be fitted to the data.

    Return type:

      list[float]

  property use_bootstrap: bool

    Whether bootstrap method is used to compute p-values of amplitudes.

    Return type:

      bool

class Linear(test_periods=24, preprocessing=False, use_bootstrap=False, n_components=1)

  A class for fitting linear combination of harmonic sines of known base period to the data using Ordinary Least Squares.

  test_periods
    Return type:

      list[float]

  Periods in hours to be fitted to the data. Defaults to 24.

  Type:

    list[float] | float

  Parameters:

    - test_periods (list[float] | float)

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  preprocessing
    Return type:

      bool

  If true, data will be detrended and low-pass filtered before applying cosinor. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (list[float] | float)

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  use_bootstrap
    Return type:

      bool

  If true, significance of fitted amplitude will be assessed using bootstrap. Might take some time for high sampling frequencies. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (list[float] | float)

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  n_components
    Return type:

      int

  Number of harmonics, that will be present in the fitted curve. Defaults to 1 (no harmonics, only base frequency).

  Type:

    int

  Parameters:

    - test_periods (list[float] | float)

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  fit(data, ch_name=None)

    Fits the specified by the object curves to provided data.

    Parameters:

      - data (_ActiData) – Actigraphic data to be fitted with cosinor method.

      - ch_name (str | None, optional) – Channel to which curve will be fitted. If None, it will be to_score in case of Raw or Epoched data and score in case of ScoredShort data. Defaults to None.

    Returns:

      List of objects containing fitting results. Each element corresponds to one period.

    Return type:

      list[CosinorResults]

  property n_components: int

    Number of harmonic components fitted to the data.

    Return type:

      int

  property preprocessing: bool

    Whether preprocessing is applied.

    Return type:

      bool

  property test_periods: list[float]

    List of periods, that will be fitted to the data.

    Return type:

      list[float]

  property use_bootstrap: bool

    Whether bootstrap method is used to compute p-values of amplitudes.

    Return type:

      bool

class Nonlinear(test_periods=(16, 32), preprocessing=False, use_bootstrap=False, n_components=1)

  A class for fitting linear combination of harmonic sines of unknown base period to the data using nonlinear methods.

  test_periods
    Return type:

      list[float]

  Lower and upper bounds for fitting periods, in hours. Defaults to (16, 32).

  Type:

    Tuple[float, float]

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  preprocessing
    Return type:

      bool

  If true, data will be detrended and low-pass filtered before applying cosinor. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  use_bootstrap
    Return type:

      bool

  If true, significance of fitted amplitude will be assessed using bootstrap. Might take some time for high sampling frequencies. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  n_components
    Return type:

      int

  Number of harmonics, that will be present in the fitted curve. Defaults to 1 (no harmonics, only base frequency).

  Type:

    int

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

    - n_components (int)

  fit(data, ch_name=None)

    Fits the specified by the object curves to provided data.

    Parameters:

      - data (_ActiData) – Actigraphic data to be fitted with cosinor method.

      - ch_name (str | None, optional) – Channel to which curve will be fitted. If None, it will be to_score in case of Raw or Epoched data and score in case of ScoredShort data. Defaults to None.

    Returns:

      List of objects containing fitting results. It containes only 1 element.

    Return type:

      list[CosinorResults]

  property n_components: int

    Number of harmonic components fitted to the data.

    Return type:

      int

  property preprocessing: bool

    Whether preprocessing is applied.

    Return type:

      bool

  property test_periods: list[float]

    List of periods, that will be fitted to the data.

    Return type:

      list[float]

  property use_bootstrap: bool

    Whether bootstrap method is used to compute p-values of amplitudes.

    Return type:

      bool

class Saw(test_periods=(16, 32), preprocessing=False, use_bootstrap=False)

  A class for fitting saw wave, possibly assymetric, of unknown base period to the data using nonlinear methods.

  test_periods
    Return type:

      list[float]

  Lower and upper bounds for fitting periods, in hours. Defaults to (16, 32).

  Type:

    Tuple[float, float]

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  preprocessing
    Return type:

      bool

  If true, data will be detrended and low-pass filtered before applying cosinor. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  use_bootstrap
    Return type:

      bool

  If true, significance of fitted amplitude will be assessed using bootstrap. Might take some time for high sampling frequencies. Defaults to False.

  Type:

    bool

  Parameters:

    - test_periods (Tuple[float, float])

    - preprocessing (bool)

    - use_bootstrap (bool)

  fit(data, ch_name=None)

    Fits the specified by the object curve to provided data.

    Parameters:

      - data (_ActiData) – Actigraphic data to be fitted with cosinor method.

      - ch_name (str | None, optional) – Channel to which curve will be fitted. If None, it will be to_score in case of Raw or Epoched data and score in case of ScoredShort data. Defaults to None.

    Returns:

      List of objects containing fitting results. It containes only 1 element.

    Return type:

      list[CosinorResults]

  property preprocessing: bool

    Whether preprocessing is applied.

    Return type:

      bool

  property test_periods: list[float]

    List of periods, that will be fitted to the data.

    Return type:

      list[float]

  property use_bootstrap: bool

    Whether bootstrap method is used to compute p-values of amplitudes.

    Return type:

      bool