Section 16 Two-way ANOVA: function lm

16.1 lm

  • We can fit a linear model using the function lm

  • Fit a linear model using the function lm to compare if there is a difference between Groups.

  • Examine the R object of the lm outputs.

  • Note: It is crucial to convert the grouping variable into a factor before running the ANOVA analysis. This is the key difference between an ANOVA analysis and a regression analysis, and the results could be very misleading if this step is not performed.


16.2 Model

\[ \Huge y_{ijk} = \mu + \tau_{i} + \delta_{j} + \epsilon_{ijk} \]


16.3 Hypothesis

\[ \large H_O: \tau_1 = \tau_2 = ...= \tau_g \]

\[ \large H_A: \tau_i \ne 0 \space for \space at \space least \space one \space \tau_i\]

\[ \large H_O: \delta_1 = \delta_2 \]

\[ \large H_A: \delta_1 \ne \delta_2 \]


16.4 Syntax

\[ \large fm \leftarrow lm(SBP \sim Group + DM, \space data=BP) \]

\[ \large anova(fm) \]

\[ \large summary(fm) \]