Predictor transformations and interactions are allowed.
By contrast, Y=\beta_0+\beta_1X_1^{\beta_2}+\varepsilon is nonlinear in the unknown exponent \beta_2.
Linear models in matrix form
y=X\beta+\varepsilon,\qquad \hat y=X\hat\beta.
y: n\times1 response vector.
X: n\times q design matrix, including the intercept when present.
\beta: q\times1 coefficient vector.
Least squares minimises \lVert y-X\beta\rVert^2.
For a full-rank design, fitted residuals are orthogonal to the columns of X and have n-q residual degrees of freedom. The random error vector itself is not constrained to that residual subspace.
Geometrical representation
Formula notation in R
It is possible to use a formula notation in R, when these are named (names()).
In previous example: Sepal.Length ~ Species
Formulas in R
variable \sim group
variables per group
This notation is homogeneous along most of R code
Formula Notation in R, II
Formulas
response \sim model
See help(formula)
log(Sepal.Length) ~ Species
Arithmetic functions are allowed:
I(Sepal.Length + Petal.Length) ~ Species
Heavily used in linear regression, but also in visualization functions
Galápagos plant species data
Galápagos Islands : 30 islands, 7 variables
Species: The number of plant species found on the island
Area: The area of the island (km^2)
Nearest: The distance from the nearest island (km)
Elevation: The highest elevation of the island (m)
Endemics: The number of endemic species
Scruz: The distance from Santa Cruz island (km)
Adjacent: the area of the adjacent island (square km)
Weighted least squares models unequal precision, for example with lm(..., weights = w).
Generalised linear models specify a response distribution and link, for example glm(..., family = binomial()).
Robust regression, such as MASS::rlm(), reduces sensitivity to particular deviations such as outliers.
A GLM does not automatically solve correlated errors.
One way anova (1/2)
Generalization of t-test
H_0: \mu_0=\mu_1=\cdots=\mu_p
oneway.test(Sepal.Length ~ Species,data=iris)
One-way analysis of means (not assuming equal variances)
data: Sepal.Length and Species
F = 138.91, num df = 2.000, denom df = 92.211, p-value < 2.2e-16
p-value small: we reject null hypothesis of equal means