LINREG: Linear Regression

LINREGR Documentation

Linear Regression

Description

This function builds a linear regression model. Standard least square method, variable selection, factorial methods are available.

Usage

LINREG(
  x,
  y,
  quali = c("none", "intercept", "slope", "both"),
  reg = c("linear", "subset", "ridge", "lasso", "elastic", "pcr", "plsr"),
  regeval = if (reg[1] == "subset") c("bic", "adjr2", "cp", "r2") else c("r2", "msep"),
  scale = TRUE,
  validation = c("CV", "LOO"),
  lambda = 10^seq(-5, 5, length.out = 101),
  alpha = 0.5,
  nrep = 1,
  tune = FALSE,
  methodparameters = NULL,
  graph = FALSE,
  seed = NULL,
  ...
)

Arguments

x

Predictor matrix.

y

Response vector.

quali

Indicates how to use the qualitative variables.

reg

The algorithm.

regeval

The criterion used to choose between models. For reg = "subset": "bic" (the default), "adjr2" or "cp", which all penalize the number of variables, and "r2", which does not – the R2 can only grow when a variable is added, so it always retains every variable. For reg = "pcr" and reg = "plsr", where the choice is a number of components: "r2" (the default) or "msep". Ignored by the other algorithms.

scale

If true, PCR and PLS use scaled dataset.

validation

How the number of components of a PCR or PLS regression is chosen: "CV" (10 random segments, the default) or "LOO" (leave-one-out, one regression per observation – only practical on a small dataset). Ignored by the other algorithms.

lambda

The lambda parameter of Ridge, Lasso and Elastic net regression.

alpha

The elasticnet mixing parameter.

nrep

How many times the cross-validation choosing lambda is repeated, its errors being averaged. One is enough in practice – cv.glmnet already averages over its own folds – and each extra repetition costs another ten fits. Raise it to steady the choice of lambda on a small or noisy dataset.

tune

If true, the function returns parameters instead of a classification model.

methodparameters

Present for interface consistency with performance (which always passes it when fitting a model). Currently unused: LINREG does not support reusing pre-tuned parameters.

graph

A logical indicating whether or not graphics should be plotted (ridge, LASSO and elastic net).

seed

A specified seed for random number generation, so that two runs on the same data give the same model. Every learning method accepts it, so that it can be set the same way whatever the method; the deterministic ones simply have nothing to draw and give the same model with or without it.

...

Other parameters.

Value

The classification model, as an object of class model-class.

See Also

lm, regsubsets, mvr, glmnet

Examples

## Not run: 
require (datasets)
# With one independent variable
data (cars)
LINREG (cars [, -2], cars [, 2])
# With two independent variables
data (trees)
LINREG (trees [, -3], trees [, 3])
# With non numeric variables
data (ToothGrowth)
LINREG (ToothGrowth [, -1], ToothGrowth [, 1], quali = "intercept") # Different intercept
LINREG (ToothGrowth [, -1], ToothGrowth [, 1], quali = "slope") # Different slope
LINREG (ToothGrowth [, -1], ToothGrowth [, 1], quali = "both") # Complete model
# With multiple numeric variables
data (mtcars)
LINREG (mtcars [, -1], mtcars [, 1])
LINREG (mtcars [, -1], mtcars [, 1], reg = "subset", regeval = "adjr2")
LINREG (mtcars [, -1], mtcars [, 1], reg = "ridge")
LINREG (mtcars [, -1], mtcars [, 1], reg = "lasso")
LINREG (mtcars [, -1], mtcars [, 1], reg = "elastic")
LINREG (mtcars [, -1], mtcars [, 1], reg = "pcr")
LINREG (mtcars [, -1], mtcars [, 1], reg = "plsr")

## End(Not run)

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.