QuestionQuestion

Objectives:
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.

Hand-in Requirements:
The lab4Script.m script containing your work for all parts.
The published script in the same directory.

Description
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.

The Spring 2019 semester has 319 diaries from 5 CS1173 Sections, plus a section for the instructors. Section 0 is the instructors. Sections 1 and 2 are hybrid sections - they meet only once weekly - Section 1 at 10:00a on T and Section 2 at 10:00a on Th. Section 3 meets TR 4:00pm, Section 4 meets TR at 8:30am and Section 5 meets TR at 6:00pm. 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
Create a directory called lab4 in V:.
Change your MATLAB working directory to be this directory.

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.
Calculate the average for each of two variables, for example hours of sleep and average wakeup time, for each individual in the entire cohort. Which pair of variables you pick is up to you. Find something interesting.
Create a scatter plot for the data:
The points for the people in each section should be plotted in a unique color.
Provide labels and legend appropriately.
You do not have to display linear fits or correlations on the graph.
Calculate and output correlation between the averages of the two variables for each section.
Calculate and output the overall correlation between the two variables (not the individual averages).
Write a short paragraph discussing the results.
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. Use SEM error bars. 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,2 and 4) and late afternoon sections (3 and 5), 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.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

%Process all the diaries.
load diariesF2012
%% Extract the fields

%Number of participants:
NP = size(bedTimes,2);
ND = size(bedTimes,1);
%% Process wakeTimes
fwakeTimes=24*(wakeTimes-floor(wakeTimes)); %in 24 hours


%% Process bedTimes
fbedTimes=24*(bedTimes-floor(bedTimes)); %in 24 hours
% Make a modification to the bedTimes for those who go to bed after
% midnight.

for i = 1:ND
    for j=1:NP
       if fbedTimes(i,j) < 6
            fbedTimes(i,j)=fbedTimes(i,j)+24;
       end
    end
end

%% Process hours of Sleep
fsleepTime=24*(wakeTimes-bedTimes); %in 24 hours
%% Part II Calculate overall median values by section.
% First we make a number of columns;
bedTimes_by_section=cell(1,7);
wakeTimes_by_section=cell(1,7);
sleepTimes_by_section=cell(1,7);
minutes_to_sleep_by_section=cell(1,7);
minutes_of_nap_by_section=cell(1,7);
times_awake_by_section=cell(1,7);
for i=1:NP
    s=section(i)+1;
    bedTimes_by_section{s}=[bedTimes_by_section{s};fbedTimes(:,i)];
    wakeTimes_by_section{s}=[wakeTimes_by_section{s};fwakeTimes(:,i)];
    sleepTimes_by_section{s}=[sleepTimes_by_section{s};fsleepTime(:,i)];
    minutes_to_sleep_by_section{s}=[minutes_to_sleep_by_section{s};toSleepMinutes(:,i)];
    minutes_of_nap_by_section{s}=[minutes_of_nap_by_section{s};minutesNap(:,i)];
    times_awake_by_section{s}=[times_awake_by_section{s};timesAwake(:,i)];
end

% compute medians by section
med_bedTimes_by_section=[];
med_wakeTimes_by_section=[];
med_sleepTimes_by_section=[];
med_minutes_to_sleep_by_section=[];
med_minutes_of_nap_by_section=[];
med_times_awake_by_section=[];...
$30.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available MATLAB for Mathematics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats