ols {desk}R Documentation

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,
  ...
)

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 = FALSE should prediction intervals be added to plot?
conf.int = FALSE should confidence intervals be added to plot?
residuals = FALSE should residuals be added to plot?
center = FALSE should mean values of both variables be added to plot?

Value

A list object including:

coefficients/coef estimated parameters of the model.
residuals/resid residuals of the estimation.
effects n vector of orthogonal single-df effects. The first rank of them correspond to non-aliased coefficients, and are named accordingly.
fitted.values fitted values of the regression line.
df.residual/df degrees of freedom in the model (number of observations minus rank).
se vector of standard errors of the parameter estimators.
t.value vector of t-values of single parameter significance tests.
p.value vector of p-values of single parameter significance tests.
data/model matrix of the variables' data used.
response the endogenous (response) variable.
model.matrix the model (design) matrix.
ssr sum of squared residuals.
sig.squ estimated error variance (sigma squared).
vcov the variance-covariance matrix of the model's estimators.
r.squ coefficient of determination (R squared).
adj.r.squ adjusted coefficient of determination (adj. R squared).
nobs number of observations.
ncoef/rank integer, giving the rank of the model (number of coefficients estimated).
has.const logical value indicating whether model has constant parameter.
f.val F-value for simultaneous significance of all slope parameters.
f.pval p-value for simultaneous significance of all slope parameters.
modform the model's regression R-formula.
call the function call by which the regression was calculated (including modform).

Examples

## 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


[Package desk version 1.1.1 Index]