CS 1173 Computation for Scientists and Engineers Lab 5
Analysis of sleep diary data for Spring 2020


  • Use vector indexing to select rows and columns from arrays.
  • Practice using statistical tools and plots.
  • Become familiar with sleep diary data for the project.
  • Handle more realistic data.
  • Interpret data and draw conclusions.
EEG of slow wave or N3 sleep

Hand-in Requirements:

All projects and laboratories should be submitted submitted electronically through Blackboard Learn under the Assignments menu. Zip up your entire lab5 directory to submit. (Right click on the project folder and follow the Send To link.)


This laboratory examines the sleep patterns of a cohort of students. The data consists of the sleep diaries recorded by CS 1173 in the Spring 2020 for the period January 23 to February 12, 2020.

Description of the data

File Description
(available in Blackboard Learn, under Addl Resources, then Sleep Diary)
The diary file contains the following variables:

  • bedTimes - bed times in decimal-date format (vector)
  • dayCaffeine - daytime caffeine indicators (vector)
  • nightCaffeine - evening caffeine indicators (vector)
  • toSleepMinutes - number of minutes to fall asleep (vector)
  • useAlarm - alarm use indicators (vector)
  • wakeTimes - wakeup times in decimal-date format (vector)
  • gender - 'male' or 'female'
  • section - your section number (vector)
  • minutesNap - number of minutes of napping (vector)
  • minsAwake - minutes awake during each night (vector)
  • SSI - Standford Sleepiness Scale

The arrays have a column for each person. The vectors have an element for each person. The values in column n correspond to the same person as the value in position n of each vector. Your position is located in Blackboard Learn's grade book under Subject #.

The Spring 2020 semester has 248 diaries from 4 CS1173 Sections, plus a section for the instructors. Section 0 is the instructors. Sections 1 and 2 meet at 10a and 6p respectively, on Tuesday and Thursdays. Section 3 and 4 are online. To find YOUR data, look in Blackboard in grades, under the 'Subject Number' heading - that is your column.

The bedtimes and wake-up times use MATLAB's decimal date format. The date is a number representing the offset from 0:00 of a particular reference day. The integer part of this value represents the day and the fractional part represents the fraction of 24 hours represented by the hour and minutes.

Part I: Initial set up

Part II: Calculate overall median values by section

You should calculate and output the overall medians of the following information by section in tabular form: wake-up time in hours, bed time in hours, hours in bed (wake-up time in hours - bed time in hours), minutes to sleep, minutes of napping, minutes awake, total daily sleep (hours in bed + hours of napping - hours to sleep - hours awake), and Stanford Sleepiness Scale.

Your output should be in tabular format (use %#.#f to line up the columns). The first column is YOUR data, and the rest of the columns are by section. The first line of the table corresponds to the headers (e.g., Me Sect0 Sect1 ...). The first column has the names of the indicators (e.g., Wake-up times, etc).

As a hint for this and other parts asking for results for multiple sections. Get the code working for one of the sections. Then you can duplicate and modify the code for the other sections. If you feel ambitious, you can shorten the code by using a function.

Part III: Relationship of two statistics for individual subjects.

Part IV: Errorbar plots of average daily hours of sleep by gender

Create a figure that has two errorbar lines -- one corresponding to the individual average hours of sleep for men in the cohort and the other corresponding to the individual average hours of sleep for women in the cohort, both by day. Your graph should look similar to Example 9 of Lesson 6, where the data is male vs female. Write a short paragraph discussing the results.

Part V: Are there differences in sleep patterns between sections? Genders?

Compare the sleep patterns (i.e., bed times, wake times, hours of sleep, etc.) among groups. Possible groups: morning section (1 and 6), evening section (2), and online (3 and 4) and instructor section (0), etc. You could also test weekday versus weekend differences by using the weekday function. By grouping data appropriately and applying the ttest2 you will test for differences between your groups. You need to include at least three t-tests. Output h, the p-values, and the confidence intervals. Based on the output of your MATLAB script, write a short paragraph discussing the results and offering conclusions.

Part VI: Publish the results

Publish your script by pushing the Publish icon. Make sure that your script is separated appropriately into cells and that each cell has a title indicating what is computed in that cell.

Grading rubric (point values)

Performance indicator
Missing Needs improvement Needs a little improvement Meets expectations Excellent
Part II: Values are properly calculated 0 2.5 4 4.5 5
Part II: Output is displayed in tabular form 0 2.5 4 4.5 5
Part III: Averages of the two variables defined correctly 0 1.25 2 2.25 2.5
Part III: Scatter plot follows specification 0 1.25 2 2.25 2.5
Part III: Correlations correctly computed and output 0 1.25 2 2.25 2.5
Part III: Correlation discussion 0 1.25 2 2.25 2.5
Part IV: Errorbars computed and displayed correctly 0 2.5 4 4.5 5
Part IV: Errorbar discussion 0 2.5 4 4.5 5
Part V: ttest2 follows specification 0 3.75 6 6.75 7.5
Part V: ttest2 discussion 0 2.5 4 4.5 5
The lab5Script contains all code 0 2.5 4 4.5 5
The lab5Script is published 0 1.25 2 2.25 2.5

This laboratory was originally written by Kay A. Robbins of the University of Texas at San Antonio and last modified by Dawn Roberson on 11/4/2019. Please contact kay.robbins@utsa.edu with comments or suggestions. The image is a screen shot of 30 seconds of an EEG recording of a patient during Slow Wave Sleep. The photograph was taken by S. S. Jähnichen on 12/9/2005. The image is available on Wikipedia as http://en.wikipedia.org/wiki/File:Sleep_EEG_Stage_4.jpg.