Exam5.2 three factor main effects only design

References

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

See also

Examples

DataSet5.2$a <- factor( x = DataSet5.2$a) DataSet5.2$b <- factor( x = DataSet5.2$b) DataSet5.2$c <- factor(x = DataSet5.2$c) ##---first adding factor a in model Exam5.2.lm1 <- lm( formula = y~ a , data = DataSet5.2 # , subset # , weights # , na.action , method = "qr" , model = TRUE # , x = FALSE # , y = FALSE , qr = TRUE , singular.ok = TRUE , contrasts = NULL # , offset # , ... ) summary( Exam5.2.lm1 )
#> #> Call: #> lm(formula = y ~ a, data = DataSet5.2, method = "qr", model = TRUE, #> qr = TRUE, singular.ok = TRUE, contrasts = NULL) #> #> Residuals: #> Min 1Q Median 3Q Max #> -1.5833 -1.2833 0.4333 0.9333 1.1167 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 9.7667 0.6913 14.13 2.11e-06 *** #> a1 1.6167 0.8466 1.91 0.0978 . #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 1.197 on 7 degrees of freedom #> Multiple R-squared: 0.3425, Adjusted R-squared: 0.2486 #> F-statistic: 3.646 on 1 and 7 DF, p-value: 0.09783 #>
library(lsmeans) ##---A first ( Lsm5.2lm1 <- lsmeans::lsmeans( object = Exam5.2.lm1 , specs = "a" # , ... ) )
#> a lsmean SE df lower.CL upper.CL #> 0 9.766667 0.6912721 7 8.132068 11.40127 #> 1 11.383333 0.4888032 7 10.227497 12.53917 #> #> Confidence level used: 0.95
## lsmeans::contrast(object = Lsm5.2lm1 , method = "pairwise") Anovalm1 <- anova(object = Exam5.2.lm1) Anovalm1
#> Analysis of Variance Table #> #> Response: y #> Df Sum Sq Mean Sq F value Pr(>F) #> a 1 5.2272 5.2272 3.6463 0.09783 . #> Residuals 7 10.0350 1.4336 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
##---then adding factor b in model Exam5.2.lm2 <- lm( formula = y~ a + b , data = DataSet5.2 # , subset # , weights # , na.action , method = "qr" , model = TRUE # , x = FALSE # , y = FALSE , qr = TRUE , singular.ok = TRUE , contrasts = NULL # , offset # , ... ) summary( Exam5.2.lm1 )
#> #> Call: #> lm(formula = y ~ a, data = DataSet5.2, method = "qr", model = TRUE, #> qr = TRUE, singular.ok = TRUE, contrasts = NULL) #> #> Residuals: #> Min 1Q Median 3Q Max #> -1.5833 -1.2833 0.4333 0.9333 1.1167 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 9.7667 0.6913 14.13 2.11e-06 *** #> a1 1.6167 0.8466 1.91 0.0978 . #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 1.197 on 7 degrees of freedom #> Multiple R-squared: 0.3425, Adjusted R-squared: 0.2486 #> F-statistic: 3.646 on 1 and 7 DF, p-value: 0.09783 #>
(Lsm5.2lm2 <- lsmeans::lsmeans( object = Exam5.2.lm2 , specs = "b" # , ... ) )
#> b lsmean SE df lower.CL upper.CL #> 0 10.95 0.6093029 6 9.45909 12.44091 #> 1 10.20 0.6093029 6 8.70909 11.69091 #> #> Results are averaged over the levels of: a #> Confidence level used: 0.95
## lsmeans::contrast(object = Lsm5.2lm2, method = "pairwise") Anovalm2 <- anova(object = Exam5.2.lm2) Anovalm2
#> Analysis of Variance Table #> #> Response: y #> Df Sum Sq Mean Sq F value Pr(>F) #> a 1 5.2272 5.2272 3.5200 0.1097 #> b 1 1.1250 1.1250 0.7576 0.4175 #> Residuals 6 8.9100 1.4850
##---then adding factor c in model Exam5.2.lm3 <- lm( formula = y~ a + b + c , data = DataSet5.2 # , subset # , weights # , na.action , method = "qr" , model = TRUE # , x = FALSE # , y = FALSE , qr = TRUE , singular.ok = TRUE , contrasts = NULL # , offset # , ... ) summary( Exam5.2.lm3 )
#> #> Call: #> lm(formula = y ~ a + b + c, data = DataSet5.2, method = "qr", #> model = TRUE, qr = TRUE, singular.ok = TRUE, contrasts = NULL) #> #> Residuals: #> 1 2 3 4 5 6 7 #> -1.500e-01 1.500e-01 3.000e-01 1.000e-01 -8.000e-01 4.000e-01 -2.500e-01 #> 8 9 #> 2.500e-01 -2.082e-17 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 10.5000 0.3469 30.264 7.39e-07 *** #> a1 1.6000 0.3469 4.612 0.00578 ** #> b1 -0.0500 0.3469 -0.144 0.89104 #> c1 -2.1000 0.3469 -6.053 0.00178 ** #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 0.4626 on 5 degrees of freedom #> Multiple R-squared: 0.9299, Adjusted R-squared: 0.8878 #> F-statistic: 22.11 on 3 and 5 DF, p-value: 0.002584 #>
(Lsm5.2lm3 <- lsmeans::lsmeans( object = Exam5.2.lm3 , specs = "c" # , ... ) )
#> c lsmean SE df lower.CL upper.CL #> 0 11.275 0.2003123 5 10.760081 11.789919 #> 1 9.175 0.2832843 5 8.446794 9.903206 #> #> Results are averaged over the levels of: a, b #> Confidence level used: 0.95
## lsmeans::contrast(object = Lsm5.2lm3, method = "pairwise") Anovalm3 <- anova(object = Exam5.2.lm3) Anovalm3
#> Analysis of Variance Table #> #> Response: y #> Df Sum Sq Mean Sq F value Pr(>F) #> a 1 5.2272 5.2272 24.426 0.004314 ** #> b 1 1.1250 1.1250 5.257 0.070401 . #> c 1 7.8400 7.8400 36.636 0.001775 ** #> Residuals 5 1.0700 0.2140 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
##---Now Change the order and add b first in model Exam5.2.lm4 <- lm( formula = y~ b , data = DataSet5.2 # , subset # , weights # , na.action , method = "qr" , model = TRUE # , x = FALSE # , y = FALSE , qr = TRUE , singular.ok = TRUE , contrasts = NULL # , offset # , ... ) summary( Exam5.2.lm4 )
#> #> Call: #> lm(formula = y ~ b, data = DataSet5.2, method = "qr", model = TRUE, #> qr = TRUE, singular.ok = TRUE, contrasts = NULL) #> #> Residuals: #> Min 1Q Median 3Q Max #> -2.96 -0.10 0.00 0.84 1.14 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 11.3600 0.5921 19.185 2.6e-07 *** #> b1 -1.1600 0.8882 -1.306 0.233 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 1.324 on 7 degrees of freedom #> Multiple R-squared: 0.1959, Adjusted R-squared: 0.08105 #> F-statistic: 1.706 on 1 and 7 DF, p-value: 0.2328 #>
(Lsm5.2lm4 <- lsmeans::lsmeans( object = Exam5.2.lm4 , specs = "b" # , ... ) )
#> b lsmean SE df lower.CL upper.CL #> 0 11.36 0.5921390 7 9.959814 12.76019 #> 1 10.20 0.6620315 7 8.634544 11.76546 #> #> Confidence level used: 0.95
## lsmeans::contrast(object = Lsm5.2lm4, method = "pairwise") Anovalm4 <- anova(object = Exam5.2.lm4) ##---then adding factor a in model Exam5.2.lm5 <- lm( formula = y~ b + a , data = DataSet5.2 # , subset # , weights # , na.action , method = "qr" , model = TRUE # , x = FALSE # , y = FALSE , qr = TRUE , singular.ok = TRUE , contrasts = NULL # , offset # , ... ) summary( Exam5.2.lm5 )
#> #> Call: #> lm(formula = y ~ b + a, data = DataSet5.2, method = "qr", model = TRUE, #> qr = TRUE, singular.ok = TRUE, contrasts = NULL) #> #> Residuals: #> Min 1Q Median 3Q Max #> -1.8667 -0.7833 0.5667 0.7667 1.1833 #> #> Coefficients: #> Estimate Std. Error t value Pr(>|t|) #> (Intercept) 10.2667 0.9083 11.303 2.87e-05 *** #> b1 -0.7500 0.8617 -0.870 0.418 #> a1 1.3667 0.9083 1.505 0.183 #> --- #> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 #> #> Residual standard error: 1.219 on 6 degrees of freedom #> Multiple R-squared: 0.4162, Adjusted R-squared: 0.2216 #> F-statistic: 2.139 on 2 and 6 DF, p-value: 0.199 #>
(Lsm5.2lm5 <- lsmeans::lsmeans( object = Exam5.2.lm5 , specs = "a" # , ... ) )
#> a lsmean SE df lower.CL upper.CL #> 0 9.891667 0.7180703 6 8.134612 11.64872 #> 1 11.258333 0.5178079 6 9.991303 12.52536 #> #> Results are averaged over the levels of: b #> Confidence level used: 0.95
## lsmeans::contrast(object = Lsm5.2lm3, method = "pairwise") Anovalm5 <- anova(object = Exam5.2.lm5) Anovalm5
#> Analysis of Variance Table #> #> Response: y #> Df Sum Sq Mean Sq F value Pr(>F) #> b 1 2.9902 2.9902 2.0136 0.2057 #> a 1 3.3620 3.3620 2.2640 0.1831 #> Residuals 6 8.9100 1.4850