Section 19 R Formula Structure
19.1 Formula in lm
Model: \(y = \beta_0 + \epsilon\)
R Formula: y ~ 1
Explanation: Simple Linear Regression - intercept only (Null) model
Model: \(y = \beta_1x + \epsilon\)
R Formula: y ~ 0 + x
OR y ~ -1 + x
Explanation: Simple Linear Regression - slope only model
Model: \(y = \beta_0 + \beta_1x + \epsilon\)
R Formula: y ~ 1 + x
OR y ~ x
Explanation: Simple Linear Regression including intercept & slope
Model: \(y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \epsilon\)
R Formula: y ~ x1 + x2
Explanation: Multiple Linear Regression with two variables including intercept & slopes, no interaction
Model: \(y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_1x_2 + \epsilon\)
R Formula: y ~ x1 + x2 + x1:x2
OR y ~ x1*x2
Explanation: Multiple Linear Regression with with two variables including intercept & slopes and two-way interaction
Model: \(\large y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_3+ \epsilon\)
R Formula: y ~ x1 + x2 + x3
Explanation: Multiple Linear Regression with three variables including intercept & slopes, no interaction
Model: \(\large y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_3 + \beta_4x_1x_2 + \beta_5x_1x_3 + \beta_6x_2x_3 + \beta_7x_1x_2x_3 + \epsilon\)
R Formula: y ~ x1 + x2 + x3 + x1:x2 + x1:x3 + x2:x3 + x1:x2:x3
OR y ~ x1*x2*x3
Explanation: Multiple Linear Regression with three variables including intercept & slopes and all two & three-way interactions
Model: \(\large y = \beta_0 + \beta_1x_1 + \beta_2x_2 + \beta_3x_3 + \beta_4x_1x_2 + \beta_5x_1x_3 + \beta_6x_2x_3 + \epsilon\)
R Formula: y ~ x1 + x2 + x3 + x1:x2 + x1:x3 + x2:x3
OR y ~ (x1 + x2 + x3)^2
Explanation: Multiple Linear Regression with three variables including intercept & slopes and only two-way interactions
Model: \(y = \beta_0 + \beta_1x + \beta_2x^2 + \epsilon\)
R Formula: y ~ 1 + x + I(x^2)
Explanation: Polynomial Linear Regression including intercept and linear & quadratic terms
Model: \(y = \beta_0 + \beta_1x + \beta_2x^2 + \beta_3x^3 + \epsilon\)
R Formula: y ~ 1 + x + I(x^2) + I(x^3)
Explanation: Polynomial Linear Regression including linear, quadratic & cubic terms
Model: \(ln(y) = \beta_0 + \beta_1x + \beta_2x + \epsilon\)
R Formula: log(y) ~ x1 + x2
Explanation: Multiple Linear Regression with log-transformed y
and including intercept & slopes