# R program for additional exercise 10.2 (VHM 802)

cheese <- read.csv("h:/vhm/vhm802/data_csv/hs10_2.csv")

library(nlme)
cheese.grp <- groupedData( moisture ~ 1|lot, data=cheese)
cheese.mixed <- lme( moisture ~ 1, random = ~1|lot, data=cheese.grp)
summary(cheese.mixed)
plot(cheese.mixed) # lowest-level residuals
plot(cheese.mixed, form=resid(., type="p") ~ fitted(.)|lot, abline=0)
qqnorm(ranef(cheese.mixed)[,]) # quantile plot for random effects
qqline(ranef(cheese.mixed)[,])

library(lme4)
cheese.mixed2 <- lmer(moisture ~ 1 + (1|lot), data=cheese)
summary(cheese.mixed2)

