raphaelvallat/yasa

More HRV-Features

skjerns opened this issue ยท 3 comments

As sleepecg already offers many different HRV features I was wondering if it would make sense to give access to all of them via yasa?

Btw: Many thanks for including sleepecg in yasa, I think the 'collaboration' is a great addition! In fact we are using it right now for one of our studies exploratory analysis :)

You're welcome! Yeah I think they really did a great job, the ECG heartbeat detection has now become by go-to method. As for more HRV features, we could certainly add them easily. My rationale for not including them was based on two reasons:

  1. Avoid having to reply to numerous emails about issues with, and interpretation of, the HRV features ๐Ÿ˜…
  2. Some of these features requires some parameterization (i.e. frequency-domain: PSD method, frequency band, etc). I wanted to avoid adding many extra arguments to the yasa.hrv_stage function, and instead keep the API simple.

All these features can however be calculated manually through the rpeaks output of the yasa.hrv_stage function.

  1. Avoid having to reply to numerous emails about issues with, and interpretation of, the HRV features ๐Ÿ˜…
  2. Some of these features requires some parameterization (i.e. frequency-domain: PSD method, frequency band, etc). I wanted to avoid adding many extra arguments to the yasa.hrv_stage function, and instead keep the API simple.

that makes total sense!

Maybe one compromise would be to allow giving a lambda as a kwarg, so that custom functions can be passed to hrv_stage? e.g. additional_features=[lambda x:x, lambda y:y] (or maybe even better, as {'name': lambda x:x}). This way all results would be in the same format and nicely separated by sleep stage in the resulting data frame.

All these features can however be calculated manually through the rpeaks output of the yasa.hrv_stage function.

Thanks, I'll check it out, I didn't know if I could simply pass the rpeaks directly to the sleepecg package. If I have time I might write a short tutorial on how to make further use of the rpeaks that is returned by the function, or would you also rather avoid having that in this repo?

If I have time I might write a short tutorial on how to make further use of the rpeaks that is returned by the function.

That'd be great! One possibility is to add the tutorial directly to the associated notebook: https://github.com/raphaelvallat/yasa/blob/master/notebooks/16_EEG-HRV_coupling.ipynb

I didn't know if I could simply pass the rpeaks directly to the sleepecg package

I have actually never tried myself but I think it should be pretty straightforward. It will require setting up a for loop on the epochs though.

One compromise would be to allow giving a lambda as a kwarg

Also a great idea. I have no time to work on this now, but will leave this issue open as a reminder for my future self. Or, feel free to submit a PR ๐Ÿ‘