Learn R Programming

desk (version 1.1.2)

ols: Ordinary Least Squares Regression

Description

Estimates linear models using ordinary least squares estimation. Generated objects should be compatible with commands expecting objects generated by lm(). The object returned by this command can be plotted using the plot() function.

Usage

ols(
  formula,
  data = list(),
  na.action = NULL,
  contrasts = NULL,
  details = FALSE,
  ...
)

Value

A list object including:

coefficients/coefestimated parameters of the model.
residuals/residresiduals of the estimation.
effectsn vector of orthogonal single-df effects. The first rank of them correspond to non-aliased coefficients, and are named accordingly.
fitted.valuesfitted values of the regression line.
df.residual/dfdegrees of freedom in the model (number of observations minus rank).
sevector of standard errors of the parameter estimators.
t.valuevector of t-values of single parameter significance tests.
p.valuevector of p-values of single parameter significance tests.
data/modelmatrix of the variables' data used.
responsethe endogenous (response) variable.
model.matrixthe model (design) matrix.
ssrsum of squared residuals.
sig.squestimated error variance (sigma squared).
vcovthe variance-covariance matrix of the model's estimators.
r.squcoefficient of determination (R squared).
adj.r.squadjusted coefficient of determination (adj. R squared).
nobsnumber of observations.
ncoef/rankinteger, giving the rank of the model (number of coefficients estimated).
has.constlogical value indicating whether model has constant parameter.
f.valF-value for simultaneous significance of all slope parameters.
f.pvalp-value for simultaneous significance of all slope parameters.
modformthe model's regression R-formula.
callthe function call by which the regression was calculated (including modform).

Arguments

formula

model formula.

data

name of data frame of variables in formula.

na.action

function which indicates what should happen when the data contain NAs.

contrasts

an optional list. See the contrasts.arg of model.matrix.default.

details

logical value indicating whether details should be printed out by default.

...

other arguments that lm.fit() supports.

Details

Let X be a model object generated by ols() then plot(X, ...) accepts the following arguments:

pred.int = FALSEshould prediction intervals be added to plot?
conf.int = FALSEshould confidence intervals be added to plot?
residuals = FALSEshould residuals be added to plot?
center = FALSEshould mean values of both variables be added to plot?

Examples

Run this code
## Minimal simple regression model
check <- c(10,30,50)
tip <- c(2,3,7)
tip.est <- ols(tip ~ check)

## Equivalent estimation using data argument
tip.est <- ols(y ~ x, data = data.tip)

## Show estimation results
tip.est

## Show details
print(tip.est, details = TRUE)

## Plot scatter and regression line
plot(tip.est)

## Plot confidence (dark) and prediction bands (light), residuals and two center lines
plot(tip.est, pred.int = TRUE, conf.int = TRUE, residuals = TRUE, center = TRUE)

## Multiple regression model
fert.est <- ols(barley ~ phos + nit, data = log(data.fertilizer), details = TRUE)
fert.est

Run the code above in your browser using DataLab