Skip to contents

Exam2.B.5 is related to multi batch regression data assuming different forms of linear models.

References

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

See also

Author

  1. Muhammad Yaseen (myaseen208@gmail.com)

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

Examples

#-----------------------------------------------------------------------------------
## Nested Model with no intercept
#-----------------------------------------------------------------------------------

data(Table1.2)
Table1.2$Batch <- factor(x = Table1.2$Batch)

Exam2.B.5.lm1 <- lm(formula = Y ~ 0 + Batch + Batch/X, data = Table1.2)
DesignMatrix.lm1 <- model.matrix (object = Exam2.B.5.lm1)
DesignMatrix.lm1
#>    Batch1 Batch2 Batch3 Batch4 Batch1:X Batch2:X Batch3:X Batch4:X
#> 1       1      0      0      0        0        0        0        0
#> 2       1      0      0      0        3        0        0        0
#> 3       1      0      0      0        6        0        0        0
#> 4       1      0      0      0        9        0        0        0
#> 5       1      0      0      0       12        0        0        0
#> 6       1      0      0      0       18        0        0        0
#> 7       1      0      0      0       24        0        0        0
#> 8       1      0      0      0       36        0        0        0
#> 9       1      0      0      0       48        0        0        0
#> 10      0      1      0      0        0        0        0        0
#> 11      0      1      0      0        0        3        0        0
#> 12      0      1      0      0        0        6        0        0
#> 13      0      1      0      0        0        9        0        0
#> 14      0      1      0      0        0       12        0        0
#> 15      0      1      0      0        0       18        0        0
#> 16      0      1      0      0        0       24        0        0
#> 17      0      1      0      0        0       36        0        0
#> 18      0      1      0      0        0       48        0        0
#> 19      0      0      1      0        0        0        0        0
#> 20      0      0      1      0        0        0        3        0
#> 21      0      0      1      0        0        0        6        0
#> 22      0      0      1      0        0        0        9        0
#> 23      0      0      1      0        0        0       12        0
#> 24      0      0      1      0        0        0       18        0
#> 25      0      0      1      0        0        0       24        0
#> 26      0      0      1      0        0        0       36        0
#> 27      0      0      1      0        0        0       48        0
#> 28      0      0      0      1        0        0        0        0
#> 29      0      0      0      1        0        0        0        3
#> 30      0      0      0      1        0        0        0        6
#> 31      0      0      0      1        0        0        0        9
#> 32      0      0      0      1        0        0        0       12
#> 33      0      0      0      1        0        0        0       18
#> 34      0      0      0      1        0        0        0       24
#> 35      0      0      0      1        0        0        0       36
#> 36      0      0      0      1        0        0        0       48
#> attr(,"assign")
#> [1] 1 1 1 1 2 2 2 2
#> attr(,"contrasts")
#> attr(,"contrasts")$Batch
#> [1] "contr.treatment"
#> 

#-----------------------------------------------------------------------------------
## Interaction Model with intercept
#-----------------------------------------------------------------------------------
Exam2.B.5.lm2 <-lm(formula = Y ~ Batch + X + Batch*X, data  = Table1.2)
DesignMatrix.lm2 <-   model.matrix (object = Exam2.B.5.lm2)
DesignMatrix.lm2
#>    (Intercept) Batch2 Batch3 Batch4  X Batch2:X Batch3:X Batch4:X
#> 1            1      0      0      0  0        0        0        0
#> 2            1      0      0      0  3        0        0        0
#> 3            1      0      0      0  6        0        0        0
#> 4            1      0      0      0  9        0        0        0
#> 5            1      0      0      0 12        0        0        0
#> 6            1      0      0      0 18        0        0        0
#> 7            1      0      0      0 24        0        0        0
#> 8            1      0      0      0 36        0        0        0
#> 9            1      0      0      0 48        0        0        0
#> 10           1      1      0      0  0        0        0        0
#> 11           1      1      0      0  3        3        0        0
#> 12           1      1      0      0  6        6        0        0
#> 13           1      1      0      0  9        9        0        0
#> 14           1      1      0      0 12       12        0        0
#> 15           1      1      0      0 18       18        0        0
#> 16           1      1      0      0 24       24        0        0
#> 17           1      1      0      0 36       36        0        0
#> 18           1      1      0      0 48       48        0        0
#> 19           1      0      1      0  0        0        0        0
#> 20           1      0      1      0  3        0        3        0
#> 21           1      0      1      0  6        0        6        0
#> 22           1      0      1      0  9        0        9        0
#> 23           1      0      1      0 12        0       12        0
#> 24           1      0      1      0 18        0       18        0
#> 25           1      0      1      0 24        0       24        0
#> 26           1      0      1      0 36        0       36        0
#> 27           1      0      1      0 48        0       48        0
#> 28           1      0      0      1  0        0        0        0
#> 29           1      0      0      1  3        0        0        3
#> 30           1      0      0      1  6        0        0        6
#> 31           1      0      0      1  9        0        0        9
#> 32           1      0      0      1 12        0        0       12
#> 33           1      0      0      1 18        0        0       18
#> 34           1      0      0      1 24        0        0       24
#> 35           1      0      0      1 36        0        0       36
#> 36           1      0      0      1 48        0        0       48
#> attr(,"assign")
#> [1] 0 1 1 1 2 3 3 3
#> attr(,"contrasts")
#> attr(,"contrasts")$Batch
#> [1] "contr.treatment"
#> 

