Homework #5
Download the data ‘studentdata’ from the package ‘LearnBayes.’
1. Create a separate column labelled as ‘HoursSlept’ in the ‘studentdata’ folder recording
how many hours each student slept the previous night. Obtain summary statistics of all
data in the enhanced ‘studentdata.’ 3 points
Code:
library(LearnBayes)
data("studentdata")
studentdata$HoursSlept= (studentdata$WakeUp- studentdata$ToSleep)
dim(studentdata)
head(studentdata)
m
er as
summary(studentdata)
co
eH w
Summary statistics:
o.
Student Height
rs e
Gender Shoes
ou urc
Min. : 1 Min. :54.0 female:435 Min. : 0.00
1st Qu.:165 1st Qu.:64.0 male :222 1st Qu.: 6.00
Median :329 Median :66.0 Median : 12.00
Mean :329 Mean :66.7 Mean : 15.42
o
3rd Qu.:493 3rd Qu.:70.0 3rd Qu.: 20.00
Max. :657 Max. :84.0 Max. :164.00
aC s
NA's :10 NA's :22
vi y re
Number Dvds ToSleep WakeUp
Min. : 1.00 Min. : 0.00 Min. :-2.500 Min. : 1.000
1st Qu.: 4.00 1st Qu.: 10.00 1st Qu.: 0.000 1st Qu.: 7.500
Median : 6.00 Median : 20.00 Median : 1.000 Median : 8.500
ed d
Mean : 5.67 Mean : 30.93 Mean : 1.001 Mean : 8.383
ar stu
3rd Qu.: 7.00 3rd Qu.: 30.00 3rd Qu.: 2.000 3rd Qu.: 9.000
Max. :10.00 Max. :1000.00 Max. : 6.000 Max. :13.000
NA's :2 NA's :16 NA's :3 NA's :2
Haircut Job Drink HoursSlept
is
Min. : 0.00 Min. : 0.00 milk :113 Min. : 2.500
1st Qu.: 10.00 1st Qu.: 0.00 pop :178 1st Qu.: 6.500
Th
Median : 16.00 Median :10.50 water:355 Median : 7.500
Mean : 25.91 Mean :11.45 NA's : 11 Mean : 7.385
3rd Qu.: 30.00 3rd Qu.:17.50 3rd Qu.: 8.500
Max. :180.00 Max. :80.00 Max. :12.500
NA's :20 NA's :32 NA's :4
sh
This study source was downloaded by 100000784424693 from CourseHero.com on 06-20-2021 21:46:31 GMT -05:00
https://www.coursehero.com/file/80103099/Biostatistics-HW5docx/
, Segregate the ‘studentdata’ by gender.
2. Obtain summary statistics of ‘Height’ for males. 2 points
Code:
males_data= subset(studentdata, studentdata$Gender=="male") #separate male data from
female
summary(males_data$Height)
Summary statistics of height for males
3. Obtain standard deviation of ‘Height’ for males. 1 point
m
er as
Code: sd(males_data$Height, na.rm = T)
co
Standard deviation of ‘Height’ for males: 3.080943 (units)
eH w
o.
4. Obtain summary statistics of ‘Height’ for females. 2 points
rs e
Code: females_data= subset(studentdata, studentdata$Gender=="female")Summary
ou urc
statistics of ‘Height’ for females:
o
aC s
vi y re
5. Obtain standard deviation of ‘Height’ for females. 1 point
Code: sd(females_data$Height, na.rm = T)
ed d
Standard deviation of ‘Height’ for females: 3.363986
ar stu
6. Portray the (density) histograms of heights for males and females in the same frame.
Superimpose each histogram with nonparametric density curve and appropriate normal
is
curve. Include the rugs. 6+4+4+2 points
Th
Code:
par(mfrow= c(1,2), oma= c(5, 4, 4, 2))
hist(males_data$Height, xlab= "Height of Males",
sh
ylab= "Density", density= 15, freq=F, col= "black",
main= "Density Histogram + Nonparametric Curve+ Normal Curve")
lines(density(x= males_data$Height, na.rm = T), col= "blue", lwd=2)
curve(dnorm(x, mean= 70.51, sd= 3.080943 ), col= "red", lwd= 2, add=T)
This study source was downloaded by 100000784424693 from CourseHero.com on 06-20-2021 21:46:31 GMT -05:00
https://www.coursehero.com/file/80103099/Biostatistics-HW5docx/