hr0 <- read.csv(pathtofile, # must edit pathtofile
skip = 1,
col.names = c("first","second","sex","class"),
colClasses = c("numeric","numeric","factor","factor"))
hr0$hr <- hr0$first + hr0$secondSTAT 516 hw 8
Students in two different classes were asked to measure their heart rates. Each student counted heartbeats during two 30-second periods separated by several minutes and, moreover, recorded his or her sex. It is of interest to see whether the mean resting heart rate is different for men and women, as claimed. Since the data were collected in several classes, the following model is considered: Assume
The code below reads in a the data set HR_sex_combined.csv which can be downloaded here.
To make this homework simpler, work with a balanced version of the data created by the following code, which draws sub-samples of size
# fix the random seed so the same subsets
# are drawn every time the code runs
set.seed(2)
hr0$class_sex <- as.factor(paste(hr0$class,hr0$sex))
classes <- levels(hr0$class_sex)
ab <- length(classes)
n <- 8
hr <- data.frame()
for(i in 1:ab){
ind <- which(hr0$class_sex == classes[i])
hr <- rbind(hr,hr0[sample(ind,n),])
}
head(hr) first second sex class hr class_sex
24 32 31 f STAT_515_sp_2026 63 STAT_515_sp_2026 f
7 44 44 f STAT_515_sp_2026 88 STAT_515_sp_2026 f
28 40 33 f STAT_515_sp_2026 73 STAT_515_sp_2026 f
9 46 39 f STAT_515_sp_2026 85 STAT_515_sp_2026 f
2 38 34 f STAT_515_sp_2026 72 STAT_515_sp_2026 f
19 44 43 f STAT_515_sp_2026 87 STAT_515_sp_2026 f
1.
Make boxplots of the heart rate measurements for all class and sex combinations.
2.
Give the values of the
3.
Obtain the method of moments estimators of the variance components in the model. Report the estimated standard deviations as well as any issues encountered.
4.
Give a 95% confidence interval for the difference (women minus men) in mean resting heart rate between the sexes. Construct the interval without using the lmer() function. Give an interpretation of your interval.
5.
Obtain the REML estimators of the variance components in the model. Report the estimated standard deviations.
6.
Give a lmer() function. Give an interpretation of your interval.
7.
Check the assumptions of the model.