library("magrittr")
## Warning: package 'magrittr' was built under R version 4.0.5
library("dplyr")
## Warning: package 'dplyr' was built under R version 4.0.4
## 
## 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(ggplot2)

Research question 1: Exploratory Data Analysis and some statistics on the variables “sleptim1” and “addepev2” in terms of the following:

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

load("brfss2013.RData")

On the “sleptim1” variable.

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

On the “addepev2” variable.

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

1.2 Provide statistics using the function summary without NA’s.

In the “addepev2” variable.

NoNAs<-brfss2013%>%
  filter(!is.na(addepev2))
summary(NoNAs$addepev2)
##    Yes     No 
##  95779 393707

In the “sleptim1” variable.

NoNAs<-brfss2013%>%
  filter(!is.na(sleptim1))
summary(NoNAs$sleptim1)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   0.000   6.000   7.000   7.052   8.000 450.000

Function summary with data at most 10 hours of sleep

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

Research question 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?

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

(17828/(17828+34275))*100
## [1] 34.21684

The results above show that 34.23% are those having depression disorder as perceived others having less than 6 hours of sleep on the average. It implies that 1 out of 3 of those who sleep less than 6 hours on the average is perceived by others having depression disorder.

Research question 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)?

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

(73771/(73771+350259))*100
## [1] 17.39759

Based on question 2 and with the result of Question 3, it shows that those having 6 to 10 hours of average sleep have lower depression disorder as perceived by others which accounts to 17.40%. This result is half of the result of those having less than 6 hours of average sleep. This tells us that having 6 to 10 hours of average sleep would lower depression disorder as perceived by others.

```