Skip to contents

Exam2.B.7 is related to multi batch regression data assuming different forms of linear models with factorial experiment.

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

#-----------------------------------------------------------------------------------
## 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
#> (Intercept)          b2       a2:b2 
#>      41.050      -2.800      -6.725 

#-----------------------------------------------------------------------------------
## 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
#>     b2  a2:b2 
#> 38.250 -6.725 

#-----------------------------------------------------------------------------------
## 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)
#> 
#> Call:
#> lm(formula = y ~ a + a/b, data = DataExam2.B.7)
#> 
#> Residuals:
#>    Min     1Q Median     3Q    Max 
#> -7.325 -1.769 -0.475  2.581  6.775 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   40.975      2.164  18.933 2.64e-10 ***
#> a2             0.150      3.061   0.049  0.96172    
#> a1:b2         -2.725      3.061  -0.890  0.39078    
#> a2:b2         -9.600      3.061  -3.137  0.00859 ** 
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Residual standard error: 4.328 on 12 degrees of freedom
#> Multiple R-squared:  0.5188,	Adjusted R-squared:  0.3985 
#> F-statistic: 4.313 on 3 and 12 DF,  p-value: 0.02787
#> 

Exam2.B.7.lm4 <- lm(formula = y~ a + a*b, data = DataExam2.B.7)
summary(Exam2.B.7.lm4)
#> 
#> Call:
#> lm(formula = y ~ a + a * b, data = DataExam2.B.7)
#> 
#> Residuals:
#>    Min     1Q Median     3Q    Max 
#> -7.325 -1.769 -0.475  2.581  6.775 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   40.975      2.164  18.933 2.64e-10 ***
#> a2             0.150      3.061   0.049    0.962    
#> b2            -2.725      3.061  -0.890    0.391    
#> a2:b2         -6.875      4.328  -1.588    0.138    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Residual standard error: 4.328 on 12 degrees of freedom
#> Multiple R-squared:  0.5188,	Adjusted R-squared:  0.3985 
#> F-statistic: 4.313 on 3 and 12 DF,  p-value: 0.02787
#>