#-----------------------------------------------------------------------------------
## Interaction Model with no intercept
#-----------------------------------------------------------------------------------
Exam2.B.5.lm3 <- lm(formula = Y ~ 0 + Batch + Batch*X, data = Table1.2)
DesignMatrix.lm3 <-   model.matrix(object = Exam2.B.5.lm3)
DesignMatrix.lm3
#>    Batch1 Batch2 Batch3 Batch4  X Batch2:X Batch3:X Batch4:X
#> 1       1      0      0      0  0        0        0        0
#> 2       1      0      0      0  3        0        0        0
#> 3       1      0      0      0  6        0        0        0
#> 4       1      0      0      0  9        0        0        0
#> 5       1      0      0      0 12        0        0        0
#> 6       1      0      0      0 18        0        0        0
#> 7       1      0      0      0 24        0        0        0
#> 8       1      0      0      0 36        0        0        0
#> 9       1      0      0      0 48        0        0        0
#> 10      0      1      0      0  0        0        0        0
#> 11      0      1      0      0  3        3        0        0
#> 12      0      1      0      0  6        6        0        0
#> 13      0      1      0      0  9        9        0        0
#> 14      0      1      0      0 12       12        0        0
#> 15      0      1      0      0 18       18        0        0
#> 16      0      1      0      0 24       24        0        0
#> 17      0      1      0      0 36       36        0        0
#> 18      0      1      0      0 48       48        0        0
#> 19      0      0      1      0  0        0        0        0
#> 20      0      0      1      0  3        0        3        0
#> 21      0      0      1      0  6        0        6        0
#> 22      0      0      1      0  9        0        9        0
#> 23      0      0      1      0 12        0       12        0
#> 24      0      0      1      0 18        0       18        0
#> 25      0      0      1      0 24        0       24        0
#> 26      0      0      1      0 36        0       36        0
#> 27      0      0      1      0 48        0       48        0
#> 28      0      0      0      1  0        0        0        0
#> 29      0      0      0      1  3        0        0        3
#> 30      0      0      0      1  6        0        0        6
#> 31      0      0      0      1  9        0        0        9
#> 32      0      0      0      1 12        0        0       12
#> 33      0      0      0      1 18        0        0       18
#> 34      0      0      0      1 24        0        0       24
#> 35      0      0      0      1 36        0        0       36
#> 36      0      0      0      1 48        0        0       48
#> attr(,"assign")
#> [1] 1 1 1 1 2 3 3 3
#> attr(,"contrasts")
#> attr(,"contrasts")$Batch
#> [1] "contr.treatment"
#> 

#-----------------------------------------------------------------------------------
## Interaction Model with intercept  but omitting X term as main effect
#-----------------------------------------------------------------------------------
Exam2.B.5.lm4 <- lm(formula = Y ~ Batch + Batch*X, data = Table1.2)
DesignMatrix.lm4 <-   model.matrix(object = Exam2.B.5.lm4)
DesignMatrix.lm4
#>    (Intercept) Batch2 Batch3 Batch4  X Batch2:X Batch3:X Batch4:X
#> 1            1      0      0      0  0        0        0        0
#> 2            1      0      0      0  3        0        0        0
#> 3            1      0      0      0  6        0        0        0
#> 4            1      0      0      0  9        0        0        0
#> 5            1      0      0      0 12        0        0        0
#> 6            1      0      0      0 18        0        0        0
#> 7            1      0      0      0 24        0        0        0
#> 8            1      0      0      0 36        0        0        0
#> 9            1      0      0      0 48        0        0        0
#> 10           1      1      0      0  0        0        0        0
#> 11           1      1      0      0  3        3        0        0
#> 12           1      1      0      0  6        6        0        0
#> 13           1      1      0      0  9        9        0        0
#> 14           1      1      0      0 12       12        0        0
#> 15           1      1      0      0 18       18        0        0
#> 16           1      1      0      0 24       24        0        0
#> 17           1      1      0      0 36       36        0        0
#> 18           1      1      0      0 48       48        0        0
#> 19           1      0      1      0  0        0        0        0
#> 20           1      0      1      0  3        0        3        0
#> 21           1      0      1      0  6        0        6        0
#> 22           1      0      1      0  9        0        9        0
#> 23           1      0      1      0 12        0       12        0
#> 24           1      0      1      0 18        0       18        0
#> 25           1      0      1      0 24        0       24        0
#> 26           1      0      1      0 36        0       36        0
#> 27           1      0      1      0 48        0       48        0
#> 28           1      0      0      1  0        0        0        0
#> 29           1      0      0      1  3        0        0        3
#> 30           1      0      0      1  6        0        0        6
#> 31           1      0      0      1  9        0        0        9
#> 32           1      0      0      1 12        0        0       12
#> 33           1      0      0      1 18        0        0       18
#> 34           1      0      0      1 24        0        0       24
#> 35           1      0      0      1 36        0        0       36
#> 36           1      0      0      1 48        0        0       48
#> attr(,"assign")
#> [1] 0 1 1 1 2 3 3 3
#> attr(,"contrasts")
#> attr(,"contrasts")$Batch
#> [1] "contr.treatment"
#>