Exam2.B.7 | R Documentation |
Exam2.B.7 is related to multi batch regression data assuming different forms of linear models with factorial experiment.
Muhammad Yaseen (myaseen208@gmail.com)
Adeela Munawar (adeela.uaf@gmail.com)
Stroup, W. W. (2012). Generalized Linear Mixed Models: Modern Concepts, Methods and Applications. CRC Press.
DataExam2.B.7
#-----------------------------------------------------------------------------------
## Classical main effects and Interaction Model
#-----------------------------------------------------------------------------------
data(DataExam2.B.7)
DataExam2.B.7$a <- factor(x = DataExam2.B.7$a)
DataExam2.B.7$b <- factor(x = DataExam2.B.7$b)
Exam2.B.7.lm1 <- lm(formula = y~ a + b + a*b, data = DataExam2.B.7)
#-----------------------------------------------------------------------------------
## One way treatment effects model
#-----------------------------------------------------------------------------------
DesignMatrix.lm1 <- model.matrix (object = Exam2.B.7.lm1)
DesignMatrix2.B.7.2 <- DesignMatrix.lm1[,!colnames(DesignMatrix.lm1) %in% c("a2","b")]
lmfit2 <- lm.fit(x = DesignMatrix2.B.7.2, y = DataExam2.B.7$y)
Coefficientslmfit2 <- coef( object = lmfit2)
Coefficientslmfit2
#-----------------------------------------------------------------------------------
## One way treatment effects model without intercept
#-----------------------------------------------------------------------------------
DesignMatrix2.B.7.3 <-
as.matrix(DesignMatrix.lm1[,!colnames(DesignMatrix.lm1) %in% c("(Intercept)","a2","b")])
lmfit3 <- lm.fit(x = DesignMatrix2.B.7.3, y = DataExam2.B.7$y)
Coefficientslmfit3 <- coef( object = lmfit3)
Coefficientslmfit3
#-----------------------------------------------------------------------------------
## Nested Model (both models give the same result)
#-----------------------------------------------------------------------------------
Exam2.B.7.lm4 <- lm(formula = y~ a + a/b, data = DataExam2.B.7)
summary(Exam2.B.7.lm4)
Exam2.B.7.lm4 <- lm(formula = y~ a + a*b, data = DataExam2.B.7)
summary(Exam2.B.7.lm4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.