Exam9.2: Example 9.2 from Generalized Linear Mixed Models: Modern...

Exam9.2R Documentation

Example 9.2 from Generalized Linear Mixed Models: Modern Concepts, Methods and Applications by Walter W. Stroup (p-276)

Description

Exam9.2 Two way random effects nested model

Author(s)

  1. Muhammad Yaseen (myaseen208@gmail.com)

  2. Adeela Munawar (adeela.uaf@gmail.com)

References

  1. Stroup, W. W. (2012). Generalized Linear Mixed Models: Modern Concepts, Methods and Applications. CRC Press.

See Also

DataSet9.2

Examples


data(DataSet9.2)
DataSet9.2$a <- factor(x = DataSet9.2$a)
DataSet9.2$b <- factor(x = DataSet9.2$b)

library(lmerTest)
Exam9.2lmer <- lmer(y ~ (1|b/a), data = DataSet9.2)
summary(Exam9.2lmer)

Exam9.2lmer2 <- lm(y ~ a + b %in% a, data = DataSet9.2)
summary(Exam9.2lmer2)

##--- Over all mean
library(phia)
list9.2 <- list(a = c("1" = 1/7,"2" = 1/7
                    , "3" = 1/7,"4" = 1/7
                    , "5" = 1/7,"6" = 1/7
                    , "7" = 1/7
                     ))
phia::testFactors(model = Exam9.2lmer2, levels = list9.2)

#---BLUP Estimates
coef <- unlist(ranef(Exam9.2lmer)$a)
BLUPa <- NULL
for(i in 1:length(coef)){
  BLUPa[i] <- (mean(DataSet9.2$y) + coef[i])
  }
print(BLUPa)

#---BLUP Estimates Narrow
BLUPaNar <- NULL
for( i in 1:length(coef)) {
  BLUPaNar[i] <- (mean(DataSet9.2$y) + coef[i])
}

BLUPaNar


StroupGLMM documentation built on Oct. 2, 2024, 1:07 a.m.