SS<-read.csv("SleepStudy.csv", header = TRUE)
names(SS)
##  [1] "Gender"           "ClassYear"        "LarkOwl"          "NumEarlyClass"   
##  [5] "EarlyClass"       "GPA"              "ClassesMissed"    "CognitionZscore" 
##  [9] "PoorSleepQuality" "DepressionScore"  "AnxietyScore"     "StressScore"     
## [13] "DepressionStatus" "AnxietyStatus"    "Stress"           "DASScore"        
## [17] "Happiness"        "AlcoholUse"       "Drinks"           "WeekdayBed"      
## [21] "WeekdayRise"      "WeekdaySleep"     "WeekendBed"       "WeekendRise"     
## [25] "WeekendSleep"     "AverageSleep"     "AllNighter"
SS$DASScore
##   [1] 15  4 45 11 46 50  2  7 48 48 27 21 41  8  5 15 44 55  6 21 34 19 12 11 18
##  [26] 44 41 56 18 29 53 21  7 27 41 16  7 12 26 40  4 15  0 20 22 33 31 12  7 20
##  [51]  8 69 15 29  4 20 59 45  5 10  6  0 16 74 26 10 10  7 23  6 11 12 28 56 21
##  [76] 31 39  9 11 14 29  9 36  1 41  2 47 10 21 46  3 40  4 18  0  8  7  8  8 35
## [101]  0 25 25 47 53 20  3 71 25 12 22  5  1  0 10  8  2 49  6 27  2 13 31 19  8
## [126]  7 17  6 45 39  6 40 10 21 13 13 19 54  2 28 31 22 32 82  8 14 19 21  6 21
## [151]  1 23  6 24  8  4 30 42  3  2 67  8 19 30 10  2 28  9 16 15 23  6 28 43  9
## [176] 10 50 18  3 36  0 21  6  5  5 11 13 26 23 12 25 43 28 31 68  3 16 17 17 48
## [201] 12  1  0 12  3 22  1 25 32 37  8 10 20  1  2 36 15 21 10 17  9 11  4  2  2
## [226]  5 29 27 34 13 22 14 11 14 45 27  2 13 12 24 12  4  7 27 24 11  2  9 24 19
## [251]  3  5  5
  1. Examine the distribution of DAS scores.
hist(SS$DASScore)

  1. Does stress level depend on the circadian preferences ( LarkOwl)?
boxplot(SS$StressScore~SS$LarkOwl, horizontal = TRUE)

  1. Are cognitive skills and alcohol use related?
boxplot(SS$CognitionZscore~SS$AlcoholUse, horizontal = TRUE)

  1. Are you a lark or an owl?
category_freq <- table(SS$LarkOwl)

# Calculate the proportions
category_proportions <- prop.table(category_freq) * 100  

print(category_proportions)
## 
##     Lark  Neither      Owl 
## 16.20553 64.42688 19.36759
  1. Calculate the z-score for DASS scores and identify outliers using based on z-scores (more than 2 or less than -2).
