[ top | up ]

Fitting Linear Models

Syntax

lm(formula, data, subset, weights, na.action=na.omit)

anova(lm.obj)
summary(lm.obj)

coefficients(lm.obj)
deviance(lm.obj)
df.residual(lm.obj)
effects(lm.obj)
fitted.values(lm.obj)
residuals(lm.obj)
weights(lm.obj)

lm.fit(x, y)
lm.w.fit(x, y, w)

Arguments

formula a symbolic description of the model to be fit. The details of model specification are given below.
data an optional data frame containing the variables in the model. By default the variables are taken from the environment which lm is called from.
subset an optional vector specifying a subset of observations to be used in the fitting process.
weights an optional vector of weights to be used in the fitting process.
na.action a function which indicates what should happen when the data contain NAs. The default action (na.omit) is to omit any incomplete observations. The alternative action na.fail causes lm to print an error message and terminate if there are any incomplete observations.
lm.obj an object of class lm.

Description

lm is used to fit linear models. It can be used to carry out regression, single stratum analysis of variance and analysis of covariance.

Models for lm are specified symbolically. A typical model has the form reponse ~ terms where response is the (numeric) response vector and terms is a series of terms which specifies a linear predictor for response. A terms specification of the form first+second indicates all the terms in first together with all the terms in second with duplicates removed. A specification of the form first:second indicates the the set of terms obtained by taking the interactions of all terms in first with all terms in second. The specification first*second indicates the cross of first and second. This is the same as first+second+first:second.

Value

lm returns an object of class lm. The function summary can be used to obtain or print a summary of the results and the function anova and be used to produce and analysis of variance table. The generic accessor functions coefficients, effects, fitted.values and residuals can be used to extract various useful features of the value returned by lm.

See Also

anova, coefficients, effects, fitted.values, glm, residuals, summary.