<ahref="https://github.com/carissalow/rapids/edit/master/docs/features/fitbit-sleep-intraday.md"title="Edit this page"class="md-content__button md-icon">
<td>Set to <code>True</code> to extract <code>FITBIT_SLEEP_INTRADAY</code> features from the <code>RAPIDS</code> provider</td>
</tr>
<tr>
<td><code>[FEATURES]</code></td>
<td>Features to be computed from sleep intraday data, see table below</td>
</tr>
<tr>
<td><code>[SLEEP_LEVELS]</code></td>
<td>Fitbit’s sleep API Version 1 only provides <code>CLASSIC</code> records. However, Version 1.2 provides 2 types of records: <code>CLASSIC</code> and <code>STAGES</code>. <code>STAGES</code> is only available in devices with a heart rate sensor and even those devices will fail to report it if the battery is low or the device is not tight enough. While <code>CLASSIC</code> contains 3 sleep levels (<code>awake</code>, <code>restless</code>, and <code>asleep</code>), <code>STAGES</code> contains 4 sleep levels (<code>wake</code>, <code>deep</code>, <code>light</code>, <code>rem</code>). To make it consistent, RAPIDS grouped them into 2 <code>UNIFIED</code> sleep levels: <code>awake</code> (<code>CLASSIC</code>: <code>awake</code> and <code>restless</code>; <code>STAGES</code>: <code>wake</code>) and <code>asleep</code> (<code>CLASSIC</code>: <code>asleep</code>; <code>STAGES</code>: <code>deep</code>, <code>light</code>, and <code>rem</code>).</td>
</tr>
<tr>
<td><code>[SLEEP_TYPES]</code></td>
<td>Types of sleep to be included in the feature extraction computation. Fitbit provides 2 types of sleep: <code>main</code>, <code>nap</code>.</td>
</tr>
<tr>
<td><code>[INCLUDE_SLEEP_LATER_THAN]</code></td>
<td>All resampled sleep rows (bin interval: one minute) that started after this time will be included in the feature computation. It is a number ranging from 0 (midnight) to 1439 (23:59) which denotes the number of minutes after midnight. If a segment is longer than one day, this value is for every day.</td>
</tr>
<tr>
<td><code>[REFERENCE_TIME]</code></td>
<td>The reference point from which the <code>[ROUTINE]</code> features are to be computed. Chosen from <code>MIDNIGHT</code> and <code>START_OF_THE_SEGMENT</code>, default is <code>MIDNIGHT</code>. If you have multiple time segments per day it might be more informative to set this flag to <code>START_OF_THE_SEGMENT</code>.</td>
<td>Number of <code>[LEVEL][TYPE]</code>sleep episodes. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code>and <code>[TYPE]</code> can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
</tr>
<tr>
<td>sumduration<code>[LEVEL][TYPE]</code></td>
<td>minutes</td>
<td>Total duration of all <code>[LEVEL][TYPE]</code>sleep episodes. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code> and <code>[TYPE]</code>can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
</tr>
<tr>
<td>maxduration<code>[LEVEL][TYPE]</code></td>
<td>minutes</td>
<td>Longest duration of any <code>[LEVEL][TYPE]</code>sleep episode. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code> and <code>[TYPE]</code>can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
</tr>
<tr>
<td>minduration<code>[LEVEL][TYPE]</code></td>
<td>minutes</td>
<td>Shortest duration of any <code>[LEVEL][TYPE]</code>sleep episode. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code> and <code>[TYPE]</code>can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
</tr>
<tr>
<td>avgduration<code>[LEVEL][TYPE]</code></td>
<td>minutes</td>
<td>Average duration of all <code>[LEVEL][TYPE]</code>sleep episodes. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code> and <code>[TYPE]</code>can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
</tr>
<tr>
<td>medianduration<code>[LEVEL][TYPE]</code></td>
<td>minutes</td>
<td>Median duration of all <code>[LEVEL][TYPE]</code>sleep episodes. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code> and <code>[TYPE]</code>can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
</tr>
<tr>
<td>stdduration<code>[LEVEL][TYPE]</code></td>
<td>minutes</td>
<td>Standard deviation duration of all <code>[LEVEL][TYPE]</code>sleep episodes. <code>[LEVEL]</code>is one of <code>[SLEEP_LEVELS]</code> (e.g. awake-classic or rem-stages) and <code>[TYPE]</code> is one of <code>[SLEEP_TYPES]</code> (e.g. main). Both <code>[LEVEL]</code> and <code>[TYPE]</code>can also be <code>all</code> when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True, which ignores the levels and groups by sleep types.</td>
<td>Ratio between the <strong>count</strong> of episodes of a single sleep <code>[LEVEL]</code> and the <strong>count</strong> of all episodes of all levels during both <code>main</code> and <code>nap</code> sleep types. This answers the question: what percentage of all <code>wake</code>, <code>deep</code>, <code>light</code>, and <code>rem</code> episodes were <code>rem</code>? (e.g., <spanclass="arithmatex">\(countepisode[remstages][all] / countepisode[all][all]\)</span>)</td>
</tr>
<tr>
<td>ratioduration<code>[LEVEL]</code></td>
<td>-</td>
<td>Ratio between the <strong>duration</strong> of episodes of a single sleep <code>[LEVEL]</code> and the <strong>duration</strong> of all episodes of all levels during both <code>main</code> and <code>nap</code> sleep types. This answers the question: what percentage of all <code>wake</code>, <code>deep</code>, <code>light</code>, and <code>rem</code> time was <code>rem</code>? (e.g., <spanclass="arithmatex">\(sumduration[remstages][all] / sumduration[all][all]\)</span>)</td>
<td>Ratio between the <strong>count</strong> of all <code>main</code> episodes (independently of the levels inside) divided by the <strong>count</strong> of all <code>main</code> and <code>nap</code> episodes. This answers the question: what percentage of all sleep episodes (<code>main</code> and <code>nap</code>) were <code>main</code>? We do not provide the ratio for <code>nap</code> because is complementary. (<spanclass="arithmatex">\(countepisode[all][main] / countepisode[all][all]\)</span>)</td>
</tr>
<tr>
<td>ratiodurationmain</td>
<td>-</td>
<td>Ratio between the <strong>duration</strong> of all <code>main</code> episodes (independently of the levels inside) divided by the <strong>duration</strong> of all <code>main</code> and <code>nap</code> episodes. This answers the question: what percentage of all sleep time (<code>main</code> and <code>nap</code>) was <code>main</code>? We do not provide the ratio for <code>nap</code> because is complementary. (<spanclass="arithmatex">\(sumduration[all][main] / sumduration[all][all]\)</span>)</td>
<td>Ratio between the <strong>count</strong> of episodes of a single sleep <code>[LEVEL]</code> during <code>main</code> sleep divided by the <strong>count</strong> of episodes of a single sleep <code>[LEVEL]</code> during <code>main</code><strong>and</strong><code>nap</code>. This answers the question: are <code>rem</code> episodes more frequent during <code>main</code> than <code>nap</code> sleep? We do not provide the ratio for <code>nap</code> because is complementary. (<spanclass="arithmatex">\(countepisode[remstages][main] / countepisode[remstages][all]\)</span>)</td>
<td>Ratio between the <strong>duration</strong> of episodes of a single sleep <code>[LEVEL]</code> during <code>main</code> sleep divided by the <strong>duration</strong> of episodes of a single sleep <code>[LEVEL]</code> during <code>main</code><strong>and</strong><code>nap</code>. This answers the question: is <code>rem</code> time more frequent during <code>main</code> than <code>nap</code> sleep? We do not provide the ratio for <code>nap</code> because is complementary. (<spanclass="arithmatex">\(countepisode[remstages][main] / countepisode[remstages][all]\)</span>)</td>
<td>Ratio between the <strong>count</strong> of episodes of a single sleep <code>[LEVEL]</code> and the <strong>count</strong> of all episodes of all levels during either <code>main</code> or <code>nap</code> sleep types. This answers the question: what percentage of all <code>wake</code>, <code>deep</code>, <code>light</code>, and <code>rem</code> episodes were <code>rem</code> during <code>main</code>/<code>nap</code> sleep time? (e.g., <spanclass="arithmatex">\(countepisode[remstages][main] / countepisode[all][main]\)</span>)</td>
<td>Ratio between the <strong>duration</strong> of episodes of a single sleep <code>[LEVEL]</code> and the <strong>duration</strong> of all episodes of all levels during either <code>main</code> or <code>nap</code> sleep types. This answers the question: what percentage of all <code>wake</code>, <code>deep</code>, <code>light</code>, and <code>rem</code> time was <code>rem</code> during <code>main</code>/<code>nap</code> sleep time? (e.g., <spanclass="arithmatex">\(sumduration[remstages][main] / sumduration[all][main]\)</span>)</td>
<li>Deleting values from <code>[SLEEP_LEVELS]</code> or <code>[SLEEP_TYPES]</code> will only change the features you receive from <code>[LEVELS_AND_TYPES]</code>. For example if <code>STAGES</code> only contains <code>[rem, light]</code> you will not receive <code>countepisode[wake|deep][TYPE]</code> or sum, max, min, avg, median, or std <code>duration</code>. These values will not influence <code>RATIOS</code> or <code>ROUTINE</code> features.</li>
<li>Any <code>[LEVEL]</code> grouping is done within the elements of each class <code>CLASSIC</code>, <code>STAGES</code>, and <code>UNIFIED</code>. That is, we never combine <code>CLASSIC</code> or <code>STAGES</code> types to compute features when <code>LEVELS_AND_TYPES_COMBINING_ALL</code> is True or when computing <code>RATIOS</code>.</li>
<td>Set to <code>True</code> to extract <code>FITBIT_SLEEP_INTRADAY</code> features from the <code>PRICE</code> provider</td>
</tr>
<tr>
<td><code>[FEATURES]</code></td>
<td>Features to be computed from sleep intraday data, see table below</td>
</tr>
<tr>
<td><code>[SLEEP_LEVELS]</code></td>
<td>Fitbit’s sleep API Version 1 only provides <code>CLASSIC</code> records. However, Version 1.2 provides 2 types of records: <code>CLASSIC</code> and <code>STAGES</code>. <code>STAGES</code> is only available in devices with a heart rate sensor and even those devices will fail to report it if the battery is low or the device is not tight enough. While <code>CLASSIC</code> contains 3 sleep levels (<code>awake</code>, <code>restless</code>, and <code>asleep</code>), <code>STAGES</code> contains 4 sleep levels (<code>wake</code>, <code>deep</code>, <code>light</code>, <code>rem</code>). To make it consistent, RAPIDS grouped them into 2 <code>UNIFIED</code> sleep levels: <code>awake</code> (<code>CLASSIC</code>: <code>awake</code> and <code>restless</code>; <code>STAGES</code>: <code>wake</code>) and <code>asleep</code> (<code>CLASSIC</code>: <code>asleep</code>; <code>STAGES</code>: <code>deep</code>, <code>light</code>, and <code>rem</code>).</td>
</tr>
<tr>
<td><code>[DAY_TYPE]</code></td>
<td>The features of this provider can be computed using daily averages/standard deviations that were extracted on <code>WEEKEND</code> days only, <code>WEEK</code> days only, or <code>ALL</code> days</td>
</tr>
<tr>
<td><code>[GROUP_EPISODES_WITHIN]</code></td>
<td>This parameter contains 2 values: <code>[START_TIME]</code> and <code>[LENGTH]</code>. Only <code>main</code> sleep episodes that intersect or contain the period between [<code>START_TIME</code>, <code>START_TIME</code> + <code>LENGTH</code>] are taken into account to compute the features described below. Both <code>[START_TIME]</code> and <code>[LENGTH]</code> are in minutes. <code>[START_TIME]</code> is a number ranging from 0 (midnight) to 1439 (23:59) which denotes the number of minutes after midnight. <code>[LENGTH]</code> is a number smaller than 1440 (24 hours).</td>
<td>Average duration of daily <code>LEVEL</code> sleep episodes. You can include daily average that were computed on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Average ratio between daily <code>LEVEL</code> time and in-bed time inferred from <code>main</code> sleep episodes. <code>LEVEL</code> is one of <code>SLEEP_LEVELS</code> (e.g. awake-classic or rem-stages). In-bed time is the total duration of all <code>main</code> sleep episodes for each day. You can include daily ratios that were computed on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Average start time of the first <code>main</code> sleep episode of each day in a time segment. You can include daily start times from episodes detected on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Average end time of the last <code>main</code> sleep episode of each day in a time segment. You can include daily end times from episodes detected on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Average mid time between the start of the first <code>main</code> sleep episode and the end of the last <code>main</code> sleep episode of each day in a time segment. You can include episodes detected on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Standard deviation of start time of the first <code>main</code> sleep episode of each day in a time segment. You can include daily start times from episodes detected on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Standard deviation of end time of the last <code>main</code> sleep episode of each day in a time segment. You can include daily end times from episodes detected on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Standard deviation of mid time between the start of the first <code>main</code> sleep episode and the end of the last <code>main</code> sleep episode of each day in a time segment. You can include episodes detected on weekend days, week days or both depending on the value of the <code>DAY_TYPE</code> flag.</td>
<td>Same as <code>avgstarttimeofepisodemain[DAY_TYPE]</code> but the average is computed over the squared differences of each pair of consecutive start times.</td>
</tr>
<tr>
<td>meanssdendtimeofepisodemain</td>
<td>minutes squared</td>
<td>Same as <code>avgendtimeofepisodemain[DAY_TYPE]</code> but the average is computed over the squared differences of each pair of consecutive end times.</td>
</tr>
<tr>
<td>meanssdmidpointofepisodemain</td>
<td>minutes squared</td>
<td>Same as <code>avgmidpointofepisodemain[DAY_TYPE]</code> but the average is computed over the squared differences of each pair of consecutive mid times.</td>
</tr>
<tr>
<td>medianssdstarttimeofepisodemain</td>
<td>minutes squared</td>
<td>Same as <code>avgstarttimeofepisodemain[DAY_TYPE]</code> but the median is computed over the squared differences of each pair of consecutive start times.</td>
</tr>
<tr>
<td>medianssdendtimeofepisodemain</td>
<td>minutes squared</td>
<td>Same as <code>avgendtimeofepisodemain[DAY_TYPE]</code> but the median is computed over the squared differences of each pair of consecutive end times.</td>
</tr>
<tr>
<td>medianssdmidpointofepisodemain</td>
<td>minutes squared</td>
<td>Same as <code>avgmidpointofepisodemain[DAY_TYPE]</code> but the median is computed over the squared differences of each pair of consecutive mid times.</td>
<li>These features are based on descriptive statistics computed across daily values (start/end/mid times of sleep episodes). This is the reason why they are only available on time segments that are longer than 24 hours (we need at least 1 day to get the average).</li>
<li>Even though Fitbit provides 2 types of sleep episodes (<code>main</code> and <code>nap</code>), only <code>main</code> sleep episodes are considered.</li>
<li>
<p>How do we assign sleep episodes to specific dates?</p>
<p><code>START_TIME</code> and <code>LENGTH</code> control the dates that sleep episodes belong to. For a pair of <code>[START_TIME]</code> and <code>[LENGTH]</code>, sleep episodes (blue boxes) can only be placed at the following places:</p>
<figcaption>Relationship between sleep episodes and the given times<code>([START_TIME], [LENGTH])</code></figcaption>
</figure></p>
<ul>
<li>
<p>If the end time of a sleep episode is before <code>[START_TIME]</code>, it will belong to the day before its start date (e.g. sleep episode #1).</p>
</li>
<li>
<p>if (1) the start time or the end time of a sleep episode are between (overlap) <code>[START_TIME]</code> and <code>[START_TIME] + [LENGTH]</code> or (2) the start time is before <code>[START_TIME]</code> and the end time is after <code>[START_TIME] + [LENGTH]</code>, it will belong to its start date (e.g. sleep episode #2, #3, #4, #5).</p>
</li>
<li>
<p>If the start time of a sleep episode is after <code>START_TIME] + [LENGTH]</code>, it will belong to the day after its start date (e.g. sleep episode #6).</p>
</li>
</ul>
<p>Only <code>main</code> sleep episodes that intersect or contain the period between <code>[START_TIME]</code> and <code>[START_TIME] + [LENGTH]</code> will be included in the feature computation. If we process the following <code>main</code> sleep episodes: </p>
<p><code>[INCLUDE_EPISODES_INTERSECTING][LENGTH]</code> = 720 (tomorrow’s 10:00, or 22:00 + 12 hours)</p>
</li>
</ul>
<p>Only sleep episodes 2, 3,and 5 would be considered.</p>
</li>
<li>
<p>Time related features represent the number of minutes between the start/end/midpoint of sleep episodes and the assigned day’s midnight.</p>
</li>
<li>
<p>All <code>main</code> sleep episodes are chunked within the requested <ahref="../../setup/configuration/#time-segments">time segments</a> which need to be at least 24 hours or more long (1, 2, 3, 7 days, etc.). Then, daily features will be extracted and averaged across the length of the time segment, for example:</p>
<p>The daily features extracted on 2021-02-01 will be:</p>
<ul>
<li>
<p>starttimeofepisodemain (bedtime) is <code>21 * 60</code> (episode 2 start time 2021-02-01 21:00)</p>
</li>
<li>
<p>endtimeofepisodemain (wake time) is <code>32 * 60</code>(episode 3 end time 2021-02-02 08:00 + 24)</p>
<scriptid="__config"type="application/json">{"base":"../..","features":["navigation.sections","search.suggest","search.highlight"],"translations":{"clipboard.copy":"Copy to clipboard","clipboard.copied":"Copied to clipboard","search.config.lang":"en","search.config.pipeline":"trimmer, stopWordFilter","search.config.separator":"[\\s\\-]+","search.placeholder":"Search","search.result.placeholder":"Type to start searching","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.term.missing":"Missing"},"search":"../../assets/javascripts/workers/search.d10a1f1d.min.js","version":{"method":"mike"}}</script>