x<-mean(SS$DASScore)
z<-(SS$DASScore - x)/sd(SS$DASScore)
z
##   [1] -0.304652782 -0.969632148  1.508927308 -0.546463461  1.569379978
##   [6]  1.811190656 -1.090537488 -0.788274139  1.690285317  1.690285317
##  [11]  0.420779254  0.058063236  1.267116629 -0.727821470 -0.909179479
##  [16] -0.304652782  1.448474638  2.113454005 -0.848726809  0.058063236
##  [21]  0.843947942 -0.062842103 -0.486010791 -0.546463461 -0.123294773
##  [26]  1.448474638  1.267116629  2.173906674 -0.123294773  0.541684593
##  [31]  1.992548665  0.058063236 -0.788274139  0.420779254  1.267116629
##  [36] -0.244200112 -0.788274139 -0.486010791  0.360326584  1.206663960
##  [41] -0.969632148 -0.304652782 -1.211442827 -0.002389434  0.118515906
##  [46]  0.783495272  0.662589933 -0.486010791 -0.788274139 -0.002389434
##  [51] -0.727821470  2.959791380 -0.304652782  0.541684593 -0.969632148
##  [56] -0.002389434  2.355264683  1.508927308 -0.909179479 -0.606916130
##  [61] -0.848726809 -1.211442827 -0.244200112  3.262054728  0.360326584
##  [66] -0.606916130 -0.606916130 -0.788274139  0.178968575 -0.848726809
##  [71] -0.546463461 -0.486010791  0.481231924  2.173906674  0.058063236
##  [76]  0.662589933  1.146211290 -0.667368800 -0.546463461 -0.365105452
##  [81]  0.541684593 -0.667368800  0.964853281 -1.150990157  1.267116629
##  [86] -1.090537488  1.629832647 -0.606916130  0.058063236  1.569379978
##  [91] -1.030084818  1.206663960 -0.969632148 -0.123294773 -1.211442827
##  [96] -0.727821470 -0.788274139 -0.727821470 -0.727821470  0.904400611
## [101] -1.211442827  0.299873915  0.299873915  1.629832647  1.992548665
## [106] -0.002389434 -1.030084818  3.080696719  0.299873915 -0.486010791
## [111]  0.118515906 -0.909179479 -1.150990157 -1.211442827 -0.606916130
## [116] -0.727821470 -1.090537488  1.750737987 -0.848726809  0.420779254
## [121] -1.090537488 -0.425558121  0.662589933 -0.062842103 -0.727821470
## [126] -0.788274139 -0.183747443 -0.848726809  1.508927308  1.146211290
## [131] -0.848726809  1.206663960 -0.606916130  0.058063236 -0.425558121
## [136] -0.425558121 -0.062842103  2.053001335 -1.090537488  0.481231924
## [141]  0.662589933  0.118515906  0.723042602  3.745676086 -0.727821470
## [146] -0.365105452 -0.062842103  0.058063236 -0.848726809  0.058063236
## [151] -1.150990157  0.178968575 -0.848726809  0.239421245 -0.727821470
## [156] -0.969632148  0.602137263  1.327569299 -1.030084818 -1.090537488
## [161]  2.838886041 -0.727821470 -0.062842103  0.602137263 -0.606916130
## [166] -1.090537488  0.481231924 -0.667368800 -0.244200112 -0.304652782
## [171]  0.178968575 -0.848726809  0.481231924  1.388021969 -0.667368800
## [176] -0.606916130  1.811190656 -0.123294773 -1.030084818  0.964853281
## [181] -1.211442827  0.058063236 -0.848726809 -0.909179479 -0.909179479
## [186] -0.546463461 -0.425558121  0.360326584  0.178968575 -0.486010791
## [191]  0.299873915  1.388021969  0.481231924  0.662589933  2.899338710
## [196] -1.030084818 -0.244200112 -0.183747443 -0.183747443  1.690285317
## [201] -0.486010791 -1.150990157 -1.211442827 -0.486010791 -1.030084818
## [206]  0.118515906 -1.150990157  0.299873915  0.723042602  1.025305951
## [211] -0.727821470 -0.606916130 -0.002389434 -1.150990157 -1.090537488
## [216]  0.964853281 -0.304652782  0.058063236 -0.606916130 -0.183747443
## [221] -0.667368800 -0.546463461 -0.969632148 -1.090537488 -1.090537488
## [226] -0.909179479  0.541684593  0.420779254  0.843947942 -0.425558121
## [231]  0.118515906 -0.365105452 -0.546463461 -0.365105452  1.508927308
## [236]  0.420779254 -1.090537488 -0.425558121 -0.486010791  0.239421245
## [241] -0.486010791 -0.969632148 -0.788274139  0.420779254  0.239421245
## [246] -0.546463461 -1.090537488 -0.667368800  0.239421245 -0.062842103
## [251] -1.030084818 -0.909179479 -0.909179479
z[z > 2|z < (-2)]
##  [1] 2.113454 2.173907 2.959791 2.355265 3.262055 2.173907 3.080697 2.053001
##  [9] 3.745676 2.838886 2.899339
  1. Is there any effect of the DASS score on sleep quality?
cor(SS$DASScore, SS$AverageSleep)
## [1] -0.08277492
plot((SS$DASScore~SS$AverageSleep))

  1. Build an appropriate model to predict sleep quality in terms of the DASS scores. How good is your model?
model <- lm(SS$DASScore ~ SS$DepressionScore)
model
## 
## Call:
## lm(formula = SS$DASScore ~ SS$DepressionScore)
## 
## Coefficients:
##        (Intercept)  SS$DepressionScore  
##              8.361               2.245
plot(model)

#regression analysis
#lm models