#Setup

#Load Packages Needed

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.5
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.5
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(magrittr)
## Warning: package 'magrittr' was built under R version 4.0.5

Other packages have been checked in default by the program

#Load data

load("brfss2013.RData")

#Research Question No.1

#1.1 What are the statistics using the function summary in R?

#Statistics on variable “sleptim1” using summary()function

summary(brfss2013$sleptim1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   0.000   6.000   7.000   7.052   8.000 450.000    7387

#Statistics on variable “addepev2”

summary(brfss2013$addepev2)
##    Yes     No   NA's 
##  95779 393707   2289

#1.2 Provide statistics using the function summary without the NA’s and data with at most 10 hours of sleep.

#Function summary in R without NA’s on the variables “sleptim1” and “addepev2”

nosleep <- brfss2013%>%
  filter(!is.na(sleptim1))
summary((nosleep$sleptim1))
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   6.000   7.000   7.052   8.000 450.000
summary(na.omit(brfss2013$addepev2))
##    Yes     No 
##  95779 393707

#Function summary of data consisting with at most 10 hours of sleep in “sleptim1” variable

atmost10hours <- nosleep%>%
  filter(sleptim1<=10)
summary(atmost10hours$sleptim1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   6.000   7.000   6.976   8.000  10.000

#Research Question No.2 –What analysis can you share on the Perception of others to the Depressive Disorder of the Respondents with those having less than 6 hours of sleep on average?

sdep <- nosleep%>%
  filter(!is.na(sleptim1), !is.na(addepev2), sleptim1<6)%>%
  group_by(addepev2)%>%
  summarise(count=n())
sdep
## # A tibble: 2 x 2
##   addepev2 count
##   <fct>    <int>
## 1 Yes      17828
## 2 No       34275
ggplot(data=sdep, aes(x=addepev2,y=count))+geom_bar(stat="identity",color='blue',fill='green')+xlab("Depressive Disorder for people having at most 5 hours of average sleep")+ylab("Number of US citizens ")

(17828/(17828+34275))
## [1] 0.3421684

The results depict that 34.22% has a depression disorder as perceived others having less than 6 hours of sleep on the average. This means that 1/3 of those who sleep less than 6 hours on the average is perceived by other people as having a depression disorder.

#Research Question No. 3 –What insights can you provide in comparing between having less than 6 hours of sleep and having 6 to 10 hours of sleep that were perceived with depression disorder (addepev2)?

sdep1 <- atmost10hours %>%
  filter(!is.na(sleptim1),!is.na(addepev2),sleptim1>5)%>%
  group_by(addepev2)%>%
  summarise(count=n())
sdep1
## # A tibble: 2 x 2
##   addepev2  count
##   <fct>     <int>
## 1 Yes       73771
## 2 No       350259
ggplot(data=sdep1,aes(x=addepev2,y=count))+geom_bar(stat="identity",color='blue',fill='green')+xlab("Depressive Disorder for people having 6 to 10 hours average sleep")+ylab("Number of US citizens ")

(73771/(73771+350259))
## [1] 0.1739759

Based on question 2 and the result above, it shows that those having 6 to 10 hours of average sleep have lower depression disorder as perceived by others which reports to 17.40%. This implication is half of the result of those having less than 6 hours of average sleep telling us that having 6 to 10 hours of average sleep would decrease depression disorder as perceived by others.