Question 3
data(eggs)
a) The response is the fat content in the egg powder samples.
b) There would be a random effect for each laboratory and each technician. (Each lab got multiple samples and each technician did multiple tests)
c) The technician random effect would be nested in each lab since technicians only work at one lab.
d) The graph is below. There doesn't appear to be much difference across labs, although lab 1 is pretty different from the others. There seems to be bigger difference across each technician. Only technician 1 from lab 5 is good at being consistent.
xyplot(Fat ~ Technician|Lab, data = eggs)
e) The model is built below.
eggmod = lmer(Fat ~ 1 + (1|Lab/Technician/Sample), data = eggs)
summary(eggmod)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Fat ~ 1 + (1 | Lab/Technician/Sample)
## Data: eggs
##
## REML criterion at convergence: -64.2
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.04098 -0.46576 0.00927 0.59713 1.54276
##
## Random effects:
## Groups Name Variance Std.Dev.
## Sample:(Technician:Lab) (Intercept) 0.003065 0.05536
## Technician:Lab (Intercept) 0.006980 0.08355
## Lab (Intercept) 0.005920 0.07694
## Residual 0.007196 0.08483
## Number of obs: 48, groups:
## Sample:(Technician:Lab), 24; Technician:Lab, 12; Lab, 6
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 0.38750 0.04296 9.019
f) The variance between technicians is 0.008002
g) The variance between labs is 0.005920
h)
eggmod2 = lmer(Fat ~ 1 + (1|Lab:Technician), data = eggs)
summary(eggmod2)
## Linear mixed model fit by REML ['lmerMod']
## Formula: Fat ~ 1 + (1 | Lab:Technician)
## Data: eggs
##
## REML criterion at convergence: -61.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -2.04786 -0.44677 0.06193 0.64865 1.97523
##
## Random effects:
## Groups Name Variance Std.Dev.
## Lab:Technician (Intercept) 0.013383 0.11568
## Residual 0.009239 0.09612
## Number of obs: 48, groups: Lab:Technician, 12
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 0.38750 0.03616 10.72
Question 4
data(abrasion)
a) The response is the 'wear' of the fabric, which is how much wear and tear it has.
b) There would be a random effect for each run on the machine. There would also be a random effect for the position on the machine. Finally, there would be a random effect for each material.
c) These random effects would all be crossed.
d) The plot is below. From this plot, it appears that material B has the lowest wear (loss of weight), and material A has the highest wear. It also appears that position 1 causes the most wear and position 2 causes the least wear.
xyplot(wear ~ material|position, data = abrasion)
e)
fabricmod = lmer(wear ~ 1 + (1|run) + (1|position) + (1|material), data = abrasion)
summary(fabricmod)
## Linear mixed model fit by REML ['lmerMod']
## Formula: wear ~ 1 + (1 | run) + (1 | position) + (1 | material)
## Data: abrasion
##
## REML criterion at convergence: 128
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -1.10395 -0.29893 -0.02499 0.41220 1.11148
##
## Random effects:
## Groups Name Variance Std.Dev.
## run (Intercept) 66.90 8.180
## position (Intercept) 107.06 10.347
## material (Intercept) 369.80 19.230
## Residual 61.25 7.826
## Number of obs: 16, groups: run, 4; position, 4; material, 4
##
## Fixed effects:
## Estimate Std. Error t value
## (Intercept) 239.50 11.82 20.26
f) p-value is 0.00123. This means that the more complex model containing material is a significant improvement over the simpler model, and we should probably use the material random effect variable. This means that mean weight loss does differ between the four materials.