linear_regression {RcppFastAD}R Documentation

Evaluate a squared-loss linear regression at a given parameter value

Description

Not that this function does not actually fit the model. Rather it evaluates the squared sum of residuals and ‘gradient’ of parameters.

Usage

linear_regression(X, y, theta_hat, initial_lr = 1e-04, max_iter = 100L,
  tol = 1e-07)

Arguments

X

Matrix with independent explanatory variables

y

Vector with dependent variable

theta_hat

Vector with initial ‘guess’ of parameter values

initial_lr

[Optional] Scalar with initial step-size value, default is 1e-4

max_iter

[Optional] Scalar with maximum number of iterations, default is 100

tol

[Optional] Scalar with convergence tolerance, default is 1e-7

Value

A list object with the ‘loss’, ‘theta’ (parameters), ‘gradient’ and ‘iter’ for iterations

Examples

data(trees)   # also used in help(lm)
X <- as.matrix(cbind(const=1, trees[, c("Girth", "Height")]))
y <- trees$Volume
linear_regression(X, y, rep(0, 3), tol=1e-12)
coef(lm(y ~ X - 1))  # for comparison

[Package RcppFastAD version 0.0.2 Index]