STAT 516 hw 8

Author

Karl Gregory

Part I.

Each student in a statistics class was asked to provide a parts per million (ppm) reading for test strips A, B, and C pictured here:

The readings can be imported into R with the following code:

link <- url("https://gregorkb.github.io/data/ppm_measure_combined.csv")
ppm_wide <- read.csv(link,skip=1)
ppm_wide$student <- c(1:nrow(ppm_wide))

ppm_long <- reshape(ppm_wide,
                    idvar = c("class","student"),
                    varying = c("A","B","C"),
                    v.names = "ppm",
                    timevar = "strip", 
                    times = c("A","B","C"), 
                    new.row.names = 1:1e4,
                    direction = "long")
               
student <- as.factor(ppm_long$student)
strip <- as.factor(ppm_long$strip)
ppm <- ppm_long$ppm

Assume the data arise from the model \[ Y_{ij} = \mu + \tau_i + B_j + \varepsilon_{ij}, \] where \(Y_{ij}\) denotes the reading for test strip \(i\) reported by student \(j\), \(\mu\) is a baseline mean, the \(\tau_i\) are test strip effects, the \(B_j\) are student effects assumed to be independent \(\mathcal{N}(0,\sigma_B^2)\) random variables, and the \(\varepsilon_{ij}\) are independent \(\mathcal{N}(0,\sigma_\varepsilon^2)\) random variables for \(i=1,2,3\) and \(j=1,\dots,b\), where \(b\) is the number of students. Moreover, assume the \(B_j\) are independent of the \(\varepsilon_{ij}\). This is the model for a randomized complete block design.

1.

As a way to visualize the data, construct interaction plots showing the students’ ppm readings for each test strip, with test strip on the horizontal axis. You may suppress the legend with legend = FALSE if desired.

2.

Give the ANOVA table for these data.

3.

Report the p-value for testing whether there is significant student to student variation in the reading of the ppm test strips. Give an interpretation of this p-value.

4.

Give the restricted maximum likelihood estimates for the two variance components in the model.

5.

Give confidence intervals for the expected ppm readings of the three test strips. Use the Bonferroni adjustment to ensure that all intervals will cover their targets with probability at least \(0.95\).

6.

Suppose the manufacturer of the test strips wishes typical users to be able to measure the true chlorine concentration to within \(20\) ppm. According to your analysis of the data, is this possible with these test strips?

Part II.

Students in three statistics 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 \[ Y_{ijk} = \mu + \tau_i + B_j + (\tau B)_{ij} + \varepsilon_{ijk}, \] where \(Y_{ijk}\) represents the heart rate (the sum of the two 30-second counts) for student \(k\) of sex \(i\) in class \(j\), \(\tau_i\) is the effect of sex \(i\), the \(B_j\) are class effects assumed to be independent \(\mathcal{N}(0,\sigma^2_B)\) random variables, the \((\tau B)_{ij}\) are interaction effects between sex and classroom assumed to be independent \(\mathcal{N}(0,\sigma^2_{AB})\) random variables, and the \(\varepsilon_{ijk}\) are independent error terms having the \(\mathcal{N}(0,\sigma^2_\varepsilon)\) distribution for \(i=1,2\), \(j = 1,2\), and \(k = 1,\dots,n_{ij}\). Moreover, assume all the random variables are independent of each other. This is a randomized complete block design with replication.

The code below reads in the data.

link <- url("https://gregorkb.github.io/data/HR_sex_combined.csv")
hr0 <- read.csv(link, 
                skip = 1,
                col.names = c("first","second","sex","class","bpm"),
                colClasses = c("numeric","numeric","factor","factor","numeric"))

To make this homework simpler, work with the balanced version of the data created by the following code, which draws subsamples of size \(n = 9\) from each class and sex combination.

# fix the random seed so the same subsets 
# are drawn every time the code runs
set.seed(1) 

hr0$class_sex <- as.factor(paste(hr0$class,hr0$sex,sep=":"))
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 bpm          class_sex
5     39     37   f STAT_515_sp_2026  76 STAT_515_sp_2026:f
8     44     36   f STAT_515_sp_2026  80 STAT_515_sp_2026:f
2     38     34   f STAT_515_sp_2026  72 STAT_515_sp_2026:f
3     45     38   f STAT_515_sp_2026  83 STAT_515_sp_2026:f
19    44     43   f STAT_515_sp_2026  87 STAT_515_sp_2026:f
28    40     33   f STAT_515_sp_2026  73 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 \(F\) test statistics and \(p\) values for testing the null hypotheses of i) no difference in mean heart rate between the sexes, ii) no significant variation between classes, and iii) no significant variation due to a class and sex interaction. Interpret your findings based on i), ii), and iii) assuming that the assumptions of the model are met.

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.

Obtain the REML estimators of the variance components in the model. Report the estimated standard deviations.

5.

Give a \(95\%\) confidence interval for the difference in mean resting heart rate between men and women (women minus men) without using the ls_means() function. Give an interpretation of your interval.

6.

Give a \(95\%\) confidence interval for the difference in mean resting heart rate between men and women (women minus men) using thels_means() function on the output of the lmer() function (this interval may differ from the one you computed in the previous step). Give an interpretation of your interval.

7.

Check whether the assumptions of the model appear to hold.