# lmr: Multiple Linear Regression Models In mlesnoff/rnirs: Dimension reduction, Regression and Discrimination for Chemometrics

 lmr R Documentation

## Multiple Linear Regression Models

### Description

Function `lmr` fits a multiple linear regression model (MLR) using function `lm`.

Row observations can eventually be weighted.

### Usage

``````
lmr(Xr, Yr, Xu, Yu = NULL, weights = NULL)

``````

### Arguments

 `Xr` A `n x p` matrix or data frame of reference (= training) observations. `Yr` A `n x q` matrix or data frame, or a vector of length `n`, of reference (= training) responses. `Xu` A `m x p` matrix or data frame of new (= test) observations to predict. `Yu` A `m x q` matrix or data frame, or a vector of length `m`, of the true responses for `Xu`. Default to `NULL`. `weights` A vector of length `n` defining a priori weights to apply to the training observations. Internally, weights are "normalized" to sum to 1. Default to `NULL` (weights are set to `1 / n`).

### Value

A list of outputs (see examples), such as:

 `y` Responses for the test data. `fit` Predictions for the test data. `r` Residuals for the test data. `fm` Output of function `lm`.

### Examples

``````
n <- 10
p <- 6
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
y1 <- 100 * rnorm(n)
y2 <- 100 * rnorm(n)
Y <- cbind(y1, y2)
set.seed(NULL)

Xr <- X[1:8, ] ; Yr <- Y[1:8, ]
Xu <- X[9:10, ] ; Yu <- Y[9:10, ]

fm <- lmr(Xr, Yr, Xu, Yu)
names(fm)
fm\$y
fm\$fit
fm\$r
names(fm\$fm)

coef(fm\$fm)

mse(fm, nam = "y1")
mse(fm, nam = "y2")
mse(fm)

``````

mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.