740 Contributors: 15 Saturday, May 13, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial:
Roadmap: roadmap

Linear Models (Regression)


  • lm(formula, data, subset, weights, na.action, method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ...)


formulaa formula in Wilkinson-Rogers notation; response ~ ... where ... contains terms corresponding to variables in the environment or in the data frame specified by the data argument
datadata frame containing the response and predictor variables
subseta vector specifying a subset of observations to be used: may be expressed as a logical statement in terms of the variables in data
weightsanalytical weights (see Weights section above)
na.actionhow to handle missing (NA) values: see ?na.action
methodhow to perform the fitting. Only choices are "qr" or "model.frame" (the latter returns the model frame without fitting the model, identical to specifying model=TRUE)
modelwhether to store the model frame in the fitted object
xwhether to store the model matrix in the fitted object
ywhether to store the model response in the fitted object
qrwhether to store the QR decomposition in the fitted object
singular.okwhether to allow singular fits, models with collinear predictors (a subset of the coefficients will automatically be set to NA in this case
contrastsa list of contrasts to be used for particular factors in the model; see the contrasts.arg argument of ?model.matrix.default. Contrasts can also be set with options() (see the contrasts argument) or by assigning the contrast attributes of a factor (see ?contrasts)
offsetused to specify an a priori known component in the model. May also be specified as part of the formula. See ?model.offset
...additional arguments to be passed to lower-level fitting functions ( or lm.wfit())

Related Examples