# How can I get the respiratory event in the different sleep stage?

Hi everyone,
My data is from the sleep test(PSG), so there are many other physiological signals except eeg. Now, I want to calculate the respiratory event in each sleep stage. In my data, the onset and duration of respiratory events and sleep stages are both provided. I first created the epoch by setting the annotations of sleep stage and transform it into events. However, I donâ€™t know what to do next. Any advice would be helpful.

What do you mean by â€śthe respiratory eventâ€ť? Is this some kind of measure that not everybody is aware of?

You mention that you do have onsets and durations of each respiratory event, so I donâ€™t understand what you mean by â€śthe respiratory eventâ€ť

Do you mean you created epochs, centered on some particular event type (like respiratory events such as â€śonset of breathing inâ€ť)?

As far as I know, sleep stages may last a long time (at least several seconds, up to many minutes). What exactly are you trying to compute or analyze?

1 Like

1. Respiratory events contain hypopnea, obstructive apnea, central apnea and other types. I want to do some eeg analysis before and after a specific respiratory event.
2. I created epochs by setting annotation. According to the sleep stage scoring rule(AASM 2.6), each epoch to score lasts 30s. My code is as below:
annotation = {}
annotation['onset'] = [0,30,60,90,....]
annotation['duration'] = [30,30,30,30,....]
annotation['description'] = ['W','N1','N1',...]

annot = mne.Annotations(onset=annotation['onset'], duration=annotation['duration'],description=annotation['description'])

annot_2_event = {'W':0, 'N1':1, 'N2':2, 'N3':3, 'R':4}
events, _ = mne.events_from_annotations(
raw, event_id=annot_2_event, chunk_duration=30)
epochs = mne.Epochs(
raw=raw,
events=events,
event_id=annot_2_event,
reject_by_annotation=True,
picks='eeg',
tmin=0,
tmax=30,
baseline=(None,None),
)
1. For example, I want to estimate eeg connectivity before and after a obstructive apnea event in stage N1. What should I do? I find that I cannot create epochs by both sleeping stage and respiratory events.

An epoch in your scenario may have two â€śdefining featuresâ€ť at the same time:

1. a sleep stage (1, 2, â€¦)
2. a type of respiratory event (apnea, hypopnea, â€¦)

This can be represented in MNE-Python, using event codes like: N1/apnea for an event, for example. This would mean sleep stage 1, and apnea as an event. The / as a separator for the event code is important.